简体   繁体   English

无法从Google App Engine节点连接到Cloud sql中的Postgres

[英]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.

相关问题 Google App Engine:如何使用Zend DB连接到Cloud SQL - Google App Engine: How to connect to Cloud SQL with Zend DB 我可以从App Engine中托管的PHP应用程序连接Google Cloud SQL吗? - Can I connect Google Cloud SQL from PHP application Hosted in App Engine? Google App Engine PHP和Cloud SQL - Google App Engine PHP and Cloud SQL 如何在 App Engine 中使用 Python3 连接到 Google Cloud Platform 中的 SQL 实例 - How to connect to SQL instance in Google Cloud Platform using Python3 in App Engine App Engine Java Servlet无法连接到Cloud SQL - App Engine Java Servlet does not connect to Cloud SQL 谷歌应用引擎中部署的应用程序拒绝了Google Cloud sql访问 - google cloud sql access denied for application deployed in google app engine Google App Engine Cloud SQL的SQL语法错误 - Error in SQL Syntax on Google App Engine Cloud SQL 如何将 SQL server beta (Google Cloud) 连接到 Google API 引擎 (Node.js) - How to connect SQL server beta (Google Cloud) to Google API engine (Node.js) NodeJS应用程序(Express)中的Google Cloud SQL连接-->错误:连接ENOENT - Google Cloud SQL connection in NodeJS app (Express) --> Error: connect ENOENT 将本地 postgres 数据库连接到 Google Cloud - Connect local postgres database to Google Cloud
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM