我已经在我的Ubuntu karma box上安装了PostgreSQL和pgAdminIII。

我能够成功地使用pgAdminIII(即连接/登录),但是当我尝试在命令行(使用psql)上使用相同的用户名/pwd登录到服务器时,我得到错误:

psql: FATAL:  Ident authentication failed for user "postgres"

现在有人知道如何解决这个问题吗?


当前回答

在以上所有的答案中,没有一个对我有用。我不得不手动更改数据库中的用户密码,它突然工作了。

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中设置正确了吗?

参见https://ubuntu.com/server/docs/databases-postgresql如何做。

对于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

编辑/etc/postgresql/8.4/main/pg_hba.conf文件,并将ident或peer替换为md5或trust,这取决于您是否希望它在您自己的计算机上询问密码。 然后重新加载配置文件:

/etc/init.d/postgresql reload

在我的情况下,解决方案是:(给关心的人) 登录postgres:

sudo -i -u postgres
psql
ALTER USER postgres WITH PASSWORD 'postgres'; # type your password here

问候

以防以上方法都不适合你: 我已经安装了不少Postgres,但今天在RedHat 6.5系统上(安装Postgres 9.3)却被搞糊涂了。Aron在上面展示的典型hba.conf配置不起作用。原来我的系统使用的是IPV6,而忽略了IPV4配置。添加一行:

host    all             all             ::1/128                 password

允许我成功登录。