Fix PostgreSQL data persistence#387
Merged
DougReeder merged 1 commit intoSep 16, 2025
Merged
Conversation
What: Returns the mountPath for the postgresql-data volume back to it's original value and adds the PGDATA environment variable to the container to specify that the PostgreSQL data be stored in a further subfolder. Why: Changing the mountPath doesn't actually change where the data is written, instead it causes Docker to create an anonymous volume at the default path that is discarded when the container/pod is deleted (which loses all the data). Using the PGDATA environment variable to specify that the PostgreSQL data be stored in a further subfolder should continue to avoid the issue of a lost+found folder being created somewhere PostgreSQL doesn't like it. Note: This will need to be updated in the future because future versions of PostgreSQL expect the data to be stored in version specific folders.
DougReeder
approved these changes
Sep 10, 2025
Member
DougReeder
left a comment
There was a problem hiding this comment.
The change looks correct.
I'd like to test it on my instance before we merge it, but my cluster now uses an external database.
This was referenced Sep 11, 2025
|
Using my CE instance as a test case I along with Imaginer tested the data persistence of this pull request as defined in the PR and it performed as intended. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Returns the mountPath for the postgresql-data volume back to it's original value and adds the PGDATA environment variable to the container to specify that the PostgreSQL data be stored in a further subfolder.
Why?
Changing the mountPath doesn't actually change where the data is written, instead it causes Docker to create an anonymous volume at the default path that is discarded when the container/pod is deleted (which loses all the data).
Using the PGDATA environment variable to specify that the PostgreSQL data be stored in a further subfolder should continue to avoid the issue of a lost+found folder being created somewhere PostgreSQL doesn't like it.
Examples
N/A
How to test
kubectl delete -f hcce.yaml.Note: if you want to preserve your old data you should back it up first with the backup scripts from PR #382
Documentation of functionality
This fixes a bug in the current behavior, so no documentation change is needed.
Limitations
This will need to be updated in the future because future versions of PostgreSQL expect the data to be stored in version specific folders.
Alternatives considered
None.
Open questions
None.
Additional details or related context
PR #363
References:
https://www.linode.com/community/questions/22421/why-is-postgres-data-deleted-when-pod-restarted-on-kubernetes
https://datageek.blog/2020/06/17/disappearing-data-in-postgresql/
https://stackoverflow.com/questions/58069267/postgres-running-on-kubernetes-looses-data-upon-pod-recreation-or-cluster-reboot
docker-library/postgres#263 (comment)
https://hub.docker.com/_/postgres#pgdata
https://github.com/docker-library/docs/blob/master/postgres/README.md
https://github.com/docker-library/postgres/blob/e2a43025b1acedac60ddfad3678ed5da1a09fd79/12/alpine3.21/Dockerfile
https://github.com/docker-library/postgres/blob/master/18/alpine3.22/Dockerfile