使用 node-postgress 连接到 PostgreSQL@localhost 时遇到困难(错误:28000)

Aus*_*oss 4 postgresql node-postgres

我目前正在 rPi3B+ (aarch64) 上运行 openSuse,并且在运行 NodeJS 连接脚本时遇到了困难。

我完成了 PostgreSQL 的标准安装(v10 是此版本的 openSuse 上提供的),然后创建了一个新角色

CREATE ROLE new_role LOGIN PASSWORD 'passwd';
Run Code Online (Sandbox Code Playgroud)

然后是一个数据库

CREATE DATABASE new_db OWNER new_role;
Run Code Online (Sandbox Code Playgroud)

&\l返回\du预期的输出表明角色和数据库均已使用正确的所有者成功创建。

因此,我然后快速创建了一个节点项目目录并从文档复制了测试脚本: https: //node-postgres.com/features/connecting

const { Pool, Client } = require('pg')
const connectionString = 'postgresql://new_role:passwd@localhost:5432/new_db'

const pool = new Pool({
  connectionString: connectionString,
})

pool.query('SELECT NOW()', (err, res) => {
  console.log(err, res)
  pool.end()
})

const client = new Client({
  connectionString: connectionString,
})
client.connect()

client.query('SELECT NOW()', (err, res) => {
  console.log(err, res)
  client.end()
})
Run Code Online (Sandbox Code Playgroud)

这会返回一些我尚未正确捕获(.cath())的违背承诺的错误,以及如下所示的错误代码 28000:

{ error: Ident authentication failed for user "new_role"
at Connection.parseE (/home/eru/postgresDB/node_modules/pg/lib/connection.js:554:11)
at Connection.parseMessage (/home/eru/postgresDB/node_modules/pg/lib/connection.js:379:19)
at Socket.<anonymous> (/home/eru/postgresDB/node_modules/pg/lib/connection.js:119:22)
at Socket.emit (events.js:182:13)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js:264:11)
at Socket.Readable.push (_stream_readable.js:219:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
  name: 'error',
  length: 99,
  severity: 'FATAL',
  code: '28000',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'auth.c',
  line: '328',
  routine: 'auth_failed' } undefined
Run Code Online (Sandbox Code Playgroud)

所以我很确定这次尝试已到达预期端口,否则我不会在终端中收到详细的错误。错误代码 =invalid_authorization_specification

我需要在服务器、psql界面上做一些事情来满足授权规范吗?

当我查看该特定搜索结果时,我似乎找不到与我的情况相关的有用搜索结果。

这里对 postgres 相当陌生,所以我确信这是一个相当菜鸟的错误,我错过了,但非常感谢任何帮助或输入!

Aus*_*oss 5

在此处进行更多挖掘后找到了答案:错误:用户身份验证失败

最终将我的 pg_hba.conf 从该ident方法编辑为md5

这是相当粗糙的,因为除了告诉 postgreSQL 检查 md5 加密密码而不是检查我的用户名是否与服务器上创建的角色匹配之外,我并不真正理解我更改了什么。

如果有人对更改的内容以及为什么我洗耳恭听有正确的解释。