Thursday, September 24, 2020


Clone Pluggable database

==========================

SQL> select name,open_mode from v$pdbs;

NAME        OPEN_MODE

------------------------------ ----------

PDB$SEED        READ ONLY

MIGPDB         READ WRITE


SQL> alter session set container=MIGPDB;

Session altered.


SQL> select file_name from dba_data_files;

SQL> select file_name from dba_data_files;

FILE_NAME

--------------------------------------------------------------------------------

/u02/oradata/MIGCDB/AFF38B6D8283019AE053AC10028C9AE1/datafile/o1_mf_system_hpojb1ry_.dbf

/u02/oradata/MIGCDB/AFF38B6D8283019AE053AC10028C9AE1/datafile/o1_mf_sysaux_hpojb1s2_.dbf

/u02/oradata/MIGCDB/AFF38B6D8283019AE053AC10028C9AE1/datafile/o1_mf_undotbs1_hpojb1s2_.dbf  etc...


SQL> show con_name

CON_NAME

------------------------------

MIGPDB


SQL> shutdown immediate;

Pluggable Database closed.

 

SQL> startup open read only

Pluggable Database opened.

 

# mkdir /u02/oradata/MIGCDB/demopdb


SQL > alter session set container=cdb$root;


SQL > show con_name


CON_NAME

------------------------------

CDB$ROOT


SQL> alter system set db_create_file_dest='/u02/oradata/MIGCDB/demopdb';


SQL> create pluggable database DEMOPDB from MIGPDB FILE_NAME_CONVERT=('/u02/oradata/MIGCDB/AFF38B6D8283019AE053AC10028C9AE1/datafile/','/u02/oradata/MIGCDB/demopdb');

 

SQL> select name,open_mode from v$pdbs;

 

NAME        OPEN_MODE

------------------------------ ----------

PDB$SEED          READ ONLY

MIGPDB              READ ONLY

DEMOPDB          MOUNTED

 

SQL> alter session set CONTAINER=MIGPDB;

 

Session altered.

 

SQL> shutdown immediate;

Pluggable Database closed.

SQL> startup

Pluggable Database opened.

SQL> show con_name

---------------------------------------------

SQL> alter session set container=DEMOPDB;

 

Session altered.

 

SQL> startup

Pluggable Database opened.


  SQL> alter session set container=cdb$root;

Connected.

SQL> select name,open_mode from v$pdbs;

 

NAME        OPEN_MODE

------------------------------ ----------

PDB$SEED        READ ONLY

MIGPDB             READ WRITE

DEMOPDB         READ WRITE

Thursday, September 17, 2020

 

Multitenant : Clone a Remote PDB

https://oracle-base.com/articles/12c/multitenant-clone-remote-pdb-or-non-cdb-12cr1#prerequisites

Connect to the remote CDB and prepare the remote PDB for cloning.

export ORAENV_ASK=NO

export ORACLE_SID=cdb3

. oraenv

export ORAENV_ASK=YES

 

sqlplus / as sysdba

Create a user in the remote database for use with the database link. In this case, we will use a local user in the remote PDB.

ALTER SESSION SET CONTAINER=pdb5;

 

CREATE USER remote_clone_user IDENTIFIED BY remote_clone_user;

GRANT CREATE SESSION, CREATE PLUGGABLE DATABASE TO remote_clone_user;

Open the remote PDB in read-only mode.

CONN / AS SYSDBA

ALTER PLUGGABLE DATABASE pdb5 CLOSE;

ALTER PLUGGABLE DATABASE pdb5 OPEN READ ONLY;

EXIT;

Switch to the local server and create a "tnsnames.ora" entry pointing to the remote database for use in the USING clause of the database link.

PDB5 =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = TCP)(HOST = ol7-121.localdomain)(PORT = 1521))

    )

    (CONNECT_DATA =

      (SERVICE_NAME = pdb5)

    )

  )

Connect to the local database to initiate the clone.

export ORAENV_ASK=NO

export ORACLE_SID=cdb1

. oraenv

export ORAENV_ASK=YES

 

sqlplus / as sysdba

Create a database link in the local database, pointing to the remote database.

DROP DATABASE LINK clone_link;

 

CREATE DATABASE LINK clone_link

  CONNECT TO remote_clone_user IDENTIFIED BY remote_clone_user USING 'pdb5';

 

-- Test link.

DESC user_tables@clone_link

Create a new PDB in the local database by cloning the remote PDB. In this case we are using Oracle Managed Files (OMF), so we don't need to bother with FILE_NAME_CONVERT parameter for file name conversions.

CREATE PLUGGABLE DATABASE pdb5new FROM pdb5@clone_link;

 

Pluggable database created.

 

SQL>

We can see the new PDB has been created, but it is in the MOUNTED state.

SELECT name, open_mode FROM v$pdbs WHERE name = 'PDB5NEW';

 

NAME                           OPEN_MODE

------------------------------ ----------

PDB5NEW                        MOUNTED

 

SQL>

The PDB is opened in read-write mode to complete the process.

ALTER PLUGGABLE DATABASE pdb5new OPEN;

 

SELECT name, open_mode FROM v$pdbs WHERE name = 'PDB5NEW';

 

NAME                           OPEN_MODE

------------------------------ ----------

PDB5NEW                        READ WRITE

 

SQL>

 

  RMAN-20207: UNTIL TIME or RECOVERY WINDOW is before RESETLOGS time https://shivanandarao-oracle.com/2012/12/05/rman-20207-until-time-or-re...