PostgreSQL: 不允许角色登录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35254786/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:10:04  来源:igfitidea点击:

PostgreSQL: role is not permitted to log in

postgresql

提问by kurtgn

I have trouble connecting to my own postgres db on a local server. I googled some similar problems and came up with this manual https://help.ubuntu.com/stable/serverguide/postgresql.html

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

so:

所以:

pg_hba.confsays:

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

then I create a user and assign a password for it:

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

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

but it doesn't let me in:

但它不让我进去:

-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

what could be the problem?

可能是什么问题呢?

回答by chalitha geekiyanage

The role you have created is not allowed to log in. You have to give the role permission to log in.

您创建的角色是不允许登录的,您必须给该角色权限才能登录。

One way to do this is to log in as the postgresuser and update the role:

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

psql -U postgres

Once you are logged in, type:

登录后,输入:

ALTER ROLE "asunotest" WITH LOGIN;

Here's the documentation http://www.postgresql.org/docs/9.0/static/sql-alterrole.html

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

回答by Yuer_1008

CREATE ROLE blog WITH
  LOGIN
  SUPERUSER
  INHERIT
  CREATEDB
  CREATEROLE
  REPLICATION;

COMMENT ON ROLE blog IS 'Test';

回答by ???? ??????

try to run

试着跑

sudo su - postgres
psql
ALTER ROLE 'dbname'