You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

本地Ubuntu环境Docker部署Chainlink节点无法连接PostgreSQL数据库求助

问题:本地Ubuntu运行Chainlink节点无法连接PostgreSQL数据库

已执行操作

  • 安装PostgreSQL
    执行命令:
    sudo apt install postgresql
    
  • 调整防火墙规则
    执行命令:
    sudo ufw allow from any to any port 5432 proto tcp
    
  • 修改PostgreSQL配置
    编辑postgresql.conf文件:
    sudo gedit /etc/postgresql/12/main/postgresql.conf
    
    修改配置项:
    listen_addresses = '*'
    
    编辑pg_hba.conf文件:
    sudo gedit /etc/postgresql/14/main/pg_hba.conf
    
    修改配置项:
    host all all 172.17.0.0/16     md5
    
  • 已创建对应的PostgreSQL用户和数据库,截图如下:
    postgresql数据库和用户列表
  • .env配置文件内容如下:
    ROOT=/chainlink
    LOG_LEVEL=debug
    ETH_CHAIN_ID=42
    MIN_OUTGOING_CONFIRMATIONS=2
    LINK_CONTRACT_ADDRESS=0xa36085F69e2889c224210F603D836748e7dC0088
    CHAINLINK_TLS_PORT=0
    SECURE_COOKIES=false
    GAS_UPDATER_ENABLED=true
    ALLOW_ORIGINS=*
    ETH_URL=wss://kovan.infura.io/ws/v3/f0d1d3d2fbb649e29922ec37d4ff0b45
    DATABASE_URL=postgresql://chainlink:password#123@127.0.0.1:5432/chainlink?ssl=disable
    DATABASE_TIMEOUT=0
    
  • 启动Chainlink节点命令:
    cd ~/.chainlink-kovan && docker run -p 6688:6688 --name chainlink-node --add-host=host:127.0.0.1 -v ~/.chainlink-kovan:/chainlink -it --env-file=.env smartcontract/chainlink:0.10.14 local n
    

报错信息

启动后节点无法连接PostgreSQL数据库,报错日志如下:

{"level":"warn","ts":1634243680.5286717,"caller":"logger/default.go:134","msg":"GAS_UPDATER_ENABLED has been deprecated, to enable the block history estimator, please use GAS_ESTIMATOR_MODE=BlockHistory instead"}
2021-10-14T20:34:40Z [INFO]  Starting Chainlink Node 0.10.14 at commit 8160d7726d778b5c425e4b56af30b76cbc6d222d cmd/local_client.go:63  InstanceUUID=c6169db0-8d75-4902-becc-643bb0672861 SHA=8160d7726d778b5c425e4b56af30b76cbc6d222d Version=0.10.14 id=boot 
2021-10-14T20:34:40Z [ERROR] invalid database url %spostgresql://chainlink:Kashif#143@127.0.0.1:5939/chainlink?ssl=disable config/config.go:372    stacktrace=github.com/smartcontractkit/chainlink/core/store/config.Config.DatabaseURL
    /chainlink/core/store/config/config.go:372
github.com/smartcontractkit/chainlink/core/cmd.ChainlinkAppFactory.NewApplication
    /chainlink/core/cmd/client.go:86
github.com/smartcontractkit/chainlink/core/cmd.(*Client).RunNode
    /chainlink/core/cmd/local_client.go:76
github.com/urfave/cli.HandleAction
    /go/pkg/mod/github.com/urfave/cli@v1.22.5/app.go:524
github.com/urfave/cli.Command.Run
    /go/pkg/mod/github.com/urfave/cli@v1.22.5/command.go:173
github.com/urfave/cli.(*App).RunAsSubcommand
    /go/pkg/mod/github.com/urfave/cli@v1.22.5/app.go:405
github.com/urfave/cli.Command.startApp
    /go/pkg/mod/github.com/urfave/cli@v1.22.5/command.go:372
github.com/urfave/cli.Command.Run
    /go/pkg/mod/github.com/urfave/cli@v1.22.5/command.go:102
github.com/urfave/cli.(*App).Run
    /go/pkg/mod/github.com/urfave/cli@v1.22.5/app.go:277
main.Run
    /chainlink/core/main.go:20
main.main
    /chainlink/core/main.go:14
runtime.main
    /usr/local/go/src/runtime/proc.go:225 
2021-10-14T20:34:40Z [ERROR] invalid database url %spostgresql://chainlink:Kashif#143@127.0.0.1:5939/chainlink?ssl=disable config/config.go:372    stacktrace=github.com/smartcontractkit/chainlink/core/store/config/config.go:372
github.com/smartcontractkit/chainlink/core/store.initializeORM
    /chainlink/core/store/store.go:167
github.com/smartcontractkit/chainlink/core/store.newStore
    /chainlink/core/store/store.go:69
github.com/smartcontractkit/chainlink/core/store.NewStore
    /chainlink/core/store/store.go:47
github.com/smartcontractkit/chainlink/core/services/chainlink.NewApplication
    /chainlink/core/services/chainlink/application.go:152
github.com/smartcontractkit/chainlink/core/cmd.ChainlinkAppFactory.NewApplication
    /chainlink/core/cmd/client.go:87
github.com/smartcontractkit/chainlink/core/cmd.(*Client).RunNode
    /chainlink/core/cmd/local_client.go:76
github.com/urfave/cli.HandleAction
    /go/pkg/mod/github.com/urfave/cli@v1.22.5/app.go:524
github.com/urfave/cli.Command.Run
    /go/pkg/mod/github.com/urfave/cli@v1.22.5/command.go:173
github.com/urfave/cli.(*App).RunAsSubcommand
    /go/pkg/mod/github.com/urfave/cli@v1.22.5/app.go:405
github.com/urfave/cli.Command.startApp
    /go/pkg/mod/github.com/urfave/cli@v1.22.5/command.go:372
github.com/urfave/cli.Command.Run
    /go/pkg/mod/github.com/urfave/cli@v1.22.5/command.go:102
github.com/urfave/cli.(*App).Run
    /go/pkg/mod/github.com/urfave/cli@v1.22.5/app.go:277
main.Run
    /chainlink/core/main.go:20
main.main
    /chainlink/core/main.go:14
runtime.main
    /usr/local/go/src/runtime/proc.go:225 
2021-10-14T20:34:40Z [ERROR] failed to initialize database, got error failed to connect to `host=/tmp user=root database=`: dial error (dial unix /tmp/.s.PGSQL.5432: connect: no such file or directory) orm/orm.go:87           stacktrace=github.com/smartcontractkit/chainlink/core/store/orm.NewORM
    /chainlink/core/store/orm/orm.go:87
github.com/smartcontractkit/chainlink/core/store.initializeORM
    /chainlink/core/store/store.go:168
github.com/smartcontractkit/chainlink/core/store.newStore
    /chainlink/core/store/store.go:69
github.com/smartcontractkit/chainlink/core/store.NewStore
    /chainlink/core/store/store.go:47
github.com/smartcontractkit/chainlink/core/services/chainlink.NewApplication
    /chainlink/core/services/chainlink/application.go:152
github.com/smartcontractkit/chainlink/core/cmd.ChainlinkAppFactory.NewApplication
    /chainlink/core/cmd/client.go:87
github.com/smartcontractkit/chainlink/core/cmd.(*Client).RunNode
    /chainlink/core/cmd/local_client.go:76
github.com/urfave/cli.HandleAction
    /go/pkg/mod/github.com/urfave/cli@v1.22.5/app.go:524
github.com/urfave/cli.Command.Run
    /go/pkg/mod/github.com/urfave/cli@v1.22.5/command.go:173
github.com/urfave/cli.(*App).RunAsSubcommand
    /go/pkg/mod/github.com/urfave/cli@v1.22.5/app.go:405
github.com/urfave/cli.Command.startApp
    /go/pkg/mod/github.com/urfave/cli@v1.22.5/command.go:372
github.com/urfave/cli.Command.Run
    /go/pkg/mod/github.com/urfave/cli@v1.22.5/command.go:102
github.com/urfave/cli.(*App).Run
    /go/pkg/mod/github.com/urfave/cli@v1.22.5/app.go:277
main.Run
    /chainlink/core/main.go:20
main.main
    /chainlink/core/main.go:14
runtime.main
    /usr/local/go/src/runtime/proc.go:225 
creating application: failed to initialize ORM: initializeORM#NewORM: unable to init DB: unable to open ?application_name=Chainlink+0.10.14+%7C+ORM+%7C+c6169db0-8d75-4902-becc-643bb0672861 for gorm DB conn &{0 0xc000b46108 0 {0 0} [] map[] 0 0 0xc00045a5a0 false map[] map[] 0 0 0 0 <nil> 0 0 0 0 0x5970a0}: failed to connect to `host=/tmp user=root database=`: dial error (dial unix /tmp/.s.PGSQL.5432: connect: no such file or directory)
问题排查与修复方案

整理出4处核心错误,按以下步骤修复即可:

  1. 修正PostgreSQL配置版本不匹配问题
    你修改的postgresql.conf对应PostgreSQL 12版本,pg_hba.conf对应PostgreSQL 14版本,说明你机器上同时安装了两个版本的PostgreSQL,修改的配置不属于同一个运行实例。
    首先执行命令查看当前运行的PostgreSQL版本和监听端口:
    sudo ss -tulnp | grep postgres
    
    确认运行版本后,到对应版本的/etc/postgresql/[版本号]/main/路径下修改两个配置文件,修改完成后重启PostgreSQL服务:
    # 以14版本为例
    sudo systemctl restart postgresql@14-main.service
    
  2. 转义DATABASE_URL中的特殊字符
    你的数据库密码包含#符号,该符号在URL中属于特殊片段标识符,会导致URL解析中断,需要转义为%23,同时修改连接地址为Docker桥接网络下的宿主机地址172.17.0.1,修正后的DATABASE_URL如下:
    DATABASE_URL=postgresql://chainlink:password%23123@172.17.0.1:5432/chainlink?ssl=disable
    
    注意:如果前面查到PostgreSQL监听端口不是5432,替换为实际监听端口即可。
  3. 删除Docker启动命令中错误的host映射
    你启动命令中--add-host=host:127.0.0.1是错误配置,容器内的127.0.0.1指向容器本身,不会映射到宿主机,修正后的启动命令如下:
    cd ~/.chainlink-kovan && docker run -p 6688:6688 --name chainlink-node -v ~/.chainlink-kovan:/chainlink -it --env-file=.env smartcontract/chainlink:0.10.14 local n
    
  4. 可选:验证网络连通性
    可以先启动一个临时容器测试是否能连通宿主机的PostgreSQL服务,确认配置无误后再启动Chainlink节点:
    docker run --rm -it postgres psql "postgresql://chainlink:password%23123@172.17.0.1:5432/chainlink?ssl=disable"
    
    能正常进入数据库命令行则证明配置正确。

内容的提问来源于stack exchange,提问作者Kashif

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 10:48:04