"ORA-02291: integrity constraint (RCUSER.RLH_F1) violated - parent key not found " while register database in recovery catalog
1.1. Error
RMAN> register database;
database registered in recovery catalog
starting full resync of recovery catalog
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03008: error while performing automatic resync of recovery catalog
ORA-02291: integrity constraint (RCUSER.RLH_F1) violated - parent key not found
1.2. Cause
A foreign key value has no matching primary key value.
1.3. Action:
Delete the foreign key or add a matching primary key.
1.4. Steps to diagnose
1.4.1. Check violate foreign key definition to find out which table and column are refered
SELECT CON.*,
R.OWNER REF_OWNER,
R.TABLE_NAME REF_TAB_NAME,
R.COLUMN_NAME REF_COL_NAME
FROM (SELECT C.OWNER,
C.CONSTRAINT_NAME,
C.CONSTRAINT_TYPE,
C.TABLE_NAME,
C.DELETE_RULE,
C.R_CONSTRAINT_NAME,
COL.COLUMN_NAME,
COL.POSITION
FROM USER_CONS_COLUMNS COL, USER_CONSTRAINTS C
WHERE C.OWNER = 'RCUSER'
AND C.CONSTRAINT_NAME = 'RLH_F1'
AND C.OWNER = COL.OWNER
AND C.CONSTRAINT_NAME = COL.CONSTRAINT_NAME) CON,
USER_CONS_COLUMNS R
WHERE CON.R_CONSTRAINT_NAME = R.CONSTRAINT_NAME;
OWNER CONSTRAINT_NAME C TABLE_NAME DELETE_RU R_CONSTRAINT_NAME
-------------------- ------------------------------ - -------------------- --------- --------------------
COLUMN_NAME POSITION REF_OWNER REF_TAB_NAME REF_COL_NAME
-------------------- ---------- -------------------- -------------------- --------------------
RCUSER RLH_F1 R RLH CASCADE DBINC_P
DBINC_KEY 1 RCUSER DBINC DBINC_KEY
SELECT DBMS_METADATA.GET_DDL('REF_CONSTRAINT','RLH_F1') FROM DUAL;
ALTER TABLE "RCUSER"."RLH" ADD CONSTRAINT "RLH_F1" FOREIGN KEY ("DBINC_KEY")
REFERENCES "RCUSER"."DBINC" ("DBINC_KEY") ON DELETE CASCADE ENABLE
SELECT DBMS_METADATA.GET_DDL('CONSTRAINT','DBINC_P') FROM DUAL;
ALTER TABLE "RCUSER"."DBINC" ADD CONSTRAINT "DBINC_P" PRIMARY KEY ("DBINC_KEY")
From the excerpt ,RCUSER.RLH foreign key RLH_F1 is refered on table RCUSER.DBINC (DBINC_KEY) with the delete option"cascade".
RCUSER.DBINC column DBINC_KEY has primary key .
1.4.2. Check the record on RCUSER.DBINC table
SQL> select * from dbinc;
DBINC_KEY DB_KEY DB_NAME RESET_SCN RESET_TIM PARENT_DBINC_KEY DBINC_ST
---------- ---------- -------- ---------- --------- ---------------- --------
754 753 ORA11G 945184 16-SEP-17 CURRENT
DBINC_KEY exists on DBIC table for database ORA11G which is the cause of failure registration .
When "unregister database",record delete from rc_rlh but parent key still exists in dbinc.
1.4.3. Check the record in both dbinc &rc_database
SQL> select * from dbinc;
DBINC_KEY DB_KEY DB_NAME RESET_SCN RESET_TIM PARENT_DBINC_KEY DBINC_ST
---------- ---------- -------- ---------- --------- ---------------- --------
754 753 ORA11G 945184 16-SEP-17 CURRENT
SQL> select * from rc_database;
DB_KEY DBINC_KEY DBID NAME RESETLOGS_CHANGE# RESETLOGS
---------- ---------- ---------- -------- ----------------- ---------
753 754 56040598 ORA11G 945184 16-SEP-17
==Another session:
RMAN> resync catalog;
starting full resync of recovery catalog
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of resync command on default channel at 03/22/2018 20:49:26
ORA-02291: integrity constraint (RCUSER.RLH_F1) violated - parent key not found
Even dbinc_key exists in both dbinc and rc_database .However when run "resync catalog" still failed .
1.4.4. Solution
When unregister database from recovery catalog , need to use dbms_rcvcat.unregisterdatabase procedure instead of "unregister database "
SQL> exec dbms_rcvcat.unregisterdatabase('754','56040598');
PL/SQL procedure successfully completed.
SQL> select * from dbinc;
no rows selected
SQL> select * from rc_database;
no rows selected