如果我在/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
我在这里做错了什么?
答案 0 :(得分:1)
作为the documentation状态,local
仅适用于UNIX套接字连接,而您正在建立与localhost
的TCP连接。
使用这样的一行:
host all myuser 127.0.0.1/32 trust
使用IPv4信任来自localhost
的所有连接(使用地址::1/128
进行IPv6)。