代码:
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
Run Code Online (Sandbox Code Playgroud)
我正在尝试创建一个hello在 Postgres 中命名的角色CREATE ROLE,并更改其登录和创建数据库的权限。但是,当我尝试登录时,-U它会显示上述内容。难道我的理解有误吗-U?
默认情况下,Postgres 身份验证系统做出的另一个假设是,将有一个与用于登录的角色同名的数据库,该角色有权访问该数据库。
请参阅此处:链接以获取更多信息。
创建数据库后,您可以执行以下操作:
sudo -u hello psql
Run Code Online (Sandbox Code Playgroud)
自动登录到 shell。
| 归档时间: |
|
| 查看次数: |
10686 次 |
| 最近记录: |