数据库没有备份无法打开处理方法之二dul
2017-06-10 10:16
369 查看
由于企业的数据库人员经验不足,或是根本没有dba,因此,可能会出现数据瘫痪,数据库不能打开的现象,但是又没有备份,那么我们一般有两种方法:
a,数据库强行打开;
b,使用oracledul工具来把数据抽取出来
一般使用dul都是强行打开数据库都无法打开,或是某个表空间文件无法online的情况下才使用,需要把这个表空间的数据挽救出来。注意此工具需要system表空间是好的。
dul是oracle内部工具,原来没有什么限制,现在有了时间限制为30天,也就是说,如果下载下来使用超过30天,就无法使用了。大家记住这个工具只是为了挽救数据,此工具会把数据库中的表的数据抽取出来,用户中的索引,存储过程,函数,触发器之类的除了表以外的对象不能使用此工具,并且即使表数据抽取出来,表的结构也无法正确抽取出来,比如表结构中一列idnumber(20)notnull,当导入的时候此列只能是idnumber,无法显示number(20),后面的非空也不会有,因此只能说挽救数据。此工具抽取数据生成两种格式的文件,一个是.dmp文件,可以直接使用imp导入,另外一个是sqlldr文件,只能使用sqlldr命令加载进去。那么其他对象怎么才可以获得到,有两个办法:
1.从开发商那里获得到用户的结构,但是不需要数据。
2.把所有文件,除了systemundo以外的其他文件全部offline,然后强行打开。如果这样可以,那么可以把用户结构导出
expsystem/passwordowner=appuserrows=n
当获得到用户结构后,需要先把空用户导入,也就是除了数据以外的用户的对象导入,然后把外键,触发器disable,然后再把dul导出的数据导入,此时要注意,如果有数据量大的表,必须要先把索引去掉,然后等导入数据后再把索引使用兵法创建的方法创建。
上边的方法最好使用第二种,因为数据库中有sequence,如果使用第一种,有可能sequence在开发商那里很小,但是在生产库很大,我们就遇到过这种情况,如果第二种方法无法实现,只能是用第一种的时候,我们可能就需要认为把sequence的cache手动加大。
下面摘自oracle文档,对dul进行一个详细说明
done.
BeforeyouuseDULyoumustbeawarethattherdbmshasmanyhiddenfeaturestoforceabaddatabaseopen.Undocumentedinit.oraparametersandeventscanbeusedtoskiprollforward,todisablerollback,disablecertainSMONactions,advancethedatabase
scnandmore.
isprintedintheloaderfileandtostandardoutput.Unloadingwillcontinuewiththenextroworblock.
forSQL*LoaderorIMP.AmatchingcontrolfileforSQL*Loaderisgeneratedaswell.
DULcanunloadindicesandindexorganizedtables.Indexunloadisusefulltodeterminehowmanyrowsatableshouldhaveortoidentifythemissingrows.
Theconfigurationparameterswithin"init.dul"willhavetobemodifiedtomatchthoseoftheoriginalplatformandO/Sratherthantheplatformfromwhichtheunloadisbeingdone.
partitionedtables.
Lateradditionsarelobs,compressedindexes,9ir2compressedtables.VarraysandADTs(userdefinedobjects)arepartlysupportedinsql*loadermode.
ASMisfullysupported,filescanbeextractedfromanasmdiskgroup.NomountedASMinstanceisused,thedisksareaccesseddirectly.Nondefaultasmallocationunitsizesaresupported.
Datacanberecoveredfromexportdumpfileswiththeunexpcommandsuite.Someinitialworkhasbeendoneforunpumptosupportdatapumpfiles.
DULcanoptionallyconverttoUTF8.ThisisforNCLOBSthatarestoredinUTF16.
MultiLevelSecurityLablesoftrustedoraclearenotsupported.
(LONG)RAW
DULcanunload(long)raws.NowadaysthereissuitableformatinSQL*Loadertopreservealllongraws.SoLongrawsandblobscanbeunloadedinbothmodes.
ORACLE8OBJECTOPTIONANDLOBS
Nestedtablesarenotyetsupported,iftheyareneededletmeknowanditwillbeadded.VarraysandADTsaresupported,alsothosethatarestoredasakernellob.CLOBS,NCLOBSaresupportedbothinSQL*Loadermodeandinexpmode.BLOBSarebesthandled
inexpmode,thegeneratedhexformatinSQL*Loadermodeisnotloadedcorrectlycurrently.
modulededicated
toDUL
bespecified.
knew,mustbeincludedinthe"control.dul"file.YoualsoneedtoeventuallyincludethefilenumbersandnamesofanyfilesfromotherTableSpacesforwhichyouwishtoeventuallyunloadTABLES andtheirdata.Thelackofinclusionofthesefileswillnotaffect
thedatadictionaryunloadstepbutitwillaffectlaterTABLEunloading.
4000
USINGDULWHENUSER$,OBJ$,TAB$andCOL$CAN BE UNLOADED
Stepstofollow:
configureDULforthetargetdatabase.Thismeanscreatingacorrect
init.dulandcontrol.dul.TheSYSTEM TableSpace'sdatafilenumbersandnamesmustbeincludedwithinthecontrol.dulfilealongwithanydatafilesforTableSpacesfromwhichyouwishtounloadTABLEsandtheirdata.ForOracle8andhigherthetablespace
numberandtherelativefilenumbermustbespecifiedforeachdatafile.
Usethe"BOOTSTRAP;"commandtoprepareforunloading.Thebootstrapprocesswillfindacompatibilitysegment,findthebootstrap$tableunloadTheold"duldictv7.ddl"renolongerneeded.
Unloadthetablesforwhichdatafileshavebeenincludedwithinthe"control.dul"file.Useoneofthefollowingcommands:
"UNLOADTABLE[owner>.]table;(donotforgetthesemicolon)
Thiswillunloadtheonetabledefinitionandthetable'sdata.
"UNLOADUSERusername;
Thisunloadsalltablesanddataforthespecifieduser.
"UNLOADDATABASE;
Thisunloadsallofthedatabasetablesavailable.(excepttheuserSYS).
yourapplicationandtheapplicationtables.ColumntypescanbeguessedbyDUL,buttableandcolumnnamesarelost.AnyoldSYSTEMtablespacefromthesamedatabasebutweeksoldcanbeofgreathelp!.MostoftheinformationthatDULusesdoesnotchange.(only
thedataobj#isduringtruncateorindexrebuild)
USINGDULWITHOUTSYSTEMTABLESPACE
Stepstofollow:
configureDULforthetargetdatabase.Thismeanscreatingacorrectinit.dulandcontrol.dul.(SeePort
specificparameters).Inthiscasecontrol.dulfilewillneedthenumbersandnamesofdatafilesfromwhichTABLEsanddatawillbeunloadedbutitdoesnotrequiretheSYSTEMTableSpace'sinformation.
SCANDATABASE;:scanthedatabase,buildextentandsegmentmap
SCANTABLES;orSCANEXTENTS;:gatherrowstatistics
Identifythelosttablesfromtheoutputofstep3.
UNLOADtheidentifiedtables.
AUTOMATEDSEARCH
Toeasethehuntforthelosttables:thescannedstatisticalinformationinseen_tab.datandseen_col.datcanbeloadedintoafreshdatabase.Ifyourecreatethetables(Hopefullythecreatetablescriptsarestillavailable)thenstructureinformationof
a"lost"tablecanbematchedtothe"seen"tablesscannedinformationwithtwoSQL*Plusscripts.(fill.sqlandgetlost.sql).
HINTSANDPITFALLS
NamesarenotreallyrelevantforDUL,onlyforthepersonwhomustloadthedata.Buttheunloadeddatadoesnothaveanyvalue,ifyoudonotknowfromwhichtableitcame.
Theguessedcolumntypescanbewrong.EventhoughthealgorithmisconservativeanddecidesUNKNOWNifnotsure.
TrailingNULLcolumnsarenotstoredinthedatabase.SoifthelastcolumnsonlycontainNULL'sthanthescannerwillNOTfindthem.(DuringunloadtrailingNULLcolumnsarehandledcorrectly).
Whenatableisdropped,thedescriptionisremovedfromthedatadictionaryonly.Thedatablocksarenotoverwrittenunlesstheyarereusedforanewsegment.Sothescannersoftwarecanseeatablethathasbeendropped.
Tableswithoutrowswillgounnoticed.
Newerobjectshaveahigherobjectidthanolderobjects.Ifantableisrecreated,orifthereisatestandaproductionversionofthesametabletheobjectidcanbeusedtodecide.
followingthreestatementswillunloadtheDEPTtable.Themostcommonformisifthedatadictionaryandtheextentmapareavailable:
Allrelevantinformationcanbespecifiedinthestatementaswell:
Oracleversion6:
Oracle7:
DUL'SOUTPUTFORMAT.
Onlycompletegoodrowsarewrittentotheoutputfile.Forthiseachrowisbuffered.Thesizeofthebuffercanchangedwiththeinit.dulparameterBUFFER.ThereisnospeedgainedwithahighBUFFERparameter,itshouldjustbebigenoughtoholdacomplete
row.Incompleteorbadrowsarenotwrittenout.TheFILE_SIZE_IN_MBinit.dulparametercanbeusedtosplittheoutput(ataproperboundary)intomultiplefiles,eachfilecanbeloadedindividually.
Therearethreedifferentmodesofoutputformat.
Exportmode
SQL*Loadermode:streamdatafiles
SQL*Loadermode:Fixedphysicalrecorddatafiles
tablestatementandthetabledata.Tablegrants,storageclauses,ortriggerswillnotbeincluded.Anminimalcreatetablestatementisincluded(nostorageclausejustcolumnnamesandtypeswithoutprecision).Thecharactersetindicationinthefileinthegenerated
headerisV6style.ItissettomeanASCIIbasedcharacterset.
Toenableexportmode,settheinit.dulparameterEXPORT_MODEtoTRUE.
AsthegeneratedpseudodumpfiledoesnotcontaincharactersetinformationsetNLS_LANGtomatchthatoftheoriginaldatabase.Inexportmodenocharactersetconversionisdone.
WhenloadingthedatayouprobablyneedtosetNLS_LANGtomatchthatoftheoriginaldatabasetopreventunwantedcharactersetconversion.
ForbothSQL*Loaderoutputformatsthecolumnswillbespaceseparatedandenclosedindoublequotes.Anydoublequoteinthedatawillbedoubled.SQL*Loaderrecognizesthisandwillloadonlyone.Thecharacterusedtoenclosethecolumnscanbechangedfrom
doublequotetoanycharacteryoulikewiththeinit.dulparameterLDR_ENCLOSE_CHAR.
Therearetwostylesofphysicalrecordorganization:
StreamMode
Nothingspecialisdoneinstreammode,anewlineisprintedaftereachrecord.Thisisacompactformatandcanbeusedifthedatadoesnotcontainnewlinecharacters.ToenablestreammodesetLDR_PHYS_REC_SIZE=0ininit.dul.
FixedPhysicalRecords
Thismodeisessentialifthedatacancontainnewlines.Onelogicalrecord,onecomleterow,canbecomposedofmultiplephysicalrecords.Thedefaultisrecordlengthis81,thisfitsnicelyonthescreenofaVT220.Thephysicalrecordsizecanbespecified
withLDR_PHYS_REC_SIZEininit.dul.
strangecharactersarestripped.(Onlyalphanumericand'_'areallowed).
IftheFILEparameterissetthegeneratednameswillbeFILEnnn.ext.Thispossibilityisaworkaroundifthefilesystemdoesnotsupportlongenoughfilenames.(Oldwindowswith6.3filenameformat)
Tounloadtabledatafromadatabaseblockthefollowinginformationmustbeknown:
Column/ClusterInformation:Thenumberandtypeofthecolumns.Forcharorvarcharcolumnsthemaximumlengthaswell.Thenumberofclustercolumnsandthetablenumberinthecluster.Thisinformationcanbesuppliedintheunloadstatementoritcan
betakenfromthepreviouslyunloadedUSER$,OBJ$,TAB$andCOL$.
Segment/Extentinformation:Whenunloadingatabletheextenttableinthedatasegmentheaderblockisusedtolocatealldatablocks.Thelocationofthissegmentheaderblock(filenumberandblocknumber)istakenfromthedatadictionaryorcanbe
specifiedintheunloadstatement.Ifthesegmentheaderisnotcorrect/availablethenanothermethodmustbeused.DULcanbuilditsownextentmapbyscanningthewholedatabase.(inaseparaterunofDULwiththescandatabasestatement.)
BINARYHEADERS
C-Structsinblockheadersarenotcopieddirectly,theyareretrievedwithspecializedfunctions.AlloffsetsofstructuremembersareprogrammedintoDUL.Thisapproachmakesitpossibletocross-unload.(UnloadanMVScreateddatafileonanHP)Apartfrom
byteorderonlyfourlayouttypeshavebeenfoundsofar.
VaxVMSandNetware:Noalignmentpaddingbetweenstructuremembers.
KoreanTicomUnixmachines:16bitalignmentofstructuremembers.
MS/DOS16bitalignmentand16bitwordsize.
Restoftheworld(IncludingAlphaVMS)structurememberalignmentonmembersize.
MACHINEDEPENDENCIES
Machinedependencies(ofthedatabase)areconfigurablewithparameters:
Orderofbytesinaword(big/littleendian).
NumberofbitsforthelowpartoftheFILE#inaDBA(BlockAddress).
AlignmentofmembersinaC-struct.
Numberofblocksorbytesbeforetheoraclefileheaderblock.
Sizeofawordusedinthesegmentheaderstructure.
UNLOADINGTHEDATADICTIONARY
DULcanusethedatadictionaryofthedatabasetobeunloadedifthefilesforitexistandareuncorrupted.Forthedatadictionarytobeused,internaltablesmustbeunloadedfirsttoexternalfiles:(USER$,OBJ$,TAB$andCOL$).Thebootstrapcommandwill
findandunloadtherequiredtables.
Ablockindexcontainsaddressofvalidoracleblocksfoundinacorruptfilesystem.Usefultomergemultiplediskimagesortounloadfromcorruptedfilesystems.Thisisonlyusefulinextremefilesystemcorruptionscenarios.
Themergecommandusestheinformationintheindexfiletolocatepossibledatablocksitlooksforacombinationoffilenumbersandobjectid,eachcandidateblockiscomparedtothecurrentblockinthedatafile.Ifthecurrentblockisbad,orhasanolder
scnthecandidatewillwillbewrittenintothedatafile.Thisisonlyusefulinextremefilesystemcorruptionscenarios.
[ owner .] tablename [ schema_name.] table_name
a,数据库强行打开;
b,使用oracledul工具来把数据抽取出来
一般使用dul都是强行打开数据库都无法打开,或是某个表空间文件无法online的情况下才使用,需要把这个表空间的数据挽救出来。注意此工具需要system表空间是好的。
dul是oracle内部工具,原来没有什么限制,现在有了时间限制为30天,也就是说,如果下载下来使用超过30天,就无法使用了。大家记住这个工具只是为了挽救数据,此工具会把数据库中的表的数据抽取出来,用户中的索引,存储过程,函数,触发器之类的除了表以外的对象不能使用此工具,并且即使表数据抽取出来,表的结构也无法正确抽取出来,比如表结构中一列idnumber(20)notnull,当导入的时候此列只能是idnumber,无法显示number(20),后面的非空也不会有,因此只能说挽救数据。此工具抽取数据生成两种格式的文件,一个是.dmp文件,可以直接使用imp导入,另外一个是sqlldr文件,只能使用sqlldr命令加载进去。那么其他对象怎么才可以获得到,有两个办法:
1.从开发商那里获得到用户的结构,但是不需要数据。
2.把所有文件,除了systemundo以外的其他文件全部offline,然后强行打开。如果这样可以,那么可以把用户结构导出
expsystem/passwordowner=appuserrows=n
当获得到用户结构后,需要先把空用户导入,也就是除了数据以外的用户的对象导入,然后把外键,触发器disable,然后再把dul导出的数据导入,此时要注意,如果有数据量大的表,必须要先把索引去掉,然后等导入数据后再把索引使用兵法创建的方法创建。
上边的方法最好使用第二种,因为数据库中有sequence,如果使用第一种,有可能sequence在开发商那里很小,但是在生产库很大,我们就遇到过这种情况,如果第二种方法无法实现,只能是用第一种的时候,我们可能就需要认为把sequence的cache手动加大。
下面摘自oracle文档,对dul进行一个详细说明
DUL'sPRINCIPLESandFEATURELIST
STANDALONEC-PROGRAM
DULisastandaloneCprogramthatdirectlyretrievesrowsfromtablesindatafiles.TheOracleRDBMSsoftwareisNOTusedatall.DULdoesdirtyreads,itassumesthateverytransactioniscommitted.Nordoesitcheck/requirethatmediarecoveryhasbeendone.
LASTRESORT
DULisintendedtoretrievedatathatcannotberetrievedotherwise.ItisNOTanalternativeforEXP,SQL*Plusetc.Itismeanttobealastresort,notfornormalproductionusage.BeforeyouuseDULyoumustbeawarethattherdbmshasmanyhiddenfeaturestoforceabaddatabaseopen.Undocumentedinit.oraparametersandeventscanbeusedtoskiprollforward,todisablerollback,disablecertainSMONactions,advancethedatabase
scnandmore.
DATABASECORRUPT-BLOCKSOK
Thedatabasecanbecorrupted,butanindividualdatablockusedmustbe100%correct.Duringallunloadingchecksaremadetomakesurethatblocksarenotcorruptedandbelongtothecorrectsegment.Ifduringascanabadblockisencountered,anerrormessageisprintedintheloaderfileandtostandardoutput.Unloadingwillcontinuewiththenextroworblock.
ROWSinCLUSTERS/TABLES/INDEXES
DULcanandwillonlyunloadindex/table/clusterdata.ItwillNOTdumptriggers,storedproceduresnorcreatesqlscriptsfortablesorviews.(Butthedatadictionarytablesdescribingthemcanbeunloaded).ThedatawillbeunloadedinaformatsuitableforSQL*LoaderorIMP.AmatchingcontrolfileforSQL*Loaderisgeneratedaswell.
DULcanunloadindicesandindexorganizedtables.Indexunloadisusefulltodeterminehowmanyrowsatableshouldhaveortoidentifythemissingrows.
CROSSPLATFORM UNLOADING
Cross-platformunloadingissupported.ThedatabasecanbecopiedfromadifferentoperatingsystemthantheDUL-host.(Databases/systemsdonesofar:Sequent/ptx,VaxVms,AlphaVms,MVS,HP9000/8xx,IBMAIX,SCOUnix,AlphaOSF/1,IntelWindowsNT).Theconfigurationparameterswithin"init.dul"willhavetobemodifiedtomatchthoseoftheoriginalplatformandO/Sratherthantheplatformfromwhichtheunloadisbeingdone.
ROBUST
DULwillnotdump,spinorhangnomatterhowbadlycorruptedthedatabaseis.(NEARLY)ALLORACLEFEATURESSUPPORTED
Fullsupportforalldatabaseconstructs:rowchaining,rowmigration,hash/indexclusters,longs,raws,rowids,dates,numbers,multiplefreelistgroups,segmenthighwatermark,NULLS,trailingNULLcolumns,andunlimitedextents,newblocklayoutofOracle8,partitionedtables.
Lateradditionsarelobs,compressedindexes,9ir2compressedtables.VarraysandADTs(userdefinedobjects)arepartlysupportedinsql*loadermode.
ASMisfullysupported,filescanbeextractedfromanasmdiskgroup.NomountedASMinstanceisused,thedisksareaccesseddirectly.Nondefaultasmallocationunitsizesaresupported.
Datacanberecoveredfromexportdumpfileswiththeunexpcommandsuite.Someinitialworkhasbeendoneforunpumptosupportdatapumpfiles.
SUPPORTEDRDBMSVERSIONS
DULshouldworkwithallversionsstartingoracle6.DULhasbeentestedwithversionsfrom6.0.26upto10.2.Eventheoldblockheaderlayout(pre6.0.27.2)issupported.MULTIBYTESUPPORT
DULitselfisessentiallyasinglebyteapplication.Thecommandparserdoesnotunderstandmultibytecharacters,butitispossibletounloadanymultibytedatabase.Forallpossiblecaveatsthereisaworkaround.DULcanoptionallyconverttoUTF8.ThisisforNCLOBSthatarestoredinUTF16.
RESTRICTIONS
MLSLABELSMultiLevelSecurityLablesoftrustedoraclearenotsupported.
(LONG)RAW
DULcanunload(long)raws.NowadaysthereissuitableformatinSQL*Loadertopreservealllongraws.SoLongrawsandblobscanbeunloadedinbothmodes.
ORACLE8OBJECTOPTIONANDLOBS
Nestedtablesarenotyetsupported,iftheyareneededletmeknowanditwillbeadded.VarraysandADTsaresupported,alsothosethatarestoredasakernellob.CLOBS,NCLOBSaresupportedbothinSQL*Loadermodeandinexpmode.BLOBSarebesthandled
inexpmode,thegeneratedhexformatinSQL*Loadermodeisnotloadedcorrectlycurrently.
PORTABLE
DULcanbeportedtoanyoperatingsystemwithanANSI-Ccompiler.DULhasbeenportedtomanyUNIXvariants,VMSandWindowsNT.CurrentlyallbuildsaredoneusinggccandacrosscompilerenvironmentonLinuxRDBMSINTERNALS
AgoodknowledgeoftheOracleRDBMSinternalsisaprerequisitetobeabletouseDULsuccessfully.ForinstancetheDataServerInternals(DSI)coursesgiveagoodfoundation.ThereisevenatoDUL
SETTINGUPandUSING DUL
CONFIGURATIONFILES
TherearetwoconfigurationfilesforDUL."init.dul"containsallconfigurationparameters.(sizeofcaches,detailsofheaderlayout,oracleblocksize,outputfileformat)Inthecontrolfile,"control.dul",thedatabasedatafilenamesandtheasmdiskscanbespecified.
DATA DICTIONARY AVAILABLE
TheOracledatadictionaryisavailableifthedatafileswhichmadeuptheSYSTEMTableSpaceareavailableanduseable.ThenumberwhichOracleassignedtothesefilesandthenameyouhavegiventhem,whichdoesnothavetobetheoriginalnamewhichOracleknew,mustbeincludedinthe"control.dul"file.YoualsoneedtoeventuallyincludethefilenumbersandnamesofanyfilesfromotherTableSpacesforwhichyouwishtoeventuallyunloadTABLES andtheirdata.Thelackofinclusionofthesefileswillnotaffect
thedatadictionaryunloadstepbutitwillaffectlaterTABLEunloading.
4000
USINGDULWHENUSER$,OBJ$,TAB$andCOL$CAN BE UNLOADED
Stepstofollow:
configureDULforthetargetdatabase.Thismeanscreatingacorrect
init.dulandcontrol.dul.TheSYSTEM TableSpace'sdatafilenumbersandnamesmustbeincludedwithinthecontrol.dulfilealongwithanydatafilesforTableSpacesfromwhichyouwishtounloadTABLEsandtheirdata.ForOracle8andhigherthetablespace
numberandtherelativefilenumbermustbespecifiedforeachdatafile.
Usethe"BOOTSTRAP;"commandtoprepareforunloading.Thebootstrapprocesswillfindacompatibilitysegment,findthebootstrap$tableunloadTheold"duldictv7.ddl"renolongerneeded.
Unloadthetablesforwhichdatafileshavebeenincludedwithinthe"control.dul"file.Useoneofthefollowingcommands:
"UNLOADTABLE[owner>.]table;(donotforgetthesemicolon)
Thiswillunloadtheonetabledefinitionandthetable'sdata.
"UNLOADUSERusername;
Thisunloadsalltablesanddataforthespecifieduser.
"UNLOADDATABASE;
Thisunloadsallofthedatabasetablesavailable.(excepttheuserSYS).
NODATA DICTIONARY AVAILABLE
IfdatafilesarenotavailablefortheSYSTEM TableSpacetheunloadcanstillcontinuebutUSER,TABLEandCOLUMnameswillnotbeknown.Identifyingthetablescanbeanoverwhelmingtask.Butitcanbe(andhasbeen)done.Youneedindepthknowledgeaboutyourapplicationandtheapplicationtables.ColumntypescanbeguessedbyDUL,buttableandcolumnnamesarelost.AnyoldSYSTEMtablespacefromthesamedatabasebutweeksoldcanbeofgreathelp!.MostoftheinformationthatDULusesdoesnotchange.(only
thedataobj#isduringtruncateorindexrebuild)
USINGDULWITHOUTSYSTEMTABLESPACE
Stepstofollow:
configureDULforthetargetdatabase.Thismeanscreatingacorrectinit.dulandcontrol.dul.(SeePort
specificparameters).Inthiscasecontrol.dulfilewillneedthenumbersandnamesofdatafilesfromwhichTABLEsanddatawillbeunloadedbutitdoesnotrequiretheSYSTEMTableSpace'sinformation.
SCANDATABASE;:scanthedatabase,buildextentandsegmentmap
SCANTABLES;orSCANEXTENTS;:gatherrowstatistics
Identifythelosttablesfromtheoutputofstep3.
UNLOADtheidentifiedtables.
AUTOMATEDSEARCH
Toeasethehuntforthelosttables:thescannedstatisticalinformationinseen_tab.datandseen_col.datcanbeloadedintoafreshdatabase.Ifyourecreatethetables(Hopefullythecreatetablescriptsarestillavailable)thenstructureinformationof
a"lost"tablecanbematchedtothe"seen"tablesscannedinformationwithtwoSQL*Plusscripts.(fill.sqlandgetlost.sql).
HINTSANDPITFALLS
NamesarenotreallyrelevantforDUL,onlyforthepersonwhomustloadthedata.Buttheunloadeddatadoesnothaveanyvalue,ifyoudonotknowfromwhichtableitcame.
Theguessedcolumntypescanbewrong.EventhoughthealgorithmisconservativeanddecidesUNKNOWNifnotsure.
TrailingNULLcolumnsarenotstoredinthedatabase.SoifthelastcolumnsonlycontainNULL'sthanthescannerwillNOTfindthem.(DuringunloadtrailingNULLcolumnsarehandledcorrectly).
Whenatableisdropped,thedescriptionisremovedfromthedatadictionaryonly.Thedatablocksarenotoverwrittenunlesstheyarereusedforanewsegment.Sothescannersoftwarecanseeatablethathasbeendropped.
Tableswithoutrowswillgounnoticed.
Newerobjectshaveahigherobjectidthanolderobjects.Ifantableisrecreated,orifthereisatestandaproductionversionofthesametabletheobjectidcanbeusedtodecide.
DDL(DULDescriptionLanguage)UNLOADSTATEMENTOVERVIEW
DULusesanSQLlikecommandinterface.ThereareDDLstatementstounloadextents,tables,usersortheentiredatabase.Datadictionaryinformationrequiredcanbespecifiedintheddlstatementsortakenfromthepreviouslyunloadeddatadictionary.ThefollowingthreestatementswillunloadtheDEPTtable.Themostcommonformisifthedatadictionaryandtheextentmapareavailable:
UNLOADTABLEscott.dept;
Allrelevantinformationcanbespecifiedinthestatementaswell:
REMColumnswithtypeinthecorrectorder
REMThesegmentheaderloactioninthestorageclause
UNLOADTABLEdept(deptnoNUMBER,dnameCHAR,locCHAR)
STORAGE(EXTENTS(FILE1BLOCK1205));
Oracleversion6:
REMversion6datablockshavesegmentheaderlocationineachblock
ALTERSESSIONSETUSE_SCANNED_EXTENT_MAP=TRUE;
UNLOADTABLEdept(deptnoNUMBER,dnameCHAR,locCHAR)
STORAGE(EXTENTS(FILE1BLOCK1205));
Oracle7:
REMOracle7datablockshaveobjectidineachblock
ALTERSESSIONSETUSE_SCANNED_EXTENT_MAP=TRUE;
UNLOADTABLEdept(deptnoNUMBER,dnameCHAR,locCHAR)
STORAGE(OBJNO1501);
DUL'SOUTPUTFORMAT.
Onlycompletegoodrowsarewrittentotheoutputfile.Forthiseachrowisbuffered.Thesizeofthebuffercanchangedwiththeinit.dulparameterBUFFER.ThereisnospeedgainedwithahighBUFFERparameter,itshouldjustbebigenoughtoholdacompleterow.Incompleteorbadrowsarenotwrittenout.TheFILE_SIZE_IN_MBinit.dulparametercanbeusedtosplittheoutput(ataproperboundary)intomultiplefiles,eachfilecanbeloadedindividually.
Therearethreedifferentmodesofoutputformat.
Exportmode
SQL*Loadermode:streamdatafiles
SQL*Loadermode:Fixedphysicalrecorddatafiles
EXPORT MODE
ThegeneratedfileiscompletelydifferentfromatablemodeexportgeneratedbyEXP!ThefileistheminimalformatthatIMPcanload.ForeachtableaseparateIMPloadablefilewillbegenerated.Itisasingletabledumpfile.Itcontainsaheaderaninserttablestatementandthetabledata.Tablegrants,storageclauses,ortriggerswillnotbeincluded.Anminimalcreatetablestatementisincluded(nostorageclausejustcolumnnamesandtypeswithoutprecision).Thecharactersetindicationinthefileinthegenerated
headerisV6style.ItissettomeanASCIIbasedcharacterset.
Toenableexportmode,settheinit.dulparameterEXPORT_MODEtoTRUE.
AsthegeneratedpseudodumpfiledoesnotcontaincharactersetinformationsetNLS_LANGtomatchthatoftheoriginaldatabase.Inexportmodenocharactersetconversionisdone.
SQL*LOADER MODES
Thedataintheiseithernotconvertedatall,oreverthingisconvertedtoUTF8ifLDR_OUTPUT_IN_UTF8isset.Thissettingisrequiredinmixedcharactersetenvironmentsasthecontentsofadatafilemusthaveasinglecharacterset.WhenloadingthedatayouprobablyneedtosetNLS_LANGtomatchthatoftheoriginaldatabasetopreventunwantedcharactersetconversion.
ForbothSQL*Loaderoutputformatsthecolumnswillbespaceseparatedandenclosedindoublequotes.Anydoublequoteinthedatawillbedoubled.SQL*Loaderrecognizesthisandwillloadonlyone.Thecharacterusedtoenclosethecolumnscanbechangedfrom
doublequotetoanycharacteryoulikewiththeinit.dulparameterLDR_ENCLOSE_CHAR.
Therearetwostylesofphysicalrecordorganization:
StreamMode
Nothingspecialisdoneinstreammode,anewlineisprintedaftereachrecord.Thisisacompactformatandcanbeusedifthedatadoesnotcontainnewlinecharacters.ToenablestreammodesetLDR_PHYS_REC_SIZE=0ininit.dul.
FixedPhysicalRecords
Thismodeisessentialifthedatacancontainnewlines.Onelogicalrecord,onecomleterow,canbecomposedofmultiplephysicalrecords.Thedefaultisrecordlengthis81,thisfitsnicelyonthescreenofaVT220.Thephysicalrecordsizecanbespecified
withLDR_PHYS_REC_SIZEininit.dul.
OUTPUT FILE NAMES
Thefilenamesgeneratedare:ownername_tablename.ext.Theextensionis".dmp"forIMPloadablefiles.".dat"and".ctl"areusedfortheSQL*Loaderdatafileandthecontrolfile.Topreventvariablesubstitutionandotherunwantedsideeffects,strangecharactersarestripped.(Onlyalphanumericand'_'areallowed).
IftheFILEparameterissetthegeneratednameswillbeFILEnnn.ext.Thispossibilityisaworkaroundifthefilesystemdoesnotsupportlongenoughfilenames.(Oldwindowswith6.3filenameformat)
SOMEDULINTERNALS
REQUIREDINFORMATIONTounloadtabledatafromadatabaseblockthefollowinginformationmustbeknown:
Column/ClusterInformation:Thenumberandtypeofthecolumns.Forcharorvarcharcolumnsthemaximumlengthaswell.Thenumberofclustercolumnsandthetablenumberinthecluster.Thisinformationcanbesuppliedintheunloadstatementoritcan
betakenfromthepreviouslyunloadedUSER$,OBJ$,TAB$andCOL$.
Segment/Extentinformation:Whenunloadingatabletheextenttableinthedatasegmentheaderblockisusedtolocatealldatablocks.Thelocationofthissegmentheaderblock(filenumberandblocknumber)istakenfromthedatadictionaryorcanbe
specifiedintheunloadstatement.Ifthesegmentheaderisnotcorrect/availablethenanothermethodmustbeused.DULcanbuilditsownextentmapbyscanningthewholedatabase.(inaseparaterunofDULwiththescandatabasestatement.)
BINARYHEADERS
C-Structsinblockheadersarenotcopieddirectly,theyareretrievedwithspecializedfunctions.AlloffsetsofstructuremembersareprogrammedintoDUL.Thisapproachmakesitpossibletocross-unload.(UnloadanMVScreateddatafileonanHP)Apartfrom
byteorderonlyfourlayouttypeshavebeenfoundsofar.
VaxVMSandNetware:Noalignmentpaddingbetweenstructuremembers.
KoreanTicomUnixmachines:16bitalignmentofstructuremembers.
MS/DOS16bitalignmentand16bitwordsize.
Restoftheworld(IncludingAlphaVMS)structurememberalignmentonmembersize.
MACHINEDEPENDENCIES
Machinedependencies(ofthedatabase)areconfigurablewithparameters:
Orderofbytesinaword(big/littleendian).
NumberofbitsforthelowpartoftheFILE#inaDBA(BlockAddress).
AlignmentofmembersinaC-struct.
Numberofblocksorbytesbeforetheoraclefileheaderblock.
Sizeofawordusedinthesegmentheaderstructure.
UNLOADINGTHEDATADICTIONARY
DULcanusethedatadictionaryofthedatabasetobeunloadedifthefilesforitexistandareuncorrupted.Forthedatadictionarytobeused,internaltablesmustbeunloadedfirsttoexternalfiles:(USER$,OBJ$,TAB$andCOL$).Thebootstrapcommandwill
findandunloadtherequiredtables.
DDL(DULDESCRIPTIONLANGUAGE)SPECIFICATION
[ALTERSESSION]SETinit.dulparameter= value;
Mostparameterscanbechangedonthefly.
BOOTSTRAP[LOCATE|GENERATE|COMPLETE
|UNLOAD Bootstrap$segmentheaderblockaddress];
Bootstrapsthedatadictionary.DefaultisCOMPLETE.
LOCATEfindsandunloadsthebootstrap$table.
GENERATEbuildsaddlfilebasedoninforationinthecache.
COMPLETEisinfactLOCATE,followedbyGENERATE(twotimes)
COMMIT;
Writesthechangedblocktothedatafile.
CREATEBLOCKINDEX index_name ON device;
Ablockindexcontainsaddressofvalidoracleblocksfoundinacorruptfilesystem.Usefultomergemultiplediskimagesortounloadfromcorruptedfilesystems.Thisisonlyusefulinextremefilesystemcorruptionscenarios.
DESCRIBE owner_name .table_name;
DUMP[TABLESPACE tablespace_no]
[FILE file_no ]
[BLOCK block_no ]
[LEVEL level_no ];
Notacompleteblockdump,mainlyusedfordebugging.
Theblockaddressisremembered.
EXTRACT asmfilename to outputfilename ;
CopiesanyASMfilefromadiskgrouptothefilesystem.
(therewasaproblemwithonlineredologsthisneedsmoretesting)
MERGEblock_indexINTO[ segment ];
Themergecommandusestheinformationintheindexfiletolocatepossibledatablocksitlooksforacombinationoffilenumbersandobjectid,eachcandidateblockiscomparedtothecurrentblockinthedatafile.Ifthecurrentblockisbad,orhasanolder
scnthecandidatewillwillbewrittenintothedatafile.Thisisonlyusefulinextremefilesystemcorruptionscenarios.
REMany_text_you_like_till_End_Of_Line:comment
REM NOTallowedinsideddlstatements.(Toavoidatwolayerlexicalscan).
ROLLBACK;#CancelstheUPDATEstatements.
SHOW DBA dba; #dba->file_noblock_nocalculator
|DBA rfile_noblock_no; #file_noblock_no->dbacalculator
|SIZES; #showsomesizeofimportantstructs
|PARAMETER; #showsthevaluesofallparameters
|LOBINFO; #lobindexesfoundwithSCANDATABASE
|DATAFILES; #summaryofconfigureddatafiles
|ASMDISKS; #summaryofconfiguredasmdisks
|ASMFILES; #summaryofconfigureddatafilesonasm
|ASMFILE cid #extentinformationforasmfile
UNEXP