2

Postgresql service refuses to start if the data folder (PGDATA) doesn't belong exclusively to the postgres user (i.e. permissions = 700).

Is there any way to disable or circumvent that condition? Ideally I would like postgresql to start even if the permissions on that folder is set to 777.

Explanations:

I have built a Docker image with a running instance of Postgresql. The requirements are:

  • a) the container should be able to run on Windows Home edition (which means Docker for Windows is not an option and we have to use docker-machine and VirtualBox)
  • b) the user should use Kitematic to download and run the Image, without any need to go to the command line or do any post-install configuration (i.e. it should work out of the box). This means that I only have control over what happens within the container running Psql; I can't change the VM or Windows configs.
  • c) the database must be stored on a data volume mounted on the file system of the host OS (because I want the container to be disposable and upgradable)

a) and b) works perfectly well. But as soon as the user enables the Data Volume in Kitematic (condition c) ) Postgres refuses to start because the owner of the DB folder is reset to 1000:staff which are the default user and group in boot2docker Virtal Machine. There is no way to programmatically change the owner or permissions inside the VirtualMachine due to the way VBox shares the folder with Windows (via a vboxfs mount).

So basically within the container I'm stuck with a PGDATA folder with full access to everyone (i.e. 777, which is not a really an issue in itself since the data is not sensitive and not exposed to other machines).

3
  • 2
    So it seems there is no way to change that condition with config file. The only way is to change Psql the source code and rebuild it. See github.com/postgres/postgres/blob/… Sep 20, 2017 at 23:14
  • Another thing I've tried is using a mount --bind to the PGDATA folder. That doesn't work either because 1) mount are only allowed only when the docker container is started with --privileged (that contradicts condition b) ) 2) permissions on the source and directory cannot be dissociated Sep 21, 2017 at 15:42
  • Symlinking PGDATA won't work either because, on linux, permissions on the link are always 0777. chmod will only change the linked-to file (which, in this case, is forced by vboxfs to 0777 as well). Sep 21, 2017 at 15:53

1 Answer 1

1

A similar issue happens with Windows wsl. If you try to move the data_directory to a Windows owned mount (e.g., different hard drive /mnt/d/...) you won't be able to change the file permissions by default.

However, this answer worked for me: https://superuser.com/a/1343737/1767400 Basically, update /etc/wsl.conf (with sudo) to add

[automount]
options = "metadata"

Then restart all systems (Windows and wsl) and you will be able to change the file permissions to make postgres happy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.