Where is my postgresql database path?

I created a postgresql docker with my server, and when it is time to put some data into it, I realized the standard path of /var/lib/postgresql/data in my ubuntu does not have postgresql/data.

This was the docker-compose.yml used:

db:
     restart: always
     image: postgres:14-alpine
     shm_size: 256mb
     networks:
       - internal_network
     healthcheck:
       test: [ 'CMD', 'pg_isready', '-U', 'postgres' ]
     volumes:
       - ./data/postgres:/var/lib/postgresql/data
     environment:
       - 'POSTGRES_HOST_AUTH_METHOD=trust'
     env_file:
       - .env.db

I remembered my database name, host, username, password, & port. I just don’t know where is the database’s path to point at. There wasn’t any noticeable error when I run the compose.

If I’m asked to fill in the “database” part, am I suppose to include this front part ./data/postgres: too, because how do I see it in my Ubuntu’s Shell?

According to doc:

Important Note: Mount the data volume at /var/lib/postgresql/data and not at /var/lib/postgresql because mounts at the latter path WILL NOT PERSIST database data when the container is re-created.

I don’t understand it. What do you mean exactly? What standard path are you referring to on your Ubuntu? /var/lib/postgresql/data is in the container. ./postgresql/data should be on your host. It is a relative path so the exact path depends on where your project is.

You mean “database path”? Or what is the “database part”?

The string on the left side of the colon is the source path. The string on the right side is the path in the container.

It is a relative path so the exact path depends on where your project is.

I see.

You mean “database path”? Or what is the “database part”?

After reading some posts & blogs, I encountered this one, and I think I had mistaken the ‘database’ to be a path, instead of a new table.

const pgclient = new Client({
    host: process.env.POSTGRES_HOST,
    port: process.env.POSTGRES_PORT,
    user: 'postgres',
    password: 'postgres',
    database: 'postgres'

Because this was kind of like the areas where I need to fill out. What do you think?

The string on the left side of the colon is the source path. The string on the right side is the path in the container.

Of course. Why I did forgot this.

Can you more clearly describe your issue?

You mount local postgres folder directly into data inside the container, so you will probably not see another data folder on the host. But the data content will be in your local postgres folder.

If that is your problem, then to make it more clear in the future, you could use:

volumes:
       - ./data/postgres/data:/var/lib/postgresql/data

[/quote]

A database is a database. Not a path and not a table either. YOu can have tables in a database so I’m with @bluepuma77 on this

I can’t follow your thoughts without that

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.