首页 > 代码库 > 《oracle管理6》
《oracle管理6》
audit
开启开关参数:
SQL> show parameter audit_trail
设置审计选项:
每次设置新的审计选项,测试用户需要重新连接
sys准备工作:
SQL> drop user user01 cascade;
SQL> create user user01 identified by password;
SQL> grant create session, create table, create any table to user01;
审计系统权限:
SQL> AUDIT CREATE ANY TABLE, CREATE TABLE BY USER01 BY ACCESS; audit
user01测试:
SQL> create table t1(x int);
SQL> create table t1(x int); 失败
SQL> create table hr.t1(x int);
SQL> create table hr.t1(x int); 失败
sys查看审计结果:
SQL> desc aud$
SQL> desc dba_audit_trail
浏览器中查看
sys添加审计条件:
SQL> AUDIT SELECT ANY TABLE BY user01 BY ACCESS;
SQL> grant select any table to user01;
user01测试:
SQL> select * from t1;
SQL> select * from hr.t1;
sys查看审计结果:
浏览器中或者查看dba_audit_trail表
删除审计选项:
SQL> NOAUDIT CREATE ANY TABLE BY USER01;
SQL> NOAUDIT CREATE TABLE BY USER01;
SQL> NOAUDIT SELECT ANY TABLE BY user01;
审计对象:
sys设置审计选项:
SQL> AUDIT SELECT ON hr.employees BY ACCESS;
SQL> drop user user01 cascade;
SQL> create user user01 identified by password;
SQL> grant create session to user01;
sys授权,每执行一个语句,user01就测试一次:
SQL> grant select any table to user01;
SQL> revoke select any table from user01;
SQL> grant select on hr.employees to user01;
user01测试(执行4次):
SQL> select count(*) from hr.employees;
默认不记录sys的行为:
SQL> select count(*) from hr.employees;
删除审计选项:
SQL> NOAUDIT SELECT ON hr.employees;
审计语句:
sys设置审计选项:
SQL> AUDIT TABLE BY user01 BY ACCESS;
user01测试:
SQL> create table t1(x int); 失败
SQL> create table t1(x int);
SQL> create table t1(y int); 失败
SQL> drop table t1;
sys查看结果:
浏览器中,或DBA_AUDIT_OBJECT表中
删除审计选项:
SQL> NOAUDIT TABLE BY USER01
审计sys的操作:
SQL> show parameter audit
修改两个参数
并发管理
读写冲突通过读一致性解决:
sys准备工作:
SQL> create user user01 identified by password;
SQL> grant dba to user01;
以下都用user01:
SQL> conn user01/password
Connected.
SQL> create table t1(x int);
SQL> insert into t1 values (1);
SQL> commit;
session1:
SQL> update t1 set x=11 where x=1;
SQL> select * from t1;
session 2:
SQL> select * from t1;
session 1:s
SQL> commit;
session 2:
SQL> select * from t1;
测试serializable:
session1:
SQL> alter session set isolation_level=serializable;
重复上面的步骤
写与写的冲突通过锁机制解决:
session 1:
SQL> update t1 set x=11 where x=1;
浏览器中查看锁信息
session 2:
SQL> update t1 set x=111 where x=1; 被阻塞
浏览器中查看锁信息
session 1:
SQL> rollback;
浏览器中查看锁信息
死锁:
session1:
SQL> select * from t1;
X
----------
1
2
SQL> update t1 set x=11 where x=1;
session2:
SQL> update t1 set x=22 where x=2;
session1:
SQL> update t1 set x=222 where x=2; 阻塞
session2:
SQL> update t1 set x=111 where x=1; 死锁
ERROR at line 1:
ORA-00060: deadlock detected while waiting for resource
$ vi /u01/app/oracle/diag/rdbms/orcl/orcl/trace/alert_orcl.log
锁和外键
select … for update
《oracle管理6》