Oracle RMAN Unregister Database from Recovery Catalog or rc_database

Oracle RMAN Unregister Database from Recovery Catalog

Purpose

Unregistering a database from an Oracle RMAN (Recovery Manager) recovery catalog removes all backup metadata and database information from the catalog repository. This process is essential when a database is decommissioned, no longer needs catalog-based backups, or when you need to clean up old database entries that are no longer accessible. The DBMS_RCVCAT package provides a direct SQL method to remove database registrations without requiring access to the target database.

Code Breakdown

Original Code

1sqlplus user/pass@rmandb
2select * from rc_database;
3select db_key, db_id from db;
4execute dbms_rcvcat.unregisterdatabase(<db_key>, <db_id>);

Line-by-Line Explanation

Line 1: Connect to Recovery Catalog Database

1sqlplus user/pass@rmandb

This command connects to the recovery catalog database using SQL*Plus. Replace user with the recovery catalog owner username (typically the schema that owns the catalog), pass with the password, and rmandb with the TNS alias for your catalog database.

Line 2: Query All Registered Databases

1select * from rc_database;

This query displays all databases registered in the recovery catalog. The RC_DATABASE view contains critical information including DB_KEY, DBID, and database NAME for each registered database.

Line 3: Query Database Key and ID

1select db_key, db_id from db;

This retrieves the specific DB_KEY and DB_ID (DBID) values needed for unregistration. A more accurate query would be: select db_key, dbid, name from rc_database where name = 'YOUR_DB_NAME'; to filter for your specific database.

Line 4: Execute Unregister Procedure

1execute dbms_rcvcat.unregisterdatabase(<db_key>, <db_id>);

This PL/SQL command removes the database registration from the catalog using the DBMS_RCVCAT package. Replace <db_key> and <db_id> with the actual numeric values from the previous query.

Key Points

  • No Target Database Access Required: This method works even when the target database is destroyed or inaccessible
  • Complete Metadata Removal: The procedure removes all backup sets, archived logs, data file copies, and database structure information from the catalog
  • Execution Time: The unregisterdatabase procedure can take 10-15 minutes to complete on systems with extensive backup history
  • Correct Parameter Order: Always use DB_KEY first, then DBID as parameters
  • Catalog Owner Required: You must connect as the recovery catalog owner, not the target database owner

Best Practices

Query Before Deletion

Always verify the database information before unregistering:

1select db_key, dbid, name from rc_database where name = 'TARGET_DB';

Complete Example

 1SQL> connect rman/rman@catdb
 2Connected.
 3SQL> select db_key, dbid, name from rc_database where name = 'PRODDB';
 4
 5DB_KEY       DBID NAME
 6---------- ---------- --------
 723085      1312293510 PRODDB
 8
 9SQL> execute dbms_rcvcat.unregisterdatabase(23085, 1312293510);
10PL/SQL procedure successfully completed.

Alternative Methods

Oracle provides multiple unregistration options:

  • RMAN Command with Target: Use when target database is accessible
  • RMAN Command Catalog Only: Use UNREGISTER DATABASE command from RMAN without target connection (Oracle 10g+)
  • DBMS_RCVCAT Package: Use when working directly in SQL*Plus

Important Considerations

  • The recovery catalog must be open and accessible
  • Standby databases sharing the same DBID will also be affected
  • This operation cannot be easily reversed; ensure you have the correct DB_KEY and DBID
  • For Data Guard environments, unregistering the primary database removes all associated standby databases

Common Issues

Issue: Wrong table name in query

  • Solution: Use rc_database not just db for the complete query

Issue: Procedure takes too long

  • Expected: Can run 10-15 minutes for databases with extensive backup history

Issue: Multiple databases with same name

  • Solution: Use DBID to uniquely identify the correct database

References

Posts in this series