如何快速删除具有现有权限的用户 [英] How to quickly drop a user with existing privileges

查看:49
本文介绍了如何快速删除具有现有权限的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我正在开发的应用程序创建受限数据库用户,并且我想删除我用于试验的 Postgres 数据库用户.有没有什么办法可以在不手动撤销用户所有权限的情况下删除用户,或者撤销用户拥有的所有授权?

解决方案

怎么样

DROP USER <用户名>

这实际上是DROP ROLE的别名.

您必须明确删除与该用户关联的任何权限,并将其所有权移至其他角色(或删除对象).

这是最好的实现

重新分配由 

拥有TO<新用户>

DROP OWNED BY <olduser>

后者将删除授予用户的任何权限.

请参阅 postgres 文档以了解 DROP ROLE更详细的描述.


补充:

显然,尝试使用此处提到的命令删除用户仅当您在连接到原始 GRANTS 所用的同一数据库时执行它们时才有效,如下所述:

https://www.postgresql.org/message-id/83894A1821034948BA27FE4DAA47427928F7C29922%40apde03.APD.Satcom.Local

I'm trying to make restricted DB users for the app I'm working on, and I want to drop the Postgres database user I'm using for experimenting. Is there any way to drop the user without having to revoke all his rights manually first, or revoke all the grants a user has?

解决方案

How about

DROP USER <username>

This is actually an alias for DROP ROLE.

You have to explicity drop any privileges associated with that user, also to move its ownership to other roles (or drop the object).

This is best achieved by

REASSIGN OWNED BY <olduser> TO <newuser>

and

DROP OWNED BY <olduser>

The latter will remove any privileges granted to the user.

See the postgres docs for DROP ROLE and the more detailed description of this.


Addition:

Apparently, trying to drop a user by using the commands mentioned here will only work if you are executing them while being connected to the same database that the original GRANTS were made from, as discussed here:

https://www.postgresql.org/message-id/83894A1821034948BA27FE4DAA47427928F7C29922%40apde03.APD.Satcom.Local

这篇关于如何快速删除具有现有权限的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆