精心总结--Oracle查询表空间的每日增长量和历史情况统计脚本

数据库 其他数据库
今天主要总结一下Oracle表空间每日增长和历史情况统计的一些脚本,仅供参考。

今天主要总结一下Oracle表空间每日增长和历史情况统计的一些脚本,仅供参考。

[[279040]]

11g统计表空间的每日增长量

  1. SELECT a.snap_id, 
  2.  c.tablespace_name ts_name, 
  3.  to_char(to_date(a.rtime, 'mm/dd/yyyy hh24:mi:ss'), 
  4.  'yyyy-mm-dd hh24:mi') rtime, 
  5.  round(a.tablespace_size * c.block_size / 1024 / 1024, 2) ts_size_mb, 
  6.  round(a.tablespace_usedsize * c.block_size / 1024 / 1024, 2) ts_used_mb, 
  7.  round((a.tablespace_size - a.tablespace_usedsize) * c.block_size / 1024 / 1024, 
  8.  2) ts_free_mb, 
  9.  round(a.tablespace_usedsize / a.tablespace_size * 100, 2) pct_used 
  10.  FROM dba_hist_tbspc_space_usage a, 
  11.  (SELECT tablespace_id, 
  12.  substr(rtime, 1, 10) rtime, 
  13.  max(snap_id) snap_id 
  14.  FROM dba_hist_tbspc_space_usage nb 
  15.  group by tablespace_id, substr(rtime, 1, 10)) b, 
  16.  dba_tablespaces c, 
  17.  v$tablespace d 
  18.  where a.snap_id = b.snap_id 
  19.  and a.tablespace_id = b.tablespace_id 
  20.  and a.tablespace_id = d.TS# 
  21.  and d.NAME = c.tablespace_name 
  22.  and to_date(a.rtime, 'mm/dd/yyyy hh24:mi:ss') >= sysdate - 30 
  23.  order by a.tablespace_id, to_date(a.rtime, 'mm/dd/yyyy hh24:mi:ss') desc; 

精心总结--Oracle查询表空间的每日增长量和历史情况统计脚本

12c统计表空间的每日增长量

  1. SELECT a.snap_id, 
  2.  a.con_id, 
  3.  e.name pdbname, 
  4.  c.tablespace_name ts_name, 
  5.  to_char(to_date(a.rtime, 'mm/dd/yyyy hh24:mi:ss'), 'yyyy-mm-dd hh24:mi') rtime, 
  6.  round(a.tablespace_size * c.block_size / 1024 / 1024, 2) ts_size_mb, 
  7.  round(a.tablespace_usedsize * c.block_size / 1024 / 1024, 2) ts_used_mb, 
  8.  round((a.tablespace_size - a.tablespace_usedsize) * c.block_size / 1024 / 1024, 
  9.  2) ts_free_mb, 
  10.  round(a.tablespace_usedsize / a.tablespace_size * 100, 2) pct_used 
  11.  FROM cdb_hist_tbspc_space_usage a,  
  12.  (SELECT tablespace_id, 
  13.  nb.con_id, 
  14.  substr(rtime, 1, 10) rtime, 
  15.  max(snap_id) snap_id 
  16.  FROM dba_hist_tbspc_space_usage nb 
  17.  group by tablespace_id, nb.con_id,substr(rtime, 1, 10)) b, 
  18.  cdb_tablespaces c, 
  19.  v$tablespace d, 
  20.  V$CONTAINERS e 
  21.  where a.snap_id = b.snap_id 
  22.  and a.tablespace_id = b.tablespace_id 
  23.  and a.con_id=b.con_id 
  24.  and a.con_id=c.con_id 
  25.  and a.con_id=d.con_id 
  26.  and a.con_id=e.con_id 
  27.  and a.tablespace_id=d.TS# 
  28.  and d.NAME=c.tablespace_name 
  29.  and to_date(a.rtime, 'mm/dd/yyyy hh24:mi:ss') >=sysdate-30 
  30.  order by a.CON_ID,a.tablespace_id,to_date(a.rtime, 'mm/dd/yyyy hh24:mi:ss') desc; 

估算oracle 数据库,数据库对象历史增长情况

 

最近七天数据库的增长情况,这个只是一个估算值。

  1. select sum(space_used_total) / 1024 / 1024 / 1024 "last 7 days db increase - G" 
  2.  from dba_hist_seg_stat s, dba_hist_seg_stat_obj o, dba_hist_snapshot sn 
  3.  where s.obj# = o.obj# 
  4.  and ssn.snap_id = s.snap_id 
  5.  and begin_interval_time > sysdate - 8 
  6.  order by begin_interval_time 

精心总结--Oracle查询表空间的每日增长量和历史情况统计脚本

查看数据库历史增长情况

此处是通过计算数据库所有表空间的历史增长情况来计算数据库历史情况。

不含undo和temp:

  1. with tmp as ( 
  2. select rtime,sum(tablespace_usedsize_kb) tablespace_usedsize_kb, sum(tablespace_size_kb) tablespace_size_kb  
  3. from (select rtime, e.tablespace_id, (e.tablespace_usedsize)*(f.block_size)/1024 tablespace_usedsize_kb,  
  4. (e.tablespace_size)*(f.block_size)/1024 tablespace_size_kb from dba_hist_tbspc_space_usage e, dba_tablespaces f, v$tablespace g 
  5.  where e.tablespace_id = g.TS# and f.tablespace_name = g.NAME and f.contents not in ('TEMPORARY','UNDO')) group by rtime)  
  6. select tmp.rtime, tablespace_usedsize_kb, tablespace_size_kb,(tablespace_usedsize_kb - LAG(tablespace_usedsize_kb, 1, NULL) 
  7.  OVER(ORDER BY tmp.rtime)) AS DIFF_KB from tmp, (select max(rtime) rtime from tmp group by substr(rtime, 1, 10)) t2 
  8.  where t2.rtime = tmp.rtime; 

含undo和temp:

  1. with tmp as ( 
  2. select min(rtime) rtime, sum(tablespace_usedsize_kb) tablespace_usedsize_kb, sum(tablespace_size_kb) tablespace_size_kb  
  3. from (select rtime, e.tablespace_id, (e.tablespace_usedsize) * (f.block_size) / 1024 tablespace_usedsize_kb,  
  4. (e.tablespace_size) * (f.block_size) / 1024 tablespace_size_kb from dba_hist_tbspc_space_usage e, dba_tablespaces f, v$tablespace g  
  5. where e.tablespace_id = g.TS# and f.tablespace_name = g.NAME) group by rtime)  
  6. select tmp.rtime, tablespace_usedsize_kb, tablespace_size_kb, (tablespace_usedsize_kb-LAG(tablespace_usedsize_kb, 1, NULL) 
  7. OVER(ORDER BY tmp.rtime)) AS DIFF_KB from tmp, (select min(rtime) rtime from tmp group by substr(rtime, 1, 10)) t2  
  8. where t2.rtime = tmp.rtime 

精心总结--Oracle查询表空间的每日增长量和历史情况统计脚本

精心总结--Oracle查询表空间的每日增长量和历史情况统计脚本

列出相关段对象在 快照时间内的使用空间的历史变化信息

  1. select obj.owner, 
  2.  obj.object_name, 
  3.  to_char(sn.BEGIN_INTERVAL_TIME, 'RRRR-MON-DD') start_day, 
  4.  sum(a.db_block_changes_delta) block_increase 
  5.  from dba_hist_seg_stat a, dba_hist_snapshot sn, dba_objects obj 
  6.  where sn.snap_id = a.snap_id 
  7.  and obj.object_id = a.obj# 
  8.  and obj.owner not in ('SYS', 'SYSTEM') 
  9.  and end_interval_time between to_timestamp('01-OCT-2019', 'DD-MON-RRRR') and 
  10.  to_timestamp('09-OCT-2019', 'DD-MON-RRRR') 
  11.  group by obj.owner, 
  12.  obj.object_name, 
  13.  to_char(sn.BEGIN_INTERVAL_TIME, 'RRRR-MON-DD') 
  14.  order by obj.owner, obj.object_name; 

责任编辑:赵宁宁 来源: 今日头条
相关推荐

2010-11-16 11:40:04

Oracle查询表空间

2010-10-27 14:41:45

Oracle查询用户表

2010-11-16 16:26:42

Oracle查询用户表

2011-04-13 09:31:50

Oracle

2009-10-21 16:03:06

Oracle查询用户表

2009-05-21 09:24:42

表空间查询Oracle

2010-11-16 10:32:01

Oracle创建表空间

2010-11-16 11:32:54

ORACLE增加表空间

2011-08-04 16:50:25

Oracle数据库表空间

2010-04-15 14:18:30

Oracle创建

2010-10-29 10:22:21

Oracle表空间

2010-11-16 11:17:41

Oracle表空间大小

2010-11-16 10:15:24

oracle创建表空间

2010-04-15 14:39:56

Oracle创建表空间

2022-01-26 07:18:57

oracle临时表空间数据库

2010-04-28 17:59:19

Oracle表空间

2011-03-16 09:42:27

Oracle临时表

2010-04-16 10:00:06

Oracle查看表空间

2009-11-02 18:03:25

Oracle用户表空间

2020-07-24 08:11:04

Java8ava5语言
点赞
收藏

51CTO技术栈公众号