我已经在我的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如何做。

其他回答

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

关于PostgreSQL安装的配置问题:

在下面提到的conf文件中配置# TYPE数据库用户地址方法部分

查找并编辑/var/lib/pgsql/10/data/pg_hba.conf或根据您的文件位置更新方法(md5)。如果你的配置中不存在,更新文件中的条目,如下所示:

# TYPE  DATABASE        USER            ADDRESS                 METHOD
# "local" is for Unix domain socket connections only
local   all             all                                     trust
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
host    all             all             0.0.0.0/0            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5

在下面提到的conf文件中配置连接和验证部分

查找并编辑/var/lib/pgsql/10/data/postgresql.conf或根据您的文件位置 更新监听地址和端口

listen_addresses = '*' // # what IP address(es) to listen on;
                                    # comma-separated list of addresses;
                                    # defaults to 'localhost'; use '*' for all
port = 5432 // Set port as 5432

重新启动PostgreSQL:

sudo systemctl restart postgresql-10 # Update service name based on your installation

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

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

问候

我发现我必须安装一个身份服务器,在113端口上监听。

sudo apt-get install pidentd
sudo service postgresql restart

然后身份就起作用了。

如果你在CentOS上使用它,你可能需要在做出上述解决方案后重新加载postgres:

systemctl restart postgresql-9.3.service