代码之家  ›  专栏  ›  技术社区  ›  647er

在nodejs中连接heroku postgres db时出错

  •  4
  • 647er  · 技术社区  · 7 年前

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

    我正在使用pg 7.4.2 npm包。

    要明确的是,我已经使用相同的连接字符串连接了6个月,没有出现问题?ssl=附加到它的true。

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

    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连接字符串进行硬编码,因此环境变量没有问题。

    我试过添加/删除?ssl=true到连接字符串的结尾,并从构造函数中添加/删除ssl:true。我也尝试过有无承诺。无论在本地还是部署到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)
    })
    
    1 回复  |  直到 7 年前
        1
  •  4
  •   vitaly-t    7 年前

    那是因为v7。4.2破坏了其SSL支持。 Here's the open issue

    您需要严格使用v7。4.1直到问题解决为止。

    使现代化

    版本7.4.3修复了该问题。

    推荐文章