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.
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:
SQL> SHUTDOWN IMMEDIATE;
$ cp -R /u01/app/oracle/oradata/ORCL/* /u01/backup/ORCL/
SQL> STARTUP;
The initialization parameter files contain the configuration settings for the database instance. To create initialization parameter files for the clone database, follow these steps:
$ 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
$ vi /u01/app/oracle/product/12.1.0/dbhome_1/dbs/initCLONE.ora
Create a new directory to store the clone database files using the following command:
$ mkdir /u01/app/oracle/oradata/CLONE
To create the clone database, follow these steps:
SQL> CREATE CONTROLFILE REUSE SET DATABASE "CLONE" RESETLOGS NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292;
SQL> ALTER DATABASE MOUNT;
SQL> RESTORE DATABASE;
SQL> RECOVER DATABASE;
SQL> ALTER DATABASE OPEN RESETLOGS;
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.
To rename the clone database, follow these steps:
SQL> SHUTDOWN IMMEDIATE;
$ vi /u01/app/oracle/product/12.1.0/dbhome_1/dbs/initCLONE.ora
$ mv /u01/app/oracle/oradata/CLONE /u01/app/oracle/oradata/NEW_DB_NAME
SQL> STARTUP;
To update the listener configuration for the renamed database, follow these steps:
SQL> ALTER SYSTEM SET SERVICE_NAMES = 'NEW_DB_NAME' SCOPE=SPFILE;
$ lsnrctl stop
$ lsnrctl start
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.
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.