历史快照_实用脚本--合理估算oracle数据库及数据库对象历史增长情况
生活随笔
收集整理的這篇文章主要介紹了
历史快照_实用脚本--合理估算oracle数据库及数据库对象历史增长情况
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
概述
很多時候我們都需要估算oracle數據庫及數據庫對象歷史增長情況,來評估是否需要擴容,擴多少。下面介紹一下怎么通過AWR來查找一段時間內,數據庫及數據庫段對象(堆表、索引)等的空間增長信息。
DBA_HIST_SEG_STAT
在Oracle 10g開始awr自動負載倉庫引入了dba_hist_seg_stat視圖,該視圖記錄了快照時間內segment-level段級的歷史統計信息:
DBA_HIST_SEG_STAT displays historical information about segment-level statistics. This view captures the top segments based on a set of criteria and captures information from V$SEGSTAT. The total value is the value of the statistics since instance startup. The delta value is the value of the statistics from the BEGIN_INTERVAL_TIME to the END_INTERVAL_TIME in the DBA_HIST_SNAPSHOT view.查看數據庫歷史增長情況
此處是通過計算數據庫所有表空間的歷史增長情況來計算數據庫歷史情況。
1、不含undo和temp
with tmp as(select rtime,sum(tablespace_usedsize_kb) tablespace_usedsize_kb,sum(tablespace_size_kb) tablespace_size_kbfrom (select rtime,e.tablespace_id,(e.tablespace_usedsize) * (f.block_size) / 1024 tablespace_usedsize_kb,(e.tablespace_size) * (f.block_size) / 1024 tablespace_size_kbfrom dba_hist_tbspc_space_usage e,dba_tablespaces f,v$tablespace gwhere e.tablespace_id = g.TS#and f.tablespace_name = g.NAMEand 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_KBfrom tmp,(select max(rtime) rtimefrom tmpgroup by substr(rtime, 1, 10)) t2where t2.rtime = tmp.rtime;2、含undo和temp
with tmp as(select min(rtime) rtime,sum(tablespace_usedsize_kb) tablespace_usedsize_kb,sum(tablespace_size_kb) tablespace_size_kbfrom (select rtime,e.tablespace_id,(e.tablespace_usedsize) * (f.block_size) / 1024 tablespace_usedsize_kb,(e.tablespace_size) * (f.block_size) / 1024 tablespace_size_kbfrom dba_hist_tbspc_space_usage e,dba_tablespaces f,v$tablespace gwhere 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_KBfrom tmp,(select min(rtime) rtimefrom tmpgroup by substr(rtime, 1, 10)) t2 where t2.rtime = tmp.rtime列出相關段對象在快照時間內的使用空間的歷史變化信息
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('01-MAY-2019', 'DD-MON-RRRR') and to_timestamp('05-MAY-2019', '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;后面會分享更多devops和DBA方面的內容,感興趣的朋友可以關注一下~
總結
以上是生活随笔為你收集整理的历史快照_实用脚本--合理估算oracle数据库及数据库对象历史增长情况的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 画图设置横纵坐标_Pyth
- 下一篇: mysql存储word文档_使用MySQ