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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: for k8s set PGDATA to subfolder #253

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

wilmardo
Copy link

@wilmardo wilmardo commented Nov 26, 2019

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, but if the data volume you're using is a filesystem mountpoint (like with GCE persistent disks), Postgres initdb recommends a subdirectory (for example /var/lib/postgresql/data/pgdata ) be created to contain the data.

Source: https://hub.docker.com/_/postgres/

Since within Kubernetes the persistent disks are filesystem mountpoints the PGDATA variable should be set to a subdir.

This should fix #251 but I have not been able to test it yet.

EDIT:
Just tested this and it works fine but it also works fine without (this is on NFS however so might not be completely representable). @Telokis could you test this?
I am still in favor of merging this since it is advised by Postgres 馃憤

Signed-off-by: wilmardo <info@wilmardenouden.nl>
@Telokis
Copy link

Telokis commented Nov 26, 2019

Hey @wilmardo !

Thanks for the PR.
I quickly glanced at it. I plan on testing it but shouldn't you use https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath instead of simply moving the mount directory?
Right now it seems like you didn't change the behavior at all but simply changed the mounted directory.

I'll try this ASAP and report here.

EDIT: My bad, I misunderstood subPath. However, I think you should only add the PD_DATA variable without changing the mountPath itself.

@Telokis
Copy link

Telokis commented Nov 26, 2019

Back with feedback!

Got the exact same error but the directory is different:

2019-11-26 15:05:28.501 UTC [142] FATAL:  data directory "/var/lib/postgresql/data/pgdata" has wrong ownership
2019-11-26 15:05:28.501 UTC [142] HINT:  The server must be started by the user that owns the data directory.

I'm gonna try with the different mountPath to see if it helps but I'm not really hopeful.

EDIT: Just tried the other idea but still no luck. It doesn't want to work.

Signed-off-by: wilmardo <info@wilmardenouden.nl>
@wilmardo
Copy link
Author

@Telokis Thanks for the test! Good point about the mountPath I restored the values to what they were.

The current approach is what you gave tested and still isn't working?

@Telokis
Copy link

Telokis commented Nov 26, 2019

Yes, I tried with the current setup (after your modifications) but I also tried with the previous setup.

In both cases, the same error arised.

@wilmardo
Copy link
Author

Could you share the values.yml you are using so I could test it?

@Telokis
Copy link

Telokis commented Nov 26, 2019

I didn't change it at all, I'm using all default values everywhere. It was a simple "clone and run" test

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

Successfully merging this pull request may close these issues.

Data directory "/var/lib/postgresql/data" has wrong ownership in Kubernetes
2 participants