How to find tablespace usage in oracle
How to find
tablespace usage in oracle
Oracle stores data logically in tablespaces and physically in datafiles
associated with the corresponding tablespace. A database is divided into one or more logical storage units
called tablespaces. Tablespaces are divided into logical units of storage
called segments, which are further divided into extents. Extents are a
collection of contiguous blocks.
Tablespaces are the bridge between certain physical and logical
components of the Oracle database. Tablespaces are where you store Oracle
database objects such as tables, indexes and rollback segments. You can
think of a tablespace like a shared disk drive in Windows. You can store files
on your shared drive, move files around and remove files. The same is true with
tablespaces.
A tablespace is made up of one or more database datafiles. The
total amount of storage space available in a tablespace is the sum of the
physical disk size of all the datafiles associated with that tablespace (less
some system overhead). The datafiles are created automatically when the
tablespace is defined. In most cases, all datafile space is pre-allocated; that
is, the space is set aside when the datafile is created. Thus, when you create
a tablespace, you define the initial size of the associated datafile.
So how to find the tablespace usage in the oracle database, here
is the SQL script that you can run into Sqlplus and get the answer.
Usage in Megabytes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
set pages 999
col tablespace_name format a40
col "size MB" format 999,999.99
col "free MB" format 999,999.99
col "% Used" format 999.99
select tsu.tablespace_name,
ceil(tsu.used_mb) "size MB"
, decode(ceil(tsf.free_mb),
NULL,0,ceil(tsf.free_mb)) "free MB"
, decode(100
- ceil(tsf.free_mb/tsu.used_mb*100), NULL, 100,
100 - ceil(tsf.free_mb/tsu.used_mb*100)) "% Used"
from (select
tablespace_name, sum(bytes)/1024/1024 used_mb
from
dba_data_files group by tablespace_name
union all
select
tablespace_name || ' **TEMP**'
, sum(bytes)/1024/1024 used_mb
from
dba_temp_files group by tablespace_name)
tsu
, (select
tablespace_name, sum(bytes)/1024/1024 free_mb
from
dba_free_space group by tablespace_name)
tsf
where tsu.tablespace_name
= tsf.tablespace_name (+)
order by 4
/
Usage in Gigabytes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
set pages 999
col tablespace_name format a40
col "size GB" format 999,999.99
col "free GB" format 999,999.99
col "% Used" format 999.99
select tsu.tablespace_name,
ceil(tsu.used_gb) "size GB"
, decode(ceil(tsf.free_gb),
NULL,0,ceil(tsf.free_gb)) "free GB"
, decode(100
- ceil(tsf.free_gb/tsu.used_gb*100), NULL, 100,
100 - ceil(tsf.free_gb/tsu.used_gb*100))
"% Used"
from (select
tablespace_name, sum(bytes)/1024/1024/1024 used_gb
from
dba_data_files group by tablespace_name
union all
select
tablespace_name || ' **TEMP**'
, sum(bytes)/1024/1024/1024 used_gb
from
dba_temp_files group by tablespace_name)
tsu
, (select
tablespace_name, sum(bytes)/1024/1024/1024 free_gb
from
dba_free_space group by tablespace_name)
tsf
where tsu.tablespace_name
= tsf.tablespace_name (+)
order by 4
/
Note:
If you want to know usage for particular
tablespace(s) like say system, sysaux and users then what you can do is use ‘and’ condition with the where clause like this:
where tsu.tablespace_name
= tsf.tablespace_name (+)
and
tsu.tablespace_name in (‘SYSTEM’,’SYSAUX’,’USERS’)
order by 4
/
If you wish you can use floor function instead of ceil function.
It is better if you use a text editor to
format SQL Code before using it in oracle database.
Comments
Post a Comment