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

Postgresql Postgres:创建一个角色并使用psql-U角色登录,postgresql,Postgresql,代码: postgres=# create role hello; CREATE ROLE postgres=# \du List of roles Role name | Attributes | Member of -----------+------------------------------------------------+-----------

代码:

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
我正试图使用
创建角色
在Postgres中创建一个名为
hello
的角色,并更改了其登录和创建数据库的权限。但是,当我尝试使用
-U
登录时,它会显示上述内容。我对
-U
的理解有误吗

默认情况下,另一个假设是Postgres认证系统 这意味着将有一个与角色同名的数据库 用于登录,角色有权访问

请参阅此处:了解更多信息

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

sudo -u hello psql

自动登录到shell。

您尚未创建数据库
您好
您的意思是创建角色时,您需要具有该名称的数据库吗?是的。Postgres希望这样,但是没有使用
CREATE ROLE
同时创建数据库的选项。我想我需要手动创建它。你必须以不同的方式创建数据库。就在贝壳上<代码>创建数据库hello然后才能登录。是的,手动创建数据库后我可以登录。然而,我在shell中看到了类似这样的东西,就像postgres一样-
postgres=#
。这两个符号之间的区别在于提示输入超级用户帐户<代码>=>表示您不是超级用户。谢谢。我明白了。