Examine the following commands for redefining a table with Virtual Private Database (VPD) policies:
BEGIN
DBMS_RLS.ADD_POLICY(
object_schema => 'hr',
object_name => 'employees',
policy_name => 'employees_policy',
function_schema => 'hr',
policy_function => 'auth_emp_dep_100',
statement_types => 'select,insert,update,delete',
);
END;
BEGIN
DBMS_REDEFINITION.START_REDEF_TABLE(
uname => 'hr',
orig_table => 'employees',
int_table => 'employees_policy',
col_mapping => NULL,
options_flag => DBMS_REDEFINITION.CONS_USE_PK,
orderby_cols => NULL,
part_name => NULL,
copy_vpd_opt => DBMS_REDEFINITION.CONS_VPD_AUTO);
END;
Which two statements are true about
redefining the table?
A. All the triggers for the table are disabled without changing
any of the column names or column types in the table.
B. The primary key constraint on the EMPLOYEES table is disabled
during redefinition.
C. VPD policies are copied from the original table to the new
table during online redefinition.
D. You must copy the VPD policies manually from the original table
to the new table during online redefinition.
【题意简述】
考察了对配置了VPD策略的表进行在线重定义时的注意事项
【考点分析】
首先 VPD 是什么?VPD 全称 Virtual Private Database (VPD),直译为虚拟私人数据库。启用VPD以后,可以在行级和列级编辑安全策略,用来对数据库进行访问控制,保护企业中名敏感的数据!其原理可以理解为,VPD 自动为 SQL 语句添加动态的 Where 条件,使得检索出来的数据符合定义的 VPD 策略。当用户直接或间接的访问被VPD策略所保护的某个表,视图或同义词时,Oracle数据库使用VPD策略中定义的函数的返回结果来修改where子句中的谓词条件,从而实现自动修改用户的SQL语句。
例如,用户执行了一个查询:
SELECT * FROM OE.ORDERS;
VPD策略动态的追加上Where 条件,
SELECT * FROM OE.ORDERS WHERE SALES_REP_ID = 159;
这样用户仅仅可以检索到 Sales Representative为159的数据行了。如果需要针对用户的session中的信息,如用户id,你可以使用上下文来实现!
SELECT * FROM OE.ORDERS WHERE SALES_REP_ID = SYS_CONTEXT(‘USERENV','SESSION_USER');
VPD 策略可以应用在Select,insert,update,delete,index语句中,但不能支持过滤DDL语句,如truncate table或alter table。
在线重定义可以改变表的结构,同时对重定义过程中表上的DML语句影响非常小。因为独占锁模式所经过的时间窗口比较短。主要操作通过DBMS_REDEFINITION包来完成。而在线重定义的表上同时有VPD策略,我们该如何处理呢?
首先 DBMS_REDEFINITION 包中提供了 copy_vpd_opt 参数,在 START_REDEF_TABLE 过程中使用 copy_vpd_opt 参数来处理VPD策略。copy_vpd_opt 参数可以指定如下一些内容:
【答案剖析】
A:源表的触发器复制到中间表后,在同步数据时,中间表的触发器会被触发,导致数据出现不一致,因此要关闭中间表的触发器,所以 A 正确。
B:题目中的 ”options_flag => DBMS_REDEFINITION.CONS_USE_PK” 参数,说明使用主键来保证重定义过程中的唯一性,因此主键不会禁用,所以 B 错误。
C:重定义中VPD策略的处理方法使用的是 DBMS_REDEFINITION.CONS_VPD_AUTO,含义为自动拷贝源表的VPD策略,所以 C 正确。
D:如果使用 DBMS_REDEFINITION.CONS_VPD_MANUAL 参数,才需要手工拷贝源表的VPD策略,所以 D 不正确。
【答案】 A,C
~~~~~~~ the end~~~~~~~~~
hoegh
2016.05.11
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30162081/viewspace-2097612/ ,如需转载,请注明出处,否则将追究法律责任。