首页 > 数据库 >【Oracle】Show the change history of tbs' size

【Oracle】Show the change history of tbs' size

时间:2023-06-01 09:35:00浏览次数:60  
标签:1024 name Show tbs 999 tablespace Oracle id con

 

注意:

脚本都从dba_hist_tbspc_space_usage系统视图获取数据,但是这个系统视图中保存的数据的时间是依赖AWR采样数据保留期限的。

所以你从这个系统视图可能查找不出很早之前的表空间数据使用情况,如果需要历史的表空间使用数据,可能需要定期采集数据并存储到起来。

 

In non multitentant DB
-- WX:DBAJOE399 --

set linesize 860;
set pagesize 120;
alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
col con_id for 999
col name for a16
col ts# for 999
col ts_mb for 999,999,999.90
col max_mb for 999,999,999.90
col used_mb for 999,999,999.90
col last_mb for 999,999,999.90
col incr for 999,999.90


select * from (
  select v.con_id
        ,v.name
        ,v.ts#
        ,s.instance_number
        ,h.tablespace_size
       * p.value/1024/1024              ts_mb
        ,h.tablespace_maxsize
       * p.value/1024/1024              max_mb
        ,h.tablespace_usedsize
       * p.value/1024/1024              used_mb
        ,to_date(h.rtime, 'MM/DD/YYYY HH24:MI:SS') resize_time
        ,lag(h.tablespace_usedsize * p.value/1024/1024, 1, h.tablespace_usedsize * p.value/1024/1024)
         over (partition by v.ts# order by h.snap_id) last_mb
        ,(h.tablespace_usedsize * p.value/1024/1024)
       - lag(h.tablespace_usedsize * p.value/1024/1024, 1, h.tablespace_usedsize * p.value/1024/1024)
         over (partition by v.con_id, v.ts# order by h.snap_id) incr
    from dba_hist_tbspc_space_usage     h
       , dba_hist_snapshot              s
       , v$tablespace                   v
       , cdb_tablespaces                t
       , v$parameter                    p
   where h.tablespace_id                = v.ts#
     --and h.con_id                       = s.con_id
     and h.con_id                       = v.con_id
     and h.con_id                       = t.con_id
     and v.name                         = t.tablespace_name
     and v.con_id                       = t.con_id
     and t.contents                not in ('UNDO', 'TEMPORARY')
     and p.name                         = 'db_block_size'
     and h.snap_id                      = s.snap_id
         /* For a specific time */
     and s.begin_interval_time          > sysdate - 7
         /* For a specific tablespace */
     and v.name =upper('&tablespace_name')
order by v.con_id, v.name, h.snap_id asc)
   where incr > 0;

 

In multitentant DB

set linesize 860;
set pagesize 120;
alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
col con_id for 999
col name for a16
col ts# for 999
col ts_mb for 999,999,999.90
col max_mb for 999,999,999.90
col used_mb for 999,999,999.90
col last_mb for 999,999,999.90
col incr for 999,999.90


select * from (
  select v.con_id
        ,v.name
        ,v.ts#
        ,s.instance_number
        ,h.tablespace_size
       * p.value/1024/1024              ts_mb
        ,h.tablespace_maxsize
       * p.value/1024/1024              max_mb
        ,h.tablespace_usedsize
       * p.value/1024/1024              used_mb
        ,to_date(h.rtime, 'MM/DD/YYYY HH24:MI:SS') resize_time
        ,lag(h.tablespace_usedsize * p.value/1024/1024, 1, h.tablespace_usedsize * p.value/1024/1024)
         over (partition by v.ts# order by h.snap_id) last_mb
        ,(h.tablespace_usedsize * p.value/1024/1024)
       - lag(h.tablespace_usedsize * p.value/1024/1024, 1, h.tablespace_usedsize * p.value/1024/1024)
         over (partition by v.con_id, v.ts# order by h.snap_id) incr
    from dba_hist_tbspc_space_usage     h
       , dba_hist_snapshot              s
       , v$tablespace                   v
       , cdb_tablespaces                t
       , v$parameter                    p
   where h.tablespace_id                = v.ts#
     --and h.con_id                       = s.con_id
     and h.con_id                       = v.con_id
     and h.con_id                       = t.con_id
     and v.name                         = t.tablespace_name
     and v.con_id                       = t.con_id
     and t.contents                not in ('UNDO', 'TEMPORARY')
     and p.name                         = 'db_block_size'
     and h.snap_id                      = s.snap_id
         /* For a specific time */
     and s.begin_interval_time          > sysdate - 7
         /* For a specific tablespace */
     and v.name =upper('&tablespace_name')
order by v.con_id, v.name, h.snap_id asc)
   where incr > 0;

  

 

标签:1024,name,Show,tbs,999,tablespace,Oracle,id,con
From: https://www.cnblogs.com/Jeona/p/17447977.html

相关文章

  • 【Oracle】Generate the tablespace creation in a time
     此脚本的使用场景是需要使用datapump方式进行数据迁移时,需要在目标数据库上创建对应的表空间,这时对于表空间数量比较多的系统,比如peoplesoft来说,手工单独创建表空间会是一个比较麻烦的事情。以下脚本在源数据库上运行,获取表空间的创建脚本,然后只需对路径相应修改即可使用。......
  • oracle 最大IOPS使用率和IOMBPS使用率监控 19c
    pdb最大iops使用率监控指标获取通过字典DBA_HIST_RSRC_PDB_METRIC分析具体字段为IOPS_THROTTLE_EXEMPT、IOMBPS_THROTTLE_EXEMPT一般最大值超过5就要告警了参数iops_throttle_exempt IndicateshowmuchoftheI/OpersecondinthecurrentPDBwasexemptedfromt......
  • ORACLE 并行度监控 19c
    oracle并行度查看通过v$resource_limit中的parallel_max_servers参数来设置初始值官方对于parallel_max_servers参数设置parallel_max_servers=PARALLEL_THREADS_PER_CPU*CPU_COUNT*concurrent_parallel_users*5Intheformula,thevalueassignedtoconcurrent......
  • Oracle 12c/19c PDB数据库配置自动启动
    在Oracle12c/19c多租户环境中,默认情况下,使用startup命令启动数据库实例后,你会发现PDB数据库的状态为MOUNT状态,PDB不会随着CDB启动而启动。如下例子所示:SQL> startupORACLE instance started.Total System Global Area 2432695872 bytesFixed Size          ......
  • 查看nebula版本号 console里show hosts graph
    (root@nebula)[(none)]>showhostsgraph+-------------+------+----------+---------+--------------+---------+|Host|Port|Status|Role|GitInfoSha|Version|+-------------+------+----------+---------+--------------+---------+|&q......
  • 【Oracle】Clean all objects belong to particular the user but not using drop use
      #--WX:DBAJOE399--DEST_SCHEMA=Expected_user_namesqlplus/assysdba<<!EOFsetserveroutputonsetechooffsetfeedbackoffWHENEVERSQLERROREXIT1WHENEVEROSEEROREXIT1altersessionsetcurrent_schema=${DEST_SCHEMA};purgedba......
  • 【Oracle】Check size of datafiles and tempfile tablespaces used in CDB and PDB
       --WX:DBAJOE399--setline200pages999columnnamefora10columntablespace_namefora15column"MAXSIZE(GB)"format9,999,990.00column"ALLOC(GB)"format9,999,990.00column"USED(GB)"format9,999,990.00selec......
  • docker部署oracle
    docker部署oracle1.拉取镜像dockerpullregistry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g2.启动容器dockerrun-id-p1521:1521--nameoracle11gregistry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g3.进行配置,首先执行如下命令进入oracle容器环境中:docker......
  • Oracle 性能慢排查脚本
    查看总消耗时间最多的前100条SQL语句select*from(selectv.sql_id,v.child_number,v.sql_text,last_load_time,v.PARSING_USER_ID,ROUND(v.ELAPSED_TIME/1000000/(CASEWHEN(EXECUTIONS=0ORNVL(EXECUTIONS,1)=1)THEN1ELSEEXECUTIONSEND),2)"执行......
  • 查询Oracle数据字典SQL
    SELECT A.TABLE_NAMEAS"表名", A.COLUMN_NAMEAS"字段名", DECODE( A.CHAR_LENGTH, 0, DECODE( A.DATA_SCALE, NULL, A.DATA_TYPE, A.DATA_TYPE||'('||A.DATA_PRECISION||','||A.DATA_SCALE||')' ), ......