jiang demo1

举报
HW_TEST 发表于 2025/11/17 13:49:15 2025/11/17
【摘要】 jiang demo1

(1) 查询表的模式名和表名
--查询系统试图 pg_tables
select tablename,schemaname from pg_tables where tablename='p_table';
(2) 查询表的所在节点 nodeoids 信息
select t1.relname,t2.nodeoids 
from pg_class t1,pgxc_class t2, pg_namespace t3 
where t1.oid=t2.pcrelid 
and t1.relnamespace=t3.oid
and t1.relname='p_table' 
and t3.nspname='root'; 
(3) 查询表所在的实例信息
select t4.* 
from pg_class t1,pgxc_class t2,pg_namespace t3, pgxc_node t4 
where t1.oid=t2.pcrelid 
and t1.relnamespace=t3.oid
and cast(t2.nodeoids as varchar(20))=cast(t4.oid as varchar(20))
and t1.relname='p_table' and t3.nspname='omm';
(4)将表 sjh_test 表的读取、删除权限授权给 sjh111 用户
----普通用户只有 public 模式的权限,需要将当前 schema 使用权限赋予给用户
grant usage on schema root to sjh111; --赋权
grant select ,delete on sjh_test to sjh111;
(5)为用户 sjh111 授权在 sjh_test 表的 a,b 列上的查询、添加和更新权限
grant select(a,b),insert(a,b),update(a,b) on sjh_test to sjh111;
(6)将用户 sjh111 授权在 sjh_test 表的 a 列上的查询、添加和更新权限回收
revoke select(a),insert(a),update(a) on sjh_test from sjh111;
(7)创建角色 sjh_audit ,此角色拥有审计权限
create role sjh_audit1 with auditadmin password "test@123";
(8)将 sjh112 角色授权于用户 sjh111,并运行 sjh111 继承权限可以再次授予其他角色或用户
grant sjh112 to sjh111 with admin option;
(9)创建新用户 sjh113,设置使用有效期"2023-01-28" 至"2026-01-01"
create user sjh113 password "test@123" valid begin "2023-01-28" valid until "2026-01-01";
(10)打开 all_data 表的行级访问控制策略开关
alter table all_data enable row level security;
(11)创建行级访问控制策略,当前用户只能查看用户自身的数据
create row level security  policy rls01 on all_data using(role=current_user);
(12)删除策略
drop row level security policy rls01 on all_data;
(13)关闭行级访问控制
alter table all_data disable row level security;
(14) 创建试图 SELECT_SD,查询学生成绩信息,查询学生姓名,课程名称,课程成绩
create or replace view SELECT_SD as select sname,cname,grade 
from student s, course c,elective e 
where e.sno=s.sno and e.cno=c.cno;
(15) 编写函数 FUNC_SUM,返回某个学生的分数总和
create or replace function FUNC_SUM(stuid int) returns integer as
$$
declare result integer;
begin
select sum(grade) into result from elective where sno=stuid;
return result;
end;
$$language plpgsql;
(16)创建触发器 DELETE_ELE,在 student 表上绑定触发器 DELETE_ELE,在删除表中某个学生时,将 ELECTIVE 表中该学生的选课记录一并删除;
create or replace function func_01() returns trigger as
$$
begin
delete from elective where sno =old.sno;
return old;
end;
$$language plpgsql; 
(17)创建触发器 DELETE_ELE
create or replace trigger DELETE_ELE before delete on student for each row execute procedure func_01();

【版权声明】本文为华为云社区用户原创内容,未经允许不得转载,如需转载请自行联系原作者进行授权。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。