首页 > 解决方案 > 无法连接到 Postgres 数据库 Postgres 需要连接到特定数据库,尝试了以下数据库:

问题描述

当我尝试连接我的 fabric-ca 以使用 postgres 作为数据库时出现此错误。

Using postgres database, connecting to database...
    2019/10/22 09:21:16 [DEBUG] Database Name: fabriccaserver
    2019/10/22 09:21:16 [DEBUG] Connecting to PostgreSQL server, using connection string: host=127.0.0.1 port=5432 user=**** password=**** dbname=fabriccaserver sslmode=disable
    2019/10/22 09:21:16 [WARNING] Failed to connect to database 'fabriccaserver'
    2019/10/22 09:21:16 [DEBUG] Connecting to PostgreSQL server, using connection string: host=127.0.0.1 port=5432 user=**** password=**** dbname=postgres sslmode=disable
    2019/10/22 09:21:16 [WARNING] Failed to connect to database 'postgres'
    2019/10/22 09:21:16 [DEBUG] Connecting to PostgreSQL server, using connection string: host=127.0.0.1 port=5432 user=**** password=**** dbname=template1 sslmode=disable
    2019/10/22 09:21:16 [WARNING] Failed to connect to database 'template1'
    2019/10/22 09:21:16 [ERROR] Error occurred initializing database: Failed to connect to Postgres database. Postgres requires connecting to a specific database, the following databases were tried: [fabriccaserver postgres template1]. Please create one of these database before continuing

标签: hyperledger-fabrichyperledgerhyperledger-fabric-ca

解决方案


我通过将 container_name 放在主机中解决了这个错误,即

db:
  db:
  type: postgres
  datasource: host=db-postgres port=5432 user=postgres password=caDbPass12345 dbname=fabriccaserver sslmode=disable  
  tls:
      enabled: false
      certfiles:
      client:
        certfile:
        keyfile:

以前,我输入 localhost 并尝试使用 127.0.0.1 之后我看到在我的 docker-compose.yaml 中我的 postgres 服务位于不同的网络下,而 ica.org1.example.com 位于不同的网络下,我已修复并且在杀死并删除所有 docker 进程后,必须执行 docker network prune。


推荐阅读