|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
操作被同步到从库上后,则主从都“回天无力”。
FetchingAcrossCommits:WhereIstheSourceoftheProblem?
ByBorisMilrud
FetchingacrosscommitsisacommonandacceptedpracticeintheOracleprogrammingworld.However,itisnotanANSI-supportedoperation.AccordingtotheANSIstandard,acursorisinvalidatedwheneveracommitisperformed,whichmeansitshouldbeclosedandreopened.Hence,youshouldbeawareofpotentialORA-01555errorsandthefactthatyouarerelyingonacursorbehaviorthatisnottotheANSIstandard.
Oraclealwaysenforcesstatement-levelreadconsistency.Thisguaranteesthatthedatareturnedbyasinglequeryisconsistentwithrespecttothetimewhenthequerybegan.Therefore,aqueryneverseesthedatachangesmadebythetransactionsthatcommitduringthecourseofaquerysexecution.
AsIdescribedinmyprevious10-MinuteSolutiononthissubject,Oracleuniquelyidentifiesanygivenpointintimebyasetofnumbers,calledtheSystemChangeNumbers.Toensurereadconsistency,OraclemarksthecurrentSCNasthequeryenterstheexecutionphase.Thequerycanseethesnapshotoftherecordsonlyastheywereatthetimethattheyweremarkedby,orassignedto,theSCN.
Thisisthesituationwhenaqueryopensacursor,thenloopsthroughfetching,changing,andcommittingtherecordsonthesametable.Thecursorrequiresa"snapshot"ofthedataatthecursorsopentimeforreadconsistency.AsdatablocksarereadonbehalfofthequeryandeachblockcontainsuncommittedchangesofothertransactionsorchangeddatawithmorerecentSCNs,thedataisthenreconstructedusingthesavedsnapshotfromtherollbacksegments.Duringalong-runningquery,undoentriesintherollbacksegmentmaygetoverwrittenbyanothertransaction,evenfromthesamequery.Inthiscase,theOracleserverwouldbeunabletoreconstructthesnapshot,resultingintheORA-01555error.
Heresanexample:AcursorisopenedatSCN=10.TheexecutionSCNofthequeryisthenmarkedasSCN=10.Everyfetchbythatcursornowneedstogettheread-consistentdatafromSCN=10.Codeinthestoredprocedureisfetchingrecordsfromthecursor,changingthem,andcommittingthem.LetssaytheywerecommittedwithSCN=20.Ifalaterfetchhappenstoretrievearecordthatsinoneofthepreviouslycommittedblocks,thenthefetchwillseethatthecurrentblockSCNis20.BecausethefetchhastogetthesnapshotfromSCN=10itwilltrytofinditintherollbacksegments.Ifitcanrollsufficientlybackaspreviouslyexplained,thenitwillbeabletoreconstructthesnapshotfromSCN=10.Ifnot,itwillreturntheORA-01555error.
Committinglessoften,thuscreatinglargerrollbacksegments,willreducetheprobabilityofgettingthiserror.TheonlydrawbacktothisisthatthedeveloperhastocontacttheDBAandmakesuretherollbacksegmentscanbeextended,andthattherollbacktablespacecanaccommodatethem.
读这类文章仍是有劳绩的。让你分明一些事变。
有了数据以后,我们就要想一个比较统一的方法来闪回。上面我们说了对于DML操作,可以通过反向执行所有逆操作来实现,对于语句里面的DDL,只能直接跳过。原因是一个DDL不一定有直接的逆操作。 |
|