Unable to connect to postgres in cloud sql from google app engine nodes

丶灬走出姿态 提交于 2021-01-29 12:31:58

问题


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();

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.

Error i get

(node:16) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: connect ETIMEDOUT xx.xx.xx.xx:5432

回答1:


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();


来源:https://stackoverflow.com/questions/49464092/unable-to-connect-to-postgres-in-cloud-sql-from-google-app-engine-nodes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!