Exploring Oracle Database 12c Multitenant best practices for your Cloud

22
1 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Exploring Oracle Database 12c Multitenant Best Practices for your Cloud Ami Aharonovich Oracle ACE & OCP [email protected] Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 2 About Me Oracle ACE Oracle Certified Professional DBA (OCP) Founder and CEO, DBAces President, Israel Oracle User Group Oracle DBA consultant and instructor, dealing with Oracle database core technologies Frequent speaker at Oracle Open World annual event and various user group conferences around the globe

Transcript of Exploring Oracle Database 12c Multitenant best practices for your Cloud

Page 1: Exploring Oracle Database 12c Multitenant best practices for your Cloud

1

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Exploring Oracle Database 12c

Multitenant Best Practices

for your Cloud

Ami Aharonovich

Oracle ACE & OCP

[email protected]

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.2

About Me

Oracle ACE

Oracle Certified Professional DBA (OCP)

Founder and CEO, DBAces

President, Israel Oracle User Group

Oracle DBA consultant and instructor, dealing with Oracle database core technologies

Frequent speaker at Oracle Open World annual event and various user group conferences around the globe

Page 2: Exploring Oracle Database 12c Multitenant best practices for your Cloud

2

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.3

About Brillix-DBAces

We are committed to provide the highest quality of services delivered by our dedicated team of industry’s top experts. We offer:

Complete end-to-end solutions based on best-of-breed innovations in database, security and big data technologies

On-site professional customized trainings led by our team of Oracle ACEs and Oracle Certified Professionals

Comprehensive security solutions and services for leading database platforms and business applications, leveraging a world-class team of security experts

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.4

Our Customers

Page 3: Exploring Oracle Database 12c Multitenant best practices for your Cloud

3

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.5

Database (Storage Structures)

Oracle Database in 11g Release 2

Server

Database

Instance

System Global Area

Process Structures

Instance

Multiple non-CDBs share nothing:• Too many background processes

• High shared/process memory

• Many copies of Oracle metadata

Pre-12c

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.6

Multitenant Container Database

Instance

System Global Area

Process Structures

Server

Single Instance

Multitenantcontainer database

root

Data files Redo Log filesControl files

Application1

Data files

SALES

Data files

Single DB shares:• Background

processes

• Shared/process

memory

• Oracle metadata

HR

Data files

Multitenant Container Database CDB

Page 4: Exploring Oracle Database 12c Multitenant best practices for your Cloud

4

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.7

Separating SYSTEM and User Data

OBJ$ TAB$ SOURCE$

EMP DEPT

User metadata only User Data

OBJ$ TAB$ SOURCE$

Oracle metadata only

Multitenant Container Database

Container for system

Container for application

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.8

Provisioning a Pluggable Database

Seed

PDB

New

empty

PDB

Imagine this

when the data files

are on a file system

that supports

copy-on-change.

root

Different methods:• Create new PDB from PDB$SEED pluggable database.

• Plug in a non-CDB.

• Clone a non-CDB into a CDB, or a PDB into the same or

another CDB.

• Plug an unplugged PDB into a CDB.

Multitenant Container Database

Page 5: Exploring Oracle Database 12c Multitenant best practices for your Cloud

5

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.9

Interacting Within Multitenant Container Database

PDB_1 PDB_2 PDB_nfast intra-CDB db link

root

Multitenant Container Database

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.10

Multitenant Container Database ArchitectureInstance

System Global Area

Process Structures

Server

Instance

Multitenantcontainer database

root container

Data files Redo Log

files

Control files

UNDO

TEMP

SYSTEM

SYSAUX

seed PDB

Data files

SYSTEM

SYSAUX

SALES PDB

SYSTEM

SYSAUX TBS2

HR PDB

Data files

TEMP1

Data files

TEMP2

PDBid2 PDBid3 PDBid4 PDBid2 PDBid4

Single DB shares:• Background

processes

• Shared/process

memory

• Oracle metadata

• Redo log files

• Control files

• Undo tablespace

Page 6: Exploring Oracle Database 12c Multitenant best practices for your Cloud

6

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.11

Containers

Two types of containers in V$CONTAINERS:

• The root container:

– The first container created at CDB creation

– Mandatory

– Oracle system-supplied common objects and metadata

– Oracle system-supplied common users and roles

• Pluggable database containers (PDBs):

– A container for an application:

— Tablespaces (permanent and temporary)

— Schemas / objects / privileges

— Created / cloned / unplugged / plugged

– Particular seed PDB:— PDB$SEED provides fast provisioning of a new PDB

– Limit of 253 PDBs in a CDB including the seed

– Limit of 1024 services in a CDB

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.12

Questions: Root Versus PDBs

What belongs to the CDB and not to a specific container?

• Control files and redo log files

What is in the root that is not in PDBs?

• UNDO tablespace (for each instance)

• System-supplied metadata

• Shared Oracle-supplied data

– PL/SQL Oracle-supplied packages (DBMS_SQL …)

– PDBs service names

• CDB dictionary views providing information

across PDBs

• CDB Resource Manager plan

UNDO

NAME

PDB_SALES

PDB_HR

TABLE_NAME CON_ID

EMPLOYEES 1

TEST 2Views CDB_xxx

NAME TYPE

TAB$ 2

USER$ 2

Table SYS.OBJ$

Table SYS.SERVICE$

CDBA

Page 7: Exploring Oracle Database 12c Multitenant best practices for your Cloud

7

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.13

Questions: PDBs Versus Root

What is in a PDB that is not in the root nor in another PDB?

• Application tablespaces

• Local temporary tablespaces

• Local users and local roles

– Local users connect to the PDB where they exist.

• Non-shared local metadata

• Non-shared application data with other PDBs

• PDB Resource Manager plan

HR_TBS

TEMP1

EMP_NAME

SMITH

JOHNTable HR.EMPLOYEES

NAME TYPE

EMPLOYEES 2

JOBS 2

Table SYS.OBJ$

PDBA

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.14

Common and Local Users

Multitenant Container Database

root

PDB_HR

PDB_SALES

Table

HR.REGIONS

USERNAME COMMON

SYS YES

SYSTEM YES

C##DBA YES

C##HR YES

View CDB_USERS

Adding a common user involves adding a description of that user in the root and in

every PDB.

A local user is a traditional user, known only

in its own PDB.

View DBA_USERS

USERNAME COMMON

SYS YES

SYSTEM YES

C##DBA YES

C##HR YES

SALES NO

USERNAME COMMON

SYS YES

SYSTEM YES

C##DBA YES

C##HR YES

HR_MGR NO

View DBA_USERS

Table

SALES.COUNTRIES

Tablespace

EXAMPLE

Tablespace

EXAMPLE

Tablespace

EXAMPLE

Page 8: Exploring Oracle Database 12c Multitenant best practices for your Cloud

8

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.15

Common and Local Privileges and Roles

Multitenant Container Database

rootPDB_HR

Common users Local users

Common Priv (granted commonly)

Local Priv (granted locally)Common roles

Local roles

SQL> GRANT c##_r1 TO C##DBA

CONTAINER=ALL;

SQL> GRANT l_priv TO C##DBA

CONTAINER=CURRENT;

Common privilege

Local privilegeCommon Role (granted commonly)

Common Role (granted locally)

COMMON role LOCAL role

X

LOCAL role COMMON role

X

Priv/role granted locally

Priv/role granted commonlyX

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.16

CDB_xxxAll objects in the multitenant container database across all PDBs

USER_xxx Objects owned by the current user

ALL_xxx Objects accessible by the current user

DBA_xxxAll of the objects in a container or pluggable database

Data Dictionary Views

• CDB_pdbs: All PDBS within CDB

• CDB_tablespaces: All tablespaces within CDB

• CDB_users: All users within CDB (common and local)

DBA dictionary views providing information within PDB:

SQL> SELECT view_name FROM dba_views WHERE view_name like 'CDB%';

SQL> SELECT table_name FROM dict WHERE table_name like 'DBA%';

Page 9: Exploring Oracle Database 12c Multitenant best practices for your Cloud

9

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.17

Impacts

• One character set for all PDBs (Unicode recommended)

• PDB initialization parameters but a single SPFILE

• No PDB qualified database object names

– SELECT * FROM HR:apps.tab1

– Use DB Links: SELECT * FROM apps.tab1@HR

• Oracle Data Guard at CDB level

• Oracle Database Vault per PDB only

• One master key per PDB to encrypt PDB data

• Unified audit both at CDB and PDB levels

• Oracle Scheduler

• Oracle GoldenGate

• Oracle Streams

• Oracle XStream both at CDB and PDB levels

Impacts

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.18

SQL*Plus OUI DBCA

EM

Cloud

Control

EM

Database

Express

SQL

DeveloperDBUA

Create a

new CDB or

PDB

Yes Yes YesYes

(PDB only)

Yes

(PDB only)

Yes

(PDB only)

Explore

CDB

instance,

architecture

and PDBs

Yes Yes Yes Yes

Upgrade a

12.1 CDB

to 12.x CDB

Yes Yes

Tools

Page 10: Exploring Oracle Database 12c Multitenant best practices for your Cloud

10

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.19

Instance

SGA

Process Structures

Instance

Container DatabaseCDB1 root container

seed pluggable database

Steps to Create a Container Database

2

1

Container Database CDB1

DatafilesControl

files

UNDO SYSTEM

SYSAUX

Redo Log

files

SYSTEM TEMP1

TEMP

SYSAUX

initCDB1.ora

3

4

Execute scripts from root catcdb.sql

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.20

Creating a Container Database: Using SQL*Plus

1. Instance startup:

a. Set ORACLE_SID=CDB1

b. Set in initCDB1.ora:– Set CONTROL_FILES to CDB control file names.

– Set DB_NAME to CDB name.

– Set ENABLE_PLUGGABLE_DATABASE to TRUE.

2. Create the database:

– CDB$ROOT container

– PDB$SEED pluggable database

3. Run the catcdb.sql script.

SQL> CONNECT / AS SYSDBA

SQL> STARTUP NOMOUNT

SQL> CREATE DATABASE CDB1 ENABLE PLUGGABLE DATABASE …

SEED FILE_NAME_CONVERT ('/oracle/dbs','/oracle/seed');

Page 11: Exploring Oracle Database 12c Multitenant best practices for your Cloud

11

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.21

Creating a Container Database: Using DBCA

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.22

After CDB Creation: What Is New in CDBs

A CDB has new characteristics compared to non-CDBs:

• Two containers:

– The root (CDB$ROOT)

– The seed PDB (PDB$SEED)

• Several services: One per container

– Name of root service = name of the CDB (cdb1)

• Common users in root and seed: SYS,SYSTEM …

• Common privileges granted to common users

• Pre-defined common roles

• Tablespaces and data files associated to each container:

– root: SYSTEM (system-supplied metadata and no user data),

SYSAUX, TEMP

– seed: SYSTEM, SYSAUX , TEMP

Page 12: Exploring Oracle Database 12c Multitenant best practices for your Cloud

12

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.23

USER_xxx Objects owned by the current user in a PDB

ALL_xxx Objects accessible by the current user in a PDB

DBA_xxxAll of the objects in the root or a pluggable database

Data Dictionary Views: DBA_xxx

DBA dictionary views providing information within PDB:

• DBA_tablespaces: All tablespaces of the PDB

• DBA_data_files: All data files of the PDB

• DBA_tables: All tables in the PDB

• DBA_users: All common and local users of the PDB

SQL> SELECT table_name FROM dict WHERE table_name like 'DBA%';

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.24

CDB_xxxAll of the objects in the container database (new column CON_ID)

USER_xxx Objects owned by the current user in a PDB

ALL_xxx Objects accessible by the current user in a PDB

DBA_xxxAll of the objects in the root or a pluggable database

Data Dictionary Views: CDB_xxx

CDB dictionary views provide information across PDBs:

• CDB_pdbs: All PDBS within the CDB

• CDB_tablespaces: All tablespaces within the CDB

• CDB_data_files: All data files within the CDB

• CDB_users: All users within the CDB (common and local)

SQL> SELECT view_name FROM dba_views WHERE view_name like 'CDB%';

Page 13: Exploring Oracle Database 12c Multitenant best practices for your Cloud

13

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.25

Data Dictionary Views: Examples

• Comparisons:

• Access to data in V$ or GV$ views showing data from

multiple PDBs can be secured using privilege.

SQL> SELECT name, open_mode FROM v$pdbs;

NAME OPEN_MODE

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

PDB$SEED READ ONLY

PDB1 READ WRITE

PDB2 READ WRITE

SQL> CONNECT / AS SYSDBA

SQL> SELECT role, common, con_id FROM cdb_roles;

SQL> SELECT role, common FROM dba_roles;

1

2

SQL> CONNECT sys@PDB1 AS SYSDBA

SQL> SELECT role, common, con_id FROM cdb_roles;

SQL> SELECT role, common FROM dba_roles;

3

4

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.26

After CDB Creation: To-Do List

After CDB creation, the CDBA has to:

• Set a separate default tablespace for the root and for each

PDB

• Set a default temporary tablespace for each container

• Start the listener

• Plug non-CDBs

• Test startup/shutdown procedures

• Define default PDB state to automate PDBs opening

• Create backup and recovery procedures

12.1.0.2

Page 14: Exploring Oracle Database 12c Multitenant best practices for your Cloud

14

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.27

Provisioning New Pluggable Databases

Different methods:

• Create a new PDB from the seed PDB.

• Plug or clone a non-CDB into a CDB.

• Clone:

– A local PDB into the same CDB

– A remote PDB into a CDB

• Plug an unplugged PDB into another CDB.

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.28

Tools

To provision new PDBs, you can use:

• SQL*Plus

• SQL Developer

• Enterprise Manager Cloud Control

• Enterprise Manager Database Express

• DBCA

– Copy from seed

– By unplugging/plugging method

Page 15: Exploring Oracle Database 12c Multitenant best practices for your Cloud

15

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.29

Method 1: Create New PDB from PDB$SEED

Container Database CDB1

root

Data files/

Tempfiles

Redo Log

files

Control

files

UNDO

TEMP

PDB$SEED

Data files

PDB1

Data files

Create

PDB1

from PDB$SEED

• Copies the data files from PDB$SEED data files

• Creates SYSTEM and SYSAUX

tablespaces

• Creates a full catalog including

metadata pointing to Oracle-

supplied objects

• Creates a temporary tablespace, TEMP

• Creates common users:– Superuser SYS

– SYSTEM

• Creates a local user (PDBA) granted local PDB_DBA role

• Creates a new default service

TEMP

SYSAUX

SYSTEM

SYSTEM

USERS

SYSAUX

SYSAUX SYSTEM

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.30

Steps: With Location Clauses

Connect to the root as a common user with the CREATE

PLUGGABLE DATABASE privilege:

• Use FILE_NAME_CONVERT:

• Use CREATE_FILE_DEST:

• Use views to verify:

SQL> CREATE PLUGGABLE DATABASE pdb1

ADMIN USER admin1 IDENTIFIED BY p1 ROLES=(CONNECT)

FILE_NAME_CONVERT = ('PDB$SEEDdir', 'PDB1dir');

SQL> CONNECT / AS SYSDBA

SQL> SELECT * FROM cdb_pdbs;

SQL> SELECT * FROM cdb_tablespaces;

SQL> SELECT * FROM cdb_data_files;

SQL> CONNECT sys@pdb1 AS SYSDBA

SQL> CONNECT admin1@pdb1

SQL> CREATE PLUGGABLE DATABASE pdb2

ADMIN USER admin2 IDENTIFIED BY p2 ROLES=(CONNECT)

CREATE_FILE_DEST = 'PDB2dir';

12.1.0.2

Page 16: Exploring Oracle Database 12c Multitenant best practices for your Cloud

16

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.31

Synchronization

• If the PDB is in MOUNTED or READ-ONLY mode

• If customer-created common users or roles are created /

modified / dropped

→ The PDB needs to be resynchronized with the root.

– Open the PDB in READ-WRITE mode to synchronize the

PDB with the target CDB.

– If you open the PDB in READ-ONLY mode, an error is

returned.

→A compatibility check is automatically performed:

– Any violation is reported in the PDB_PLUG_IN_VIOLATIONS

view.

– If there is no violation, the PDB status is changed to NORMAL.

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.32

Method 2: Plug a Non-CDB into a CDB

Three possible methods:

• TTS or TDB or full export/import

• XML file definition with DBMS_PDB

• Replication

Entities are created in the new PDB:• Tablespaces: SYSTEM, SYSAUX,

TEMP

• A full catalog• Common users: SYS, SYSTEM

• A local administrator (PDBA)

• A new default service

Container Database CDB1

root

Data files/

Temp files

Redo Log

files

Control

files

PDB$SEED

Data files / Temp files

Create

PDB2

from

ORCL

ORCL

Data files Control

files

Redo Log

files

Dump file

PDB2

Data files

impdp TTS

12.1

expdp TTS

ReplicationXML file

DBMS_PDB

Plug

Page 17: Exploring Oracle Database 12c Multitenant best practices for your Cloud

17

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.33

Plug a Non-CDB in to CDB Using DBMS_PDB

Container Database CDB1

root

Data files/

Temp files

Redo Log

files

Control

files

PDB$SEED

PDB2

Data files

Create

PDB2

from

ORCL

DBMS_PDB.DESCRIBE

Plug

XML metadata file

1. Open ORCL in READ ONLY mode.

2.

3. Connect to the target CDB1 CDB as a

common user with CREATE PLUGGABLE

DATABASE privilege.4. Plug in the unplugged ORCL as PDB2.

5. Run the noncdb_to_pdb.sql script.

6. Open PDB2.

SQL> CREATE PLUGGABLE DATABASE

PDB2 USING '/tmp/ORCL.xml';

SQL> EXEC DBMS_PDB.DESCRIBE

('/tmp/ORCL.xml')

SQL> CONNECT sys@PDB2 AS SYSDBA

SQL> @$ORACLE_HOME/rdbms/admin/noncdb_to_pdb

Data files / Tempfiles

ORCL

Datafiles Control

files

Redo Log

files

12.1

SQL> ALTER PLUGGABLE DATABASE

PDB2 OPEN;

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.34

Method 3: Clone Local PDBs

Container Database CDB1

root

Data files/

Temp files

Redo Log

files

Control

files

PDB$SEED

Data files / Temp files

PDB1

Data files

Create

PDB3

from

PDB1

1. Set the DB_CREATE_FILE_DEST or

DB_FILE_NAME_CONVERT instance

parameter oruse the CREATE_FILE_DEST clause.

2. Connect to the root.

3. Quiesce PDB1:

4. Clone PDB3 from PDB1:

5. Open PDB3 in read-write mode.

6. Reopen PDB1.

PDB3

Data files

PDB3 owns:

• SYSTEM, SYSAUX tablespaces

• Full catalog

• A temporary tablespace• SYS, SYSTEM common users

• Same local administrator name• New service name

SQL> ALTER PLUGGABLE DATABASE

pdb1 CLOSE;

SQL> ALTER PLUGGABLE DATABASE

pdb1 OPEN READ ONLY;

SQL> CREATE PLUGGABLE DATABASE

pdb3 FROM pdb1;

SQL> ALTER PLUGGABLE DATABASE

pdb3 OPEN;

12.1.0.2

Page 18: Exploring Oracle Database 12c Multitenant best practices for your Cloud

18

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.35

Method 4: Plug Unplugged PDB in to CDB

Unplug PDB1 from CDB1:

1. Connect to CDB1 as a common user.

2. Verify that PDB1 is closed.

3.

4. Optionally, drop PDB1 from CDB1.

Plug PDB1 in to CDB2:

1. Connect to CDB2 as a common user.

2. Use DBMS_PDB package to check the

compatibility of PDB1 with CDB2.

3.

4. Open PDB1 in read-write mode.

Container Database CDB1

root

PDB$SEED

PDB1

Data files

XML file

USERS

Unplug PDB1

Container Database CDB2

root

PDB$SEED

PDB1

Data files

Plug PDB1

SQL> ALTER PLUGGABLE DATABASE

pdb1 UNPLUG INTO

'xmlfile1.xml';

SQL> CREATE PLUGGABLE DATABASE

pdb1 USING 'xmlfile1.xml'

NOCOPY;

SYSAUX

SYSTEM

USERSSYSAUX

SYSTEM

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.36

Method 4: Flow

Are new PDB files based on

same files that were used to

create existing PDB in CDB?

If not, AS CLONE clause is required and so, it ensures

that Oracle Database generates unique PDB DBID,

GUID, and other identifiers expected for the new PDB.

XML file accurately describes

current locations of files?

Are files in correct location?

Do you want to specify

storage limits for PDB?

If not, the SOURCE_FILE_NAME_CONVERT clause is

required.

If not, specify COPY to copy files to new location or MOVE

to move them to another location.If yes, use NOCOPY. COPY as the default.

If yes, specify the STORAGE clause.

• FILE_NAME_CONVERT or CREATE_FILE_DEST

clauses of CREATE PLUGGABLE DATABASE statement

• Instances DB_CREATE_FILE_DEST or

PDB_FILE_NAME_CONVERT parameters

Several clauses can be used in conjunction:

Page 19: Exploring Oracle Database 12c Multitenant best practices for your Cloud

19

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.37

Plug Sample Schemas PDB: Using DBCA

1

2

3

4

Plug a new PDB with Sample Schemas using a PDB File Set

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.38

Dropping a PDB

Container Database CDB1

root

Data files/

Temp files

Redo Log

files

Control

files

File2

TEMP

PDB$SEED

Data files

File5File6

File7

File4

File1

File3

PDB1

Data files

File8 Drop PDB1

• Updates control files• If INCLUDING DATAFILES:

– Removes PDB1 datafiles

• If KEEP DATAFILES (default):

– Retain data files

– Can be plugged in another or

the same CDB

• Requires SYSDBA privilege

• Cannot drop seed PDB

File9 File10

PDB4

Data files

SQL> ALTER PLUGGABLE DATABASE

pdb1 CLOSE;

SQL> DROP PLUGGABLE DATABASE

pdb1 [INCLUDING DATAFILES];…

File7

File8

File9

File10

Page 20: Exploring Oracle Database 12c Multitenant best practices for your Cloud

20

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.39

Migrating pre-12.1 Databases to 12.1 CDB

There are two methods:

1. Upgrade an existing pre-12.1

database to 12c.

2. Plug-in non-CDB into a CDB.

Or

1. Pre-create a PDB in CDB.

2. Use 11g expdp / 12c impdp

or replication between non-CDB

and PDB.

CDB CDB1

root

Data files/

Temp files

Redo Log

files

Control

files

ORCL

Data files Control

files

Redo Log

files

expdp

Dump file

PDB1

Data files

impdp

ORCL

Data files Control

files

Redo Log

files

1

2

11g

12c

Replication XML file

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.40

MOUNT

NOMOUNT

SHUTDOWN

Instance

started

– CDB control files opened for

the instance

– Root mounted

– PDBs mounted

– Root opened

– PDBs still mounted,

except seed in RO

OPEN

SQL> STARTUP

SQL> ALTER DATABASE cdb1 OPEN;

Or

SQL> SELECT name,open_mode

2 FROM v$pdbs;

NAME OPEN_MODE

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

PDB$SEED READ ONLY

PDB1 MOUNTED

PDB2 MOUNTED

Opening a CDB

Page 21: Exploring Oracle Database 12c Multitenant best practices for your Cloud

21

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.41

OPEN

MOUNT

NOMOUNT

SHUTDOWN

Instance

started

– CDB control files opened for the

instance

– Root mounted

– PDBs mounted

– Root opened

– PDBs still mounted,

except seed in RO

PDB OPEN

PDBs opened RW,

except seed in RO

SQL> CONNECT sys@CDB1 AS SYSDBA

SQL> ALTER PLUGGABLE DATABASE pdb1 OPEN;

SQL> ALTER PLUGGABLE DATABASE ALL OPEN;

Or

SQL> SELECT name,open_mode

2 FROM v$pdbs;

NAME OPEN_MODE

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

PDB$SEED READ ONLY

PDB1 READ WRITE

PDB2 READ WRITE

Opening a PDB

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.42

CDB OPEN

MOUNT

NOMOUNT

SHUTDOWNInstance

started

– CDB control files opened for the instance

– Root mounted

– PDBs mounted

– Root opened

– PDBs mounted, except

seed still RO

PDB CLOSE

PDBs closed

SQL> CONNECT / AS SYSDBA

SQL> ALTER PLUGGABLE DATABASE pdb1

CLOSE IMMEDIATE;

SQL> ALTER PLUGGABLE DATABASE

ALL EXCEPT pdb1 CLOSE;

SQL> ALTER PLUGGABLE DATABASE

ALL CLOSE;

SQL> CONNECT sys@pdb1 AS SYSDBA

SQL> ALTER PLUGGABLE DATABASE CLOSE;

Or SQL> SHUTDOWN IMMEDIATE;

Closing a PDB

Page 22: Exploring Oracle Database 12c Multitenant best practices for your Cloud

22

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.43

SQL> CONNECT sys@CDB1 AS SYSDBA

SQL> SHUTDOWN IMMEDIATE

Shutting Down a CDB Instance

• All PDBs closed (no new specific message)

• CDB closed

• CDB dismounted

• Instance shut down

• PDB closed

SQL> CONNECT sys@PDB1 AS SYSDBA

SQL> SHUTDOWN IMMEDIATE

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Exploring Oracle Database 12c

Multitenant Best Practices

for your Cloud

Ami Aharonovich

Oracle ACE & OCP

[email protected]