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

时间:2019-01-05 00:46:22

标签: postgresql node-postgres

我目前正在rPi3B +(aarch64)上运行openSuse,并且碰到了运行NodeJS连接脚本的墙。

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

CREATE ROLE new_role LOGIN PASSWORD 'passwd';

然后是一个数据库

CREATE DATABASE new_db OWNER new_role;

\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()
})

这将返回一些我尚未正确捕获的{.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

因此,我非常确定尝试将其插入了预期的端口,否则我将不会在终端中收到详细的错误。错误代码= invalid_authorization_specification

我需要在服务器psql接口上完成满足授权规范的事情吗?

当我调查了那个特定的对象时,似乎找不到与我的情况相关的有用的搜索结果。

这里是postgres的新手,所以我确定这是我很想念的菜鸟错误,但是非常感谢您的帮助或投入!

1 个答案:

答案 0 :(得分:1)

在这里进行了更多的挖掘后找到了答案:error: Ident authentication failed for user

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

这很粗糙,因为除了告诉postgreSQL检查md5加密密码,而不是检查我的用户名是否与服务器上创建的角色匹配之外,我还不明白我所做的更改。

如果有人对发生的变化以及我为什么全神贯注地拥有正确的解释。