Verificando se o banco de dados é CDB
SQL> select cdb from v$database; CDB --- YES
Conectando ao Container
$ export ORACLE_SID=pcdb01 $ sqlplus / as sysdba SQL> show con_name CON_NAME ------------------------------ CDB$ROOT SQL> show con_id CON_ID ------------------------------ 1 SQL> show pdbs; CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 PRD_PDB_CON READ WRITE NO 4 PRD_PDB_TEN READ WRITE NO
Navegando pelos PDBs
SQL> alter session set container=PDB$SEED; Session altered. SQL> alter session set container=PRD_PDB_CON; Session altered.
Informações sobre PDBs
SQL> COLUMN PDB_NAME FORMAT A15 SQL> COLUMN PDB_NAME FORMAT A15 SQL> SELECT PDB_ID, PDB_NAME, STATUS FROM DBA_PDBS ORDER BY PDB_ID; PDB_ID PDB_NAME STATUS ---------- --------------- --------- 2 PDB$SEED NORMAL 3 PRD_PDB_CON NORMAL 4 PRD_PDB_TEN NORMAL
Verificando/alterando parâmetro
SQL> select * from v$system_parameter; SQL> select * from PDB_SPFILE$; SQL> alter system set parameter_name=value; SQL> alter system set parameter_name=value CONTAINER=CURRENT;
Iniciando e Parando o PDB
Alguns valores:
STARTUP [NOMOUNT | MOUNT | RESTRICT | UPGRADE | FORCE | READ ONLY]
SHUTDOWN [IMMEDIATE | ABORT]
$ export ORACLE_SID=pcdb01 $ sqlplus / as sysdba SQL> shutdown immediate;
Parando o Pluggable Database
SQL> alter pluggable database PRD_PDB_CON close [immediate]; SQL> alter pluggable database ALL EXCEPT PRD_PDB_CON close [immediate]; SQL> alter pluggable database ALL close; SQL> alter pluggable database PRD_PDB_CON close [immediate] [instances=all];
Ou:
SQL> alter SESSION SET CONTAINER = PRD_PDB_CON; SQL> shutdown immediate;
Iniciando o Pluggable Database
STARTUP FORCE
STARTUP OPEN READ WRITE [RESTRICT]
STARTUP OPEN READ ONLY [RESTRICT]
STARTUP UPGRADE
SHUTDOWN [IMMEDIATE]
SQL> alter pluggable database PDB01 open; SQL> alter pluggable database ALL EXCEPT PRD_PDB_CON open; SQL> alter pluggable database ALL open; SQL> alter pluggable database PDB01 open [instances=all];
Ou
SQL> alter SESSION SET CONTAINER = PRD_PDB_CON; SQL> startup;
Preservar o estado de inicialização do PDB (12.1.0.2 em diante)
SQL> alter PLUGGABLE DATABASE pdb2 OPEN; SQL> alter PLUGGABLE DATABASE pdb2 SAVE STATE;
A view DBA_PDB_SAVED_STATES exibe informações sobre o estado salvo dos containers.
SQL> COLUMN con_name FORMAT A20 SQL> COLUMN instance_name FORMAT A20 SQL> SELECT con_name, instance_name, state FROM dba_pdb_saved_states; CON_NAME INSTANCE_NAME STATE -------------------- -------------------- -------------- PRD_PDB_CON pcdb01 OPEN
Checando tamanho do container database
SQL> COLUMN NAME FORMAT A20 SQL> SELECT DBID, NAME, CON_ID, CON_UID, TOTAL_SIZE FROM V$CONTAINERS ORDER BY CON_ID; DBID NAME CON_IDCON_UID TOTAL_SIZE ---------- ------------------------------ ---------- ---------- ---------- 2732069181 CDB$ROOT 1 1 0 3552543733 PDB$SEED 2 3552543733 775946240 4008367944 PRD_PDB_CON 3 4008367944 1203765248 2667104724 PRD_PDB_TEN 4 2667104724 1182793728
Startup time do pluggable database
SQL> set linesize 180 SQL> col name for a30 SQL> col open_time for a33 SQL> select con_id,name,dbid,open_mode,open_time from v$containers; CON_ID NAME DBID OPEN_MODE OPEN_TIME ---------- ---------------- -------------- ---------- ---------- --------------------------------- 1 CDB$ROOT 456650806 READ WRITE 17-MAR-18 11.59.36.176 PM -03:00 2 PDB$SEED 2688102972 READ ONLY 17-MAR-18 11.59.36.182 PM -03:00 3 PDB_PN1O0101 1079206163 READ WRITE 18-MAR-18 12.00.00.589 AM -03:00 4 PDB_BATCHWEB 2340495643 READ WRITE 18-MAR-18 12.00.03.485 AM -03:00 4 rows selected.
Tempo que os PDBs estão operando
SQL> set linesize 180 SQL> col name for a30 SQL> col open_time for a28 SQL> select name,floor(sysdate-cast(open_time as date))||'Days '||floor(((sysdate-cast(open_time as date))-floor(sysdate-cast(open_time as date)))*24)||'hours '||round(((sysdate-cast(open_time as date)-floor(sysdate-cast(open_time as date) )*24)-floor((sysdate-cast(open_time as date)-floor(sysdate-cast(open_time as date))*24)))*60)||'minutes' "Database Uptime" from v$containers; NAME Database Uptime --------------- --------------------------- CDB$ROOT 1331Days 11hours 28minutes PDB$SEED 1331Days 11hours 28minutes PDB_PN1O0101 1331Days 11hours 28minutes PDB_BATCHWEB 1331Days 11hours 28minutes 4 rows selected.
Nome dos serviços
SQL> COLUMN NAME FORMAT A30 SQL> SELECT NAME,CON_ID,PDB FROM V$SERVICES ORDER BY CON_ID; NAME CON_ID PDB ------------------------------ ---------- ------------------------------ pcdb01XDB 1 CDB$ROOT SYS$BACKGROUND 1 CDB$ROOT SYS$USERS 1 CDB$ROOT pcdb01 1 CDB$ROOT prd_pdb_con 3 PRD_PDB_CON prd_pdb_ten 4 PRD_PDB_TEN 6 rows selected.
Criando common users com acesso a todos os pdbs
SQL> CREATE USER c##user1 IDENTIFIED BY password1 CONTAINER=ALL; User created. SQL> GRANT CREATE SESSION TO c##user1 CONTAINER=ALL; Grant succeeded.
Criando usuários comuns sem acessos aos pdbs
SQL> CREATE USER c##user2 IDENTIFIED BY password1; User created. SQL> GRANT CREATE SESSION TO c##user2; Grant succeeded.
Criando usuários locais com acesso apenas ao pdb
SQL> CREATE USER user3 IDENTIFIED BY password3 CONTAINER=CURRENT; User created. SQL> GRANT CREATE SESSION TO user3 CONTAINER=CURRENT; Grant succeeded.
Criando role comum
SQL> CONN / AS SYSDBA SQL> CREATE ROLE c##role1; Role created. SQL> GRANT CREATE SESSION TO c##role1; Grant succeeded.
Conceder role a um usuário comum
SQL> GRANT c##role1 TO c##user1 CONTAINER=ALL; Grant succeeded.
Roles Locais
SQL> CONN / AS SYSDBA SQL> alter SESSION SET CONTAINER = PRD_PDB_CON; Session altered. SQL> CREATE ROLE role1; Role created. SQL> GRANT CREATE SESSION TO role1; Grant succeeded.
Criando PDBs
SQL> create pluggable database HMLPDB admin user admin identified by PassDw1 roles = (DBA); SQL> create pluggable database DSVPDB admin user admin identified by Manager1roles = (DBA) storage (MAXSIZE 1G) FILE_NAME_CONVERT=('/u01/app/oracle/oradata/pcdb01/pcdb01_pdbseed_','/u01/app/oracle/oradata/dsvpdb/dsvpdb_'); SQL> create pluggable database DSVPDB1 from DSVPDB file_name_convert=('/DSVPDB/','/DSVPDB1/');
Excluindo PDBs
SQL> alter pluggable database DSVPDB1 close [immediate] [instances=all]; SQL> drop pluggable database DSVPDB1 including datafiles;
Desplugando (unplugging) PDBs
$ sqlplus / as sysdba SQL> alter pluggable database PRD_PDB_CON close; SQL> alter pluggable database PRD_PDB_CON unplug into '/tmp/prd_pdb_con.xml';
Plugando (plugging) PDBs
$ sqlplus / as sysdba SQL> create pluggable database PRD_PDB_CON using '/tmp/prd_pdb_con.xml' FILE_NAME_CONVERT=('/oradata/cdb1/prd_pdb_con', '/oradata/cdb2/prd_pdb_con'); SQL> alter pluggable database PRD_PDB_CON open;
Configurando serviços no Oracle RAC com CDBs
$ srvctl add service -db CDB01 -service new_service -pdb PRD_PDB_CON $ srvctl modify service -db CDB01 -service new_service -pdb PRD_PDB_CON $ srvctl remove service -db CDB01 -service new_service BEGIN DBMS_SERVICE.CREATE_SERVICE( service_name => 'new_service', network_name => 'new_service.com'); END; / BEGIN DBMS_SERVICE.DELETE_SERVICE( service_name => 'new_service'); END; /
Com o root container, as views cdb_tablespaces e cdb_data_files mostra as tablespaces e datafiles de todo container no CDB.
Quando conectado a um PDB, as views cdb_tablespaces e cdb_data_files mostram as mesmas informações que as views dba_tablespaces e dba_data_files para o PDB.
SQL> alter session set container=CDB$ROOT; Session altered. SQL> select tablespace_name, con_id from cdb_tablespaces order by con_id; TABLESPACE_NAME CON_ID ------------------------------ -------- SYSTEM 1 SYSAUX 1 UNDOTBS2 1 TEMP 1 USERS 1 UNDOTBS1 1 SYSTEM 3 SYSAUX 3 TBS_GEN_01 3 TEMP 3 TBS_CON_IDX_01 3 TBS_CON_DT_01 3 USERS 3 SYSTEM 4 SYSAUX 4 TBS_GEN_01 4 USERS 4 TEMP 4 18 rows selected. SQL> select tablespace_name from dba_tablespaces; TABLESPACE_NAME ------------------------------ SYSTEM SYSAUX UNDOTBS1 TEMP USERS UNDOTBS2 6 rows selected.
Como verificar Local Undo no Oracle 12 release 2
No Oracle Database 12c Release 1, todos os containers em uma instância compartilha a mesma tablespace de UNDO.
No Oracle 12c Release 2, cada container em uma instância pode usar sua própria tablespace de UNDO.
SQL> shutdown immediate; SQL> startup upgrade; SQL> alter database local undo on; SQL> shutdown immediate; SQL> startup; SQL> col property_name format a30 SQL> col property_value format a30 SQL> select property_name, property_value from database_properties where property_name = 'LOCAL_UNDO_ENABLED'; PROPERTY_NAME PROPERTY_VALUE ---------------- -------------- LOCAL_UNDO_ENABLED TRUE