Closed cobolbaby closed 6 months ago
I still don't quite understand this detail. If executed with the root user, after running gosu postgres bash pg_upgrade --link
once, does it continue with operations like initdb
or exec "$@"
?
Flattened and without conditionals, the flow is something like:
# as root
mkdir -p "$PGDATAOLD" "$PGDATANEW"
chmod 700 "$PGDATAOLD" "$PGDATANEW"
chown postgres .
chown -R postgres "$PGDATAOLD" "$PGDATANEW"
# as postgres
PGDATA="$PGDATANEW" eval "initdb $POSTGRES_INITDB_ARGS"
exec pg_upgrade ...
Copy that.
This line:
https://github.com/tianon/docker-postgres-upgrade/blob/65ab4e308514a3139bca8ac94bdabfba234a29f5/docker-upgrade#L13
boils down to essentially "run this script with the same arguments, but as user
postgres
instead ofroot
" (note that it's in anif [ "$(id -u)" = '0' ]; then
block, which is "if we areroot
")See also https://github.com/docker-library/postgres/blob/1424abf76f421d6f7bf933d9e42bbbed866fae3a/16/bookworm/docker-entrypoint.sh#L311-L314