【发布时间】:2021-06-04 17:24:34
【问题描述】:
我正处于使用 Postgres 在 Heroku 上设置开发应用程序的早期阶段。 NodeJS中问题代码的一个简单版本是:
const {Client} = require('pg');
const client = new Client({connectionString: 'postgres://{username}:{password}@{host}:5432/{dbname}'});
client.connect();
const result = client.query('SELECT now()');
client.end();
connectionString 是从 data.heroku.com 的凭据窗格中提供的字符串的副本,经过检查和重新检查。我可以:
- 使用来自多个不同本地应用程序(例如 DataGrip)的连接字符串进行连接
- 使用该代码(使用不同的连接字符串)连接到在 Docker 映像中运行的本地版本的 Postgres
我不能:
- 从本地计算机上的 Node 应用程序连接
- 从部署到 Heroku 的 Node 应用程序连接
当代码对远程数据库失败时,node-postgres 会抛出此错误:
{
"length": 168,
"name": "error",
"severity": "FATAL",
"code": "28000",
"file": "auth.c",
"line": "496",
"routine": "ClientAuthentication"
}
使用 Node v14.15.1,node-postgres ("pg") 8.5.1
更新: 可能还值得一提的是,我无法找到一种方法来从 Java 中获得与 fail 的这种连接……故障肯定在 Node node-postgres [基础 postgres 驱动程序] 中的某个地方 Heroku(即,数据库很好,连接也很好)……但是在哪里?
【问题讨论】:
标签: node.js postgresql heroku heroku-postgres node-postgres