我已经在我的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"
现在有人知道如何解决这个问题吗?
当前回答
在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
以防以上方法都不适合你: 我已经安装了不少Postgres,但今天在RedHat 6.5系统上(安装Postgres 9.3)却被搞糊涂了。Aron在上面展示的典型hba.conf配置不起作用。原来我的系统使用的是IPV6,而忽略了IPV4配置。添加一行:
host all all ::1/128 password
允许我成功登录。
如果你做了所有这些,它仍然不工作,检查该用户的到期:
Postgres密码认证失败
在我的情况下,解决方案是:(给关心的人) 登录postgres:
sudo -i -u postgres
psql
ALTER USER postgres WITH PASSWORD 'postgres'; # type your password here
问候
以下步骤适用于在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