權限
系統(tǒng)權限 role和user都是用戶,只不過role屬性不能登錄當然也可以指定
超級權限 不做權限檢查(實際中是很危險的)
Pg權限分為兩部分稼锅,一部分是“系統(tǒng)權限”或者數(shù)據(jù)庫用戶的屬性董习,可以授予role或user(兩者區(qū)別在于login權限)晾捏;
一部分為數(shù)據(jù)庫對象上的操作權限。對超級用戶不做權限檢查因俐,其它走acl。
對于數(shù)據(jù)庫對象屿笼,開始只有所有者和超級用戶可以做任何操作眷柔,其它走acl。
在pg里公你,對acl模型做了簡化踊淳,組和角色都是role,用戶和角色的區(qū)別是角色沒有l(wèi)ogin權限陕靠。
超級權限
- 創(chuàng)建超級用戶(create user alice with superuser password '123456';)系統(tǒng)不會做權限操作校驗,僅僅是不能夠創(chuàng)建用戶與刪除用戶
系統(tǒng)權限
(create role blake password '123456';)(create user bob password '123456';)(create database testdb;)
(grant all on database testdb to bob;grant all on database testdb to blake;)
測試如下 用戶bob可以登錄而blake不能登錄直接拋出了FATL:role blake is not 'permitted to log in'
( drop database testdb;drop role blake;drop user bob;)
(create user bob password '123456';)(alter user bob set default_transaction_read_only=on;grant all on database testdb to bob;grant select on all tables in schema public to bob; )
(revoke all on database testdb from bob;revoke select on all tables in schema public from bob;)刪除前撤銷(drop user bob)
(grant DELETE,UPDATE,SELECT,INSERT on all tables in schema public to bob;)
查詢
- 查詢系統(tǒng)中用戶的權限(SELECT * FROM pg_roles;)
- 顯示用戶和用戶的用戶屬性(\du)
- 查看全部可設置的管理權限(\h)
刪除
- (drop user bob) (drop role bob)要注意在刪除前必須把權限先刪除,還有一種笨辦法就是把數(shù)據(jù)庫先備份然后在刪除這時就可以刪除用戶了
系統(tǒng)登錄
- (sudo su postgres -c psql template1)(psql -U alice -d testdb -h localhost -W)參數(shù)含義: -U指定用戶 -d要連接的數(shù)據(jù)庫 -h要連接的主機 -W提示輸入密碼迂尝。
修改系統(tǒng)密碼
- (sudo passwd -d postgres)
sudo su postgres -c psql template1
會出現(xiàn) postgres=#
輸入postgres=# \password
輸入2次密碼
然后輸入(退出)
postgres=# \q