Skip to content

Commit c1683bd

Browse files
author
aegis/crew/arnold
committed
Fix exec_sql to use configured credentials instead of hardcoded defaults
The exec_sql function hardcoded PGPASSWORD=password and -U postgres when connecting via psql. This caused init scripts in /docker-entrypoint-initdb.d/ to silently fail when DOLTGRES_USER or DOLTGRES_PASSWORD were set to custom values, because the postgres user no longer exists. Use the existing get_env_var helper to read DOLTGRES_USER/PASSWORD (or POSTGRES_USER/PASSWORD), falling back to postgres/password only when neither is set. Fixes #2300
1 parent 0873c7e commit c1683bd

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

docker-entrypoint.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,21 @@ exec_sql() {
9292
echo "running psql command found in: "
9393
echo $(which psql)
9494

95+
local pg_user pg_password
96+
pg_user=$(get_env_var "USER")
97+
pg_password=$(get_env_var "PASSWORD")
98+
pg_user="${pg_user:-postgres}"
99+
pg_password="${pg_password:-password}"
100+
95101
while true; do
96102
if [ -n "$query" ]; then
97103
set +e
98-
output=$(PGPASSWORD=password psql -h 127.0.0.1 -U postgres -c "$query" 2>&1)
104+
output=$(PGPASSWORD="$pg_password" psql -h 127.0.0.1 -U "$pg_user" -c "$query" 2>&1)
99105
status=$?
100106
set -e
101107
else
102108
set +e # tmp disabled to initdb.d/ file err
103-
output=$(PGPASSWORD=password psql -h 127.0.0.1 -U postgres < /dev/stdin 2>&1)
109+
output=$(PGPASSWORD="$pg_password" psql -h 127.0.0.1 -U "$pg_user" < /dev/stdin 2>&1)
104110
status=$?
105111
set -e
106112
fi

0 commit comments

Comments
 (0)