Oracle表变更趋势追踪记录(转)

注意文章中的object_type='TABLE' 条件忽略了分区表“TABLE PARTITION”,各位看客使用的时候修改下即可

from http://www.myexception.cn/database/489598.html


这几天数据库上的用户表空间疯涨,一天的增长量达到了20~30GB,平时就4~5GB的增长量。问了开发商,他们也说不出个所以然。PS:那些鸟开发商,现在我已经对他们绝望了,什么都不知道。情急之下直接对该表空间进行了扩容,问题总算解决了。事后总想弄个明白,想知道是那张表导致的表空间增长如此之快,以免下次出现同样的问题又是不知所措。

google了一番后发现DBA_HIST_SEG_STAT可以看出对象的使用趋势 
构造如下SQL查询出每个时间段内数据库对象的增长量,其中DB_BLOCK_CHANGES_DELTA为块个数

select c.SNAP_ID,to_char(c.END_INTERVAL_TIME,'yyyy-mm-dd') SNAP_TIME,a.OWNER ,a.OBJECT_NAME, a.OBJECT_TYPE, b.DB_BLOCK_CHANGES_DELTA
from dba_objects a,
(select SNAP_ID,obj#,DB_BLOCK_CHANGES_DELTA from DBA_HIST_SEG_STAT where DB_BLOCK_CHANGES_DELTA > 20000 order by snap_id desc, DB_BLOCK_CHANGES_DELTA desc) b,
DBA_HIST_SNAPSHOT c
where a.object_id=b.obj# and object_type='TABLE' and b.SNAP_ID=c.SNAP_ID
order by DB_BLOCK_CHANGES_DELTA

下面的SQL查询出某个时间段内,数据库对象的变化大小,单位以换算成GB

select a.OBJECT_NAME, to_char(c.END_INTERVAL_TIME,'yyyy-mm-dd') SNAP_TIME, sum(b.DB_BLOCK_CHANGES_DELTA)/1024/1024 GB from dba_objects a,(select SNAP_ID,obj#,DB_BLOCK_CHANGES_DELTA from DBA_HIST_SEG_STAT where DB_BLOCK_CHANGES_DELTA > 20000 order by snap_id desc, DB_BLOCK_CHANGES_DELTA desc) b,DBA_HIST_SNAPSHOT c
where a.object_id=b.obj# and object_type='TABLE' and b.SNAP_ID=c.SNAP_ID
group by a.OBJECT_NAME,c.END_INTERVAL_TIME
order by GB 

简单介绍下DBA_HIST_SEG_STAT

DBA_HIST_SEG_STAT视图内记录了数据库实例启动以来段的变化信息,该视图的数据来自于v$segstat

Column Datatype NULL Description
SNAP_IDNUMBER Unique snapshot ID
DBIDNUMBER Database ID for the snapshot
INSTANCE_NUMBERNUMBER Instance number for the snapshot
TS#NUMBER Tablespace number
OBJ#NUMBER Dictionary object number
DATAOBJ#NUMBER Data object number
LOGICAL_READS_TOTALNUMBER Cumulative value for logical reads
LOGICAL_READS_DELTANUMBER Delta value for logical reads
BUFFER_BUSY_WAITS_TOTALNUMBER Cumulative value for buffer busy waits
BUFFER_BUSY_WAITS_DELTANUMBER Delta value for buffer busy waits
DB_BLOCK_CHANGES_TOTALNUMBER Cumulative value for db block changes
DB_BLOCK_CHANGES_DELTANUMBER Delta value for db block changes
PHYSICAL_READS_TOTALNUMBER Cumulative value for physical reads
PHYSICAL_READS_DELTANUMBER Delta value for physical reads
PHYSICAL_WRITES_TOTALNUMBER Cumulative value for physical writes
PHYSICAL_WRITES_DELTANUMBER Delta value for physical writes
PHYSICAL_READS_DIRECT_TOTALNUMBER Cumulative value for physical reads direct
PHYSICAL_READS_DIRECT_DELTANUMBER Delta value for physical reads direct
PHYSICAL_WRITES_DIRECT_TOTALNUMBER Cumulative value for physical writes direct
PHYSICAL_WRITES_DIRECT_DELTANUMBER Delta value for physical writes direct
ITL_WAITS_TOTALNUMBER Cumulative value for ITL waits
ITL_WAITS_DELTANUMBER Delta value for ITL waits
ROW_LOCK_WAITS_TOTALNUMBER Cumulative value for row lock waits
ROW_LOCK_WAITS_DELTANUMBER Delta value for row lock waits
GC_CR_BLOCKS_SERVED_TOTALNUMBER Cumulative value for global cache CR blocks served
GC_CR_BLOCKS_SERVED_DELTANUMBER Delta value for global cache CR blocks served
GC_CU_BLOCKS_SERVED_TOTALNUMBER Cumulative value for global cache current blocks served
GC_CU_BLOCKS_SERVED_DELTANUMBER Delta value for global cache current blocks served
GC_BUFFER_BUSY_TOTALNUMBER Cumulative value for global cache buffer busy
GC_BUFFER_BUSY_DELTANUMBER Delta value for global cache buffer busy
GC_CR_BLOCKS_RECEIVED_TOTALNUMBER Cumulative value for global cache CR blocks received
GC_CR_BLOCKS_RECEIVED_DELTANUMBER Delta value for global cache CR blocks received
GC_CU_BLOCKS_RECEIVED_TOTALNUMBER Cumulative value for global cache current blocks received
GC_CU_BLOCKS_RECEIVED_DELTANUMBER Delta value for global cache current blocks received
SPACE_USED_TOTALNUMBER Cumulative value for space used
SPACE_USED_DELTANUMBER Delta value for space used
SPACE_ALLOCATED_TOTALNUMBER Cumulative value for space allocated
SPACE_ALLOCATED_DELTANUMBER Delta value for space allocated
TABLE_SCANS_TOTALNUMBER Cumulative value for table scans
TABLE_SCANS_DELTANUMBER Delta value for table scans

顺便说一句DBA_HIST_TBSPC_SPACE_USAGE视图可以监控表空间的使用趋势

 

感谢杨帅军的指点

参考至:http://oracle.erkansaka.org/2007/09/how-to-determine-tables-with-highest.html

            http://docs.oracle.com/cd/B19306_01/server.102/b14237/statviews_3165.htm

本文原创,转载请注明出处、作者
如有错误,欢迎指正

邮箱:czmcj@163.com


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值