| Lesson 6 | Performing time-based recovery |
| Objective | Select a justified time target and explain how to restore and recover a whole CDB to that target with RMAN, while recognizing narrower recovery alternatives. |
At 12:10 PM on 18-JAN-2025, a developer reports that the CUSTOMERS table was accidentally dropped at approximately 12:01 PM. The application needs the table back. You consider noon as a possible recovery target because it appears to precede the unwanted operation.
Your first task is to establish what happened and which recovery scope is appropriate. Identify the owning schema and PDB, confirm the operation and its timing, and investigate whether the table can be recovered without rewinding the whole CDB. A report of a dropped table does not automatically justify database point-in-time recovery.
The dates in this lesson are fixed illustrative values. In an actual incident, use the verified event time and confirm that the available backups and recovery history cover the chosen target. A valid command format does not guarantee that a particular historical date is recoverable.
For an eligible dropped table that remains in the recycle bin, Flashback Drop may provide a direct remedy. If that option is unavailable or unsuitable, consider RMAN table recovery or another supported scoped procedure. The choice depends on the object, available history, and the complete recovery requirement.
Flashback Table and Flashback Drop address different situations. A normal ROLLBACK does not undo a committed DROP TABLE, and truncating a table is not the same incident as dropping it. Establish the actual operation before choosing a remedy merely because its name contains the word flashback.
Teaching assumption: For the following example, the recovery team has evaluated targeted remedies and determined that they do not meet the scenario's requirements. Application owners have accepted whole-CDB recovery to noon, after verifying that this target precedes the unwanted change and is supported by the available recovery material.
This decision affects other PDBs and valid transactions within the CDB. Do not assume that lunch means little work occurred: scheduled jobs, integrations, and other applications may still be active. Determine what later work will be excluded and how it will be reconciled.
Time-based recovery expresses the endpoint using a clock time. In this scenario, the proposed target is 12:00:00 PM on 18-JAN-2025. Compare the developer's report with available application records, audit evidence, and appropriate log analysis. The report describes an approximate event time, so noon must be justified rather than accepted without investigation.
Distinguish when an operation began, when its effects committed, and when someone noticed the problem. A reported failure time can describe any of these. If related harmful changes occurred before noon, the proposed target would be too late even though it preceded the reported table drop.
Oracle documents RMAN UNTIL TIME as an upper, noninclusive limit. Recovery nevertheless depends on time information recorded in redo, so a timestamp is not a guarantee of arbitrary subsecond precision. Verify the resulting state. If an exact change boundary is available, SCN-based recovery may express it more directly.
The RMAN example uses an explicit TO_DATE format mask. This avoids dependence on NLS_DATE_FORMAT but does not identify a time zone. Reconcile application timestamps with the database recovery context before deciding what noon means. Use a fixed target for reproducibility; a relative expression changes meaning when the procedure is retried later.
Querying CURRENT_SCN after the incident does not identify the historical DROP. Likewise, redo-history views identify intervals rather than automatically locating one SQL statement. SCN/time mappings have availability and precision limits. Use them with appropriate evidence, not as a substitute for incident analysis.
The main procedure assumes a CDB in ARCHIVELOG mode, a current control file and SPFILE, and a target within the current incarnation. Data file backups and the required recovery history must support the selected endpoint. Access to backup storage, RMAN channels, and any necessary decryption keys or passwords must be established.
Connect RMAN to CDB$ROOT as an appropriately privileged common user, such as one with SYSBACKUP or SYSDBA. The root connection administers recovery of the whole CDB. It does not permit independent point-in-time recovery of only the root while leaving its PDBs at unrelated states.
A lost control file or SPFILE, an ancestor-incarnation target, and RAC or Data Guard coordination require additional procedures. Do not insert a generic RESTORE CONTROLFILE command into this example without addressing backup discovery and startup requirements. The later control-file lesson treats that recovery context separately.
Preserve useful current-state material and incident evidence where feasible. A fresh closed database backup is not a universal prerequisite and does not replace the earlier backups needed for noon. Stop application access before restoration and prevent automatic jobs or client reconnections from resuming writes during verification.
The following example assumes an initially open CDB that can shut down normally. If it is already mounted, omit the shutdown and startup commands. The target is the verified noon boundary for the scenario, not a value to reuse indiscriminately in another database.
SHUTDOWN IMMEDIATE;
STARTUP MOUNT;
RUN {
SET UNTIL TIME "TO_DATE('2025-01-18 12:00:00', 'YYYY-MM-DD HH24:MI:SS')";
RESTORE DATABASE;
RECOVER DATABASE;
}
ALTER DATABASE OPEN RESETLOGS;
Treat this as a supervised recovery sequence. Resolve any restore or recovery error before proceeding to RESETLOGS. The final open command does not bypass missing redo, incompatible files, or incomplete restoration.
STARTUP MOUNT starts the instance and mounts the database using the control file without opening it for normal application access. In this RMAN workflow, mounting precedes RESTORE DATABASE. Describing MOUNT as an open mode obscures this distinction.
Confirm the target environment before overwriting data files. An operating-system directory listing or file modification time is not a recoverability test. Backup suitability depends on database metadata, file state, target requirements, and available recovery history.
SET UNTIL TIME appears before both RESTORE and RECOVER in the same RUN block. This ensures that RMAN selects data file backups compatible with the endpoint and applies recovery information under that same target. Setting the target only after restoration can leave files that are too recent.
RMAN selects suitable backups under the target and other criteria. These need not be the newest backups overall or all belong to one backup set. A newer backup containing changes beyond noon cannot be rolled backward to noon by ordinary forward media recovery.
RESTORE DATABASE retrieves the data files that provide the starting state. RECOVER DATABASE then applies the required incremental changes and redo to reach the selected endpoint. Restoring a backup does not necessarily make its files consistent or place the database at the requested time.
If RMAN needs archived logs that are available in backup, it can restore them using suitable channels. A required gap cannot simply be skipped. Investigate alternate copies, storage access, and viable recovery paths before changing the intended target.
After successful whole-CDB incomplete recovery, OPEN RESETLOGS establishes a new database incarnation and restarts redo sequencing. It does not reset database SCNs or DBID to 1. Oracle's recovery consistency requirements must already be satisfied.
Opening the CDB does not automatically open its PDBs. In a separate SQL*Plus session connected to the root, the following opens all applicable PDBs when that matches the operating plan:
ALTER PLUGGABLE DATABASE ALL OPEN;
Otherwise, open the intended PDBs individually. Keep application access controlled until the recovered state has been checked. Opening containers is a technical milestone, while deciding that service can resume requires application verification.
The recovery may need working space for archived logs restored from backup. This is a different task from configuring where Oracle generates new archived logs during normal operation. RMAN can stage restored logs in a selected server-side directory.
If needed, add this setting inside the same RUN block before RECOVER:
SET ARCHIVELOG DESTINATION TO '/u02/recovery_arch';
The path is a Linux/Unix-style illustration. Use a real directory on the database server with suitable access and capacity. RMAN knows where it restored the archives and can use available logs already on disk. There is no general requirement to manually restore every archive before starting recovery.
Do not change persistent production archiving settings solely to tell RMAN where to stage these files. The historical ARCHIVE LOG START TO approach is not the recovery-location mechanism used here. Windows environments should use their actual server-side paths rather than copying the sample directory.
SQL*Plus user-managed media recovery remains documented, but it has separate restore preparation and command syntax. The following is an alternative workflow after suitable user-managed data file restoration and mounting. It is not an additional command to execute after the RMAN sequence.
RECOVER DATABASE UNTIL TIME '2025-01-18:12:00:00'
The SQL*Plus form uses a colon between the date and time and a 24-hour time representation. It differs from the RMAN TO_DATE expression. AUTO at the recovery prompt, or the AUTOMATIC keyword, can automate supplying expected archived-log filenames.
When restored archives are in another directory, this single SQL*Plus command specifies that location:
RECOVER AUTOMATIC FROM '/u02/recovery_arch' DATABASE UNTIL TIME '2025-01-18:12:00:00'
Automatic application does not create missing redo or confirm that noon is the correct business endpoint. The files must still be recoverable to a consistent state. Use RESETLOGS as one keyword when following the appropriate reopening procedure; do not test recovery by deliberately trying to open an insufficiently recovered database.
Use the monitoring methods from Lesson 5: preserve RMAN output, correlate it with the correct instance's alert log, and inspect relevant progress measurements from a separate session. A completed recovery phase and an open database are different observations.
Where the recovered state permits it, optional read-only inspection can help assess the data before committing to RESETLOGS. This cannot bypass unresolved media recovery. Return to mounted state before continuing recovery or performing the final RESETLOGS open.
After reopening, inspect the intended CDB and PDB states from SQL*Plus connected to the root:
SELECT name, open_mode FROM v$database;
SELECT name, open_mode FROM v$pdbs ORDER BY con_id;
Then connect to the PDB owning CUSTOMERS and validate the application data. A matching table name in another PDB is not evidence that the affected application was recovered. Use the correct owner and container when comparing results with the recovery requirements.
| Check | Evidence to compare |
|---|---|
| Object identity | The intended CUSTOMERS table exists under the correct owner in the correct PDB. |
| Representative rows | Known customer keys and important attributes match the expected earlier state. |
| Relationships | Related orders and other application data agree with the recovered customers. |
| Later work | Valid changes excluded by the noon target are identified for reconciliation. |
Object existence or a row count alone is insufficient. A table can exist and still contain the wrong business state. Agree on representative validation evidence before recovery so that the reopening decision is based on something more than the absence of Oracle errors.
RESETLOGS_TIME records when RESETLOGS occurred, which can be later than the noon recovery target. It is not proof that the database was recovered to noon. RESETLOGS_CHANGE# describes the incarnation transition and must also be interpreted with the recovery context.
Establish the result using the configured target, recovery output, relevant diagnostic records, and application checks. Redo sequence numbering restarts during RESETLOGS, but subsequent log switches may already have occurred by the time you inspect it. Observing a sequence other than 1 does not alone invalidate the recovery.
If the endpoint was too early and RESETLOGS has not established the new branch, further available redo may permit advancement. If too much redo was applied, a restore-based retry generally requires restoring suitable backups again. After RESETLOGS, further recovery planning must account for incarnation history.
Old-branch redo cannot simply be appended to the new branch, but earlier backups and recovery material are not automatically invalidated. Preserve them according to retention requirements. Avoid an absolute claim that recovery can never reach a later state after RESETLOGS; the available procedures depend on the preserved history and intended result.
A fresh whole-database backup after RESETLOGS is optional in Oracle 26ai. It may provide a useful new baseline under the backup policy, and an RMAN backup in ARCHIVELOG mode does not inherently require another shutdown. In Data Guard environments, assess the documented options for the standby to follow the recovered primary rather than automatically rebuilding every standby.
The main example recovers the whole CDB, but supported PDB PITR, TSPITR, and RMAN table recovery provide narrower workflows. They have their own prerequisites and consistency rules. Independently rewinding arbitrary data files is not equivalent to performing one of those supported scoped operations.
Flashback Database can avoid restoring data files when usable flashback history and required redo support the endpoint. DB_FLASHBACK_RETENTION_TARGET expresses a retention objective, not proof that every requested time remains reachable. A suitable guaranteed restore point has separate semantics and storage requirements.
Time-based and SCN-based targets are ways of identifying endpoints; SCN-based and change-based refer to the same underlying target concept. Recovery scope and the condition of the control file are separate decisions. Understanding those distinctions helps you choose the next procedure without relying on the legacy idea of four exclusive recovery flavors.
Recovering to noon excludes later valid commits within the selected scope along with the unwanted changes. Identify those transactions from authoritative records. Do not assume that all work can safely be repeated just because it is absent from the recovered database.
Payments may already have settled, messages may already have been consumed, and remote applications may retain later records. Verify these external effects before replaying orders or updates. Coordinate the sequence of reconciliation and reopening with the application owners.
Normal distributed transaction coordination does not automatically rewind independent databases after one CDB undergoes PITR. SCNs order database change history; they are not globally unique transaction identifiers or a guarantee that entering the same timestamp everywhere restores business consistency.
Complete the incident by recording the selected target, achieved recovery result, validation evidence, and outstanding reconciliation work. The developer's table is only one part of the acceptance decision when the chosen procedure has affected the whole CDB.
The next lesson shows how to perform a cancel-based recovery.