PostgreSQL:不允许角色登录

kur*_*tgn 109 postgresql

我无法在本地服务器上连接到我自己的postgres数据库.我搜索了一些类似的问题并提出了这本手册 https://help.ubuntu.com/stable/serverguide/postgresql.html

所以:

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
Run Code Online (Sandbox Code Playgroud)

然后我创建一个用户并为其分配密码:

postgres=# create role asunotest;
CREATE ROLE
postgres=# alter role asunotest with encrypted password '1234';
ALTER ROLE
Run Code Online (Sandbox Code Playgroud)

但它不允许我进入:

-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
Run Code Online (Sandbox Code Playgroud)

可能是什么问题呢?

cha*_*age 236

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

psql -U postgres
Run Code Online (Sandbox Code Playgroud)

  • 由于我无法使用“ psql”,我该如何更改角色? (2认同)
  • @ RomulusUrakagiTs'ai,您应该以postgres用户身份输入(sudo -u postgres psql postgres) (2认同)

小智 5

CREATE ROLE blog WITH
  LOGIN
  SUPERUSER
  INHERIT
  CREATEDB
  CREATEROLE
  REPLICATION;

COMMENT ON ROLE blog IS 'Test';
Run Code Online (Sandbox Code Playgroud)