如果我在 /etc/postgresql/9.4/main/pg_hba.conf 中有一条记录特别信任我的特定用户
# TYPE DATABASE USER ADDRESS METHOD
local all myuser trust
因为我在 debian 上,所以我像这样重新启动 postgresql
sudo /etc/init.d/postgresql restart
这是我对此进行测试的整个源文件:
const pg = require('pg');
const connectionString = "postgres://myuser:mypassword@localhost/mydbname";
const client = new pg.Client(connectionString);
client.connect();
const query = client.query('SELECT * FROM USERS');
query.on('end', () => { client.end(); });
这是我一直收到的错误:
error: password authentication failed for user "myuser"
at Connection.parseE (/home/myuser/webserver/node_modules/pg/lib/connection.js:539:11)
at Connection.parseMessage (/home/myuser/webserver/node_modules/pg/lib/connection.js:366:17)
at Socket.<anonymous> (/home/myuser/webserver/node_modules/pg/lib/connection.js:105:22)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:551:20)
还值得注意的是,执行以下工作:
psql -h localhost -U myuser mydb
我在这里做错了什么?
As 文档 https://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html状态,local
仅适用于 UNIX 套接字连接,当您正在建立 TCP 连接时localhost
.
使用这样的行:
host all myuser 127.0.0.1/32 trust
信任来自的所有连接localhost
使用 IPv4(使用地址::1/128
对于 IPv6)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)