lob segment shrink space

4
PowerView is Off (0) Faisal (Available) Contact Us Help In this Document Goal Solution References APPLIES TO: Oracle Database Enterprise Edition Version 9.2.0.1 to 11.2.0.3 [Release 9.2 to 11.2] Information in this document applies to any platform. GOAL Some hints about how to check the actual size of a LOB segment including the free and available space, above and below the HWM, including the commands to free the space above the HWM. SOLUTION The size of the LOB segment can be found by querying dba_segments, as follows: select bytes from dba_segments where segment_name ='<lob segment name>' and owner ='<table owner>'; To get the details of the table to which this LOB segment belong to: SELECT TABLE_NAME, COLUMN_NAME FROM DBA_LOBS WHERE OWNER = '<owner>' AND SEGMENT_NAME= '<lob segment name>' ; The first thing to do would be to check the space that is actually allocated to the LOB data. select sum(dbms_lob.getlength (<lob column name>)) from <table_name>; Please note that the UNDO data for a LOB segment is kept within the LOB segment space. The above query result is merely the still active LOB data. The rest of allocated data is undo space. The undo space can vary quite a lot, from being very small in size (when LOBs are only inserted) to being very large (when many LOBs are deleted) and is largely depending on the PCTVERSION LOB parameter or the RETENTION parameter. Hence, The difference between these two is free space and/or undo space. It is not possible to assess the actual empty space using the queries above alone, because of the UNDO segment size, which is virtually impossible to assess. Furthermore, even when there is free space in the LOB, this does not mean this space can be released to the tablespace, it could be under the HWM. To find the freeable space, use the UNUSED_SPACE procedure as shown below. Check the "free" space within a LOB segment. First, remember that a lob can have 3 states: "inuse", "deleted" and "free". There are no statistics for the LOB segment, the DBMS_SPACE package is the only tool that could give an idea about it. As well, there is no view showing the deleted space within the LOB. The deleted space can be converted into free by rebuilding the freelist or by rebuilding the LOB segment itself, but this is not always possible. Note: LOB Partition sizing is not supported in DBMS_SPACE package until 10g. Error ORA00600 [ktsircinfo_num1] will be generated if the procedure is run against the lob partition on versions below 10g P.S: When using dbms_lob.getlength, the output is in characters for CLOBs and NCLOBs, and in bytes for BLOBS and BFILES. One can get an idea about how much space is actually used and what could be deallocated as follows: 1. Determine the unused space within the LOB segment, above the HWM. using the UNUSED_SPACE procedure. set serveroutput on declare TOTAL_BLOCKS number; TOTAL_BYTES number; UNUSED_BLOCKS number; UNUSED_BYTES number; LAST_USED_EXTENT_FILE_ID number; LAST_USED_EXTENT_BLOCK_ID number; LAST_USED_BLOCK number; begin dbms_space.unused_space('<owner>','<lob segment name>','LOB', TOTAL_BLOCKS, TOTAL_BYTES, UNUSED_BLOCKS, UNUSED_BYTES, LAST_USED_EXTENT_FILE_ID, LAST_USED_EXTENT_BLOCK_ID, LAST_USED_BLOCK); Document Details Type: Status: Last Major Update: Last Update: HOWTO PUBLISHED 16Dec2014 16Dec2014 Related Products Oracle Database Enterprise Edition Information Centers Index of Oracle Database Information Centers [1568043.2] Information Center: Overview of Database Security Products [1548952.2] Information Center: Overview Database Server/Client Installation and Upgrade/Migration [1351022.2] Document References How to Determine what storage is used in a LOBSEGMENT and should it be shrunk / reorganized? [1453350.1] 11g Advanced Compression How to Check Space Occupied by LOB Compression [861344.1] Recently Viewed How to determine the actual size of the LOB segments and how to free the deleted/unused space above/below the HWM (Doc ID 386341.1) To Bottom How to Free Space from LOB Segments in the SOA Schema [1380989.1] SEGMENT ADVISOR not Working as Expected for LOB or SYS_LOB SEGMENT [988744.1] Data Guard Support for Heterogeneous Primary and Physical Standbys in Same Data Guard Configuration [413484.1] MAA Creating a Single Instance Physical Standby for a RAC Primary [387339.1] Downgrading Database Without Executing catdwgrd.sql (11.1.0.x to 10.2.0.x/10.2.0.x to 10.2.0.x) [783643.1] Show More Dashboard Service Requests Patches & Updates Knowledge Give Feedback...

Upload: theahmadkhan

Post on 18-Aug-2015

249 views

Category:

Documents


2 download

DESCRIPTION

Lob Segment Shrink Space

TRANSCRIPT

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