我已经在我的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"
现在有人知道如何解决这个问题吗?
当前回答
我只需要简单地添加-h localhost位就可以工作了
其他回答
在以上所有的答案中,没有一个对我有用。我不得不手动更改数据库中的用户密码,它突然工作了。
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中的身份验证配置顺序与您的情况相关。默认配置文件在普通安装中包含几行。这些默认值可以匹配身份验证尝试的条件,从而导致身份验证失败。不管在.conf文件末尾添加了什么额外的配置,它都会失败。
要检查使用的是哪一行配置,请确保查看消息的默认日志文件。你可能会看到这样的东西
LOG: could not connect to Ident server at address "127.0.0.1", port 113: Connection refused
FATAL: Ident authentication failed for user "acme"
DETAIL: Connection matched pg_hba.conf line 82: "host all all 127.0.0.1/32 ident"
结果是这条默认行导致了拒绝。
host all all 127.0.0.1/32 ident
试着把它注释掉。
关于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
可以设置环境变量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:
在pg_hba.conf中设置正确了吗?
参见https://ubuntu.com/server/docs/databases-postgresql如何做。