Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Question: Why is the /var/lib/postgresql/data directory cleared when mounting /var/lib/postgresql as volume? #1163

Closed
larsderidder opened this issue Dec 11, 2023 · 1 comment

Comments

@larsderidder
Copy link

larsderidder commented Dec 11, 2023

We had an issue in our Azure K8S deployment using this image, where restarting the pod caused the database to be recreated. Upon further inspection it turned out that the /var/lib/postgresql/data directory was recreated every time the pod was restarted.

Normally when using this image, I mount a volume directly on /var/lib/postgresql/data, but in this case the pod mounted /var/lib/postgresql. The reason for this was that mounting /var/lib/postgresql/data on Azure gives an error, as Azure volumes have a lost+found file on the root of the mount point, and then Postgres complains that the data directory isn't empty and it cannot initialize the database.

Anyway, I just don't understand why this wouldn't work. Any files created directly in /var/lib/postgresql are persisted on restart. I solved it now by setting the PGDATA env variable to /var/lib/postgresql/pgdata, and that directory is properly persisted. I looked at the init_db.sh script but didn't see any reason for it to wipe the /var/lib/postgresql/data directory.

What is the reason that specific directory is cleared?

@tianon
Copy link
Member

tianon commented Dec 11, 2023

It's probably getting cleared because it's marked as a "volume" in the image metadata, so the container runtime is likely creating a new mount underneath it on every container startup if you didn't specify one explicitly.

To solve the lost+found problem, you should be able to specify that Kubernetes should create/mount a subdirectory of the volume it creates into the container (instead of mounting the root of the volume raw). Alternatively, you should be able to set PGDATA to an alternate directory to control where PostgreSQL looks for it / puts it (#952).

@docker-library docker-library locked and limited conversation to collaborators Dec 11, 2023
@tianon tianon converted this issue into discussion #1165 Dec 11, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants