2016-01-14 24 views
0

我刚刚在EC2 AMI实例上安装了PostgreSQL 9.2服务器。但是,我无法从命令提示符连接到它。无法连接到ec2上的postgres

此外我看到/var/lib中的两个目录:pgsql9pgsql92。 pgsql92中的数据目录是空的,因此它看起来像pgsql9是正在使用的那个。

[[email protected] etc]# psql 
Password: 
psql: FATAL: password authentication failed for user "root" 
[[email protected] etc]# sudo su - postgres 
-bash-4.2$ psql 
Password: 
psql: FATAL: password authentication failed for user "postgres" 
-bash-4.2$ psql -U postgres 
Password for user postgres: 
psql: FATAL: password authentication failed for user "postgres" 
-bash-4.2$ 

的pg_hba.conf

# "local" is for Unix domain socket connections only 
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     ident 
# Allow replication connections from localhost, by a user with the 
# replication privilege. 
#local replication  postgres        peer 
#host replication  postgres  127.0.0.1/32   ident 
#host replication  postgres  ::1/128     ident 

的postgresql.conf

listen_addresses = '*' 
+1

可能重复[Postgresql:密码认证失败的用户“postgres”](http://stackoverflow.com/questions/7695962/postgresql-password-authentication-failed-for-user-postgres) –

+0

试图从解决方案链接,但仍然得到相同的错误 – user2325154

回答

1

摸出其中PG安装使用的是:ps -ef | grep pgsql。您将会确定使用哪个二进制,数据目录和配置文件来为您提供一些安慰。

你是否将默认的pg_hba.conf更改了?如果是这样,你重新加载它吗?像sudo service postgresql reload应该这样做,这取决于您的操作系统。

您可能还想将IPv6本地连接更改为使用md5

尝试将-h localhost-h 127.0.0.1添加到您的psql命令中。 psql -h localhost -U postgres

检查postgres密码是/三重肯定。

否则,请查看您的操作系统安装的具体文档。有时aptyum回购为您做了一些额外的安全配置。

最后,最坏的情况下,所有的pg_hba.conf AUTH方法更改为trust,然后重新启动数据库,登录,修改密码postgres,注销,改变身份验证的方法来md5,重新装入,然后再次尝试登录。