docker-library / postgres

Docker Official Image packaging for Postgres
http://www.postgresql.org
MIT License
2.14k stars 1.11k forks source link

Feature Request: Archive Mode #1143

Closed ackava closed 7 months ago

ackava commented 8 months ago

I am aware of POSTGRES_INITDB_WALDIR and I am using it, but what I want to achieve is, I want to archive the logs periodically to different docker volume which is synced to S3 or any other cloud storage. Currently, I am forced to archive logs in the subfolder of WALDIR because I cannot copy logs to volume outside of PGDATA or WALDIR.

I also tried putting chmod 777 $POSTGRES_ARCHIVE_DIR in /docker-entrypoint-initdb.d/setup.sh but it results in error operation not permitted

I have created following patch, https://github.com/docker-library/postgres/compare/master...ackava:postgres:master

However, I am not sure if this is correct way to do it, that's why I haven't submitted the pull request.

In which, we can manually specify the variable POSTGRES_ARCHIVE_DIR, which will enable archiving logs to specified folder and specific configuration turned on. Also give access rights to PGUSER, currently I have no way to give access rights to a different volume.

LaurentGoderre commented 8 months ago

It might be simpler to user a sidecar container to achieve this.

ackava commented 8 months ago

@LaurentGoderre Another container, additional configuration, additional code, additional dependency, just to avoid a single folder which can have write access same as pguser?

LaurentGoderre commented 8 months ago

In that case you can use the initialization script to run those changes in a bash script inside /docker-entrypoint-initdb.d

ackava commented 8 months ago

@LaurentGoderre I have updated my original post, it fails with error operation not permitted.

yosifkit commented 8 months ago

The entrypoint script only sets up permissions on a minimum set of directories and we are unlikely to add more. We'd rather not add yet more environment variables.

https://github.com/docker-library/postgres/blob/f85674ce472bc78b8b8a0478dacd595e44cb9616/docker-entrypoint.sh#L48-L60

Any extra directories you need should be provided with the correct permissions for the postgres user to access (or the user that you are running the contianer as). Unfortunately the initdb.d scripts are run as the postgres user (the drop down from root occurs earlier), so the few options are: