如何编写Oracle查询表空间的每日增长量和历史情况统计的脚本
如何编写Oracle查询表空间的每日增长量和历史情况统计的脚本,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。
今天主要总结一下Oracle表空间每日增长和历史情况统计的一些脚本,仅供参考。
11g统计表空间的每日增长量
SELECTa.snap_id,c.tablespace_namets_name,to_char(to_date(a.rtime,'mm/dd/yyyyhh34:mi:ss'),'yyyy-mm-ddhh34: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_usedFROMdba_hist_tbspc_space_usagea,(SELECTtablespace_id,substr(rtime,1,10)rtime,max(snap_id)snap_idFROMdba_hist_tbspc_space_usagenbgroupbytablespace_id,substr(rtime,1,10))b,dba_tablespacesc,v$tablespacedwherea.snap_id=b.snap_idanda.tablespace_id=b.tablespace_idanda.tablespace_id=d.TS#andd.NAME=c.tablespace_nameandto_date(a.rtime,'mm/dd/yyyyhh34:mi:ss')>=sysdate-30orderbya.tablespace_id,to_date(a.rtime,'mm/dd/yyyyhh34:mi:ss')desc;
12c统计表空间的每日增长量
SELECTa.snap_id,a.con_id,e.namepdbname,c.tablespace_namets_name,to_char(to_date(a.rtime,'mm/dd/yyyyhh34:mi:ss'),'yyyy-mm-ddhh34: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_usedFROMcdb_hist_tbspc_space_usagea,(SELECTtablespace_id,nb.con_id,substr(rtime,1,10)rtime,max(snap_id)snap_idFROMdba_hist_tbspc_space_usagenbgroupbytablespace_id,nb.con_id,substr(rtime,1,10))b,cdb_tablespacesc,v$tablespaced,V$CONTAINERSewherea.snap_id=b.snap_idanda.tablespace_id=b.tablespace_idanda.con_id=b.con_idanda.con_id=c.con_idanda.con_id=d.con_idanda.con_id=e.con_idanda.tablespace_id=d.TS#andd.NAME=c.tablespace_nameandto_date(a.rtime,'mm/dd/yyyyhh34:mi:ss')>=sysdate-30orderbya.CON_ID,a.tablespace_id,to_date(a.rtime,'mm/dd/yyyyhh34:mi:ss')desc;
估算oracle 数据库,数据库对象历史增长情况
最近七天数据库的增长情况,这个只是一个估算值。
selectsum(space_used_total)/1024/1024/1024"last7daysdbincrease-G"fromdba_hist_seg_stats,dba_hist_seg_stat_objo,dba_hist_snapshotsnwheres.obj#=o.obj#andssn.snap_id=s.snap_idandbegin_interval_time>sysdate-8orderbybegin_interval_time
查看数据库历史增长情况
此处是通过计算数据库所有表空间的历史增长情况来计算数据库历史情况。
不含undo和temp:
withtmpas(selectrtime,sum(tablespace_usedsize_kb)tablespace_usedsize_kb,sum(tablespace_size_kb)tablespace_size_kbfrom(selectrtime,e.tablespace_id,(e.tablespace_usedsize)*(f.block_size)/1024tablespace_usedsize_kb,(e.tablespace_size)*(f.block_size)/1024tablespace_size_kbfromdba_hist_tbspc_space_usagee,dba_tablespacesf,v$tablespacegwheree.tablespace_id=g.TS#andf.tablespace_name=g.NAMEandf.contentsnotin('TEMPORARY','UNDO'))groupbyrtime)selecttmp.rtime,tablespace_usedsize_kb,tablespace_size_kb,(tablespace_usedsize_kb-LAG(tablespace_usedsize_kb,1,NULL)OVER(ORDERBYtmp.rtime))ASDIFF_KBfromtmp,(selectmax(rtime)rtimefromtmpgroupbysubstr(rtime,1,10))t2wheret2.rtime=tmp.rtime;
含undo和temp:
withtmpas(selectmin(rtime)rtime,sum(tablespace_usedsize_kb)tablespace_usedsize_kb,sum(tablespace_size_kb)tablespace_size_kbfrom(selectrtime,e.tablespace_id,(e.tablespace_usedsize)*(f.block_size)/1024tablespace_usedsize_kb,(e.tablespace_size)*(f.block_size)/1024tablespace_size_kbfromdba_hist_tbspc_space_usagee,dba_tablespacesf,v$tablespacegwheree.tablespace_id=g.TS#andf.tablespace_name=g.NAME)groupbyrtime)selecttmp.rtime,tablespace_usedsize_kb,tablespace_size_kb,(tablespace_usedsize_kb-LAG(tablespace_usedsize_kb,1,NULL)OVER(ORDERBYtmp.rtime))ASDIFF_KBfromtmp,(selectmin(rtime)rtimefromtmpgroupbysubstr(rtime,1,10))t2wheret2.rtime=tmp.rtime
列出相关段对象在 快照时间内的使用空间的历史变化信息
selectobj.owner,obj.object_name,to_char(sn.BEGIN_INTERVAL_TIME,'RRRR-MON-DD')start_day,sum(a.db_block_changes_delta)block_increasefromdba_hist_seg_stata,dba_hist_snapshotsn,dba_objectsobjwheresn.snap_id=a.snap_idandobj.object_id=a.obj#andobj.ownernotin('SYS','SYSTEM')andend_interval_timebetweento_timestamp('01-OCT-2019','DD-MON-RRRR')andto_timestamp('09-OCT-2019','DD-MON-RRRR')groupbyobj.owner,obj.object_name,to_char(sn.BEGIN_INTERVAL_TIME,'RRRR-MON-DD')orderbyobj.owner,obj.object_name;
看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注亿速云行业资讯频道,感谢您对亿速云的支持。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。