Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django 如何在docker容器中执行psql interactive?_Django_Postgresql_Docker_Docker Compose_Psql - Fatal编程技术网

Django 如何在docker容器中执行psql interactive?

Django 如何在docker容器中执行psql interactive?,django,postgresql,docker,docker-compose,psql,Django,Postgresql,Docker,Docker Compose,Psql,我想在Postgres interactive shell中运行查询。为此,我使用docker容器,如下所示: 以下是docker compose的相关部分: db_of_ivms: image: postgres:10 restart: unless-stopped ports: - 5432:5432 container_name: db_of_ivms environment: POSTGRES_PASSWORD: xxx

我想在Postgres interactive shell中运行查询。为此,我使用docker容器,如下所示:

以下是docker compose的相关部分:

  db_of_ivms:
    image: postgres:10
    restart: unless-stopped
    ports:
     - 5432:5432
    container_name: db_of_ivms
    environment:
      POSTGRES_PASSWORD: xxx
      POSTGRES_USER: ivms_usr
      POSTGRES_DB: ivms_db
然而,我正在处理这个错误:

docker exec-it-u 0 db_of_ivms bash


您需要与postgres用户一起使用shell

docker exec -it -u postgres db_of_ivms bash
现在,对于未指定POSTGRES\u用户:ivms\u usr的容器:

如果指定POSTGRES_USER:ivms_usr和Database note psql命令参数:

docker exec -it -u postgres db_of_ivms bash
postgres@2cec2435bb83:/$ 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)

您需要与postgres用户一起使用shell

docker exec -it -u postgres db_of_ivms bash
现在,对于未指定POSTGRES\u用户:ivms\u usr的容器:

如果指定POSTGRES_USER:ivms_usr和Database note psql命令参数:

docker exec -it -u postgres db_of_ivms bash
postgres@2cec2435bb83:/$ 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)
我通过Django shell找到了另一种方法:

$python manage.py shell

从django.db导入连接 cursor=connection.cursor 来自django_迁移的cursor.executeElete,其中app='settings' 我通过Django shell找到了另一种方法:

$python manage.py shell

从django.db导入连接 cursor=connection.cursor 来自django_迁移的cursor.executeElete,其中app='settings'
例如,我使用以下步骤获取转储:

docker exec -it -u 0 <container-name> bash

例如,我使用以下步骤获取转储:

docker exec -it -u 0 <container-name> bash

谢谢你的回复。但是,问题仍然存在:/$psql:psql:FATAL:role postgres不存在您是否可以尝试docker exec-it-u ivms_usr db_of_ivms bash无法找到用户ivms_usr:passwd文件中没有匹配的条目感谢您的响应。但是,问题仍然存在:/$psql:psql:FATAL:role postgres不存在能否请尝试docker exec-it-u ivms_usr db_of_ivms bash找不到用户ivms_usr:passwd文件中没有匹配的条目