greenplum用户权限管理
一、新建用户,拥有原有库的所有权限
新建用户:
CREATE role irdw_user WITH LOGIN ENCRYPTED PASSWORD ‘******’;
赋予库、schema权限给用户
GRANT ALL ON DATABASE irdw_xut TO irdw_user;
GRANT ALL ON SCHEMA “public” to irdw_user;
修改配置文件
/data/disk1/gpdata/master/gpseg-1/pg_hba.conf
添加配置
host all irdw_user 0.0.0.0/0 md5
重新加载配置:
gpstop -u
二、新建用户read_role,对某些库表的只读权限
1.创建一个用户名为read_role密码为ropass的用户
CREATE USER read_role WITH ENCRYPTED PASSWORD ‘ropass’;
2.用户只读事务
alter user read_role set default_transaction_read_only=on;
3.把所有库的语言的USAGE权限给到read_role
GRANT USAGE ON SCHEMA vt_profile to read_role;
4.授予select权限(这句要进入具体数据库操作在哪个db环境执行就授予那个db的权)
grant select on all tables in schema vt_profile to read_role;
报错了:
GRANT SELECT on ALL TABLES in SCHEMA vt_profile TO read_role
ERROR: syntax error at or near “ALL”
LINE 1: GRANT SELECT on ALL TABLES in SCHEMA vt_profile TO read_role
greenplum 虽然是postgresql的衍生产品?,但是语法上略有不同。所以这里使用其他的办法
select ‘grant SELECT on table ’ || schemaname || ‘.’ || tablename || ’ to read_role;’ from pg_tables
where schemaname = ‘vt_profile’
得到如下语句
grant SELECT on table vt_profile.temp_jackical_middle_result1 to read_role;
grant SELECT on table vt_profile.tmp_jackical_video_middle_result_final1_analysis to read_role;
grant SELECT on table vt_profile.tmp_jackical_video_middle_result_totaluv_final1_analysis to read_role;
grant SELECT on table vt_profile.tmp_jackical_video_middle_result_final_total_analysis to read_role;
grant SELECT on table vt_profile.actiondata_day_2018y to read_role;
grant SELECT on table vt_profile.dim_media_video_base to read_role;
grant SELECT on table vt_profile.mut_rawdata_201845_w to read_role;
。。。。。。
然后执行就可以了
5、上面的SQL命令只把现有的表的权限给了用户read_role,但如果这之后创建的表,read_role用户还是不能读,需要使用下面的SQL把以后创建的表的SELECT权限也给用户read_role:
ALTER DEFAULT PRIVILEGES IN SCHEMA vt_profile grant select on tables to read_role;
三、删除用户
删除用户之前,应该移除该用户拥有的权限
drop user read_role;
revoke SELECT on TABLE tmp_middle_process_1_201843_w_mvt from read_role;
revoke SELECT on TABLE bt_personas_attr_prop_new_201844_w_mvt from read_role;
revoke SELECT on TABLE bt_pc_personas_profile_new_201844_w_mvt from read_role;
revoke USAGE on schema public from read_role;
再删除就ok了
四、管理对象权限
本文来源:https://blog.csdn.net/weixin_42658788/article/details/88040209
相关文章