meta données pour cette page
  •  

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
oracle:database:duplicate_pdb_to_another_cdb [11/03/2024 14:38] mdloracle:database:duplicate_pdb_to_another_cdb [02/12/2025 10:47] (Version actuelle) mdl
Ligne 39: Ligne 39:
 odacli create-database --dbname CHRMSP2 --databaseUniqueName CHRMSP2 --pdbname P_ODA1901 --cdb --dbtype RAC --dbclass OLTP --dbhomeid cf868ba0-6fff-4b9d-84e2-53cc1a95ca1b --bshape odb1 --dbstorage ASM --dbdomainname db.test.com --associated-networks Public-network --characterset AL32UTF8 --nationalscharacterset AL16UTF16 --dblanguage american --dbterritory america odacli create-database --dbname CHRMSP2 --databaseUniqueName CHRMSP2 --pdbname P_ODA1901 --cdb --dbtype RAC --dbclass OLTP --dbhomeid cf868ba0-6fff-4b9d-84e2-53cc1a95ca1b --bshape odb1 --dbstorage ASM --dbdomainname db.test.com --associated-networks Public-network --characterset AL32UTF8 --nationalscharacterset AL16UTF16 --dblanguage american --dbterritory america
 </code> </code>
- +  
-//Note: When creating a CDB, the create database command requires a PDB Name.  This is a temporary database that the DBA has to drop it, once container is created successfully. //+//Note: When creating a CDB, the create database command requires a PDB Name.  This is a temporary database that the DBA has to drop it, once container is created successfully.//
  
 b) Check create container job status b) Check create container job status
Ligne 47: Ligne 47:
 srvctl status database -d CHRMSP2 -v  srvctl status database -d CHRMSP2 -v
 srvctl config database -d CHRMSP2  srvctl config database -d CHRMSP2
-<code PLSQL>+</code>
  
   * Drop P_ODA1901 PDB   * Drop P_ODA1901 PDB
 +<code PLSQL>
       SQL> show pdbs       SQL> show pdbs
  
Ligne 70: Ligne 70:
  
        2 PDB$SEED                       READ ONLY  NO        2 PDB$SEED                       READ ONLY  NO
 +</code>
 +3) Compare initialization parameters(init.ora) of CHRMSP1 and CHRMSP2 containers and do the necessary parameter changes.
  
- 3) Compare initialization parameters(init.ora) of CHRMSP1 and CHRMSP2 containers and do the  +4) Add newly created container CHRMSP2 into OEM and schedule RMAN backup jobs
- +
-           necessary parameter changes. +
- +
- 4) Add newly created container CHRMSP2 into OEM and schedule RMAN backup jobs +
- +
- 5) Create a TNS entry for source PDB (to be used during migration)+
  
 +5) Create a TNS entry for source PDB (to be used during migration)
 +<code PLSQL>
     P_HRDP_MIG =     P_HRDP_MIG =
- 
       (DESCRIPTION =       (DESCRIPTION =
- 
           (ADDRESS = (PROTOCOL = TCP)(HOST = indodap1-scan)(PORT = 1521))           (ADDRESS = (PROTOCOL = TCP)(HOST = indodap1-scan)(PORT = 1521))
- 
                  (CONNECT_DATA =                  (CONNECT_DATA =
- 
              (SERVER = DEDICATED)              (SERVER = DEDICATED)
- 
           (SERVICE_NAME = P_HRDP.db.test.com)           (SERVICE_NAME = P_HRDP.db.test.com)
- 
  )  )
- 
       )       )
 +</code>
 ** Migration Phase ** ** Migration Phase **
 +Referred MOS Doc ID: 2297470.1 - How to clone PDB (Remote Clone) across CDB using Database Link 
 +1) Take Full Export backup of P_HRDP PDB
 +=> Directory Location:  /acfs01/backup/CHRMSP1/P_HRDP
 +<code BASH>
 +nohup expdp <username>/<password>@P_HRDP_MIG DIRECTORY=DATADUMP DUMPFILE=EXPDP_P_HRDP_FULL_%U.dmp LOGFILE=EXPDP_P_HRDP_FULL.log FULL=Y PARALLEL=4 EXCLUDE=STATISTICS,MARKER &
 +</code>
  
- Referred MOS Doc ID: 2297470.1 - How to clone PDB (Remote Cloneacross CDB using Database Link +2Stop P_HRDP_SVC service from source container CHRMSP1 
 +<code BASH> 
 +srvctl stop service -d CHRMSP1 -s P_HRDP_SVC 
 +srvctl disable service -d CHRMSP1 -s P_HRDP_SVC  
 +</code>
  
- 1) Take Full Export backup of P_HRDP PDB +3) clone P_HRDP database from source container(CHRMSP1) to target container(CHRMSP2)    
- +** Source Container (CHRMSP1) **  
-           Directory Location:  /acfs01/backup/CHRMSP1/P_HRDP +<code PLSQL> 
- +ALTER SESSION SET CONTAINER=P_HRDP; 
-    nohup expdp <username>/<password>@P_HRDP_MIG DIRECTORY=DATADUMP DUMPFILE=EXPDP_P_HRDP_FULL_%U.dmp LOGFILE=EXPDP_P_HRDP_FULL.log FULL=Y PARALLEL=4 EXCLUDE=STATISTICS,MARKER &  +CREATE USER remote_clone_user IDENTIFIED BY remote_clone_user; 
- +GRANT CREATE SESSION, CREATE PLUGGABLE DATABASE TO remote_clone_user; 
- 2) Stop P_HRDP_SVC service from source container CHRMSP1 +Grant select any dictionary to remote_clone_user; 
- +ALTER PLUGGABLE DATABASE P_HRDP CLOSE IMMEDIATE instances=all; 
-    srvctl stop service -d CHRMSP1 -s P_HRDP_SVC +ALTER PLUGGABLE DATABASE P_HRDP OPEN READ ONLY instances=all; <<< Restart database in read only mode 
- +SHOW PDBS  
-       srvctl disable service -d CHRMSP1 -s P_HRDP_SVC  +</code> 
- +**Target Container (CHRMSP2)**  
- 3) clone P_HRDP database from source container(CHRMSP1) to target container(CHRMSP2)    +
- +
-    ** Source Container (CHRMSP1) **  +
- +
-       ALTER SESSION SET CONTAINER=P_HRDP; +
- +
-       CREATE USER remote_clone_user IDENTIFIED BY remote_clone_user; +
- +
-              GRANT CREATE SESSION, CREATE PLUGGABLE DATABASE TO remote_clone_user; +
- +
-       Grant select any dictionary to remote_clone_user; +
- +
-       ALTER PLUGGABLE DATABASE P_HRDP CLOSE IMMEDIATE instances=all; +
- +
-       ALTER PLUGGABLE DATABASE P_HRDP OPEN READ ONLY instances=all; <<< Restart database in read only mode +
- +
-              SHOW PDBS  +
- +
- ** Target Container (CHRMSP2) **    +
- +
-    ** Create database link pointing to source PDB   +
  
 +  * Create database link pointing to source PDB   
 +<code PLSQL>
        CREATE DATABASE LINK clone_link CONNECT TO remote_clone_user IDENTIFIED BY remote_clone_user USING 'P_HRDP_MIG'; <<< Use TNS Entry which was created in above step        CREATE DATABASE LINK clone_link CONNECT TO remote_clone_user IDENTIFIED BY remote_clone_user USING 'P_HRDP_MIG'; <<< Use TNS Entry which was created in above step
- +</code> 
-           ** Test Database link (check users list and confirm it is connecting to correct database) +  * Test Database link (check users list and confirm it is connecting to correct database) 
 +<code PLSQL>
        DESC user_tables@clone_link        DESC user_tables@clone_link
  
        Select username from dba_users@clone_link where(oracle_maintained='N');         Select username from dba_users@clone_link where(oracle_maintained='N');
- +</code> 
-        ** Create a shell script to clone PDB +  * Create a shell script to clone PDB 
 +<code BASH>
        cd /home/oracle         cd /home/oracle
- 
        vi clone_P_HRDP_pdb.sh        vi clone_P_HRDP_pdb.sh
- 
        #!/bin/sh          #!/bin/sh  
- 
        sqlplus /nolog << ! >> /dev/null        sqlplus /nolog << ! >> /dev/null
- 
        connect / as sysdba        connect / as sysdba
- 
        spool clone_P_HRDP_pdb_02Jan2024.log        spool clone_P_HRDP_pdb_02Jan2024.log
- 
        select username from dba_users@clone_link where(oracle_maintained='N' and username not like 'C##%');        select username from dba_users@clone_link where(oracle_maintained='N' and username not like 'C##%');
- 
        CREATE PLUGGABLE DATABASE P_HRDP FROM P_HRDP@clone_link;        CREATE PLUGGABLE DATABASE P_HRDP FROM P_HRDP@clone_link;
- 
        alter pluggable database P_HRDP open instances=all services=all;        alter pluggable database P_HRDP open instances=all services=all;
- 
        spool off;        spool off;
 +</code>
 +      
  
-       !  + * Before executing a script make sure environment is set for target container CHRMSP2 
- +<code BASH>
-    ** Before executing a script make sure environment is set for target container CHRMSP2 +
        $ export ORACLE_SID=CHRMSP2        $ export ORACLE_SID=CHRMSP2
- 
        $ export ORACLE_HOME=/u01/app/oracle/product/19.0.0.0/dbhome_2        $ export ORACLE_HOME=/u01/app/oracle/product/19.0.0.0/dbhome_2
- 
        $ nohup clone_P_HRDP_pdb.sh &         $ nohup clone_P_HRDP_pdb.sh &
 +</code>
        ** Logs        ** Logs
 +<code PLSQL>
           $ sqlplus / as sysdba           $ sqlplus / as sysdba
- 
        SQL*Plus: Release 19.0.0.0.0 - Production on Fri Sep 22 17:58:42 2023        SQL*Plus: Release 19.0.0.0.0 - Production on Fri Sep 22 17:58:42 2023
- 
        Version 19.17.0.0.0        Version 19.17.0.0.0
- 
         Copyright (c) 1982, 2022, Oracle.  All rights reserved.         Copyright (c) 1982, 2022, Oracle.  All rights reserved.
- 
        Connected to:        Connected to:
- 
        Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production        Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
- 
        Version 19.17.0.0.0         Version 19.17.0.0.0
- 
        SQL> show pdbs                  SQL> show pdbs          
  
            CON_ID CON_NAME                       OPEN MODE  RESTRICTED            CON_ID CON_NAME                       OPEN MODE  RESTRICTED
- 
            ---------- ------------------------------ ---------- ----------            ---------- ------------------------------ ---------- ----------
- 
         2 PDB$SEED                       READ ONLY  NO         2 PDB$SEED                       READ ONLY  NO
- 
         3 P_HRDP                         READ WRITE NO         3 P_HRDP                         READ WRITE NO
  
        SQL> select name from v$services;        SQL> select name from v$services;
- 
     NAME     NAME
- 
     ----------------------------------------------------------------     ----------------------------------------------------------------
- 
     CHRMSP2XDB     CHRMSP2XDB
- 
     CHRMSP2.db.test.com     CHRMSP2.db.test.com
- 
     SYS$BACKGROUND     SYS$BACKGROUND
- 
     P_HRDP_SVC     P_HRDP_SVC
- 
     SYS$USERS     SYS$USERS
- 
     P_HRDP      P_HRDP
- +</code> 
-        Note: Here, we can see that cloning the pdb will also copy all the services associate with source PDB+**Note**: Here, we can see that cloning the pdb will also copy all the services associate with source PDB
  
  4.Create a high availability service for the new PDB in CHRMSP2  4.Create a high availability service for the new PDB in CHRMSP2
 +<code BASH>
    srvctl add service -db CHRMSP2 -pdb P_HRDP -service P_HRDP_SVC -failovertype SELECT -failovermethod BASIC -preferred "CHRMSP21,CHRMSP22"    srvctl add service -db CHRMSP2 -pdb P_HRDP -service P_HRDP_SVC -failovertype SELECT -failovermethod BASIC -preferred "CHRMSP21,CHRMSP22"
  
Ligne 226: Ligne 179:
  
    srvctl status service -db CHRMSP2     srvctl status service -db CHRMSP2
 +</code>
 + 5. Rename global name of Source PDB(P_HRDP) to P_HRDP_OLD in source container CHRMSP1 (This step is required to avoid conflict of pdb with same name on same server)
  
- 5. Rename global name of Source PDB(P_HRDP) to P_HRDP_OLD in source container CHRMSP1 (This step  +  * Login to CHRMSP1 container
- +
-           is required to avoid conflict of pdb with same name on same server) +
- +
-    Login to CHRMSP1 container    +
 <code PLSQL> <code PLSQL>
 alter pluggable database P_HRDP close immediate instances=all; alter pluggable database P_HRDP close immediate instances=all;