diff --git a/pica-mattermost/Dockerfile b/pica-mattermost/Dockerfile
index be7137c8fb443f839d142997545f30489ebbc285..8eab834fcbe201f3fbde65dcad923b658b4d0859 100644
--- a/pica-mattermost/Dockerfile
+++ b/pica-mattermost/Dockerfile
@@ -22,6 +22,7 @@ RUN apk add --no-cache \
 	netcat-openbsd \
 	xmlsec-dev \
 	tzdata \
+	postgresql-client \
 	&& rm -rf /tmp/*
 
 # Get Mattermost
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