[英]Unable to connect to postgres in cloud sql from google app engine nodes
I am working on a nodejs and postgres application. 我正在开发一个nodejs和postgres应用程序。 Both are deployed in google. 两者都部署在谷歌。 I have my postgres in google cloud sql and nodejs is deployed in google app engine. 我在Google Cloud SQL中使用了postgres,并且在Google App Engine中部署了Node.js。 I am trying to connect to postgres from nodejs, but it throws it cannot connect to cloud postgres. 我正在尝试从nodejs连接到postgres,但是它抛出它无法连接到云postgres。 I have updated app.yml file and i am using regular pg client and not knex. 我已经更新了app.yml文件,并且我使用的是常规pg客户端,而不是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();
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. 所有这些在我的本地机器上都可以正常工作,我已经将我的本地公共IP列入了白名单。任何帮助将不胜感激。
Error i get 错误我得到
(node:16) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: connect ETIMEDOUT xx.xx.xx.xx:5432
Changing to below configuration worked. 更改为以下配置即可。
const client = new Client({
user: 'postgres',
host: '/cloudsql/proj-name:us-central1:app-name',
database: 'xxxxx',
password: 'xxxx',
port: 5432
});
client.connect();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.