当我使用CLI连接到我的数据库时,一切正常。Postgresql:我可以连接命令行,但不能连接node-postgres
psql dbname postgres
psql问我密码我之前设置(与ALTER)和我连接。
在我的pg_hba.conf文件,我得到了下面一行:
local all postgres md5
但是,当我使用节点Postgres的尝试同样的事情,我总是得到一个错误:
could not connect to postgres { [error: Ident authentication failed for user "postgres"]
代码我使用的是基本的(假设我的密码是mypwd)
var pg = require('pg');
var conString = "postgres://postgres:[email protected]/database";
var client = new pg.Client(conString);
client.connect(function(err) {
if(err) {
return console.error('could not connect to postgres', err);
}
client.query('SELECT NOW() AS "theTime"', function(err, result) {
if(err) {
return console.error('error running query', err);
}
console.log(result.rows[0].theTime);
//output: Tue Jan 15 2013 19:12:47 GMT-600 (CST)
client.end();
});
});
你有什么想法吗?
[编辑:我的完整的pg_hba.conf]
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all postgres md5
# IPv4 local connections:
host all all 127.0.0.1/32 ident
# IPv6 local connections:
host all all ::1/128 ident
这很奇怪,但您的nodejs代码尝试使用ident aut-method连接到数据库,而不是md5。你可以添加完整的pg_hba.conf到你的文章? –