PostgreSQL:不允许角色登录


136

我无法连接到本地服务器上的自己的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

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

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

可能是什么问题呢?

Answers:


289

您创建的角色不允许登录。您必须授予角色登录权限。

一种方法是以postgres用户身份登录并更新角色:

psql -U postgres

登录后,键入:

ALTER ROLE "asunotest" WITH LOGIN;

这是文档 http://www.postgresql.org/docs/9.0/static/sql-alterrole.html


2
如我所不能psql,我该如何更改角色?
Romulus Urakagi Ts'ai

2
@ RomulusUrakagiTs'ai,您应该以postgres用户身份输入(sudo -u postgres psql postgres)
Mi Ka,

9
CREATE ROLE blog WITH
  LOGIN
  SUPERUSER
  INHERIT
  CREATEDB
  CREATEROLE
  REPLICATION;

COMMENT ON ROLE blog IS 'Test';

0

使用pgadmin4

  1. 在侧面菜单中选择角色
  2. 在仪表板中选择属性。
  3. 单击编辑,然后选择权限

现在,您可以启用或禁用登录名,角色和其他选项


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.