PostgreSQL - 如何将超级用户更改为无超级用户?

avi*_*avi 7 sql database postgresql alter superuser

我有一个角色:

CREATE ROLE x LOGIN
  ENCRYPTED PASSWORD '....'
  SUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;
Run Code Online (Sandbox Code Playgroud)

该角色已经创建。

我想修改为:

  NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;
Run Code Online (Sandbox Code Playgroud)

将 更改SUPERUSERNOSUPERUSER;

不做就可以做吗Drop role

Vao*_*sun 9

https://www.postgresql.org/docs/current/static/sql-alterrole.html

ALTER ROLE 角色规范 [WITH] 选项 [...]

其中选项可以是:

  SUPERUSER | NOSUPERUSER
Run Code Online (Sandbox Code Playgroud)
t=# create user su superuser;
CREATE ROLE
t=# \du+ su
                  List of roles
 Role name | Attributes | Member of | Description
-----------+------------+-----------+-------------
 su        | Superuser  | {}        |

t=# alter user su nosuperuser;
ALTER ROLE
t=# \du+ su
                  List of roles
 Role name | Attributes | Member of | Description
-----------+------------+-----------+-------------
 su        |            | {}        |
Run Code Online (Sandbox Code Playgroud)

或可选的WITH:

t=# alter user su with nosuperuser;
ALTER ROLE
Run Code Online (Sandbox Code Playgroud)