Skip to content

Commit

Permalink
Create postgres user explicitly if $POSTGRES_USER is not "postgres" (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
pensnarik authored and paunin committed Dec 16, 2018
1 parent 7d96beb commit 2f7fa65
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/pgsql/bin/postgres/primary/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
set -e
FORCE_RECONFIGURE=1 postgres_configure

# We need to create postgres user explicitly,
# see https://github.com/docker-library/postgres/commit/3f585c58df93e93b730c09a13e8904b96fa20c58
if [ ! "$POSTGRES_USER" = "postgres" ]; then
echo ">>> Creating postgres user explicitly"
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -c "CREATE ROLE postgres LOGIN SUPERUSER"
fi

echo ">>> Creating replication user '$REPLICATION_USER'"
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -c "CREATE ROLE $REPLICATION_USER WITH REPLICATION PASSWORD '$REPLICATION_PASSWORD' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;"

Expand Down

0 comments on commit 2f7fa65

Please sign in to comment.