|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
使为了数据安全,我们搭建了主从。但实时主从备份只能防止硬件问题,比如主库的硬盘损坏。但对于误操作,则无能为力。比如在主库误删一张表,或者一个update语句没有指定where条件,导致全表被更新。FROM:http://www.idevelopment.info/data/Oracle/DBA_tips/Oracle8i_New_Features/ORA8i_17.shtml
TransportableTablespaces
byJeffHunter,Sr.DatabaseAdministrator
Contents
OverviewIntroductiontoTransportableTablespacesUsingTransportableTablespaces
OverviewOraclesTransportableTablespaceisoneofthosemuchawaitedfeaturesthatwasintroducedinOracle8i(8.1.5)andiscommonlyusedinDataWarehouses(DW).Usingtransportabletablespacesismuchfasterthanusingotherutilitieslikeexport/import,SQL*Pluscopytables,orbackupandrecoveryoptionstocopydatafromonedatabasetoanother.
Thisarticleprovidesabriefintroductionintoconfiguringandusingtransportabletablespaces.
IntroductiontoTransportableTablespacesBeforecoveringthedetailsofhowtosetupandusetransportabletablespaces,letsfirstdiscusssomeoftheterminologyandlimitationstoprovideuswithanintroduction.
Theuseoftransportabletablespacesaremuchfasterthanusingexport/import,SQL*Pluscopytables,orbackupandrecoveryoptionstocopydatafromonedatabasetoanother.
Atransportabletablespacesetisdefinedastwocomponents:
Allofthedatafilesthatmakeupthetablespacesthatwillbemoved.
AND
Anexportthatcontainsthedatadictionaryinformationaboutthosetablespaces.
COMPATIBLEmustbesetinboththesourceandtargetdatabasetoatleast8.1.
WhentransportingatablespacefromanOLTPsystemtoadatawarehouseusingtheExport/Importutility,youwillmostlikelyNOTneedtotransportTRIGGERandCONSTRAINTinformationthatisassociatedwiththetablesinthetablespaceyouareexporting.Thatis,youwillsettheTRIGGERSandCONSTRAINTSExportutilityparametersequalto"N".
Thedatainadatawarehouseisinsertedandalteredunderverycontrolledcircumstancesanddoesnotrequirethesameusageofconstraintsandtriggersasatypicaloperationalsystemdoes.
ItiscommonandrecommendedthoughthatyouusetheGRANTSoptionbysettingittoY.
TheTRIGGERSoptionisnewinOracle8iforusewiththeexportcommand.Itisusedtocontrolwhethertriggerinformation,associatedwiththetablesinatablespace,areincludedinthetablespacetransport.
LimitationsofTransportableTablespaces:
Thetransportablesetmustbeself-contained.
BoththesourceandtargetdatabasemustberunningOracle8.1orhigherrelease.
Thetwodatabasesdonothavetobeonthesamerelease
Thesourceandtargetdatabasesmustbeonthesametypeofhardwareandoperating-systemplatform.
Thesourceandtargetdatabasesmusthavethesamedatabaseblocksize.
Thesourceandtargetdatabasesmusthavethesamecharacterset.
Atablespacewiththesamenamemustnotalreadyexistinthetargetdatabase.
Materializedviews,function-basedindexes,scopedREFs,8.0compatibleadvancedqueueswithmultiple-recipients,anddomainindexescantbetransportedinthismanner.(AsofOracle8i)
Userswithtablesintheexportedtablespaceshouldexistinthetargetdatabasepriortoinitiatingtheimport.Createtheuserreportedbytheerrormessage.
Explanation:Themetadataexportedfromthetargetdatabasedoesnotcontainenoughinformationtocreatetheuserinthetargetdatabase.Thereasonisthat,ifthemetadatacontainedtheuserdetails,itmightoverwritetheprivilegesofanexistinguserinthetargetdatabase.
(i.e.Iftheuserbythesamenamealreadyexistsinthetargetdatabase)
Bynotmaintainingtheuserdetails,wepreservethesecurityofthedatabase.
UsingTransportableTablespacesInthissection,wefinallygettoseehowtousetransportabletablespaces.Hereisanoverviewofthestepswewillperforminthissection:
Verifythatthesetofsourcetablespacesareself-containedGenerateatransportabletablespaceset.TransportthetablespacesetImportthetablespacessetintothetargetdatabase.
Inthisexample,wewillbetransportingthetablespaces,"FACT1,FACT2,andFACT_IDX"fromadatabasenamedDWDBtoREPORTDB.Theuserthatownsthesetableswillbe"DW"andpassword"DW".
VerifySelf-ContainedStatuswiththeDBMS_TTSPackageToverifythatalltablespacestotransportareself-contained,wecanusetheTRANSPORT_SET_CHECKprocedurewithintheDBMS_TTSPL/SQLPackage.Thefirstparametertothisprocedureisalistofthetablespacestotransport.Keepinmindthatallindexesforatable,partitions,andLOBcolumnsegmentsinthetablespacemustalsoresideinthetablespaceset.Thesecondparametertothisprocedureisabooleanvaluethatindicateswhetherornottocheckforreferentialintegrity.
SQL>connectsys/change_on_install@dwdbassysdbaSQL>execDBMS_TTS.TRANSPORT_SET_CHECK(fact1,fact2,TRUE);SQL>SELECT*FROMTRANSPORT_SET_VIOLATIONS;VIOLATIONS--------------------------------------------------------------------------------IndexDW.DEPT_PKintablespaceFACT_IDXenforcesprimaryconstriantsoftableDW.DEPTintablespaceFACT1IndexDW.EMP_PKintablespaceFACT_IDXenforcesprimaryconstriantsoftableDW.EMPintablespaceFACT1
OOOPS!Aswecanseefromtheaboveexample,Iforgottoincludealltablespacesthatwillmakethisself-contained.Inthisexample,IforgottoincludetheFACT_IDXtablespace.Letscorrectthat:
SQL>execDBMS_TTS.TRANSPORT_SET_CHECK(fact1,fact2,fact_idx,TRUE);SQL>SELECT*FROMTRANSPORT_SET_VIOLATIONS;norowsselected
GenerateaTransportableTablespaceSetTogenerateaTransportableTablespaceSet,youwillneedtoperformthefollowing:
PlacealltablespacewithinthetablespacesetinREADONLYmode.UseExporttogathertablespacedata-dictionaryinformation.Copydatafilesandtheexportdumpfromthesourcelocationtothetargetlocation.PlacealltablespacewithinthetablespacesetbacktoREAD/WRITE.
%sqlplus"sys/change_on_install@dwdbassysdba"SQL>ALTERTABLESPACEfact1READONLY;SQL>ALTERTABLESPACEfact2READONLY;SQL>ALTERTABLESPACEfact_idxREADONLY;SQL>exit%expuserid="sys/change_on_install@dwdbassysdba"transport_tablespace=ytablespaces=fact1,fact2,fact_idxtriggers=yconstraints=ygrants=yfile=fact_dw.dmp%cp/u10/app/oradata/DWDB/fact1_01.dbf/u10/app/oradata/REPORTDB/fact1_01.dbf%cp/u10/app/oradata/DWDB/fact2_01.dbf/u10/app/oradata/REPORTDB/fact2_01.dbf%cp/u09/app/oradata/DWDB/fact_idx01.dbf/u09/app/oradata/REPORTDB/fact_idx01.dbf%sqlplus"sys/change_on_install@dwdbassysdba"SQL>ALTERTABLESPACEfact1READWRITE;SQL>ALTERTABLESPACEfact2READWRITE;SQL>ALTERTABLESPACEfact_idxREADWRITE;SQL>exit
TransporttheTablespaceSetToactuallytransportthetablespace,thisisnothingmorethancopying(orFTPing)alltablespacesetdatafilestobeputintheirproperlocationonthetargetdatabase.Inthesectionprevioustothis,wedidthatwiththecpcommandinUNIX.
Insomecasesthiswouldbenecessaryifthefileswherecopiedofftoastagingareainthepreviousstep.
ImporttheTablespaceSetBeforeactuallyimportingthetablespace(s)intothetargetdatabase,youwillneedtoensurethatallusersthatownsegmentsintheimportedtablespacesexist.Forthisexample,theonlyuserthatownssegmentsintheexportedtablespacesisDW.Iwillcreatethisuser:
%sqlplus"sys/change_on_install@reportdbassysdba"SQL>createuserdwidentifiedbydwdefaulttablespaceusers;SQL>grantdba,resource,connecttodw;SQL>exit
WenowusetheImportutilitytobringthetablespacesetsdata-dictionaryinformationintothetargetdatabase.
ThetworequiredparametersareTRANSPORT_TABLESPACE=YandDATAFILES=...asinthefollowingexample:
%impuserid="sys/change_on_install@reportdbassysdba"transport_tablespace=ydatafiles=/u10/app/oradata/REPORTDB/fact1_01.dbf,/u10/app/oradata/REPORTDB/fact2_01.dbf,/u09/app/oradata/REPORTDB/fact_idx01.dbffile=fact_dw.dmp
FinalCleanupWhenthetablespacesaresuccessfullyimportedintothetargetdatabase,theyareinREADONLYmode.IfyouintendtousethetablespacesforREADWRITE,youwillneedtomanuallyalterthem:
%sqlplus"sys/change_on_install@reportdbassysdba"SQL>ALTERTABLESPACEfact1READWRITE;SQL>ALTERTABLESPACEfact2READWRITE;SQL>ALTERTABLESPACEfact_idxREADWRITE;SQL>exitPageCount:261
这章描述如何检查和处理在MySQL数据库中的数据损坏。如果你的表损坏很多,你应该尝试找出其原因!见G.1调试一个MySQL服务器。 |
|