2017年7月3日 坐标西安 天气晴,温度 热
今日同事过来说开发提要求他们的库的oracle用户,
不要有drop table的权限。当时正在装oracle集群,正好也没遇到问题,也没多考虑。
解决了安装rac的问题之后,静下心来想到这个权限的问题,第一反应,奇葩啊,连本用户的表都不能有删除的权限啊,做oracle这么长时间第一次遇到这种需求,
不过也难怪,之前就是由开发人员误删除表,引起了领导的关注,这把直接不要这个权限。
一般建用户给权限都是给connect和resource权限(11G),12C的还要加一个unlimit 对应表空间。以下是基于11.2.0.4。
方法一:先按常规给了connect和resource权限以后,revoke掉drop table可以吗?
SQL> create user db1 identified by db1;
User created.
SQL> grant connect,resource to db1;
Grant succeeded.
SQL> revoke drop table from db1;
revoke drop table from db1
*
ERROR at line 1:
ORA-00990: missing or invalid privilege
那要是只给connect和create table 权限可行吗???
SQL> create user zx identified by zx1;
User created.
SQL> grant connect,create table to zx;
Grant succeeded.
SQL> alter user zx quota unlimited on users;
User altered.
SQL> conn zx/zx1
Connected.
SQL> create table aqz as select * from dual;
Table created.
SQL> drop table aqz;
Table dropped.
SQL> create table aqz as select * from dual;
Table created.
看样子只给connect和create table的也不行,那索性把create table的权限额回收,试试看
SQL> revoke create table from zx;
Revoke succeeded.
SQL> conn zx/zx1
Connected.
SQL> drop table aqz;
Table dropped.
SQL> select * from session_privs;
PRIVILEGE
----------------------------------------
CREATE SESSION
事实证明不可行,不能revoke权限drop table。就算是仅有connect的权限,还是可以删表的,查询相关权限表,也没有说有drop table 的权限,只有drop any table 那咋办????
触发器!!!!!!!!!
关于drop权限,不允许整个库有drop操作
create or replace trigger drop_tri
before drop on db1
declare
l_errmsg varchar2(100):= 'No permission please dba/13310086888';
begin
if ora_sysevent = 'DROP' then
raise_application_error(-20001, ora_dict_obj_owner || '.' || ora_dict_obj_name || ' ' || l_errmsg);
end if;
exception
when no_data_found then
null;
end;
/
Trigger created.
这个是针对于整个库的,那么是不是不仅仅drop tables???还有index,view 等等,,
SQL> create table db1.a2 as select * from dual; //创建测试表
Table created.
SQL> create index db1.a3 on db1.a2(dummy); //创建测试索引
Index created.
SQL> create view db1.aw as select * from dual; //创建测试视图
View created.
SQL> drop table db1.a2; //无法删表
drop table db1.a2
*
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-20001: DB1.A2 No permission please dba/13310086888
ORA-06512: at line 5
SQL> drop index db1.a3; //无法删索引
drop index db1.a3
*
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-20001: DB1.A3 No permission please dba/13310086888
ORA-06512: at line 5
SQL> drop view db1.aw; //无法删视图
drop view db1.aw
*
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-20001: DB1.AW No permission please dba/13310086888
ORA-06512: at line 5
SQL> create table aaa as select * from dual;
Table created.
SQL> drop table aaa; //甚至连系统用户都不行
drop table aaa
*
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-20001: SYS.AAA No permission please dba/13310086888
ORA-06512: at line 5
看样子,针对库的触发器还是不能建,这个
影响太大,不管删什么都要先disable触发器,效果能达到,但是不建议使用
只能是针对表(以aa1表为例)的那就将上面的加个条件,语句如下:
create or replace trigger trg_dropdeny
before drop on database
begin
if lower(ora_dict_obj_name()) = 'aa1'
then
raise_application_error(
num => -20000,
msg => 'No permission please dba/13310086888');
end if;
end;
/
但是触发器影响数据库性能的,要是有大量的表不能删,那太影响数据库性能了。不建议,,,,,估计只能通过完善的备份策略,开启各种flashback(闪回表,闪回数据库)