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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Mac+VFS) data directory "/var/lib/postgresql/data" has wrong ownership #361

Closed
daweimau opened this issue Sep 17, 2023 · 3 comments
Closed

Comments

@daweimau
Copy link

Given the below docker-compose yml:

version: "3.7"

services:
    db:
        container_name: db
        image: postgis/postgis:15-3.4-alpine
        ports:
            - "5010:5432"  
        environment:
            POSTGRES_DB: my-db
            POSTGRES_USER: postgres
            POSTGRES_PASSWORD: verysecretpass
        volumes:
            - ./pgdata:/var/lib/postgresql/data 
  • If we replace image with postgres:alpine, we have no issues. Everything works.
  • If we use postgis/postgis:15-3.4-alpine, building the image seems ok, and first run also seems ok. Subsequent runs with docker compose up db will produce this error:
db  | 2023-09-17 01:22:45.415 UTC [1] FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
db  | 2023-09-17 01:22:45.415 UTC [1] HINT:  The server must be started by the user that owns the data directory.

But it works with the postgres alpine image. Why should it not work now?

Seeing as we extend the postgres-alpine image, and postgres-alpine works, I figured we must be introducing the problem after the base image layers / entrypoint.

    db:
        container_name: db
        build:
            context: "./pg"
            dockerfile: "./Dockerfile"
        ports:

Since doing so, the data directory "/var/lib/postgresql/data" has wrong ownership error has disappeared.

I don't understand the details. But I believe the initdb-postgis.sh script is doing it

@daweimau daweimau changed the title var/lib/postgres/data no permission data directory "/var/lib/postgresql/data" has wrong ownership Sep 17, 2023
@ImreSamu
Copy link
Member

Thank you for reporting this issue!

To better assist you, could you provide more details about:

  • Your operating system and its version
  • The Docker / docker-compose version you are using
  • Any other relevant information that might help prevent similar issues in the future would also be appreciated.

By the way, what exact filesystem do you have under the volume? ( ./pgdata: )

For instance, postgres doesn't work for others under Mac/VirtioFS either.

Please try using "docker volume" as a workaround. It has solved the problem for many.

Please also check the related issues in the

If we replace image with postgres:alpine, we have no issues. Everything works.

Please also replace the data dir ( ./pgdatapostgres01: vs. ./pgdatapostgis02: ) and check the logs for the initialization process.
Please share both logs so we can check.

I don't understand the details. But I believe the initdb-postgis.sh script is doing it

There are two initialization steps, which can be challenging to debug. Please share your initialization logs with us.

Or you can replace/remove the postgis initialization with a dummy script, so the original 10_postgis.sh is not running.

  • -v $(pwd)/10_postgis.sh:/docker-entrypoint-initdb.d/10_postgis.sh

@daweimau
Copy link
Author

os

Mac M1 pro sillicon
macOS Ventura 13.5.1
Docker 4.11.0 

Thanks for your links. Reading them made me more suspicious of my workaround. I've since confirmed:

  • My workaround in OP does not reliably work - only intermittently. That aligns with some other users experience of the root issue
  • Based on other posts and your advice, I confirmed below in my case:
    • Docker 4.11 + VFS enabled - Never works (other than first run)
    • Docker 4.11 + VFS disabled - Seems to always work, could not reproduce issue
    • Docker 4.23 + VFS enabled - Seems to always work, could not reproduce issue
    • Docker 4.23 + VFS disabled (use gRPC) - Seems to always work, could not reproduce issue

The behaviour can be quite intermittent so I will come back if my observation changes; I will continue with 4.23+VFS

@ImreSamu ImreSamu changed the title data directory "/var/lib/postgresql/data" has wrong ownership (Mac+VFS) data directory "/var/lib/postgresql/data" has wrong ownership Dec 4, 2023
@ImreSamu
Copy link
Member

ImreSamu commented Dec 4, 2023

The behaviour can be quite intermittent so I will come back if my observation changes; I will continue with 4.23+VFS

I am closing this issue.
However, if there is any important matter that was overlooked, please let me know and I will reopen the issue.

@ImreSamu ImreSamu closed this as completed Dec 4, 2023
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

No branches or pull requests

2 participants