con8926 good-con8926 bryn llewellyn plsql app to self provision pdbs
DESCRIPTION
12c DatabaseTRANSCRIPT
Self-provisioningpluggable databasesusing PL/SQL
Bryn Llewellyn,Distinguished Product Manager,
Database Server Technologies Division
Oracle HQ
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.3
The following is intended to outline our general product direction. It is intended
for information purposes only, and may not be incorporated into any contract.
It is not a commitment to deliver any material, code, or functionality, and should
not be relied upon in making purchasing decisions. The development, release,
and timing of any features or functionality described for Oracle’s products
remains at the sole discretion of Oracle.
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.4
Agenda
The primitive top-level SQL statements
The “raw” PL/SQL encapsulation AS SYSDBA
The privilege model
Using the raw encapsulation safely via the
new-in-12.1 scheduler a Job_Type, SQL_SCRIPT
Other uses of the scheduler job method
Summary
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.5
The macroscopic provisioning operations
Create PDB
Clone PDB
Unplug PDB
Plug in PDB
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.6
The macroscopic provisioning operations
Create PDB
Clone PDB
Unplug PDB
Plug in PDB
Drop PDB
Also, set the mode
read-write, read-only, mounted | restricted?
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.7
The SQL statements
create pluggable database... admin user... identified by...
create pluggable database... from...
alter pluggable database... unplug into...
-- "as clone" is incompatible with "move"
create pluggable database... [as clone] using... [copy/move]
-- "keep" makes sense only after "unplug"
drop pluggable database... [including/keep] datafiles
alter pluggable database... close [immediate] [force]
alter pluggable database... open [read only/read write] [restricted]
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.9
Raw PL/SQL encapsulation: create a PDB
begin
execute immediate '
create pluggable database PDB1
admin user PDB_Admin identified by oracle
default tablespace Users';
execute immediate '
alter pluggable database PDB1 open';
Execute_Stmt_In_PDB1(
'grant Sysdba to PDB_Admin with admin option');
end;
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.10
“alter session set container”is illegal from PL/SQL
procedure Execute_Stmt_In_PDB1(Stmt in varchar2) is
Cur integer := DBMS_Sql.Open_Cursor(Security_Level=>2);
Dummy integer;
begin
Dbms_Sql.Parse(
c=>Cur,
Statement=>Stmt,
Container=>'PDB1',
Language_Flag=>DBMS_Sql.Native);
Dummy := DBMS_Sql.Execute(Cur);
DBMS_Sql.Close_Cursor(Cur);
end Execute_Stmt_In_PDB1;
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.11
Raw PL/SQL encapsulation: clone a PDB
declare
Source_Open_Mode Sys.v_$PDBs.Open_Mode%type not null := '?';
begin
select a.Open_Mode
into Source_Open_Mode
from Sys.v_$PDBs a
where a.Name = 'PDB3';
if Source_Open_Mode = 'READ WRITE' then
execute immediate 'alter pluggable database PDB3 open read only force';
end if;
execute immediate 'create pluggable database PDB4 from PDB3';
if Source_Open_Mode = 'READ WRITE' then
execute immediate 'alter pluggable database PDB3 open read write force';
end if;
execute immediate 'alter pluggable database PDB4 open read write';
end;
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.12
Basic PL/SQL encapsulation
Demo
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.13
The PL/SQL API – core
procedure Sys.Create_PDB(
PDB_Name in varchar2)
procedure Sys.Clone_PDB(
Source_PDB_Name in varchar2, Clone_PDB_Name in varchar2)
procedure Sys.Unplug_PDB(
PDB_Name in varchar2, Manifest_Dir in varchar := null)
procedure Sys.Plug_In_PDB(
PDB_Name in varchar2, Manifest_Dir in varchar2 := null)
procedure Sys.Drop_PDB_Incl_Files(
PDB_Name in varchar2)
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.14
The API – extras
function Check_Plug_Compatibility(
PDB_Name in varchar2, Manifest_Dir in varchar2 := null)
return varchar2
view PDBs(Name, Open_Mode, Res, Status, Create_Scn)
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.15
The privilege model
“create PDB” requires the system privilege
Create Pluggable Database
The “drop PDB” and “alter PDB” statements require
a session authorized AS SYSOPER
These are mutually incompatible during the lifetime
of a session
AS SYSDBA is the only viable superset
The “AS” mode of a session cannot be encapsulated
by definer’s rights PL/SQL
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.16
The scheduler’s Job_Type => 'Sql_Script'
New in 12.1
Create a SQL*Plus script programmatically
Have it executed by SQL*Plus on the server
Use a credential for the o/s username/password
Use a credential for the database username/password
and role (e.g. AS SYSDBA)
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.17
The scheduler’s Job_Type => 'Sql_Script'
Demo
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.18
Other uses of Job_Type => 'Sql_Script'
Run noncdb_to_pdb.sql from a provisioning app
The modern model for o/s authentication
for “batch jobs” in a PDB
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.19
Job_Type => 'Sql_Script‘ for noncdb_to_pdb.sql
Demo
(but it takes 7 minutes)
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.20
Putting the PL/SQL API through its paces
Demo
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.22
Summary
The primitive SQL operations on PDBs as entities
are very fast
It’s easy to encapsulate the macroscopic PDB
provisioning task in PL/SQL, exposing each as a
suitably parameterized procedure
So the provisioning procedures are very fast too!
With a functional PL/SQL API, you can build any app
you want, with the business rules you want, in the
classic way
Copyright © 2012, Oracle and/or its affiliates. All rights reserved.23
The downloadable APEX app forself-provisioning PDBs
http://www.oracle.com/technetwork/database/
multitenant/downloads/index.html