Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


how to calculate disc space occupied by a table

Posted on 2004-08-02
Medium Priority
Last Modified: 2008-02-01
what is the easy way to calculate the disc space occupied by a table in oracle
Question by:oraram9
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 15

Expert Comment

ID: 11699327
select segment_name as table_name, sum(bytes)
from user_segments
where segment_type = 'TABLE'
group by segment_name;

Author Comment

ID: 11699509
do the above query retrieve  the space allocated to that table or space occupied by the table data on the disc at this point of time???
LVL 15

Expert Comment

ID: 11700156
It is the space allocated to the table.

Not sure that you can easily see how much space is free in the allocated space.
I believe you can you dba|user_free_space to find the blocks/bytes that are above the high water mark, but there isn't a way to see how much space there is below it.
Though its been a while since I looked at this and I don't have the scripts I came up with with me ...

Expert Comment

ID: 11700571

the query given by ishando is the space occupied by the table in the tablespace which is there in ur hard disk. so try to get the total space occupied in a given segment and then minus it from the total tablespace size. that should give u the free space and also the space occupied in a tablespace.

select sum(bytes)
from user_segments
where tablespace_name = <tablespace name>;

get the size of the tablespace by searching for the dbf file
subtract the value ie total tablespace size - sum(bytes) will give u the free space and sum(bytes) gives u the space occupied in the tablespace

LVL 13

Accepted Solution

riazpk earned 150 total points
ID: 11702280
My preferred way to do this:

    ( p_segname in varchar2,
      p_owner   in varchar2 default user,
      p_type    in varchar2 default 'INDEX' )
        l_free_blks                 number;
        l_total_blocks              number;
       l_total_bytes               number;
       l_unused_blocks             number;
       l_unused_bytes              number;
       l_LastUsedExtFileId         number;
       l_LastUsedExtBlockId        number;
       l_LAST_USED_BLOCK           number;
       procedure p( p_label in varchar2, p_num in number )
           dbms_output.put_line( rpad(p_label,40,'.') ||
                                 p_num );
       ( segment_owner     => p_owner,
         segment_name      => p_segname,
         segment_type      => p_type,
         freelist_group_id => 0,
         free_blks         => l_free_blks );
       ( segment_owner     => p_owner,
         segment_name      => p_segname,
         segment_type      => p_type,
         total_blocks      => l_total_blocks,
         total_bytes       => l_total_bytes,
         unused_blocks     => l_unused_blocks,
         unused_bytes      => l_unused_bytes,
         LAST_USED_EXTENT_FILE_ID => l_LastUsedExtFileId,
         LAST_USED_EXTENT_BLOCK_ID => l_LastUsedExtBlockId,
       dbms_output.put_line('Segment Name=  '||p_segname);
       p( 'Free Blocks', l_free_blks );
       p( 'Total Blocks', l_total_blocks );
       p( 'Total Bytes', l_total_bytes );
       p( 'Total MBytes', l_total_bytes/1024/1024);
       p( 'Unused Blocks', l_unused_blocks );
       p( 'Unused Bytes', l_unused_bytes );
       p( 'Last Used Ext FileId', l_LastUsedExtFileId );
       p( 'Last Used Ext BlockId', l_LastUsedExtBlockId );
       p( 'Last Used Block', l_LAST_USED_BLOCK );

SQL> set serveroutput on
SQL> execute show_space('TABLE1',user,'TABLE');
Segment Name=  TABLE1
Free Blocks.............................4566
Total Blocks............................167808
Total Bytes.............................1374683136
Total MBytes............................1311
Unused Blocks...........................4962
Unused Bytes............................40648704
Last Used Ext FileId....................12
Last Used Ext BlockId...................138377
Last Used Block.........................3230

PL/SQL procedure successfully completed.

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows how to recover a database from a user managed backup
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question