2016-02-07 65 views
54

我无法连接到我自己的本地服务器上的postgres数据库。 我GOOGLE了一些类似的问题,本手册 https://help.ubuntu.com/stable/serverguide/postgresql.htmlPostgreSQL:角色不允许登录

所以想出了:

pg_hba.conf说:

# TYPE DATABASE  USER   ADDRESS     METHOD 

# "local" is for Unix domain socket connections only 
local all    all          trust 
# IPv4 local connections: 
host all    all    127.0.0.1/32   md5 
# IPv6 local connections: 
host all    all    ::1/128     trust 

然后我创建了一个用户并分配给它一个密码:

postgres=# create role asunotest; 
CREATE ROLE 
postgres=# alter role asunotest with encrypted password '1234'; 
ALTER ROLE 

但它不让我在:

-bash-4.2$ psql -h 127.0.0.1 -U asunotest 
Password for user asunotest: 1234 
psql: FATAL: role "asunotest" is not permitted to log in 

可能是什么问题?

回答

99

您创建的角色不允许登录。阅读文档http://www.postgresql.org/docs/9.0/static/sql-alterrole.html

ALTER ROLE "asunotest" WITH LOGIN; 
+1

正如我不能'psql',我怎么能ALTER作用? –

+1

@ RomulusUrakagiTs'ai你应该输入一个postgres用户(sudo -u postgres psql postgres) –