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

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

问题描述

我正在尝试使正在使用的应用程序的数据库用户受限,并且我想删除用于实验的Postgres数据库用户。有什么方法可以丢弃用户而不必先手动撤消其所有权限,也不必撤消用户拥有的所有授予权?

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?

推荐答案

DROP USER <username>

这实际上是 DROP角色的别名。

您必须明确删除与该用户关联的所有特权,还必须将其所有权转移到其他角色(或删除对象)。

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

最好通过

REASSIGN OWNED BY <olduser> TO <newuser>

DROP OWNED BY <olduser>

后者将删除授予用户的任何特权。

The latter will remove any privileges granted to the user.

有关 DROP角色的信息,请参见postgres文档对此进行更详细的描述

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



添加:

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

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/83894A1821034948BA27FE4DAA47427928F7C299 .Satcom.Local

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

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