代码:
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
的角色,使用CREATE ROLE
命令更改它的登录和创建数据库权限。但是,当我尝试使用-U
登录时,出现了上述错误信息。我对-U
的理解是否有误?
hello
。 - MekichaCREATE ROLE
选项中没有创建数据库的选项。我认为我需要手动创建它。 - wonder