#C
15
LV
REMINDER
Check in on the COLLABORATE mobile app
Pluggable Databases :Save money and time by harnessing the power of ORACLE for database consolidation
Prepared by:John LarkinSr. Database Administrator, OCPAdvanced Database Services, LLC.
.
Session ID#: 830
#C
15
LV
2
Pluggable Databases : Save money and time cont’d
■ Oracle DBA for 18 years. (28 yrs overall).■ OCP■ UNIX (Linux, Solaris, Aix, Windows)■ Multi-year project to migrate to RAC One-Node■ Major Financial, Chemical, publishing and retail industries.
#C
15
LV
3
Why do we want to use a Container Database?
Retain cost savings and efficiencies of shared resources in the next generation server environment.
#C
15
LV
4
Pluggable Databases : Agenda
■ Consolidation Overview■ Multitenant concepts
▪ Scope
▪ Currency
▪ Services
▪ Connections
▪ Commonality
■ Installation■ Physical Structure■ Migration – Get Plugged In■ Gotcha’s
#C
15
LV
5
Pluggable Databases : Save money and time cont’d
■ Consolidation▪ Prior methods worked at different levels
— Server
— Schema
– issues
▪ Oracle Database 12c— Integrated into the database
— Decreased cost
— Higher density
– Shared memory
– Shared processes
#C
15
LV
6
Pluggable Databases :Save money and time cont’d
Figure 2: OLTP Benchmark Comparison Only 3 GB of memory vs. 20 GB memory used for 50 databases. Multitenant architecture scaled to over 250 DBs while separate database
#C
15
LV
7
Pluggable Databases : Save money and time cont’d
■ Multitenant Container Database Concepts▪ The CDB – the backbone of Oracle’s multitenant architecture
— holds the Containers
— Root Container
— Seed Pluggable database
— Pluggable database – 0 or more
— CDB is the instance
– Demo
– @d010
#C
15
LV
8
Pluggable Databases : Save money and time cont’d
CDB is the instance – cont’d
■ (sqlplus / as sysdba) Instance VERSION User Dbname -------------- -------------- --------- ---------------------- orcl12a 12.1.0.2.0 SYS ORCL12A
CON_NAME CON_ID (CONTAINER information)
---------------- ----------------CDB$ROOT 1
(alter session set container=pdborcl12a1) CON_NAME CON_ID (PDB information)
---------------- ----------------PDBORCL12A1 3
#C
15
LV
9
Pluggable Databases : Save money and time cont’d
CDB is the instance – cont’d (Windows Services window)
#C
15
LV
10
Pluggable Databases : Save money and time cont’d
Some important Terms■ CDB – multitenant container database – the top level.
▪ A database that holds the containers.
■ Container - all within a CDB▪ collection of schemas, objects, related structures in a CDB
▪ Appears to a client (user or application) as a separate database.
▪ Unique ID and name within a CDB— Root and all PDB’s.
— Indistinguishable from non-CDB (12c and all pre-12c) to users.
– Unless… you’re a DBA.
— Isolate and insulate
#C
15
LV
11
Pluggable Databases : Save money and time cont’d
■ The ROOT container▪ CDB$ROOT
▪ Only 1 per CDB
▪ All PDB’s belong to it.
▪ No user data
▪ Common user (prefix/suffix modifiable)
#C
15
LV
12
Pluggable Databases : Save money and time cont’d
■ PDB – Pluggable database, a container▪ Compatibility Guarantee
— A PDB is fully compatible with a non-CDB
— Application to run without code changes and deliver the same results
— Init.ora changes might be needed
▪ User-created
▪ Owned by SYS common user
▪ Looks like a standalone database
▪ Segregate application data and code
▪ Migrations— from one CDB to another
— Upgrades
#C
15
LV
13
Pluggable Databases : Save money and time cont’d
■ PDB cont’d▪ Services
— PDB accessed by a service name that is the same as the PDB name
– PDB name must conform to service naming standards
▪ SCOPE— Name resolution - dictionary of the container where you’re connected
– Dictionary is horizontally partitioned.
— Schemas in different databases
– Independent, different datastore
» Even if owned by a common user
— Behaves like a non-CDB
#C
15
LV
14
Pluggable Databases : Save money and time cont’d
■ Data Dictionary Architecture/▪ non-CDB dictionary
— a mixture of Oracle-supplied and user-created objects
▪ CDB Dictionaries appear to be separated by container— Data dictionary metadata is split between the root and the PDB’s
— Views show different row counts in each container.
— Keeps the oracle-owned and user-created objects separate.
▪ ROOT— Oracle-owned objects
▪ PDB— Unique user-created data
— Pointers to ROOT dictionary
#C
15
LV
15
Pluggable Databases : Save money and time cont’d
■ Data Dictionary Architecture cont’d▪ Reduce unnecessary duplication
▪ Efficient upgrade path— i.e. DBMS_SCHEDULER package only in CDB$ROOT
■ Dictionary Separation provided by Links■ Metadata Links
▪ Managed automatically, not user-modifiable— maintain the metadata about dictionary objects in the root
— column definitions for Oracle-owned table exist only in the ROOT
— Metadata link in the PDB points to the definition in the ROOT
– i.e. OBJ$ - defined in ROOT, data in PDB
▪ User-defined objects reside completely in the PDB.(container)
▪ Includes init.ora
#C
15
LV
16
Pluggable Databases : Save money and time cont’d
■ Metadata Links cont’d■ Object Links - The other side of the coin
— Store non-root container data for some special objects in the ROOT
– AWR data (DBA_HIST_ACTIVE_SESSION)
– Available to all containers.
■ Container Data Objects (CDO(my term))▪ Tables/views - data from multiple containers and/or the CDB
▪ built-in - restricts data based on common user permissions
▪ Oracle-Supplied views - V$ and CDB_ are examples of CDO’s— CON_ID column – determine source
— CDB_* data returned based on which container you’re connected to:
– From ROOT – query metadata across all containers
– From PDB – returns data only from that container
#C
15
LV
17
Pluggable Databases : Save money and time cont’d
■ Container Data Objects cont’d▪ Container ID Maps To
0 The Whole CDB or a non-CDB
1 CDB$ROOT2 PDB$SEED3+ User-created PDB
▪ DEMO
@d020
#C
15
LV
18
Pluggable Databases : Save money and time cont’d
■ CDB_ vs DBA_■ ROOT: PDBORCL12a1:■ select count(*)■ from CDB_tables■ COUNT(*) COUNT(*)■ -------------- --------------■ 4747 2409■ ■ select count(*)■ from DBA_tables■ COUNT(*) COUNT(*)■ -------------- --------------■ 2338 2409
#C
15
LV
19
Pluggable Databases : Save money and time cont’d
■ Current Container■ The container in which the current session is running.
▪ can be in the root, for common users
▪ a PDB.
■ A session has only one current container at any point in time.▪ name resolution /privilege authorization – curr. container’s dict.
■ Cross container operation ▪ DDL statement that affects the CDB, multiple containers, entities
in common containers or a container different than the issuing user’s current container.
▪ include database recovery and common user modifications.
■ DEMO - files
@d030
#C
15
LV
20
Pluggable Databases : Save money and time cont’d
■ Services and Connections■ connect to a PDB using a service
▪ starts a session in a PDB— current container - permanent for the lifetime of the session.
#C
15
LV
21
Pluggable Databases : Save money and time cont’d
■ Demo▪ Standalone database
— Upgrade to 12c
— Other options, but more complicated
▪ Read-Only
▪ Describe the standalone db – generate xml manifest— dbms_pdb.describe()
– Back it up w/ the datafiles – SCN in all must match
▪ In CDB:— dbms_pdb.check_plug_compatibility
— query pdb_plug_in_violations for ERRORS/WARNINGS(cdb$root)
▪ Create PLUGGABLE DATABASE pdb1 using ‘c:\manifiest.xml’
▪ Run noncdb_to_pdb.sql in the NEW PDB.
#C
15
LV
22
Pluggable Databases : Save money and time cont’d
DEMO cont’d■ Create description/manifestexec dbms_pdb.describe(pdb_descr_file=>
'C:\Data\Collab2015\noncdb12b.xml');
#C
15
LV
Pluggable Databases : Save money and time cont’d
DEMO cont’d
DECLARE compatibility CONSTANT VARCHAR2(3) := CASE DBMS_PDB.CHECK_PLUG_COMPATIBILITY( pdb_descr_file => 'C:\Data\Collab2015\noncdb12b.xml', pdb_name => 'PDBORCL12A2') WHEN TRUE THEN 'Db to be PLUGGED in is COMPATIBLE' ELSE 'Db to be PLUGGED in is *** NOT COMPATIBLE ***'END;BEGIN DBMS_OUTPUT.PUT_LINE(compatibility);END;
23
#C
15
LV
Pluggable Databases : Save money and time cont’d
DEMO cont’d■ Check for Errors (still in CDB$ROOT)
▪ SET lines 200
▪ col message FOR a100
▪ SET pages 100
▪ SELECT name,cause,TYPE,message FROM PDB_PLUG_IN_VIOLATIONS WHERE name='PDBORCL12A2';
24
#C
15
LV
Pluggable Databases : Save money and time cont’d
■ DEMO cont’d▪ DEMO
xx@d040
25
#C
15
LV
Pluggable Databases : Save money and time cont’d
■ DEMO cont’d
26
#C
15
LV
Pluggable Databases : Save money and time cont’d
■ Gotcha’s▪ Windows user accounts
▪ Standardization— Database options
— Database version
▪ Multiple ways to get there
▪ Non-CDBs are deprecated in 12c
▪ Oracle recommends using CDBs (single-tenant or multitenant)
▪ New paradigm – it’s coming, best to get used to it now
▪ Noncdb_to_pdb.sql – errors out/closes sqlplus if not run from the PDB - duh.
27
#C
15
LV
28
Pluggable Databases :Save money and time cont’d
■ References▪ Tanel Poder
▪ also see http://blog.yannickjaquier.com/oracle/multitenant-standalone-to-pluggable-migration.html
#C
15
LV
Please complete the session evaluationWe appreciate your feedback and insight
You may complete the session evaluation either on paper or online via the mobile app
#C
15
LV
30
Demo Scripts-- --- DEMO START 0 ----------------- CDB/PDB
select INSTANCE_NAME, CON_ID,VERSION, status, logins, shutdown_pending, DATABASE_STATUS, ACTIVE_STatefrom v$instance/
prompt CDB/PDB infoCOLUMN name FORMAT A30
prompt SERVICEt info:SELECT name, pdbFROM v$servicesORDER BY name/
prompt CURRENT CONTAINER info:
--col "Container" format a16--col "Container_ID" format a16col CON_NAME format a16col CON_ID format a16
SELECT SYS_CONTEXT('USERENV', 'CON_NAME') "CON_NAME", SYS_CONTEXT('USERENV', 'CON_ID') "CON_ID"FROM dual/
-- dupe name - diff datatype-- cdb_info.sql - almost te same as show pdbscol CON_ID format 999999999999prompt PDB info:select CON_ID, --DBID, NAME,OPEN_MODE,--RESTRICTEDSNAPSHOT_PARENT_CON_IDfrom v$pdbs/
-- condollar - show all containers and id's
select CON_ID#, DBIDfrom sys.CONTAINER$/
-- cdatafile_info-- cdatafile_info.sql
col file_name for a75col TABLESPACE_NAME for a30
prompt CDB_data_files--select * from cdb_data_filesselect CON_ID,FILE_NAME,FILE_ID,Rpad(TABLESPACE_NAME, 30, ' .') TABLESPACE_NAME,--BYTES--BLOCKS--STATUS--RELATIVE_FNOAUTOEXTENSIBLE,MAXBYTES,--MAXBLOCKS--INCREMENT_BY--USER_BYTES--USER_BLOCKSONLINE_STATUSfrom cdb_data_filesorder by file_id/
prompt DBA_DATA_FILESselect 'NULL ' Conn_ID,FILE_NAME,FILE_ID,TABLESPACE_NAME,--BYTES--BLOCKS--STATUS--RELATIVE_FNOAUTOEXTENSIBLE,MAXBYTES,--MAXBLOCKS--INCREMENT_BY--USER_BYTES--USER_BLOCKSONLINE_STATUS
from dba_data_filesorder by file_id/
set timing on
-- --- CONVERT 1 ------------------ STANDALONE
#rem In a PLAIN DOS windowset ORACLE_SID=ncdb12bset SQLPATH=C:\Data\DBA\scripts\sql
sqlplus / as sysdbaset lin 200set pages 49999set sqlblanklines on
select INSTANCE_NAME, VERSION, status, logins, shutdown_pending, DATABASE_STATUS, ACTIVE_STate, CON_IDfrom v$instance/
-- in noncdb12bshutdown immediate
startup mount exclusiveselect * from v$instance;
alter database open read only;select * from v$instance;
-- generate the manifest of the NONcdb - -- writes SCN into the xml - matching the headers of the datafiles..
exec dbms_pdb.describe(pdb_descr_file=>'C:\Data\Oracle_Training\noncdb12bmodC1a.xml');
-- --- CONVERT 2 ------------------ CDB
-- IN CDB
set feedback offSET SERVEROUTPUT ONDECLARE compatibility CONSTANT VARCHAR2(40) := CASE DBMS_PDB.CHECK_PLUG_COMPATIBILITY( pdb_descr_file => 'C:\Data\Oracle_Training\noncdb12bmodC1a.xml', pdb_name => 'PDBORCL12C1') WHEN TRUE THEN 'Db to be PLUGGED-IN is COMPATIBLE' ELSE 'Db to be PLUGGED-IN is *** NOT COMPATIBLE ***'END;BEGIN DBMS_OUTPUT.PUT_LINE(' . .'); DBMS_OUTPUT.PUT_LINE(compatibility); DBMS_OUTPUT.PUT_LINE(' . .');END;/
set feedback ON
-- --- CONVERT 3 ------------------ non-CDB---- shutdown noncdb, prepare to copy the data files
shutdown immediate
-- copy files if necessary
-- --- CONVERT 4 ------------------ CDB
--... in the CDB
-- this is BEFORE the create. (JM)
SET lines 200col message FOR a100SET pages 100
SELECT name,cause,TYPE,message FROM PDB_PLUG_IN_VIOLATIONS WHERE name='PDBORCL12C1';
-- OR check for ANY prior db errors--SELECT name,cause,TYPE,message FROM PDB_PLUG_IN_VIOLATIONS
--Create a PDB by using the noncdb manifest file. Use the file_name_convert parameter to place the copied data files in a different location.
create pluggable database PDBORCL12C1 using 'C:\Data\Oracle_Training\noncdb12bmodC1a.xml'copy file_name_convert=('C:\app\oracle\oradata\ncdb12b', 'C:\APP\ORACLE\ORADATA\ORCL12A\ORCL12A\PDBORCL12B1')tempfile reuse
-- CHECK ALERT LOGS for my 1st successful PLUGIN !!!! Tuesday. then recreate a 3rd and see if it was the exit cmd tha closed my window???
--@cdb -- show COntainer informationprompt CDB/PDB infoCOLUMN name FORMAT A30
prompt SERVICEt info:SELECT name, pdbFROM v$servicesORDER BY name/
prompt CURRENT CONTAINER info:
--col "Container" format a16--col "Container_ID" format a16col CON_NAME format a16col CON_ID format a16
SELECT SYS_CONTEXT('USERENV', 'CON_NAME') "CON_NAME", SYS_CONTEXT('USERENV', 'CON_ID') "CON_ID"FROM dual/
-- dupe name - diff datatype-- cdb_info.sql - almost te same as show pdbscol CON_ID format 999999999999prompt PDB info:select CON_ID, --DBID, NAME,OPEN_MODE,--RESTRICTEDSNAPSHOT_PARENT_CON_IDfrom v$pdbs/
3.Finalize the plug-in by opening the new PDB, closing it, and then reopening it.
alter pluggable database PDBORCL12C1 open;
alter pluggable database PDBORCL12C1 close;
alter pluggable database PDBORCL12C1 open;
-- change to the PDB !!!!!!! -- ...in PDB
--@altp-- altp.sql-- USAGE - pass the #ic protion of the pdb name, already have the prefix (pdborcl) in place.
PROMPT USAGE - pass the #ic portion of the pdb name, already have the prefix (pdborcl) in place.
ALTER SESSION SET container = pdborcl&1/
-- script is in the CDB's ORACLE_HOME@?\rdbms\admin\noncdb_to_pdb.sql
-- start 1:48, end 2:10
--closes session if not in the NEW PDB!
-- WAITING for conversion to complete - review more CDB details -- ...... approximately 20 min on a laptop
-- Notice the datafiles from the new PDB are not visible from the CDB ROOT yet.--@cdatafile_info-- cdatafile_info.sql
col file_name for a75col TABLESPACE_NAME for a30
prompt CDB_data_files--select * from cdb_data_filesselect CON_ID,FILE_NAME,FILE_ID,Rpad(TABLESPACE_NAME, 30, ' .') TABLESPACE_NAME,--BYTES--BLOCKS--STATUS--RELATIVE_FNOAUTOEXTENSIBLE,MAXBYTES,--MAXBLOCKS--INCREMENT_BY--USER_BYTES--USER_BLOCKSONLINE_STATUSfrom cdb_data_filesorder by file_id/
prompt DBA_DATA_FILESselect 'NULL ' Conn_ID,FILE_NAME,FILE_ID,TABLESPACE_NAME,--BYTES--BLOCKS--STATUS--RELATIVE_FNOAUTOEXTENSIBLE,MAXBYTES,--MAXBLOCKS--INCREMENT_BY--USER_BYTES--USER_BLOCKSONLINE_STATUS
from dba_data_filesorder by file_id
-- check the registrycol comp_id for a10col comp_name for a35col version for a12col status for a12
select * from registry$history
select COMP_ID, COMP_NAME, VERSION, STATUS, MODIFIEDfrom dba_registry
-- The datafiles from the new PDB will be visible from the CDB ROOT AFTER the restart.-- Need close/reopen to get everything in sync
alter pluggable database PDBORCL12C1 CLOSE
alter pluggable database PDBORCL12C1 OPEN
-- now see files across ALL containers.
--@cdatafile_info-- cdatafile_info.sql
col file_name for a75col TABLESPACE_NAME for a30
prompt CDB_data_files--select * from cdb_data_filesselect CON_ID,FILE_NAME,FILE_ID,Rpad(TABLESPACE_NAME, 30, ' .') TABLESPACE_NAME,--BYTES--BLOCKS--STATUS--RELATIVE_FNOAUTOEXTENSIBLE,MAXBYTES,--MAXBLOCKS--INCREMENT_BY--USER_BYTES--USER_BLOCKSONLINE_STATUSfrom cdb_data_filesorder by file_id/
prompt DBA_DATA_FILESselect 'NULL ' Conn_ID,FILE_NAME,FILE_ID,TABLESPACE_NAME,--BYTES--BLOCKS--STATUS--RELATIVE_FNOAUTOEXTENSIBLE,MAXBYTES,--MAXBLOCKS--INCREMENT_BY--USER_BYTES--USER_BLOCKSONLINE_STATUS
from dba_data_filesorder by file_id/