DBA Tips Archive for Oracle
How to efficiently drop a table with many extents
by Jeff Hunter, Sr. Database Administrator
While attempting to drop a table with many extents, the user process (shadow process) can take a considerable amount of CPU. Most of the processing here (for Dictionary Extent Management) involves moving used extents (sys.uet$) to free extents (sys.fet$). This month I will provide a solution to assist the DBA when attempting to drop a table with a considerable amount of extents.
Major Steps Involved
Consider a table called BIGTABLE. The size of this table is 2G and consists of 262144 8Kb extents. In this example, we are working with a small CPU and past experience has shown that dropping a table of this size (and this many extents) would take several days. Also in this example, the system has very little usage at night. (Batch / CRON Jobs). In this case, you could drop the table in stages using the procedures below. Assume that it would take 3 days (72 hours) to drop the table. We decide to spread this out over 6 nights. (i.e. drop 1/3 Gb per night).
SQL> TRUNCATE TABLE BIGTABLE REUSE STORAGE;
SQL> ALTER TABLE BIGTABLE DEALLOCATE UNUSED KEEP 1707M; (2Gb*5/6)
SQL> ALTER TABLE BIGTABLE DEALLOCATE UNUSED KEEP 1365M; (2Gb*4/6)
SQL> ALTER TABLE BIGTABLE DEALLOCATE UNUSED KEEP 1024M; (2Gb*3/6)
SQL> ALTER TABLE BIGTABLE DEALLOCATE UNUSED KEEP 683M; (2Gb*2/6)
SQL> ALTER TABLE BIGTABLE DEALLOCATE UNUSED KEEP 341M; (2Gb*1/6)
SQL> DROP TABLE BIGTABLE;
Copyright (c) 1998-2018 Jeffrey M. Hunter. All rights reserved.
All articles, scripts and material located at the Internet address of http://www.idevelopment.info is the copyright of Jeffrey M. Hunter and is protected under copyright laws of the United States. This document may not be hosted on any other site without my express, prior, written permission. Application to host any of the material elsewhere can be made by contacting me at firstname.lastname@example.org.
I have made every effort and taken great care in making sure that the material included on my web site is technically accurate, but I disclaim any and all responsibility for any loss, damage or destruction of data or any other property which may arise from relying on it. I will in no case be liable for any monetary damages arising from such loss, damage or destruction.