Neste artigo, vamos explorar a criação de Applications PDBs a partir do Application Root gerado em nosso último post.
Logando no Application Root:
[oracle@quiasma admin]$ sqlplus sys/oracle@HR_AC as sysdba
SQL*Plus: Release 18.0.0.0.0 - Production on Tue Jul 6 19:54:40 2021
Version 18.13.0.0.0
Copyright (c) 1982, 2018, Oracle. All rights reserved.
Connected to:
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
Version 18.13.0.0.0
SQL> SHOW CON_ID CON_NAME;
CON_ID
------------------------------
5
CON_NAME
------------------------------
HR_AC
Agora vamos disparar a criação de um PDB. Como estamos conectados em um Application Root, automaticamente teremos a criação de um Application PDB (Container):
SQL> CREATE PLUGGABLE DATABASE hr_pdb1 admin user hr_pdb1adm identified by oracle;
Pluggable database created.
Abrindo o novo Application PDB e salvando o seu status:
SQL> ALTER PLUGGABLE DATABASE hr_pdb1 OPEN;
Pluggable database altered.
SQL> ALTER PLUGGABLE DATABASE hr_pdb1 SAVE STATE;
Pluggable database altered.
Validando o status do Application PDB:
SQL> SELECT STATUS FROM DBA_PDBS WHERE PDB_NAME='HR_PDB1';
STATUS
----------
NORMAL
Nesse ponto, podemos realizar uma operação importante: após fazer o switch de conexão para o PDB criado, podemos “sincronizá-lo” com o Application Root:
SQL> ALTER SESSION SET CONTAINER=hr_pdb1;
Session altered.
SQL> ALTER PLUGGABLE DATABASE APPLICATION hr_app SYNC;
Pluggable database altered.
Conectando ao Application PDB e validando o conteúdo de alguns objetos:
SQL> conn hr/oracle@//quiasma:1521/hr_pdb1.localdomain
Connected.
SQL> SELECT TNAME FROM TAB ;
TNAME
--------------------------------------------------------------------------------
COUNTRIES
DEPARTMENTS
EMPLOYEES
JOBS
LOCATIONS
REGIONS
6 rows selected.
SQL> SELECT * FROM REGIONS ;
REGION_ID REGION_NAME
---------- -------------------------
1 Europe
2 Americas
3 Asia
4 Middle East and Africa
SQL> SELECT SEQUENCE_NAME FROM USER_SEQUENCES ;
SEQUENCE_NAME
--------------------------------------------------------------------------------
DEPARTMENTS_SEQ
EMPLOYEES_SEQ
LOCATIONS_SEQ
Para nos permitir validar outros recursos em artigos posteriores, vamos criar um segundo Application PDB conforme abaixo:
SQL> conn sys/oracle@hr_ac as sysdba
Connected.
SQL> CREATE PLUGGABLE DATABASE hr_pdb2 admin user hr_pdb2adm identified by oracle;
Pluggable database created.
SQL> ALTER PLUGGABLE DATABASE hr_pdb2 OPEN;
Pluggable database altered.
SQL> ALTER PLUGGABLE DATABASE hr_pdb2 SAVE STATE;
Pluggable database altered.
SQL> ALTER SESSION SET CONTAINER=hr_pdb2;
Session altered.
SQL> ALTER PLUGGABLE DATABASE APPLICATION hr_app SYNC;
Pluggable database altered.
SQL> conn hr/oracle@//quiasma:1521/hr_pdb2.localdomain
Connected.
SQL> SELECT TNAME FROM TAB ;
TNAME
--------------------------------------------------------------------------------
COUNTRIES
DEPARTMENTS
EMPLOYEES
JOBS
LOCATIONS
REGIONS
6 rows selected.
Validando todos os PDBs criados:
SQL> conn sys/oracle@HR_AC as sysdba
Connected.
SQL> SHOW PDBS;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
5 HR_AC READ WRITE NO
6 HR_PDB1 READ WRITE NO
7 HR_PDB2 READ WRITE NO
SQL> conn / as sysdba
Connected.
SQL> SHOW PDBS;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 HIPOFISE2 READ WRITE NO
4 HIPOFISE1 READ WRITE NO
5 HR_AC READ WRITE NO
6 HR_PDB1 READ WRITE NO
7 HR_PDB2 READ WRITE NO
Obs: Este procedimento foi criado pelo senhor Ahmed Baraka (www.ahmedbaraka.com) e foi apenas reproduzido por mim em um laboratório pessoal para fins de aprendizado.