Oracle查询表空间的每日增长量
---11g
SELECT a.snap_id, c.tablespace_name ts_name, to_char(to_date(a.rtime, 'mm/dd/yyyy hh24:mi:ss'), 'yyyy-mm-dd hh24:mi') rtime, round(a.tablespace_size * c.block_size / 1024 / 1024, 2) ts_size_mb, round(a.tablespace_usedsize * c.block_size / 1024 / 1024, 2) ts_used_mb, round((a.tablespace_size - a.tablespace_usedsize) * c.block_size / 1024 / 1024, 2) ts_free_mb, round(a.tablespace_usedsize / a.tablespace_size * 100, 2) pct_used FROM dba_hist_tbspc_space_usage a, (SELECT tablespace_id, substr(rtime, 1, 10) rtime, max(snap_id) snap_id FROM dba_hist_tbspc_space_usage nb group by tablespace_id, substr(rtime, 1, 10)) b, dba_tablespaces c, v$tablespace d where a.snap_id = b.snap_id and a.tablespace_id = b.tablespace_id and a.tablespace_id=d.TS# and d.NAME=c.tablespace_name and to_date(a.rtime, 'mm/dd/yyyy hh24:mi:ss') >=sysdate-30 order by a.tablespace_id,to_date(a.rtime, 'mm/dd/yyyy hh24:mi:ss') desc;
--- 12c
SELECT a.snap_id, a.con_id, e.name pdbname, c.tablespace_name ts_name, to_char(to_date(a.rtime, 'mm/dd/yyyy hh24:mi:ss'), 'yyyy-mm-dd hh24:mi') rtime, round(a.tablespace_size * c.block_size / 1024 / 1024, 2) ts_size_mb, round(a.tablespace_usedsize * c.block_size / 1024 / 1024, 2) ts_used_mb, round((a.tablespace_size - a.tablespace_usedsize) * c.block_size / 1024 / 1024, 2) ts_free_mb, round(a.tablespace_usedsize / a.tablespace_size * 100, 2) pct_used FROM cdb_hist_tbspc_space_usage a, (SELECT tablespace_id, nb.con_id, substr(rtime, 1, 10) rtime, max(snap_id) snap_id FROM dba_hist_tbspc_space_usage nb group by tablespace_id, nb.con_id,substr(rtime, 1, 10)) b, cdb_tablespaces c, v$tablespace d, V$CONTAINERS e where a.snap_id = b.snap_id and a.tablespace_id = b.tablespace_id and a.con_id=b.con_id and a.con_id=c.con_id and a.con_id=d.con_id and a.con_id=e.con_id and a.tablespace_id=d.TS# and d.NAME=c.tablespace_name and to_date(a.rtime, 'mm/dd/yyyy hh24:mi:ss') >=sysdate-30 order by a.CON_ID,a.tablespace_id,to_date(a.rtime, 'mm/dd/yyyy hh24:mi:ss') desc;
---其它sql
select u.snap_id, to_char(s.begin_interval_time, 'yyyy-mm-dd hh24') begin_time, to_char(s.end_interval_time, 'yyyy-mm-dd hh24') end_time, t.name, round(u.tablespace_size * ts.block_size / 1024 / 1024, 2) ts_size_mb, round(u.tablespace_usedsize * ts.block_size / 1024 / 1024, 2) ts_used_mb, round((u.tablespace_size - u.tablespace_usedsize) * ts.block_size / 1024 / 1024, 2) ts_free_mb, round(u.tablespace_usedsize / u.tablespace_size * 100, 2) pct_used from dba_hist_tbspc_space_usage u, v$tablespace t, dba_hist_snapshot s, dba_tablespaces ts where u.tablespace_id = t.ts# and u.snap_id = s.snap_id and t.name = ts.tablespace_name and s.instance_number = 1 and t.name = 'SYSTEM' and s.end_interval_time > sysdate - 7 order by snap_id desc; select u.snap_id, to_char(s.begin_interval_time, 'yyyy-mm-dd hh24') begin_time, to_char(s.end_interval_time, 'yyyy-mm-dd hh24') end_time, t.name, round(u.tablespace_size * ts.block_size / 1024 / 1024, 2) ts_size_mb, round(u.tablespace_usedsize * ts.block_size / 1024 / 1024, 2) ts_used_mb, round((u.tablespace_size - u.tablespace_usedsize) * ts.block_size / 1024 / 1024, 2) ts_free_mb, round(u.tablespace_usedsize / u.tablespace_size * 100, 2) pct_used from cdb_hist_tbspc_space_usage u, v$tablespace t, cdb_hist_snapshot s, cdb_tablespaces ts where u.tablespace_id = t.ts# and u.snap_id = s.snap_id and t.name = ts.tablespace_name and s.instance_number = 1 and u.CON_ID=t.CON_ID and u.CON_ID=s.CON_ID and u.CON_ID=ts.CON_ID and t.name = 'SYSTEM' and s.end_interval_time > sysdate - 7 order by snap_id desc;
如何估算oracle 数据库,数据库对象历史增长情况
-----最近七天数据库的增长情况,这个只是一个估算值。
select sum(space_used_total)/1024/1024/1024 "last 7 days db increase - G" from dba_hist_seg_stat s, dba_hist_seg_stat_obj o, dba_hist_snapshot sn where s.obj# = o.obj# and sn.snap_id = s.snap_id and begin_interval_time > sysdate-8 order by begin_interval_time /
以下再补充两个类似的脚本脚本来之网上:
scripts:查看数据库历史增长情况
查看数据库历史增长情况 此处是通过计算数据库所有表空间的历史增长情况来计算数据库历史情况。 --不含undo和temp
with tmp as (select rtime, sum(tablespace_usedsize_kb) tablespace_usedsize_kb, sum(tablespace_size_kb) tablespace_size_kb from (select rtime, e.tablespace_id, (e.tablespace_usedsize) * (f.block_size) / 1024 tablespace_usedsize_kb, (e.tablespace_size) * (f.block_size) / 1024 tablespace_size_kb 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_kb, tablespace_size_kb, (tablespace_usedsize_kb - LAG(tablespace_usedsize_kb, 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_kb) tablespace_usedsize_kb, sum(tablespace_size_kb) tablespace_size_kb from (select rtime, e.tablespace_id, (e.tablespace_usedsize) * (f.block_size) / 1024 tablespace_usedsize_kb, (e.tablespace_size) * (f.block_size) / 1024 tablespace_size_kb 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_kb, tablespace_size_kb, (tablespace_usedsize_kb - LAG(tablespace_usedsize_kb, 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
############################################################## SQL脚本:列出相关段对象在 快照时间内的使用空间的历史变化信息:
column owner format a16 column object_name format a36 column start_day format a11 column block_increase format 9999999999
select obj.owner, obj.object_name, to_char(sn.BEGIN_INTERVAL_TIME,'RRRR-MON-DD') start_day, sum(a.db_block_changes_delta) block_increase from dba_hist_seg_stat a, dba_hist_snapshot sn, dba_objects obj where sn.snap_id = a.snap_id and obj.object_id = a.obj# and obj.owner not in ('SYS','SYSTEM') and end_interval_time between to_timestamp('17-FEB-2014','DD-MON-RRRR') and to_timestamp('25-FEB-2014','DD-MON-RRRR') group by obj.owner, obj.object_name, to_char(sn.BEGIN_INTERVAL_TIME,'RRRR-MON-DD') order by obj.owner, obj.object_name ;
About Me
........................................................................................................................
● 本文作者:小麦苗,部分内容整理自网络,若有侵权请联系小麦苗删除
● 本文在itpub、博客园、CSDN和个人微 信公众号( xiaomaimiaolhr)上有同步更新
● 本文itpub地址: http://blog.itpub.net/26736162
● 本文博客园地址: http://www.cnblogs.com/lhrbest
● 本文CSDN地址: https://blog.csdn.net/lihuarongaini
● 本文pdf版、个人简介及小麦苗云盘地址: http://blog.itpub.net/26736162/viewspace-1624453/
● 数据库笔试面试题库及解答: http://blog.itpub.net/26736162/viewspace-2134706/
● DBA宝典今日头条号地址: http://www.toutiao.com/c/user/6401772890/#mid=1564638659405826
........................................................................................................................
● QQ群号: 230161599 、618766405
● 微 信群:可加我微 信,我拉大家进群,非诚勿扰
● 联系我请加QQ好友 ( 646634621 ),注明添加缘由
● 于 2019-09-01 06:00 ~ 2019-09-31 24:00 在西安完成
● 最新修改时间:2019-09-01 06:00 ~ 2019-09-31 24:00
● 文章内容来源于小麦苗的学习笔记,部分整理自网络,若有侵权或不当之处还请谅解
● 版权所有,欢迎分享本文,转载请保留出处
........................................................................................................................
● 小麦苗的微店: https://weidian.com/s/793741433?wfr=c&ifr=shopdetail
● 小麦苗出版的数据库类丛书: http://blog.itpub.net/26736162/viewspace-2142121/
● 小麦苗OCP、OCM、高可用网络班: http://blog.itpub.net/26736162/viewspace-2148098/
● 小麦苗腾讯课堂主页: https://lhr.ke.qq.com/
........................................................................................................................
使用 微 信客户端扫描下面的二维码来关注小麦苗的微 信公众号( xiaomaimiaolhr)及QQ群(DBA宝典)、添加小麦苗微 信, 学习最实用的数据库技术。
........................................................................................................................

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