我已经在我的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
我发现我必须安装一个身份服务器,在113端口上监听。
sudo apt-get install pidentd
sudo service postgresql restart
然后身份就起作用了。
对于Windows,如果您不想编辑pb_gba.conf,即保留MD5方法(默认),请在PGadmin的查询工具中运行此查询,创建一个新用户
CREATE USER admin WITH PASSWORD 'secret'
然后在CMD中
psql "dbname=Main_db host=127.0.0.1 user=admin password=secret port=5432
哪里dbname是你的db在postgresql
我只需要简单地添加-h localhost位就可以工作了
如果你在CentOS上使用它,你可能需要在做出上述解决方案后重新加载postgres:
systemctl restart postgresql-9.3.service