You are on page 1of 4

PowerViewisOff

Dashboard

Knowledge

ServiceRequests

(0)

Faisal(Available)

ContactUs

Help

Patches&Updates
GiveFeedback...

HowtodeterminetheactualsizeoftheLOBsegmentsandhowtofreethedeleted/unusedspaceabove/belowthe
HWM(DocID386341.1)
InthisDocument

ToBottom

DocumentDetails

Goal
Type:
Status:
LastMajor
Update:
LastUpdate:

Solution
References

APPLIESTO:
OracleDatabaseEnterpriseEditionVersion9.2.0.1to11.2.0.3[Release9.2to11.2]
Informationinthisdocumentappliestoanyplatform.

RelatedProducts

GOAL

InformationCenter:Overview
ofDatabaseSecurityProducts
[1548952.2]

ThesizeoftheLOBsegmentcanbefoundbyqueryingdba_segments,asfollows:

InformationCenter:Overview
DatabaseServer/Client
Installationand
Upgrade/Migration
[1351022.2]

selectbytesfromdba_segmentswheresegment_name='<lobsegmentname>'andowner='<tableowner>'

TogetthedetailsofthetabletowhichthisLOBsegmentbelongto:

DocumentReferences

11gAdvancedCompression
HowtoCheckSpaceOccupied
byLOBCompression
[861344.1]

selectsum(dbms_lob.getlength(<lobcolumnname>))from<table_name>

Checkthe"free"spacewithinaLOBsegment.
First,rememberthatalobcanhave3states:"inuse","deleted"and"free".TherearenostatisticsfortheLOBsegment,the
DBMS_SPACEpackageistheonlytoolthatcouldgiveanideaaboutit.Aswell,thereisnoviewshowingthedeletedspacewithin
theLOB.ThedeletedspacecanbeconvertedintofreebyrebuildingthefreelistorbyrebuildingtheLOBsegmentitself,butthis
isnotalwayspossible.
Note:
LOBPartitionsizingisnotsupportedinDBMS_SPACEpackageuntil10g.
ErrorORA00600[ktsircinfo_num1]willbegeneratediftheprocedureisrunagainstthelobpartitiononversionsbelow10g
P.S:Whenusingdbms_lob.getlength,theoutputisincharactersforCLOBsandNCLOBs,andinbytesforBLOBSandBFILES.
Onecangetanideaabouthowmuchspaceisactuallyusedandwhatcouldbedeallocatedasfollows:
1.DeterminetheunusedspacewithintheLOBsegment,abovetheHWM.usingtheUNUSED_SPACEprocedure.
setserveroutputon
declare
TOTAL_BLOCKSnumber
TOTAL_BYTESnumber
UNUSED_BLOCKSnumber
UNUSED_BYTESnumber
LAST_USED_EXTENT_FILE_IDnumber
LAST_USED_EXTENT_BLOCK_IDnumber
LAST_USED_BLOCKnumber
begin
dbms_space.unused_space('<owner>','<lobsegmentname>','LOB',
TOTAL_BLOCKS,TOTAL_BYTES,UNUSED_BLOCKS,UNUSED_BYTES,
LAST_USED_EXTENT_FILE_ID,LAST_USED_EXTENT_BLOCK_ID,
LAST_USED_BLOCK)

HowtoDeterminewhat
storageisusedina
LOBSEGMENTandshoulditbe
shrunk/reorganized?
[1453350.1]

ThefirstthingtodowouldbetocheckthespacethatisactuallyallocatedtotheLOBdata.

Hence,Thedifferencebetweenthesetwoisfreespaceand/orundospace.Itisnotpossibletoassesstheactualemptyspace
usingthequeriesabovealone,becauseoftheUNDOsegmentsize,whichisvirtuallyimpossibletoassess.Furthermore,even
whenthereisfreespaceintheLOB,thisdoesnotmeanthisspacecanbereleasedtothetablespace,itcouldbeunderthe
HWM.Tofindthefreeablespace,usetheUNUSED_SPACEprocedureasshownbelow.

IndexofOracleDatabase
InformationCenters
[1568043.2]

SOLUTION

PleasenotethattheUNDOdataforaLOBsegmentiskeptwithintheLOBsegmentspace.Theabovequeryresultismerelythe
stillactiveLOBdata.Therestofallocateddataisundospace.Theundospacecanvaryquitealot,frombeingverysmallinsize
(whenLOBsareonlyinserted)tobeingverylarge(whenmanyLOBsaredeleted)andislargelydependingonthePCTVERSION
LOBparameterortheRETENTIONparameter.

OracleDatabaseEnterprise
Edition
InformationCenters

SomehintsabouthowtochecktheactualsizeofaLOBsegmentincludingthefreeandavailablespace,aboveandbelowthe
HWM,includingthecommandstofreethespaceabovetheHWM.

SELECTTABLE_NAME,COLUMN_NAMEFROMDBA_LOBSWHEREOWNER='<owner>'ANDSEGMENT_NAME='<lobsegment
name>'

HOWTO
PUBLISHED
16Dec2014
16Dec2014

RecentlyViewed
HowtoFreeSpacefromLOB
SegmentsintheSOA
Schema[1380989.1]
SEGMENTADVISORnot
WorkingasExpectedforLOB
orSYS_LOBSEGMENT
[988744.1]
DataGuardSupportfor
HeterogeneousPrimaryand
PhysicalStandbysinSame
DataGuardConfiguration
[413484.1]
MAACreatingaSingle
InstancePhysicalStandby
foraRACPrimary
[387339.1]
DowngradingDatabase
WithoutExecuting
catdwgrd.sql(11.1.0.xto
10.2.0.x/10.2.0.xto10.2.0.x)
[783643.1]
ShowMore

dbms_output.put_line('SEGMENT_NAME=<LOBSEGMENTNAME>')
dbms_output.put_line('')
dbms_output.put_line('TOTAL_BLOCKS='||TOTAL_BLOCKS)
dbms_output.put_line('TOTAL_BYTES='||TOTAL_BYTES)
dbms_output.put_line('UNUSED_BLOCKS='||UNUSED_BLOCKS)
dbms_output.put_line('UNUSEDBYTES='||UNUSED_BYTES)
dbms_output.put_line('LAST_USED_EXTENT_FILE_ID='||LAST_USED_EXTENT_FILE_ID)
dbms_output.put_line('LAST_USED_EXTENT_BLOCK_ID='||LAST_USED_EXTENT_BLOCK_ID)
dbms_output.put_line('LAST_USED_BLOCK='||LAST_USED_BLOCK)
end
/

ThisistheonlyspacethatcouldbedeallocatedusingtheALTERTABLE...DEALLOCATEUNUSEDcommandasseenbelow.
2.1.Fortablespacesthatareusingfreelists,thefollowingprocedurescouldbeusedtofindtheblocksthatareonthefreelists
(whichisnotextremelyusefulwhenwantingtofreeupsomespace,astheseblocksarejustfilledbelowthePCTUSED.
Nevertheless,thisshowsthereissomefreespacewithintheLOB.
2.1.1.foronefreelistgroup:
declare
free_blocksnumber
begin
DBMS_SPACE.FREE_BLOCKS('<owner>','<lobsegmentname>','LOB',0,free_blocks)
dbms_output.put_line('Nboffreeblocks='||free_blocks)
end
/

2.1.2.formultiplefreelistgroups:
variablefree_blksnumber
declareiint
declarev_freelist_groups:=100replacethiswiththeactualnumber
begin
FORiIN0..v_freelist_groups1LOOP
DBMS_SPACE.FREE_BLOCKS('<owner>','<lobsegmentname>','LOB',i,:free_blks)
dbms_output.put_line('instance#:'||i)
dbms_output.put_line('free_blks:'||:free_blks)
dbms_output.put_line('')
ENDLOOP

theaboveprocedureswouldnotworkforASSMtablespaces,becausethefree_blocksproceduredoesnotworkwiththem.
2.2SPACE_USAGEprocedurecouldbeusedforASSMsegmentsinstead:
declare
v_unformatted_blocksnumber
v_unformatted_bytesnumber
v_fs1_blocksnumber
v_fs1_bytesnumber
v_fs2_blocksnumber
v_fs2_bytesnumber
v_fs3_blocksnumber
v_fs3_bytesnumber
v_fs4_blocksnumber
v_fs4_bytesnumber
v_full_blocksnumber
v_full_bytesnumber
begin
dbms_space.space_usage('<owner>','<lobsegmentname>','LOB',v_unformatted_blocks,
v_unformatted_bytes,v_fs1_blocks,v_fs1_bytes,v_fs2_blocks,v_fs2_bytes,
v_fs3_blocks,v_fs3_bytes,v_fs4_blocks,v_fs4_bytes,v_full_blocks,v_full_bytes)
dbms_output.put_line('UnformattedBlocks='||v_unformatted_blocks)
dbms_output.put_line('FS1Blocks='||v_fs1_blocks)
dbms_output.put_line('FS2Blocks='||v_fs2_blocks)
dbms_output.put_line('FS3Blocks='||v_fs3_blocks)
dbms_output.put_line('FS4Blocks='||v_fs4_blocks)
dbms_output.put_line('FullBlocks='||v_full_blocks)
end
/

DetermineASSMtablespacesorASSMresidingLOBswith:

selecttablespace_name,EXTENT_MANAGEMENT,allocation_type,segment_space_management
fromdba_tablespaceswheresegment_space_management='AUTO'
andtablespace_nameNOTLIKE'%UNDO%'
andtablespace_name='<nameoftablespace>'

andtablespace_name='<nameoftablespace>'
/
FindLOBsthatresideinASSMtablespaces:
colTableformata24
colTablespaceformata22
colpartitionedformata11
colcolumn_nameformata24
selectcolumn_name"Column",table_name"Table",tablespace_name"Tablespace",partitioned
fromDBA_LOBS
wheretablespace_namein(selecttablespace_name
fromDBA_TABLESPACESwheresegment_space_management='AUTO'
andtablespace_nameNOTLIKE'%UNDO%'
andownerNOTIN('SYS','SYSTEM','CTXSYS','MDSYS','ORDSYS','DBSNMP',
'SYSMAN','XDB','MDSYS','ORDSYS','EXFSYS','DMSYS','WMSYS'))
orderbytablespace_name
/

3.Thecommandusedtodeallocatethelobfreespaceis:
altertable<tablename>modifylob(<lobcolumnname>)(deallocateunused)

Thisisnotveryusefulinmostcircumstances.Thereisprobablyverylittlespaceabovethehighwatermark.Ontopofthis,the
deletedspacefrominsidethethelobsegmentisnotevenshownbytheproceduresabove.Thisistheexpectedbehaviourand,
unfortunately,currentlythereisnoprocedure/viewtoshowthedeletedspace.Havingsuchanoptionisthecurrentsubjectofan
enhancementrequest.
However,thedeletedspacecanbeturnedintofreespaceand,whenthishappens,theprocedurein2.2wouldshowthisfree
space.Toturnthedeletedspaceintofreespace,onehastorebuildthefreepools.Thecommandusedtodothisis:
altertable<tablename>modifylob(<lobcolumnname>)(freepools<numberoffreepools>)

Thefreepoolsnumbercanbetakenfromthedba_lobsview.Whenthisvalueisnull,thecommandcanberunwithafreepools
numberof1.Thisprocedurewillnotreleasethefreespacetothetablespace.
Ifonewantstoreleasethespace,
forversionsbelow10.2,onehastorebuildtheLOBsegmentusingtheMOVEcommand:
altertable<tablename>movelob(<lobcolumnname>)storeas(tablespace<tablespacename>)

10.2introducedanevenbetteroption,itextendedtheSHRINKSPACEcommandtoLOBs.Assuch,onecanremovethedeleted
andfreespacealtogetherfromtheLOBsegmentandLOBindex:
altertable<tablename>modifylob(<lobcolumnname>)(shrinkspace[cascade])

WARNINGS:
#1.BeawareofthefollowingbugbeforeadjustingstoragefreelistsforanyLOB
SeriousLOBcorruptioncanoccurafteran
ALTERTABLE<table>MODIFYLOB("<lob_column>")(STORAGE(freelists<n>))
hasbeenissuedonaLOBcolumnwhichresidesinamanualspacemanagedtablespace.SubsequentuseoftheLOBcanfailwith
variousinternalerrorssuchas:
ORA600[ktsbvmap1]
ORA600[25012]
Formoreinformation,pleaserefertobug4450606.
#2.BeawareofthefollowingbugbeforeusingtheSHRINKoptioninreleaseswhichare<=10.2.0.3:
Bug:5636728LOBcorruption/ORA1555whenreadingLOBsafteraSHRINKoperation
Pleasecheck:
Note.5636728.8Ext/PubBug5636728LOBcorruption/ORA1555whenreadingLOBsafteraSHRINKoperation
fordetailsonit.
#3.Beawarethat,sometimes,itcouldbeneededtoperformtheshrinkoperationtwice,inordertoavoidthe:
Bug:5565887SHRINKSPACEISREQUIREDTWICEFORRELEASINGSPACE.
isfixedin10.2.

REFERENCES
NOTE:1453350.1HowtoDeterminewhatstorageisusedinaLOBSEGMENTandshoulditbeshrunk/reorganized?
NOTE:861344.111gAdvancedCompressionHowtoCheckSpaceOccupiedbyLOBCompression

Related
Products
OracleDatabaseProducts>OracleDatabaseSuite>OracleDatabase>OracleDatabaseEnterpriseEdition>RDBMS>SpaceUsage,Fragmentation,UnabletoExtenderrors,
segmentsreorg/shrink/move,enq:FB,enq:HW,Recyclebinissues,segmentadvisor

segmentsreorg/shrink/move,enq:FB,enq:HW,Recyclebinissues,segmentadvisor

Keywords
DBMS_LOB.GETLENGTH DBMS_SPACE.FREE_BLOCKS DBMS_SPACE.SPACE_USAGE DBMS_SPACE.UNUSED_SPACE FREESPACE HWM LOB SHRINK

Errors
KTSBVMAP1 KTSIRCINFO_NUM1 ORA1555 ORA600[25012] ORA600[KTSBVMAP1] ORA600[KTSIRCINFO_NUM1]
BacktoTop

Copyright(c)2015,Oracle.Allrightsreserved.

LegalNoticesandTermsofUse

PrivacyStatement

You might also like