Create an application container and application

From Robs_Wiki
Jump to: navigation, search
Introduction
========

Oracle 12.2 introduces the concept of application containers, which act like a mini-root container. They can be used to centralize shared configuration and applications, which are used by their dependent application PDBs

Step 1 Create Application Root
==================
SQL> create pluggable database myapp_root as application container admin user pdbadmin identified by pdbadmin roles = (DBA); 

SQL> alter pluggable database myapp_root open;  

SQL> alter pluggable database myapp_root save state; 

Step 2 Create Application Containers
======================
Creating an application PDB is the same as creating a regular PDB. The only difference is that you need to connect to the application root first !

SQL> alter session set container = myapp_root;

SQL> create pluggable database myapp_one admin user pdbadmin identified by pdbadmin roles = (DBA); 

SQL> alter pluggable database myapp_one open; 

SQL> alter pluggable database myapp_one save state;

Step 3 Create the application
=================
Connect to the application root and install the application

SQL> alter session set container=myapp_root;

--create the application
SQL> alter pluggable database application myapp begin install '1.0'; 

-- create the tablespace
SQL> create tablespace myapp_data datafile size 10M autoextend on maxsize 500M; 

--create the application owner and application objects
SQL> create user myapp_owner identified by myapp_owner default tablespace myapp_data container=all;

SQL> grant create session, create table to myapp_owner; 

SQL> alter user myapp_owner quota unlimited on myapp_data; 

SQL> alter session set current_schema=myapp_owner; 

SQL> create table myapp_table sharing=metadata (n number primary key); 

SQL> create table myapp_static sharing=data (n number primary key, s varchar2(20)); 

SQL> insert into myapp_static values (1,'ONE'); 

SQL> insert into myapp_static values (2,'TWO'); 

SQL> insert into myapp_table values (1); 1 row created.

 SQL> commit; 
 
-- complete the installation
SQL> alter pluggable database application myapp end install '1.0';
  
Step 4 synchronize the application
=====================

SQL> alter session set container=myapp_one; 

SQL> alter pluggable database application myapp sync;

Step 5 Check the version of the application
==========================
SQL> select app_name, app_version from dba_app_versions where app_name = 'MYAPP'; 

APP_NAME       APP_VERSION 
----------------      ------------------- 
MYAPP               1.0

Step 6 update the application
=================
After the application is upgraded, the application containers need to resync to adopt the changes. 
 
 SQL> alter session set containar=myapp_root; 
 
 SQL> select app_name, app_version from dba_app_versions where app_name = 'MYAPP'; 
 
SQL> ALTER PLUGGABLE DATABASE APPLICATION myapp BEGIN UPGRADE '1.0' TO '1.1';

SQL> create table myapp_owner.robs_update (kol1 varchar2(10));

SQL> ALTER PLUGGABLE DATABASE APPLICATION myapp end upgrade;

SQL> select app_name, app_version from dba_app_versions;

APP_NAME       APP_VERSION 
----------------      ------------------- 
MYAPP               1.0
MYAPP               1.1

Step 6 create an application seed (optional)
==========================
This is an optional choice. If you configure an application seed new applications will be created based on this application seed.

SQL> show con_name 

CON_NAME 
------------------------------ 
MYAPP_ROOT 

SQL> create pluggable database as seed from myapp_one; 

SQL> alter pluggable database myapp_root$SEED open read only;

--Remark: the application seed needs to be synchronize just like the application containers. In order to to do so it needs to be opened in Read / Write mode temporarily:

SQL> alter session set container=myapp_root;
SQL> altter pluggable database myapp_root$SEED open read only;
SQL> alter session set container=myapp_root$SEED;
SQL> alter pluggable database application myapp sync;
SQL> alter session set container=myapp_root;
SQL> alter pluggable database myapp_root$SEED open read only;