我已经在我的Ubuntu karma box上安装了PostgreSQL和pgAdminIII。
我能够成功地使用pgAdminIII(即连接/登录),但是当我尝试在命令行(使用psql)上使用相同的用户名/pwd登录到服务器时,我得到错误:
psql: FATAL: Ident authentication failed for user "postgres"
现在有人知道如何解决这个问题吗?
我已经在我的Ubuntu karma box上安装了PostgreSQL和pgAdminIII。
我能够成功地使用pgAdminIII(即连接/登录),但是当我尝试在命令行(使用psql)上使用相同的用户名/pwd登录到服务器时,我得到错误:
psql: FATAL: Ident authentication failed for user "postgres"
现在有人知道如何解决这个问题吗?
当前回答
以下步骤适用于在Ubuntu 12.04上重新安装postgres 9.1。(也适用于Ubuntu 14.04上的postgres 9.3.9)
默认情况下,postgres会创建一个名为'postgres'的用户。我们以她的身份登录,给她一个密码。
$ sudo -u postgres psql
\password
Enter password: ...
...
通过输入\q或ctrl+d退出psql。然后我们用postgres来联系。-h localhost部分很重要:它告诉psql客户端我们希望使用TCP连接(配置为使用密码身份验证)进行连接,而不是通过PEER连接(不关心密码)。
$ psql -U postgres -h localhost
其他回答
在pg_hba.conf中设置正确了吗?
参见https://ubuntu.com/server/docs/databases-postgresql如何做。
解决这个问题的一个方法是编辑pg_hba.conf
sudo vi /etc/postgresql/9.3/main/pg_hba.conf
暂时
# Database administrative login by Unix domain socket
local all postgres trust
至此,您就完成了。为了安全,那就去吧
sudo -u postgres psql template1
ALTER USER postgres with encrypted password 'your_password';
然后返回,将pg_hba.conf设置为
# Database administrative login by Unix domain socket
local all postgres md5
如果你在CentOS上使用它,你可能需要在做出上述解决方案后重新加载postgres:
systemctl restart postgresql-9.3.service
编辑/etc/postgresql/8.4/main/pg_hba.conf文件,并将ident或peer替换为md5或trust,这取决于您是否希望它在您自己的计算机上询问密码。 然后重新加载配置文件:
/etc/init.d/postgresql reload
我花了更多的时间来解决这个我愿意承认的错误。
我认为pg_hba.conf中的身份验证配置顺序与您的情况相关。默认配置文件在普通安装中包含几行。这些默认值可以匹配身份验证尝试的条件,从而导致身份验证失败。不管在.conf文件末尾添加了什么额外的配置,它都会失败。
要检查使用的是哪一行配置,请确保查看消息的默认日志文件。你可能会看到这样的东西
LOG: could not connect to Ident server at address "127.0.0.1", port 113: Connection refused
FATAL: Ident authentication failed for user "acme"
DETAIL: Connection matched pg_hba.conf line 82: "host all all 127.0.0.1/32 ident"
结果是这条默认行导致了拒绝。
host all all 127.0.0.1/32 ident
试着把它注释掉。