Friday 18 July 2014

command to know tablespace usage for storage management

command to know tablespace usage:
SQL>select df.tablespace_name "Tablespace",totalusedspace "Used MB",(df.totalspace - tu.totalusedspace) "Free MB",df.totalspace "Total MB",round(100 * ( (df.totalspace - tu.totalusedspace)/ df.totalspace))"Pct. Free" 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;

command to know only segment usage:
SQL> select bytes totalusedspace, tablespace_name,segment_name from dba_segments where segment_name='<segment name>';

SQL> select bytes totalusedspace, tablespace_name,segment_name from dba_segments where segment_name='I_OBJ1';

TOTALUSEDSPACE TABLESPACE_NAME
-------------- ------------------------------
SEGMENT_NAME
--------------------------------------------------------------------------------
      10551296 SYSTEM
I_OBJ1

Command to know tablespace usage along with index_name,segment_name:(with tablespacename prompt)


select df.tablespace_name "Tablespace",totalusedspace "Used MB",(df.totalspace - tu.totalusedspace) "Free MB",df.totalspace "Total MB",round(100 * ( (df.totalspace - tu.totalusedspace)/ df.totalspace))"Pct. Free",di.index_name "INDEX_NAME",tu.segment_name "SEGMENT_NAME" 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,segment_name from dba_segments group by tablespace_name , segment_name) tu,(select tablespace_name,index_name  from dba_indexes)di where df.tablespace_name = tu.tablespace_name and di.tablespace_name=tu.tablespace_name and df.tablespace_name=’&TablespaceName’;

Command to know tablespace usage along with index_name,segment_name:(with index_name prompt)


select df.tablespace_name "Tablespace",totalusedspace "Used MB",(df.totalspace - tu.totalusedspace) "Free MB",df.totalspace "Total MB",round(100 * ( (df.totalspace - tu.totalusedspace)/ df.totalspace))"Pct. Free",di.index_name "INDEX_NAME",tu.segment_name "SEGMENT_NAME" 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,segment_name from dba_segments group by tablespace_name , segment_name) tu,(select tablespace_name,index_name  from dba_indexes)di where df.tablespace_name = tu.tablespace_name and di.tablespace_name=tu.tablespace_name and di.index_name=’&Index_Name’;

Command to know tablespace usage along with index_name,segment_name:(with segment_name prompt)


select df.tablespace_name "Tablespace",totalusedspace "Used MB",(df.totalspace - tu.totalusedspace) "Free MB",df.totalspace "Total MB",round(100 * ( (df.totalspace - tu.totalusedspace)/ df.totalspace))"Pct. Free",di.index_name "INDEX_NAME",tu.segment_name "SEGMENT_NAME" 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,segment_name from dba_segments group by tablespace_name , segment_name) tu,(select tablespace_name,index_name  from dba_indexes)di where df.tablespace_name = tu.tablespace_name and di.tablespace_name=tu.tablespace_name and tu.segment_name=’&Segment_Name’;
command to make output alignment:
SQL>set wrap off
SQL> set linesize 3000
Command to know tablespace usage along with index_name,segment_name:(with table_name prompt):

select df.tablespace_name "Tablespace",totalusedspace "Used MB",(df.totalspace - tu.totalusedspace) "Free MB",df.totalspace "Total MB",round(100 * ( (df.totalspace - tu.totalusedspace)/ df.totalspace))"Pct. Free", tu.segment_name "SEGMENT_NAME",di.table_name "TABLE_NAME" 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,segment_name from dba_segments group by tablespace_name , segment_name) tu,(select tablespace_name,table_name, index_name  from dba_indexes)di where df.tablespace_name = tu.tablespace_name and di.tablespace_name=tu.tablespace_name and di.table_name='&Table_Name';

No comments:

Post a Comment