Oracle12cr1新特性之容器數據庫(CDB)和可插拔數據庫(PDB) 的啓動和關閉

 

 

Oracle12c中引入的多宿主選項(multitenant option)容許一個容器數據庫容納多個獨立的可插拔數據庫(PDB)。本文將說明如何啓動和關閉容器數據庫(CDB)和可插拔數據庫(PDB)。數據庫

1.   容器數據庫(CDB)it

啓動和關閉容器數據庫和以往同樣。看成爲受權用戶鏈接到CDB時,SQL*Plus中可使用STARTUP和SHUTDOWN命令。具體語法以下:io

STARTUP [NOMOUNT | MOUNT | RESTRICT | UPGRADE| FORCE | READ ONLY]容器

SHUTDOWN [IMMEDIATE | ABORT]select

2.        可插拔數據庫(PDB)語法

可插拔數據庫能用SQL*Plus命令或 ALTER PLUGGABLEDATABASE命令啓動和關閉。數據

3.       SQL*Plus命令db

看成爲受權用戶鏈接至可插拔數據庫時,以下命令可用來啓動和關閉數據庫:dba

STARTUP FORCE;ant

STARTUP OPEN READ WRITE [RESTRICT];

STARTUP OPEN READ ONLY [RESTRICT];

STARTUP UPGRADE;

SHUTDOWN [IMMEDIATE];

 

示例以下:

STARTUP FORCE;

SHUTDOWN IMMEDIATE;

 

STARTUP OPEN READ WRITE RESTRICT;

SHUTDOWN;

 

STARTUP;

SHUTDOWN IMMEDIATE;

4.        ALTER PLUGGABLE DATABASE

ALTER PLUGGABLE DATABASE命令能在CDB或PDB中使用。

看成爲受權用戶鏈接至PDB時,以下命令可用來打開和關閉目前的PDB。

ALTER PLUGGABLE DATABASE OPEN READ WRITE[RESTRICTED] [FORCE];

ALTER PLUGGABLE DATABASE OPEN READ ONLY[RESTRICTED] [FORCE];

ALTER PLUGGABLE DATABASE OPEN UPGRADE[RESTRICTED];

ALTER PLUGGABLE DATABASE CLOSE [IMMEDIATE];

示例以下。

ALTER PLUGGABLE DATABASE OPEN READ ONLYFORCE;

ALTER PLUGGABLE DATABASE CLOSE IMMEDIATE;

 

ALTER PLUGGABLE DATABASE OPEN READ WRITE;

ALTER PLUGGABLE DATABASE CLOSE IMMEDIATE;

看成爲受權用戶鏈接至CDB時,以下命令可用來打開和關閉一個或多個PDB。

ALTER PLUGGABLE DATABASE<pdb-name-clause> OPEN READ WRITE[RESTRICTED] [FORCE];

ALTER PLUGGABLE DATABASE<pdb-name-clause> OPEN READ ONLY[RESTRICTED] [FORCE];

ALTER PLUGGABLE DATABASE<pdb-name-clause> OPEN UPGRADE [RESTRICTED];

ALTER PLUGGABLE DATABASE<pdb-name-clause> CLOSE [IMMEDIATE];

 <pdb-name-clause> 子句能夠是以下值:

一個或多個以逗號分隔的PDB名。

 ALL關鍵字指全部PDB。

ALL EXCEPT關鍵字,後面跟一個或多個逗號分隔的PDB,指一個PDB子集。

示例以下:

ALTER PLUGGABLE DATABASE pdb1, pdb2 OPEN READONLY FORCE;

ALTER PLUGGABLE DATABASE pdb1, pdb2 CLOSEIMMEDIATE;

 

ALTER PLUGGABLE DATABASE ALL OPEN;

ALTER PLUGGABLE DATABASE ALL CLOSE IMMEDIATE;

 

ALTER PLUGGABLE DATABASE ALL EXCEPT pdb1OPEN;

ALTER PLUGGABLE DATABASE ALL EXCEPT pdb1CLOSE IMMEDIATE;

5.        可插拔數據庫(PDB)自動啓動

Oracle12.1.0.2補丁集已引入了保持PDB啓動狀態的能力,所以,不用再經過下面的觸發器方式來實現自動打開PDB。

Oracle12.1.0.2以前,CDB啓動後,全部的PDB都處於加載狀態。CDB啓動時,沒有默認機制自動啓動PDB。只能經過在CDB上創建一個系統觸發器來自動啓動部分或全部PDB。

CREATE OR REPLACE TRIGGER open_pdbs

  AFTERSTARTUP ON DATABASE

BEGIN

  EXECUTE IMMEDIATE 'ALTER PLUGGABLEDATABASE ALL OPEN';

END open_pdbs;

/

若是你不想啓動全部的PDB,能夠定製修改該觸發器。

6.        保持PDB處於啓動狀態(12.1.0.2以後)

Oracle12.1.0.2補丁集可讓PDB在CDB重啓時保持啓動狀態。這能夠經過ALTERPLUGGABLE DATABASE命令實現。

咱們能夠觀察CDB重啓的整個過程。注意,重啓前,PDB都處於可讀寫模式,但重啓後卻處於加載模式。

SELECT name, open_mode FROM v$pdbs;

 

NAME                          OPEN_MODE

------------------------------ ----------

PDB$SEED                       READ ONLY

PDB1                           READWRITE

PDB2                           READWRITE

 

SQL>

SHUTDOWN IMMEDIATE;

STARTUP;

 

SELECT name, open_mode FROM v$pdbs;

 

NAME                          OPEN_MODE

------------------------------ ----------

PDB$SEED                       READONLY

PDB1                          MOUNTED

PDB2                          MOUNTED

 

SQL>

接着,咱們打開兩個PDBS,但只保存PDB1的狀態。

ALTER PLUGGABLE DATABASE pdb1 OPEN;

ALTER PLUGGABLE DATABASE pdb2 OPEN;

ALTER PLUGGABLE DATABASE pdb1 SAVE STATE;

視圖DBA_PDB_SAVED_STATES顯示容器保存狀態的信息。

COLUMN con_name FORMAT A20

COLUMN instance_name FORMAT A20

 

SELECT con_name, instance_name, state FROMdba_pdb_saved_states;

 

CON_NAME            INSTANCE_NAME        STATE

-------------------- ----------------------------------

PDB1                 cdb1                 OPEN

 

SQL>

 

重啓CDB將會出現一個不一樣結果。

SELECT name, open_mode FROM v$pdbs;

NAME                          OPEN_MODE

------------------------------ ----------

PDB$SEED                       READONLY

PDB1                           READWRITE

PDB2                           READWRITE

 

SQL>

 

 

SHUTDOWN IMMEDIATE;

STARTUP;

 

 

SELECT name, open_mode FROM v$pdbs;

 

NAME                         OPEN_MODE

------------------------------ ----------

PDB$SEED                       READONLY

PDB1                           READWRITE

PDB2                          MOUNTED

 

SQL>

被保存的狀態能夠經過以下命令被廢棄。

ALTER PLUGGABLE DATABASE pdb1 DISCARD STATE;

 

COLUMN con_name FORMAT A20

COLUMN instance_name FORMAT A20

 

SELECT con_name, instance_name, state FROMdba_pdb_saved_states;

 

no rows selected

 

SQL>

7.        注意:

Ø  只有容器處於只讀或讀寫模式,狀態才能夠在視圖DBA_PDB_SAVED_STATES中保存和顯式。當對一個加載狀態的容器運行ALTER PLUGGABLE DATABASE ... SAVE STATE命令時,既不報錯,也不會記錄狀態,由於這是CDB重啓後的默認狀態。

Ø  像 ALTER PLUGGABLEDATABASE命令的其餘例子同樣, PDBs能夠單獨列出,也能夠是逗號分隔的PDB列,或者用 ALL或 ALL EXCEPT關鍵字。

Ø  RAC環境中,能夠增長INSTANCES子句。該子句中能夠寫單個實例,逗號分隔的實例列,ALL或ALL EXCEPT關鍵字。無論INSTANCES 子句, SAVE/DISCARD STATE命令隻影響當前的實例。

相關文章
相關標籤/搜索