Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with lost+found dir and mounting parent folder (/var/lib/postgres) as volume #952

Closed
Torkolis opened this issue Apr 13, 2022 · 1 comment

Comments

@Torkolis
Copy link

Torkolis commented Apr 13, 2022

According to this: https://www.postgresql.org/message-id/12168.1312921709%40sss.pgh.pa.us
it is not possible to mount "data" dir directly as for example longhorn volume in kubernetes so I should mount the parent folder, but according to
https://github.com/docker-library/postgres/blob/master/14/alpine/Dockerfile
line 155 VOLUME /var/lib/postgresql/data
it does not work to mount it, because then it only contains an empty "data" folder (next to the lost+found one) and the actuall database is then mounted separately into an anonymous volume and therefore lost on container restart.
So what is the solution?

@Torkolis
Copy link
Author

Ah found explanation on dockerhub:

PGDATA
This optional variable can be used to define another location - like a subdirectory - for the database files. The default is /var/lib/postgresql/data. If the data volume you're using is a filesystem mountpoint (like with GCE persistent disks) or remote folder that cannot be chowned to the postgres user (like some NFS mounts), Postgres initdb recommends a subdirectory be created to contain the data.

For example:

$ docker run -d
--name some-postgres
-e POSTGRES_PASSWORD=mysecretpassword
-e PGDATA=/var/lib/postgresql/data/pgdata
-v /custom/mount:/var/lib/postgresql/data
postgres
This is an environment variable that is not Docker specific. Because the variable is used by the postgres server binary (see the PostgreSQL docs), the entrypoint script takes it into account.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant