我已经安装了PostgreSQL 8.4,Postgres客户端和Pgadmin 3。在控制台客户端和Pgadmin中,用户"postgres"的认证都失败。我把用户输入为"postgres",密码输入为"postgres",因为它以前是有效的。但现在认证失败了。我之前做了几次都没有这个问题。我应该怎么做?会发生什么?
psql -U postgres -h localhost -W
Password for user postgres:
psql: FATAL: password authentication failed for user "postgres"
FATAL: password authentication failed for user "postgres"
如果我没记错的话,Ubuntu上的postgres
用户默认没有设置DB密码。这意味着,你只能通过使用postgres
的OS用户账户登录到该账户。
假设你在盒子上有root
权限,你可以这样做。
sudo -u postgres psql
如果失败了,出现了 "数据库"postgres"不存在 "的错误,那么你很可能不是在Ubuntu或Debian服务器上 :-)在这种情况下,只需在命令中加入template1
即可。
sudo -u postgres psql template1
如果这些命令中的任何一个出现错误psql:FATAL: password authentication failed for user "postgres"
然后检查文件/etc/postgresql/8.4/main/pg_hba.conf
。必须有这样一行,作为第一个非注释行。
local all postgres ident
对于较新版本的PostgreSQL,ident
实际上可能是peer
。这也是可以的。
在psql
shell中,你可以给DB用户postgres
一个密码。
ALTER USER postgres PASSWORD 'newPassword';
你可以通过输入CtrlD命令离开psql
外壳,或者使用q
命令。
现在你应该可以给pgAdmin一个有效的数据库超级用户的密码,它也会很高兴的 :-)