question

Cee avatar image
Cee asked

How do I determine the free space in a tablespace?

How do I determine the free space in a tablespace?

oraclestoragetablespace
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Andrew Mobbs avatar image
Andrew Mobbs answered

Query DBA_FREE_SPACE.

Possibly more usefully, understand how space is allocated in extents by Oracle. Each Segment (table, partition, index etc.) has one or more extents for storing data. The extents exist in a tablespace. When more storage is needed by a segment, another extent is allocated, the space in that extent may still mostly be unused, but now can only be used by that segment.

DBA_FREE_SPACE will tell you about the unallocated extents in a tablespace.

Use the procedures in DBMS_SPACE to query how much unused space has been allocated to an object.

http://download.oracle.com/docs/cd/B28359_01/server.111/b28310/schema005.htm provides a good overview

2 comments
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

This can get tricky, if autoextend is on, then the tablespace can grow as needed, and won't really be 'full' until it hits it's quota or the device becomes full if set to 'UNLIMITED'. Toad tries to account for this if you happen to have it available...
0 Likes 0 ·
The unallocated space isn't technically in the tablespace yet :-) Good point; though modern filesystems can be dynamically resized, and some (such as NetApp filers) are also capable of autogrow, so even just looking at space left in the filesystem isn't always sufficient to determine the growth limits.
0 Likes 0 ·
prodlife avatar image
prodlife answered

Here's a query I use:

SELECT a.TABLESPACE_NAME, a.BYTES bytes_used, b.BYTES bytes_free, b.largest, round(((a.BYTES-b.BYTES)/a.BYTES)*100,2) percent_used from ( select TABLESPACE_NAME, sum(BYTES) BYTES from dba_data_files group by TABLESPACE_NAME ) a left outer join ( select TABLESPACE_NAME, sum(BYTES) BYTES , max(BYTES) largest from dba_free_space group by TABLESPACE_NAME ) b on a.TABLESPACE_NAME=b.TABLESPACE_NAME order by ((a.BYTES-b.BYTES)/a.BYTES) desc

10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.