Guest User

Oracle7 / TECH: Internals of Recovery

a guest
Feb 2nd, 2020
780
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 120.77 KB | None | 0 0
  1. Subject: TECH: Internals of Recovery
  2. Type: REFERENCE
  3. Creation Date: 13-SEP-1996
  4.  
  5. Oracle7 v7.2 Recovery Outline
  6.  
  7. Authors: Andrea Borr & Bill Bridge
  8. Version: 1 May 3, 1995
  9.  
  10. Abstract
  11.  
  12. This document gives an overview of how database recovery works
  13. in Oracle7 version 7.2. It is assumed that the reader is familiar
  14. with the Database Administrator's Guide for Oracle7 version 7.2.
  15. The intention of this document is to describe the recovery
  16. algorithms and data structures, providing more details than the
  17. Administrator's Guide.
  18.  
  19. Table of Contents
  20.  
  21. 1 Introduction
  22. 1.1 Instance Recovery and Media Recovery: Common Mechanisms
  23. 1.2 Instance Failure and Recovery, Crash Failure and Recovery
  24. 1.3 Media Failure and Recovery
  25.  
  26. 2 Fundamental Data Structures
  27. 2.1 Controlfile
  28. 2.1.1 Database Info Record (resetControlfile)
  29. 2.1.2 Datafile Record (Controlfile)
  30. 2.1.3 Thread Record (Controlfile)
  31. 2.1.4 Logfile Record (Controlfile)
  32. 2.1.5 Filename Record (Controlfile)
  33. 2.1.6 Log-History Record (Controlfile)
  34. 2.2 Datafile Header
  35. 2.3 Logfile Header
  36. 2.4 Change Vector
  37. 2.5 Redo Record
  38. 2.6 System Change Number (SCN)
  39. 2.7 Redo Logs
  40. 2.8 Thread of Redo
  41. 2.9 Redo Byte Address (RBA)
  42. 2.10 Checkpoint Structure
  43. 2.11 Log History
  44. 2.12 Thread Checkpoint Structure
  45. 2.13 Database Checkpoint Structure
  46. 2.14 Datafile Checkpoint Structure
  47. 2.15 Stop SCN
  48. 2.16 Checkpoint Counter
  49. 2.17 Tablespace-Clean-Stop SCN
  50. 2.18 Datafile Offline Range
  51.  
  52. 3 Redo Generation
  53. 3.1 Atomic Changes
  54. 3.2 Write-Ahead Log
  55. 3.3 Transaction Commit
  56. 3.4 Thread Checkpoint
  57. 3.5 Online-Fuzzy Bit
  58. 3.6 Datafile Checkpoint
  59. 3.7 Log Switch
  60. 3.8 Archiving Log Switches
  61. 3.9 Thread Open
  62. 3.10 Thread Close
  63. 3.11 Thread Enable
  64. 3.12 Thread Disable
  65.  
  66. 4 Hot Backup
  67. 4.1 BEGIN BACKUP
  68. 4.2 File Copy
  69. 4.3 END BACKUP
  70. 4.4 "Crashed" Hot Backup
  71.  
  72. 5 Instance Recovery
  73. 5.1 Detection of the Need for Instance Recovery
  74. 5.2 Thread-at-a-Time Redo Application
  75. 5.3 Current Online Datafiles Only
  76. 5.4 Checkpoints
  77. 5.5 Crash Recovery Completion
  78.  
  79. 6 Media Recovery
  80. 6.1 When to Do Media Recovery
  81. 6.2 Thread-Merged Redo Application
  82. 6.3 Restoring Backups
  83. 6.4 Media Recovery Commands
  84. 6.4.1 RECOVER DATABASE
  85. 6.4.2 RECOVER TABLESPACE
  86. 6.4.3 RECOVER DATAFILE
  87. 6.5 Starting Media Recovery
  88. 6.6 Applying Redo, Media Recovery Checkpoints
  89. 6.7 Media Recovery and Fuzzy Bits
  90. 6.7.1 Media-Recovery-Fuzzy
  91. 6.7.2 Online-Fuzzy
  92. 6.7.3 Hotbackup-Fuzzy
  93. 6.8 Thread Enables
  94. 6.9 Thread Disables
  95. 6.10 Ending Media Recovery (Case of Complete Media Recovery)
  96. 6.11 Automatic Recovery
  97. 6.12 Incomplete Recovery
  98. 6.12.1 Incomplete Recovery UNTIL Options
  99. 6.12.2 Incomplete Recovery and Consistency
  100. 6.12.3 Incomplete Recovery and Datafiles Known to the
  101. Controlfile
  102. 6.12.4 Resetlogs Open after Incomplete Recovery
  103. 6.12.5 Files Offline during Incomplete Recovery
  104. 6.13 Backup Controlfile Recovery
  105. 6.14 CREATE DATAFILE: Recover a Datafile Without a Backup
  106. 6.15 Point-in-Time Recovery Using Export/Import
  107.  
  108. 7 Block Recovery
  109. 7.1 Block Recovery Initiation and Operation
  110. 7.2 Buffer Header RBA Fields
  111. 7.3 PMON vs. Foreground Invocation
  112.  
  113. 8 Resetlogs
  114. 8.1 Fuzzy Files
  115. 8.2 Resetlogs SCN and Counter
  116. 8.3 Effect of Resetlogs on Threads
  117. 8.4 Effect of Resetlogs on Redo Logs
  118. 8.5 Effect of Resetlogs on Online Datafiles
  119. 8.6 Effect of Resetlogs on Offline Datafiles
  120. 8.7 Checking Dictionary vs. Controlfile on Resetlogs Open
  121.  
  122. 9 Recovery-Related V$ Fixed-Views
  123. 9.1 V$LOG
  124. 9.2 V$LOGFILE
  125. 9.3 V$LOG_HISTORY
  126. 9.4 V$RECOVERY_LOG
  127. 9.5 V$RECOVER_FILE
  128. 9.6 V$BACKUP
  129.  
  130. 10 Miscellaneous Recovery Features
  131. 10.1 Parallel Recovery (v7.1)
  132. 10.1.1 Parallel Recovery Architecture
  133. 10.1.2 Parallel Recovery System Initialization Parameters
  134. 10.1.3 Media Recovery Command Syntax Changes
  135. 10.2 Redo Log Checksums (v7.2)
  136. 10.3 Clear Logfile (v7.2)
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145. 1 Introduction
  146.  
  147. The Oracle RDBMS provides database recovery facilities capable
  148. of preserving database integrity in the face of two major failure
  149. modes:
  150.  
  151. 1. Instance failure: loss of the contents of a buffer cache, or data
  152. residing in memory.
  153.  
  154. 2. Media failure: loss of database file storage on disk.
  155.  
  156. Each of these two major failure modes raises its own set of
  157. challenges for database integrity. For each, there is a set of
  158. requirements that a recovery utility addressing that failure mode
  159. must satisfy.
  160.  
  161. Although recovery processing for the two failure modes has much
  162. in common, the requirements differ enough to motivate the
  163. implementation of two different recovery facilities:
  164.  
  165. 1. Instance recovery: recovers data lost from the buffer cache
  166. due to instance failure.
  167.  
  168. 2. Media recovery: recovers data lost from disk storage.
  169.  
  170. 1.1 Instance Recovery and Media Recovery: Common Mechanisms
  171.  
  172. Both instance recovery and media recovery depend for their
  173. operation on the redo log. The redo log is organized into redo
  174. threads, referred to hereafter simply as threads. The redo log of a
  175. single-instance (non-Parallel Server option) database consists of a
  176. single thread. A Parallel Server redo log has a thread per instance.
  177.  
  178. A redo log thread is a set of operating system files in which an
  179. instance records all changes it makes - committed and
  180. uncommitted - to memory buffers containing datafile blocks.
  181. Since this includes changes made to rollback segment blocks, it
  182. follows that rollback data is also (indirectly) recorded in the redo
  183. log.
  184.  
  185. The first phase of both instance and media recovery processing is
  186. roll-forward. Roll-forward is the task of the RDBMS recovery
  187. layer. During roll-forward, changes recorded in the redo log are re-
  188. applied (as needed) to the datafiles. Because changes to rollback
  189. segment blocks are recorded in the redo log, roll-forward also
  190. regenerates the corresponding rollback data. When the recovery
  191. layer finishes its task, all changes recorded in the redo log have
  192. been restored by roll-forward. At this point, the datafile blocks
  193. contain not only all committed changes, but also any uncommitted
  194. changes recorded in the redo log.
  195.  
  196. The second phase of both instance and media recovery processing
  197. is roll-back. Roll-back is the task of the RDBMS transaction layer.
  198. During roll-back, undo information from rollback segments (as
  199. well as from save-undo/deferred rollback segments, if appropriate)
  200. is used to undo uncommitted changes that were applied during the
  201. roll-forward phase.
  202.  
  203. 1.2 Instance Failure and Recovery, Crash Failure and Recovery
  204.  
  205. Instance failure, a failure resulting in the loss of the instance's
  206. buffer cache, occurs when an instance is aborted, either
  207. unexpectedly or expectedly. Examples of reasons for unexpected
  208. instance aborts are operating system crash, power failure, or
  209. background process failure. Examples of reasons for expected
  210. instance aborts are use of the commands SHUTDOWN ABORT
  211. and STARTUP FORCE.
  212.  
  213. Crash failure is the failure of all instances accessing a database. In
  214. the case of a single-instance (non-Parallel Server option) database,
  215. the terms crash failure and instance failure are used
  216. interchangeably. Crash recovery (equivalent to instance recovery in
  217. this case) is the process of recovering all online datafiles to a
  218. consistent state following a crash. This is done automatically in
  219. response to the ALTER DATABASE OPEN command.
  220.  
  221. In the case of the Parallel Server option, the term crash failure is
  222. used to refer to the simultaneous failures of all open instances.
  223. Parallel Server crash recovery is the process of recovering all
  224. online datafiles to a consistent state after all instances accessing the
  225. database have failed. This is done automatically in response to the
  226. ALTER DATABASE OPEN command. Parallel Server instance
  227. failure refers to the failure of an instance while a surviving instance
  228. continues in operation. Parallel Server instance recovery is the
  229. automatic recovery by a surviving instance of a failed instance.
  230.  
  231. Instance failure impairs database integrity because it results in loss
  232. of the instance's dirty buffer cache. A "dirty" buffer is one whose
  233. memory version differs from its disk version. An instance that
  234. aborts has no opportunity for writing out "dirty" buffers so as to
  235. prevent database integrity breakage on disk following a crash. Loss
  236. of the dirty buffer cache is a problem due to the fact that the cache
  237. manager uses algorithms optimized for OLTP performance rather
  238. than for crash-tolerance. Examples of performance-optimizing
  239. cache management algorithms that make the task of instance
  240. recovery more difficult are as follows:
  241.  
  242. 7 LRU (least recently used) based buffer replacement
  243.  
  244. 7 no-datablock-force-at-commit (see 3.3).
  245.  
  246. As a consequence of the performance-oriented cache management
  247. algorithms, instance failure can cause database integrity breakage
  248. as follows:
  249.  
  250. A. At crash time, the datafiles on disk might contain some but not
  251. all of a set of datablock changes that constitute a single atomic
  252. change to the database with respect to structural integrity
  253. (see 2.5).
  254.  
  255. B. At crash time, the datafiles on disk might contain some dat-
  256. ablocks modified by uncommitted transactions.
  257.  
  258. C. At crash time, the datafiles on disk might contain some dat-
  259. ablocks missing changes from committed transactions.
  260.  
  261. During instance recovery, the RDBMS recovery layer repairs
  262. database integrity breakages A and C. It also enables subsequent
  263. repair - by the RDBMS transaction layer - of database integrity
  264. breakage B.
  265.  
  266. In addition to the requirement that it repair any integrity breakages
  267. resulting from the crash, instance recovery must meet the following
  268. requirements:
  269.  
  270. 1. Instance recovery must accomplish the repair using the current
  271. online datafiles (as left on disk after the crash).
  272.  
  273. 2. Instance Recovery must use only the on-line redo logs. It must
  274. not require use of the archived logs. Although instance recov-
  275. ery could work successfully from archived logs (except for a
  276. database running in NOARCHIVELOG mode), it could not
  277. work autonomously (requirement 4) if an operator were
  278. required to restore archived logs.
  279.  
  280. 3. The invocation of instance recovery must be automatic,
  281. implicit at the next database startup.
  282.  
  283. 4. Detection of the need for repair and the repair itself must pro-
  284. ceed autonomously, without operator intervention.
  285.  
  286. 5. The duration of the roll-forward phase of instance recovery is
  287. governed by both RDBMS internal mechanisms (checkpoint)
  288. and user-configurable parameters (e.g. number and sizes of
  289. logfiles, checkpoint-frequency tuning parameters, parallel
  290. recovery parameters).
  291.  
  292. As seen above, Oracle's buffer cache component is optimized for
  293. OLTP performance rather than for crash-tolerance. This document
  294. describes some of the mechanisms used by the cache and recovery
  295. components to solve the problems posed by use of performance-
  296. optimizing cache algorithms such as LRU buffer replacement and
  297. no-datablock-force-at-commit. These mechanisms enable instance
  298. recovery to meet its requirements while allowing optimal OLTP
  299. performance. These mechanisms include:
  300.  
  301. 7 Log-Force-at-Commit: see 3.3.
  302. Facilitates repair of breakage type C by guaranteeing that, at
  303. transaction commit time, all of the transaction's redo records,
  304. including its "commit record," are stored on disk in the on-line
  305. redo log.
  306.  
  307. 7 Checkpointing: see 3.4, 3.6.
  308. Bounds the amount of transaction redo that instance recovery
  309. must potentially apply.
  310. Works in conjunction with online-log switch management to
  311. ensure that instance recovery can be accomplished using only
  312. online logs and current online datafiles.
  313.  
  314. 7 Online-Log Switch Management: see 3.7.
  315. Works in conjunction with checkpointing to ensure that
  316. instance recovery can be accomplished using only online logs
  317. and current online datafiles. It guarantees that the current
  318. checkpoint is beyond an online logfile before that logfile is
  319. reused.
  320.  
  321. 7 Write-Ahead-Log: see 3.2.
  322. Facilitates repair of breakage types A and B by guaranteeing
  323. that: (i) at crash time there are no changes in the datafiles that
  324. are not in the redo log; (ii) no datablock change was written to
  325. disk without first writing to the log sufficient information to
  326. enable undo of the change should a crash intervene before
  327. commit.
  328.  
  329. 7 Atomic Redo Record Generation: see 3.1.
  330. Facilitates repair of breakage types A and B.
  331.  
  332. 7 Thread-Open Flag: 5.1.
  333. Enables detection at startup time of the need for crash recov-
  334. ery.
  335.  
  336. 1.3 Media Failure and Recovery
  337.  
  338. Instance failure affects logical database integrity. Because instance
  339. failure leaves a recoverable version of the online datafiles on the
  340. post-crash disk, instance recovery can use the online datafiles as a
  341. starting point.
  342.  
  343. Media failure, on the other hand, affects physical storage media
  344. integrity or accessibility. Because the original datafile copies are
  345. damaged, media recovery uses restored backup copies of the
  346. datafiles as a starting point. Media recovery then uses the redo log
  347. to roll-forward these files, either to a consistent present state or to a
  348. consistent past state. Media recovery is run by issuing one of the
  349. following commands: RECOVER DATABASE, RECOVER
  350. TABLESPACE, RECOVER DATAFILE.
  351.  
  352. Depending on the failure scenario, a media failure has the potential
  353. for causing database integrity breakages similar to those caused by
  354. an instance failure. For example, an integrity breakage of type A,
  355. B, or C could result if I/O accessibility to a datablock were lost
  356. between the time the block was read into the buffer cache and the
  357. time DBWR attempted to write out an updated version of the
  358. block. More typical, however, is the case of a media failure that
  359. results in the permanent loss of the current version of a datafile, and
  360. hence of all updates to that datafile that occurred since the last time
  361. the file was backed up.
  362.  
  363. Before media recovery is invoked, backup copies of the damaged
  364. datafiles are restored. Media recovery then applies relevant
  365. portions of the redo log to roll-forward the datafile backups,
  366. making them current. Current implies a pre-failure state consistent
  367. with the rest of the database
  368.  
  369. Media recovery and instance recovery have in common the
  370. requirement to repair database integrity breakages A-C. However,
  371. media recovery and instance recovery differ with respect to
  372. requirements 1-5. The requirements for media recovery are as
  373. follows:
  374.  
  375. 1. Media recovery must accomplish the repair using restored
  376. backups of damaged datafiles.
  377.  
  378. 2. Media recovery can use archived logs as well as the online
  379. logs.
  380.  
  381. 3. Invocation of media recovery is explicit, by operator com-
  382. mand.
  383.  
  384. 4. Detection of media failure (i.e. the need to restore a backup) is
  385. not automatic.Once a backup has been restored however,
  386. detection of the need to recover it via media recovery is auto-
  387. matic.
  388.  
  389. 5. The duration of the roll-forward phase of media recovery is
  390. governed solely by user policy
  391. (e.g. frequency of backups, parallel recovery parameters)
  392. rather than by RDBMS internal mechanisms.
  393.  
  394.  
  395.  
  396. 2 Fundamental Data Structures
  397.  
  398. 2.1 Controlfile
  399.  
  400. The controlfile contains records that describe and keep state
  401. information about all the other files of the database.
  402.  
  403. The controlfile contains the following categories of records:
  404.  
  405. 7 Database Info Record (1)
  406.  
  407. 7 Datafile Records (1 per datafile)
  408.  
  409. 7 Thread Records (1 per thread)
  410.  
  411. 7 Logfile Records (1 per logfile)
  412.  
  413. 7 Filename Records (1 per datafile or logfile group member)
  414.  
  415. 7 Log-History Records (1 per completed logfile)
  416.  
  417. Fields of the controlfile records referenced in the remainder of this
  418. document are listed below, together with the number(s) of the
  419. section(s) describing their use:
  420.  
  421. 2.1.1 Database Info Record (Controlfile)
  422.  
  423. 7 resetlogs timestamp: 8.2
  424.  
  425. 7 resetlogs SCN: 8.2
  426.  
  427. 7 enabled thread bitvec: 8.3
  428.  
  429. 7 force archiving SCN: 3.8
  430.  
  431. 7 database checkpoint thread (thread record index): 2.13, 3.10
  432.  
  433. 2.1.2 Datafile Record (Controlfile)
  434.  
  435. 7 checkpoint SCN: 2.14, 3.4
  436.  
  437. 7 checkpoint counter: 2.16, 5.3, 6.2
  438.  
  439. 7 stop SCN: 2.15, 6.5, 6.10, 6.13
  440.  
  441. 7 offline range (offline-start SCN, offline-end checkpoint): 2.18
  442.  
  443. 7 online flag
  444.  
  445. 7 read-enabled, write-enabled flags (1-1: read/write, 1-0: read-
  446. only)
  447.  
  448. 7 filename record index
  449.  
  450. 2.1.3 Thread Record (Controlfile)
  451.  
  452. 7 thread checkpoint structure: 2.12, 3.4, 8.3
  453.  
  454. 7 thread-open flag: 3.9, 3.11, 8.3
  455.  
  456. 7 current log (logfile record index)
  457.  
  458. 7 head and tail (logfile record indices) of list of logfiles in
  459. thread: 2.8
  460.  
  461. 2.1.4 Logfile Record (Controlfile)
  462.  
  463. 7 log sequence number: 2.7
  464.  
  465. 7 thread number: 8.4
  466.  
  467. 7 next and previous (logfile record indices) of list of logfiles in
  468. thread: 2.8
  469.  
  470. 7 count of files in group: 2.8
  471.  
  472. 7 low SCN: 2.7
  473.  
  474. 7 next SCN: 2.7
  475.  
  476. 7 head and tail (filename record indices) of list of filenames in
  477. group: 2.8
  478.  
  479. 7 "being cleared" flag: 10.3
  480.  
  481. 7 "archiving not needed" flag: 10.3
  482.  
  483. 2.1.5 Filename Record (Controlfile)
  484.  
  485. 7 filename
  486.  
  487. 7 filetype
  488.  
  489. 7 next and previous (filename record indices) of list of filenames
  490. in group: 2.8
  491.  
  492. 2.1.6 Log-History Record (Controlfile)
  493.  
  494. 7 thread number: 2.11
  495.  
  496. 7 log sequence number: 2.11
  497.  
  498. 7 low SCN: 2.11
  499.  
  500. 7 low SCN timestamp: 2.11
  501.  
  502. 7 next SCN: 2.11
  503.  
  504. 2.2 Datafile Header
  505.  
  506. Fields of the datafile header referenced in the remainder of this
  507. document are listed below, together with the number(s) of the
  508. section(s) describing their use:
  509.  
  510. 7 datafile checkpoint structure: 2.14
  511.  
  512. 7 backup checkpoint structure: 4.1
  513.  
  514. 7 checkpoint counter: 2.16, 3.4, 5.3, 6.2
  515.  
  516. 7 resetlogs timestamp: 8.2
  517.  
  518. 7 resetlogs SCN: 8.2
  519.  
  520. 7 creation SCN: 8.1
  521.  
  522. 7 online-fuzzy bit: 3.5, 6.7.1, 8.1
  523.  
  524. 7 hotbackup-fuzzy bit: 4.1, 4.4, 6.7.1, 8.1
  525.  
  526. 7 media-recovery-fuzzy bit: 6.7.1, 8.1
  527.  
  528. 2.3 Logfile Header
  529.  
  530. Fields of the logfile header referenced in the remainder of this
  531. document are listed below, together with the number(s) of the
  532. section(s) describing their use:
  533.  
  534. 7 thread number: 2.7
  535.  
  536. 7 sequence number: 2.7
  537.  
  538. 7 low SCN: 2.7
  539.  
  540. 7 next SCN: 2.7
  541.  
  542. 7 end-of-thread flag: 6.10
  543.  
  544. 7 resetlogs timestamp: 8.2
  545.  
  546. 7 resetlogs SCN: 8.2
  547.  
  548. 2.4 Change Vector
  549.  
  550. A change vector describes a single change to a single datablock. It
  551. has a header that gives the Data Block Address(DBA) of the block,
  552. the incarnation number, the sequence number, and the operation.
  553. After the header is information that depends on the operation. The
  554. incarnation number and sequence number are copied from the
  555. block header when the change vector is constructed. When a block
  556. is made "new," the incarnation number is set to a value that is
  557. greater than its previous incarnation number and the sequence
  558. number is set to one. The sequence number on the block is
  559. incremented after every change is applied.
  560.  
  561. 2.5 Redo Record
  562.  
  563. A redo record is a group of change vectors describing a single
  564. atomic change to the database. For example, a transaction's first
  565. redo record might group a change vector for the transaction table
  566. (rollback segment header), a change vector for the undo block
  567. (rollback segment), and a change vector for the datablock. A
  568. transaction can generate multiple redo records. The grouping of
  569. change vectors into a redo record allows multiple database blocks
  570. to be changed so that either all changes occur or no changes occur,
  571. despite arbitrary intervening failures. This atomicity guarantee is
  572. one of the fundamental jobs of the cache layer. Recovery preserves
  573. redo record atomicity across failures.
  574.  
  575. 2.6 System Change Number (SCN)
  576.  
  577. An SCN defines a committed version of the database. A query
  578. reports the contents of the database as it looked at some specific
  579. SCN. An SCN is allocated and saved in the header of a redo record
  580. that commits a transaction. An SCN may also be saved in a record
  581. when it is necessary to mark the redo as being allocated after a
  582. specific SCN. SCN's are also allocated and stored in other data
  583. structures such as the controlfile or datafile headers. An SCN is at
  584. least 48 bits long. Thus they can be allocated at a rate of 16,384
  585. SCN's per second for over 534 years without running out of them.
  586. We will run out of SCN's in June, 2522 AD (we use 31 day months
  587. for time stamps).
  588.  
  589. 2.7 Redo Logs
  590.  
  591. All changes to database blocks are made by constructing a redo
  592. record for the change, saving this record in a redo log, then
  593. applying the change vectors to the datablocks. Recovery is the
  594. process of applying redo to old versions of datablocks to make
  595. them current. This is necessary when the current version has been
  596. lost.
  597.  
  598. When a redo log becomes full it is closed and a log switch occurs.
  599. Each log is identified by its thread number (see below), sequence
  600. number (within thread), and the range of SCN's spanned by its redo
  601. records. This information is stored in the thread number, sequence
  602. number, low SCN, and next SCN fields of the logfile header.
  603.  
  604. The redo records in a log are ordered by SCN. Moreover, redo
  605. records containing change vectors for a given block occur in
  606. increasing SCN order across threads (case of Parallel Server). Only
  607. some records have SCN's in their header, but every record is
  608. applied after the allocation of the SCN appearing with or before it
  609. in the log. The header of the log contains the low SCN and the next
  610. SCN. The low SCN is the SCN associated with the first redo record
  611. (unless there is an SCN in its header). The next SCN is the low
  612. SCN of the log with the next higher sequence number for the same
  613. thread. The current log of an enabled thread has an infinite next
  614. SCN, since there is no log with a higher sequence number.
  615.  
  616. 2.8 Thread of Redo
  617.  
  618. The redo generated by an instance - by each instance in the
  619. Parallel Server case - is called a thread of redo. A thread is
  620. comprised of an online portion and (in ARCHIVELOG mode) an
  621. archived portion. The online portion of a thread is comprised of
  622. two or more online logfile groups. Each group is comprised of one
  623. or more replicated members. The set of members in a group is
  624. referred to variously as a logfile group, group, redo log, online log,
  625. or simply log. A redo log contains only redo generated by one
  626. thread. Log sequence numbers are independently allocated for each
  627. thread. Each thread switches logs independently.
  628.  
  629. For each logfile, there is a controlfile record that describes it. The
  630. index of a log's controlfile record is referred to as its log number.
  631. Note that log numbers are equivalent to log group numbers, and are
  632. globally unique (across all threads). The list of a thread's logfile
  633. records is anchored in the thread record (i.e. via head and tail
  634. logfile record indices), and linked through the logfile records, each
  635. of which stores the thread number. The logfile record also has fields
  636. identifying the number of group members, as well as the head and
  637. tail (i.e. filename record indices) of the list (linked through
  638. filename records) of filenames in the group.
  639.  
  640. 2.9 Redo Byte Address (RBA)
  641.  
  642. An RBA points to a specific location in a particular redo thread. It
  643. is ten bytes long and has three components: log sequence number,
  644. block number within log, and byte number within block.
  645.  
  646. 2.10 Checkpoint Structure
  647.  
  648. The checkpoint structure is a data structure that defines a point in
  649. all the redo ever generated for a database. Checkpoint structures
  650. are stored in datafile headers and in the per-thread records of the
  651. controlfile. They are used by recovery to know where to start
  652. reading the log thread(s) for redo application.
  653.  
  654. The key fields of the checkpoint structure are the checkpoint SCN
  655. and the enabled thread bitvec.
  656.  
  657. The checkpoint SCN effectively demarcates a specific location in
  658. each enabled thread (for a definition of enabled see 3.11). For each
  659. thread, this location is where redo was being generated at some
  660. point in time within the resolution of one commit. The redo record
  661. headers in the log can be scanned to find the first redo record that
  662. was allocated at the checkpoint SCN or higher.
  663.  
  664. The enabled thread bitvec is a mask defining which threads were
  665. enabled at the time the checkpoint SCN was allocated. Note that a
  666. bit is set for each thread that was enabled, regardless of whether it
  667. was open or closed. Every thread that was enabled has a redo log
  668. that contains the checkpoint SCN. A log containing this SCN is
  669. guaranteed to exist (either online or archived).
  670.  
  671. The checkpoint structure also stores the time that the checkpoint
  672. SCN was allocated. This timestamp is only used to print a message
  673. to aid a person looking for a log.
  674.  
  675. In addition, the checkpoint structure stores the number of the
  676. thread that allocated the checkpoint SCN and the current RBA in
  677. that thread when the checkpoint SCN was allocated. Having an
  678. explicitly-stored thread RBA (as opposed to only having the
  679. checkpoint SCN as an implicit thread location "pointer") makes the
  680. log sequence number (part of the RBA) and archived log name
  681. readily available for the single-instance (i.e. single-thread, non
  682. Parallel Server) case.
  683.  
  684. A checkpoint structure for a port that supports up to 1023 threads
  685. of redo is 150 bytes long. A VMS checkpoint is 30 bytes and
  686. supports up to 63 threads of redo.
  687.  
  688. 2.11 Log History
  689.  
  690. The controlfile can be configured (using the MAXLOGHISTORY
  691. clause of the CREATE DATABASE or CREATE CONTROLFILE
  692. command) to contain a history record for every logfile that is
  693. completed. Log history records are small (24 bytes on VMS). They
  694. are overwritten in a circular fashion so that the oldest information
  695. is lost.
  696.  
  697. For each logfile, the log-history controlfile record contains the
  698. thread number, log sequence number, low SCN, low SCN
  699. timestamp, and next SCN (i.e. low SCN of the next log in
  700. sequence). The purpose of the log history is to reconstruct archived
  701. logfile names from an SCN and thread number. Since a log
  702. sequence number is contained in the checkpoint structure (part of
  703. the RBA), single thread (i.e. non-Parallel Server) databases do not
  704. need log history to construct archived log names.
  705.  
  706. The fields of the log history records are viewable via the
  707. V$LOG_HISTORY "fixed-view" (see Section 9 for a description
  708. of the recovery-related "fixed-views"). Additionally,
  709. V$RECOVERY_LOG, which displays information about archived
  710. logs needed to complete media recovery, is derived from
  711. information in the log history records. Although log history is not
  712. strictly needed for easy administration of single-instance (non-
  713. Parallel Server) databases, enabling use of V$LOG_HISTORY and
  714. V$RECOVERY_LOG might be a reason to configure it.
  715.  
  716. 2.12 Thread Checkpoint Structure
  717.  
  718. Each enabled thread's controlfile record contains a checkpoint
  719. structure called the thread checkpoint. The SCN field in this
  720. structure is known as the thread checkpoint SCN. The thread
  721. number and RBA fields in this structure refer to the associated
  722. thread.
  723.  
  724. The thread checkpoint structure is updated each time an instance
  725. checkpoints its thread (see 3.4). During such thread checkpoint
  726. events, the instance associated with the thread writes to disk in the
  727. online datafiles all dirty buffers modified by redo generated before
  728. the thread checkpoint SCN.
  729.  
  730. A thread checkpoint event guarantees that all pre-thread-
  731. checkpoint-SCN redo generated in that thread for all online
  732. datafiles has been written to disk. (Note that if the thread is closed,
  733. then there is no redo beyond the thread checkpoint SCN; i.e. the
  734. RBA points just past the last redo record in the current log.)
  735.  
  736. It is the job of instance recovery to ensure that all of the thread's
  737. redo for all online datafiles is applied. Because of the guarantee
  738. that all of the thread's redo prior to the thread checkpoint SCN has
  739. already been applied, instance recovery can make the guarantee
  740. that, by starting redo application at the thread checkpoint SCN, and
  741. continuing through end-of-thread, all of the thread's redo will have
  742. been applied.
  743.  
  744. 2.13 Database Checkpoint Structure
  745.  
  746. The database checkpoint structure is the thread checkpoint of the
  747. thread that has the lowest checkpoint SCN of all the open threads.
  748. The number of the database checkpoint thread - the number of
  749. the thread whose thread checkpoint is the current database
  750. checkpoint - is recorded in the database info record of the
  751. controlfile. If there are no open threads, then the database
  752. checkpoint is the thread checkpoint that contains the highest
  753. checkpoint SCN of all the enabled threads.
  754.  
  755. Since each instance guarantees that all redo generated before its
  756. own thread checkpoint SCN has been written, and since the
  757. database checkpoint SCN is the lowest of the thread checkpoint
  758. SCNs, it follows that all pre-database-checkpoint-SCN redo in all
  759. instances has been written to all online datafiles.
  760.  
  761. Thus, all pre-database-checkpoint-SCN redo generated in all
  762. threads for all online datafiles is guaranteed to be in the files on
  763. disk already. This is described by saying that the online datafiles
  764. are checkpointed at the database checkpoint. This is the rationale
  765. for using the database checkpoint to update the online datafile
  766. checkpoints (see below) when an instance checkpoints its thread
  767. (see 3.4).
  768.  
  769. 2.14 Datafile Checkpoint Structure
  770.  
  771. The header of each datafile contains a checkpoint structure known
  772. as the datafile checkpoint. The SCN field in this structure is known
  773. as the datafile checkpoint SCN.
  774.  
  775. All pre-checkpoint-SCN redo generated in all threads for a given
  776. datafile is guaranteed to be in the file on disk already. An online
  777. datafile has its checkpoint SCN replicated in its controlfile record.
  778. Note: Oracle's recovery layer code is designed to "tolerate" a
  779. discrepancy in checkpoint SCN between the file header and the
  780. controlfile record. These values could get out of sync should an
  781. instance failure occur between the time the file header was updated
  782. and the time the controlfile "transaction" committed. (Note: A
  783. controlfile "transaction" is an RDBMS internal mechanism,
  784. independent of the Oracle transaction layer, that allows an
  785. arbitrarily large update to the controlfile to be "committed"
  786. atomically.)
  787.  
  788. The execution of a datafile checkpoint (see 3.6) for a given datafile
  789. updates the checkpoint structure in the file header, and guarantees
  790. that all pre-checkpoint-SCN redo generated in all threads for that
  791. datafile is on disk already.
  792.  
  793. A thread checkpoint event (see 3.4) guarantees that all pre-
  794. database-checkpoint-SCN redo generated in all threads for all
  795. online datafiles has been written to disk. The execution of a thread
  796. checkpoint may advance the database checkpoint (e.g. in the
  797. single-instance case; or if the thread having the oldest checkpoint
  798. changed from being the current thread to another thread). If the
  799. database checkpoint does advance, then the new database
  800. checkpoint is used to update the datafile checkpoints of all the
  801. online datafiles (except those in hot backup: see Section 4).
  802.  
  803. It is the job of media recovery (see Section 6) to ensure that all redo
  804. for a recovery-datafile (i.e. a datafile being media-recovered)
  805. generated in any thread through the recovery end-point is applied.
  806. Because of the guarantee that all recovery-datafile-redo generated
  807. in any enabled thread prior to that datafile's checkpoint SCN has
  808. already been applied, media recovery can make the guarantee that,
  809. by starting redo application in each enabled thread with the datafile
  810. checkpoint SCN and continuing through the recovery end-point
  811. (e.g. end-of-thread on all threads in the case of complete media
  812. recovery), all redo for the recovery-datafile from all threads will
  813. have been applied.
  814.  
  815. Since the datafile checkpoint is stored in the header of the datafile
  816. itself, it is also present in backup copies of the datafile. It is the job
  817. of hot backup (see Section 4) to ensure that - despite the
  818. occurrence of ongoing updates to the datafile during the backup
  819. copy operation - the version of the datafile's checkpoint captured
  820. in the backup copy satisfies the checkpoint-SCN guarantee with
  821. respect to the versions of the datafile's datablocks captured in the
  822. backup copy.
  823.  
  824. 2.15 Stop SCN
  825.  
  826. Each datafile's controlfile record has a field called the stop SCN. If
  827. the file is offline or read-only, the stop SCN is the SCN beyond
  828. which no further redo exists for that datafile. If the file is online and
  829. any instance has the database open, the stop SCN is set to
  830. "infinity." The stop SCN is used during media recovery to
  831. determine when redo application for a particular datafile can stop.
  832. This ensures that media recovery will terminate when recovering
  833. an offline file while the database is open.
  834.  
  835. The stop SCN is set whenever a datafile is taken offline or set read-
  836. only. This is true whether the offline was "immediate" (due to an I/
  837. O error, or due to taking the file's tablespace offline "immediate"),
  838. "temporary" (due to taking the file's tablespace offline
  839. "temporary"), or "normal" (due to taking the file's tablespace
  840. offline "normal"). However, in the case of a datafile taken offline
  841. "immediate," there is no file checkpoint (see 3.6), and dirty buffers
  842. are discarded. Hence, media recovery may need to apply redo from
  843. before the stop SCN in order to bring the datafile online. However,
  844. media recovery does not need to look for redo after the stop SCN,
  845. since it does not exist. If the stop SCN is equal to the datafile
  846. checkpoint SCN, then the file does not need recovery.
  847.  
  848. 2.16 Checkpoint Counter
  849.  
  850. There is a checkpoint counter kept in both the datafile header and
  851. in the datafile's controlfile record. Its purpose is to allow detection
  852. of the fact that a datafile or controlfile is a restored backup.
  853.  
  854. The checkpoint counter is incremented every time checkpoints of
  855. online files are being advanced (e.g. by thread checkpoint). Thus
  856. the datafile's checkpoint counter is incremented even though the
  857. datafile's checkpoint is not being advanced because the file is in hot
  858. backup (see Section 4), or because its checkpoint SCN is already
  859. beyond that of the intended checkpoint (e.g. the file is new or has
  860. undergone a recent datafile checkpoint).
  861.  
  862. The old value of the checkpoint counter - matching the
  863. checkpoint counter in the datafile's controlfile record - is also
  864. remembered in the file header. It is usually one less than the current
  865. counter in the header, but may differ from the current counter by
  866. more than one if the previous file header update failed after the
  867. header was written but before the controlfile "transaction"
  868. committed.
  869.  
  870. A mismatch in checkpoint counters between the datafile header and
  871. the datafile's controlfile record is used to detect when a backup
  872. datafile (or a backup controlfile) has been restored.
  873.  
  874. 2.17 Tablespace-Clean-Stop SCN
  875.  
  876. TS$, a data dictionary table that describes tablespaces, has a
  877. column called the tablespace-clean-stop-SCN. It identifies an SCN
  878. at which a tablespace was taken offline or set read-only "cleanly":
  879. i.e. after checkpointing its datafiles (see 3.6). The SCN at which the
  880. datafiles are checkpointed is recorded in TS$ as the
  881. tablespace-clean-stop SCN. It allows such a "clean-stopped"
  882. tablespace to survive (i.e. not need to be dropped after) a
  883. RESETLOGS open (see 8.6). During media recovery, prior to
  884. resetlogs, the "clean-stopped" tablespace would be set offline.
  885. After resetlogs, the tablespace - which needs no recovery - is
  886. permitted to be brought online and/or set read-write. (An
  887. immediate backup of the tablespace is recommended).
  888.  
  889. The tablespace-clean-stop SCN is set to zero (after being set
  890. momentarily to "infinity" during datafile state transition) when
  891. bringing an offline-clean tablespace online, or setting a read-only
  892. tablespace read-write. The tablespace-clean-stop SCN is also
  893. zeroed when taking a tablespace offline "immediate" or
  894. "temporary."
  895.  
  896. A tablespace that has a non-zero tablespace-clean-stop SCN in TS$
  897. is clean at that SCN: the tablespace currently contains all redo up
  898. through that SCN, and no redo for the tablespace beyond that SCN
  899. exists. If the tablespace's datafiles are still in the state they had
  900. when the tablespace was taken offline "normal" or set read-only -
  901. i.e. they are not restored backups, are not fuzzy, and are
  902. checkpointed at the clean-stop SCN - then the tablespace can be
  903. brought online without recovery. Note that the semantics of the
  904. tablespace-clean-stop SCN differ from those of a constituent
  905. datafile's stop SCN in the datafile's controlfile record. The
  906. controlfile stop SCN designates an SCN beyond which no redo for
  907. the datafile exists. This does not imply that the datafile currently
  908. contains all redo up through that SCN.
  909.  
  910. The tablespace-clean-stop SCN is stored in TS$ rather than in the
  911. controlfile so that it is covered by redo and will finish in the correct
  912. state - i.e. reflecting the correct online/offline state of the
  913. tablespace - following an incomplete recovery (see 6.12). Its
  914. value will not be lost if a backup controlfile is restored, or if a new
  915. controlfile is created. Furthermore, the presence of the tablespace-
  916. clean-stop SCN in TS$ allows an offline normal (or read-only)
  917. tablespace to survive (not need to be dropped after) a
  918. RESETLOGS open, since it is known that no redo application is
  919. needed to bring it online (see 8.6 for more detail). Thus, for
  920. example, an offline normal (or read-only) tablespace that was
  921. offline during an incomplete recovery can be brought online (or set
  922. read-write) subsequent to a RESETLOGS open. Without the
  923. tablespace-clean-stop SCN, there would be no way of knowing that
  924. the tablespace does not need recovery using redo that was
  925. discarded by the resetlogs. The only alternative would have been to
  926. force the tablespace to be dropped.
  927.  
  928. 2.18 Datafile Offline Range
  929.  
  930. The offline-start SCN and offline-end checkpoint fields of the
  931. controlfile datafile record describe the offline range. If valid, they
  932. delimit a log range guaranteed not to contain any redo for the
  933. datafile. Thus, media recovery can skip this log range when
  934. recovering the datafile, obviating the need to access old archived
  935. log data (which may be uavailable or unusable due to resetlogs: see
  936. Section 7). This optimization aids in recovering a datafile that is
  937. presently online (or read-write), but that was offline-clean (or read-
  938. only) for a long time, and whose last backup dates from that time.
  939. For example, this would be the case if, after a RESETLOGS open,
  940. an offline normal (or read-only) tablespace had been brought online
  941. (or set read-write), but not yet backed up.
  942.  
  943. When a datafile transitions from offline-clean to online (or from
  944. read-only to read-write), the offline range is set as follows: The
  945. offline-start SCN is set from the tablespace-clean-stop SCN saved
  946. when setting the file offline (or read-only). The offline-end
  947. checkpoint is set from the file checkpoint taken when setting the
  948. file online (or read-write).
  949.  
  950.  
  951.  
  952.  
  953.  
  954.  
  955.  
  956.  
  957.  
  958. 3 Redo Generation
  959.  
  960. Redo is generated to describe all changes made to database blocks.
  961. This section describes the various operations that occur while the
  962. database is open and generating redo.
  963.  
  964. 3.1 Atomic Changes
  965.  
  966. The most fundamental operation is to atomically change a set of
  967. datablocks. A foreground process intending to change one or more
  968. datablocks first acquires exclusive access to cache buffers
  969. containing those blocks. It then constructs the change vectors
  970. describing the changes. Space is allocated in the redo log buffer to
  971. hold the redo record. The redo log buffer - the buffer from which
  972. LGWR writes the redo log - is located in the SGA (System
  973. Global Area). It may be necessary to ask LGWR to write the buffer
  974. to the redo log in order to make space. If the log is full, LGWR
  975. may need to do a log switch in order to make the space available.
  976. Note that allocating space in the redo buffer also allocates space in
  977. the logfile. Thus, even though the redo buffer has been written, it
  978. may not be possible to allocate redo log space. After the space is
  979. allocated, the foreground process builds the redo record in the redo
  980. buffer. Only after the redo record has been built in the redo buffer
  981. may the datablock buffers be changed. Writing the redo to disk is
  982. the real change to the database. Recovery ensures that all changes
  983. that make it into the redo log make it into the datablocks (except in
  984. the case of incomplete recovery).
  985.  
  986. 3.2 Write-Ahead Log
  987.  
  988. Write-ahead log is a cache-enforced protocol governing the order
  989. in which dirty datablock buffers are written vs. when the redo log
  990. buffer is written. According to write-ahead log protocol, before
  991. DBWR can write out a cache buffer containing a modified
  992. datablock, LGWR must write out the redo log buffer containing
  993. redo records describing changes to that datablock.
  994.  
  995. Note that write-ahead log is independent of log-force-at-commit
  996. (see 3.3).
  997.  
  998. Note also that write-ahead log protocol only applies to datafile
  999. writes that originate from the buffer cache. In particular, write-
  1000. ahead log does not apply to so-called direct path writes (e.g.
  1001. originating from direct path load, table create via subquery, or
  1002. index create). Direct path writes (targeted above the segment high-
  1003. water mark) originate not as writes out of the buffer cache, but as
  1004. bulk-writes out of the foreground process' data space. Indeed,
  1005. correct handling of direct path writes by media recovery dictates a
  1006. write-behind-log protocol. (The basic reason is that, because the
  1007. bulk-writes do not go through the buffer cache, there is no
  1008. mechanism to guarantee their completion at checkpoint).
  1009.  
  1010. One guarantee made by write-ahead log protocol is that there are
  1011. no changes in the datafiles that are not in the redo log, regardless of
  1012. intervening failure. This is what enables recovery to preserve the
  1013. guarantee of redo record atomicity despite intervening failure.
  1014.  
  1015. Another guarantee made by write-ahead log protocol is that no
  1016. datablock change can be written to disk without first writing to the
  1017. redo log sufficient information to enable the change to be undone
  1018. should the transaction fail to commit. That undo-enabling
  1019. information is written to the redo log in the form of "redo" for the
  1020. rollback segment.
  1021.  
  1022. Write-ahead log protocol plays a key role in enabling the
  1023. transaction layer to preserve the guarantee of transaction atomicity
  1024. despite intervening failure.
  1025.  
  1026. 3.3 Transaction Commit
  1027.  
  1028. Transaction commit allocates an SCN and builds a commit redo
  1029. record containing that SCN. The commit is complete when all of
  1030. the transaction's redo (including commit redo record) is on disk in
  1031. the log. Thus, commit forces the redo log to disk - at least up to
  1032. and including the transaction's commit record. This is termed log-
  1033. force-at-commit.
  1034.  
  1035. Recovery is designed such that it is sufficient to write only the redo
  1036. log at commit time - rather than all datablocks changed by the
  1037. transaction - in order to guarantee transaction durability despite
  1038. intervening failure. This is termed no-datablock-force-at-commit.
  1039.  
  1040. 3.4 Thread Checkpoint
  1041.  
  1042. A thread checkpoint event, executed by the instance associated
  1043. with the redo thread being checkpointed, forces to disk all dirty
  1044. buffers in that instance that contain changes to any online datafile
  1045. before a designated SCN - the thread checkpoint SCN. Once all
  1046. redo in the thread prior to the checkpoint SCN has been written to
  1047. disk, the thread checkpoint structure in the thread's controlfile
  1048. record is updated in a controlfile transaction.
  1049.  
  1050. When a thread checkpoint begins, an SCN is captured and a
  1051. checkpoint structure is initialized. Then all the dirty buffers in the
  1052. instance's cache are marked for checkpointing. DBWR proceeds to
  1053. write out the marked buffers in a staged manner. Once all the
  1054. marked buffers have been written, the SCN in the checkpoint
  1055. structure is set to the captured SCN, and the thread checkpoint
  1056. structure in the thread's controlfile record is updated in a controlfile
  1057. transaction.
  1058.  
  1059. A thread checkpoint might or might not advance the database
  1060. checkpoint. If only one thread is open, the new checkpoint is the
  1061. new database checkpoint. If multiple threads are open, the database
  1062. checkpoint will advance if the local thread is the current database
  1063. checkpoint. Since the new checkpoint SCN was allocated recently,
  1064. it is most likely greater than the thread checkpoint SCN in some
  1065. other open thread. If it advances, the database checkpoint becomes
  1066. the new lowest-SCN open thread checkpoint. If the old checkpoint
  1067. SCN for the local thread was higher than the current checkpoint
  1068. SCN of some other open thread, then the database checkpoint does
  1069. not change.
  1070.  
  1071. If the database checkpoint is advanced, then the checkpoint counter
  1072. is advanced in every online datafile header. Furthermore, for each
  1073. online datafile that is not in hot backup (see Section 4), and not
  1074. already checkpointed at a higher SCN (e.g. as would be the case for
  1075. a recently added or recovered file), the datafile header checkpoint is
  1076. advanced to the new database checkpoint, and the file header is
  1077. written to disk. Also, the checkpoint SCN in the datafile's
  1078. controlfile record is advanced to the new database checkpoint SCN.
  1079.  
  1080. 3.5 Online-Fuzzy Bit
  1081.  
  1082. Note that more changes - beyond those already in the marked
  1083. buffers - may be generated after the start of checkpoint. Such
  1084. changes would be generated at SCNs higher than the SCN that will
  1085. be recorded in the file header. They could either be changes to
  1086. marked buffers that were added since checkpoint start, or else
  1087. changes to unmarked buffers. Buffers containing these changes
  1088. could written out for a variety of reasons. Thus, the online files are
  1089. online-fuzzy; that is, they generally contain changes in the future of
  1090. (i.e. generated at higher SCNs than) their header checkpoint SCN.
  1091. A datafile is virtually always online-fuzzy while it is online and the
  1092. database is open.
  1093.  
  1094. Online-fuzzy state is indicated by setting the so-called online-fuzzy
  1095. bit in the datafile header. The online-fuzzy bits of all online
  1096. datafiles are set at database open time. Also, when a datafile is
  1097. brought online while the database is open, its online-fuzzy bit is
  1098. set.
  1099.  
  1100. The online-fuzzy bits are cleared after the last instance does a
  1101. shutdown "normal" or "immediate." Other occasions for clearing
  1102. the online-fuzzy bits are: (i) the finish of crash recovery; (ii) when
  1103. media recovery "checkpoints" (flushes its buffers) after
  1104. encountering an end-crash-recovery redo record (see 5.5); (iii)
  1105. when taking a datafile offline "temporary" or "normal" (i.e. an
  1106. offline operation that is preceded by a file checkpoint); (iv) when
  1107. BEGIN BACKUP is issued (see 4.1).
  1108.  
  1109. As will be seen in 8.1, open with resetlogs will fail if any online
  1110. datafile has the online-fuzzy bit (or any fuzzy bit) set.
  1111.  
  1112. 3.6 Datafile Checkpoint
  1113.  
  1114. A datafile checkpoint event, executed by all open instances (for all
  1115. open threads), forces to disk all dirty buffers in any instance that
  1116. contain changes to a particular datafile (or set of datafiles) before a
  1117. designated SCN - the datafile checkpoint SCN. Once all datafile-
  1118. related redo from all open threads prior to the checkpoint SCN has
  1119. been written to disk, the datafile checkpoint structure in the file
  1120. header is updated and written to disk.
  1121.  
  1122. Datafile checkpoints occur as part of operations such as beginning
  1123. hot backup (see Section 4) and offlining datafiles as part of taking a
  1124. tablespace offline normal (see 2.17).
  1125.  
  1126. 3.7 Log Switch
  1127.  
  1128. When an instance needs to generate more redo but cannot allocate
  1129. enough blocks in the current log, it does a log switch. The first step
  1130. in a log switch is to find an online log that is a candidate for reuse.
  1131.  
  1132. The first requirement for the candidate log is that it must not be
  1133. active: i.e. it must not be needed for crash/instance recovery. In
  1134. other words, it must be overwritable without losing redo data
  1135. needed for instance recovery. The principle enforced is that a
  1136. logfile cannot be reused until the current thread checkpoint is
  1137. beyond that logfile. Since instance recovery starts at the current
  1138. thread checkpoint SCN/RBA (and expects to find that RBA in an
  1139. online redo log), the ability to do instance recovery using only
  1140. online logs translates into the requirement that the current thread
  1141. checkpoint SCN be beyond the highest SCN associated with redo
  1142. in the candidate log. If this is not the case, then the thread
  1143. checkpoint currently in progress - e.g. the one started when the
  1144. candidate log was originally switched into (see below) - is
  1145. hurried up to complete.
  1146.  
  1147. The other requirement for the candidate log is that it does not need
  1148. archiving. Of course, this requirement only applies to a database
  1149. running in ARCHIVELOG mode. If archiving is required, the
  1150. archiver is posted.
  1151.  
  1152. As soon as the log switch completes, a new thread checkpoint is
  1153. started in the new log. Hopefully, the checkpoint will complete
  1154. before the next log switch is needed.
  1155.  
  1156. 3.8 Archiving Log Switches
  1157.  
  1158. Each thread switches logs independently. Thus, when running
  1159. Parallel Server, an SCN is almost never at the beginning of a log in
  1160. all threads. However, it is desirable to have roughly the same range
  1161. of SCNs in the archived logs of all enabled threads. This ensures
  1162. that the last log archived in each thread is reasonably current. If an
  1163. unarchived log for an enabled thread contained a very old SCN (as
  1164. would occur in the case of a relatively idle instance), it would not
  1165. be possible to use archived logs from a primary site to do recovery
  1166. to a higher SCN at a standby site. This would be true even if the log
  1167. with the low SCN contained no redo.
  1168.  
  1169. This problem is solved by forcing log switches in other threads
  1170. when their current log is significantly behind the log just archived.
  1171. For the case of an open thread, a lock is used to "kick" the laggard
  1172. instance into switching logs and archiving when it can. For the case
  1173. of a closed thread, the archiving process in the active instance does
  1174. the closed thread's log switch and archiving for it. Note that this
  1175. can result in a thread that is enabled but never used having a bunch
  1176. of archived logs with only a file header. A force archiving SCN is
  1177. maintained in the database info controlfile record to implement this
  1178. feature. The system strives to archive any log that contains that
  1179. SCN or less. In general, the log with the lowest SCN is archived
  1180. first.
  1181.  
  1182. The command ALTER SYSTEM ARCHIVE LOG CURRENT can
  1183. be used to manually archive the current logs of all enabled threads.
  1184. It forces all threads, open and closed, to switch to a new log. It
  1185. archives what is necessary to ensure all the old logs are archived. It
  1186. does not return until all redo generated before the command was
  1187. entered is archived. This command is useful for ensuring all redo
  1188. logs necessary for the recovery of a hot backup are archived. It is
  1189. also useful for ensuring the potential currency of a standby site in a
  1190. configuration in which archived logs from a primary site are
  1191. shipped to a standby site for application by recovery in case of
  1192. disaster (i.e. "standby database").
  1193.  
  1194. 3.9 Thread Open
  1195.  
  1196. When an instance opens the database, it needs to open a thread for
  1197. redo generation. The thread is chosen at mount time. A system
  1198. initialization parameter can be used to specify the thread to mount
  1199. by number. Otherwise, any available publicly-enabled thread can
  1200. be chosen by the instance at mount time. A thread-mounted lock is
  1201. used to prevent two instances from mounting the same thread.
  1202. When an instance opens a thread, it sets the thread-open flag in the
  1203. thread's controlfile record. While the instance is alive, it holds a set
  1204. of thread-opened locks (one held by each of LGWR, DBWR,
  1205. LCK0, LCK1, ...). (These are released at instance death, enabling
  1206. one instance to detect the death of another in the Parallel Server
  1207. environment: see 5.1). Also at thread open time, a new checkpoint
  1208. is captured and used for the thread checkpoint. If this is the first
  1209. database open, this becomes the new database checkpoint, ensuring
  1210. all online files have their header checkpoints advanced at open
  1211. time. Note that a log switch may be forced at thread open time.
  1212.  
  1213. 3.10 Thread Close
  1214.  
  1215. When an instance closes the database, or when a thread is
  1216. recovered by instance/crash recovery, the thread is closed. The first
  1217. step in closing a thread is to ensure that no more redo is generated
  1218. in it. The next step is to ensure that all changes described by
  1219. existing redo records are in the online datafiles on disk. In the case
  1220. of normal database close, this is accomplished by doing a thread
  1221. checkpoint. The SCN from this final thread checkpoint is said to be
  1222. the "SCN at which the thread was closed." Finally, the thread's
  1223. controlfile record is updated to clear the thread-open flag.
  1224.  
  1225. In the case of thread close by instance recovery, the presence in the
  1226. online datafiles of all changes described by thread redo records is
  1227. ensured by starting redo application at the most recent thread
  1228. checkpoint and continuing through end-of-thread. Once all changes
  1229. described by thread redo records are in the online datafiles, the
  1230. thread checkpoint is advanced to the end-of-thread. Just as in the
  1231. case of a normal thread checkpoint, this checkpoint may advance
  1232. the database checkpoint. If this is the last thread close, the database
  1233. checkpoint thread field in the database info controlfile record -
  1234. which normally points to an open thread - will be left pointing at
  1235. this thread, even though it is closed.
  1236.  
  1237. 3.11 Thread Enable
  1238.  
  1239. In order for a thread to be opened, it must be enabled. This ensures
  1240. that its redo will be found during media recovery. A thread may be
  1241. enabled in either public or private mode. A private thread can only
  1242. be mounted by an instance that specifies it in the THREAD system
  1243. initialization parameter. This is analogous to rollback segments. A
  1244. thread must have at least two online redo log groups while it is
  1245. enabled. An enabled thread always has one online log that is its
  1246. current log. The next SCN of the current log is infinite, so that any
  1247. new SCN allocated will be within the current log. A special thread-
  1248. enable redo record is written in the thread of an instance enabling a
  1249. new thread (i.e. via ALTER DATABASE ENABLE THREAD).
  1250. The thread-enable redo record is used by media recovery to start
  1251. applying redo from the new thread. Note that this means it takes an
  1252. open thread to enable another thread. This chicken and egg
  1253. problem is resolved by having thread one automatically enabled
  1254. publicly at database creation. This also means that databases that
  1255. do not run in Parallel Server mode do not need to enable a thread.
  1256.  
  1257. 3.12 Thread Disable
  1258.  
  1259. If a thread is not going to be used for a long while, it is best to
  1260. disable it. This means that media recovery will not expect any redo
  1261. to be found in the thread. Once a thread is disabled, its logs may be
  1262. dropped. A thread must be closed before it can be disabled. This
  1263. ensures all its changes have been written to the datafiles. A new
  1264. SCN is allocated to save as the next SCN for the current log. The
  1265. log header is marked with this SCN and flags saying it is the end of
  1266. a disabled thread. It is important that a new current SCN is
  1267. allocated. This ensures the SCN in any checkpoint with this thread
  1268. enabled will appear in one of the logs from the thread. Note that
  1269. this means a thread must be open in order to disable another thread.
  1270. Thus, it is not possible to disable all threads.
  1271.  
  1272.  
  1273.  
  1274.  
  1275.  
  1276.  
  1277.  
  1278.  
  1279.  
  1280. 4 Hot Backup
  1281.  
  1282. A hot backup is a copy of a datafile that is taken while the file is in
  1283. active use. Datafile writes (by DBWR) go on as usual during the
  1284. time the backup is being copied. Thus, the backup gets a "fuzzy"
  1285. copy of the datafile:
  1286.  
  1287. 7 Some blocks may be ahead in time versus other blocks of the
  1288. copy.
  1289.  
  1290. 7 Some blocks of the copy may be ahead of the checkpoint SCN
  1291. in the file header of the copy.
  1292.  
  1293. 7 Some blocks may contain updates that constitute breakage of
  1294. the redo record atomicity guarantee with respect to other
  1295. blocks in this or other datafiles.
  1296.  
  1297. 7 Some block copies may be "fractured" (due to front and back
  1298. halves being copied at different times, with an intervening
  1299. update to the block on disk).
  1300.  
  1301. The "hotbackup-fuzzy" copy is unusable without "focusing" (via
  1302. the redo log) that occurs when the backup is restored and
  1303. undergoes media recovery. Media recovery applies redo (from all
  1304. threads) from the begin-backup checkpoint SCN (see Step 2. in
  1305. Section 4.1) through the end-point of the recovery operation (either
  1306. complete or incomplete). The result is a transaction-consistent
  1307. "focused" version of the datafile.
  1308.  
  1309. There are three steps to taking a hot backup:
  1310.  
  1311. 7 Execute the ALTER TABLESPACE ... BEGIN BACKUP
  1312. command.
  1313.  
  1314. 7 Use an operating system copy utility to copy the constituent
  1315. datafiles of the tablespace(s).
  1316.  
  1317. 7 Execute the ALTER TABLESPACE ... END BACKUP com-
  1318. mand.
  1319.  
  1320. 4.1 BEGIN BACKUP
  1321.  
  1322. The BEGIN BACKUP command takes the following actions (not
  1323. necessarily in the listed order) for each datafile of the tablespace:
  1324.  
  1325. 1. It sets a flag in the datafile header - the hotbackup-fuzzy bit
  1326. - to indicate that the file is in hot backup. The header with
  1327. this flag set (copied by the copy utility) enables the copy to be
  1328. recognized as a hot backup. A further purpose of this flag in
  1329. the online file header is to cause the checkpoint in the file
  1330. header to be "frozen" at the begin-backup checkpoint value
  1331. that will be set in Step 4. This is the value that it must have in
  1332. the backup copy in order to ensure that, when the backup is
  1333. recovered, media recovery will start redo application at a suffi-
  1334. ciently early checkpoint SCN so as to cover all changes to the
  1335. file in all threads since the execution of BEGIN BACKUP (see
  1336. 6.5). Since we cannot guarantee that the file header will be the
  1337. first block to be written out by the copy utility, it is important
  1338. that the file header checkpoint structure remain "frozen" until
  1339. END BACKUP time. This flag keeps the datafile checkpoint
  1340. structure "frozen" during hot backup, preventing it (and the
  1341. checkpoint SCN in the datafile's controlfile record) from being
  1342. updated during thread checkpoint events that advance the
  1343. database checkpoint. New in v7.2: While the file is in hot
  1344. backup, a new "backup" checkpoint structure in the datafile
  1345. header receives the updates that the "frozen" checkpoint
  1346. would have received.
  1347.  
  1348. 2. It executes a datafile checkpoint, capturing the resultant
  1349. "begin-backup" checkpoint information, including the begin-
  1350. backup checkpoint SCN. When the file is checkpointed, all
  1351. instances are requested to write out all dirty buffers they have
  1352. for the file. If the need for instance recovery is detected at this
  1353. time, the file checkpoint operation waits until it is completed
  1354. before proceeding. Checkpointing the file at begin-backup
  1355. time ensures that only file blocks changed after begin-backup
  1356. time might have been written to disk during the course of the
  1357. file copy. This guarantee is crucial to enabling block before-
  1358. image logging to cope with the fractured block problem, as
  1359. described in Step 3.
  1360.  
  1361. 3. [Platform-dependent option]: It starts block before-image log-
  1362. ging for the file. During block before-image logging, all
  1363. instances log a full block before-image to the redo log prior to
  1364. the first change to each block of the file (since the backup
  1365. started, or since the block was read anew into the buffer
  1366. cache). This is to forestall a recovery problem that would arise
  1367. if the backup were to contain a fractured block copy (mis-
  1368. matched halves). This could happen if (the database block size
  1369. is greater than the operating system block size, and) the front
  1370. and back halves of the block were copied to the backup at dif-
  1371. ferent times - with an intervening update to the block on
  1372. disk. In this eventuality, recovery can reconstruct the block
  1373. using the logged block before-image.
  1374.  
  1375. 4. It sets the checkpoint in the file header equal to the begin-
  1376. backup checkpoint captured in Step 2. This file header check-
  1377. point will be "frozen" until END BACKUP is executed.
  1378.  
  1379. 5. It clears the file's online-fuzzy bit. The online-fuzzy bit
  1380. remains clear during the course of the file copy operation, thus
  1381. ensuring a cleared online-fuzzy bit in the file copy. Note that
  1382. the online-fuzzy bit is set again by the execution of END
  1383. BACKUP.
  1384.  
  1385. 4.2 File Copy
  1386.  
  1387. The file copy is done by utilities that are not part of Oracle. The
  1388. presumption is that the platform vendor will have backup facilities
  1389. that are superior to any portable facility that we could develop. It is
  1390. the responsibility of the administrator to ensure that copies are only
  1391. taken between the BEGIN BACKUP and END BACKUP
  1392. commands, or when the file is not in use.
  1393.  
  1394. 4.3 END BACKUP
  1395.  
  1396. The END BACKUP command takes the following actions for each
  1397. datafile of the tablespace:
  1398.  
  1399. 1. It restores (i.e. sets) the file's online-fuzzy bit.
  1400.  
  1401. 2. It creates an end-backup redo record (end-backup "marker")
  1402. for the datafile. This record, interpreted only by media recov-
  1403. ery, contains the begin-backup checkpoint SCN (i.e. the SCN
  1404. matching that in the "frozen" checkpoint in the backup's
  1405. header). This record serves to mark the end of the redo gener-
  1406. ated during the backup. The end-backup "marker" is used by
  1407. media recovery to determine when all redo generated between
  1408. BEGIN BACKUP and END BACKUP has been applied to the
  1409. datafile. Upon encountering the end-backup "marker", media
  1410. recovery can (at the next media recovery checkpoint: see
  1411. 6.7.1) clear the hotbackup-fuzzy bit. This is only important in
  1412. preventing an incomplete recovery that might erroneously
  1413. attempt to end before all redo generated between BEGIN
  1414. BACKUP and END BACKUP has been applied. Ending
  1415. incomplete recovery at such a point may result in an inconsis-
  1416. tent file, since the backup copy may already have contained
  1417. changes beyond this endpoint. As will be seen on 8.1, open
  1418. with resetlogs following incomplete media recovery will fail if
  1419. any online datafile has the hotbackup-fuzzy bit (or any other
  1420. fuzzy bit) set.
  1421.  
  1422. 3. It clears the file's hotbackup-fuzzy bit.
  1423.  
  1424. 4. It stops block before-image logging for the file.
  1425.  
  1426. 5. It advances the file checkpoint to the current database check-
  1427. point. This compensates for any file header update(s) missed
  1428. during thread checkpoints that may have advanced the data-
  1429. base checkpoint while the file was in hot backup state, with its
  1430. checkpoint "frozen".
  1431.  
  1432. 4.4 "Crashed" Hot Backup
  1433.  
  1434. A normal shutdown of the instance that started a backup, or the last
  1435. remaining instance, is not allowed while any files are in hot
  1436. backup. Nor may a file in backup be taken offline normal or
  1437. temporary. This is to ensure an end-backup "marker" is generated
  1438. whenever possible, and to make administrators aware that they
  1439. forgot to issue the END BACKUP command, and that the backup
  1440. copy is unusable.
  1441.  
  1442. When an instance failure or shutdown abort leaves a hot backup
  1443. operation incomplete (i.e. lacking termination via END BACKUP),
  1444. any file that was in backup before the failure has its hotbackup-
  1445. fuzzy bit set and its checkpoint "frozen" at the begin-backup
  1446. checkpoint. Even though the online file's datablocks are actually
  1447. current to the database checkpoint, the file's header makes it look
  1448. like a restored backup that needs media recovery and is current
  1449. only to the begin-backup checkpoint. Crash recovery will fail -
  1450. claiming media recovery is required - if it encounters an online
  1451. file in "crashed" hot backup state. The file does not actually need
  1452. media recovery, however, but only an adjustment to its file header
  1453. to take it out of "crashed" hot backup state.
  1454.  
  1455. Media recovery could be used to recover and allow normal open of
  1456. a database that has files left in "crashed" hot backup state. For v7.2
  1457. however, a preferable option - because it requires no archived
  1458. logs - is to use the (new in v7.2) command ALTER DATABASE
  1459. DATAFILE... END BACKUP on the files left in "crashed" hot
  1460. backup state (identifiable using the V$BACKUP fixed-view: see
  1461. 9.6). Following execution of this command, crash recovery will
  1462. suffice to open the database. Note that the ALTER TABLESPACE
  1463. ... END BACKUP format of the command cannot be used when the
  1464. database is not open. This is because the database must be open in
  1465. order to translate (via the data dictionary) tablespace names into
  1466. their constituent datafile names.
  1467.  
  1468.  
  1469.  
  1470.  
  1471.  
  1472.  
  1473.  
  1474.  
  1475.  
  1476. 5 Instance Recovery
  1477.  
  1478. Instance recovery is used to recover from both crash failures and
  1479. Parallel Server instance failures. Instance recovery refers either to
  1480. crash recovery or to Parallel Server instance recovery (where a
  1481. surviving instance recovers when one or more other instances fail).
  1482.  
  1483. The goal of instance recovery is to restore the datablock changes
  1484. that were in the cache of the dead instance and to close the thread
  1485. that was left open. Instance recovery uses only online redo logfiles
  1486. and current online datafiles (not restored backups). It recovers one
  1487. thread at a time, starting at the most recent thread checkpoint and
  1488. continuing until end-of-thread.
  1489.  
  1490. 5.1 Detection of the Need for Instance Recovery
  1491.  
  1492. The kernel performs instance recovery automatically upon
  1493. detecting that an instance died leaving its thread-open flag set in
  1494. the controlfile. Instance recovery is performed automatically on
  1495. two occasions:
  1496.  
  1497. 1. at the first database open after a crash (crash recovery);
  1498.  
  1499. 2. when some but not all instances of a Parallel Server fail.
  1500.  
  1501. In the case of Parallel Server, a surviving instance detects the need
  1502. to perform instance recovery for one or more failed instances by
  1503. the following means:
  1504.  
  1505. 1. A foreground process in a surviving instance detects an
  1506. "invalid block lock" condition when it attempts to bring a
  1507. datablock into the buffer cache. This is an indication that
  1508. another instance died while a block covered by that lock was
  1509. in a potentially "dirty" state in its buffer cache.
  1510.  
  1511. 2. The foreground process sends a notification to its instance's
  1512. SMON process, which begins a search for dead instances.
  1513.  
  1514. 3. The death of another instance is detected if the current
  1515. instance is able to acquire that instance's thread-opened locks
  1516. (see 3.9).
  1517.  
  1518. SMON in the surviving instance obtains a stable list of dead
  1519. instances, together with a list of "invalid" block locks. Note: After
  1520. instance recovery is complete, locks in this list will undergo "lock
  1521. cleanup" (i.e. they will have their "invalid" condition cleared,
  1522. making the underlying blocks accessible again).
  1523.  
  1524. 5.2 Thread-at-a-Time Redo Application
  1525.  
  1526. Instance recovery operates by processing one thread at a time,
  1527. thereby recovering one instance at a time. It applies all redo (from
  1528. the thread checkpoint through the end-of-thread) from each thread
  1529. before starting on the next thread. This algorithm depends on the
  1530. fact that only one instance at a time can have a given block
  1531. modified in its cache. Between changes to the block by different
  1532. instances, the block is written to disk. Thus, a given block (as read
  1533. from disk during instance recovery) can need redo applied from at
  1534. most one thread - the thread containing the most recent
  1535. modification.
  1536.  
  1537. Instance recovery can always be accomplished using the online
  1538. redo logs for the thread being recovered. Crash recovery operates
  1539. on the thread with the lowest checkpoint SCN first. It proceeds to
  1540. recover the threads in the order of increasing thread checkpoint
  1541. SCNs. This ensures that the database checkpoint is advanced by
  1542. each thread recovered.
  1543.  
  1544. 5.3 Current Online Datafiles Only
  1545.  
  1546. The checkpoint counters are used to ensure that the datafiles are the
  1547. current online files rather than restored backups. If a backup copy
  1548. of a datafile is restored, then media recovery is required.
  1549.  
  1550. Media recovery is required for a restored backup even if recovery
  1551. can be accomplished using the online logs. The reason is that crash
  1552. recovery applies all post-thread-checkpoint redo from each thread
  1553. before starting on the next thread. Crash recovery can use this
  1554. thread-at-a-time redo application algorithm because a given
  1555. datablock can need redo application from at most one thread.
  1556.  
  1557. However, starting recovery from a restored backup enables no such
  1558. assumption about the number of threads that have relevant redo.
  1559. Thus, the thread-at-a-time algorithm would not work. Recovering a
  1560. backup requires thread-merged redo application: i.e. application of
  1561. all post-file-checkpoint redo, simultaneously merging redo from all
  1562. threads in SCN order. This thread-merged redo application
  1563. algorithm is the one used by media recovery (see Section 6).
  1564.  
  1565. Crash recovery would not suffice - even with thread-merged redo
  1566. application - to recover a backup datafile, even if it were
  1567. checkpointed at the current database checkpoint. The reason is that
  1568. in all but the database checkpoint thread, crash recovery would
  1569. miss applying redo between the database checkpoint and the
  1570. (higher) thread checkpoint. By contrast, media recovery would
  1571. start redo application at the file checkpoint in all threads.
  1572. Furthermore, crash recovery might fail even if it started redo
  1573. application at the file checkpoint in all threads. The reason is that
  1574. crash recovery assumes that it will need only online logfiles. All
  1575. but the database checkpoint thread might have already archived
  1576. and re-used a needed log.
  1577.  
  1578. If the STARTUP RECOVER command is used (in place of simple
  1579. STARTUP), and crash recovery fails due to datafiles needing
  1580. media recovery (e.g. they are restored backups), then media
  1581. recovery via RECOVER DATABASE (see 6.4.1) is automatically
  1582. executed prior to database open.
  1583.  
  1584. 5.4 Checkpoints
  1585.  
  1586. Instance recovery does not attempt to apply redo that is before the
  1587. checkpoint SCN of a datafile. (The datafile header checkpoint
  1588. SCNs are not used to decide where to start recovery, however.)
  1589.  
  1590. The redo from the thread checkpoint through the end-of-thread
  1591. must be read to find the end-of-thread and the highest SCN
  1592. allocated by the thread. These are then used to close the thread and
  1593. advance the thread checkpoint. The end of a instance recovery
  1594. almost always advances the datafile checkpoints, and always
  1595. advances the checkpoint counters.
  1596.  
  1597. 5.5 Crash Recovery Completion
  1598.  
  1599. At the termination of crash recovery, the "fuzzy bits" - online-
  1600. fuzzy, hotbackup-fuzzy, media-recovery-fuzzy - of all online
  1601. datafiles are cleared. A special redo record, the end-crash-recovery
  1602. "marker," is generated. This record is interpreted by media
  1603. recovery to know when it is permissible to clear the online-fuzzy
  1604. and hotbackup-fuzzy bits of the datafiles undergoing recovery (see
  1605. 6.6).
  1606.  
  1607.  
  1608.  
  1609.  
  1610.  
  1611.  
  1612.  
  1613.  
  1614.  
  1615. 6 Media Recovery
  1616.  
  1617. Media recovery is used to recover from a lost or damaged datafile,
  1618. or from a lost current controlfile. It is used to transform a restored
  1619. datafile backup into a "current" datafile. It is also used to restore
  1620. changes that were lost when a datafile went offline without a
  1621. checkpoint. Media recovery can apply archived logs as well as
  1622. online logs. Unlike instance or crash recovery, media recovery is
  1623. invoked only via explicit command.
  1624.  
  1625. 6.1 When to Do Media Recovery
  1626.  
  1627. As was seen in 5.3, a restored datafile backup always needs media
  1628. recovery, even if its recovery can be accomplished using only
  1629. online logs. The same is true of a datafile that went offline without
  1630. a checkpoint. The database cannot be opened if any of the online
  1631. datafiles needs media recovery. A datafile that needs media
  1632. recovery cannot be brought online until media recovery has been
  1633. executed. Unless the database is not open by any instance, media
  1634. recovery can only operate on offline files. Media recovery may be
  1635. explicitly invoked to recover a database prior to open even when
  1636. crash recovery would have sufficed. If so, crash recovery - though
  1637. it may find nothing to do - will still be invoked automatically at
  1638. database open. Note that media recovery may be run - and, in
  1639. cases such as restored backups or datafiles that went offline
  1640. immediate, must be run - even if recovery can be accomplished
  1641. using only the online logs. Media recovery may find nothing to do
  1642. - and signal the "no recovery required" error - if invoked for
  1643. files that do not need recovery.
  1644.  
  1645. If the current controlfile is lost and a backup controlfile is restored
  1646. in its place, media recovery must be done. This is the case even if
  1647. all of the datafiles are current.
  1648.  
  1649. 6.2 Thread-Merged Redo Application
  1650.  
  1651. Media recovery uses a thread-merged redo application algorithm:
  1652. i.e. it applies redo from all threads simultaneously, merging redo
  1653. records in increasing SCN order. The process of media-recovering
  1654. a backup datafile differs from the process of crash-recovering a
  1655. current online datafile in the following fundamental way: Crash
  1656. recovery applies redo from one thread at a time because any block
  1657. of a current online file can need redo from at most one thread (one
  1658. instance at a time can dirty a block in cache). With a restored
  1659. backup, however, no assumption can be made about the number of
  1660. threads that have redo relevant to particular block. In general,
  1661. recovering a backup requires simultaneous application of redo
  1662. from all threads, with merging of redo records across threads in
  1663. SCN order. Note that this algorithm depends on a redo-generation-
  1664. time guarantee that changes for a given block occur in increasing
  1665. SCN order across threads (case of Parallel Server).
  1666.  
  1667. 6.3 Restoring Backups
  1668.  
  1669. The administrator may copy backup versions of datafiles to the
  1670. current datafile while the database is shut down or the file is offline.
  1671. There is a strong assumption that backups are never copied to files
  1672. that are currently accessible. Every file header read verifies that this
  1673. has not been done by comparing the checkpoint counter in the file
  1674. header with the checkpoint counter in the datafile's controlfile
  1675. record.
  1676.  
  1677. 6.4 Media Recovery Commands
  1678.  
  1679. There are three media recovery commands:
  1680.  
  1681. 7 RECOVER DATABASE
  1682.  
  1683. 7 RECOVER TABLESPACE
  1684.  
  1685. 7 RECOVER DATAFILE
  1686.  
  1687. The only essential difference in these commands is in how the set
  1688. of files to recover is determined. They all use the same criteria for
  1689. determining if the files can be recovered. There is a lock per
  1690. datafile that is held exclusive by a process doing media recovery on
  1691. a file, and is held shared by an instance that has the database open
  1692. with the file online. Media recovery signals an error if it cannot get
  1693. the lock for a file it is asked to recover. This prevents two recovery
  1694. sessions from recovering the same file, and prevents media
  1695. recovery of a file that is in use.
  1696.  
  1697. 6.4.1 RECOVER DATABASE
  1698.  
  1699. This command does media recovery on all online datafiles that
  1700. need any redo applied. If all instances were cleanly shutdown, and
  1701. no backups were restored, this command will signal the "no
  1702. recovery required" error. It will also fail if any instances have the
  1703. database open, since they will have the datafile locks.
  1704.  
  1705. 6.4.2 RECOVER TABLESPACE
  1706.  
  1707. This command does media recovery on all datafiles in the
  1708. tablespaces specified. In order to translate (i.e. via the data
  1709. dictionary) the tablespace names into datafile names, the database
  1710. must be open. This means that the tablespaces and their constituent
  1711. datafiles must be offline in order to do the recovery. An error is
  1712. signalled if none of the tablepace's constituent files needs recovery.
  1713.  
  1714. 6.4.3 RECOVER DATAFILE
  1715.  
  1716. This command specifies the datafiles to be recovered. The database
  1717. may be open; or it may be closed, as long as the media recovery
  1718. locks can be acquired. If the database is open in any instance, then
  1719. datafile recovery can only recover offline files.
  1720.  
  1721. 6.5 Starting Media Recovery
  1722.  
  1723. Media recovery starts by finding the media-recovery-start SCN: i.e.
  1724. the lowest SCN of the datafile header checkpoints of the files being
  1725. recovered. Note: An exception occurs if a file's checkpoint is in its
  1726. offline range (see 2.18). In that case, the file's offline-end
  1727. checkpoint is used in place of its datafile header checkpoint in
  1728. computing the media-recovery-start SCN.
  1729.  
  1730. A buffer for reading redo is allocated for each thread in the enabled
  1731. thread bitvec of the media-recovery-start checkpoint (i.e. the
  1732. datafile checkpoint with the lowest SCN). The initial file header
  1733. checkpoint SCN of every file is saved to ensure that no redo from a
  1734. previous use of the file number is applied, as well as to eliminate
  1735. needlessly attempting to apply redo to a file from before its
  1736. checkpoint. The stop SCNs (from the datafiles' controlfile records)
  1737. are also saved. If finite, the highest stop SCN can be used to allow
  1738. recovery to terminate without needlessly searching for redo beyond
  1739. that SCN to apply (see 6.10). At recovery completion, any datafile
  1740. initially found to have a finite stop SCN will be left checkpointed at
  1741. that stop SCN (rather than at the recovery end-point). This allows
  1742. an offline-clean or read-only datafile to be left checkpointed at an
  1743. SCN that matches the tablespace-clean-stop-SCN of its tablespace.
  1744.  
  1745. 6.6 Applying Redo, Media Recovery Checkpoints
  1746.  
  1747. A log is opened for each thread of redo that was enabled at the time
  1748. the media-recovery-start SCN was allocated (i.e. for each thread in
  1749. the enabled thread bitvec of the media-recovery-start checkpoint).
  1750. If the log is online, then it is automatically opened. If the log was
  1751. archived, then the user is prompted to enter the name of the log
  1752. (unless automatic recovery is being used). The redo is applied from
  1753. all the threads in the order it was generated, switching threads as
  1754. needed. The order of application of redo records without an SCN is
  1755. not precise, but it is good enough for rollback to make the database
  1756. consistent.
  1757.  
  1758. Except in the case of cancel-based incomplete recovery (see
  1759. 6.12.1) and backup controlfile recovery (see 6.13), the next online
  1760. log in sequence is accessed automatically, if it is on disk. If not, the
  1761. user is prompted for the next log.
  1762.  
  1763. At log boundaries, media recovery executes a "checkpoint." As
  1764. part of media recovery checkpoint, the dirty recovery buffers are
  1765. written to disk and the datafile header checkpoints of the files
  1766. undergoing recovery are advanced, so that the redo does not need
  1767. to be reapplied. Another type of media recovery "checkpoint"
  1768. occurs when a datafile initially found to have a finite stop SCN
  1769. reaches that stop SCN. At such a stop SCN boundary, all dirty
  1770. recovery buffers are written to disk, and the datafiles that have been
  1771. made current have their datafile header checkpoints advanced to
  1772. their stop SCN values.
  1773.  
  1774. 6.7 Media Recovery and Fuzzy Bits
  1775.  
  1776. 6.7.1 Media-Recovery-Fuzzy
  1777.  
  1778. The media-recovery-fuzzy bit is a flag in the datafile header that is
  1779. used to indicate that - due to ongoing redo application by media
  1780. recovery - the file may contain changes in the future of (at SCNs
  1781. beyond) the current header checkpoint SCN. The media-recovery-
  1782. fuzzy bit is set at the start of media recovery for each file
  1783. undergoing recovery. Generally the media-recovery-fuzzy bits can
  1784. be cleared when a media recovery checkpoint advances the
  1785. checkpoints in the datafile headers. They are left clear when a
  1786. media recovery session completes successfully or is cancelled. As
  1787. will be seen on 8.1, open with resetlogs following incomplete
  1788. media recovery will fail if any online datafile has the media-
  1789. recovery-fuzzy bit (or any fuzzy bit) set.
  1790.  
  1791. 6.7.2 Online-Fuzzy
  1792.  
  1793. Upon encountering an end-crash-recovery "marker" (or a file-
  1794. specific offline-immediate "marker": generated when a datafile
  1795. goes offline without a checkpoint), media recovery can (at the next
  1796. media recovery checkpoint) clear (if set) the online-fuzzy and
  1797. hotbackup-fuzzy bits in the appropriate datafile header(s).
  1798.  
  1799. 6.7.3 Hotbackup-Fuzzy
  1800.  
  1801. Upon encountering an end-backup "marker" (or an end-crash-
  1802. recovery "marker"), media recovery can (at the next media
  1803. recovery checkpoint) clear the hotbackup-fuzzy bit. Open with
  1804. resetlogs following incomplete media recovery will fail if any
  1805. online datafile has the hotbackup-fuzzy bit (or any fuzzy bit) set.
  1806. This prevents a successful RESETLOGS open following an
  1807. incomplete recovery that terminated before all redo generated
  1808. between BEGIN BACKUP and END BACKUP had been applied.
  1809. Ending incomplete recovery at such a point would generally result
  1810. in an inconsistent file, since the backup copy may already have
  1811. contained changes between this endpoint and the END BACKUP.
  1812.  
  1813. 6.8 Thread Enables
  1814.  
  1815. A special thread-enable redo record is written in the thread of an
  1816. instance enabling a new thread. If media recovery encounters a
  1817. thread-enable redo record, it allocates a new redo buffer, opens the
  1818. appropriate log in the new thread, and prepares to start applying
  1819. redo from the new thread.
  1820.  
  1821. 6.9 Thread Disables
  1822.  
  1823. When a thread is disabled, its current log is marked as the end of a
  1824. disabled thread. After media recovery finishes applying redo from
  1825. such a log, it deallocates the thread's redo buffer and stops looking
  1826. for redo from the thread.
  1827.  
  1828. 6.10 Ending Media Recovery (Case of Complete Media Recovery)
  1829.  
  1830. The current (i.e. last) log in every enabled thread has the end-of-
  1831. thread flag set in its header. Complete (as opposed to incomplete:
  1832. see 6.12) media recovery always continues redo application
  1833. through the end-of-thread in all threads. The end-of-thread log can
  1834. be identified without having the current controlfile, since the end-
  1835. of-thread flag is in the log header rather than in the logfile's
  1836. controlfile record.
  1837.  
  1838. Note: Backing up and later restoring copies of current online logs
  1839. is dangerous, and can lead to mis-identification of the current true
  1840. end-of-thread. This is because the end-of-thread flag in the backup
  1841. copy will in general be out-of-date with respect to the current end-
  1842. of-thread log.
  1843.  
  1844. If the datafiles being recovered have finite stop SCNs in their
  1845. controlfile records (assuming a current controlfile), then media
  1846. recovery can stop prior to the end-of-threads. Redo application for
  1847. a datafile with a finite stop SCN can terminate at that SCN, since it
  1848. is guaranteed that no redo for that datafile beyond that SCN was
  1849. generated.
  1850.  
  1851. As described on 2.15, the stop SCN is set when a datafile goes
  1852. offline. Note that without the optimization that allows recovery of a
  1853. file with a finite stop SCN to terminate at that SCN, it could not be
  1854. guaranteed that recovery of an offline datafile while the database is
  1855. open would terminate.
  1856.  
  1857. 6.11 Automatic Recovery
  1858.  
  1859. Automatic recovery is invoked by using the AUTOMATIC option
  1860. of the media recovery command. It saves the user the trouble of
  1861. entering the names of archived logfiles, provided they are on disk.
  1862. If the sequence number of the log can be determined, then a name
  1863. can be constructed by concatenating the current values of the
  1864. initialization parameters LOG_ARCHIVE_DEST and
  1865. LOG_ARCHIVE_FORMAT. The current LOG_ARCHIVE_DEST
  1866. is assumed, unless the user overrides it by specifying a different
  1867. archiving destination for the recovery session. The media-
  1868. recovery-start checkpoint (see 6.5) contains (in the RBA field) the
  1869. initial log sequence number for one thread (i.e. the thread that
  1870. generated the checkpoint). If multiple threads of redo are enabled,
  1871. the log history section of the controlfile (if configured) can be used
  1872. to map the media-recovery-start SCN to a log sequence number for
  1873. each thread. Once the initial recovery log is found for a thread, all
  1874. subsequent logs needed from the thread follow in order. If it is not
  1875. possible to determine the initial log sequence number, the user will
  1876. have to guess and try logs until the right one is accepted. The
  1877. timestamp from the media-recovery-start checkpoint is reported to
  1878. aid in this effort.
  1879.  
  1880. 6.12 Incomplete Recovery
  1881.  
  1882. A RECOVER DATABASE execution can be stopped and the
  1883. database opened before all the redo has been applied. This type of
  1884. recovery is termed incomplete recovery. The subsequent database
  1885. open is termed a RESETLOGS open.
  1886.  
  1887. Incomplete recovery effectively sets the entire database backwards
  1888. in time to a transaction-consistent state at or near the recovery end-
  1889. point. All subsequent updates to the database are lost and must be
  1890. re-entered.
  1891.  
  1892. Use of incomplete recovery is indicated in the following
  1893. circumstances:
  1894.  
  1895. 7 Media recovery is necessary (e.g. due to datafile damage or
  1896. loss), but cannot be complete (i.e. all redo cannot be applied)
  1897. because all copies of a needed online or archived redo log
  1898. were lost.
  1899.  
  1900. 7 All copies of an active (i.e. needed for instance recovery) log
  1901. were damaged or lost while the database was open. Since
  1902. crash recovery is precluded, this case reduces to the previous
  1903. case.
  1904.  
  1905. 7 It is necessary to reverse the effect of an erroneous user action
  1906. (e.g. table drop or batch run); and it is acceptable to set the
  1907. entire database - not just the affected schema objects -
  1908. backwards to a point-in-time before the error.
  1909.  
  1910. 6.12.1 Incomplete Recovery UNTIL Options
  1911.  
  1912. There are three types of incomplete recovery. They differ in the
  1913. means used to stop the recovery:
  1914.  
  1915. 7 Cancel-Based (RECOVER DATABASE UNTIL CANCEL)
  1916.  
  1917. 7 Change-Based (RECOVER DATABASE UNTIL CHANGE)
  1918.  
  1919. 7 Time-Based (RECOVER DATABASE UNTIL TIME)
  1920.  
  1921. The UNTIL CANCEL option terminates recovery when the user
  1922. enters "cancel" rather than the name of a log. Online logs are not
  1923. automatically applied in this mode in case cancellation at the next
  1924. log is desired. If multiple threads of redo are being recovered, there
  1925. may be logs in other threads that are partially applied when the
  1926. recovery is cancelled.
  1927.  
  1928. The UNTIL CHANGE option terminates redo application just
  1929. before any redo associated with the specified SCN or higher. Thus
  1930. the transaction that committed at that SCN will be rolled back. If
  1931. you want to recover through a transaction that committed at a
  1932. specific SCN, then add one to the specified SCN.
  1933.  
  1934. The UNTIL TIME option works similarly to the UNTIL CHANGE
  1935. option, except that a time rather than an SCN is specified.
  1936. Recovery uses the timestamps in the redo block headers to convert
  1937. the specified time into an SCN. Then recovery is stopped when that
  1938. SCN is reached.
  1939.  
  1940. 6.12.2 Incomplete Recovery and Consistency
  1941.  
  1942. In order to avoid database corruption when running incomplete
  1943. recovery, all datafiles must be recovered to the exact same point.
  1944. Furthermore, no datafile must have any changes in the future of this
  1945. point. This requires that incomplete media recovery must start from
  1946. datafiles restored from backups whose copies completed prior to
  1947. the intended stop time. The system uses file header fuzzy bits (see
  1948. 8.1) to ensure that the datafiles contain no changes in the future of
  1949. the stop time.
  1950.  
  1951. 6.12.3 Incomplete Recovery and Datafiles Known to the Controlfile
  1952.  
  1953. If recovering to a time before a datafile was dropped, the dropped
  1954. file must appear in the controlfile used for recovery. Otherwise it
  1955. would not be recovered. One alternative for achieving this is to
  1956. recover using a backup controlfile made before the datafile was
  1957. dropped. Another alternative is to use the CREATE
  1958. CONTROLFILE command to construct a controlfile that lists the
  1959. dropped datafile.
  1960.  
  1961. Recovering to a time before a file was added is not a problem. The
  1962. extra datafile will be eliminated from the controlfile after the
  1963. database is open. The unwanted file may be taken offline before the
  1964. recovery to avoid accessing it.
  1965.  
  1966. 6.12.4 Resetlogs Open after Incomplete Recovery
  1967.  
  1968. The next database open after an incomplete recovery must specify
  1969. the RESETLOGS option. Amongst other effects (see Section 7),
  1970. resetlogs throws away the redo that was not applied during the
  1971. incomplete recovery, and marks the database so that the skipped
  1972. redo can never be accidentally applied by a subsequent recovery. If
  1973. the incomplete recovery was a mistake (e.g. the lost log was
  1974. found), the next open can specify the NORESETLOGS option.
  1975. However, for the open with NORESETLOGS to succeed, it must
  1976. be preceded by a successful execution of complete recovery (i.e.
  1977. one in which all redo is applied).
  1978.  
  1979. 6.12.5 Files Offline during Incomplete Recovery
  1980.  
  1981. If a file is offline during incomplete recovery, it will not be
  1982. recovered. This is ok if the file is part of a tablespace that was taken
  1983. offline normal, and that is still offline normal at the recovery end-
  1984. point. Otherwise, if the file is still offline when the resetlogs is
  1985. done, the tablespace containing the file will have to be dropped.
  1986. This is because it will need media recovery with logs from before
  1987. the resetlogs. In general V$DATAFILE should be checked to
  1988. ensure that files are online before running an incomplete recovery.
  1989. Only files that will be dropped and files that are part of offline
  1990. normal (or read-only) tablespaces should be offline (Section 8.6).
  1991.  
  1992. 6.13 Backup Controlfile Recovery
  1993.  
  1994. If recovery is done with a controlfile other than the current one,
  1995. then backup controlfile recovery (RECOVER
  1996. DATABASE...USING BACKUP CONTROLFILE) must be used.
  1997. This applies both to the case of a restored controlfile backup, and to
  1998. the case of a "backup" controlfile created via CREATE
  1999. CONTROLFILE...RESETLOGS.
  2000.  
  2001. Use of CREATE CONTROLFILE...RESETLOGS makes a
  2002. controlfile that is a "backup." Only a backup controlfile recovery
  2003. can be run after executing CREATE
  2004. CONTROLFILE...RESETLOGS. Only a RESETLOGS open can
  2005. be used after executing CREATE
  2006. CONTROLFILE...RESETLOGS. Use of CREATE
  2007. CONTROLFILE...RESETLOGS is indicated if (all copies of) an
  2008. online redo log were lost in addition to (all copies of) the control
  2009. file.
  2010.  
  2011. By contrast, CREATE CONTROLFILE...NORESETLOGS makes
  2012. a controlfile that is "current"; i.e. it has knowledge of the current
  2013. state of the online logfiles and log sequence numbers. A backup
  2014. controlfile recovery is not necessary following CREATE
  2015. CONTROLFILE...NORESETLOGS. Indeed, no recovery at all is
  2016. required if there was a clean shutdown, and if no datafile backups
  2017. have been restored. A normal or NORESETLOGS open may
  2018. follow CREATE CONTROLFILE ...NORESETLOGS.
  2019.  
  2020. A backup controlfile lacks valid information about the current
  2021. online logs and datafile stop SCNs. Hence, recovery cannot look
  2022. for online logs to automatically apply. Moreover, recovery must
  2023. assume infinite stop SCN's. A RESETLOGS open corrects this
  2024. information. The backup controlfile may have a different set of
  2025. threads enabled than did the original controlfile. That set will be the
  2026. effective enabled thread set following RESETLOGS open.
  2027.  
  2028. The BACKUP CONTROLFILE option may be used either alone or
  2029. in conjunction with an incomplete recovery option. Unless an
  2030. incomplete recovery option is included, all threads must be applied
  2031. to the end-of-thread. This is validated at open resetlogs time.
  2032.  
  2033. It is currently required that a RESETLOGS open follow execution
  2034. of backup controlfile recovery, even if no incomplete recovery
  2035. option was used. The following procedure could be used to avoid a
  2036. backup controlfile recovery and resetlogs in case the only problem
  2037. is a lost current controlfile (and a backup controlfile exists):
  2038.  
  2039. 1. Copy the backup controlfile to the current control file and do a
  2040. STARTUP MOUNT.
  2041.  
  2042. 2. Issue ALTER DATABASE BACKUP CONTROLFILE TO
  2043. TRACE NORESETLOGS.
  2044.  
  2045. 3. Issue the CREATE CONTROLFILE...NORESETLOGS com-
  2046. mand from the SQL script output by Step 2.
  2047.  
  2048. It is important to assure that the CREATE CONTROLFILE
  2049. command issued in Step 3 creates a controlfile reflecting a database
  2050. structure equivalent to that of the lost current controlfile. For
  2051. example, if a datafile was added since the backup controlfile was
  2052. saved, then the CREATE CONTROLFILE command should be
  2053. modified to declare the added datafile.
  2054.  
  2055. Failure to specify the BACKUP CONTROLFILE option on the
  2056. RECOVER DATABASE command when the controlfile is indeed a
  2057. backup can frequently be detected. One indication of a restored
  2058. backup controlfile would be a datafile header checkpoint count that
  2059. is greater than the checkpoint count in the datafile's controlfile
  2060. record. However, this test may not catch the backup controlfile if
  2061. the datafiles are also backups. Another test validates the online
  2062. logfile headers against their corresponding controlfile records, but
  2063. this too may not always catch an old controlfile.
  2064.  
  2065. 6.14 CREATE DATAFILE: Recover a Datafile Without a Backup
  2066.  
  2067. If a datafile is lost or damaged and no backup of the file is
  2068. available, it can be recovered using only information in the redo
  2069. logs and control file. The following conditions must be met:
  2070.  
  2071. 1. All redo logs written since the datafile was originally created
  2072. must be available.
  2073.  
  2074. 2. A control file in which the datafile is declared (i.e. name and
  2075. size information) must be available or re-creatable.
  2076.  
  2077. The CREATE DATAFILE clause of the ALTER DATABASE
  2078. command is first used to create a new, empty replacement for the
  2079. lost datafile. RECOVER DATAFILE is then used to apply all redo
  2080. generated for the file from the time of its original creation until the
  2081. time it was lost. After all redo logs written since the datafile was
  2082. originally created have been applied, the file will have been
  2083. restored to its state at the time it was lost. This mechanism is useful
  2084. for recovering a recently-created datafile for which no backup has
  2085. yet been taken. The original datafiles of the SYSTEM tablespace
  2086. cannot be recovered by this means, however, since relevant redo
  2087. data is not saved at database creation time.
  2088.  
  2089. 6.15 Point-in-Time Recovery Using Export/Import
  2090.  
  2091. Occasionally, it may become necessary to reverse the effect of an
  2092. erroneous user action (e.g. table drop or batch run). One approach
  2093. would be to perform an incomplete media recovery to a point-in-
  2094. time before the corruption, then open the database with the
  2095. RESETLOGS option. Using this approach, the entire database -
  2096. not just the affected schema objects - would be set backwards in
  2097. time.
  2098.  
  2099. This approach has an undesirable side-effect: it discards committed
  2100. transactions. Any updates that occurred subsequent to the resetlogs
  2101. SCN are lost and must be re-entered. Resetlogs has another
  2102. undesirable side-effect: it renders all pre-existing backups unusable
  2103. for future recovery.
  2104.  
  2105. Setting a mission-critical database globally back in time is often
  2106. not an acceptable solution. The following procedure is an
  2107. alternative whose effect on the mission-critical database is to set
  2108. just the affected schema objects - termed the recovery-objects -
  2109. backwards in time.
  2110.  
  2111. Point-in-time incomplete media recovery is run against a side-copy
  2112. of the production database, called the recovery-database. The
  2113. initial version of the recovery-database is created using backups of
  2114. the production database that were taken before the corruption
  2115. occurred. Non-relevant objects in the recovery-database can be
  2116. taken offline in order to avoid unnecessarily recovering them.
  2117. However, the SYSTEM tablespace and all tablespaces containing
  2118. rollback segments must participate in the media recovery in order
  2119. to allow a clean open. (Note that this is a good reason to place
  2120. rollback segments and data segments into separate tablespaces.)
  2121.  
  2122. After it has undergone point-in-time incomplete media recovery,
  2123. the recovery-database is opened with the RESETLOGS option.
  2124. The recovery-database is now set backwards to a point-in-time
  2125. before the recovery-objects were corrupted. This effectively
  2126. creates pre-corruption versions of the recovery-objects in the
  2127. recovery-database. These objects can then be exported from the
  2128. recovery-database and imported back into the production database.
  2129. Prior to importing the recovery-objects, the production database is
  2130. prepared as follows:
  2131.  
  2132. 7 In the case of recovering an erroneously updated schema
  2133. object, the copy of the object in the production database is pre-
  2134. pared by discarding just the data; e.g. the table is truncated.
  2135.  
  2136. 7 In the case of recovering an erroneously dropped schema
  2137. object, the object is re-created (empty) in the production data-
  2138. base.
  2139.  
  2140. The import operation is then executed, using the data-only option
  2141. as appropriate. Since export/import can be a lengthy process, it
  2142. may be desirable to postpone it until a time when recovery-object
  2143. unavailability can be tolerated. In the meantime, the recovery-
  2144. objects can be made available, albeit at degraded performance, via
  2145. a database link between the production database and the recovery-
  2146. database.
  2147.  
  2148. An undesirable side-effect of this approach is that transaction
  2149. consistency across objects is lost. This side-effect can be avoided
  2150. by widening the recovery-object set to include all objects that must
  2151. be kept transaction-consistent.
  2152.  
  2153.  
  2154.  
  2155.  
  2156.  
  2157.  
  2158.  
  2159.  
  2160.  
  2161. 7 Block Recovery
  2162.  
  2163. Block recovery is the simplest type of recovery. It is performed
  2164. automatically by the system during normal operation of the
  2165. database, and is transparent to the user.
  2166.  
  2167. 7.1 Block Recovery Initiation and Operation
  2168.  
  2169. Block recovery is used to clean up the state of a buffer whose
  2170. modification by a foreground process (in the middle of invoking a
  2171. redo application callback to apply a change vector to the buffer)
  2172. was interrupted by the foreground process dying or signalling an
  2173. error. Recovery involves (i) reading the block from disk; (ii) using
  2174. the current thread's online redo logs to reconstruct the buffer to a
  2175. state consistent with the redo already generated; and (iii) writing
  2176. the recovered block back to disk. If block recovery fails, then after
  2177. a second attempt, the block is marked logically corrupt (by setting
  2178. the block sequence number to zero) and a corrupt block error is
  2179. signalled.
  2180.  
  2181. Block recovery is guaranteed doable using only the current thread's
  2182. online redo logs, since:
  2183.  
  2184. 1. Block recovery cannot require redo from another thread or
  2185. from before the last thread checkpoint.
  2186.  
  2187. 2. Online logs are not reused until the current thread checkpoint
  2188. is beyond the log.
  2189.  
  2190. 3. No buffer currently in the cache can need recovery from
  2191. before the last thread checkpoint.
  2192.  
  2193. 7.2 Buffer Header RBA Fields
  2194.  
  2195. The buffer header (an in-memory data structure) contains the
  2196. following fields pertaining to block recovery:
  2197.  
  2198. Low-RBA and High-RBA: Delineate the range of redo (from the
  2199. current thread) that needs to be applied to the disk version of the
  2200. block in order make it consistent with redo already generated.
  2201.  
  2202. Recovery-RBA: A place marker for recording progress in case the
  2203. invoker of block recovery is PMON and complete recovery in
  2204. one invocation would take too long (see next section).
  2205.  
  2206. 7.3 PMON vs. Foreground Invocation
  2207.  
  2208. If an error is signalled while a foreground process is in a redo
  2209. application callback, then the process itself executes block
  2210. recovery. If foreground process death is detected during a redo
  2211. application callback, on the other hand, PMON executes block
  2212. recovery.
  2213.  
  2214. Block recovery may require an unbounded amount of time and I/O.
  2215. However, PMON cannot be allowed to spend an inordinate amount
  2216. of time working on the recovery of one block while neglecting
  2217. other necessary time-critical tasks. Therefore, a limit is placed on
  2218. the amount of redo applied by one PMON call to block recovery.
  2219. (A port-specific constant specifies the maximum number of redo
  2220. log blocks applied per invocation). As PMON applies redo during
  2221. invocations of block recovery, it updates the recovery-RBA in the
  2222. buffer header to record its progress. When a PMON call to block
  2223. recovery causes the recovery-RBA to reach the high-RBA, then
  2224. block recovery for that block is complete.
  2225.  
  2226.  
  2227.  
  2228.  
  2229.  
  2230.  
  2231.  
  2232.  
  2233.  
  2234.  
  2235.  
  2236. 8 Resetlogs
  2237.  
  2238. The RESETLOGS option is needed on the first database open
  2239. following:
  2240.  
  2241. 7 Incomplete recovery
  2242.  
  2243. 7 Backup controlfile recovery
  2244.  
  2245. 7 CREATE CONTROLFILE...RESETLOGS.
  2246.  
  2247. The primary function of resetlogs is to discard the redo that was not
  2248. applied during incomplete recovery, ensuring that the skipped redo
  2249. can never be accidentally applied by a subsequent recovery. To
  2250. accomplish this, resetlogs effectively invalidates all existing redo
  2251. in all online and archived redo logfiles. This has the side effect of
  2252. making any existing datafile backups unusable for future recovery
  2253. operations.
  2254.  
  2255. Resetlogs also reinitializes the controlfile information about online
  2256. logs and redo threads, clears the contents of any existing online
  2257. redo log files, creates the online redo log files if they do not
  2258. currently exist, and resets the log sequence number in all threads to
  2259. one.
  2260.  
  2261. 8.1 Fuzzy Files
  2262.  
  2263. The most important requirement when doing a RESETLOGS open
  2264. is that all datafiles be validated as recovered to the same point-in-
  2265. time. This is what ensures that all the changes in a single redo
  2266. record are done atomically. It is also important for other
  2267. consistency reasons. If all threads of redo have been applied
  2268. through end-of-thread to all online datafiles, then we can be sure
  2269. that the database is consistent.
  2270.  
  2271. If incomplete recovery was done, there is the possibility that a file
  2272. was not restored from a sufficiently old backup. In the general case,
  2273. this is detectable if the file has a different checkpoint than the other
  2274. files (exceptions: offline or read-only files).
  2275.  
  2276. The other possibility is that the file is fuzzy - i.e. it may contain
  2277. changes in the future of its checkpoint. As seen earlier, the
  2278. following "fuzzy bits" are maintained in the file header to
  2279. determine if a file is fuzzy:
  2280.  
  2281. 7 online-fuzzy bit (see 3.5, 6.7.2)
  2282.  
  2283. 7 hotbackup-fuzzy bit (see 4, 6.7.3)
  2284.  
  2285. 7 media-recovery-fuzzy bit (see 6.7.1)
  2286.  
  2287. Open with resetlogs following incomplete media recovery will fail
  2288. if any online datafile has any of the three fuzzy bits set.
  2289.  
  2290. Redo records are created at the end of a hot backup (the end-
  2291. backup "marker") and after crash recovery (the end-crash-recovery
  2292. "marker") to enable media recovery to determine when it can clear
  2293. the fuzzy bits. Resetlogs signals an error if any of the datafiles has
  2294. any of the fuzzy bits set.
  2295.  
  2296. Except in the following special circumstances, resetlogs signals an
  2297. error if any of the datafiles is recovered to a checkpoint SCN
  2298. different from the one at which the other files are checkpointed (i.e.
  2299. the resetlogs SCN: see 8.2):
  2300.  
  2301. 1. A file recovered to an SCN earlier than the resetlogs SCN
  2302. would be tolerated in case there were no redo generated for the
  2303. file between its checkpoint SCN and the resetlogs SCN. For
  2304. example, such would be the case if the file were read-only, and
  2305. its offline range spanned the checkpoint SCN and resetlogs
  2306. SCN. In this case, resetlogs would allow the file but set it
  2307. offline.
  2308.  
  2309. 2. A file checkpointed at an SCN later than the resetlogs SCN
  2310. would be tolerated in case its creation SCN (allocated at file
  2311. creation time and stored in the file header) showed it to have
  2312. been created after the resetlogs SCN. During the data dictio-
  2313. nary vs. controlfile check performed by RESETLOGS open
  2314. (see 8.7), such a file would be found to be missing from the
  2315. data dictionary but present in the controlfile. As a conse-
  2316. quence, it would be eliminated from the controlfile.
  2317.  
  2318. 8.2 Resetlogs SCN and Counter
  2319.  
  2320. A resetlogs SCN and resetlogs timestamp - known together as the
  2321. resetlogs data - are kept in the database info record of the
  2322. controlfile. The resetlogs data is intended to uniquely identify each
  2323. execution of a RESETLOGS open. The resetlogs data is also stored
  2324. in each datafile header and in each logfile header. A redo log cannot
  2325. be applied by recovery if its resetlogs data does not match that in
  2326. the database info record of the controlfile. Except for some very
  2327. special circumstances (e.g. offline normal or read-only
  2328. tablespaces), a datafile cannot be recovered or accessed if its
  2329. resetlogs data does not match that of the database info record of the
  2330. controlfile. This ensures that changes discarded by resetlogs do not
  2331. get back into the database. It also renders previous backups
  2332. unusable for future recovery operations, making it prudent to take a
  2333. database backup immediately after a resetlogs.
  2334.  
  2335. 8.3 Effect of Resetlogs on Threads
  2336.  
  2337. Each thread's controlfile record is updated to clear the thread-open
  2338. flag and to set the thread-checkpoint SCN to the resetlogs SCN.
  2339. Thus, the thread appears to have been closed at the resetlogs SCN.
  2340. The set of enabled threads from the enabled thread bitvec of the
  2341. database info controlfile record is used as is. It does not matter
  2342. which threads were enabled at the end of recovery, since none of
  2343. the old redo can ever be applied to the database again. The log
  2344. sequence numbers in all threads are also reset to one. One of the
  2345. enabled threads is picked as the database checkpoint.
  2346.  
  2347. 8.4 Effect of Resetlogs on Redo Logs
  2348.  
  2349. The redo is thrown away by zeroing all the online logs. Note that
  2350. this means that redo in the online logs would be lost forever - and
  2351. there would be no way to undo the resetlogs in an emergency - if
  2352. the online logs were not backed up prior to executing resetlogs.
  2353. Note that ensuring the ability to undo an erroneous resetlogs is the
  2354. only valid rationale for making backups of online logs. Undoing an
  2355. erroneous resetlogs requires re-running the entire recovery
  2356. operation from the beginning, after restoring backups of all
  2357. datafiles, controlfile, and online logs.
  2358.  
  2359. One log is picked to be the current log for every enabled thread.
  2360. That log header is written as log sequence number one. Note that
  2361. the set of logs and their thread association is picked up from the
  2362. controlfile (i.e. using the thread number and log list fields of the
  2363. logfile records). If it is a backup controlfile, this may be different
  2364. from what was current the last time the database was open.
  2365.  
  2366. 8.5 Effect of Resetlogs on Online Datafiles
  2367.  
  2368. The headers of all the online datafiles are updated to be
  2369. checkpointed at the new database checkpoint. The new resetlogs
  2370. data is also written to the header.
  2371.  
  2372. 8.6 Effect of Resetlogs on Offline Datafiles
  2373.  
  2374. The controlfile record for an offline file is set to indicate the file
  2375. needs media recovery. However that will not be possible because it
  2376. would be necessary to apply redo from logs with the wrong
  2377. resetlogs data. This means that the tablespace containing the file
  2378. will have to be dropped. There is one important exception to this
  2379. rule. When a tablespace is taken offline normal or set read-only, the
  2380. checkpoint SCN written to the headers of the tablespace's
  2381. constituent datafiles is saved in the data dictionary TS$ table as the
  2382. tablespace-clean-stop SCN (see 2.17). No recovery is ever needed
  2383. to bring a tablespace and its files online if the files are not fuzzy
  2384. and are checkpointed at exactly the tablespace-clean-stop SCN.
  2385. Even the resetlogs data in the offline file header is ignored in this
  2386. case. Thus a tablespace that is offline normal is unaffected by any
  2387. resetlogs that leaves the database at a time when the tablespace is
  2388. offline.
  2389.  
  2390. 8.7 Checking Dictionary vs. Controlfile on Resetlogs Open
  2391.  
  2392. After the rollback phase of RESETLOGS open, the datafiles listed
  2393. in the data dictionary FILE$ table are compared with the datafiles
  2394. listed in the controlfile. This is also done on the first open after a
  2395. CREATE CONTROLFILE. There is the possibility that incomplete
  2396. recovery ended at a time when the files in the database were
  2397. different from those in the controlfile used for the recovery. Using a
  2398. backup controlfile or creating one can have the same problem.
  2399. Checking the dictionary does not do any harm, so it could be done
  2400. on every database open; however there is no point in wasting the
  2401. time under normal circumstances.
  2402.  
  2403. The entry in FILE$ is compared with the entry in the controlfile
  2404. for every file number. Since FILE$ reflects the space allocation
  2405. information in the database, it is correct, and the controlfile might
  2406. be wrong. If the file does not exist in FILE$ but the controlfile
  2407. record says the file exists, then the file is simply dropped from the
  2408. controlfile.
  2409.  
  2410. If a file exists in FILE$ but not in the controlfile, a placeholder
  2411. entry is created in the control file under the name MISSINGnnnn
  2412. (where nnnn is the file number in decimal). MISSINGnnnn is
  2413. flagged in the control file as being offline and needing media
  2414. recovery. The actual file corresponding (with respect to the file
  2415. header contents as opposed to the file name) to MISSINGnnnn can
  2416. be made accessible by renaming MISSINGnnnn to point to it.
  2417.  
  2418. In the RESETLOGS open case however, rename can succeed in
  2419. making the file usable only in case the file was read-only or offline
  2420. normal. If, on the other hand, MISSINGnnnn corresponds to a file
  2421. that was not read-only or offline normal, then the rename operation
  2422. cannot be used to make it accessible, since bringing it online would
  2423. require media recovery with redo from before the resetlogs. In this
  2424. case, the tablespace containing the datafile must be dropped.
  2425.  
  2426. When the dictionary check is due to open after CREATE
  2427. CONTROLFILE...NORESETLOGS rather than to open resetlogs,
  2428. media recovery may be used to make the file current.
  2429.  
  2430. Another option is to repeat the entire operation that lead up to the
  2431. dictionary check with a controlfile that lists the same datafiles as
  2432. the data dictionary. For incomplete recovery, this would involve
  2433. restoring all backups and repeating the recovery.
  2434.  
  2435.  
  2436.  
  2437.  
  2438.  
  2439.  
  2440.  
  2441.  
  2442.  
  2443. 9 Recovery-Related V$ Fixed-Views
  2444.  
  2445. The V$ fixed-views contain columns that extract information from
  2446. data structures dynamically maintained in memory by the kernel.
  2447. These "views" make this information accessible to the DBA under
  2448. SYS. The following is a summary of recovery-related information
  2449. that is viewable via V$ views:
  2450.  
  2451. 9.1 V$LOG
  2452.  
  2453. Contains log group information from the controlfile:
  2454.  
  2455. GROUP#
  2456.  
  2457. THREAD#
  2458.  
  2459. SEQUENCE#
  2460.  
  2461. SIZE_IN_BYTES
  2462.  
  2463. MEMBERS_IN_GROUP
  2464.  
  2465. ARCHIVED_FLAG
  2466.  
  2467. STATUS_OF_ GROUP (unused, current, active, inactive)
  2468.  
  2469. LOW_SCN
  2470.  
  2471. LOW_SCN_TIME
  2472.  
  2473. 9.2 V$LOGFILE
  2474.  
  2475. Contains log file (i.e. group member) information from the
  2476. controlfile:
  2477.  
  2478. GROUP#
  2479.  
  2480. STATUS_OF_MEMBER (invalid, stale, deleted)
  2481.  
  2482. NAME_OF_MEMBER
  2483.  
  2484. 9.3 V$LOG_HISTORY
  2485.  
  2486. Contains log history information from the controlfile:
  2487.  
  2488. THREAD#
  2489.  
  2490. SEQUENCE#
  2491.  
  2492. LOW_SCN
  2493.  
  2494. LOW_SCN_TIME
  2495.  
  2496. NEXT_SCN
  2497.  
  2498. 9.4 V$RECOVERY_LOG
  2499.  
  2500. Contains information (from the controlfile log history) about
  2501. archived logs needed to complete media recovery.:
  2502.  
  2503. THREAD#
  2504.  
  2505. SEQUENCE#
  2506.  
  2507. LOW_SCN_TIME
  2508.  
  2509. ARCHIVED_NAME
  2510.  
  2511. 9.5 V$RECOVER_FILE
  2512.  
  2513. Contains information on the status of files needing media recovery:
  2514.  
  2515. FILE#
  2516.  
  2517. ONLINE_FLAG
  2518.  
  2519. REASON_MEDIA_RECOVERY_NEEDED
  2520.  
  2521. RECOVERY_START_SCN
  2522.  
  2523. RECOVERY_START_SCN_TIME
  2524.  
  2525. 9.6 V$BACKUP
  2526.  
  2527. Contains status information relative to datafiles in hot backup:
  2528.  
  2529. FILE#
  2530.  
  2531. FILE_STATUS (no-backup-active, backup-active, offline-normal,
  2532. error)
  2533.  
  2534. BEGIN_BACKUP_SCN
  2535.  
  2536. BEGIN_BACKUP_TIME
  2537.  
  2538.  
  2539.  
  2540.  
  2541.  
  2542.  
  2543.  
  2544.  
  2545.  
  2546. 10 Miscellaneous Recovery Features
  2547.  
  2548. 10.1 Parallel Recovery (v7.1)
  2549.  
  2550. The goal of the parallel recovery feature is to use compute and I/O
  2551. parallelism to reduce the elapsed time required to perform crash
  2552. recovery, single-instance recovery, or media recovery. Parallel
  2553. recovery is most effective at reducing recovery time when several
  2554. datafiles on several disks are being recovered concurrently.
  2555.  
  2556. 10.1.1 Parallel Recovery Architecture
  2557.  
  2558. Parallel recovery partitions recovery processing into two
  2559. operations:
  2560.  
  2561. 1. Reading the redo log.
  2562.  
  2563. 2. Applying the change vectors.
  2564.  
  2565. Operation #1 does not easily lend itself to parallelization. The redo
  2566. log(s) must be read in sequentially, and merged in the case of
  2567. media recover. Thus, this task is assigned to one process: the
  2568. redo-reading-process.
  2569.  
  2570. Operation #2, on the other hand, easily lends itself to
  2571. parallelization. Thus, the task of change vector application is
  2572. delegated to some number of redo-application-slave-processes.
  2573. The redo-reading-process sends change vectors to the redo-
  2574. application-slave-processes using the same IPC (inter-process-
  2575. communication) mechanism used by parallel query. The change
  2576. vectors are distributed based on the hash function that takes the
  2577. block address as argument (i.e. DBA modulo # redo-application-
  2578. slave-processes). Thus, each redo-application-slave-process
  2579. handles only change vectors for blocks whose DBAs hash to its
  2580. "bucket" number. The redo-application-slave-processes are
  2581. responsible for reading the datablocks into cache, checking
  2582. whether or not the change vectors need to be applied, and applying
  2583. the change vectors if needed.
  2584.  
  2585. This architecture achieves parallelism in log read I/O, datablock
  2586. read I/O, and change vector processing. It allows overlap of log
  2587. read I/Os with datablock read I/Os. Moreover, it allows overlap of
  2588. datablock read I/Os for different hash "buckets." Recovery elapsed
  2589. time is reduced as long as the benefits of compute and I/O
  2590. parallelism outweigh the costs of process management and inter-
  2591. process-communication.
  2592.  
  2593. 10.1.2 Parallel Recovery System Initialization Parameters
  2594.  
  2595. PARALLEL_RECOVERY_MAX_THREADS
  2596.  
  2597. PARALLEL_RECOVERY_MIN_THREADS
  2598. These initialization parameters control the number of redo-
  2599. application-slave-processes used during crash recovery or
  2600. media recovery of all datafiles.
  2601.  
  2602. PARALLEL_INSTANCE_RECOVERY_THREADS
  2603. This initialization parameter controls the number of redo-appli-
  2604. cation-slave-processes used during instance recovery.
  2605.  
  2606. 10.1.3 Media Recovery Command Syntax Changes
  2607.  
  2608. RECOVER DATABASE has a new optional parameter for specify-
  2609. ing the number of redo-application-slave-processes. If specified,
  2610. it overrides PARALLEL_RECOVERY_MAX_THREADS.
  2611.  
  2612. RECOVER TABLESPACE has a new optional parameter for spec-
  2613. ifying the number of redo-application-slave-processes. If speci-
  2614. fied, it overrides PARALLEL_RECOVERY_MIN_THREADS.
  2615.  
  2616. RECOVER DATAFILE has a new optional parameter for specify-
  2617. ing the number of redo-application-slave-processes. If specified,
  2618. it overrides PARALLEL_RECOVERY_MIN_THREADS.
  2619.  
  2620. 10.2 Redo Log Checksums (v7.2)
  2621.  
  2622. The log checksum feature allows a potential corruption in an online
  2623. redo log to be detected when the log is read for archiving. The goal
  2624. is to prevent the corruption from being propagated, undetected, to
  2625. the archive log copy. This feature is intended to be used in
  2626. conjunction with a new command, CLEAR LOGFILE, that allows
  2627. a corrupted online redo log to be discarded without having to
  2628. archive it.
  2629.  
  2630. A new initialization parameter, LOG_BLOCK_CHECKSUM,
  2631. controls activation of log checksums. If it is set, a log block
  2632. checksum is computed and placed in the header of each log block
  2633. as it is written out of the redo log buffer. If present, checksums are
  2634. validated whenever log blocks are read for archiving or recovery. If
  2635. a checksum is detected as invalid, an attempt is made to read
  2636. another member of the log group (if any). If an irrecoverable
  2637. checksum error is detected - i.e. the checksum is invalid in all
  2638. members - then the log read operation fails.
  2639.  
  2640. Note that a rudimentary mechanism for detecting log block header
  2641. corruption was added, along with log group support, in v7.1. The
  2642. log checksum feature extends corruption detection to the whole
  2643. block.
  2644.  
  2645. If an irrecoverable checksum error prevents a log from being read
  2646. for archiving, then the log cannot be reused. Eventually log switch
  2647. - and redo generation - will stall. If no action is taken, the
  2648. database will hang. The CLEAR LOGFILE command provides a
  2649. way to obviate the requirement that the log be archived before it
  2650. can be reused.
  2651.  
  2652. 10.3 Clear Logfile (v7.2)
  2653.  
  2654. If all members of an online redo log group are "lost" or "corrupted"
  2655. (e.g. due to checksum error, media error, etc.), redo generation may
  2656. proceed normally until it becomes necessary to reuse the logfile.
  2657. Once the thread checkpoints of all threads are beyond the log, it is a
  2658. potential candidate for reuse. Possible scenarios preventing reuse
  2659. are the following:
  2660.  
  2661. 1. The log cannot be archived due to a checksum error; it cannot
  2662. be reused because it needs archiving.
  2663.  
  2664. 2. A log switch attempt fails because the log is inaccessible (e.g.
  2665. due to a media error). The log may or may not have been
  2666. archived.
  2667.  
  2668. The ALTER DATABASE CLEAR LOGFILE command is
  2669. provided as an aid to recovering from such scenarios involving an
  2670. inactive online redo log group (i.e. one that is not needed for crash
  2671. recovery). CLEAR LOGFILE allows an inactive online logfile to
  2672. be "cleared": i.e. discarded and reinitialized, in a manner analogous
  2673. to DROP LOGFILE followed by ADD LOGFILE. In many cases,
  2674. use of this command obviates the need for database shutdown or
  2675. resetlogs.
  2676.  
  2677. Note: CLEAR LOGFILE cannot be used to clear a log needed for
  2678. crash recovery (i.e. a "current" or "active" log of an open thread).
  2679. Instead, if such a log becomes lost or corrupted, shutdown abort
  2680. followed by incomplete recovery and open resetlogs will be
  2681. necessary.
  2682.  
  2683. Use of the UNARCHIVED option allows the log clear operation to
  2684. proceed even if the log needs archiving: an operation that would be
  2685. disallowed by DROP LOGFILE. Furthermore, CLEAR LOGFILE
  2686. allows the log clear operation to proceed in the following cases:
  2687.  
  2688. 7 There are only two logfile groups in the thread.
  2689.  
  2690. 7 All log group members have been lost through media failure.
  2691.  
  2692. 7 The logfile being cleared is the current log of a closed thread.
  2693.  
  2694. All of these operations would be disallowed in the case of DROP
  2695. LOGFILE.
  2696.  
  2697. Clearing an unarchived log makes unusable any existing backup
  2698. whose recovery would require applying redo from the cleared log.
  2699. Therefore, it is recommended that the database be immediately
  2700. backed up following use of CLEAR LOGFILE with the
  2701. UNARCHIVED option. Furthermore, the UNRECOVERABLE
  2702. DATAFILE option must be used if there is a datafile that is offline,
  2703. and whose recovery prior to onlining requires application of redo
  2704. from the cleared logfile. Following use of CLEAR LOGFILE with
  2705. the UNRECOVERABLE DATAFILE option, the offline datafile,
  2706. together with its entire tablespace, will have to be dropped from the
  2707. database. This is due to the fact that redo necessary to bring it
  2708. online has been cleared, and there is no other copy of it.
  2709.  
  2710. The foreground process executing CLEAR LOGFILE processes
  2711. the command in several steps:
  2712.  
  2713. 7 It checks that the logfile is not needed for crash recovery and
  2714. is clearable.
  2715.  
  2716. 7 It sets the "being cleared" and "archiving not needed" flags in
  2717. the logfile controlfile record. While the "being cleared" flag is
  2718. set, the logfile is ineligible for reuse by log switch.
  2719.  
  2720. 7 It recreates a new logfile, and performs multiple writes to clear
  2721. it to zeroes (a lengthy process).
  2722.  
  2723. 7 It resets the "being cleared" flag.
  2724.  
  2725. If the foreground process executing CLEAR LOGFILE dies while
  2726. execution is in process, the log will not be usable as the current log.
  2727. Redo generation may stall and the database may hang, much as
  2728. would happen if log switch had to wait for checkpoint completion,
  2729. or for log archive completion. Should the process executing
  2730. CLEAR LOGFILE die, the operation should be completed by
  2731. reissuing the same command. Another option would be to drop the
  2732. partially-cleared log. CLEAR LOGFILE could also fail due to an I/
  2733. O error encountered while writing zeros to a log group member. An
  2734. option for recovering would be to drop that member and add
  2735. another to replace it.
Add Comment
Please, Sign In to add comment