在Node.js中连接到Heroku Postgres数据库时出错 [英] Error connecting to heroku postgres db in nodejs

查看:103
本文介绍了在Node.js中连接到Heroku Postgres数据库时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

It seems after my database was upgraded to 10.2 I'm unable to connect.

我正在使用pg 7.4.2 npm软件包。

I'm using the pg 7.4.2 npm package.

要清楚地说明,我已经连续6个月使用相同的连接字符串(没有附加?ssl = true)连接了。

To be clear, I have been connecting without issue for 6 months using the same connection string which had ?ssl=true appended to it.

我通过池或客户端连接出现此错误。

I get this error connecting via Pool or Client.

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变量没有问题。

I'm now hardcoding the full postgres connection string so there is no issue with env variables.

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

I've tried adding/removing ?ssl=true to the end of the connection string and adding/removing ssl:true from the constructor. I've also tried with and without promises. Same error no matter what on both local and deployed to heroku.

导入:

import { Pool, Client } from 'pg'

方法1

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

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

方法2:

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


推荐答案

v7.4.2中断了对SSL的支持。 这是未解决的问题

That's because v7.4.2 broke its SSL support. Here's the open issue.

您必须严格使用v7.4.1,直到问题解决。

You need to use strictly v7.4.1 till the issue is resolved.

更新

版本7.4.3解决了该问题。

Version 7.4.3 fixed the issue.

这篇关于在Node.js中连接到Heroku Postgres数据库时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆