连接到 PostgreSQL:Postico 和 TablePlus DB GUI 无法连接,但 Docker 中的 `psql` 有效(致命:用户密码验证失败)
Connecting to PostgreSQL: Postico and TablePlus DB GUIs can't connect but `psql` in Docker works (FATAL: password authentication failed for user)
我已经使用 Docker 在本地部署了我的 PostgreSQL 数据库。这是我的 Docker 撰写文件:
version: '3'
services:
prisma:
image: prismagraphql/prisma:1.30-alpha
restart: always
ports:
- "4466:4466"
environment:
PRISMA_CONFIG: |
port: 4466
# uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
# managementApiSecret: my-secret
prototype: true
databases:
default:
connector: postgres
host: postgres
user: prisma
password: prisma
port: 5432
postgres:
image: postgres
restart: always
environment:
POSTGRES_USER: prisma
POSTGRES_PASSWORD: prisma
volumes:
- postgres:/var/lib/postgresql/data
volumes:
postgres:
我是从 docker-compose up -d
开始的。
Docker 个容器是 运行:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
26b14120f89f prismagraphql/prisma:1.30-alpha "/bin/sh -c /app/sta…" 17 minutes ago Up 17 minutes 0.0.0.0:4466->4466/tcp newdm1_prisma_1
05dfdaeaf609 postgres "docker-entrypoint.s…" 17 minutes ago Up 17 minutes 5432/tcp newdm1_postgres_1
现在,出于某种原因我无法使用数据库 GUI 进行连接(尝试过 Postico 和 TablePlus)。在两个客户端中,我都收到以下错误:
FATAL: password authentication failed for user "prisma"
我 100% 确定我提供 prisma
作为 Docker 撰写文件中指定的密码。
此外,当我使用 psql
从 postgres
Docker 容器内部连接到数据库时,它确实有效:
docker exec -it 05dfdaeaf609 bash
然后在 Docker 容器中我这样做:
root@05dfdaeaf609:/# psql -U prisma -W prisma
Password:
psql (11.1 (Debian 11.1-1.pgdg90+1))
Type "help" for help.
prisma=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+--------+----------+------------+------------+-------------------
postgres | prisma | UTF8 | en_US.utf8 | en_US.utf8 |
prisma | prisma | UTF8 | en_US.utf8 | en_US.utf8 |
template0 | prisma | UTF8 | en_US.utf8 | en_US.utf8 | =c/prisma +
| | | | | prisma=CTc/prisma
template1 | prisma | UTF8 | en_US.utf8 | en_US.utf8 | =c/prisma +
| | | | | prisma=CTc/prisma
(4 rows)
prisma=# \c prisma
Password for user prisma:
You are now connected to database "prisma" as user "prisma".
我在 psql
中提供的密码是 prisma
,类似于我在 Postico 和 TablePlus 中提供的密码。
连接到 Docker 容器中的 PostgreSQL 数据库时,我需要做什么特别的事情吗?
PORTS
0.0.0.0:4466->4466/tcp
5432/tcp
如果您检查 docker ps
命令的端口列,您会发现 Postgres 端口未公开供主机使用。
要解决此问题,您需要将以下内容添加到 docker-compose.yml
文件中:
ports:
- "5432:5432"
使完整文件看起来像这样:
version: '3'
services:
prisma:
image: prismagraphql/prisma:1.30-alpha
restart: always
ports:
- "4466:4466"
environment:
PRISMA_CONFIG: |
port: 4466
# uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
# managementApiSecret: my-secret
prototype: true
databases:
default:
connector: postgres
host: postgres
user: prisma
password: prisma
port: 5432
postgres:
image: postgres
restart: always
ports:
- "5432:5432"
environment:
POSTGRES_USER: prisma
POSTGRES_PASSWORD: prisma
volumes:
- postgres:/var/lib/postgresql/data
volumes:
postgres:
然后您需要 运行 docker-compose up -d
应用新的更改。如果设置正确,docker ps
的 PORTS
列应该如下所示
PORTS
0.0.0.0:4466->4466/tcp
0.0.0.0:5432->5432/tcp
我已经使用 Docker 在本地部署了我的 PostgreSQL 数据库。这是我的 Docker 撰写文件:
version: '3'
services:
prisma:
image: prismagraphql/prisma:1.30-alpha
restart: always
ports:
- "4466:4466"
environment:
PRISMA_CONFIG: |
port: 4466
# uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
# managementApiSecret: my-secret
prototype: true
databases:
default:
connector: postgres
host: postgres
user: prisma
password: prisma
port: 5432
postgres:
image: postgres
restart: always
environment:
POSTGRES_USER: prisma
POSTGRES_PASSWORD: prisma
volumes:
- postgres:/var/lib/postgresql/data
volumes:
postgres:
我是从 docker-compose up -d
开始的。
Docker 个容器是 运行:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
26b14120f89f prismagraphql/prisma:1.30-alpha "/bin/sh -c /app/sta…" 17 minutes ago Up 17 minutes 0.0.0.0:4466->4466/tcp newdm1_prisma_1
05dfdaeaf609 postgres "docker-entrypoint.s…" 17 minutes ago Up 17 minutes 5432/tcp newdm1_postgres_1
现在,出于某种原因我无法使用数据库 GUI 进行连接(尝试过 Postico 和 TablePlus)。在两个客户端中,我都收到以下错误:
FATAL: password authentication failed for user "prisma"
我 100% 确定我提供 prisma
作为 Docker 撰写文件中指定的密码。
此外,当我使用 psql
从 postgres
Docker 容器内部连接到数据库时,它确实有效:
docker exec -it 05dfdaeaf609 bash
然后在 Docker 容器中我这样做:
root@05dfdaeaf609:/# psql -U prisma -W prisma
Password:
psql (11.1 (Debian 11.1-1.pgdg90+1))
Type "help" for help.
prisma=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+--------+----------+------------+------------+-------------------
postgres | prisma | UTF8 | en_US.utf8 | en_US.utf8 |
prisma | prisma | UTF8 | en_US.utf8 | en_US.utf8 |
template0 | prisma | UTF8 | en_US.utf8 | en_US.utf8 | =c/prisma +
| | | | | prisma=CTc/prisma
template1 | prisma | UTF8 | en_US.utf8 | en_US.utf8 | =c/prisma +
| | | | | prisma=CTc/prisma
(4 rows)
prisma=# \c prisma
Password for user prisma:
You are now connected to database "prisma" as user "prisma".
我在 psql
中提供的密码是 prisma
,类似于我在 Postico 和 TablePlus 中提供的密码。
连接到 Docker 容器中的 PostgreSQL 数据库时,我需要做什么特别的事情吗?
PORTS
0.0.0.0:4466->4466/tcp
5432/tcp
如果您检查 docker ps
命令的端口列,您会发现 Postgres 端口未公开供主机使用。
要解决此问题,您需要将以下内容添加到 docker-compose.yml
文件中:
ports:
- "5432:5432"
使完整文件看起来像这样:
version: '3'
services:
prisma:
image: prismagraphql/prisma:1.30-alpha
restart: always
ports:
- "4466:4466"
environment:
PRISMA_CONFIG: |
port: 4466
# uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
# managementApiSecret: my-secret
prototype: true
databases:
default:
connector: postgres
host: postgres
user: prisma
password: prisma
port: 5432
postgres:
image: postgres
restart: always
ports:
- "5432:5432"
environment:
POSTGRES_USER: prisma
POSTGRES_PASSWORD: prisma
volumes:
- postgres:/var/lib/postgresql/data
volumes:
postgres:
然后您需要 运行 docker-compose up -d
应用新的更改。如果设置正确,docker ps
的 PORTS
列应该如下所示
PORTS
0.0.0.0:4466->4466/tcp
0.0.0.0:5432->5432/tcp