'How can I check postgres database in docker volume?
I followed the tutorial from prisma.io to get started building a local server.
Follow the docker-compose.yml
:
version: '3'
services:
prisma:
image: prismagraphql/prisma:1.34
restart: always
ports:
- '4466:4466'
environment:
PRISMA_CONFIG: |
port: 4466
databases:
default:
connector: postgres
host: postgres
port: 5432
user: prisma
password: prisma
postgres:
image: postgres:10.3
restart: always
environment:
POSTGRES_USER: prisma
POSTGRES_PASSWORD: prisma
volumes:
- postgres:/var/lib/postgresql/data
volumes:
postgres: ~
I builded two docker containers, one is prisma server, the other is postgres database.
As I thought after command prisma depoly
the Model User should create a users table in the database.
But I try to check the schema in the database and got the result:
docker exec -it myContainer psql -U prisma
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+------------+------------+-----------------------
postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
prisma | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
prisma=# \z // or postgres=# \z
Access privileges
Schema | Name | Type | Access privileges | Column privileges | Policies
--------+------+------+-------------------+-------------------+----------
(0 rows)
prisma=# \dt or postgres=# \dt
Did not find any relations.
Then I tried to check the volume folder in the VM machine
docker run -it --rm --privileged --pid=host justincormack/nsenter1
/var/lib/docker/volumes/first_prisma_postgres/_data # ls
PG_VERSION pg_commit_ts pg_ident.conf pg_notify pg_snapshots pg_subtrans pg_wal postgresql.conf
base pg_dynshmem pg_logical pg_replslot pg_stat pg_tblspc pg_xact postmaster.opts
global pg_hba.conf pg_multixact pg_serial pg_stat_tmp pg_twophase postgresql.auto.conf postmaster.pid
The data exactly exist at the VM machine, but how can I checked the data or made dump backup from it?
Solution 1:[1]
Once if you are connected to postgres in your container, you can execute normal queries.
Example:
\l
to display all the schema
\dt
to display all tables.
maybe connecting to database is the one you are missing.
Run - \c schema_name
to connect to db
Once you are connected, you can execute any normal queries.
Solution 2:[2]
To check all volumes you can run:
docker volume ls
To check one of them:
docker volume inspect postgres_db
, where postgres_db is a name of your volume
As a result you may see something like this:
[
{
"CreatedAt": "2022-05-05T14:24:04Z",
"Driver": "local",
"Labels": {
"com.docker.compose.project": "s-deployment",
"com.docker.compose.version": "2.4.1",
"com.docker.compose.volume": "postgres_db"
},
"Mountpoint": "/var/lib/docker/volumes/s-deployment_postgres_db/_data",
"Name": "s-deployment_postgres_db",
"Options": null,
"Scope": "local"
}
]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | karikevinod |
Solution 2 | Kolya Terletskyi |