在9i中,初始化参数AUDIT_TRAIL只有NONE、DB和OS三个可选值,而在10g中,Oracle又增加了几个新的选项。
这篇介绍XML选项。
数据库版本和默认AUDIT_TRAIL参数设置:
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database10gEnterpriseEdition Release10.2.0.3.0 - 64bi
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for Linux: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
SQL> show parameter audit_trail
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
audit_trail string NONE
下面设置参数为XML,并重启数据库:
SQL> alter system set audit_trail = xml scope = spfile;
System altered.
SQL> conn / as sysdba
Connected.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 2147483648 bytes
Fixed Size 2074112 bytes
Variable Size 486541824 bytes
Database Buffers 1644167168 bytes
Redo Buffers 14700544 bytes
Database mounted.
Database opened.
SQL> show parameter audit
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
audit_file_dest string /opt/ora10g/admin/primary/adump
audit_sys_operations boolean FALSE
audit_syslog_level string
audit_trail string XML
数据库中开启审计并触发:
SQL> audit create table;
Audit succeeded.
SQL> conn test/test
Connected.
SQL> create table t_audit (id number);
Table created.
虽然XML参数设置会使得审计信息写到操作系统中,不过Oracle仍然提供了视图可以访问到所有的AUDIT记录:
SQL> select audit_type, db_user, object_name, statement_type, sql_text, os_privilege
2 from dba_common_audit_trail;
AUDIT_TYPE DB_USER OBJECT_NAME STATEMENT_TYPE SQL_TEXT OS_PRIV
---------------------- -------- ------------ --------------- -------------------- -------
Mandatory XML Audit / CONNECT SYSDBA
Mandatory XML Audit / CONNECT SYSDBA