m6米乐安卓版下载-米乐app官网下载
暂无图片
3

postgresql运维—drop role -m6米乐安卓版下载

原创 李先生 2022-02-10
1027

语法

drop role — remove a database role

drop role [ if exists ] name [, ...]

描述

drop role removes the specified role(s). to drop a superuser role, you must be a superuser yourself; to drop non-superuser roles, you must have createrole privilege.

postgres=# create user u1 with superuser; create role postgres=# create user u2; create role postgres=# create user u3; create role postgres=# \du list of roles role name | attributes | member of ----------- ------------------------------------------------------------ ----------- lxs | superuser, create role, create db | {} postgres | superuser, create role, create db, replication, bypass rls | {} u1 | superuser | {} u2 | | {} u3 | | {} postgres=# \c - u2 you are now connected to database "postgres" as user "u2". postgres=> drop user u1; error: permission denied to drop role postgres=> drop user u3; error: permission denied to drop role postgres=# alter user u2 createrole; alter role postgres=# drop user u3; drop role postgres=# alter user u2 superuser; alter role postgres=# drop user u1; drop role postgres=# \c - postgres you are now connected to database "postgres" as user "postgres". postgres=# drop user u2; drop role postgres=#

a role cannot be removed if it is still referenced in any database of the cluster; an error will be raised if so.

postgres=# create user u1; create role postgres=# create table t1(id int); create table postgres=# grant select on t1 to u1; grant postgres=# drop user u1; error: role "u1" cannot be dropped because some objects depend on it detail: privileges for table t1 postgres=#

before dropping the role, you must drop all the objects it owns (or reassign their ownership) and revoke any privileges the role has been granted on other objects. the reassign owned and drop owned commands can be useful for this purpose;

postgres=# \du list of roles role name | attributes | member of ----------- ------------------------------------------------------------ ----------- lxs | superuser, create role, create db | {} postgres | superuser, create role, create db, replication, bypass rls | {} u1 | | {} postgres=# reassign owned by u1 to lxs; reassign owned postgres=# reassign owned by u1 to lxs; reassign owned postgres=# drop owned by u1; drop owned postgres=# drop user u1; drop role postgres=#

however, it is not necessary to remove role memberships involving the role; drop role automatically revokes any memberships of the target role in other roles, and of other roles in the target role. the other roles are not dropped nor otherwise affected.

参数

  • if exists

    do not throw an error if the role does not exist. a notice is issued in this case.

    postgres=# drop user if; error: role "if" does not exist postgres=# drop user if exists u1; notice: role "u1" does not exist, skipping drop role postgres=#
  • name

    the name of the role to remove.

    postgres=# create user u1; create role postgres=# drop user u1; drop role postgres=#

注解

postgresql includes a program dropuserthat has the same functionality as this command (in fact, it calls this command) but can be run from the command shell.

postgres=# create user u1; create role postgres=# \du list of roles role name | attributes | member of ----------- ------------------------------------------------------------ ----------- lxs | superuser, create role, create db | {} postgres | superuser, create role, create db, replication, bypass rls | {} u1 | | {} postgres=# \q [postgres@lyp ~]$ dropuser u1; [postgres@lyp ~]$ psql psql (14.1) type "help" for help. postgres=# \du list of roles role name | attributes | member of ----------- ------------------------------------------------------------ ----------- lxs | superuser, create role, create db | {} postgres | superuser, create role, create db, replication, bypass rls | {} postgres=#

兼容性

the sql standard defines drop role, but it allows only one role to be dropped at a time, and it specifies different privilege requirements than postgresql uses.

sql 标准定义了drop role, 但是它只允许一次删除一个角色并且它指定了和 postgresql不同的特权需求。

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【米乐app官网下载的版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

网站地图