重慶分公司,新征程啟航
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊(cè)、服務(wù)器等服務(wù)
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊(cè)、服務(wù)器等服務(wù)
創(chuàng)新互聯(lián)www.cdcxhl.cn八線動(dòng)態(tài)BGP香港云服務(wù)器提供商,新人活動(dòng)買(mǎi)多久送多久,劃算不套路!
小編給大家分享一下postgresql刪除用戶密碼的方法,相信大部分人都還不怎么了解,因此分享這邊文章給大家學(xué)習(xí),希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去學(xué)習(xí)方法吧!
在多租戶場(chǎng)景或者其他場(chǎng)景下,很多時(shí)候需要主動(dòng)清理一些用戶,本文將介紹PostgreSQL 下如何快速刪除一個(gè)用戶(role)。
具體方法
一般情況下直接執(zhí)行 drop role xxx; 就可以把這個(gè)用戶刪除。但是很多時(shí)候會(huì)因?yàn)橛脩粲幸蕾嚩鴪?bào)錯(cuò)。
權(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ù)庫(kù)postgres 的權(quán)限賦予了test 用戶,所以直接刪除的時(shí)候會(huì)報(bào)錯(cuò)。面對(duì)這種情況,我們需要先將role 的權(quán)限所有的權(quán)限全部revoke 掉,如下:
postgres=# revoke all on database postgres from test; REVOKE postgres=# drop role test; DROP ROLE
注意:需要把該用戶在所有數(shù)據(jù)庫(kù)具有權(quán)限的所有數(shù)據(jù)庫(kù)對(duì)象的(表,視圖,SEQUENCE)權(quán)限全部回收,才能刪除該用戶。
對(duì)象依賴
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。如果不需要保留該對(duì)象,則需要先把該依賴對(duì)象
刪除。如果需要保留該對(duì)象,則應(yīng)該在刪除之前先把owner 賦予別人,如下:
postgres=# alter table test OWNER TO postgres; ALTER TABLE postgres=# drop role test; DROP ROLE
需要把該用戶在所有數(shù)據(jù)庫(kù)具有owner 權(quán)限的所有數(shù)據(jù)庫(kù)對(duì)象(表,視圖,SEQUENCE)刪除或者執(zhí)行alter xx owner to,才能刪除該用戶。
以上是postgresql刪除用戶密碼的方法的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道!