Sprawdź, czy baza danych to CDB czy nie
SQL> select cdb from v$database; CDB --- YES
Łączenie z kontenerem
$ 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
Nawiguj po plikach PDB
SQL> alter session set container=PDB$SEED; Session altered. SQL> alter session set container=PRD_PDB_CON; Session altered. SQL>
Informacje o plikach PDB
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
Sprawdzanie/zmiana parametrów
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;
Uruchamianie i zamykanie PDB
Niektóre typowe wartości:
URUCHAMIANIE [LICZBA | MONTAŻ | OGRANICZ | UPGRADE | SIŁA | TYLKO CZYTAĆ]
WYŁĄCZENIE [NATYCHMIASTOWE | ABORT]
$ export ORACLE_SID=pcdb01 $ sqlplus / as sysdba SQL> shutdown immediate;
Zatrzymaj podłączaną bazę danych
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];
Lub:
SQL> alter SESSION SET CONTAINER = PRD_PDB_CON; SQL> shutdown immediate;
Uruchom podłączaną bazę danych
SIŁA STARTOWA
URUCHAMIANIE OTWÓRZ CZYTAJ ZAPIS [OGRANICZ]
URUCHAMIANIE OTWARTE TYLKO DO ODCZYTU [OGRANICZONE]
AKTUALIZACJA URUCHOMIENIA
WYŁĄCZENIE [NATYCHMIASTOWE]
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];
Lub:
SQL> alter SESSION SET CONTAINER = PRD_PDB_CON; SQL> startup; SQL> alter PLUGGABLE DATABASE <pdb-name-clause> OPEN READ WRITE [RESTRICTED] [FORCE]; SQL> alter PLUGGABLE DATABASE <pdb-name-clause> OPEN READ ONLY [RESTRICTED][FORCE]; SQL> alter PLUGGABLE DATABASE <pdb-name-clause> OPEN UPGRADE [RESTRICTED]; SQL> alter PLUGGABLE DATABASE <pdb-name-clause> CLOSE [IMMEDIATE];
Zachowaj stan uruchamiania PDB (12.1.0.2 i nowsze)
SQL> alter PLUGGABLE DATABASE pdb2 OPEN; SQL> alter PLUGGABLE DATABASE pdb2 SAVE STATE;
Widok DBA_PDB_SAVED_STATES wyświetla informacje o zapisanym stanie kontenerów.
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
Rozmiar podłączanej bazy danych
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
Czas uruchomienia podłączanej bazy danych
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.
Czas działania podłączanej bazy danych
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.
Nazwa usług
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.
Utwórz zwykłych użytkowników z dostępem do wszystkich plików pdb
SQL> CREATE USER c##user1 IDENTIFIED BY password1 CONTAINER=ALL; User created. SQL> GRANT CREATE SESSION TO c##user1 CONTAINER=ALL; Grant succeeded.
Twórz zwykłych użytkowników bez dostępu do plików pdb
SQL> CREATE USER c##user2 IDENTIFIED BY password1; User created. SQL> GRANT CREATE SESSION TO c##user2; Grant succeeded.
Utwórz lokalnego użytkownika z dostępem tylko do pdb
SQL> CREATE USER user3 IDENTIFIED BY password3 CONTAINER=CURRENT; User created. SQL> GRANT CREATE SESSION TO user3 CONTAINER=CURRENT; Grant succeeded.
Utwórz wspólną rolę
SQL> CONN / AS SYSDBA SQL> CREATE ROLE c##role1; Role created. SQL> GRANT CREATE SESSION TO c##role1; Grant succeeded.
Przyznaj rolę wspólnemu użytkownikowi
SQL> GRANT c##role1 TO c##user1 CONTAINER=ALL; Grant succeeded.
Przyznaj rolę wspólnemu użytkownikowi użytkownikowi lokalnemu
SQL> alter SESSION SET CONTAINER = PRD_PDB_CON; Session altered. SQL> GRANT c##role1 TO user2; Grant succeeded.
Role lokalne
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.
Tworzenie plików PDB
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/');
Wykluczanie plików PDB
SQL> alter pluggable database DSVPDB1 close [immediate] [instances=all]; SQL> drop pluggable database DSVPDB1 including datafiles;
Odłączanie plików PDB
$ 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';
Podłączanie plików PDB
$ 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;
Konfigurowanie usług w Oracle RAC z CDB
$ 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; /
W przypadku kontenera głównego mamy cdb_tablespaces, a cdb_data_files pokazuje przestrzeń tabel i pliki danych wszystkich kontenerów w CDB.
Po połączeniu z PDB, cdb_tablespaces i cdb_data_files wyświetlają te same informacje, co dba_tablespaces, dba_data_files dla 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.
Jak sprawdzić funkcję lokalnego cofania w 12.2
W Oracle Database 12c Release 1 wszystkie kontenery w instancji współdzieliły ten sam obszar tabel cofania.
W Oracle 12c Release 2 każdy kontener w instancji może używać własnego obszaru tabel cofania.
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
Referencje
https://docs.oracle.com