我已经在我的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"
现在有人知道如何解决这个问题吗?
当前回答
可以设置环境变量PGHOST=localhost:
$ psql -U db_user db_name
psql: FATAL: Peer authentication failed for user "db_user"
$ export PGHOST=localhost
$ psql -U db_user db_name
Password for user mfonline:
其他回答
在以上所有的答案中,没有一个对我有用。我不得不手动更改数据库中的用户密码,它突然工作了。
psql -U postgres -d postgres -c "alter user produser with password 'produser';"
我使用了以下设置:
pg_hba.conf
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 password
# IPv6 local connections:
host all all ::1/128 password
以下命令连接成功:
psql -U produser -d dbname -h localhost -W
我有类似的问题,我在pg_hba.conf中修复了它,当删除所有识别方法时,即使是IP6地址(尽管我在机器上只有IP4)。
host all all 127.0.0.1/32 password
host all all ::1/128 password
#for pgAdmin running at local network
host all all 192.168.0.0/24 md5
在我的情况下,解决方案是:(给关心的人) 登录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
可以设置环境变量PGHOST=localhost:
$ psql -U db_user db_name
psql: FATAL: Peer authentication failed for user "db_user"
$ export PGHOST=localhost
$ psql -U db_user db_name
Password for user mfonline: