Home > Oracle MiddleWare > Query to find table spaces in Oracle Database

Query to find table spaces in Oracle Database


This is one useful query to know the total table space allotted, used and free.

Step 1: Login as sys user in the sqlplus

Step 2: Run the following query

select df.tablespace_name, totalusedspace, df.totalspace from (select tablespace_name, round(sum(bytes)/1048576) totalspace from dba_data_files group by tablespace_name) df,
(select round(sum(bytes)/(1024*1024)) totalusedspace,tablespace_name from dba_segments group by tablespace_name) tu where df.tablespace_name=tu.tablespace_name;

Here is the output:

To get free space you can modify the above query as:

select df.tablespace_name, totalusedspace "used MB", (df.totalspace-tu.totalusedspace) "Free MB", df.totalspace "total MB" from (select tablespace_name, round(sum(bytes)/1048576) totalspace from dba_data_files group by tablespace_name) df,
(select round(sum(bytes)/(1024*1024)) totalusedspace,tablespace_name from dba_segments group by tablespace_name) tu where df.tablespace_name=tu.tablespace_name;

Here is the output with free space:

Hope that helps.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: