Tuesday, July 5, 2022

Change CDB and PDB names in 12c

Change CDB name from DEVCDB to TESTCDB

*********************************************
Backup database before performing this action
*********************************************



	

SQL> SHUTDOWN IMMEDIATE;
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> STARTUP MOUNT
ORACLE instance started.
Total System Global Area 2.0133E+10 bytes
Fixed Size                  3721176 bytes
Variable Size            2684356648 bytes
Database Buffers         1.7381E+10 bytes
Redo Buffers               63385600 bytes
Database mounted.
SQL> exit

[oracle@hostname ~]$ nid TARGET=/ DBNAME=TESTCDB
DBNEWID: Release 12.1.0.2.0 - Production on Fri Jul 1 12:44:48 2022
Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.
Connected to database DEVCDB (DBID=2721637057)
Connected to server version 12.1.0
Control Files in database:
    /oradata/devcdb/oradata/DEVCDB/controlfile/o1_mf_kcx8zx9n_.ctl
    /oradata/devcdb/fast_recovery_area/DEVCDB/controlfile/o1_mf_kcx8zxcj_.ctl
Change database ID and database name DEVCDB to TESTCDB? (Y/[N]) => Y
Proceeding with operation
Changing database ID from 2721637057 to 2850317248
Changing database name from DEVCDB to TESTCDB
    Control File /oradata/devcdb/oradata/DEVCDB/controlfile/o1_mf_kcx8zx9n_.ctl - modified
    Control File /oradata/devcdb/fast_recovery_area/DEVCDB/controlfile/o1_mf_kcx8zxcj_.ctl - modified
    Datafile /oradata/devcdb/oradata/DEVCDB/datafile/o1_mf_system_kcx8xpcx_.db - dbid changed, wrote new name
    Datafile /oradata/devcdb/oradata/DEVCDB/datafile/o1_mf_sysaux_kcx8wm74_.db - dbid changed, wrote new name
    Datafile /oradata/devcdb/oradata/DEVCDB/datafile/o1_mf_undotbs1_kcx8ytp3_.db - dbid changed, wrote new name
    Datafile /oradata/devcdb/oradata/DEVCDB/datafile/o1_mf_system_kcx9039v_.db - dbid changed, wrote new name
    Datafile /oradata/devcdb/oradata/DEVCDB/datafile/o1_mf_users_kcx8yslq_.db - dbid changed, wrote new name
    Datafile /oradata/devcdb/oradata/DEVCDB/datafile/o1_mf_sysaux_kcx9039r_.db - dbid changed, wrote new name
    Datafile /oradata/devcdb/oradata/DEVCDB/E2BA8506A8CF2123E053052AA8C092B1/datafile/o1_mf_system_kcx9b6cy_.db - dbid changed, wrote new name
    Datafile /oradata/devcdb/oradata/DEVCDB/E2BA8506A8CF2123E053052AA8C092B1/datafile/o1_mf_sysaux_kcx9b6d3_.db - dbid changed, wrote new name
    Datafile /oradata/devcdb/oradata/DEVCDB/E2BA8506A8CF2123E053052AA8C092B1/datafile/o1_mf_users_kcx9bb00_.db - dbid changed, wrote new name
    Datafile /oradata/devcdb/oradata/DEVCDB/datafile/o1_mf_temp_kcx901k3_.tm - dbid changed, wrote new name
    Datafile /oradata/devcdb/oradata/DEVCDB/datafile/pdbseed_temp012022-07-01_11-37-02-AM.db - dbid changed, wrote new name
    Datafile /oradata/devcdb/oradata/DEVCDB/E2BA8506A8CF2123E053052AA8C092B1/datafile/o1_mf_temp_kcx9b6d3_.db - dbid changed, wrote new name
    Control File /oradata/devcdb/oradata/DEVCDB/controlfile/o1_mf_kcx8zx9n_.ctl - dbid changed, wrote new name
    Control File /oradata/devcdb/fast_recovery_area/DEVCDB/controlfile/o1_mf_kcx8zxcj_.ctl - dbid changed, wrote new name
    Instance shut down
Database name changed to TESTCDB.
Modify parameter file and generate a new password file before restarting.
Database ID for database TESTCDB changed to 2850317248.
All previous backups and archived redo logs for this database are unusable.
Database is not aware of previous backups and archived logs in Recovery Area.
Database has been shutdown, open database with RESETLOGS option.
Succesfully changed database name and ID.
DBNEWID - Completed succesfully.
[oracle@hostname ~]$

SQL> startup nomount;
ORACLE instance started.
Total System Global Area 2.0133E+10 bytes
Fixed Size                  3721176 bytes
Variable Size            2684356648 bytes
Database Buffers         1.7381E+10 bytes
Redo Buffers               63385600 bytes

SQL> alter system set db_name='TESTCDB' scope=spfile;
System altered.

SQL> SHUTDOWN IMMEDIATE;
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> exit

[oracle@hostname ~]$ export ORACLE_SID=TESTCDB

SQL> STARTUP MOUNT
ORACLE instance started.
Total System Global Area 2.0133E+10 bytes
Fixed Size                  3721176 bytes
Variable Size            2684356648 bytes
Database Buffers         1.7381E+10 bytes
Redo Buffers               63385600 bytes
Database mounted.
SQL>

SQL> ALTER DATABASE OPEN RESETLOGS;
Database altered.

SQL> show pdbs
    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 DEVPDB                         MOUNTED

SQL> alter pluggable database DEVPDB open;
Pluggable database altered.

SQL> show pdbs
    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 DEVPDB                         READ WRITE NO

SQL> select name from v$database;
NAME
---------
TESTCDB

SQL> select instance_name from v$instance;
INSTANCE_NAME
----------------
TESTCDB

SQL> show parameter db_name
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_name                              string      TESTCDB



    


Change PDB name from DEVPDB to TESTPDB (NON TDE Environment)

*********************************************
Backup database before performing this action
*********************************************


	

SQL> alter pluggable database DEVPDB close;
Pluggable database altered.

SQL> alter pluggable database DEVPDB unplug into '/orabin/app/product/12.1.0/dbs/DEVPDB_meta.xml';
Pluggable database altered.

SQL> drop pluggable database DEVPDB;
Pluggable database dropped.

SQL> create pluggable database TESTPDB using '/orabin/app/product/12.1.0/dbs/DEVPDB_meta.xml' NOCOPY;
Pluggable database created.

SQL> show pdbs
    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 TESTPDB                        MOUNTED

SQL> alter pluggable database TESTPDB open;
Pluggable database altered.

SQL> show pdbs
    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 TESTPDB                        READ WRITE NO

SQL> alter pluggable database all save state instances=all;
Pluggable database altered.

SQL> show pdbs
    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 TESTPDB                        READ WRITE NO

SQL> show parameter service
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
service_names                        string      TESTCDB


SQL> exit

Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
[oracle@hostname ~]$



    


Change PDB name from DEVPDB to TESTPDB (TDE Environment)

*********************************************
Backup database before performing this action
*********************************************

In RAC Environment run the below commands from only one node, close the PDB on other nodes using below commands



	

alter pluggable database DEVPDB close immediate instances=all ;

alter pluggable database DEVPDB open restricted ;

alter session set container=DEVPDB ;

alter pluggable database rename global_name to TESTPDB ;

alter pluggable database close immediate ;

alter pluggable database open instances=all ;


    





No comments:

Post a Comment