0% found this document useful (0 votes)
10 views

DB Scripts 5

This document contains several SQL queries that summarize database size, temporary tablespace utilization, sort segment usage by tablespace, datafile usage before shrinking, and estimating flashback space requirements. The queries return metrics like total database size, used vs free space, tablespace sizes and usage, datafile allocation and usage, and average daily archive log generation size to estimate flashback space needs.

Uploaded by

Satish PV
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

DB Scripts 5

This document contains several SQL queries that summarize database size, temporary tablespace utilization, sort segment usage by tablespace, datafile usage before shrinking, and estimating flashback space requirements. The queries return metrics like total database size, used vs free space, tablespace sizes and usage, datafile allocation and usage, and average daily archive log generation size to estimate flashback space needs.

Uploaded by

Satish PV
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

DB Size :

col "Database Size" format a20

col "Free space" format a20

col "Used space" format a20

select round(sum(used.bytes) / 1024 / 1024 / 1024 ) || ' GB' "Database Size"

, round(sum(used.bytes) / 1024 / 1024 / 1024 ) -

round(free.p / 1024 / 1024 / 1024) || ' GB' "Used space"

, round(free.p / 1024 / 1024 / 1024) || ' GB' "Free space"

from (select bytes

from v$datafile

union all

select bytes

from v$tempfile

union all

select bytes

from v$log) used

, (select sum(bytes) as p

from dba_free_space) free

group by free.p

temp tablespace utilization

set lines 200

select TABLESPACE_NAME, sum(BYTES_USED/1024/1024),sum(BYTES_FREE/1024/1024)

from V$TEMP_SPACE_HEADER group by TABLESPACE_NAME;

SELECT A.tablespace_name tablespace, D.GB_total,

SUM (A.used_blocks * D.block_size) / 1024 / 1024 /1024 GB_used,

D.mb_total - SUM (A.used_blocks * D.block_size) / 1024 / 1024 / 1024 GB_free


FROM v$sort_segment A,

SELECT B.name, C.block_size, SUM (C.bytes) / 1024 / 1024 /1024 GB_total

FROM v$tablespace B, v$tempfile C

WHERE B.ts#= C.ts#

GROUP BY B.name, C.block_size

)D

WHERE A.tablespace_name = D.name

GROUP by A.tablespace_name, D.GB_total;

Before shrink know the used size.

col file_name for a60;

set pagesize 500;

set linesize 500;

SELECT SUBSTR (df.NAME, 1, 40) file_name, df.bytes / 1024 / 1024 allocated_mb,

((df.bytes / 1024 / 1024) - NVL (SUM (dfs.bytes) / 1024 / 1024, 0))

used_mb,

NVL (SUM (dfs.bytes) / 1024 / 1024, 0) free_space_mb

FROM v$datafile df, dba_free_space dfs

WHERE df.file# = dfs.file_id(+)

GROUP BY dfs.file_id, df.NAME, df.file#, df.bytes

ORDER BY file_name;

Sometimes application team will ask DBA to enable Tashback for x

number of days. In such case, a DBA needs to estimate the Tashback

space required for x number of days in order to store the Tashback logs.

The flashback log size is same as archive log size generated in a database.

Check the archive generation size via below query

Take the average per day size of archives generated


Multiply the average archive size with x number of days

Ask storage team to add the required space for flashback file system

Check archive generation size via below query:

select to_char(COMPLETION_TIME,'DD-MON-YYYY') Arch_Date,count(*) No#_Logs,

sum((BLOCKS*512)/1024/1024/1024) Arch_LogSize_GB

from v$archived_log

where to_char(COMPLETION_TIME,'DD-MON-YYYY')>=trunc(sysdate-7) and DEST_ID=1

group by to_char(COMPLETION_TIME,'DD-MON-YYYY')

order by to_char(COMPLETION_TIME,'DD-MON-YYYY');

Note: Take average size * 30 days to get 1 month flashback space size.

You might also like