SET
SERVEROUT
ON
SET
VERIFY
OFF
SET
LINES 200
SET
PAGES 2000
DECLARE
v_ts_id NUMBER;
not_in_awr EXCEPTION;
v_ts_block_size NUMBER;
v_begin_snap_id NUMBER;
v_end_snap_id NUMBER;
v_begin_snap_date
DATE
;
v_end_snap_date
DATE
;
v_numdays NUMBER;
v_count NUMBER;
v_ts_begin_size NUMBER;
v_ts_end_size NUMBER;
v_ts_growth NUMBER;
v_ts_begin_allocated_space NUMBER;
v_ts_end_allocated_space NUMBER;
v_db_begin_size NUMBER := 0;
v_db_end_size NUMBER := 0;
v_db_begin_allocated_space NUMBER := 0;
v_db_end_allocated_space NUMBER := 0;
v_db_growth NUMBER := 0;
CURSOR
v_cur
IS
SELECT
tablespace_name
FROM
dba_tablespaces
WHERE
contents =
'PERMANENT'
;
BEGIN
FOR
v_rec
IN
v_cur LOOP
BEGIN
v_ts_begin_allocated_space := 0;
v_ts_end_allocated_space := 0;
v_ts_begin_size := 0;
v_ts_end_size := 0;
SELECT
ts#
INTO
v_ts_id
FROM
v$tablespace
WHERE
SELECT
block_size
INTO
v_ts_block_size
FROM
dba_tablespaces
WHERE
SELECT
COUNT
(*)
INTO
v_count
FROM
dba_hist_tbspc_space_usage
WHERE
tablespace_id = v_ts_id;
IF
v_count = 0
THEN
RAISE not_in_awr;
END
IF;
SELECT
MIN
(snap_id),
MAX
(snap_id),
MIN
(trunc(TO_DATE(
rtime,
'MM/DD/YYYY HH24:MI:SS'
) ) ),
MAX
(trunc(TO_DATE(
rtime,
'MM/DD/YYYY HH24:MI:SS'
) ) )
INTO
v_begin_snap_id,v_end_snap_id,v_begin_snap_date,v_end_snap_date
FROM
dba_hist_tbspc_space_usage
WHERE
tablespace_id = v_ts_id;
IF
THEN
v_numdays := v_end_snap_date - v_begin_snap_date;
END
IF;
SELECT
round(
MAX
(tablespace_size) * v_ts_block_size / 1024 / 1024,
2
)
INTO
v_ts_begin_allocated_space
FROM
dba_hist_tbspc_space_usage
WHERE
tablespace_id = v_ts_id
AND
snap_id = v_begin_snap_id;
SELECT
round(
MAX
(tablespace_size) * v_ts_block_size / 1024 / 1024,
2
)
INTO
v_ts_end_allocated_space
FROM
dba_hist_tbspc_space_usage
WHERE
tablespace_id = v_ts_id
AND
snap_id = v_end_snap_id;
SELECT
round(
MAX
(tablespace_usedsize) * v_ts_block_size / 1024 / 1024,
2
)
INTO
v_ts_begin_size
FROM
dba_hist_tbspc_space_usage
WHERE
tablespace_id = v_ts_id
AND
snap_id = v_begin_snap_id;
SELECT
round(
MAX
(tablespace_usedsize) * v_ts_block_size / 1024 / 1024,
2
)
INTO
v_ts_end_size
FROM
dba_hist_tbspc_space_usage
WHERE
tablespace_id = v_ts_id
AND
snap_id = v_end_snap_id;
v_db_begin_allocated_space := v_db_begin_allocated_space + v_ts_begin_allocated_space;
v_db_end_allocated_space := v_db_end_allocated_space + v_ts_end_allocated_space;
v_db_begin_size := v_db_begin_size + v_ts_begin_size;
v_db_end_size := v_db_end_size + v_ts_end_size;
v_db_growth := v_db_end_size - v_db_begin_size;
END
;
END
LOOP;
|| v_db_end_allocated_space
||
' MB'
||
' ('
|| round(
v_db_end_allocated_space / 1024,
2
)
||
' GB)'
);
|| v_db_end_size
||
' MB'
||
' ('
|| round(
v_db_end_size / 1024,
2
)
||
' GB)'
);
|| round(
v_db_end_size / v_db_end_allocated_space * 100,
2
)
||
' %'
);
|| v_begin_snap_date
||
': '
|| v_db_begin_allocated_space
||
' MB'
||
' ('
|| round(
v_db_begin_allocated_space / 1024,
2
)
||
' GB)'
);
|| v_end_snap_date
||
': '
|| v_db_end_allocated_space
||
' MB'
||
' ('
|| round(
v_db_end_allocated_space / 1024,
2
)
||
' GB)'
);
|| v_begin_snap_date
||
': '
|| v_db_begin_size
||
' MB'
||
' ('
|| round(
v_db_begin_size / 1024,
2
)
||
' GB)'
);
|| v_end_snap_date
||
': '
|| v_db_end_size
||
' MB'
||
' ('
|| round(
v_db_end_size / 1024,
2
)
||
' GB)'
);
|| v_numdays
||
' days between '
|| v_begin_snap_date
||
' and '
|| v_end_snap_date
||
': '
|| v_db_growth
||
' MB'
||
' ('
|| round(
v_db_growth / 1024,
2
)
||
' GB)'
);
IF
( v_db_growth <= 0
OR
v_numdays <= 0 )
THEN
ELSE
|| v_numdays
||
' days: '
|| round(
v_db_growth / v_numdays,
2
)
||
' MB'
||
' ('
|| round(
(v_db_growth / v_numdays) / 1024,
2
)
||
' GB)'
);
|| round(
(v_db_growth / v_numdays) * 30,
2
)
||
' MB'
||
' ('
|| round(
( (v_db_growth / v_numdays) * 30) / 1024,
2
)
||
' GB)'
);
|| round(
(v_db_growth / v_numdays) * 60,
2
)
||
' MB'
||
' ('
|| round(
( (v_db_growth / v_numdays) * 60) / 1024,
2
)
||
' GB)'
);
|| round(
(v_db_growth / v_numdays) * 90,
2
)
||
' MB'
||
' ('
|| round(
( (v_db_growth / v_numdays) * 90) / 1024,
2
)
||
' GB)'
);
END IF;
EXCEPTION
WHEN not_in_awr THEN
dbms_output.put_line('
====================================================================================================================
'
);
);
dbms_output.put_line('
===================================================================================================================='
);
END
;
/