12c中,增强的ADR功能,可以记录ddl操作的日志。
alter system set enable_ddl_logging=true; create table test1(c number); create table test2(c varchar2(10)); create user c##user1 identified by oracle; drop user c##user1; drop table test1; drop table test2; cd /u01/app/oracle/diag/rdbms/test/test/log/ddl adrci show log
测试如下:
启用ddl logging, 并执行ddl操作
SYS@test>alter system set enable_ddl_logging=true; System altered. SYS@test>create table test1(c number); Table created. SYS@test>create table test2(c varchar2(10)); Table created. SYS@test>create user c##user1 identified by oracle; User created. SYS@test>drop user c##user1; User dropped. SYS@test>drop table test1; Table dropped. SYS@test>drop table test2; Table dropped. SYS@test>
查看xml格式的操作记录
[oracle@orcl12c ddl]$ pwd /u01/app/oracle/diag/rdbms/test/test/log/ddl [oracle@orcl12c ddl]$ [oracle@orcl12c ddl]$ ls log.xml [oracle@orcl12c ddl]$ more log.xml <msg time='2018-05-14T08:54:21.207+08:00' org_id='oracle' comp_id='rdbms' msg_id='opiexe:4705:2946163730' type='UNKNOWN' group='diag_adl' level='16' host_id='orcl12c.us.oracle.com' host_addr='192.168.2.18' pid='3385' version='1' con_uid='1' con_id='1' con_name='CDB$ROOT'> <txt>create table test1(c number) </txt> </msg> <msg time='2018-05-14T08:54:27.829+08:00' org_id='oracle' comp_id='rdbms' msg_id='opiexe:4705:2946163730' type='UNKNOWN' group='diag_adl' level='16' host_id='orcl12c.us.oracle.com' host_addr='192.168.2.18' pid='3385' con_uid='1' con_id='1' con_name='CDB$ROOT'> <txt>create table test2(c varchar2(10)) </txt> </msg> <msg time='2018-05-14T08:55:59.572+08:00' org_id='oracle' comp_id='rdbms' msg_id='opiexe:4705:2946163730' type='UNKNOWN' group='diag_adl' level='16' host_id='orcl12c.us.oracle.com' host_addr='192.168.2.18' pid='3385' con_uid='1' con_id='1' con_name='CDB$ROOT'> <txt>drop user c##user1 </txt> </msg> <msg time='2018-05-14T08:56:02.281+08:00' org_id='oracle' comp_id='rdbms' msg_id='opiexe:4705:2946163730' type='UNKNOWN' group='diag_adl' level='16' host_id='orcl12c.us.oracle.com' host_addr='192.168.2.18' pid='3385' con_uid='1' con_id='1' con_name='CDB$ROOT'> <txt>drop table test1 </txt> </msg> <msg time='2018-05-14T08:56:08.755+08:00' org_id='oracle' comp_id='rdbms' msg_id='opiexe:4705:2946163730' type='UNKNOWN' group='diag_adl' level='16' host_id='orcl12c.us.oracle.com' host_addr='192.168.2.18' pid='3385' con_uid='1' con_id='1' con_name='CDB$ROOT'> <txt>drop table test2 </txt> </msg> [oracle@orcl12c ddl]$
通过adrci 查看刚才的ddl操作记录
[oracle@orcl12c ddl]$ adrci ADRCI: Release 12.2.0.1.0 - Production on Mon May 14 08:57:33 2018 Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved. ADR base = "/u01/app/oracle" adrci> show log ADR Home = /u01/app/oracle/diag/rdbms/test/test: ************************************************************************* Output the results to file: /tmp/utsout_8590_139645_1.ado 2018-05-14 08:54:21.207000 +08:00 create table test1(c number) 2018-05-14 08:54:27.829000 +08:00 create table test2(c varchar2(10)) 2018-05-14 08:55:59.572000 +08:00 drop user c##user1 2018-05-14 08:56:02.281000 +08:00 drop table test1 2018-05-14 08:56:08.755000 +08:00 drop table test2 ~ ~
另外,在log目录下,也有ddl_test.log 文件
[oracle@orcl12c test]$ cd log [oracle@orcl12c log]$ ls ddl ddl_test.log debug hcs imdb test [oracle@orcl12c log]$ cat ddl_test.log 2018-05-14T08:54:21.207943+08:00 diag_adl:create table test1(c number) 2018-05-14T08:54:27.829114+08:00 diag_adl:create table test2(c varchar2(10)) 2018-05-14T08:55:59.572883+08:00 diag_adl:drop user c##user1 2018-05-14T08:56:02.281134+08:00 diag_adl:drop table test1 2018-05-14T08:56:08.755791+08:00 diag_adl:drop table test2 [oracle@orcl12c log]$ pwd /u01/app/oracle/diag/rdbms/test/test/log [oracle@orcl12c log]$end