暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Oracle 统计信息-对表的监控

oracleEDU 2017-08-21
1760

实施对表的监控,查看一个表发生了多少次DML动作

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.  统计只从上一次统计信息收集以来的修改

dba_tab_modifications

all_tab_modifications

user_tab_modifications

这几个视图收集了表自从上一次分析之后的DML累积次数。但是要注意,考虑到性能的影响,Oracle并不是实时统计这个数据的,在Oracle9i之前,约3个小时SMON进程会刷新一次数据,而Oracle9i以后这个时间间隔变成了15分钟。

因此以较高的频率来实时监控这个表的话,得到的并不是当前的准确数据。Oracle在dbms_stat包中提供了一个过程来手动刷新统计数据,假如在一天的业务低峰期采集一次数据的话,可以先执行该过程,就能得到较为准确的数据。但是,不建议在业务高峰期执行该过程。

EXEC DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO;

在Oracle10g之前,必须手工开启表的monitoring属性,才会将DML统计信息收集到这个视图中。可以通过dba_tables.monitoring列查看表是否已经开启了监控。

alter table test monitoring;

Oracle10g之后,只要statistics_level是TYPICAL(默认)或者ALL,就能自动收集信息了,即使给表设置为nomonitoring也不能阻止,这个表的属性已经被废弃了。

SQL> desc dba_tab_modifications

 Name   Null    Type

 ----------------------------------------- -------- ----------------------------

 TABLE_OWNER    VARCHAR2(30)

 TABLE_NAME            VARCHAR2(30)

 PARTITION_NAME    VARCHAR2(30)

 SUBPARTITION_NAME    VARCHAR2(30)

 INSERTS                    NUMBER

 UPDATES            NUMBER

 DELETES                    NUMBER

 TIMESTAMP            DATE

 TRUNCATED            VARCHAR2(3)

 DROP_SEGMENTS    NUMBER

例子来了

SQL> create table scott.e as select * from scott.emp;

Table created.

SQL> exec dbms_stats.gather_table_stats('SCOTT','E');

PL/SQL procedure successfully completed.

SQL> select TABLE_OWNER,TABLE_NAME,INSERTS from dba_tab_modifications where TABLE_OWNER='SCOTT' and TABLE_NAME='E';

no rows selected

模拟统计信息之后的DML动作

一次插入,一次更新,一次删除

SQL> insert into scott.E(empno,ename) values(1,'jerry');

1 row created.

SQL> update scott.e set sal=100 where ename in('SCOTT','SMITH');

2 rows updated.

SQL> delete from scott.e where ename = 'SCOTT';

1 row deleted.

SQL> commit;

SQL> select TABLE_OWNER,TABLE_NAME,INSERTS from dba_tab_modifications where TABLE_OWNER='SCOTT' and TABLE_NAME='E';

no rows selected    #信息不实时,等待15分钟

手工调用更新信息

SQL> exec dbms_stats.flush_database_monitoring_info;

PL/SQL procedure successfully completed.

SQL> select table_owner,table_name,inserts,deletes,updates from dba_tab_modifications where table_owner='SCOTT' and table_name='E';

TABLE_OWNE TABLE_NAME INSERTS DELETES UPDATES

----------     ----------     -------     -------     -------

SCOTT   E    1        1         2

SQL> select table_name,num_rows from dba_tables where table_name='E' and owner='SCOTT';

TABLE_NAME   NUM_ROWS

---------- ----------

E   15

再次收集统计信息:

SQL> exec dbms_stats.gather_table_stats('SCOTT','E');

PL/SQL procedure successfully completed.

SQL>  select TABLE_OWNER ,TABLE_NAME,INSERTS,DELETES,UPDATES  from   DBA_TAB_MODIFICATIONS

where TABLE_OWNER='SCOTT' and TABLE_NAME='E'   ;

no rows selected

最后修改时间:2021-04-28 19:52:45
文章转载自oracleEDU,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论