【问题标题】:Unable to connect to postgres in cloud sql from google app engine nodes无法从谷歌应用引擎节点连接到云 sql 中的 postgres
【发布时间】:2018-09-02 23:34:37
【问题描述】:

我正在开发一个 nodejs 和 postgres 应用程序。两者都部署在谷歌中。我在谷歌云 sql 中有我的 postgres,并且 nodejs 部署在谷歌应用引擎中。我正在尝试从 nodejs 连接到 postgres,但它抛出它无法连接到云 postgres。我已经更新了 app.yml 文件,我使用的是常规的 pg 客户端而不是 knex。谁能帮我。我的配置如下

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 列入白名单。任何帮助将不胜感激。

我得到的错误

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

【问题讨论】:

  • Cloud SQL 实例和 App Engine 应用是否托管在不同的 GCP 项目上?如果是这样,您需要按照here 的说明授予对其他项目的 GAE 服务帐户的访问权限。无论如何,您还可以在该链接上找到更多说明,这些说明可能会有所帮助。
  • 没有两个都在同一个项目中。

标签: sql google-app-engine cloud google-cloud-sql


【解决方案1】:

更改为以下配置有效。

  const client = new Client({
      user: 'postgres',
      host: '/cloudsql/proj-name:us-central1:app-name',
      database: 'xxxxx',
      password: 'xxxx',
      port: 5432
    });

client.connect();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-19
    相关资源
    最近更新 更多