Skip to content

chown: changing ownership of '/var/lib/postgresql/data': Input/output error When running the image in Kubernetes #495

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

Closed
asakapab0i opened this issue Sep 9, 2018 · 7 comments
Labels
question Usability question, not directly related to an error with the image

Comments

@asakapab0i
Copy link

I'm using OSS filesystem in Alibaba, similar to S3 in AWS.

Can someone assist why this is happening?

@asakapab0i asakapab0i changed the title chown: changing ownership of '/var/lib/postgresql/data': Input/output error When running Kubernetes chown: changing ownership of '/var/lib/postgresql/data': Input/output error When running the image in Kubernetes Sep 9, 2018
@wglambert wglambert added the question Usability question, not directly related to an error with the image label Sep 10, 2018
@wglambert
Copy link

Same issue #361

As Yosifkit said: this seems like a general debugging question and not really a problem with the image, it'd be better to post questions like this in the Docker Community Forums, the Docker Community Slack, or Stack Overflow.

Closing since this issue is environmental, not something we can really fix in the image.

@asakapab0i
Copy link
Author

this seems like a general debugging question and not really a problem with the image

Its a clear BUG to me, I say reopen and address it rather than closing it because you found "other related issue" which is also closed btw. That is why it was not resolved because you keep closing the issue. Let other people see and solve it rather than burying it into the deep.

@tianon
Copy link
Member

tianon commented Sep 17, 2018

It sounds to me like the filesystem you're using (or the driver you're using to access it) do not support chown -- you'll need to either resolve that or run the image directly as a user with access to the filesystem so that it skips the chown code (with --user on docker run; there should be a similar option for Kubernetes).

As far as I can see, there's nothing we can change about the image to fix this environment-specific issue?

@asakapab0i
Copy link
Author

Sounds good enough, the filesystem permission can be changed via the UI so I guess that solves it. Maybe address a proper error if something fails specifically to this error? That could be a big help to anyone.

@supereagle
Copy link

you'll need to either resolve that or run the image directly as a user with access to the filesystem so that it skips the chown code (with --user on docker run; there should be a similar option for Kubernetes).

Use securityContext in k8s to specify the user, but the pod can not start:

# kubectl logs -f test-5fc6b7bbf4-v7425
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

initdb: directory "/var/lib/postgresql/data/pgdata" exists but is not empty
If you want to create a new database system, either remove or empty
the directory "/var/lib/postgresql/data/pgdata" or run initdb
with an argument other than "/var/lib/postgresql/data/pgdata".

@bn-nb
Copy link

bn-nb commented Sep 14, 2024

This usually happens when postgresql attempts chown on the /var/lib/postgres/data directory, and if this is mapped to the host file system, it will end up changing the permissions on host too.

This is especially problematic if the host is a Windows device using NTFS filesystems, where unix-style permission changes are not allowed. I can think of two solutions:

  1. Either prevent postgresql from changing ownership and work normally otherwise by some containerization policies.
  2. Or enable docker-compose methods to simulate file system permissions when bindings to host data are used.

@tianon
Copy link
Member

tianon commented Sep 16, 2024

If you run the container directly as a non-root user, it will completely avoid the chown logic (because it can't ever work in that case). For docker run, that's the --user flag, for docker-compose that's the user: key, and for Kubernetes that's runAsUser:+runAsGroup:.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Usability question, not directly related to an error with the image
Projects
None yet
Development

No branches or pull requests

5 participants