新聞中心
這篇文章將為大家詳細(xì)講解有關(guān)postgresql數(shù)據(jù)庫刪除用戶的方法,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
在南安等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站制作、成都做網(wǎng)站 網(wǎng)站設(shè)計(jì)制作定制網(wǎng)站建設(shè),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),成都營銷網(wǎng)站建設(shè),外貿(mào)營銷網(wǎng)站建設(shè),南安網(wǎng)站建設(shè)費(fèi)用合理。
將介紹PostgreSQL下如何快速刪除一個(gè)用戶(role)。
一般情況下直接執(zhí)行 drop role xxx; 就可以把這個(gè)用戶刪除。但是很多時(shí)候會因?yàn)橛脩粲幸蕾嚩鴪?bào)錯(cuò)。
推薦:postgresql教程
權(quán)限依賴
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
可以看出,因?yàn)槲覀儼褦?shù)據(jù)庫postgres 的權(quán)限賦予了test 用戶,所以直接刪除的時(shí)候會報(bào)錯(cuò)。面對這種情況,我們需要先將role 的權(quán)限
所有的權(quán)限全部revoke 掉,如下:
postgres=# revoke all on database postgres from test; REVOKE postgres=# drop role test; DROP ROLE
注意:需要把該用戶在所有數(shù)據(jù)庫具有權(quán)限的所有數(shù)據(jù)庫對象的(表,視圖,SEQUENCE)權(quán)限全部回收,才能刪除該用戶。
對象依賴
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
可以看出,因?yàn)閠est 用戶是test 表的owner,所以刪除的時(shí)候報(bào)錯(cuò)owner of table test。如果不需要保留該對象,則需要先把該依賴對象
刪除。如果需要保留該對象,則應(yīng)該在刪除之前先把owner 賦予別人,如下:
postgres=# alter table test OWNER TO postgres; ALTER TABLE postgres=# drop role test; DROP ROLE
注意:需要把該用戶在所有數(shù)據(jù)庫具有owner 權(quán)限的所有數(shù)據(jù)庫對象(表,視圖,SEQUENCE)刪除或者執(zhí)行alter xx owner to,才能
刪除該用戶。
關(guān)于postgresql數(shù)據(jù)庫刪除用戶的方法就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。
網(wǎng)頁標(biāo)題:postgresql數(shù)據(jù)庫刪除用戶的方法
轉(zhuǎn)載來源:http://www.dlmjj.cn/article/jepghh.html