天天看點

PG權限相關

預設 超級管理者 postgres

建立審計管理者(隻讀使用者) sys_auditor

create role sys_auditor login password 'sys_auditor' ;
 alter role sys_auditor set default_transaction_read_only=on; 
 GRANT USAGE ON SCHEMA public to sys_auditor; 
 -- 對于未來建立的表, 自動配置設定讀權限給 sys_auditor
 grant select on all tables in schema public to sys_auditor;ALTER DEFAULT PRIVILEGES for role postgres IN SCHEMA public GRANT select ON TABLES TO sys_auditor;      

建立普通操作員(普通操作使用者) sys_operator

create role sys_operator login password 'sys_operator' nosuperuser nocreatedb noinherit noreplication  ;      

删除被其他對象依賴的使用者

reassign owned by test to postgres;
drop owned by test cascade;
drop role test ;
create role test login password 'passwd';      

建立隻讀使用者

CREATE USER test WITH ENCRYPTED PASSWORD 'passwd';
alter user test set default_transaction_read_only=on;
GRANT USAGE ON SCHEMA public to test;      
grant select on all tables in schema public to test      

# 檢視postgresql資料庫使用者系統權限、對象權限的方法

1、檢視某使用者的系統權限

SELECT * FROM  pg_roles WHERE rolname='postgres';      

2、檢視某使用者的表權限

select * from information_schema.table_privileges where grantee='postgres';      

3、檢視某使用者的usage權限

select * from information_schema.usage_privileges where grantee='postgres';      

4、檢視某使用者在存儲過程函數的執行權限

select * from information_schema.routine_privileges where grantee='postgres';      

5、檢視某使用者在某表的列上的權限

select * from information_schema.column_privileges where grantee='postgres';      

6、檢視目前使用者能夠通路的資料類型

select * from information_schema.data_type_privileges ;      
select * from information_schema.udt_privileges where grantee='postgres';      

繼續閱讀