无法从Google App Engine节点连接到Cloud sql中的Postgres [英] Unable to connect to postgres in cloud sql from google app engine nodes
问题描述
我正在开发一个nodejs和postgres应用程序.两者都部署在谷歌.我在Google Cloud SQL中使用了postgres,并且在Google App Engine中部署了Node.js.我正在尝试从nodejs连接到postgres,但是它抛出它无法连接到云postgres.我已经更新了app.yml文件,并且我使用的是常规pg客户端,而不是knex.谁能帮我.我的配置如下
I am working on a nodejs and postgres application. Both are deployed in google. I have my postgres in google cloud sql and nodejs is deployed in google app engine. I am trying to connect to postgres from nodejs, but it throws it cannot connect to cloud postgres. I have updated app.yml file and i am using regular pg client and not knex. Can anyone help me. My config as below
const client = new Client({
user: 'postgres',
host:'xx.xx.xx.xx',
socketpath: '/cloudsql/proj-name:us-central1:app-name',
database: 'xxxxx',
password: 'xxxx',
port: 5432,
ssl: true,
});
client.connect();
我尝试了没有套接字路径和主机.什么都行不通.所有这些在我的本地机器上都可以正常工作,我已经将我的本地公共IP列入了白名单.任何帮助将不胜感激.
I tried without socket path and host. Nothing works. All this works fine from my local machine, i have whitelisted my local public ip.Any help would be much appreciated.
我得到错误
(node:16) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: connect ETIMEDOUT xx.xx.xx.xx:5432
推荐答案
更改为以下配置即可.
const client = new Client({
user: 'postgres',
host: '/cloudsql/proj-name:us-central1:app-name',
database: 'xxxxx',
password: 'xxxx',
port: 5432
});
client.connect();
这篇关于无法从Google App Engine节点连接到Cloud sql中的Postgres的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!