计算每日增长量,预测数据库的增长

表空间点检是DBA日常点检中上一项内容,对一个数据量增长迅速的数据库,这项内容就更不能忽略了.为了避免由空间不足导致系统不能使用,我们一般会通过执行写好的SQL查看表空间使用情况.如果你手上刚好又有多台数据库要维护,你会想到把这多台数据库的表空间的使用情况,放到一个表中,每天点只需要查看一下这个表就OK.这些数据统计了一段时间,你有一种想分析这些数据的冲动吧.分析这些数据可以得到资料的每天增长量,预测资料增长,提前添加数据文件.

如果你已经这样做了下面的内容,就没有必要看了,如你没有这样做,我将带你实现.

    实现过程:

1.创建用于存放表空间使用情况的表:check_tbs

create table oak.check_tbs(
host varchar2(16),
tablespace_name varchar2(50),
megs_alloc number(8,2),
megs_free number(8,2),
megs_used number(8,2),
Pct_Free number(5,2),
pct_used number(5,2),
max number(8,2),
recorddate date) tablespace tbs_oak;
2.
sys的帐号下添加一job用于没天收集表空间使用情况

insert into oak.check_tbs
select a.host, a.tablespace_name,
       round(a.bytes_alloc / 1024 / 1024, 2) megs_alloc,
       round(nvl(b.bytes_free, 0) / 1024 / 1024, 2) megs_free,
       round((a.bytes_alloc - nvl(b.bytes_free, 0)) / 1024 / 1024, 2) megs_used,
       round((nvl(b.bytes_free, 0) / a.bytes_alloc) * 100, 2) Pct_Free,
       100 - round((nvl(b.bytes_free, 0) / a.bytes_alloc) * 100, 2) Pct_used,
       round(maxbytes / 1048576, 2) Max,
       a.recorddate
  from (select '10.182.15.55' as host , f.tablespace_name,
               sum(f.bytes) bytes_alloc,
               sum(decode(f.autoextensible, 'YES', f.maxbytes, 'NO', f.bytes)) maxbytes, sysdate as recorddate
          from dba_data_files f
         group by tablespace_name) a,
       (select f.tablespace_name, sum(f.bytes) bytes_free
          from sys.dba_free_space f
         group by tablespace_name) b
 where a.tablespace_name = b.tablespace_name(+)

union all
select '10.182.15.55' as host, h.tablespace_name,
       round(sum(h.bytes_free + h.bytes_used) / 1048576, 2) megs_alloc,
       round(sum((h.bytes_free + h.bytes_used) - nvl(p.bytes_used, 0)) /
             1048576,
             2) megs_free,
       round(sum(nvl(p.bytes_used, 0)) / 1048576, 2) megs_used,
       round((sum((h.bytes_free + h.bytes_used) - nvl(p.bytes_used, 0)) /
             sum(h.bytes_used + h.bytes_free)) * 100,
             2) Pct_Free,
       100 -
       round((sum((h.bytes_free + h.bytes_used) - nvl(p.bytes_used, 0)) /
             sum(h.bytes_used + h.bytes_free)) * 100,
             2) pct_used,
       round(f.maxbytes / 1048576, 2) max,
       sysdate as recorddate
  from sys.v_$TEMP_SPACE_HEADER h,
       sys.v_$Temp_extent_pool  p,
       dba_temp_files           f
 where p.file_id(+) = h.file_id
   and p.tablespace_name(+) = h.tablespace_name
   and f.file_id = h.file_id
   and f.tablespace_name = h.tablespace_name
 group by h.tablespace_name, f.maxbytes;

3.创建一临时表用于某一表空间每天的使用量

create global temporary table tbs_temp

(used number(8),

 recorddate date);

4.向临时表中插入数据,为统计每天的增长量做准备

insert into tbs_temp

select t.megs_used, trunc(t.recorddate)

from checktablespace t

where t.ip='10.182.15.30'

and t.tablespace_name='TBS_SFCDATA'

and t.recorddate > trunc(sysdate -30);

5.计算每天的增长量

select a.used-b.used, a.recorddate

from tbs_temp a, tbs_temp b

where a.recorddate=b.recorddate+1;

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7419833/viewspace-615043/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/7419833/viewspace-615043/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值