通过alter table TABLE_NAME monitoring 语句,可以监控对表的delete、update、insert以及truncate等操作。
当执行此语句后,任何对表的DML操作均被记录到视图sys.DBA_TAB_MODIFICATIONS中,该视图的基表是sys.mon_mods$ table。
打开此项监控对于性能来说没有太多影响,因为这项机制是工作在内存,并周期性的对DBA_TAB_MODIFICATIONS视图进行刷新。
这个视图里的DML次数表示从最近一次收集统计信息后的DML次数,在9i中需要手动执行该语句将监控功能打开,而在10g中该项功能默认已经打开。
SQL> create table test1(A number,B varchar2(100));
Table created.
SQL> select monitoring from user_tables where table_name = 'TEST1';
MON
---
NO
SQL> alter table test1 monitoring;
Table altered.
SQL> select monitoring from user_tables where table_name = 'TEST1';
MON
---
YES
SQL> select * from user_tab_modifications;
no rows selected
SQL> insert into test1 values (1,'a');
1 row created.
SQL> insert into test1 values (2,'b');
1 row created.
SQL> insert into test1 values (3,'c');
1 row created.
SQL> commit;
Commit complete.
SQL> select * from user_tab_modifications;
no rows selected
SQL> exec dbms_stats.flush_database_monitoring_info;
PL/SQL procedure successfully completed.
SQL> alter session set nls_date_format='yyyymmdd hh24:mi:ss';
Session altered.
SQL> col table_name for a10
SQL> col partition_name for a5
SQL> col SUBPARTITION_NAME for a5
SQL> select * from user_tab_modifications;
TABLE_NAME PARTI SUBPA INSERTS UPDATES DELETES TIMESTAMP TRU
---------- ----- ----- ---------- ---------- ---------- ----------------- ---
TEST1 3 0 0 20090219 06:35:34 NO
当对表做统计信息收集之后,这些DML操作记录将被清空:
SQL> exec dbms_stats.gather_table_stats(user,'TEST1');
PL/SQL procedure successfully completed.
SQL> select * from user_tab_modifications;
no rows selected
上述测试都是在oracle 9i环境下进行:
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
PL/SQL Release 9.2.0.4.0 - Production
CORE 9.2.0.3.0 Production
TNS for Linux: Version 9.2.0.4.0 - Production
NLSRTL Version 9.2.0.4.0 - Production
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10972173/viewspace-555612/ ,如需转载,请注明出处,否则将追究法律责任。