Monday, November 11, 2013

Unregister database in RMAN catalog database without RMAN

Sometimes you remove a database and forgot to unregister the database in the RMAN catalog database.

This can happen in an environment where you clone databases quite often for testing purposes.
In this case you can't easily connect via RMAN to the catalog database and issue a unregister database command.

 But there is a solution out there which basically was the only solution in the beginning of RMAN catalog database:

1. First, go to the database you wish to unregister and find the DBID:

 SQL> select dbid,name from v$database;

DBID       NAME 
—————–     —————————— 
1122334455 ORCL 

2. Second, connect to the recovery catalog database as schema owner and get the DB_KEY of the database :

 SQL> select db_key,dbid,name from rc_database where dbid = 1122334455;

DB_KEY    DBID       NAME 
—————–    —————–     —————————— 
888888888 1122334455 ORCL

3. Thrird, You can use the PL_SQL Procedure dbms_rcvcat.unregisterdatabase(db_key,db_id) to unregister the database.
Please provide the db_key and db_id from the previous query. Connected as the RMAN catalog owner run:
SQL> execute dbms.rcvcat.unregisterdatabase(888888888 , 1122334455);
 PL/SQL procedure successfully completed.

 Your database is now removed from the catalog database.