Home » SQL & PL/SQL » SQL & PL/SQL » how to release the storage when truncating the partition (oracle 10g)
how to release the storage when truncating the partition [message #555692] Sun, 27 May 2012 07:10 Go to next message
kashifchughtai
Messages: 125
Registered: October 2007
Senior Member
hi guys,

my assuption is that when we truncate the partition it immediatly release the allocatd storage.
i have just tested the scenario , but still i can see that table size is same even after truncating the partition( which have around 25% of the data)

can you please tell if my assumption is right?

alter table test truncate partition t1p3 update indexes ;


OR

alter table test truncate partition t1p3 drop storage update indexes ;



to see the table size:

SELECT owner, table_name, TRUNC(sum(bytes) / 1024 / 1024) Meg
  FROM (SELECT segment_name table_name, owner, bytes
          FROM dba_segments
         WHERE segment_type = 'TABLE'
        UNION ALL
        SELECT i.table_name, i.owner, s.bytes
          FROM dba_indexes i, dba_segments s
         WHERE s.segment_name = i.index_name
           AND s.owner = i.owner
           AND s.segment_type = 'INDEX'
        UNION ALL
        SELECT l.table_name, l.owner, s.bytes
          FROM dba_lobs l, dba_segments s
         WHERE s.segment_name = l.segment_name
           AND s.owner = l.owner
           AND s.segment_type = 'LOBSEGMENT'
        UNION ALL
        SELECT l.table_name, l.owner, s.bytes
          FROM dba_lobs l, dba_segments s
         WHERE s.segment_name = l.index_name
           AND s.owner = l.owner
           AND s.segment_type = 'LOBINDEX')
WHERE owner ='OWNER'
and table_name= 'TEST'
GROUP BY table_name, owner
HAVING SUM(bytes) / 1024 / 1024 > 10 
 ORDER BY SUM(bytes) desc


regards,
kashif
Re: how to release the storage when truncating the partition [message #555694 is a reply to message #555692] Sun, 27 May 2012 08:40 Go to previous messageGo to next message
Michel Cadot
Messages: 68757
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Quote:
my assuption is that when we truncate the partition it immediatly release the allocatd storage.


By default, yes.
Have more than "min extents" extents?

Regards
Michel
Re: how to release the storage when truncating the partition [message #555697 is a reply to message #555692] Sun, 27 May 2012 09:18 Go to previous messageGo to next message
kashifchughtai
Messages: 125
Registered: October 2007
Senior Member
how can i check the min extent?
Re: how to release the storage when truncating the partition [message #555698 is a reply to message #555694] Sun, 27 May 2012 09:25 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3305
Registered: January 2010
Location: Connecticut, USA
Senior Member
Michel Cadot wrote on Sun, 27 May 2012 09:40
Have more than "min extents" extents?


Just FYI, starting 11.2.0.2 you can specify DROP ALL STORAGE to drop beyond MINEXTENTS - to drop segment completely (subject to deferred segment creation rules and restrictions).

SY.
Re: how to release the storage when truncating the partition [message #555699 is a reply to message #555697] Sun, 27 May 2012 09:25 Go to previous messageGo to next message
kashifchughtai
Messages: 125
Registered: October 2007
Senior Member
i checked the table size before truncating the partition and it was 7023 MB, and after the truncating also it is same.
Re: how to release the storage when truncating the partition [message #555700 is a reply to message #555699] Sun, 27 May 2012 09:28 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>i checked the table size before truncating the partition and it was 7023 MB, and after the truncating also it is same.
Yes, TRUNCATE does not change physical size.
Re: how to release the storage when truncating the partition [message #555701 is a reply to message #555700] Sun, 27 May 2012 09:34 Go to previous messageGo to next message
kashifchughtai
Messages: 125
Registered: October 2007
Senior Member
does it mean tht storage will not be released with truncating the partition?
Re: how to release the storage when truncating the partition [message #555702 is a reply to message #555701] Sun, 27 May 2012 09:39 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>does it mean tht storage will not be released with truncating the partition?
when TRUNCATE is issued, the space previously consumed by the object will be released back to the TABLESPACE.
Oracle does not return disk space to the Operating System (OS) voluntarily.
Oracle must be explicitly commanded to return disk space to the OS.
Re: how to release the storage when truncating the partition [message #555703 is a reply to message #555692] Sun, 27 May 2012 09:45 Go to previous messageGo to next message
John Watson
Messages: 8974
Registered: January 2010
Location: Global Village
Senior Member
your query against dba_segments doesn't include segments of type TABLE PARTITION, is that deliberate or a mistake? I think it may be confusing the issue.
Re: how to release the storage when truncating the partition [message #555705 is a reply to message #555703] Sun, 27 May 2012 09:46 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
http://www.oracle.com/pls/db112/search?remark=quick_search&word=resize
Re: how to release the storage when truncating the partition [message #555707 is a reply to message #555705] Sun, 27 May 2012 09:54 Go to previous messageGo to next message
kashifchughtai
Messages: 125
Registered: October 2007
Senior Member
@BLACKSWAN: are you sure it returns the space back to tablespace , i dont see any increase in tablespace after deleting the partition? idealy it should have increased?

@John Watson: i missed it, but how it confusing the issue?
Re: how to release the storage when truncating the partition [message #555709 is a reply to message #555698] Sun, 27 May 2012 09:58 Go to previous messageGo to next message
Michel Cadot
Messages: 68757
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
syakobson wrote on Sun, 27 May 2012 16:25
Michel Cadot wrote on Sun, 27 May 2012 09:40
Have more than "min extents" extents?


Just FYI, starting 11.2.0.2 you can specify DROP ALL STORAGE to drop beyond MINEXTENTS - to drop segment completely (subject to deferred segment creation rules and restrictions).

SY.


Thanks for the tip.

Regards
Michel

Re: how to release the storage when truncating the partition [message #555710 is a reply to message #555707] Sun, 27 May 2012 10:03 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_10006.htm#i2067571

"DROP STORAGE Specify DROP STORAGE to deallocate all space from the deleted rows from the table or cluster except the space allocated by the MINEXTENTS parameter of the table or cluster. This space can subsequently be used by other objects in the tablespace. Oracle Database also sets the NEXT storage parameter to the size of the last extent removed from the segment in the truncation process. This is the default."

consider querying DBA_FREE_SPACE in order to conclude what is reality.
Re: how to release the storage when truncating the partition [message #555712 is a reply to message #555707] Sun, 27 May 2012 10:05 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3305
Registered: January 2010
Location: Connecticut, USA
Senior Member
kashifchughtai wrote on Sun, 27 May 2012 10:54
@BLACKSWAN: are you sure it returns the space back to tablespace , i dont see any increase in tablespace after deleting the partition? idealy it should have increased?


Why should it? Think about what is "returned back". Extents, previously occupied by table segment are simply marked as free. So nothing happens to datafile file size on OS level.

kashifchughtai wrote on Sun, 27 May 2012 10:54

@John Watson: i missed it, but how it confusing the issue?


Since you are truncating partition, your table is partitioned table. Therefore, there will be no TABLE type segments for it. Segement type will be TABLE PARTITION. Same way for partitioned indexes segment type will be INDEX PARTITION. So your query doesn't measuse size correctly and you can't make any conclusions based on it.

SY.
Re: how to release the storage when truncating the partition [message #555729 is a reply to message #555712] Mon, 28 May 2012 01:15 Go to previous message
kashifchughtai
Messages: 125
Registered: October 2007
Senior Member
Thanks guys, i will go back and check again.

@SY, you are right...i need to include the missing segments.
Previous Topic: uniqueidentifier in PL/SQL
Next Topic: formatting in utl_mail output
Goto Forum:
  


Current Time: Fri Apr 25 00:26:49 CDT 2025