无法从Firebase函数连接到Cloud Sql(postgres)

时间:2018-12-21 22:09:29

标签: firebase google-cloud-functions google-cloud-sql

我正在使用nodejs firebase函数。我使用sequlize连接到postgres数据库。

我尝试按照文档https://cloud.google.com/functions/docs/sql从firebase函数连接到数据库,但无法连接。我收到此错误。

Failed to prune sessions: connect ECONNREFUSED 127.0.0.1:5432

这是我使用的配置。

{ username: 'postgres',
    password: '*********',
    database: 'testdb',
    host: '/cloudsql/my-project:us-central1:db-instance',
    port: 5432,
    dialect: 'postgres',
    dialectOptions: { ssl: false }}

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我的坏。我也正在使用pg session,它正在使用连接字符串。我猜pg无法将主机与连接字符串区分开。

用pg pool对象替换连接字符串后,我就可以连接了。