英文:
ECONNREFUSED with Postgres, what is wrong with my addresses?
问题
I have a cloud server (ubuntu 18.04) with NodeJS, postgresql, sequelize. My server starts, but can't connect to DB, I get Error: connect ECONNREFUSED 192.168.0.2:5432.
If I run ss -tl [tcp] (https://i.stack.imgur.com/YQV6s.png) and here is the sequelize.js:
export default new Sequelize(
process.env.DB_NAME,
process.env.DB_USER,
process.env.DB_PASS,
{
dialect: 'postgres',
host: "127.0.0.1",
port: 5432,
define: {
underscored: true
},
logging: false,
timezone: 'Europe',
}
)
I am new to linux, sorry, got confused. I tried to switch host in sequelize to 192.168.0.2, the error is the same. How do I fix this?
英文:
I have a cloud server (ubuntu 18.04) with NodeJS, postgresql, sequelize. My server starts, but cant connect to DB, i get
Error: connect ECONNREFUSED 192.168.0.2:5432
If i run ss -tl
[tcp] (https://i.stack.imgur.com/YQV6s.png)
and here is the sequilize.js
export default new Sequelize(
process.env.DB_NAME,
process.env.DB_USER,
process.env.DB_PASS,
{
dialect: 'postgres',
host: "127.0.0.1",
port: 5432,
define: {
underscored: true
},
logging: false,
timezone: 'Europe',
}
)
I am new to linux, sorry, got confused. I tried to switch host in sequilize to 192.168.0.2, the error is the same. How do i fix this?
答案1
得分: 1
在这种情况下,尝试连接已知可以正常工作的工具是很重要的,以确保您的主机确实可以从该 IP 访问 porn,并且数据库服务器会响应并正常工作。
对于Postgres,有一个名为psql
的命令行工具可以使用:
psql -h 127.0.0.1 -p 5432 -U $DB_USER $DB_NAME
您可以使用任何其他可以连接到Postgres的CLI或GUI工具,但请确保它在与您的Node应用程序在同一主机上本地运行。
如果以这种方式无法连接,则您的Node应用程序也将无法连接。
正如评论中已经提到的,您的数据库可能不接受来自本地主机的连接。如果您确认是这种情况,请检查配置,特别是:listen_addresses
。
请参阅文档:
英文:
In cases like this it's always good to try to connect with some tool that is known to work to make sure that you can indeed reach that porn on that IP from your host, and that the database server responds and works.
For Postgres, there is a command line tool called psql
that you can use:
psql -h 127.0.0.1 -p 5432 -U $DB_USER $DB_NAME
You can use any other CLI or GUI tool that can connect to Postgres, but make sure that it is run locally on the same host as your Node app is running.
If you cannot connect in that way, then your Node app would not connect as well.
As freakish already noticed in the comments, your database may not accept connections from localhost. If you verify that this is the case, check the configuration, in particular: listen_addresses
See the documentation:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论