网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

postgresql数据库删除用户的方法-创新互联

创新互联www.cdcxhl.cn八线动态BGP香港云服务器提供商,新人活动买多久送多久,划算不套路!

创新互联建站主要从事成都网站建设、成都网站制作、网页设计、企业做网站、公司建网站等业务。立足成都服务库尔勒,十余年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:028-86922220

这篇文章将为大家详细讲解有关postgresql数据库删除用户的方法,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

将介绍PostgreSQL下如何快速删除一个用户(role)。

一般情况下直接执行 drop role xxx; 就可以把这个用户删除。但是很多时候会因为用户有依赖而报错。

推荐:postgresql教程

权限依赖

postgres=# create role test with login;
CREATE ROLE
postgres=# grant all on database postgres to test;
GRANT
postgres=# drop role test;
ERROR:  role "test" cannot be dropped because some objects depend on it
DETAIL:  privileges for database postgres

可以看出,因为我们把数据库postgres 的权限赋予了test 用户,所以直接删除的时候会报错。面对这种情况,我们需要先将role 的权限

所有的权限全部revoke 掉,如下:

postgres=# revoke all on database postgres from test;
REVOKE
postgres=# drop role test;
DROP ROLE

注意:需要把该用户在所有数据库具有权限的所有数据库对象的(表,视图,SEQUENCE)权限全部回收,才能删除该用户。

对象依赖

postgres=# create role test with login;
CREATE ROLE
postgres=# \c - test
You are now connected to database "postgres" as user "test".
postgres=> create table test (id int);
CREATE TABLE
postgres=# \c - postgres
You are now connected to database "postgres" as user "postgres".
postgres=# drop role test;
ERROR:  role "test" cannot be dropped because some objects depend on it
DETAIL:  owner of table test

可以看出,因为test 用户是test 表的owner,所以删除的时候报错owner of table test。如果不需要保留该对象,则需要先把该依赖对象

删除。如果需要保留该对象,则应该在删除之前先把owner 赋予别人,如下:

postgres=# alter table test OWNER  TO postgres;
ALTER TABLE
postgres=# drop role test;
DROP ROLE

注意:需要把该用户在所有数据库具有owner 权限的所有数据库对象(表,视图,SEQUENCE)删除或者执行alter xx owner to,才能

删除该用户。

关于postgresql数据库删除用户的方法就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。


当前名称:postgresql数据库删除用户的方法-创新互联
URL链接:http://bjjierui.cn/article/dhhcge.html

其他资讯