【问题标题】:Error connecting to heroku postgres db in nodejs在nodejs中连接到heroku postgres db时出错
【发布时间】:2018-10-16 15:25:18
【问题描述】:

我的数据库升级到 10.2 后似乎无法连接。

我正在使用 pg 7.4.2 npm 包。

需要说明的是,我已经使用附加了 ?ssl=true 的相同连接字符串进行了 6 个月的无问题连接。

我通过池或客户端连接时收到此错误。

AssertionError [ERR_ASSERTION]: false == true
    at Object.exports.connect (_tls_wrap.js:1099:3)
    at Socket.<anonymous> (/home/e/express/testpg/node_modules/pg/lib/connection.js:94:23)
    at Object.onceWrapper (events.js:219:13)
    at Socket.emit (events.js:127:13)
    at Socket.emit (domain.js:421:20)
    at addChunk (_stream_readable.js:269:12)
    at readableAddChunk (_stream_readable.js:256:11)
    at Socket.Readable.push (_stream_readable.js:213:10)
    at TCP.onread (net.js:598:20)

我现在正在对完整的 postgres 连接字符串进行硬编码,因此 env 变量没有问题。

我尝试在连接字符串的末尾添加/删除 ?ssl=true 并从构造函数中添加/删除 ssl:true。我也尝试过有无承诺。无论在本地还是部署到 heroku,都会出现相同的错误。

进口:

import { Pool, Client } from 'pg'

方法一:

let pool = new Pool({
  connectionString: csnew,
  ssl: true
})

pool.connect().then( client => {
  console.log('connected')
})
.catch(e=> {
  console.log(e)
})

方法二:

let pgclient = new Client({
  connectionString: csnew,
  ssl: true
})
pgclient.connect().then( () => {
  console.log('connected')
}).catch(e=> {
  console.log(e)
})

【问题讨论】:

    标签: node.js postgresql express heroku psql


    【解决方案1】:

    那是因为 v7.4.2 中断了它的 SSL 支持。 Here's the open issue.

    在问题解决之前,您需要严格使用 v7.4.1。

    更新

    版本 7.4.3 修复了该问题。

    【讨论】:

    • 感谢@vitaly-t,降级到 7.4.1 对我们有用
    • @647er 也许您必须在 package.json 中的目标版本之前删除 ^
    • @647er 您要么将其包含为“^7.0.0”,要么没有正确重新安装。该问题在 v7.4.2 之前不存在
    猜你喜欢
    • 1970-01-01
    • 2016-08-14
    • 2013-11-16
    • 1970-01-01
    • 2018-04-25
    • 2019-11-08
    • 2019-06-06
    • 1970-01-01
    • 2016-10-26
    相关资源
    最近更新 更多