Oracle 12c 之前的版本中没有什么好方法来对DDL操作进行日志记录。只有通过logmnr 工具对日志进行分析,有时候对误操作的时间点无法判断,分析起来非常麻烦。
在12c R1中,可以将DDL操作写入xml和日志文件中,存放路径$ORACLE_BASE/diag/rdbms/DBNAME/log|ddl, xml文件中包含DDL命令,IP地址,时间戳等信息。
对DDl操作就了如直掌,可以更快的定位到问题和分析。
以下的DDL语句可能会记录在xml或日志文件中:
CREATE|ALTER|DROP|TRUNCATE TABLE
DROP USER
CREATE|ALTER|DROP PACKAGE|FUNCTION|VIEW|SYNONYM|SEQUENCE
开启DDL日志功能
SQL> ALTER SYSTEM|SESSION SET ENABLE_DDL_LOGGING=TRUE; --可以系统级别和会话级别
以下是验证过程:
SQL> show parameter enable
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
enable_ddl_logging boolean TRUE
enable_pluggable_database boolean TRUE
Java_jit_enabled boolean TRUE
max_enabled_roles integer 150
optimizer_features_enable string 12.1.0.1
parallel_fault_tolerance_enabled boolean FALSE
parallel_io_cap_enabled boolean FALSE
query_rewrite_enabled string TRUE
star_transformation_enabled string FALSE
temp_undo_enabled boolean FALSE
trace_enabled boolean TRUE
SQL>
SQL>
SQL> create table test (id number);
Table created.
查看xml日志
[oracle@db12c ddl]$ more log.xml
<msg time='2013-12-06T17:26:38.971+08:00' org_id='oracle' comp_id='rdbms'
msg_id='opiexe:4181:2946163730' type='UNKNOWN' group='diag_adl'
level='16' host_id='db12c.oracle.com' host_addr='::ffff:127.0.0.1'
version='1'>
<txt>ALTER DATABASE CLOSE NORMAL
</txt>
</msg>
<msg time='2013-12-06T17:26:39.011+08:00' org_id='oracle' comp_id='rdbms'
msg_id='opiexe:4181:2946163730' type='UNKNOWN' group='diag_adl'
level='16' host_id='db12c.oracle.com' host_addr='::ffff:127.0.0.1'>
<txt>ALTER DATABASE DISMOUNT
</txt>
</msg>
<msg time='2013-12-06T17:27:12.142+08:00' org_id='oracle' comp_id='rdbms'
msg_id='opiexe:4181:2946163730' type='UNKNOWN' group='diag_adl'
level='16' host_id='db12c.oracle.com' host_addr='::ffff:127.0.0.1'>
<txt>ALTER DATABASE OPEN
</txt>
</msg>
<msg time='2013-12-06T17:27:32.299+08:00' org_id='oracle' comp_id='rdbms'
msg_id='opiexe:4181:2946163730' type='UNKNOWN' group='diag_adl'
level='16' host_id='db12c.oracle.com' host_addr='::ffff:127.0.0.1'>
<txt>create table test (id number) </txt>
</msg>
[oracle@db12c ddl]$