Recovering a database further then the last backupped controlfile

A question on forums.oracle.com asked: can we recover a database further in time then the time of backup of the last controlfile. Nice question…my gut feeling immediately says : YES we can. But…I do not have a proof of it, and one quick search on the internet did not supply a adequate answer. So…then I have to demonstrate it myself.

Plan of attack:

  1. Preparation
    1. Create backup
      1. datafiles
      2. archives
      3. control- and spfile autobackup
    2. Create some more archives
      1. these archives are not known to the allready backedup controlfile (step 1.1.3)
      2. These archives are still on disk. They are not in the backup. (If they would be in a backup you could easily restore them :-))
      3. Check which sequence is the last sequence generated
  2. Restore/recover
    1. get the old controlfile back
      1. startup noumount
      2. restore controlefile from backupfile
    2. restart the database in mount mode
      1. restore the database
    3. Recover the database until the last generated archivelog
    4. alter database open resetlog

Let’s see how that works:

Preparation: Backing up the database

RMAN> backup database plus archivelog delete input;

Starting backup at 2024/04/04 13:13:49
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=4 RECID=3 STAMP=1165410707
...
...
input archived log thread=1 sequence=15 RECID=14 STAMP=1165410739
input archived log thread=1 sequence=16 RECID=15 STAMP=1165410832
channel ORA_DISK_1: starting piece 1 at 2024/04/04 13:13:52
channel ORA_DISK_1: finished piece 1 at 2024/04/04 13:13:53
piece handle=/u04/bloemkool.bos/backup/072ndggg_7_1_1 tag=TAG20240404T131352 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u03/LIES/archivelog/1_4_1165409047.dbf RECID=3 STAMP=1165410707
archived log file name=/u03/LIES/archivelog/1_5_1165409047.dbf RECID=4 STAMP=1165410708
...
...
archived log file name=/u03/LIES/archivelog/1_15_1165409047.dbf RECID=14 STAMP=1165410739
archived log file name=/u03/LIES/archivelog/1_16_1165409047.dbf RECID=15 STAMP=1165410832
Finished backup at 2024/04/04 13:13:53

Starting backup at 2024/04/04 13:13:53
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u02/oradata/LIES/datafile/o1_mf_system_m0x0zlqp_.dbf
...
...
input datafile file number=00007 name=/u02/oradata/LIES/datafile/o1_mf_users_m0x10vyd_.dbf
channel ORA_DISK_1: starting piece 1 at 2024/04/04 13:13:53
channel ORA_DISK_1: finished piece 1 at 2024/04/04 13:16:38
piece handle=/u04/bloemkool.bos/backup/082ndggh_8_1_1 tag=TAG20240404T131353 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:45
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00010 name=/u02/oradata/LIES/154444752F0C4E6CE0630203A8C0091D/datafile/o1_mf_sysaux_m0x253w6_.dbf
...
...
input datafile file number=00012 name=/u02/oradata/LIES/154444752F0C4E6CE0630203A8C0091D/datafile/o1_mf_users_m0x25qqk_.dbf
channel ORA_DISK_1: starting piece 1 at 2024/04/04 13:16:38
channel ORA_DISK_1: finished piece 1 at 2024/04/04 13:17:33
piece handle=/u04/bloemkool.bos/backup/092ndglm_9_1_1 tag=TAG20240404T131353 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00006 name=/u02/oradata/LIES/datafile/o1_mf_sysaux_m0x17jvv_.dbf
input datafile file number=00005 name=/u02/oradata/LIES/datafile/o1_mf_system_m0x17jvq_.dbf
input datafile file number=00008 name=/u02/oradata/LIES/datafile/o1_mf_undotbs1_m0x17jvx_.dbf
channel ORA_DISK_1: starting piece 1 at 2024/04/04 13:17:33
channel ORA_DISK_1: finished piece 1 at 2024/04/04 13:18:28
piece handle=/u04/bloemkool.bos/backup/0a2ndgnd_10_1_1 tag=TAG20240404T131353 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55
Finished backup at 2024/04/04 13:18:28

Starting backup at 2024/04/04 13:18:28
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=17 RECID=16 STAMP=1165411109
channel ORA_DISK_1: starting piece 1 at 2024/04/04 13:18:29
channel ORA_DISK_1: finished piece 1 at 2024/04/04 13:18:30
piece handle=/u04/bloemkool.bos/backup/0b2ndgp5_11_1_1 tag=TAG20240404T131829 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u03/LIES/archivelog/1_17_1165409047.dbf RECID=16 STAMP=1165411109
Finished backup at 2024/04/04 13:18:30

Starting Control File and SPFILE Autobackup at 2024/04/04 13:18:30
piece handle=/u04/bloemkool.bos/backup/c-2295896278-20240404-01 comment=NONE
Finished Control File and SPFILE Autobackup at 2024/04/04 13:18:33

RMAN>

Create some more  archivelogs (wich will not be backed up)

RMAN> alter system switch logfile;

Statement processed

RMAN> alter system switch logfile;

Statement processed

RMAN> alter system switch logfile;

Statement processed

RMAN>

Check which archivelogs are not backupped

RMAN> list archivelog all;

List of Archived Log Copies for database with db_unique_name LIES
=====================================================================

Key Thrd Seq S Low Time
------- ---- ------- - -------------------
17 1 18 A 2024/04/04 13:18:28
Name: /u03/LIES/archivelog/1_18_1165409047.dbf

...
...

29 1 30 A 2024/04/04 13:28:23
Name: /u03/LIES/archivelog/1_30_1165409047.dbf

RMAN>

As you can see : tha last created archivelog (which is still on disk) is sequence 30.

Restore the (old) Controlfile

RMAN> shutdown immediate;

database closed
database dismounted
Oracle instance shut down

RMAN> startup nomount;

connected to target database (not started)
Oracle instance started

Total System Global Area 3221225344 bytes

Fixed Size 9691008 bytes
Variable Size 654311424 bytes
Database Buffers 2550136832 bytes
Redo Buffers 7086080 bytes

RMAN> restore controlfile from '/u04/bloemkool.bos/backup/c-2295896278-20240404-01';

Starting restore at 2024/04/04 13:33:49
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=28 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
output file name=/u03/LIES/controlfile/o1_mf_m0wy0s3s_.ctl
Finished restore at 2024/04/04 13:33:52

RMAN>

Restore the database

RMAN> shutdown immediate;

Oracle instance shut down

RMAN> startup mount;

connected to target database (not started)
Oracle instance started
database mounted

Total System Global Area 3221225344 bytes

Fixed Size 9691008 bytes
Variable Size 654311424 bytes
Database Buffers 2550136832 bytes
Redo Buffers 7086080 bytes

RMAN> restore database;

Starting restore at 2024/04/04 13:34:36
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=31 device type=DISK

skipping datafile 5; already restored to file /u02/oradata/LIES/datafile/o1_mf_system_m0x17jvq_.dbf
skipping datafile 6; already restored to file /u02/oradata/LIES/datafile/o1_mf_sysaux_m0x17jvv_.dbf
skipping datafile 8; already restored to file /u02/oradata/LIES/datafile/o1_mf_undotbs1_m0x17jvx_.dbf
skipping datafile 9; already restored to file /u02/oradata/LIES/154444752F0C4E6CE0630203A8C0091D/datafile/o1_mf_system_m0x253w1_.dbf
skipping datafile 10; already restored to file /u02/oradata/LIES/154444752F0C4E6CE0630203A8C0091D/datafile/o1_mf_sysaux_m0x253w6_.dbf
skipping datafile 11; already restored to file /u02/oradata/LIES/154444752F0C4E6CE0630203A8C0091D/datafile/o1_mf_undotbs1_m0x253w6_.dbf
skipping datafile 12; already restored to file /u02/oradata/LIES/154444752F0C4E6CE0630203A8C0091D/datafile/o1_mf_users_m0x25qqk_.dbf
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u02/oradata/LIES/datafile/o1_mf_system_m0x0zlqp_.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u02/oradata/LIES/datafile/o1_mf_sysaux_m0x10ct0_.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u02/oradata/LIES/datafile/o1_mf_undotbs1_m0x10tw5_.dbf
channel ORA_DISK_1: restoring datafile 00007 to /u02/oradata/LIES/datafile/o1_mf_users_m0x10vyd_.dbf
channel ORA_DISK_1: reading from backup piece /u04/bloemkool.bos/backup/082ndggh_8_1_1
channel ORA_DISK_1: piece handle=/u04/bloemkool.bos/backup/082ndggh_8_1_1 tag=TAG20240404T131353
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:02:36
Finished restore at 2024/04/04 13:37:12

RMAN>

Recover the database (until sequence 31)

RMAN> recover database until sequence 31;

Starting recover at 2024/04/04 13:38:09
using channel ORA_DISK_1

starting media recovery

archived log for thread 1 with sequence 29 is already on disk as file /u03/LIES/onlinelog/o1_mf_2_m0x13q8r_.log
archived log for thread 1 with sequence 30 is already on disk as file /u03/LIES/onlinelog/o1_mf_3_m0x13q9p_.log
channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=17
channel ORA_DISK_1: reading from backup piece /u04/bloemkool.bos/backup/0b2ndgp5_11_1_1
channel ORA_DISK_1: piece handle=/u04/bloemkool.bos/backup/0b2ndgp5_11_1_1 tag=TAG20240404T131829
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u03/LIES/archivelog/1_17_1165409047.dbf thread=1 sequence=17
archived log file name=/u03/LIES/archivelog/1_18_1165409047.dbf thread=1 sequence=18
archived log file name=/u03/LIES/archivelog/1_19_1165409047.dbf thread=1 sequence=19
archived log file name=/u03/LIES/archivelog/1_20_1165409047.dbf thread=1 sequence=20
archived log file name=/u03/LIES/archivelog/1_21_1165409047.dbf thread=1 sequence=21
archived log file name=/u03/LIES/archivelog/1_22_1165409047.dbf thread=1 sequence=22
archived log file name=/u03/LIES/archivelog/1_23_1165409047.dbf thread=1 sequence=23
archived log file name=/u03/LIES/archivelog/1_24_1165409047.dbf thread=1 sequence=24
archived log file name=/u03/LIES/archivelog/1_25_1165409047.dbf thread=1 sequence=25
archived log file name=/u03/LIES/archivelog/1_26_1165409047.dbf thread=1 sequence=26
archived log file name=/u03/LIES/archivelog/1_27_1165409047.dbf thread=1 sequence=27
archived log file name=/u03/LIES/archivelog/1_28_1165409047.dbf thread=1 sequence=28
archived log file name=/u03/LIES/onlinelog/o1_mf_2_m0x13q8r_.log thread=1 sequence=29
archived log file name=/u03/LIES/onlinelog/o1_mf_3_m0x13q9p_.log thread=1 sequence=30
media recovery complete, elapsed time: 00:00:02
Finished recover at 2024/04/04 13:38:12

RMAN>

Alter database open resetlogs

RMAN> alter database open resetlogs;

Statement processed

RMAN>

 

So…I say…yes we can recover past the time of backup of the controlfile 🙂

 

Leave a Reply

Your email address will not be published. Required fields are marked *