在Render上部署Golang应用程序时出现连接拒绝错误

eqqqjvef  于 2023-08-01  发布在  Go
关注(0)|答案(1)|浏览(165)

我在尝试在Render上部署Golang应用程序时遇到了一个问题。应用程序初始化数据库连接失败,并返回“连接拒绝”错误。我已经按照Render提供的部署步骤进行了操作,但无法建立到数据库的连接。
下面是我从渲染日志中得到的错误

Jul 10 02:56:40 AM  [error] failed to initialize database, got error failed to connect to `host=127.0.0.1 user=postgres database=easytickets`: dial error (dial tcp 127.0.0.1:6500: connect: connection refused)
Jul 10 02:56:56 AM  ==> Using Node version 14.17.0 (default)
Jul 10 02:56:56 AM  ==> Docs on specifying a Node version: https://render.com/docs/node-version
Jul 10 02:57:00 AM  ==> Starting service with './main'
Jul 10 02:57:00 AM  
Jul 10 02:57:00 AM  2023/07/10 01:57:00 Failed To Connect To The Database
Jul 10 02:57:00 AM  2023/07/10 01:57:00 /opt/render/project/go/src/github.com/E-phraim/jeje-tickets/initializers/connectDB.go:1`

字符串
我在Render应用 Jmeter 板中设置了环境变量,如下所示:

POSTGRES_HOST=127.0.0.1
POSTGRES_USER=postgres
POSTGRES_PASSWORD=*******
POSTGRES_DB=easytickets
POSTGRES_PORT=6500

PORT=8000
CLIENT_ORIGIN=http://localhost:3000

EMAIL_FROM=******
SMTP_HOST=*******
SMTP_USER=*********
SMTP_PASS=*********
SMTP_PORT=587

ar5n3qh5

ar5n3qh51#

问题出在hostport上。因为你不能在这里提到127.0.0.1。你必须将其设置为host name

POSTGRES_HOST=db-host-name

字符串
同时将端口设置为5432

POSTGRES_PORT=5432


参见https://render.com/docs/databases#connecting-to-your-database

相关问题