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

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

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

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


当前回答

我有类似的问题,我在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

其他回答

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

我在Mac OSX的PostgreSQL 9.3上的解决方案是在bash shell中使用sudo进入数据文件夹,然后将必要的行追加到pg_hba.conf文件,以允许所有用户都是可信的,并能够登录。这就是我所做的:

# in bash_profile edit PGDATA environmental variable
open ~/.bash_profile

# append this line to bash_profile
export PGDATA="/Library/PostgreSQL/9.3/data"

# reload bash_profile
source ~/.bash_profile

# open pg_hba.conf in vim
sudo vi /Library/PostgreSQL/9.3/data/pg_hba.conf

# append these two lines to the end of the pg_hba.conf file
local   all   all                  trust
host    all   all   127.0.0.1/32   trust

# can now login as user in bash
psql -d <db_name> -U <user_name> -W

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

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

问候

对于fedora26和postgres9.6

首先,以root用户登录,然后通过以下命令进入psql

$ su postgres  

then

$ psql

在PSQL中查找hba_file ==>的位置意味着pg_hba.conf

postgres=# show hba_file ; 
 hba_file  
--------------------------------------   
 /etc/postgresql/9.6/main/pg_hba.conf  
(1 row)  

在pg_hba.conf文件中将用户访问权限更改为this

host all all 127.0.0.1/32 md5

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

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