Showing posts with label RMAN. Show all posts
Showing posts with label RMAN. Show all posts

Tuesday, February 21, 2023

Copy Archivelogs From Standby DR to Primary

You may think the title of this article is wrong; what is the scenario that requires copying archivelogs from Standby to Primary?

I ran into a situation on a primary RAC DB data guarded by a standby RAC DB, where dozens of archivelogs were needed for goldengate replication got deleted by Oracle because of space pressure on Flash Recovery Area FRA. For my good luck, those archivelogs were still available on the Standby DB and hence in this article I'll demonstrate how to restore them back on the primary DB.

Note: Both Primary and Standby DBs are two nodes RAC, this explains why I've to specify the thread in most of RMAN commands.

Backup the Archivelogs on the Standby:

I managed to figure out the archivelogs sequence numbers I need to copy from the Standby DB and hence I used the following RMAN command to back up the needed Archivelogs on the Standby DB:

RUN{
ALLOCATE CHANNEL ch1 DEVICE TYPE DISK ;
ALLOCATE CHANNEL ch2 DEVICE TYPE DISK ;
ALLOCATE CHANNEL ch3 DEVICE TYPE DISK ;
ALLOCATE CHANNEL ch4 DEVICE TYPE DISK ;
backup as compressed backupset
archivelog sequence between 112700 and 112902 thread 1
format '/backup/archives/%d_%s_%p_%c_%t.arc.bkp'
archivelog sequence between 102590 and 102669 thread 2 format '/backup/archives/%d_%s_%p_%c_%t.arc.bkp';
}

Note: Using "as compressed backupset" option will shrink the backup file size, and it doesn't require a license.

Then, Copy the backed up Archivelogs from the Standby to one of the Primary DB nodes:
# scp /backup/archives/* oracle@primary_n1:/backup/archives


Restore the Archivelogs on the Primary:

On the Primary DB node where the backupfiles are copied, use the following command to Catalog the backup files, so they will be aware of by the Restore command:

RMAN> catalog start with '/backup/archives/';

On the same Primary Node I used the following RMAN command to restore the archives logs to their default location which is +RECO ASM diskgroup in my case:

RUN{
ALLOCATE CHANNEL ch1 DEVICE TYPE DISK ;
ALLOCATE CHANNEL ch2 DEVICE TYPE DISK ;
ALLOCATE CHANNEL ch3 DEVICE TYPE DISK ;
ALLOCATE CHANNEL ch4 DEVICE TYPE DISK ;
restore
archivelog from logseq=112700 until logseq=112902 thread 1
archivelog from logseq=102590 until logseq=102669 thread 2;
}

In case you want to restore the archivelogs to a non-default location i.e. /backup/archives/restored you can use "set archivelog destination" command as follows:

RUN{
ALLOCATE CHANNEL ch1 DEVICE TYPE DISK ;
ALLOCATE CHANNEL ch2 DEVICE TYPE DISK ;
ALLOCATE CHANNEL ch3 DEVICE TYPE DISK ;
ALLOCATE CHANNEL ch4 DEVICE TYPE DISK ;
set archivelog destination to '/backup/archives/restored';
restore
archivelog from logseq=112700 until logseq=112902 thread 1
archivelog from logseq=102590 until logseq=102669 thread 2;
}

 

Tuesday, October 11, 2022

ORA-19909: datafile 1 belongs to an orphan incarnation, After Recovering the Standby DB from Service

Scenario: 

On a 19.5 DB, I've opened the Standby in Read Write mode (ACTIVATED not SNAPSHOT mode) for testing purpose for 24 hours, which make it lag too way behind the primary and needs shipping of 700 GB of Archivelogs which will take ages to complete, So I followed the new feature of recovering the standby DB from RMAN incremental backup using the following one command:

RMAN> RECOVER STANDBY DATABASE FROM SERVICE PRC;

Problem:

After the completion of the recovery, --which took a couple of hours, I got this error in the DB alert log:

2022-10-05T18:05:52.215176+00:00
Errors in file /u01/oracle/diag/rdbms/prs/prs/trace/prs_mz00_15686.trc:
ORA-01110: data file 93: '+DATA/PRS/DATAFILE/p_data.278.1068357141'
2022-10-05T18:05:52.321877+00:00

When trying to start the recovery, it crashed, and I got the following error in the alertlog:

SQL> recover managed standby database using current logfile nodelay disconnect;

Excerpt from the alertlog:

2022-10-05T17:57:23.619258+00:00
PR00 (PID:11782): Managed Standby Recovery starting Real Time Apply
Warning: Recovery target destination is in a sibling branch
of the controlfile checkpoint. Recovery will only recover
changes to datafiles.
Datafile 1 (ckpscn 6629958934149) is orphaned on incarnation#=2
PR00 (PID:11782): MRP0: Detected orphaned datafiles!
2022-10-05T17:57:23.804939+00:00
Errors in file /u01/oracle/diag/rdbms/prs/prs/trace/prs_pr00_11782.trc:
ORA-19909: datafile 1 belongs to an orphan incarnation
ORA-01110: data file 1: '+DATA/PRS/DATAFILE/system.378.1040043713'
PR00 (PID:11782): Managed Standby Recovery not using Real Time Apply
stopping change tracking


Analysis:

As the error mentioning the incarnation, I went to RMAN to check all incarnations of the DB:

RMAN> list incarnation of database;

using target database control file instead of recovery catalog

List of Database Incarnations
DB Key  Inc Key DB Name  DB ID            STATUS  Reset SCN  Reset Time
------- ------- -------- ---------------- --- ---------- ----------
1       1       PRD  1352250453       PARENT  1          17-APR-19
2       2       PRD  1352250453       PARENT  1920977    07-MAY-20

3       3       PRD  1352250453       ORPHAN  6472651405014 12-MAY-20
4       4       PRD  1352250453       ORPHAN  6473945178918 15-JUN-20
5       5       PRD  1352250453       ORPHAN  6475796134931 07-JUL-20
6       6       PRD  1352250453       ORPHAN  6476092131516 10-JUL-20
7       7       PRD  1352250453       ORPHAN  6476262305573 12-JUL-20
8       8       PRD  1352250453       ORPHAN  6476996897342 22-JUL-20
9       9       PRD  1352250453       ORPHAN  6476997075925 22-JUL-20
10      10      PRD  1352250453       ORPHAN  6476998329789 22-JUL-20
11      11      PRD  1352250453       ORPHAN  6477049189900 22-JUL-20
12      12      PRD  1352250453       ORPHAN  6477792328248 03-AUG-20
13      13      PRD  1352250453       ORPHAN  6477896848188 04-AUG-20
14      14      PRD  1352250453       ORPHAN  6477898103437 04-AUG-20
15      15      PRD  1352250453       ORPHAN  6477898886110 04-AUG-20
16      16      PRD  1352250453       ORPHAN  6477907643794 04-AUG-20
17      17      PRD  1352250453       ORPHAN  6477908164587 04-AUG-20
18      18      PRD  1352250453       ORPHAN  6477908493572 04-AUG-20
19      19      PRD  1352250453       ORPHAN  6477908951719 04-AUG-20
20      20      PRD  1352250453       ORPHAN  6478017068793 05-AUG-20
21      21      PRD  1352250453       ORPHAN  6478101320713 06-AUG-20
22      22      PRD  1352250453       ORPHAN  6478223633690 07-AUG-20
23      23      PRD  1352250453       ORPHAN  6478226677036 07-AUG-20
24      24      PRD  1352250453       ORPHAN  6478261288240 07-AUG-20
25      25      PRD  1352250453       ORPHAN  6478262694239 07-AUG-20
26      26      PRD  1352250453       ORPHAN  6478358471117 08-AUG-20
27      27      PRD  1352250453       ORPHAN  6478434623641 09-AUG-20
28      28      PRD  1352250453       ORPHAN  6478438625990 09-AUG-20
29      29      PRD  1352250453       ORPHAN  6478446183062 09-AUG-20
30      30      PRD  1352250453       ORPHAN  6480950862854 31-AUG-20
31      31      PRD  1352250453       ORPHAN  6482153817265 09-SEP-20
32      32      PRD  1352250453       ORPHAN  6482271564751 10-SEP-20
33      33      PRD  1352250453       ORPHAN  6482286544445 10-SEP-20
34      34      PRD  1352250453       ORPHAN  6482723618944 14-SEP-20
35      35      PRD  1352250453       ORPHAN  6482800530717 15-SEP-20
36      36      PRD  1352250453       ORPHAN  6482918772612 16-SEP-20
37      37      PRD  1352250453       ORPHAN  6483074592719 17-SEP-20
38      38      PRD  1352250453       ORPHAN  6483533227915 21-SEP-20
39      39      PRD  1352250453       ORPHAN  6485299063993 05-OCT-20
40      40      PRD  1352250453       ORPHAN  6486322720680 13-OCT-20
41      41      PRD  1352250453       ORPHAN  6489734338575 10-NOV-20
42      42      PRD  1352250453       ORPHAN  6491112740659 19-NOV-20
43      43      PRD  1352250453       ORPHAN  6491676585105 23-NOV-20
44      44      PRD  1352250453       ORPHAN  6493754498541 07-DEC-20
45      45      PRD  1352250453       ORPHAN  6505194885552 16-FEB-21
46      46      PRD  1352250453       ORPHAN  6506134480796 21-FEB-21
47      47      PRD  1352250453       ORPHAN  6506147964368 21-FEB-21
48      48      PRD  1352250453       ORPHAN  6506415997452 23-FEB-21
49      49      PRD  1352250453       ORPHAN  6516084726181 21-APR-21
50      50      PRD  1352250453       ORPHAN  6516942842956 26-APR-21
51      51      PRD  1352250453       ORPHAN  6520146079148 23-MAY-21
52      52      PRD  1352250453       ORPHAN  6522049248024 06-JUN-21
53      53      PRD  1352250453       ORPHAN  6529792338188 28-JUL-21
54      54      PRD  1352250453       ORPHAN  6533931540996 22-AUG-21
55      55      PRD  1352250453       ORPHAN  6541654583957 27-SEP-21
56      56      PRD  1352250453       ORPHAN  6547395262155 20-OCT-21
57      57      PRD  1352250453       ORPHAN  6549851396517 31-OCT-21
58      58      PRD  1352250453       ORPHAN  6549859042608 31-OCT-21
59      59      PRD  1352250453       ORPHAN  6554974463446 21-NOV-21
60      60      PRD  1352250453       ORPHAN  6555002692454 21-NOV-21
61      61      PRD  1352250453       ORPHAN  6560037620145 12-DEC-21
62      62      PRD  1352250453       ORPHAN  6572404510789 07-FEB-22
63      63      PRD  1352250453       ORPHAN  6573278923413 10-FEB-22
64      64      PRD  1352250453       ORPHAN  6573612206898 11-FEB-22
65      65      PRD  1352250453       ORPHAN  6574219150557 14-FEB-22
66      66      PRD  1352250453       ORPHAN  6574446599929 15-FEB-22
67      67      PRD  1352250453       ORPHAN  6574733753234 16-FEB-22
68      68      PRD  1352250453       ORPHAN  6575284306973 18-FEB-22
69      69      PRD  1352250453       ORPHAN  6575932360856 21-FEB-22
70      70      PRD  1352250453       ORPHAN  6576184619358 22-FEB-22
71      71      PRD  1352250453       ORPHAN  6576483271333 23-FEB-22
72      72      PRD  1352250453       ORPHAN  6576483271333 23-FEB-22
73      73      PRD  1352250453       ORPHAN  6576488218054 23-FEB-22
74      74      PRD  1352250453       ORPHAN  6576751793528 24-FEB-22
75      75      PRD  1352250453       ORPHAN  6576760598850 24-FEB-22
76      76      PRD  1352250453       ORPHAN  6577014030463 25-FEB-22
77      77      PRD  1352250453       ORPHAN  6577276447034 26-FEB-22
78      78      PRD  1352250453       ORPHAN  6577498266856 27-FEB-22
79      79      PRD  1352250453       ORPHAN  6577655247878 28-FEB-22
80      80      PRD  1352250453       ORPHAN  6577922958840 01-MAR-22
81      81      PRD  1352250453       ORPHAN  6578182486068 02-MAR-22
82      82      PRD  1352250453       ORPHAN  6578472039163 03-MAR-22
83      83      PRD  1352250453       ORPHAN  6578790664228 04-MAR-22
84      84      PRD  1352250453       ORPHAN  6578791447776 04-MAR-22
85      85      PRD  1352250453       ORPHAN  6579600980093 08-MAR-22
86      86      PRD  1352250453       ORPHAN  6580043914718 09-MAR-22
87      87      PRD  1352250453       ORPHAN  6581184664237 15-MAR-22
88      88      PRD  1352250453       ORPHAN  6585156574467 29-MAR-22
89      89      PRD  1352250453       ORPHAN  6585320699260 30-MAR-22
90      90      PRD  1352250453       ORPHAN  6594564672284 17-MAY-22
91      91      PRD  1352250453       ORPHAN  6601496376855 16-JUN-22
92      92      PRD  1352250453       CURRENT 6629485928030 04-OCT-22

There are tons of orphan incarnations found, but there are only 2 PARENT incarnations and 1 CURRENT, definitely the CURRENT incarnation is not working for my DB, so I've to set the DB incarnation to one of the PARENT ones.

Solution:

Reset the incarnation of the database to the most recent "Reset SCN"  PARENT incarnation, from above output incarnation# 2 is the one with most recent "Reset SCN"

RMAN> reset database to incarnation 2;

database reset to incarnation 2


References:

Roll Forward Physical Standby Using RMAN Incremental Backup in Single Command (Doc ID 2431311.1)

Monday, July 25, 2022

Recover a TRUNCATE TABLE Statement Using FLASHBACK DATABASE Feature

Scenario Summary:

This was a real production scenario I've gone through to restore big number of tables been truncated mistakenly by someone who ran a script that suppose to run on test environment. The DB version is 11.2.0.4 and the Flashback Database feature was turned ON.

Scenario Details:

- An Architect mistakenly ran a script to truncate multiple tables on production DB instead of running it on Test DB --Was opening multiple windows at the same time, one of them was Prod.
- The issue been identified few hours later.
- Because of the late identification of the issue, other applications which were not impacted by that truncation has loaded data on other tables sharing the same tablespace of the truncated tables.
- Due to the storage free space constraint on the same server and because of other infrastructure limitations, it was very difficult to restore the impacted tablespace to a point in time in the same server or even in a different server.
- I decided to use the Flashback Database approach to restore those tables, as I managed to get a downtime for 1 hour on the impacted DB.


Facts: 

- If your DB version is 12c and above I recommend you to use "RECOVER TABLE" RMAN command to restore the truncated tables instead of using Flashback method explained in this article; unfortunately, because my impacted DB version was 11.2.0.4, "Recover Table" feature is not available.

- When it comes to recover from a TRUNCATE statement in 11g, you will end up having few recoverability options to select from. Up to Oracle 19c, still "FLASHBACK TABLE" feature cannot recover a TRUNCATE operation, because this feature is dependent on UNDO data which get invalidated if a DDL get executed against the table which change its architecture, TRUNCATE is doing the same by moving the table's high watermark.
Available options to recover a TRUNCATE statement can be using "Flashback Data Archive" feature, if it's enabled before the truncation, otherwise the best option you will have in your arsenal is to flash back the whole DB, then export the impacted tables, then flash forward/recover the DB to return it back to its latest status, then import the impacted tables. This solution involves a downtime on the whole DB. Another option you can use; is to restore the whole tablespace --where the truncated tables reside to a point in time to a different/new DB and export the truncated tables from there and import them back to the impacted DB.

- To Flash back a database using Flashback Database feature, the following requirements should be met:

    1- Flashback Database feature should be turned on before the truncation.
    2- All the Flashback Logs generated up to the time before the truncation should be available on the server (FRA).
    3- All the Archive Logs generated up to before the truncation time should be available on the server.(either as files or backup pieces).

V.Imp Note:
Once you come to know about the truncation incident, DO NOT change the DB structure by CREATE OR DELETE any TABLESPACE or DATAFILE, or SHRINK a DATAFILE or RECREATE the CONTROLFILE as this may invalidate the recovery when you try to recover the DB to flash it forward to the original status!


Technical Steps:

Check the prerequsites for the Flashback to succeed:

- Check how far the DB can be flashed back:

SQL> col OLDEST_FLASHBACK_SCN for 999999999999999999999
           select * from V$FLASHBACK_DATABASE_LOG;

- Increase the flashback retention to avoid the auto-deletion of the Flashback archive files: [e.g. 4 days]

SQL> alter system set db_flashback_retention_target=6000;

- Stop/Disable any cron or backup jobs that can delete any RMAN backups or archivelogs: [Until the truncated tables get restored]

Get the SCN just before the truncation time: [Just before the errorenous truncate]

My Truncation time happened at 11/07/2022 18:00:12

-- Convert Timestamp to SCN

SQL> col scn for 999999999999999999999999
           select timestamp_to_scn(to_timestamp('11/07/2022 18:00:00','DD/MM/YYYY HH24:MI:SS')) as scn from dual;





- Check the availability of the archive logs required to cover the flashback period: [Requirement for Flashback to succeed]

SQL> select SEQUENCE#,FIRST_TIME from v$archived_log where FIRST_TIME>sysdate-1;

For my bad luck only the last 6 hours archive logs are available on the server, which means I need to restore the older archives to cover the last 24 hours needed for the flashback to work:

- Checking the needed Archive logs that are not available and restore them:

SQL> select SEQUENCE#,FIRST_TIME from v$archived_log where FIRST_TIME>sysdate-1 and name is  null;


 

- Restore the needed Archive logs from TAPE to the server: [Below tape parameters are specific to my environment]

RMAN> run
{
allocate channel 'dev_1' type 'sbt_tape' parms 'SBT_LIBRARY=/opt/omni/lib/libob2oracle8_64bit.so,ENV=(OB2BARTYPE=Oracle8,OB2APPNAME=DB01,OB2BARLIST=RDB01_ORCL_Arch _Log_SO)';
#send device type 'sbt_tape' 'OB2BARHOSTNAME=rdb01';
set archivelog destination to '/backup/arch/';
restore archivelog from sequence 470 until sequence 485;
}



-- Catalog the restored archivelogs:

RMAN> catalog start with '/backup/arch';


It's always wise to take a full DB backup before starting the flashback task, just in case the DB have a problem with flashing it forward.



Flashback the DB to before the tables truncation time:

-- Note down the current SCN:
SQL> col current_scn for 999999999999999999999999
           select current_scn from v$database;


6605314662302

-- Flashback the DB to before the Truncation:

SQL> alter system checkpoint;
SQL> shu immediate
           startup mount

>>From rman:
# rman target /
RMAN> FLASHBACK DATABASE TO SCN 6607836579369;

-- Open the DB in Read Only mode:
RMAN> alter database open read only;


Export the truncated tables: [Using legacy exp as expdp will not work in Read Only mode]

# exp  \'/ as sysdba\' TABLES=PL.F_PRICE,PL.E_CODES,PL.ET_STATUS,PL.BATCH_SO,PL.FL_INFO DIRECT=y CONSISTENT=y STATISTICS=NONE FEEDBACK=100000 RESUMABLE=y RESUMABLE_NAME=DBA_BUNDLE_EXPORT RESUMABLE_TIMEOUT=86400 FILE=/backup/EXPORT_TABLES.dmp log=/backup/EXPORT_TABLES.log

Note: Because legacy exp tool doesn't provide parallelism option, you can make your own parallelism by running the same exp command from different sessiosns providing different set of tables in each session and run them at the same time.

Once the export is done, Return the DB back to its original state before the flashback:

-- First use recover technique to recover the DB until the latest REDOLOG:
   SQL> SHU IMMEDIATE
   SQL> STARTUP MOUNT

  # rman target /
   RMAN> recover database;
   RMAN> alter database open;

Unfortunately, in my case a new tablespace was created after the truncation of tables which made the above command to fail, so instead of using "recover database" command I had to use the FLASHBACK command using the SCN I noted down before the first shutdown of the DB.

If recover technique didn't work use Flashback:
-- From mount mode:
RMAN> FLASHBACK DATABASE TO SCN 6605314662302;
RMAN> alter database open resetlogs;

Once the DB is open in RW mode,

Import the dump file to recover the truncated tables:


-- Disable the triggers on the truncated tables first: [If found]
SQL> select 'alter trigger '||owner||'.'||trigger_name||' disable;' from dba_triggers where owner='PL' and table_name in ('F_PRICE','E_CODES','ET_STATUS','BATCH_SO','FL_INFO');

-- You can also set the tables into NOLOGGING mode (if you have no data guard setup)

-- Execute the import commands:
I distributed the tuncated tables on three sets based on their size, then execute each set in the background to have the tables get imported in parallel:

Note: In my real case I used INDEXES=N parameter during the import as I've collected the DDL for all indexes on the impacted tables before the import, then dropped them, and lastly created them back after the import with high PARALLEL degree and NOLOGGING option to save the time.

# Set1:
nohup imp  \'/ as sysdba\' fromuser=PL touser=PL TABLES=F_PRICE, E_CODES  file=/backup/EXPORT_TABLES.dmp log=/backup/imp_PL_truncated_tables_set1.log ignore=y  RESUMABLE=Y RESUMABLE_NAME=SET1_SUSPENDED resumable_timeout=3600 commit=y buffer=10240 feedback=10000  > nohup1.log 2>&1 &

 

# Set2:
nohup imp  \'/ as sysdba\' fromuser=PL touser=PL TABLES=BATCH_SO  file=/backup/EXPORT_TABLES.dmp log=/backup/imp_PL_truncated_tables_set2.log ignore=y  RESUMABLE=Y RESUMABLE_NAME=SET2_SUSPEND  resumable_timeout=3600 commit=y buffer=10240 feedback=10000  > nohup1.log 2>&1 &

 

# Set3:
nohup imp  \'/ as sysdba\' fromuser=PL touser=PL TABLES=FL_INFO  file=/backup/EXPORT_TABLES.dmp log=/backup/imp_PL_truncated_tables_set3.log ignore=y  RESUMABLE=Y RESUMABLE_NAME=SET3_SUSPEND  resumable_timeout=3600 commit=y buffer=10240 feedback=10000  > nohup1.log 2>&1 &


After the completion of the import:

-- Enable the constraints: [In case the import fails to enable them]
SQL> select 'alter table pnl_owner.'||table_name||' ENABLE CONSTRAINT '|| constraint_name||' ;' from dba_constraints where owner='PNL_OWNER' and table_name in ('ADV_STG_FUEL_INFO','DIM_FUEL_PRICE','ERROR_CODES','PNL_ETL_JOB_STATUS','DIM_INFLIGHT','SYS_C0029531 DIM_STANDARD_COSTS','PROCESS_EXECUTION_STATISTICS','STG_CARGO','STG_FUEL_INFO','STG_RCT_INFO','WEEKLY_CARGO','DIM_CURRENCY','DIM_GLOBAL_VAL','DIM_OTHER_INC','DIM_SERVICE_TYPE_AIMS','PROCESS_CHECKLIST','SNAPSHOT_WORKING','STG_BSP_REVENUE');

-- Enable back the triggers: [In case you disabled them before the import]
SQL> select 'alter trigger '||owner||'.'||trigger_name||' enable;' from dba_triggers where owner='PNL_OWNER' and STATUS='DISABLED' and table_name in ('ADV_STG_FUEL_INFO','DIM_FUEL_PRICE','ERROR_CODES','PNL_ETL_JOB_STATUS','BATCH_STATUS','DIM_INFLIGHT','SYS_C0029531 DIM_STANDARD_COSTS','PROCESS_EXECUTION_STATISTICS','STG_CARGO','STG_FUEL_INFO','STG_RCT_INFO','WEEKLY_CARGO','DIM_CURRENCY','DIM_GLOBAL_VAL','DIM_OTHER_INC','DIM_SERVICE_TYPE_AIMS','PROCESS_CHECKLIST','SNAPSHOT_WORKING','STG_BSP_REVENUE','WEEKLY_UNUTILIZED_BLOCK','STANDARD_BASE_AUDIT','DIM_PROV_NON_REPATRIABLE_FUNDS','STG_PAX_INFO','DIM_DOC_RATES','APEX_UPLOAD_STATUS','DAILY_UNUTLZD_BLOCK','DIM_ROUTES','WEEKLY_REVENUE','DATA_LOADING_INFO','DIM_CREW_LO','DIM_DATE','DIM_FLT_SCHEDULE','DIM_REV_CODES','EMAIL_LOG','FINAL_STANDARDS','STANDARD_BASE','DIM_HEDGED_QTY','FLT_SECTOR_PAIR','DIM_AIRPORTS','THRESHOLD_SETTINGS','AUDIT_BATCH_STATUS','PNL_ETL_EMAIL_CONFIG','MONTHLY_ACTUALS_FEEDER','STG__OAL_NO_SHOW_PAX','STG_MEAL_REV_CNT','STG_OAL_NO_SHOW_PAX','STG_RCT_DETAILS','PARAMRTAG','DIM_INFLIGHT_PARAM','STG_UNUTLZD_BLOCK');

Reset back the Flashback retention to its original setting:
SQL> alter system set db_flashback_retention_target=3000;

Enable back the disabled cron and backup jobs which you may disabled before the flashback:

Gather statistics on the imported tables:
EXEC DBMS_STATS.GATHER_TABLE_STATS('PL', 'F_PRICE');
EXEC DBMS_STATS.GATHER_TABLE_STATS('PL', 'E_CODES');
EXEC DBMS_STATS.GATHER_TABLE_STATS('PL', 'ET_STATUS');
EXEC DBMS_STATS.GATHER_TABLE_STATS('PL', 'BATCH_SO');
EXEC DBMS_STATS.GATHER_TABLE_STATS('PL', 'FL_INFO');

It's always wise to take a Full DB Backup after such activity 😀



 

Saturday, March 26, 2022

RMAN Duplicate hang on error: WAITED TOO LONG FOR A ROW CACHE ENQUEUE LOCK!

Problem:

I was trying to duplicate a 19c database from an RMAN backup, but it was hanging at this final stage of opening the cloned DB in resetlogs mode:

Analysis:

When checked the alertlog I found the following messages in the alertlog:

2022-03-21T13:14:26.588816+00:00
>>> WAITED TOO LONG FOR A ROW CACHE ENQUEUE LOCK! pid=58
System State dumped to trace file /oracle/19.5/diag/rdbms/uat3/uat3/trace/UAT3_p00e_5888.trc
2022-03-21T13:14:27.941400+00:00
TT03 (PID:5858): Sleep 160 seconds and then try to clear SRLs in 8 time(s)
2022-03-21T13:17:07.941846+00:00
TT03 (PID:5858): Sleep 320 seconds and then try to clear SRLs in 9 time(s)
2022-03-21T13:18:01.355711+00:00
********************  WARNING **************************
The errors during server control file autobackup are not
fatal, as it is attempted after sucessful completion of
the command. However, it is recomended to take an RMAN
control file backup as soon as possible because the
autobackup failed with the following error:
ORA-00237: snapshot operation disallowed: control file newly created

********************  END OF WARNING *******************

 After a long search, I figured out that it's Bug 30931981 which impacts 19c and was fixed in 21c, also I figured that I'm having more patches installed on the target cloned target DB ORACLE_HOME compared to the ones installed on the source DB ORACLE_HOME which I'm cloning from.

Solution:

Permanent: Apply patch 30931981

Workaround: Make sure the target "cloned DB" ORACLE HOME is having same patches installed as similar to the source DB you are cloning from.


Friday, March 25, 2022

Duplicate of a Standby DB from an RMAN backup throws RMAN-05657: There are multiple database IDs present

 Problem:

The RMAN duplicate command for creating a standby database from a backup throws the following error, just right after allocating auxiliary channels:

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 03/24/2022 13:32:59
RMAN-05501: aborting duplication of target database
RMAN-05657: There are multiple database IDs present.

Solution:

Try to set the same DBID of the primary DB in the duplicate script of the standby DB:

Get the DBID from the primary DB:

SQL> select dbid from v$database;

      DBID
----------
1352250453

 

Or from the RMAN backup logfile:

Then set the DBID in the duplicate script like this:

set dbid 1352250453
run {
allocate auxiliary channel aux1 type disk;
...
duplicate target database for standby backup location '/backup/RMANBKP' nofilenamecheck
spfile
...
}

Good luck!


Wednesday, March 9, 2022

Continue the Duplicate after RMAN-06054: media recovery requesting unknown archived log

 Problem:

During the execution of Duplicate RMAN command to create a new 19c database from an RMAN backup, the duplicate processes terminated with RMAN-06054 before the completion of the duplicate process:

Analysis:

The backup I was restoring from was missing some critical archivelogs to bring all datafiles in a consistent state. Luckily, the datafile which was inconsistent belonged to goldengate tablespace which I don't need it in the new database.

ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
ORA-01194: file 68 needs more recovery to be consistent
ORA-01110: data file 68: '+DATA/SPP/DATAFILE/ggtbs.339.1098850765'

Solution:

1- Backup the current controlfile [In case things may go wrong, and you want to restore it back]

SQL> ALTER DATABASE BACKUP CONTROLFILE TO '/home/oracle/controlfile.bkp';

2- Generate the controlfile script with the RESETLOGS option:

-- Generate the controlfile script:

SQL> ALTER DATABASE BACKUP CONTROLFILE TO TRACE AS '/home/oracle/controlfile.trc' RESETLOGS;

-- Edit the controlfile trace script adding "SET" keyword: [If you will change the database name, make sure to modify the parameter db_name in the SPFILE to the same as well]

CREATE CONTROLFILE REUSE SET DATABASE "SPP" RESETLOGS
...

CHARACTER SET AL32UTF8
;

 

Delete the rest of lines after CHARACTER SET XXX ;

3- Shutdown the database and recreate the controlfile using the edited trace script:

SQL> shu abort
SQL> @/home/oracle/controlfile.trc

4- Set the inconsistent datafile in OFFLINE mode:

SQL> alter database datafile '+DATA/SPP/DATAFILE/ggtbs.339.1098850765' offline;

5- Open the database with RESETLOGS mode:

 SQL> ALTER DATABASE OPEN RESETLOGS;

6- Add TEMP FILES to the TEMPORARY TABLESPACE:

SQL> ALTER TABLESPACE TEMP ADD TEMPFILE;

Note: Setting parameter "_allow_resetlogs_corruption"=TRUE scope=spfile; may be an option here if you cannot set the datafiles in OFFLINE mode for any reason, but first you need to consult Oracle support before doing so; as the database will not be in a consistent state and most probably you will hit ora-00600 errors frequently!