laverne_guo

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
-- |----------------------------------------------------------------------------|
-- | DATABASE : Oracle                                                          |
-- | FILE     : show_database_increase.sql                                      |
-- | CLASS    : Database Administration                                         |
-- | PURPOSE  : This script is listed in the relevant paragraph database        |
-- | history of the use of space in a snapshot of time change information       |
-- | This information is not contain undo and temp tablespace                   |
-- | NOTE     :                                                                 |
-- +----------------------------------------------------------------------------+

SET TERMOUT OFF;
COLUMN current_instance NEW_VALUE current_instance NOPRINT;
SELECT rpad(instance_name, 17) current_instance FROM v$instance;
COLUMN USER NEW_VALUE user_name NOPRINT;
SELECT USER FROM DUAL;
SET TERMOUT ON;

PROMPT
PROMPT +------------------------------------------------------------------------+
PROMPT | Report   : show_database_increase                                      |
PROMPT | Instance : &current_instance                                           |
PROMPT | USER     : &user_name                                                  |
PROMPT +------------------------------------------------------------------------+


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
        ORDER BY rtime
        /
posted on 2020-04-10 17:13  laverne_guo  阅读(646)  评论(0编辑  收藏  举报