Skip to content

Commit 2f7fa65

Browse files
pensnarikpaunin
authored andcommitted
Create postgres user explicitly if $POSTGRES_USER is not "postgres" (#201)
This is because initdb in official PostgreSQL Docker image does not create postgres user during initialization anymore. Therefore createdb statement which implicitly uses postgres system user to connect to the cluster will fail. See docker-library/postgres@3f585c5
1 parent 7d96beb commit 2f7fa65

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/pgsql/bin/postgres/primary/entrypoint.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
set -e
33
FORCE_RECONFIGURE=1 postgres_configure
44

5+
# We need to create postgres user explicitly,
6+
# see https://github.com/docker-library/postgres/commit/3f585c58df93e93b730c09a13e8904b96fa20c58
7+
if [ ! "$POSTGRES_USER" = "postgres" ]; then
8+
echo ">>> Creating postgres user explicitly"
9+
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -c "CREATE ROLE postgres LOGIN SUPERUSER"
10+
fi
11+
512
echo ">>> Creating replication user '$REPLICATION_USER'"
613
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -c "CREATE ROLE $REPLICATION_USER WITH REPLICATION PASSWORD '$REPLICATION_PASSWORD' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;"
714

0 commit comments

Comments
 (0)