如何估算O racle 数据库每日数据增长量
场景:老板问 dba 小何,我们数据库现需要扩容文件系统,可以提供一些数据支撑吗?
回答:对于十年的dba小何,这问题简单地狠,我们根据所有表空间的历史增长情况来计算数据库历史情况。
原理:此处是通过计算数据库所有表空间的历史增长情况来计算数据库历史情况。
-- 不含undo 和temp
with tmp as
(select rtime,
sum(tablespace_usedsize_gb) tablespace_usedsize_gb,
sum(tablespace_size_gb) tablespace_size_gb
from (select rtime,
e.tablespace_id,
(e.tablespace_usedsize) * (f.block_size) /1024/1024/1024 tablespace_usedsize_gb,
(e.tablespace_size) * (f.block_size) /1024/1024/1024 tablespace_size_gb
from dba_hist_tbspc_space_usage e,
dba_tablespaces f,
v$tablespace g
where e.tablespace_id = g.TS#
and f.tablespace_name = g.NAME
and f.contents not in ('TEMPORARY','UNDO'))
group by rtime)
select tmp.rtime,
tablespace_usedsize_gb,
tablespace_size_gb,
(tablespace_usedsize_gb -
LAG(tablespace_usedsize_gb, 1, NULL) OVER(ORDER BY tmp.rtime)) AS DIFF_KB
from tmp,
(select max(rtime) rtime
from tmp
group by substr(rtime, 1, 10)) t2
where t2.rtime = tmp.rtime;
-- 含undo 和temp
with tmp as
(select min(rtime) rtime,
sum(tablespace_usedsize_gb) tablespace_usedsize_gb,
sum(tablespace_size_gb) tablespace_size_gb
from (select rtime,
e.tablespace_id,
(e.tablespace_usedsize) * (f.block_size) /1024/1024/1024 tablespace_usedsize_gb,
(e.tablespace_size) * (f.block_size) /1024/1024/1024 tablespace_size_gb
from dba_hist_tbspc_space_usage e,
dba_tablespaces f,
v$tablespace g
where e.tablespace_id = g.TS#
and f.tablespace_name = g.NAME)
group by rtime)
select tmp.rtime,
tablespace_usedsize_gb,
tablespace_size_gb,
(tablespace_usedsize_gb -
LAG(tablespace_usedsize_gb, 1, NULL) OVER(ORDER BY tmp.rtime)) AS DIFF_KB
from tmp,
(select min(rtime) rtime
from tmp
group by substr(rtime, 1, 10)) t2 where t2.rtime = tmp.rtime
参考:https://blog.csdn.net/lihuarongaini/article/details/101068291