Application Containers

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.

Create the Application Root

SQL> create pluggable database myapp_root as application container admin user rob identified by rob roles = (DBA);

Pluggable database created.

SQL> alter pluggable database myapp_root open;

Pluggable database altered.

SQL> alter pluggable database myapp_root save state;

Pluggable database altered.

Create an application inside the Application Root

SQL> alter session set container = myapp_root;

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

Pluggable database altered.

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

Tablespace created.

SQL> create user myapp_owner identified by myapp_owner default tablespace myapp_data container=all;

User created.

SQL> grant create session, create table to myapp_owner;

Grant succeeded.

SQL> alter user myapp_owner quota unlimited on myapp_data;

User altered.

SQL> alter session set current_schema=myapp_owner;

Session altered.

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

Table created.

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

Table created.

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

1 row created.

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

1 row created.

SQL> insert into myapp_table values (1);

1 row created.

SQL> commit;

Commit complete.

SQL> alter pluggable database application myapp end install '1.0';

Pluggable database altered.

Create an application PDB

SQL> create pluggable database myapp_one admin user rob identified by rob;      

Pluggable database created.

SQL> alter pluggable database myapp_one open;

Pluggable database altered.

SQL> alter pluggable database myapp_one save state;

SQL> alter session set container=myapp_one;

Session altered.

SQL> alter pluggable database application myapp sync;

Pluggable database altered.

SQL> show user
USER is "SYS"

SQL> show con_name       

CON_NAME
------------------------------
MYAPP_ONE

SQL> select * from myapp_owner.myapp_static; 

         N S
---------- --------------------
         1 ONE
         2 TWO

Create an Application Seed (optional)

An application root container can optionally have an application seed database, allowing you to have a preconfigured seed for creation of new application containers. An application seed can be created from the CDB seed, an existing application container or an application root container. In this example we will create a new application seed from the CDB seed.

To create an application seed from an existing application pdb (the easiest way):

SQL> show con_name

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

SQL> create pluggable database as seed from myapp_one;

Pluggable database created.

SQL> alter pluggable database myapp_root$SEED open;

Pluggable database altered.

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

Pluggable database altered.

Update the Application in the Application Root

Connect to the application root and proceed:

SQL> alter session set containar=myapp_root;

SQL> select app_name, app_version from dba_app_versions where app_name = 'MYAPP';

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

SQL> ALTER PLUGGABLE DATABASE APPLICATION myapp BEGIN UPGRADE '1.0' TO '1.1';

Pluggable database altered.


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

Table created.

SQL> ALTER PLUGGABLE DATABASE APPLICATION myapp end upgrade;

Pluggable database altered.

SQL> select app_name, app_version from dba_app_versions;

APP_NAME                                 APP_VERSION
---------------------------------------- ------------------------------
APP$AF7FD61EEFBB6141E0533800A8C05EB8     1.0
MYAPP                                    1.0
MYAPP                                    1.1

Synchronize the changes in the Application Containers

SQL> alter pluggble database myapp_root$SEED open;

SQL> alter session set container=myapp_root$SEED;

Session altered.

SQL> select app_name, app_version from dba_app_versions;

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

SQL> select table_name from dba_tables where owner = 'MYAPP_OWNER';

TABLE_NAME
--------------------
MYAPP_TABLE
MYAPP_STATIC

SQL> ALTER PLUGGABLE DATABASE APPLICATION myapp SYNC;

Pluggable database altered.

SQL> select app_name, app_version from dba_app_versions where app_name = 'MYAPP';

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

SQL>  select table_name from dba_tables where owner = 'MYAPP_OWNER';

TABLE_NAME
--------------------
MYAPP_TABLE
MYAPP_STATIC
ROBS_UPDATE

SQL> alter session set container=myapp_root;

Session altered.

SQL> alter pluggable database myapp_root$SEED close immediate;

Pluggable database altered.

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

Pluggable database altered.

Additional Remarks

=== Closing the Application Root When you close the application root, the application pdbs are automatically closed as well

SQL> alter pluggable database pdb10 close immediate;

Pluggable database altered.

SQL> alter pluggable database north close immediate;
alter pluggable database north close immediate
*
ERROR at line 1:
ORA-65020: pluggable database NORTH already closed
=== dropping the application root ===
You can only drop the application root, after all the application pdb’s are dropped:
SQL> drop pluggable database pdb10 including datafiles;
drop pluggable database pdb10 including datafiles
*
ERROR at line 1:
ORA-65265: PDB cannot be dropped or unplugged.

=== Synching the application ===
Syncing an application needs to be done via the application PDB, not via the application root
<[re>
SQL> alter pluggable database application myapp sync;
alter pluggable database application myapp sync
*
ERROR at line 1:
ORA-65272: operation not allowed from outside an application PDB


SQL> show con_name

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