您的位置:首页 > 数据库 > Oracle

Oracle DUL/AUL/ODU 工具说明

2011-09-14 17:39 267 查看
假设我们的数据库遇到以下情况:

第一,没有备份;

第二,常规方法无法恢复;

第三,数据很重要,但又无法或成本太高而进行重新输入.如丢失了Oracle的System表空间,System表空间损坏到无法启动的地步,意外删除表空间或表,意外截断(Truncate)表等,

在这3中情况下,最后的方法就是通过工具直接读取数据文件里的数据,将我们的数据找回来。并且工具不需要Oracle环境的支持。

据我目前的了解,有3种工具:

(1)Oracle的内部工具是DUL(DataUnLoader)。这个需要Oracle的支持。

(2)老熊写的ODU。网址:http://www.oracleodu.com/en/

(3)d.c.b.a(支付宝楼方鑫)写的AUL.网址:http://www.anysql.net/download

ODU之前是免费的,现在老熊和dbsnake在维护ODU,需要购买才能使用。

d.c.b.a的AUL是用C语言写的,免费版本最大只支持2个,最大256M的datafile。如果是更大的datafile,也是需要购买授权。

能写出这样的软件都是牛人了,需要了解各个版本Oracleblock的详细信息。AUL和ODU的操作和OracleDUL类似。

关于DUL,MOS有说明:MOSNote72554.1

UsingDULtoRecoverfromDatabaseCorruption

TableOfContents
~~~~~~~~~~~~~~~~~
1.Introduction
2.UsingDUL
2.1Createanappropriateinit.dulfile
2.2Createthecontrol.dulfile
2.3Unloadtheobjectinformation
2.4InvokeDUL
2.5Rebuildthedatabase
3.Howtorebuildobjectdefinitionsthatarestoredinthedatadictionary?
4.Howtounloaddatawhenthesegmentheaderblockiscorrupted?
5.Howtounloaddatawhenthefileheaderblockiscorrupted?
6.Howtounloaddatawithoutthesystemtablespace?
7.AppendixA:Wheretofindtheexecutables?
8.References
1.Introduction
~~~~~~~~~~~~~~~
ThisdocumentistoexplainhowtouseDULratherthantogiveafull
explanationofBernard'sDataUnLoadercapabilities.
Thisdocumentisforinternaluseonlyandshouldnotbegiventocustomersat
anytime,Dulshouldalwaysbeusedbyorunderthesupervisionofasupport
analyst.
DUL(DataUnLoader)isintendedtoretrievedatafromtheOracleDatabasethat
cannotberetrievedotherwise.Thisisnotanalternativefortheexport
utilityorSQL*Loader.Thedatabasemaybecorruptedbutanindividualdata
blockusedmustbe100%correct.Duringallunloadingchecksaremadetomake
surethatblocksarenotcorruptedandbelongtothecorrectsegment.Ifa
corruptedblockisdetectedbyDUL,anerrormessageisprintedintheloader
fileandtothestandardoutput,butthiswillnotterminatetheunloadingof
thenextroworblock.
2.UsingDUL
~~~~~~~~~~~~
Firstyoumustretrievethenecessaryinformationabouttheobjectsthatexists
inthedatabase,thesestatisticswillbeloadedintotheDULdictionaryto
unloadthedatabaseobjects.
ThisinformationisretrievedfromtheUSER$,OBJ$,TAB$andCOL$tablesthat
werecreatedatdatabasecreationtime,theycanbeunloadedbasedonthefact
thatobjectnumbersarefixedforthesetablesduetotherigidnatureofsql.
bsq.DULcanfindtheinformationinthesystemtablespace,thereforthesystem
tablespacedatafile(s)mustbeincludedinthecontrolfile,ifthisdatafile(s)
isnotpresentseechapter6.
2.1Createanappropriate"init.dul"file
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
REMPlatformspecificparameters(NT)
REMAListofparametersforthemostcommonplatformscanbeobtainedfrom
REM
'target='_blank'>http://www.nl.oracle.com/support/dul/index.html
osd_big_endian_flag=false
osd_dba_file_bits=10
osd_c_struct_alignment=32
osd_file_leader_size=1
osd_word_size=32
REMSizesofduldictionarycaches.Ifoneoftheseistoolowstartupwill
REMfail.
dc_columns=2000000
dc_tables=10000
dc_objects=1000000
dc_users=400
dc_segments=100000
REMLocationandfilenameofthecontrolfile,defaultvalueiscontrol.dul
REMinthecurrentdirectory
control_file=D:\Dul\control_orcl.dul
REMDatabaseblocksize,canbefoundintheinit<SID>.orafileorcanbe
REMretrievedbydoing"showparameter%db_block_size%"inservermanager
REM(svrmgr23/30/l)changesthisparametertowhatevertheblocksizeisof
REMthecrasheddatabase.
db_block_size=4096
REMCan/mustbespecifiedwhendataisneededintoexport/importformat.
REMthiswillcreateafilesuitabletousebytheoracleimportutility,
REMalthoughthegeneratedfileiscompletelydifferentfromatablemode
REMexportgeneratedbytheEXPutility.Itisasingletabledumpfile
REMwithonlyacreatetablestructurestatementandthetabledata.
REMGrants,storageclauses,triggersarenotincludedintothisdumpfile!
export_mode=true
REMCompatibleparametermustbespecifiedancanbeeither6,7or8
compatible=8
REMThisparameterisoptionalandcanbespecifiedonplatformsthatdo
REMnotsupportlongfilenames(e.g.8.3DOS)orwhenthefileformatthat
REMDULuses"owner_name.table_name.ext"isnotacceptable.Thedumpfiles
REMwillbesomethinglikedump001.ext,dump002.ext,etcinthiscase.
file=dump
Acompletelistcanbeobtainedat
'target='_blank'>http://www.nl.oracle.com/support/DUL/ucg8.
htmlsection"DULParameters"althoughthisinit.dulfilewillworkinmost
casesandcontainsallaccurateparameterstosuccesfullycompletethe
unloading.
2.2Createthe"control.dul"file
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Agoodknowledgeaboutthelogicaltablespaceandphysicaldatafile
structureisneededoryoucandothefollowingquerieswhenthedatabase
ismounted:
Oracle6,7
-----------
>connectinternal
>spoolcontrol.DUL
>select*fromv$dbfile;
>spooloff
Oracle8
--------
>connectinternal
>spoolcontrol.DUL
>selectts#,rfile#,namefromv$datafile;
>spooloff
Editthespoolfileandchange,ifneeded,thedatafilelocationandstripe
outunnecessaryinformationliketableheaders,feedbackline,etc...
Asamplecontrolfilelookssomethinglikethis:
REMOracle7controlfile
1D:\DUL\DATAFILE\SYS1ORCL.DBF
3D:\DUL\DATAFILE\DAT1ORCL.DBF
7D:\DUL\DATAFILE\USR1ORCL.DBF
REMOracle8controlfile
01D:\DUL\DATAFILE\SYS1ORCL.DBF
12D:\DUL\DATAFILE\USR1ORCL.DBF
13D:\DUL\DATAFILE\USR2ORCL.DBF
24D:\DUL\DATAFILE\DAT1ORCL.DBF
Note:Eachentrycancontainapartofadatafile,thiscanbeusefulwhen
youneedtosplitdatafilesthataretoobigforDUL,sothateach
partissmallerthanforexample2GB.Forexample:
REMOracle8withadatafilesplitintomultipleparts,eachpartis
REMsmallerthan1GB!
01D:\DUL\DATAFILE\SYS1ORCL.DBF
12D:\DUL\DATAFILE\USR1ORCL.DBFstartblock1endblock1000000
12D:\DUL\DATAFILE\USR1ORCL.DBFstartblock1000001endblock2000000
12D:\DUL\DATAFILE\USR1ORCL.DBFstartblock2000001endblock2550000
2.3Unloadtheobjectinformation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
StarttheDULutilitywiththeappropriateddl(DulDescriptionLanguage)
script.Thereare3scriptsavailabletounloadtheUSER$,OBJ$,TAB$and
COL$tablesaccordingtothedatabaseversion.
Oracle6:>dul8.exedictv6.ddl
Oracle7:>dul8.exedictv7.ddl
Oracle8:>dul8.exedictv8.ddl
DataUnLoader:Release8.0.5.3.0-InternalUseOnly-onTueJun2222:19:
Copyright(c)1994/1999BernardvanDuijnenAllrightsreserved.
Parameteraltered
Sessionaltered.
Parameteraltered
Sessionaltered.
Parameteraltered
Sessionaltered.
Parameteraltered
Sessionaltered.
.unloadingtableOBJ$2271rowsunloaded
.unloadingtableTAB$245rowsunloaded
.unloadingtableCOL$10489rowsunloaded
.unloadingtableUSER$22rowsunloaded
.unloadingtableTABPART$0rowsunloaded
.unloadingtableIND$274rowsunloaded
.unloadingtableICOL$514rowsunloaded
.unloadingtableLOB$13rowsunloaded
LifeisDULwithoutit
ThiswillunloadthedataoftheUSER$,OBJ$,TAB$andCOl$datadictionary
tablesintoSQL*Loaderfiles,thiscannotbemanipulatedintodumpfiles
oftheimportformat.Theparameterexport_mode=falseishardcodedinto
theddlscriptsandcannotbechangedtothevalue"true"sincethiswill
causeDULtofailwiththeerror:
.unloadingtableOBJ$
DUL:Error:Column"DATAOBJ#"actualsize(2)greaterthanlengthincolumn
definition(1)
.............etc...............
2.4InvokeDUL
~~~~~~~~~~~~~~
StartDULininteractivemodeoryoucanprepareascriptsthatcontainsall
theddlcommandstounloadthenecessarydatafromthedatabase.Iwill
describeinthisdocumentthemostusedcommands,thisisnotacompletelist
ofpossibleparametersthatcanbespecified.Acompletelistcanbefoundat
http://www.nl.oracle.com/support/DUL/ucg8.htmlsection"DDLDescription".
DUL>unloaddatabase;
=>thiswillunloadtheentiredatabasetables(includessys'tablesaswell)
DUL>unloaduser<username>;
=>thiswillunloadallthetablesownedbythatparticullarlyuser.
DUL>unloadtable<username.table_name>;
=>thiswillunloadthespecifiedtableownedbythatusername
DUL>describe<owner_name.table_name>;
=>willrepresentthetablecolumnswiththererelativepointerstothe
datafile(s)ownedbythespecifieduser.
DUL>scandatabase;
=>Scansallblocksofalldatafiles.
Twofilesaregenerated:
1:seg.datinformationoffoundsegmentheaders(index/cluster/table)
(objectid,filenumber,andblocknumber).
2:ext.datinformationofcontiguoustable/clusterdatablocks.
(objectid(V7),fileandblocknumberofsegmentheader(V6),
filenumberandblocknumberoffirstblock,
numberofblocks,numberoftables)
DUL>scantables;
=>Usesseg.datandext.datasinput.
Scansalltablesinalldatasegments(aheaderblockandatleastone
matchingextentwithatleast1table).
2.5Rebuildthedatabase
~~~~~~~~~~~~~~~~~~~~~~~~
CreatethenewdatabaseanduseimportorSQL*Loadertorestorethedata
retrievedbyDUL.Notethatwhenyouonlyunloadedthedatathattable
structures,indexation,grants,PL/SQLandtriggerswillnolongerexistin
thenewdatabase.Toobtainanexactlysamecopyofthedatabaseasbefore
youwillneedtorerunyourcreationscriptsforthetables,indexes,PL/SQL,
etc.
Ifyoudon'thavethesescriptsthenyouwillneedtoperformthesteps
describedinsection3ofthisdocument.
3.Howtorebuildobjectdefinitionsthatarestoredinthedatadictionary
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
YouwanttorebuildPL/SQL(packages,procedures,functionsortriggers),grants,
indexes,constraintsorstorageclauses(oldtablestructure)withDUL.Thiscan
bedonebutisalittlebittricky.Youneedtounloadtherelevantdata
dictionarytablesusingDULandthenloadthesetablesintoahealthydatabase,
besuretouseadifferentuserthansysor(system).Loadingthedata
dictionarytablesofthecrasheddatabaseintothehealthydatabasedictionary
couldcorruptthehealthydatabaseaswell.
Detailedexplanationtoretrieveforexamplepl/sqlpackages/procedures/
functionsfromacorrupteddatabase:
1)Followthestepsexplainedinthe"UsingDUL"sectionandunloadthedata
dictionarytable"source$"
2)Createanewuserintoahealthydatabaseandspecifythedesireddefault
andtemporarytablespace.
3)Grantconnect,resource,imp_full_databasetothenewuser.
4)Import/loadthetable"source$"intothenewcreatedschema:
e.g.:imp80userid=newuser/passwfile=d:\dul\scott_emp.dmp
log=d:\dul\impemp.txtfull=y
5)Youcannowqueryfromthetable<newuser.source$>torebuildthepl/sql
procedures/functionsfromthecorrupteddatabase.Scriptscanbefoundon
WebIvtogeneratesuchPL/SQLcreationscripts.
Thesamestepscanbefollowedtorecreateindexes,constraints,andstorage
parametersortoregrantprivilegestotheappropiateusers.Pleasenoticethat
youalwaysneedtouseascriptofsomekindthatcanrecreatetheobjectsand
includeallthefeaturesofthecrasheddatabaseversion.Forexample:when
thecrasheddatabaseisofversion7.3.4andyouhaveseveralbitmapindexes,
ifyouwoulduseascriptthatsupportsversion7.3.2orprior,thenyouwon't
beabletorecreatethebitmapindexessuccesful!
4.Howtounloaddatawhenthesegmentheaderblockiscorrupted
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
WhenDULcan'tretrievedatablockinformationonthenormalway,itcanscan
thedatabasetocreateitsownsegment/extentmap.Theprocedureofscanning
thedatabaseisnecessarytounloadthedatafromthedatafiles.
(toillustratethisexampleIcopiedanemptyblockontopofthesegmentheader
block)
1)Createanappropiate"init.dul"(see2.1)and"control.dul"(see2.2)file.
2)Unloadthetable.Thiswillfailandindicatethatthereisacorruptionin
thesegmentheaderblock:
DUL>unloadtablescott.emp;
.unloadingtableEMP
DUL:Warning:Blockisneverused,blocktypeiszero
DUL:Error:Whilecheckingtablespace6file10block2
DUL:Error:Whileprocessingblockts#=6,file#=10,block#=2
DUL:Error:Couldnotread/parsesegmentheader
0rowsunloaded
3)runthescandatabasecommand:
DUL>scandatabase;
tablespace0,datafile1:10239blocksscanned
tablespace6,datafile10:2559blocksscanned
4)IndicatetoDULthatitshoulduseitsowngeneratedextentmapratherthan
thesegmentheaderinformation.
DUL>altersessionsetuse_scanned_extent_map=true;
Parameteraltered
Sessionaltered.
DUL>unloadtablescott.emp;
.unloadingtableEMP14rowsunloaded
5.Howtounloaddatawhenthedatafileheaderblockiscorrupted
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Acorruptioninthedatafileheaderblockisalwayslistedatthemomentyou
openthedatabasethisisnotlikeaheadersegmentblockcorruption(seepoint
4)wherethedatabasecanbesuccesfullyopenendandthecorruptionislisted
atthemomentyoudoaqueryofatable.Dulhasnoproblemswithrecovering
fromsuchsituationsalthoughthereareotheralternativesofrecoveringfrom
thissituationlikepatchingthedatafileheaderblock.
Theerroryouwillreceivelookssomethinglike:
ORACLEinstancestarted.
TotalSystemGlobalArea11739136bytes
FixedSize49152bytes
VariableSize7421952bytes
DatabaseBuffers4194304bytes
RedoBuffers73728bytes
Databasemounted.
ORA-01122:databasefile10failedverificationcheck
ORA-01110:datafile10:'D:\DATA\TRGT\DATAFILES\JUR1TRGT.DBF'
ORA-01251:UnknownFileHeaderVersionreadforfilenumber10
6.Howtounloaddatawithoutthesystemtablespace
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ifdatafilesarenotavailableforthesystemtablespacetheunloadcanstill
continuebuttheobjectinformationcan'tberetrievedfromthedatadictionary
tablesUSER$,OBJ$,TAB$andCOL$.Soownername,tablenameandcolumnnameswill
notbeloadedintotheDULdictionary.Identifyingthetablescanbean
overwhelmingtaskandagoodknowledgeoftheRDBMSinternalsareneededhere.
Firstofallyouneedagoodknowledgeofyourapplicationandit'stables.
ColumntypescanbeguessedbyDUL,buttableandcolumnnameswillbelost.
Anyoldsystemtablespacefromthesamedatabase(maybeweeksold)canbea
greathelp!
1)Createthe"init.dul"fileandthe"control.dul"fileasexplainedinabove
steps1and2.Inthiscasethecontrolfilewillcontainallthedatafiles
fromwhichyouwanttorestorebutitdoesn'trequirethesystemtablespace
information.
2)ThenYouinvokedulandtypethefollowingcommand:
DUL>scandatabase;
datafile61280blocksscanned
Thiswillbuildtheextentandsegmentmap.Probablythedulcommand
interpreterwillbeterminatedaswell.
3)reinvokethedulcommandinterpreteranddothefollowing:
DataUnLoader:Release8.0.5.3.0-InternalUseOnly-onTueAug0313:33:
Copyright(c)1994/1999OracleCorporation,TheNetherlands.Allrightsres
Loaded4segments
Loaded2extents
Extentmapsorted
DUL>altersessionsetuse_scanned_extent_map=true;
DUL>scantables;(orscanextents;)
Scanningtableswithsegmentheader
Oid1078fno6bno2tablenumber0
UNLOADTABLET_O1078(C1NUMBER,C2UNKNOWN,C3UNKNOWN)
STORAGE(TABNO0EXTENTS(FILE6BLOCK2));
ColnoSeenMaxIntSzNull%C75%C100Num%NiNu%Dat%Rid%
1420%0%0%100%100%0%0%
24100%100%100%100%0%0%0%
3480%100%100%100%0%0%50%
"10""ACCOUNTING""NEWYORK"
"20""RESEARCH""DALLAS"
"30""SALES""CHICAGO"
"40""OPERATIONS""BOSTON"
Oid1080fno6bno12tablenumber0
UNLOADTABLET_O1080(C1NUMBER,C2UNKNOWN,C3UNKNOWN,C4NUMBER,
C5DATE,C6NUMBER,C7NUMBER,C8NUMBER)
STORAGE(TABNO0EXTENTS(FILE6BLOCK12));
ColnoSeenMaxIntSzNull%C75%C100Num%NiNu%Dat%Rid%
11430%0%0%100%100%0%0%
21460%100%100%100%0%0%21%
31490%100%100%100%0%0%0%
41437%0%0%100%100%0%0%
51470%0%0%0%0%100%0%
61430%0%0%100%100%0%0%
714271%0%0%100%100%0%0%
81420%0%0%100%100%0%0%
"7369""SMITH""CLERK""7902""17-DEC-1980AD00:00:00""800""""20"
"7499""ALLEN""SALESMAN""7698""20-FEB-1981AD00:00:00""1600""300""30"
"7521""WARD""SALESMAN""7698""22-FEB-1981AD00:00:00""1250""500""30"
"7566""JONES""MANAGER""7839""02-APR-1981AD00:00:00""2975""""20"
"7654""MARTIN""SALESMAN""7698""28-SEP-1981AD00:00:00""1250""1400""30"
Note:itmightbebestthatyouredirecttheoutputtoalogfilesince
commandslikethe"scantables"canproducealotofoutput.
OnWindowsNTyoucandothefollowingcommand:
C:\>dul8>c:\temp\scan_tables.txt
scantables;
exit;
4)Identifythelosttablesfromtheoutputofstep3;ifyoulookcarefullyto
theoutputabovethenyouwillnoticethattheunloadsyntaxisalreadygiven
butthatthetablenamewillbeoftheformatt_0<objectno>andthecolumn
nameswillbeoftheformatC<no>;datatypeswillnotbeanexactmatchof
thedatatypeasitwasbefore.
Lookespeciallyforstringslike"Oid1078fno6bno2tablenumber0"where:
oid=objectid,willbeusedtounloadtheobject
fno=(data)filenumber
bno=blocknumber
5)Unloadtheidentifiedtableswiththe"unloadtable"command:
DUL>unloadtabledept(deptnonumber(2),dnamevarchar2(14),
locvarchar2(13))storage(OBJNO1078)
Unloadingextent(s)oftableDEPT4rows


-------------------------------------------------------------------------------------------------------

Blog:http://blog.csdn.net/tianlesoftware
Weibo:http://weibo.com/tianlesoftware
Email:dvd.dba@gmail.com

DBA1群:62697716(满);DBA2群:62697977(满)DBA3群:62697850(满)

DBA超级群:63306533(满);DBA4群:83829929(满)DBA5群:142216823(满)

DBA6群:158654907(满)DBA7群:69087192(满)DBA8群:172855474

DBA超级群2:151508914DBA9群:102954821聊天群:40132017(满)

--加群需要在备注说明Oracle表空间和数据文件的关系,否则拒绝申请
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: