diff --git a/pica-mattermost/entrypoint.sh b/pica-mattermost/entrypoint.sh
index c504225324686fd4db4c55f6cfc33cebc840f29f..bbaba57e59f0609bba1475c5d885fb22258e913b 100644
--- a/pica-mattermost/entrypoint.sh
+++ b/pica-mattermost/entrypoint.sh
@@ -68,7 +68,11 @@ if [ "$1" = 'mattermost' ]; then
 
   # Wait another second for the database to be properly started.
   # Necessary to avoid "panic: Failed to open sql connection pq: the database system is starting up"
-  sleep 1
+  until pg_isready -h $DB_HOST -p $DB_PORT_NUMBER
+  do
+	  echo "Database is not ready yet. Waiting 5 seconds."
+	  sleep 5
+  done
 
   echo "Starting mattermost"
 fi