DBA_TAB_MODIFICATIONS 视图学习

简介:

通过测试来学习DBA_TAB_MODIFICATIONS视图的作用

DBA_TAB_MODIFICATIONS describes modifications to all tables in the database that have been modified since the last time statistics were gathered on the tables. Its columns are the same as those in "ALL_TAB_MODIFICATIONS".

DBA_TAB_MODIFICATIONS描述的是收集完统计信息之后的数据库中所有表的DML操作。
Note:
This view is populated only for tables with the MONITORING attribute. It is intended for statistics collection over a long period of time. For performance reasons, the Oracle Database does not populate this view immediately when the actual modifications occur. Run the FLUSH_DATABASE_MONITORING_INFO procedure in the DBMS_STATS PL/SQL package to populate this view with the latest information. The ANALYZE_ANY system privilege is required to run this procedure.
SQL> desc dba_tab_modifications;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 TABLE_OWNER                                        VARCHAR2(128)
 TABLE_NAME                                         VARCHAR2(128)
 PARTITION_NAME                                     VARCHAR2(128)
 SUBPARTITION_NAME                                  VARCHAR2(128)
 INSERTS                                            NUMBER    ##插入
 UPDATES                                            NUMBER  ##更新
 DELETES                                            NUMBER  ##删除
 TIMESTAMP                                          DATE
 TRUNCATED                                          VARCHAR2(3)  ##截断
 DROP_SEGMENTS                                      NUMBER

SQL> 
SQL> select * from v$version where rownum=1;

BANNER
--------------------------------------------------------------------------------
    CON_ID
----------
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
         0
SQL> create table t1 as select *  from dba_objects;

Table created.
SQL> select table_owner,table_name,inserts,UPDATES,deletes,timestamp,truncated,drop_segments from sys.dba_tab_modifications where table_name='T1';

no rows selected

SQL> update t1 set object_id=1 where object_id=30;

1 row updated.

SQL> select table_owner,table_name,inserts,UPDATES,deletes,timestamp,truncated,drop_segments from sys.dba_tab_modifications where table_name='T1';

no rows selected

SQL> exec dbms_stats.flush_database_monitoring_info;

PL/SQL procedure successfully completed.

SQL> select table_owner,table_name,inserts,UPDATES,deletes,timestamp,truncated,drop_segments from sys.dba_tab_modifications where table_name='T1';

TABLE_OWNER
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
   INSERTS    UPDATES    DELETES TIMESTAMP               TRU DROP_SEGMENTS
---------- ---------- ---------- ----------------------- --- -------------
SYS
T1
         0          1          0 19-FEB-2018 06:59:33    NO              0

SQL> exec dbms_stats.flush_database_monitoring_info;

PL/SQL procedure successfully completed.

SQL> select table_owner,table_name,inserts,UPDATES,deletes,timestamp,truncated,drop_segments from sys.dba_tab_modifications where table_name='T1';

TABLE_OWNER
--------------------------------------------------------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
   INSERTS    UPDATES    DELETES TIMESTAMP               TRU DROP_SEGMENTS
---------- ---------- ---------- ----------------------- --- -------------
SYS
T1
         0          1          0 19-FEB-2018 06:59:33    NO              0

SQL> exec dbms_stats.gather_table_stats('SYS','T1');

PL/SQL procedure successfully completed.

SQL> select table_owner,table_name,inserts,UPDATES,deletes,timestamp,truncated,drop_segments from sys.dba_tab_modifications where table_name='T1';

no rows selected

SQL> 

小结:
1、dml操作不提交,也会记录到视图中。
2、考虑到性能问题,我们需要手动flush,视图中才会有记录。
3、收集完统计信息,视图中相关表记录置空,与官方文档描述一样

测试二:

SQL> alter system set "_dml_monitoring_enabled"=false scope=memory;

System altered.

SQL> delete from t1;

90974 rows deleted.

SQL> select table_owner,table_name,inserts,UPDATES,deletes,timestamp,truncated,drop_segments from sys.dba_tab_modifications where table_name='T1';

no rows selected

SQL> exec dbms_stats.flush_database_monitoring_info;

PL/SQL procedure successfully completed.

SQL> select table_owner,table_name,inserts,UPDATES,deletes,timestamp,truncated,drop_segments from sys.dba_tab_modifications where table_name='T1';

no rows selected

SQL> 

小结:
关闭监视器以后,不管我们做任何操作,此视图都不会记录dml的相关操作。










本文转自 roidba 51CTO博客,原文链接:http://blog.51cto.com/roidba/2071855,如需转载请自行联系原作者
目录
相关文章
SQL视图View(是一张虚拟的表)
SQL视图View(是一张虚拟的表)
|
前端开发
table布局的一些总结
table-layout作用就是让表格布局固定,使表格的宽度不会根据内容多少而动态变化。
163 0
table布局的一些总结
|
iOS开发
AppleWatch开发入门四——Table视图的应用
AppleWatch开发入门四——Table视图的应用
144 0
AppleWatch开发入门四——Table视图的应用
|
数据库 数据库管理
如何让普通用户可以对DBA_SOURCE视图进行闪回查询?
如何让普通用户可以对DBA_SOURCE视图进行闪回查询? 赋权:GRANT SELECT , FLASHBACK ON DBA_SOURCE TO LHR10;或:GRANT DBA,SELECT_CATALOG_ROLE TO LHR10;...
1227 0
用table布局和div布局的区别
table布局的渲染是将整个table全部渲染出来,如果网路不给力的情况下,整个table会卡死在页面div布局的话,页面渲染,会一个一个的div渲染,网页出现会一个一个出来,不管网速怎样,不会全局卡死
993 0