我已经安装了PostgreSQL 8.4,Postgres客户端和Pgadmin3。控制台客户端和Pgadmin的用户“ postgres”的身份验证失败。 我已经输入了用户“ postgres”和密码“ postgres”,由于它之前能够工做。 可是如今身份验证失败。 我以前几回都没有出现此问题。 我该怎么办? 那会发生什么呢? sql
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"
工做人员的回答是正确的,可是若是您想进一步自动化,能够这样作: shell
$ sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"
数据库
作完了! 您保存了用户= postgres和密码= postgres。 ubuntu
若是您没有User postgres ubuntu的密码,请执行如下操做: centos
$ sudo passwd postgres
服务器
若是您尝试以postgres用户身份登陆postgres shell,则可使用如下命令。 ide
切换到postgres用户 post
# su - postgres
登陆到psql spa
# psql
但愿能有所帮助 rest
使人沮丧的是,以上大多数答案都是正确的,可是它们没有说起您必须从新启动数据库服务才能使pg_hba.conf文件中的更改生效。
所以,若是您如上所述进行更改:
local all postgres ident
而后以root身份从新启动 (在centos上相似service service postgresql-9.2 restart),如今您应该可以以用户postgres的身份访问数据库
$psql psql (9.2.4) Type "help" for help. postgres=#
但愿这能够为新的postgres用户添加信息
编辑pg_hba.conf文件,例如,使用sudo emacs /etc/postgresql/9.3/main/pg_hba.conf
将全部身份验证方法更改成trust
。 更改“ postgres”用户的Unix密码。 从新启动服务器。 使用psql -h localhost -U postgres
登陆,并使用刚刚设置的Unix密码。 若是可行,您能够将pg_hba.conf文件从新设置为默认值。
我只是想补充一点,您还应该检查密码是否已过时。
有关详细信息,请参见Postgres密码验证失败 。