Periksa apakah database CDB atau non-CDB
SQL> select cdb from v$database; CDB --- YES
Menghubungkan ke Kontainer
$ 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
Menavigasi di seluruh PDB
SQL> alter session set container=PDB$SEED; Session altered. SQL> alter session set container=PRD_PDB_CON; Session altered. SQL>
Informasi tentang 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
Memeriksa/mengubah Parameter
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;
Memulai dan mematikan PDB
Beberapa nilai tipikal:
MULAI [JUMLAH | GUNUNG | BATAS | MENINGKATKAN | KEKUATAN | BACA SAJA]
MATI [SEGERA | ABORT]
$ export ORACLE_SID=pcdb01 $ sqlplus / as sysdba SQL> shutdown immediate;
Hentikan Basis Data yang Dapat Dicolokkan
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];
Atau:
SQL> alter SESSION SET CONTAINER = PRD_PDB_CON; SQL> shutdown immediate;
Mulai Basis Data Pluggable
KEKUATAN MULAI
MULAI TERBUKA BACA TULIS [BATAS]
STARTUP BUKA HANYA BACA [BATAS]
MULAI PENINGKATAN
SHUTDOWN [SEGERA]
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];
Atau:
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];
Pertahankan Status Startup PDB (12.1.0.2 dan seterusnya)
SQL> alter PLUGGABLE DATABASE pdb2 OPEN; SQL> alter PLUGGABLE DATABASE pdb2 SAVE STATE;
Tampilan DBA_PDB_SAVED_STATES menampilkan informasi tentang status container yang disimpan.
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
Ukuran basis data yang dapat dipasang
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
Waktu mulai database yang dapat dipasang
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.
Waktu aktif basis data yang dapat dipasang
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.
Nama layanan
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.
Buat pengguna umum dengan akses ke semua pdbs
SQL> CREATE USER c##user1 IDENTIFIED BY password1 CONTAINER=ALL; User created. SQL> GRANT CREATE SESSION TO c##user1 CONTAINER=ALL; Grant succeeded.
Buat pengguna umum tanpa akses ke pdbs
SQL> CREATE USER c##user2 IDENTIFIED BY password1; User created. SQL> GRANT CREATE SESSION TO c##user2; Grant succeeded.
Buat pengguna lokal dengan akses hanya ke pdb
SQL> CREATE USER user3 IDENTIFIED BY password3 CONTAINER=CURRENT; User created. SQL> GRANT CREATE SESSION TO user3 CONTAINER=CURRENT; Grant succeeded.
Buat peran bersama
SQL> CONN / AS SYSDBA SQL> CREATE ROLE c##role1; Role created. SQL> GRANT CREATE SESSION TO c##role1; Grant succeeded.
Berikan peran kepada pengguna biasa
SQL> GRANT c##role1 TO c##user1 CONTAINER=ALL; Grant succeeded.
Berikan peran kepada pengguna umum kepada pengguna lokal
SQL> alter SESSION SET CONTAINER = PRD_PDB_CON; Session altered. SQL> GRANT c##role1 TO user2; Grant succeeded.
Peran Lokal
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.
Membuat 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/');
Tidak termasuk PDB
SQL> alter pluggable database DSVPDB1 close [immediate] [instances=all]; SQL> drop pluggable database DSVPDB1 including datafiles;
Mencabut 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';
Memasukkan 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;
Mengonfigurasi Layanan di Oracle RAC dengan 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; /
Dengan wadah root, kami memiliki cdb_tablespaces dan cdb_data_files menunjukkan tablespace dan file data dari semua wadah di CDB.
Saat terhubung ke PDB, cdb_tablespaces dan cdb_data_files menunjukkan informasi yang sama seperti dba_tablespaces, dba_data_files untuk 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.
Cara memeriksa fitur Pembatalan Lokal di 12.2
Di Oracle Database 12c Release 1 semua container dalam sebuah instance berbagi tablespace undo yang sama.
Di Oracle 12c Release 2, setiap container dalam sebuah instance dapat menggunakan ruang tabel undo-nya sendiri.
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
Referensi
https://docs.oracle.com