lob segment shrink space
DESCRIPTION
Lob Segment Shrink SpaceTRANSCRIPT
PowerViewisOff(0) Faisal(Available) ContactUs HelpInthisDocumentGoalSolutionReferencesAPPLIESTO:OracleDatabaseEnterpriseEditionVersion9.2.0.1to11.2.0.3[Release9.2to11.2]Informationinthisdocumentappliestoanyplatform.GOALSomehintsabouthowtochecktheactualsizeofaLOBsegmentincludingthefreeandavailablespace,aboveandbelowtheHWM,includingthecommandstofreethespaceabovetheHWM.SOLUTIONThesizeoftheLOBsegmentcanbefoundbyqueryingdba_segments,asfollows:selectbytesfromdba_segmentswheresegment_name=''andowner=''TogetthedetailsofthetabletowhichthisLOBsegmentbelongto:SELECTTABLE_NAME,COLUMN_NAMEFROMDBA_LOBSWHEREOWNER=''ANDSEGMENT_NAME=''ThefirstthingtodowouldbetocheckthespacethatisactuallyallocatedtotheLOBdata.selectsum(dbms_lob.getlength())fromPleasenotethattheUNDOdataforaLOBsegmentiskeptwithintheLOBsegmentspace.TheabovequeryresultismerelythestillactiveLOBdata.Therestofallocateddataisundospace.Theundospacecanvaryquitealot,frombeingverysmallinsize(whenLOBsareonlyinserted)tobeingverylarge(whenmanyLOBsaredeleted)andislargelydependingonthePCTVERSIONLOBparameterortheRETENTIONparameter.Hence,Thedifferencebetweenthesetwoisfreespaceand/orundospace.Itisnotpossibletoassesstheactualemptyspaceusingthequeriesabovealone,becauseoftheUNDOsegmentsize,whichisvirtuallyimpossibletoassess.Furthermore,evenwhenthereisfreespaceintheLOB,thisdoesnotmeanthisspacecanbereleasedtothetablespace,itcouldbeundertheHWM.Tofindthefreeablespace,usetheUNUSED_SPACEprocedureasshownbelow.Checkthe"free"spacewithinaLOBsegment.First,rememberthatalobcanhave3states:"inuse","deleted"and"free".TherearenostatisticsfortheLOBsegment,theDBMS_SPACEpackageistheonlytoolthatcouldgiveanideaaboutit.Aswell,thereisnoviewshowingthedeletedspacewithintheLOB.ThedeletedspacecanbeconvertedintofreebyrebuildingthefreelistorbyrebuildingtheLOBsegmentitself,butthisisnotalwayspossible.Note:LOBPartitionsizingisnotsupportedinDBMS_SPACEpackageuntil10g.ErrorORA00600[ktsircinfo_num1]willbegeneratediftheprocedureisrunagainstthelobpartitiononversionsbelow10gP.S:Whenusingdbms_lob.getlength,theoutputisincharactersforCLOBsandNCLOBs,andinbytesforBLOBSandBFILES.Onecangetanideaabouthowmuchspaceisactuallyusedandwhatcouldbedeallocatedasfollows:1.DeterminetheunusedspacewithintheLOBsegment,abovetheHWM.usingtheUNUSED_SPACEprocedure.setserveroutputondeclareTOTAL_BLOCKSnumberTOTAL_BYTESnumberUNUSED_BLOCKSnumberUNUSED_BYTESnumberLAST_USED_EXTENT_FILE_IDnumberLAST_USED_EXTENT_BLOCK_IDnumberLAST_USED_BLOCKnumberbegindbms_space.unused_space('','','LOB',TOTAL_BLOCKS,TOTAL_BYTES,UNUSED_BLOCKS,UNUSED_BYTES,LAST_USED_EXTENT_FILE_ID,LAST_USED_EXTENT_BLOCK_ID,LAST_USED_BLOCK) DocumentDetails Type:Status:LastMajorUpdate:LastUpdate:HOWTOPUBLISHED16Dec201416Dec2014 RelatedProducts OracleDatabaseEnterpriseEdition InformationCenters IndexofOracleDatabaseInformationCenters[1568043.2]InformationCenter:OverviewofDatabaseSecurityProducts[1548952.2]InformationCenter:OverviewDatabaseServer/ClientInstallationandUpgrade/Migration[1351022.2] DocumentReferences HowtoDeterminewhatstorageisusedinaLOBSEGMENTandshoulditbeshrunk/reorganized?[1453350.1]11gAdvancedCompressionHowtoCheckSpaceOccupiedbyLOBCompression[861344.1] RecentlyViewed HowtodeterminetheactualsizeoftheLOBsegmentsandhowtofreethedeleted/unusedspaceabove/belowtheHWM(DocID386341.1)ToBottomHowtoFreeSpacefromLOBSegmentsintheSOASchema[1380989.1]SEGMENTADVISORnotWorkingasExpectedforLOBorSYS_LOBSEGMENT[988744.1]DataGuardSupportforHeterogeneousPrimaryandPhysicalStandbysinSameDataGuardConfiguration[413484.1]MAACreatingaSingleInstancePhysicalStandbyforaRACPrimary[387339.1]DowngradingDatabaseWithoutExecutingcatdwgrd.sql(11.1.0.xto10.2.0.x/10.2.0.xto10.2.0.x)[783643.1]ShowMoreDashboard ServiceRequests Patches&Updates KnowledgeGiveFeedback...dbms_output.put_line('SEGMENT_NAME=')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:declarefree_blocksnumberbeginDBMS_SPACE.FREE_BLOCKS('','','LOB',0,free_blocks)dbms_output.put_line('Nboffreeblocks='||free_blocks)end/2.1.2.formultiplefreelistgroups:variablefree_blksnumberdeclareiintdeclarev_freelist_groups:=100replacethiswiththeactualnumberbeginFORiIN0..v_freelist_groups1LOOPDBMS_SPACE.FREE_BLOCKS('','','LOB',i,:free_blks)dbms_output.put_line('instance#:'||i)dbms_output.put_line('free_blks:'||:free_blks)dbms_output.put_line('')ENDLOOPtheaboveprocedureswouldnotworkforASSMtablespaces,becausethefree_blocksproceduredoesnotworkwiththem.2.2SPACE_USAGEprocedurecouldbeusedforASSMsegmentsinstead:declarev_unformatted_blocksnumberv_unformatted_bytesnumberv_fs1_blocksnumberv_fs1_bytesnumberv_fs2_blocksnumberv_fs2_bytesnumberv_fs3_blocksnumberv_fs3_bytesnumberv_fs4_blocksnumberv_fs4_bytesnumberv_full_blocksnumberv_full_bytesnumberbegindbms_space.space_usage('','','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_managementfromdba_tablespaceswheresegment_space_management='AUTO'andtablespace_nameNOTLIKE'%UNDO%'andtablespace_name=''andtablespace_name=''/FindLOBsthatresideinASSMtablespaces:colTableformata24colTablespaceformata22colpartitionedformata11colcolumn_nameformata24selectcolumn_name"Column",table_name"Table",tablespace_name"Tablespace",partitionedfromDBA_LOBSwheretablespace_namein(selecttablespace_namefromDBA_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:altertablemodifylob()(deallocateunused)Thisisnotveryusefulinmostcircumstances.Thereisprobablyverylittlespaceabovethehighwatermark.Ontopofthis,thedeletedspacefrominsidethethelobsegmentisnotevenshownbytheproceduresabove.Thisistheexpectedbehaviourand,unfortunately,currentlythereisnoprocedure/viewtoshowthedeletedspace.Havingsuchanoptionisthecurrentsubjectofanenhancementrequest.However,thedeletedspacecanbeturnedintofreespaceand,whenthishappens,theprocedurein2.2wouldshowthisfreespace.Toturnthedeletedspaceintofreespace,onehastorebuildthefreepools.Thecommandusedtodothisis:altertablemodifylob()(freepools)Thefreepoolsnumbercanbetakenfromthedba_lobsview.Whenthisvalueisnull,thecommandcanberunwithafreepoolsnumberof1.Thisprocedurewillnotreleasethefreespacetothetablespace.Ifonewantstoreleasethespace,forversionsbelow10.2,onehastorebuildtheLOBsegmentusingtheMOVEcommand:altertablemovelob()storeas(tablespace)10.2introducedanevenbetteroption,itextendedtheSHRINKSPACEcommandtoLOBs.Assuch,onecanremovethedeletedandfreespacealtogetherfromtheLOBsegmentandLOBindex:altertablemodifylob()(shrinkspace[cascade])WARNINGS:#1.BeawareofthefollowingbugbeforeadjustingstoragefreelistsforanyLOBSeriousLOBcorruptioncanoccurafteranALTERTABLEMODIFYLOB("")(STORAGE(freelists))hasbeenissuedonaLOBcolumnwhichresidesinamanualspacemanagedtablespace.SubsequentuseoftheLOBcanfailwithvariousinternalerrorssuchas:ORA600[ktsbvmap1]ORA600[25012]Formoreinformation,pleaserefertobug4450606.#2.BeawareofthefollowingbugbeforeusingtheSHRINKoptioninreleaseswhichareOracleDatabaseSuite>OracleDatabase>OracleDatabaseEnterpriseEdition>RDBMS>SpaceUsage,Fragmentation,UnabletoExtenderrors,segmentsreorg/shrink/move,enq:FB,enq:HW,Recyclebinissues,segmentadvisorsegmentsreorg/shrink/move,enq:FB,enq:HW,Recyclebinissues,segmentadvisorKeywordsDBMS_LOB.GETLENGTH DBMS_SPACE.FREE_BLOCKS DBMS_SPACE.SPACE_USAGE DBMS_SPACE.UNUSED_SPACE FREESPACE HWM LOB SHRINKErrorsKTSBVMAP1 KTSIRCINFO_NUM1 ORA1555 ORA600[25012] ORA600[KTSBVMAP1] ORA600[KTSIRCINFO_NUM1]BacktoTopCopyright(c)2015,Oracle.Allrightsreserved.LegalNoticesandTermsofUse PrivacyStatement