PostgreSQL
 sql >> Datenbank >  >> RDS >> PostgreSQL

Wie führe ich psql interactive in seinem Docker-Container aus?

Sie müssen sich mit dem postgres-Benutzer einloggen

docker exec -it -u postgres db_of_ivms bash

Jetzt für Container, die Sie nicht angeben POSTGRES_USER: ivms_usr :

[email protected]:/$ psql
postgres=# \l
                                 List of databases
   Name    |  Owner   | Encoding |  Collate   |   Ctype    |   Access privileges   
-----------+----------+----------+------------+------------+-----------------------
 postgres  | 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
(3 rows)

Wenn Sie POSTGRES_USER: ivms_usr angeben und Datenbank (beachten Sie die psql-Befehlsargumente):

docker exec -it -u postgres db_of_ivms bash
[email protected]:/$ psql -U ivms_usr -d ivms_db
psql (10.12 (Debian 10.12-1.pgdg90+1))
Type "help" for help.

ivms_db=# \l
                                 List of databases
   Name    |  Owner   | Encoding |  Collate   |   Ctype    |   Access privileges   
-----------+----------+----------+------------+------------+-----------------------
 ivms_db   | ivms_usr | UTF8     | en_US.utf8 | en_US.utf8 | 
 postgres  | ivms_usr | UTF8     | en_US.utf8 | en_US.utf8 | 
 template0 | ivms_usr | UTF8     | en_US.utf8 | en_US.utf8 | =c/ivms_usr          +
           |          |          |            |            | ivms_usr=CTc/ivms_usr
 template1 | ivms_usr | UTF8     | en_US.utf8 | en_US.utf8 | =c/ivms_usr          +
           |          |          |            |            | ivms_usr=CTc/ivms_usr
(4 rows)