04 June, 2021

Restoring a Standby Database to the Primary

 When you lose the Primary database, you can restore a backup of the Standby to the Primary.  

Update : This method can also be used to restore a Standby to another server as an independent Primary, except that you must decide the Recovery Point (ArchiveLog Sequence# and make those ArchiveLogs available either from the Standby server or the actual source Primary server)


First, I start with a backup of the Standby :



SQL> select
  2  i.host_name, i.status,
  3  d.dbid, d.name, d.controlfile_type, d.database_role, d.current_scn
  4  from v$instance i, v$database d
  5  /

HOST_NAME        STATUS             DBID NAME      CONTROL DATABASE_ROLE    CURRENT_SCN
---------------- ------------ ---------- --------- ------- ---------------- -----------
ora19cs1         MOUNTED      2778483057 ORCLCDB   STANDBY PHYSICAL STANDBY    12445248

SQL> !echo $ORACLE_SID
STDBYDB

SQL>
SQL> alter database recover managed standby database cancel;

Database altered.

SQL> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
oracle19c>
oracle19c>rman target /

Recovery Manager: Release 19.0.0.0.0 - Production on Thu Jun 3 22:29:59 2021
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCLCDB (DBID=2778483057, not open)

RMAN> backup as compressed backupset database;

Starting backup at 03-JUN-21
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/opt/oracle/oradata/STDBYDB/system01.dbf
input datafile file number=00003 name=/opt/oracle/oradata/STDBYDB/sysaux01.dbf
input datafile file number=00004 name=/opt/oracle/oradata/STDBYDB/undotbs01.dbf
input datafile file number=00007 name=/opt/oracle/oradata/STDBYDB/users01.dbf
channel ORA_DISK_1: starting piece 1 at 03-JUN-21
channel ORA_DISK_1: finished piece 1 at 03-JUN-21
piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jckswmk4_.bkp tag=TAG20210603T223042 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00010 name=/opt/oracle/oradata/STDBYDB/ORCLPDB1/sysaux01.dbf
input datafile file number=00012 name=/opt/oracle/oradata/STDBYDB/ORCLPDB1/users01.dbf
input datafile file number=00009 name=/opt/oracle/oradata/STDBYDB/ORCLPDB1/system01.dbf
input datafile file number=00011 name=/opt/oracle/oradata/STDBYDB/ORCLPDB1/undotbs01.dbf
input datafile file number=00026 name=/opt/oracle/oradata/STDBYDB/8812E29864F47615E0530100007FA424/datafile/o1_mf_data_min_j36xw6vr_.dbf
channel ORA_DISK_1: starting piece 1 at 03-JUN-21
channel ORA_DISK_1: finished piece 1 at 03-JUN-21
piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/8812E29864F47615E0530100007FA424/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jcksybw9_.bkp tag=TAG20210603T223042 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00028 name=/opt/oracle/oradata/STDBYDB/C07D1F2BA98C23D0E0530100007F7D34/datafile/o1_mf_sysaux_j80dl94j_.dbf
input datafile file number=00027 name=/opt/oracle/oradata/STDBYDB/C07D1F2BA98C23D0E0530100007F7D34/datafile/o1_mf_system_j80dl8qy_.dbf
input datafile file number=00029 name=/opt/oracle/oradata/STDBYDB/C07D1F2BA98C23D0E0530100007F7D34/datafile/o1_mf_undotbs1_j80dl96d_.dbf
input datafile file number=00030 name=/opt/oracle/oradata/STDBYDB/C07D1F2BA98C23D0E0530100007F7D34/datafile/o1_mf_rman_tbs_j80f1p8x_.dbf
channel ORA_DISK_1: starting piece 1 at 03-JUN-21
channel ORA_DISK_1: finished piece 1 at 03-JUN-21
piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/C07D1F2BA98C23D0E0530100007F7D34/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jckszgbr_.bkp tag=TAG20210603T223042 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00006 name=/opt/oracle/oradata/STDBYDB/pdbseed/sysaux01.dbf
input datafile file number=00005 name=/opt/oracle/oradata/STDBYDB/pdbseed/system01.dbf
input datafile file number=00008 name=/opt/oracle/oradata/STDBYDB/pdbseed/undotbs01.dbf
channel ORA_DISK_1: starting piece 1 at 03-JUN-21
channel ORA_DISK_1: finished piece 1 at 03-JUN-21
piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/88129263B99F4BBDE0530100007F7BDF/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jckt07r9_.bkp tag=TAG20210603T223042 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25
Finished backup at 03-JUN-21

Starting Control File and SPFILE Autobackup at 03-JUN-21
piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/autobackup/2021_06_03/o1_mf_s_1074102643_jckt126x_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 03-JUN-21

RMAN>


Let's say that some of the datafiles on my Primary are corrupt and I need to restore the Primary database from this Standby backup.  (Alternately, instead of restoring to the actual Primary, I might be planning to build a new Primary, maybe at a different Data Centre, from the Standby backup)
Let's assume that I had captured this information about the Primary before I lost the datafiles of the Primary  (I don't really need all this, I just need to know the Archive Log Sequence#s from the alert.log) :

SQL> select
  2  i.host_name, i.status,
  3  d.dbid, d.name, d.controlfile_type, d.database_role, d.current_scn
  4  from v$instance i, v$database d
  5  /

HOST_NAME        STATUS             DBID NAME      CONTROL DATABASE_ROLE    CURRENT_SCN
---------------- ------------ ---------- --------- ------- ---------------- -----------
ora19cP1         OPEN         2778483057 ORCLCDB   CURRENT PRIMARY             12770765

SQL>
SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /opt/oracle/archivelog/ORCLCDB
Oldest online log sequence     224
Next log sequence to archive   226
Current log sequence           226
SQL>
SQL> select sequence#, next_change#
  2  from v$archived_log
  3  where sequence# > 215
  4  order by 1
  5  /

 SEQUENCE# NEXT_CHANGE#
---------- ------------
       216     12439207
       216     12439207
       217     12545592
       218     12645850
       219     12746127
       220     12760012
       221     12760153
       222     12760157
       223     12760486
       224     12770051
       225     12770693

11 rows selected.

SQL>


Given that the Standby had SCN 12445248, after the RESTORE, I must RECOVER from SEQUENCE#217.
So I begin to restore the Standby backup which I've copied to the /var/tmp folder on the Primary / New Primary Server.  My ORACLE_SID here is ORCLCDB.


oracle19c>cd /var/tmp
oracle19c>tar xvf STDBYDB_bak.TAR
oracle19c>cd STDBYDB
oracle19c>pwd
/var/tmp/STDBYDB
oracle19c>ls -l
total 0
drwxr-x---. 3 oracle oinstall 23 May 22  2020 88129263B99F4BBDE0530100007F7BDF
drwxr-x---. 3 oracle oinstall 23 May 22  2020 8812E29864F47615E0530100007FA424
drwxr-x---. 5 oracle oinstall 60 Jun  3 22:33 autobackup
drwxr-x---. 5 oracle oinstall 60 Jun  3 22:30 backupset
drwxr-x---. 3 oracle oinstall 23 Apr 21 22:38 C07D1F2BA98C23D0E0530100007F7D34
drwxr-x---. 2 oracle oinstall  6 Mar 27  2020 flashback
drwxr-x---. 2 oracle oinstall  6 Mar 26  2020 onlinelog
oracle19c>
oracle19c>echo $ORACLE_SID
ORCLCDB
oracle19c>rman target /

Recovery Manager: Release 19.0.0.0.0 - Production on Thu Jun 3 23:11:01 2021
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.

connected to target database (not started)

RMAN> startup nomount;

Oracle instance started

Total System Global Area    1207955552 bytes

Fixed Size                     9134176 bytes
Variable Size                822083584 bytes
Database Buffers             369098752 bytes
Redo Buffers                   7639040 bytes

RMAN> restore PRIMARY controlfile from
2> '/var/tmp/STDBYDB/autobackup/2021_06_03/o1_mf_s_1074102643_jckt126x_.bkp';

Starting restore at 03-JUN-21
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/opt/oracle/oradata/ORCLCDB/control01.ctl
output file name=/opt/oracle/oradata/ORCLCDB/control02.ctl
Finished restore at 03-JUN-21

RMAN> alter database mount;

released channel: ORA_DISK_1
Statement processed

RMAN>


I now have the Standby Controlfile restored as a Primary Controlfile.
Next, I must remove information about unavailable backups and catalog only the backups that I have copied from the Standby.


RMAN> crosscheck backup;

Starting implicit crosscheck backup at 03-JUN-21
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=24 device type=DISK
Crosschecked 19 objects
Finished implicit crosscheck backup at 03-JUN-21

Starting implicit crosscheck copy at 03-JUN-21
using channel ORA_DISK_1
Finished implicit crosscheck copy at 03-JUN-21

searching for all files in the recovery area
cataloging files...
no files cataloged

using channel ORA_DISK_1
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/backupset/2021_02_22/o1_mf_nnndf_TAG20210222T173935_j36yyqqo_.bkp RECID=21 STAMP=1065202775
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/8812E29864F47615E0530100007FA424/backupset/2021_02_22/o1_mf_nnndf_TAG20210222T173935_j36z0h1w_.bkp RECID=22 STAMP=1065202831
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/88129263B99F4BBDE0530100007F7BDF/backupset/2021_02_22/o1_mf_nnndf_TAG20210222T173935_j36z1lx8_.bkp RECID=23 STAMP=1065202866
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/autobackup/2021_02_22/o1_mf_s_1065202724_j36z2q4m_.bkp RECID=24 STAMP=1065202903
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/backupset/2021_02_22/o1_mf_annnn_TAG20210222T174817_j36zh2k1_.bkp RECID=25 STAMP=1065203298
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/autobackup/2021_02_22/o1_mf_s_1065203261_j36zl5fz_.bkp RECID=26 STAMP=1065203397
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/backupset/2021_04_21/o1_mf_nnndf_TAG20210421T223703_j80g4j55_.bkp RECID=27 STAMP=1070491024
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/backupset/2021_04_21/o1_mf_nnndf_TAG20210421T223703_j80g4hv6_.bkp RECID=28 STAMP=1070491023
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/8812E29864F47615E0530100007FA424/backupset/2021_04_21/o1_mf_nnndf_TAG20210421T223703_j80g5qmn_.bkp RECID=29 STAMP=1070491063
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/8812E29864F47615E0530100007FA424/backupset/2021_04_21/o1_mf_nnndf_TAG20210421T223703_j80g5v6j_.bkp RECID=30 STAMP=1070491067
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/C07D1F2BA98C23D0E0530100007F7D34/backupset/2021_04_21/o1_mf_nnndf_TAG20210421T223703_j80g6nhq_.bkp RECID=31 STAMP=1070491092
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/C07D1F2BA98C23D0E0530100007F7D34/backupset/2021_04_21/o1_mf_nnndf_TAG20210421T223703_j80g6p4q_.bkp RECID=32 STAMP=1070491093
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/88129263B99F4BBDE0530100007F7BDF/backupset/2021_04_21/o1_mf_nnndf_TAG20210421T223703_j80g7j4f_.bkp RECID=33 STAMP=1070491119
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/88129263B99F4BBDE0530100007F7BDF/backupset/2021_04_21/o1_mf_nnndf_TAG20210421T223703_j80g7gj2_.bkp RECID=34 STAMP=1070491118
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/autobackup/2021_04_21/o1_mf_s_1070490998_j80g8k1q_.bkp RECID=35 STAMP=1070491152
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jckswmk4_.bkp RECID=36 STAMP=1074292243
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/8812E29864F47615E0530100007FA424/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jcksybw9_.bkp RECID=37 STAMP=1074292298
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/C07D1F2BA98C23D0E0530100007F7D34/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jckszgbr_.bkp RECID=38 STAMP=1074292334
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/88129263B99F4BBDE0530100007F7BDF/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jckt07r9_.bkp RECID=39 STAMP=1074292359
Crosschecked 19 objects


RMAN>

RMAN> delete noprompt expired backup;

using channel ORA_DISK_1

List of Backup Pieces
BP Key  BS Key  Pc# Cp# Status      Device Type Piece Name
------- ------- --- --- ----------- ----------- ----------
21      21      1   1   EXPIRED     DISK        /opt/oracle/FRA/STDBYDB/STDBYDB/backupset/2021_02_22/o1_mf_nnndf_TAG20210222T173935_j36yyqqo_.bkp
22      22      1   1   EXPIRED     DISK        /opt/oracle/FRA/STDBYDB/STDBYDB/8812E29864F47615E0530100007FA424/backupset/2021_02_22/o1_mf_nnndf_TAG20210222T173935_j36z0h1w_.bkp
23      23      1   1   EXPIRED     DISK        /opt/oracle/FRA/STDBYDB/STDBYDB/88129263B99F4BBDE0530100007F7BDF/backupset/2021_02_22/o1_mf_nnndf_TAG20210222T173935_j36z1lx8_.bkp
24      24      1   1   EXPIRED     DISK        /opt/oracle/FRA/STDBYDB/STDBYDB/autobackup/2021_02_22/o1_mf_s_1065202724_j36z2q4m_.bkp
25      25      1   1   EXPIRED     DISK        /opt/oracle/FRA/STDBYDB/STDBYDB/backupset/2021_02_22/o1_mf_annnn_TAG20210222T174817_j36zh2k1_.bkp
26      26      1   1   EXPIRED     DISK        /opt/oracle/FRA/STDBYDB/STDBYDB/autobackup/2021_02_22/o1_mf_s_1065203261_j36zl5fz_.bkp
27      27      1   1   EXPIRED     DISK        /opt/oracle/FRA/STDBYDB/STDBYDB/backupset/2021_04_21/o1_mf_nnndf_TAG20210421T223703_j80g4j55_.bkp
28      28      1   1   EXPIRED     DISK        /opt/oracle/FRA/STDBYDB/STDBYDB/backupset/2021_04_21/o1_mf_nnndf_TAG20210421T223703_j80g4hv6_.bkp
29      29      1   1   EXPIRED     DISK        /opt/oracle/FRA/STDBYDB/STDBYDB/8812E29864F47615E0530100007FA424/backupset/2021_04_21/o1_mf_nnndf_TAG20210421T223703_j80g5qmn_.bkp
30      30      1   1   EXPIRED     DISK        /opt/oracle/FRA/STDBYDB/STDBYDB/8812E29864F47615E0530100007FA424/backupset/2021_04_21/o1_mf_nnndf_TAG20210421T223703_j80g5v6j_.bkp
31      31      1   1   EXPIRED     DISK        /opt/oracle/FRA/STDBYDB/STDBYDB/C07D1F2BA98C23D0E0530100007F7D34/backupset/2021_04_21/o1_mf_nnndf_TAG20210421T223703_j80g6nhq_.bkp
32      32      1   1   EXPIRED     DISK        /opt/oracle/FRA/STDBYDB/STDBYDB/C07D1F2BA98C23D0E0530100007F7D34/backupset/2021_04_21/o1_mf_nnndf_TAG20210421T223703_j80g6p4q_.bkp
33      33      1   1   EXPIRED     DISK        /opt/oracle/FRA/STDBYDB/STDBYDB/88129263B99F4BBDE0530100007F7BDF/backupset/2021_04_21/o1_mf_nnndf_TAG20210421T223703_j80g7j4f_.bkp
34      34      1   1   EXPIRED     DISK        /opt/oracle/FRA/STDBYDB/STDBYDB/88129263B99F4BBDE0530100007F7BDF/backupset/2021_04_21/o1_mf_nnndf_TAG20210421T223703_j80g7gj2_.bkp
35      35      1   1   EXPIRED     DISK        /opt/oracle/FRA/STDBYDB/STDBYDB/autobackup/2021_04_21/o1_mf_s_1070490998_j80g8k1q_.bkp
36      36      1   1   EXPIRED     DISK        /opt/oracle/FRA/STDBYDB/STDBYDB/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jckswmk4_.bkp
37      37      1   1   EXPIRED     DISK        /opt/oracle/FRA/STDBYDB/STDBYDB/8812E29864F47615E0530100007FA424/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jcksybw9_.bkp
38      38      1   1   EXPIRED     DISK        /opt/oracle/FRA/STDBYDB/STDBYDB/C07D1F2BA98C23D0E0530100007F7D34/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jckszgbr_.bkp
39      39      1   1   EXPIRED     DISK        /opt/oracle/FRA/STDBYDB/STDBYDB/88129263B99F4BBDE0530100007F7BDF/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jckt07r9_.bkp
deleted backup piece
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/backupset/2021_02_22/o1_mf_nnndf_TAG20210222T173935_j36yyqqo_.bkp RECID=21 STAMP=1065202775
deleted backup piece
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/8812E29864F47615E0530100007FA424/backupset/2021_02_22/o1_mf_nnndf_TAG20210222T173935_j36z0h1w_.bkp RECID=22 STAMP=1065202831
deleted backup piece
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/88129263B99F4BBDE0530100007F7BDF/backupset/2021_02_22/o1_mf_nnndf_TAG20210222T173935_j36z1lx8_.bkp RECID=23 STAMP=1065202866
deleted backup piece
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/autobackup/2021_02_22/o1_mf_s_1065202724_j36z2q4m_.bkp RECID=24 STAMP=1065202903
deleted backup piece
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/backupset/2021_02_22/o1_mf_annnn_TAG20210222T174817_j36zh2k1_.bkp RECID=25 STAMP=1065203298
deleted backup piece
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/autobackup/2021_02_22/o1_mf_s_1065203261_j36zl5fz_.bkp RECID=26 STAMP=1065203397
deleted backup piece
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/backupset/2021_04_21/o1_mf_nnndf_TAG20210421T223703_j80g4j55_.bkp RECID=27 STAMP=1070491024
deleted backup piece
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/backupset/2021_04_21/o1_mf_nnndf_TAG20210421T223703_j80g4hv6_.bkp RECID=28 STAMP=1070491023
deleted backup piece
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/8812E29864F47615E0530100007FA424/backupset/2021_04_21/o1_mf_nnndf_TAG20210421T223703_j80g5qmn_.bkp RECID=29 STAMP=1070491063
deleted backup piece
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/8812E29864F47615E0530100007FA424/backupset/2021_04_21/o1_mf_nnndf_TAG20210421T223703_j80g5v6j_.bkp RECID=30 STAMP=1070491067
deleted backup piece
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/C07D1F2BA98C23D0E0530100007F7D34/backupset/2021_04_21/o1_mf_nnndf_TAG20210421T223703_j80g6nhq_.bkp RECID=31 STAMP=1070491092
deleted backup piece
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/C07D1F2BA98C23D0E0530100007F7D34/backupset/2021_04_21/o1_mf_nnndf_TAG20210421T223703_j80g6p4q_.bkp RECID=32 STAMP=1070491093
deleted backup piece
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/88129263B99F4BBDE0530100007F7BDF/backupset/2021_04_21/o1_mf_nnndf_TAG20210421T223703_j80g7j4f_.bkp RECID=33 STAMP=1070491119
deleted backup piece
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/88129263B99F4BBDE0530100007F7BDF/backupset/2021_04_21/o1_mf_nnndf_TAG20210421T223703_j80g7gj2_.bkp RECID=34 STAMP=1070491118
deleted backup piece
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/autobackup/2021_04_21/o1_mf_s_1070490998_j80g8k1q_.bkp RECID=35 STAMP=1070491152
deleted backup piece
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jckswmk4_.bkp RECID=36 STAMP=1074292243
deleted backup piece
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/8812E29864F47615E0530100007FA424/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jcksybw9_.bkp RECID=37 STAMP=1074292298
deleted backup piece
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/C07D1F2BA98C23D0E0530100007F7D34/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jckszgbr_.bkp RECID=38 STAMP=1074292334
deleted backup piece
backup piece handle=/opt/oracle/FRA/STDBYDB/STDBYDB/88129263B99F4BBDE0530100007F7BDF/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jckt07r9_.bkp RECID=39 STAMP=1074292359
Deleted 19 EXPIRED objects


RMAN>


RMAN> catalog start with '/var/tmp/STDBYDB';

searching for all files that match the pattern /var/tmp/STDBYDB

List of Files Unknown to the Database
=====================================
File Name: /var/tmp/STDBYDB_bak.TAR
File Name: /var/tmp/STDBYDB/88129263B99F4BBDE0530100007F7BDF/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jckt07r9_.bkp
File Name: /var/tmp/STDBYDB/8812E29864F47615E0530100007FA424/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jcksybw9_.bkp
File Name: /var/tmp/STDBYDB/autobackup/2021_06_03/o1_mf_s_1074102643_jckt126x_.bkp
File Name: /var/tmp/STDBYDB/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jckswmk4_.bkp
File Name: /var/tmp/STDBYDB/C07D1F2BA98C23D0E0530100007F7D34/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jckszgbr_.bkp

Do you really want to catalog the above files (enter YES or NO)? YES
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /var/tmp/STDBYDB/88129263B99F4BBDE0530100007F7BDF/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jckt07r9_.bkp
File Name: /var/tmp/STDBYDB/8812E29864F47615E0530100007FA424/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jcksybw9_.bkp
File Name: /var/tmp/STDBYDB/autobackup/2021_06_03/o1_mf_s_1074102643_jckt126x_.bkp
File Name: /var/tmp/STDBYDB/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jckswmk4_.bkp
File Name: /var/tmp/STDBYDB/C07D1F2BA98C23D0E0530100007F7D34/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jckszgbr_.bkp

List of Files Which Were Not Cataloged
=======================================
File Name: /var/tmp/STDBYDB_bak.TAR
  RMAN-07517: Reason: The file header is corrupted

RMAN>

RMAN> list backup;


List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
40      Full    119.55M    DISK        00:00:20     03-JUN-21
        BP Key: 40   Status: AVAILABLE  Compressed: YES  Tag: TAG20210603T223042
        Piece Name: /var/tmp/STDBYDB/88129263B99F4BBDE0530100007F7BDF/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jckt07r9_.bkp
  List of Datafiles in backup set 40
  Container ID: 2, PDB Name: PDB$SEED
  File LV Type Ckp SCN    Ckp Time  Abs Fuz SCN Sparse Name
  ---- -- ---- ---------- --------- ----------- ------ ----
  5       Full 4931679    20-MAY-20              NO    /opt/oracle/oradata/STDBYDB/pdbseed/system01.dbf
  6       Full 4931679    20-MAY-20              NO    /opt/oracle/oradata/STDBYDB/pdbseed/sysaux01.dbf
  8       Full 4931679    20-MAY-20              NO    /opt/oracle/oradata/STDBYDB/pdbseed/undotbs01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
41      Full    150.14M    DISK        00:00:32     03-JUN-21
        BP Key: 41   Status: AVAILABLE  Compressed: YES  Tag: TAG20210603T223042
        Piece Name: /var/tmp/STDBYDB/8812E29864F47615E0530100007FA424/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jcksybw9_.bkp
  List of Datafiles in backup set 41
  Container ID: 3, PDB Name: ORCLPDB1
  File LV Type Ckp SCN    Ckp Time  Abs Fuz SCN Sparse Name
  ---- -- ---- ---------- --------- ----------- ------ ----
  9       Full 12441929   01-JUN-21 12444076     NO    /opt/oracle/oradata/STDBYDB/ORCLPDB1/system01.dbf
  10      Full 12441973   01-JUN-21              NO    /opt/oracle/oradata/STDBYDB/ORCLPDB1/sysaux01.dbf
  11      Full 12442030   01-JUN-21 12444077     NO    /opt/oracle/oradata/STDBYDB/ORCLPDB1/undotbs01.dbf
  12      Full 12442056   01-JUN-21              NO    /opt/oracle/oradata/STDBYDB/ORCLPDB1/users01.dbf
  26      Full 12442098   01-JUN-21              NO    /opt/oracle/oradata/STDBYDB/8812E29864F47615E0530100007FA424/datafile/o1_mf_data_min_j36xw6vr_.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
42      Full    17.95M     DISK        00:00:02     03-JUN-21
        BP Key: 42   Status: AVAILABLE  Compressed: NO  Tag: TAG20210603T223304
        Piece Name: /var/tmp/STDBYDB/autobackup/2021_06_03/o1_mf_s_1074102643_jckt126x_.bkp
  SPFILE Included: Modification time: 03-JUN-21
  SPFILE db_unique_name: STDBYDB
  Standby Control File Included: Ckp SCN: 12445249     Ckp time: 01-JUN-21

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
43      Full    318.54M    DISK        00:00:45     03-JUN-21
        BP Key: 43   Status: AVAILABLE  Compressed: YES  Tag: TAG20210603T223042
        Piece Name: /var/tmp/STDBYDB/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jckswmk4_.bkp
  List of Datafiles in backup set 43
  File LV Type Ckp SCN    Ckp Time  Abs Fuz SCN Sparse Name
  ---- -- ---- ---------- --------- ----------- ------ ----
  1       Full 12441752   01-JUN-21 12444640     NO    /opt/oracle/oradata/STDBYDB/system01.dbf
  3       Full 12441842   01-JUN-21 12445226     NO    /opt/oracle/oradata/STDBYDB/sysaux01.dbf
  4       Full 12441901   01-JUN-21 12445227     NO    /opt/oracle/oradata/STDBYDB/undotbs01.dbf
  7       Full 12441924   01-JUN-21              NO    /opt/oracle/oradata/STDBYDB/users01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
44      Full    121.72M    DISK        00:00:22     03-JUN-21
        BP Key: 44   Status: AVAILABLE  Compressed: YES  Tag: TAG20210603T223042
        Piece Name: /var/tmp/STDBYDB/C07D1F2BA98C23D0E0530100007F7D34/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jckszgbr_.bkp
  List of Datafiles in backup set 44
  Container ID: 4, PDB Name: RMANCAT
  File LV Type Ckp SCN    Ckp Time  Abs Fuz SCN Sparse Name
  ---- -- ---- ---------- --------- ----------- ------ ----
  27      Full 11082204   21-APR-21              NO    /opt/oracle/oradata/ORCLCDB/C07D1F2BA98C23D0E0530100007F7D34/datafile/o1_mf_system_j80dl8qy_.dbf
  28      Full 11082204   21-APR-21              NO    /opt/oracle/oradata/ORCLCDB/C07D1F2BA98C23D0E0530100007F7D34/datafile/o1_mf_sysaux_j80dl94j_.dbf
  29      Full 11082204   21-APR-21              NO    /opt/oracle/oradata/ORCLCDB/C07D1F2BA98C23D0E0530100007F7D34/datafile/o1_mf_undotbs1_j80dl96d_.dbf
  30      Full 11082204   21-APR-21              NO    /opt/oracle/oradata/STDBYDB/C07D1F2BA98C23D0E0530100007F7D34/datafile/o1_mf_rman_tbs_j80f1p8x_.dbf

RMAN>

RMAN> quit


Recovery Manager complete.
oracle19c>


So I have now CATALOGed all the backups that I copied over from the Standby server.
Before I proceed with the RESTORE, I verify the "database" information in the controlfile :


oracle19c>echo $ORACLE_SID
ORCLCDB
oracle19c>sqlplus '/ as sysdba'

SQL*Plus: Release 19.0.0.0.0 - Production on Thu Jun 3 23:37:54 2021
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.


Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL> col host_name format a16
SQL> select
  2  i.host_name, i.status,
  3  d.dbid, d.name, d.controlfile_type, d.database_role, d.current_scn
  4  from v$instance i, v$database d
  5  /

HOST_NAME        STATUS             DBID NAME      CONTROL DATABASE_ROLE    CURRENT_SCN
---------------- ------------ ---------- --------- ------- ---------------- -----------
ora19cP1         MOUNTED      2778483057 ORCLCDB   BACKUP  PRIMARY                    0

SQL>
SQL> show parameter db_create

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_create_file_dest                  string      /opt/oracle/oradata
db_create_online_log_dest_1          string
db_create_online_log_dest_2          string
db_create_online_log_dest_3          string
db_create_online_log_dest_4          string
db_create_online_log_dest_5          string
SQL>
SQL> create pfile from spfile;

File created.

SQL> shutdown;
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.
SQL>  --- at this point modify the created pfile to set DB_FILE_NAME_CONVERT and LOG_FILE_NAME_CONVERT
SQL> !tail -2 $ORACLE_HOME/dbs/initORCLCDB.ora
*.db_file_name_convert='STDBYDB','ORCLCDB'
*.log_file_name_convert='STDBYDB','ORCLCDB'

SQL>
SQL> startup mount pfile='$ORACLE_HOME/dbs/initORCLCDB.ora';
ORACLE instance started.

Total System Global Area 1207955552 bytes
Fixed Size                  9134176 bytes
Variable Size             822083584 bytes
Database Buffers          369098752 bytes
Redo Buffers                7639040 bytes
Database mounted.
SQL> show parameter file_name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert                 string      STDBYDB, ORCLCDB
log_file_name_convert                string      STDBYDB, ORCLCDB
pdb_file_name_convert                string
SQL>



This shows that I have the correct database controlfile based on the DBID and NAME and that database will now be a PRIMARY, not a Standby.
I cannot check the SCN because the database is not OPEN (in fact, it hasn't been RESTOREd yet !)
However, I had to set DB_FILE_NAME_CONVERT and LOG_FILE_NAME_CONVERT because the file names in the control file had STDBYDB in the path and db_create_file_dest would not overwrite that.

I can now proceed to RESTORE database :
SQL> quit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
oracle19c>rman target /

Recovery Manager: Release 19.0.0.0.0 - Production on Thu Jun 3 23:58:05 2021
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCLCDB (DBID=2778483057, not open)

RMAN> restore database;

Starting restore at 03-JUN-21
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=259 device type=DISK

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 /opt/oracle/oradata/ORCLCDB/system01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /opt/oracle/oradata/ORCLCDB/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /opt/oracle/oradata/ORCLCDB/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00007 to /opt/oracle/oradata/ORCLCDB/users01.dbf
channel ORA_DISK_1: reading from backup piece /var/tmp/STDBYDB/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jckswmk4_.bkp
channel ORA_DISK_1: piece handle=/var/tmp/STDBYDB/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jckswmk4_.bkp tag=TAG20210603T223042
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:45
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 00005 to /opt/oracle/oradata/ORCLCDB/pdbseed/system01.dbf
channel ORA_DISK_1: restoring datafile 00006 to /opt/oracle/oradata/ORCLCDB/pdbseed/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00008 to /opt/oracle/oradata/ORCLCDB/pdbseed/undotbs01.dbf
channel ORA_DISK_1: reading from backup piece /var/tmp/STDBYDB/88129263B99F4BBDE0530100007F7BDF/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jckt07r9_.bkp
channel ORA_DISK_1: piece handle=/var/tmp/STDBYDB/88129263B99F4BBDE0530100007F7BDF/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jckt07r9_.bkp tag=TAG20210603T223042
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
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 00009 to /opt/oracle/oradata/ORCLCDB/ORCLPDB1/system01.dbf
channel ORA_DISK_1: restoring datafile 00010 to /opt/oracle/oradata/ORCLCDB/ORCLPDB1/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00011 to /opt/oracle/oradata/ORCLCDB/ORCLPDB1/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00012 to /opt/oracle/oradata/ORCLCDB/ORCLPDB1/users01.dbf
channel ORA_DISK_1: restoring datafile 00026 to /opt/oracle/oradata/ORCLCDB/8812E29864F47615E0530100007FA424/datafile/o1_mf_data_min_jcky1j3g_.dbf
channel ORA_DISK_1: reading from backup piece /var/tmp/STDBYDB/8812E29864F47615E0530100007FA424/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jcksybw9_.bkp
channel ORA_DISK_1: piece handle=/var/tmp/STDBYDB/8812E29864F47615E0530100007FA424/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jcksybw9_.bkp tag=TAG20210603T223042
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:25
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 00027 to /opt/oracle/oradata/ORCLCDB/C07D1F2BA98C23D0E0530100007F7D34/datafile/o1_mf_system_j80dl8qy_.dbf
channel ORA_DISK_1: restoring datafile 00028 to /opt/oracle/oradata/ORCLCDB/C07D1F2BA98C23D0E0530100007F7D34/datafile/o1_mf_sysaux_j80dl94j_.dbf
channel ORA_DISK_1: restoring datafile 00029 to /opt/oracle/oradata/ORCLCDB/C07D1F2BA98C23D0E0530100007F7D34/datafile/o1_mf_undotbs1_j80dl96d_.dbf
channel ORA_DISK_1: restoring datafile 00030 to /opt/oracle/oradata/ORCLCDB/C07D1F2BA98C23D0E0530100007F7D34/datafile/o1_mf_rman_tbs_j80f1p8x_.dbf
channel ORA_DISK_1: reading from backup piece /var/tmp/STDBYDB/C07D1F2BA98C23D0E0530100007F7D34/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jckszgbr_.bkp
channel ORA_DISK_1: piece handle=/var/tmp/STDBYDB/C07D1F2BA98C23D0E0530100007F7D34/backupset/2021_06_03/o1_mf_nnndf_TAG20210603T223042_jckszgbr_.bkp tag=TAG20210603T223042
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
Finished restore at 04-JUN-21

RMAN>
RMAN> quit


Recovery Manager complete.


I can now proceed to RECOVER the database. Note how I had identified that I would need the ArchiveLogs from SEQUENCE#217 onwards.  Here, either I already have the ArchiveLogs on-disk (if I am restoring the database to the Primary)  OR have copied them from the Old Primary server to the New Primary Server (if I am building the database with a RESTORE on a new Server)
oracle19c>sqlplus '/ as sysdba'

SQL*Plus: Release 19.0.0.0.0 - Production on Fri Jun 4 00:00:48 2021
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.


Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL>
SQL> recover database using backup controlfile until cancel;
ORA-00279: change 12441752 generated at 06/01/2021 17:33:06 needed for thread 1
ORA-00289: suggestion : /opt/oracle/archivelog/ORCLCDB/1_217_1036108814.dbf
ORA-00280: change 12441752 for thread 1 is in sequence #217


Specify log: {RET=suggested | filename | AUTO | CANCEL}

ORA-00279: change 12545592 generated at 06/03/2021 14:12:45 needed for thread 1
ORA-00289: suggestion : /opt/oracle/archivelog/ORCLCDB/1_218_1036108814.dbf
ORA-00280: change 12545592 for thread 1 is in sequence #218
ORA-00278: log file '/opt/oracle/archivelog/ORCLCDB/1_217_1036108814.dbf' no longer needed for this recovery


Specify log: {RET=suggested | filename | AUTO | CANCEL}

ORA-00279: change 12645850 generated at 06/03/2021 14:19:21 needed for thread 1
ORA-00289: suggestion : /opt/oracle/archivelog/ORCLCDB/1_219_1036108814.dbf
ORA-00280: change 12645850 for thread 1 is in sequence #219
ORA-00278: log file '/opt/oracle/archivelog/ORCLCDB/1_218_1036108814.dbf' no longer needed for this recovery


Specify log: {RET=suggested | filename | AUTO | CANCEL}

ORA-00279: change 12746127 generated at 06/03/2021 14:21:22 needed for thread 1
ORA-00289: suggestion : /opt/oracle/archivelog/ORCLCDB/1_220_1036108814.dbf
ORA-00280: change 12746127 for thread 1 is in sequence #220
ORA-00278: log file '/opt/oracle/archivelog/ORCLCDB/1_219_1036108814.dbf' no longer needed for this recovery


Specify log: {RET=suggested | filename | AUTO | CANCEL}

ORA-00279: change 12760012 generated at 06/03/2021 15:04:16 needed for thread 1
ORA-00289: suggestion : /opt/oracle/archivelog/ORCLCDB/1_221_1036108814.dbf
ORA-00280: change 12760012 for thread 1 is in sequence #221
ORA-00278: log file '/opt/oracle/archivelog/ORCLCDB/1_220_1036108814.dbf' no longer needed for this recovery


Specify log: {RET=suggested | filename | AUTO | CANCEL}

ORA-00279: change 12760153 generated at 06/03/2021 15:04:42 needed for thread 1
ORA-00289: suggestion : /opt/oracle/archivelog/ORCLCDB/1_222_1036108814.dbf
ORA-00280: change 12760153 for thread 1 is in sequence #222
ORA-00278: log file '/opt/oracle/archivelog/ORCLCDB/1_221_1036108814.dbf' no longer needed for this recovery


Specify log: {RET=suggested | filename | AUTO | CANCEL}

ORA-00279: change 12760157 generated at 06/03/2021 15:04:43 needed for thread 1
ORA-00289: suggestion : /opt/oracle/archivelog/ORCLCDB/1_223_1036108814.dbf
ORA-00280: change 12760157 for thread 1 is in sequence #223
ORA-00278: log file '/opt/oracle/archivelog/ORCLCDB/1_222_1036108814.dbf' no longer needed for this recovery


Specify log: {RET=suggested | filename | AUTO | CANCEL}

ORA-00279: change 12760486 generated at 06/03/2021 22:43:35 needed for thread 1
ORA-00289: suggestion : /opt/oracle/archivelog/ORCLCDB/1_224_1036108814.dbf
ORA-00280: change 12760486 for thread 1 is in sequence #224
ORA-00278: log file '/opt/oracle/archivelog/ORCLCDB/1_223_1036108814.dbf' no longer needed for this recovery


Specify log: {RET=suggested | filename | AUTO | CANCEL}

ORA-00279: change 12770051 generated at 06/03/2021 22:45:50 needed for thread 1
ORA-00289: suggestion : /opt/oracle/archivelog/ORCLCDB/1_225_1036108814.dbf
ORA-00280: change 12770051 for thread 1 is in sequence #225
ORA-00278: log file '/opt/oracle/archivelog/ORCLCDB/1_224_1036108814.dbf' no longer needed for this recovery


Specify log: {RET=suggested | filename | AUTO | CANCEL}

ORA-00279: change 12770693 generated at 06/03/2021 22:45:55 needed for thread 1
ORA-00289: suggestion : /opt/oracle/archivelog/ORCLCDB/1_226_1036108814.dbf
ORA-00280: change 12770693 for thread 1 is in sequence #226
ORA-00278: log file '/opt/oracle/archivelog/ORCLCDB/1_225_1036108814.dbf' no longer needed for this recovery


Specify log: {RET=suggested | filename | AUTO | CANCEL}

ORA-00308: cannot open archived log '/opt/oracle/archivelog/ORCLCDB/1_226_1036108814.dbf'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 7


SQL>
SQL> alter database open resetlogs;

Database altered.

SQL>
SQL> select
  2  i.host_name, i.status,
  3  d.dbid, d.name, d.controlfile_type, d.database_role, d.current_scn
  4  from v$instance i, v$database d
  5  /

HOST_NAME        STATUS             DBID NAME      CONTROL DATABASE_ROLE    CURRENT_SCN
---------------- ------------ ---------- --------- ------- ---------------- -----------
ora19cP1         OPEN         2778483057 ORCLCDB   CURRENT PRIMARY             12773006

SQL>
SQL> select name from v$datafile order by 1;

NAME
------------------------------------------------------------------------------------------------------------------------------------
/opt/oracle/oradata/ORCLCDB/8812E29864F47615E0530100007FA424/datafile/o1_mf_data_min_jckz2yvk_.dbf
/opt/oracle/oradata/ORCLCDB/C07D1F2BA98C23D0E0530100007F7D34/datafile/o1_mf_rman_tbs_jckz3r09_.dbf
/opt/oracle/oradata/ORCLCDB/C07D1F2BA98C23D0E0530100007F7D34/datafile/o1_mf_sysaux_jckz3qy8_.dbf
/opt/oracle/oradata/ORCLCDB/C07D1F2BA98C23D0E0530100007F7D34/datafile/o1_mf_system_jckz3qym_.dbf
/opt/oracle/oradata/ORCLCDB/C07D1F2BA98C23D0E0530100007F7D34/datafile/o1_mf_undotbs1_jckz3r04_.dbf
/opt/oracle/oradata/ORCLCDB/ORCLPDB1/sysaux01.dbf
/opt/oracle/oradata/ORCLCDB/ORCLPDB1/system01.dbf
/opt/oracle/oradata/ORCLCDB/ORCLPDB1/undotbs01.dbf
/opt/oracle/oradata/ORCLCDB/ORCLPDB1/users01.dbf
/opt/oracle/oradata/ORCLCDB/pdbseed/sysaux01.dbf
/opt/oracle/oradata/ORCLCDB/pdbseed/system01.dbf
/opt/oracle/oradata/ORCLCDB/pdbseed/undotbs01.dbf
/opt/oracle/oradata/ORCLCDB/sysaux01.dbf
/opt/oracle/oradata/ORCLCDB/system01.dbf
/opt/oracle/oradata/ORCLCDB/undotbs01.dbf
/opt/oracle/oradata/ORCLCDB/users01.dbf

16 rows selected.

SQL> 
SQL> create spfile from pfile;

File created.

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup;
ORACLE instance started.

Total System Global Area 1207955552 bytes
Fixed Size                  9134176 bytes
Variable Size             822083584 bytes
Database Buffers          369098752 bytes
Redo Buffers                7639040 bytes
Database mounted.
Database opened.
SQL>
SQL> show parameter spfile;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
spfile                               string      /opt/oracle/product/19c/dbhome
                                                 _1/dbs/spfileORCLCDB.ora
SQL>
SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /opt/oracle/archivelog/ORCLCDB
Oldest online log sequence     3
Next log sequence to archive   5
Current log sequence           5
SQL> alter system archive log current;

System altered.

SQL>


(Note : I removed the "<" and ">" signs around the "RET" to preservve HTML formatting)

If I had the Online Redo Logs still available on-disk, I could have done a COMPLETE Recovery of the INCOMPLETE Recovery until SEQUENCE#225.  Transactions in SEQUENCE#226 are lost because they were in the Online Redo Log that hadn't been Archived out at the Primary.

Earlier, my Primary was at SCN 12770765,  now (with the INCOMPLETE Recovery) it has been recovered to some transaction at around SCN 12773005 or thereabouts (because the OPEN RESETLOGS also increments the SCN).


Thus, I have restored from a Standby backup as of SCN 12445248 on server ora19cs1, where the ORACLE_SID and file names were STDBYDB  to SCN 12773005 as a new Primary on server ora19cP1 where the ORACLE_SID and file names are ORCLCDB

Of course, since this was an INCOMPLETE Recovery and I have created a new Incarnation of the Primary, I have to FLASHBACK the Standby to a Lower SCN  OR  Rebuild the Standby.
Had I been able to do a COMPLETE Recovery, I could have simply resumed DataGuard between the Primary and the Standby.

Note :  If the Restored Database is no longer to be a Primary in a DataGuard configuration, you can unset LOG_ARCHIVE_DEST_x  (where x is 2 or greater) and drop any Standby Log files currently defined.

30 May, 2021

Performance Hub for On-Premises Database

Previously, I have demonstrated the Performance Hub on an Oracle Autonomous Transaction Processing database on the Oracle Cloud.

 However, you can use the DBMS_PERF package for a similar report on your On-Premises database.

The code to generate such a report is (you can connect explicitly to the target PDB to generate the Performance Hub report) :

set pages 0 linesize 32767 trimspool on trim on long 1000000 longchunksize 10000000
spool DBMS_PERF_REPORT.html
select dbms_perf.report_perfhub(is_realtime=>1,type=>'active') from dual;
-- is_realtime 1 and active shows the report for the last 1hour
-- for more options see the documentation on DBMS_PERF
spool off
-- then edit the html file to remove the first line and the spool off command if necessary


I have generated a similar report for the database in my On-Premises VM.


See the 19c documentation on DBMS_PERF for more details.


Note :   The window is only 5minutes because the default selected_start_time parameter is 5minutes before the current time (i.e. the time when the report is generated)


27 May, 2021

A DDL Trigger ... and writing to the alert log file

 Below is sample code for a DDL Trigger that writes to the alert log when a specific condition is encountered.



SQL> show user
USER is "SYS"
SQL> alter session set container=orclpdb1;

Session altered.

SQL> @Drop_Table_not_permitted.sql
SQL> create or replace trigger DROP_TABLE_NOT_PERMITTED
  2  after ddl
  3  on database
  4  begin
  5    if (ora_sysevent='DROP'  and  ora_dict_obj_type = 'TABLE')
  6    then
  7   --- code for INSERT into an audit log table
  8   --- INSERT INTO ....
  9   ---
 10   --- code below is to write to the alert log file
 11   --- dbms_log is undocumented but available since 12c or 11.2.0.4
 12   ---   see https://jonathanlewis.wordpress.com/2018/10/12/dbms_log/
 13   --- dbms_log.ksdwrt is the same as dbms_system.ksdwrt
 14   ---   see https://hemantoracledba.blogspot.com/2008/11/database-event-trigger-and-sysoper.html
 15       dbms_log.ksdwrt(2,' Warning :  ' || sys_context('USERENV','SESSION_USER')
 16                      || ' tried to drop  ' || ora_dict_obj_name
 17                      || '  in SID ' || sys_context('USERENV','SID')
 18                      || ', AUDSID ' || sys_context('USERENV','SESSIONID')
 19                      || '  and service name  ' || sys_context('USERENV','SERVICE_NAME'));
 20      raise_application_error(-20001,'You are not permitted to Drop Tables');
 21    end if;
 22  end;
 23  /

Trigger created.

SQL>


When I connect to the PDB and attempt to execute a DROP TABLE ...

SQL> connect hemant/hemant@orclpdb1
Connected.
SQL> desc dummy_tab
 Name                                                           Null?    Type
 -------------------------------------------------------------- -------- ------------------------
 ID_COL                                                                  NUMBER

SQL> drop table dummy_tab;
drop table dummy_tab
           *
ERROR at line 1:
ORA-04088: error during execution of trigger 'SYS.DROP_TABLE_NOT_PERMITTED'
ORA-00604: error occurred at recursive SQL level 1
ORA-20001: You are not permitted to Drop Tables
ORA-06512: at line 17


SQL>


The alert log shows this entry :

2021-05-27T21:38:11.859746+08:00
ORCLPDB1(3): Warning :  HEMANT tried to drop  DUMMY_TAB  in SID 272, AUDSID 1061583  and service name  orclpdb1


You could use more information from SYS_CONTEXT ( I have retrieved only some pieces of information in my PL/SQL Trigger code above) and populate an Audit Log table with more information.

Comment : The "2" as the first parameter to dbms_log.ksdwrt references the instance's alert log. "1" would reference the session's trace file.  "3" would reference both files.