Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles
New Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 
 

dba_extents scripts tips

Oracle Database Tips by Donald BurlesonJuly 4, 2013


Question:  Hew do you use the dba_extents view in scripts to see the amount of allocated extents for any table or index?  How does dba_extents compare to dba_data_files?

Answer: The dba_extents view contains one row for each extents for each object:   

dba_extents columns

OWNER           VARCHAR2 Owner of the segment associated with the extent
SEGMENT_NAME    VARCHAR2 Name of the segment associated with the extent
PARTITION_NAME  VARCHAR2 Partition/Subpartition Name of the segment
SEGMENT_TYPE    VARCHAR2 Type of the segment
TABLESPACE_NAME VARCHAR2 Name of the tablespace containing the extent
EXTENT_ID       NUMBER   Extent number in the segment
FILE_ID         NUMBER   Name of the file containing the extent
BLOCK_ID        NUMBER   Starting block number of the extent
BYTES           NUMBER   Size of the extent in bytes
BLOCKS          NUMBER   Size of the extent in ORACLE blocks
RELATIVE_FNO    NUMBER   Relative number of the file containing the segment                  header

dba_extents scripts

Here are some scripts that use dba_extents to examine the number of extents used by an object:

Amount of spaced used from dba_extents:

Select
   tablespace_name,sum(bytes) bytes_full
From
   dba_extents
Group by
   tablespace_name;

Total available space from dba_data_files:

Select
   tablespace_name,
   sum(bytes) bytes_total
From
   dba_data_files

Group by
   tablespace_name;

So if we add this with our original statement, we can select on pct_used (less than 70 percent):

select 'alter database '||a.name||' datafile '''||b.file_name||''''
from v$database a
,dba_data_files b
,(Select tablespace_name,sum(bytes) bytes_full
From dba_extents
Group by tablespace_name) c
,(Select tablespace_name,sum(bytes) bytes_total
From dba_data_files
Group by tablespace_name) d
Where b.tablespace_name = c.tablespace_name
And b.tablespace_name = d.tablespace_name
And bytes_full/bytes_total < .7
;

According to the command, a selection has been made based on tablespace. What if you want to resize based on file? It's crucial to remember that multiple files can exist in any tablespace. Plus, only space that is after the last data block can be de-allocated. So the next step should be to find the last data block:

select
   tablespace_name,
   file_id,max(block_id) max_data_block_id
from
   dba_extents
group by
   tablespace_name,file_id;

Now that the command to find the last data block has been inserted, it is time to find the free space in each file above that last data block:

Select
   a.tablespace_name,
   a.file_id,
   b.bytes    bytes_free
From
   (select
      tablespace_name,
      file_id,max(block_id) max_data_block_id
    from
      dba_extents
    group by tablespace_name,file_id) a,
   dba_free_space b
where
   a.tablespace_name = b.tablespace_name
and
   a.file_id = b.file_id
and
   b.block_id > a.max_data_block_id;

See

 
Get the Complete
Oracle SQL Tuning Information 

The landmark book "Advanced Oracle SQL Tuning  The Definitive Reference"  is filled with valuable information on Oracle SQL Tuning. This book includes scripts and tools to hypercharge Oracle 11g performance and you can buy it for 30% off directly from the publisher.

 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2020

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.

 

 

��  
 
 
Oracle Training at Sea
 
 
 
 
oracle dba poster
 

 
Follow us on Twitter 
 
Oracle performance tuning software 
 
Oracle Linux poster