Postgres:使用psql -U角色创建角色并登录

问题描述 投票:0回答:1

码:

postgres=# create role hello;
CREATE ROLE
postgres=# \du
                             List of roles
 Role name |                   Attributes                   | Member of
-----------+------------------------------------------------+-----------
 hello     | Cannot login                                   | {}
 postgres  | Superuser, Create role, Create DB, Replication | {}

postgres=# ALTER ROLE hello WITH LOGIN;
ALTER ROLE
postgres=# ALTER ROLE hello WITH CREATEDB;
ALTER ROLE
postgres=# \du
                             List of roles
 Role name |                   Attributes                   | Member of
-----------+------------------------------------------------+-----------
 hello     | Create DB                                      | {}
 postgres  | Superuser, Create role, Create DB, Replication | {}

postgres=# ALTER ROLE hello WITH PASSWORD '123';
ALTER ROLE
postgres=# \q
-bash-4.2$ logout
[root@host test_user]# psql -U hello
Password for user hello:
psql: FATAL:  database "hello" does not exist

我正在尝试使用hello在Postgres中创建一个名为CREATE ROLE的角色,并更改了其登录和创建数据库的权限。但是,当我尝试使用-U登录时,它向我展示了上述内容。我对-U的理解是错误的吗?

postgresql
1个回答
1
投票

默认情况下,Postgres身份验证系统的另一个假设是,将有一个与用于登录的角色同名的数据库,该角色可以访问该角色。

请参阅:link了解更多信息。

创建数据库后,您可以执行以下操作:

sudo -u hello psql

自动登录shell。

© www.soinside.com 2019 - 2024. All rights reserved.