Cloning and/or Renaming an Oracle Database 12c

How to Clone and/or Rename an Oracle Database 12c

Posted by Daniel Brody on March 14, 2023 · 6 mins read

Cloning and/or Renaming an Oracle Database 12c

Cloning an Oracle Database is the process of creating a copy of an existing database. This is useful when you need to create a testing or development environment that is identical to the production environment. Renaming an Oracle database is the process of changing the database name. This is useful when you need to change the name of the database to reflect a new business requirement or naming convention. In this tutorial, we will walk you through the steps to clone and rename an Oracle database.

Prerequisites:

  • A working Oracle database instance with SYSDBA privileges
  • Sufficient disk space to store the cloned database

Step 1: Create a Cold Backup of the Source Database

A cold backup is a backup taken while the database is shut down. This backup will be used to create the clone database. To take a cold backup of the source database, follow these steps:

  1. Log in to the database using the SYSDBA privileges.
  2. Shut down the database using the following command:
    • SQL> SHUTDOWN IMMEDIATE;
  3. Copy the database files to a backup directory using the following command:
    • $ cp -R /u01/app/oracle/oradata/ORCL/* /u01/backup/ORCL/
  4. Start the database using the following command:
    • SQL> STARTUP;

Step 2: Create Initialization Parameter Files for the Clone Database

The initialization parameter files contain the configuration settings for the database instance. To create initialization parameter files for the clone database, follow these steps:

  1. Copy the initialization parameter file of the source database to a new location using the following command:
    • $ cp /u01/app/oracle/product/12.1.0/dbhome_1/dbs/initORCL.ora /u01/app/oracle/product/12.1.0/dbhome_1/dbs/initCLONE.ora
  2. Open the initialization parameter file for the clone database using a text editor:
    • $ vi /u01/app/oracle/product/12.1.0/dbhome_1/dbs/initCLONE.ora
  3. Edit the following parameters in the initialization parameter file to reflect the new database name:
    • DB_NAME
    • DB_UNIQUE_NAME
    • CONTROL_FILES
    • DB_FILE_NAME_CONVERT
    • LOG_FILE_NAME_CONVERT
  4. Save and close the initialization parameter file.

Step 3: Create a New Directory for the Clone Database Files

Create a new directory to store the clone database files using the following command:

  • $ mkdir /u01/app/oracle/oradata/CLONE

Step 4: Create the Clone Database

To create the clone database, follow these steps:

  1. Connect to the database using the SYSDBA privileges.
  2. Run the following command to create a new control file for the clone database:
    • SQL> CREATE CONTROLFILE REUSE SET DATABASE "CLONE" RESETLOGS NOARCHIVELOG
    • MAXLOGFILES 16
    • MAXLOGMEMBERS 3
    • MAXDATAFILES 100
    • MAXINSTANCES 8
    • MAXLOGHISTORY 292;
  3. Mount the clone database using the following command:
    • SQL> ALTER DATABASE MOUNT;
  4. Restore the cold backup of the source database to the clone database using the following command:
    • SQL> RESTORE DATABASE;
  5. Recover the clone database using the following command:
    • SQL> RECOVER DATABASE;
  6. Open the clone database using the following command:
    • SQL> ALTER DATABASE OPEN RESETLOGS;

Step 5: Test the Clone Database

To test the clone database, log in to the database using SQL*Plus and run some test queries to verify that the clone database is working correctly.

Step 6: Rename the Clone Database

To rename the clone database, follow these steps:

  1. Shut down the clone database using the following command:
    • SQL> SHUTDOWN IMMEDIATE;
  2. Edit the initialization parameter file for the clone database to reflect the new database name using a text editor:
    • $ vi /u01/app/oracle/product/12.1.0/dbhome_1/dbs/initCLONE.ora
    • Change the value of the DB_NAME parameter to the new database name.
    • Save and close the initialization parameter file.
  3. Rename the directory that contains the clone database files using the following command:
    • $ mv /u01/app/oracle/oradata/CLONE /u01/app/oracle/oradata/NEW_DB_NAME
  4. Start the clone database using the following command:
    • SQL> STARTUP;

Step 7: Update the Listener Configuration

To update the listener configuration for the renamed database, follow these steps:

  1. Log in to the database using the SYSDBA privileges.
  2. Run the following command to change the service name for the renamed database:
    • SQL> ALTER SYSTEM SET SERVICE_NAMES = 'NEW_DB_NAME' SCOPE=SPFILE;
  3. Stop and restart the listener using the following commands:
    • $ lsnrctl stop
    • $ lsnrctl start

Step 8: Verify the Renamed Database

To verify that the renamed database is working correctly, log in to the database using SQL*Plus and run some test queries. Also, check the listener status to make sure that it is listening to the new database name.

Conclusion:

Cloning and renaming an Oracle database can be a complex process, but it is a useful tool for creating testing and development environments and adapting to changing business requirements. By following the steps outlined in this tutorial, you can create a clone of an existing database and rename it to reflect a new database name or naming convention. Remember to test the cloned and renamed database thoroughly before deploying it in a production environment.


  • HowTo: Clone Oracle Database 12c
  • March 14, 2023
  • Brody, Daniel
  • COPYRIGHT 2022 Yom Shore Ventures LLC - All Rights Reserved