Oracle 12c CDB 和PDB 資料庫的啟動與關閉 說明,12cpdb

來源:互聯網
上載者:User

Oracle 12c CDB 和PDB 資料庫的啟動與關閉 說明,12cpdb


 

 

在Oracle 12c中,分CDB 和PDB,他們的啟動和關閉操作整理如下。

 

1  Container Database (CDB)

 

對於CDB,啟動和關閉與之前傳統的方式一樣,具體文法如下:

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

SHUTDOWN[IMMEDIATE | ABORT]

 

 

要注意,在12c資料庫建立完成後,預設情況下使用sqlplus / as sysdba  登入串連的是CDB。

 

[oracle@Ora12c~]$ sqlplus / as sysdba

 

SQL*Plus:Release 12.1.0.1.0 Production on Thu Apr 24 17:50:34 2014

 

Copyright(c) 1982, 2013, Oracle.  All rightsreserved.

 

 

Connectedto:

OracleDatabase 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production

Withthe Partitioning, OLAP, Advanced Analytics and Real Application Testing options

 

SQL>show con_name

 

CON_NAME

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

CDB$ROOT

SQL>

 

SQL>select con_id, dbid, guid, name , open_mode from v$pdbs;

 

    CON_ID      DBID GUID                            NAME                          OPEN_MODE

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

         2 4088301206 F7C1E3C96BBF0585E0430A01A8C05459PDB$SEED                       READ ONLY

         3 426143573 F7C209EB1DFC0854E0430A01A8C0B787 PDBCNDBA                       READ WRITE

 

我們現在串連的是CDB,即root container。

 

我們關閉CDB:

SQL>shutdown immediate

Databaseclosed.

Databasedismounted.

ORACLEinstance shut down.

 

我們關閉CDB之前PDB 是沒有關閉的,所以這個操作也會把PDB 關閉掉。

 

SQL>startup

ORACLEinstance started.

 

TotalSystem Global Area 1269366784 bytes

FixedSize                  2287912 bytes

VariableSize             788530904 bytes

DatabaseBuffers          469762048 bytes

RedoBuffers                8785920 bytes

Databasemounted.

Databaseopened.

 

SQL>  select con_id, dbid, guid, name , open_modefrom v$pdbs;

 

    CON_ID      DBID GUID                            NAME                          OPEN_MODE

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

         2 4088301206F7C1E3C96BBF0585E0430A01A8C05459 PDB$SEED                       READ ONLY

         3 426143573 F7C209EB1DFC0854E0430A01A8C0B787 PDBCNDBA                       MOUNTED

 

注意這裡的PDB,在CDB 啟動之,PDB 是自動啟動到mount狀態,而不是OPEN。 所以我們還需要手工去open它,當然,也可以通過在CDB中配置觸發器來自動open。

 

 

2  Pluggable Database (PDB)

 

PDB 的操作可以通過SQL*PLUS 來操作,也可以通過ALTER PLUGGABLE DATABASE 命令操作。

 

2.1             使用SQL*Plus 命令

 

 

因為預設串連的是CDB,所以必須先指定PDB才可以通過sqlplus來啟動和關閉PDB,

 

具體文法和普通執行個體一樣:

 

STARTUPFORCE;

STARTUPOPEN READ WRITE [RESTRICT];

STARTUPOPEN READ ONLY [RESTRICT];

STARTUPUPGRADE;

SHUTDOWN[IMMEDIATE];

 

SQL>show con_name

 

CON_NAME

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

CDB$ROOT

 

SQL>selectcon_id, dbid, guid, name , open_mode from v$pdbs;

 

    CON_ID      DBID GUID                            NAME            OPEN_MODE

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

         2 4088301206F7C1E3C96BBF0585E0430A01A8C05459 PDB$SEED       READ ONLY

         3 426143573 F7C209EB1DFC0854E0430A01A8C0B787 PDBCNDBA        MOUNTED

 

注意這裡是mount,表示PDB 是關閉的。

 

--指定PDB 資料庫:

SQL>alter session set container=pdbcndba;

Sessionaltered.

 

SQL>startup

PluggableDatabase opened.

SQL>select con_id, dbid, guid, name , open_mode from v$pdbs;

 

    CON_ID      DBID GUID                            NAME            OPEN_MODE

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

         3 426143573 F7C209EB1DFC0854E0430A01A8C0B787 PDBCNDBA        READ WRITE

SQL>

 

啟動成功。 當我們切換到PDB之後,就看不到seed PDB的資訊了。

 

 

2.2             使用ALTER PLUGGABLE DATABASE命令

 

如果在PDB中可以使用如下文法:

 

ALTERPLUGGABLE DATABASE OPEN READ WRITE [RESTRICTED] [FORCE];

ALTERPLUGGABLE DATABASE OPEN READ ONLY [RESTRICTED] [FORCE];

ALTERPLUGGABLE DATABASE OPEN UPGRADE [RESTRICTED];

ALTERPLUGGABLE DATABASE CLOSE [IMMEDIATE];

 

如果是在CDB中,可以使用如下文法:

ALTERPLUGGABLE DATABASE <pdd-name-clause> OPEN READ WRITE [RESTRICTED][FORCE];

ALTERPLUGGABLE DATABASE <pdd-name-clause> OPEN READ ONLY [RESTRICTED] [FORCE];

ALTERPLUGGABLE DATABASE <pdd-name-clause> OPEN UPGRADE [RESTRICTED];

ALTERPLUGGABLE DATABASE <pdd-name-clause> CLOSE [IMMEDIATE];

 

<pdd-name-clause>表示的是多個PDB,如果有多個,用逗號分開。 也可以使用ALL或者ALL EXCEPT關鍵字來替代。

 

ALL:表示所有的PDBS。

ALLEXCEPT 表示需要排除的PDBS。

 

如:

ALTERPLUGGABLE DATABASE pdb1, pdb2 OPEN READ ONLY FORCE;

ALTERPLUGGABLE DATABASE pdb1, pdb2 CLOSE IMMEDIATE;

 

ALTERPLUGGABLE DATABASE ALL OPEN;

ALTERPLUGGABLE DATABASE ALL CLOSE IMMEDIATE;

 

ALTERPLUGGABLE DATABASE ALL EXCEPT pdb1 OPEN;

ALTERPLUGGABLE DATABASE ALL EXCEPT pdb1 CLOSE IMMEDIATE;

 

樣本:

SQL>alter session set container=CDB$ROOT;

Sessionaltered.

 

SQL>select con_id, dbid, guid, name , open_mode from v$pdbs;

 

    CON_ID      DBID GUID                            NAME            OPEN_MODE

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

         2 4088301206F7C1E3C96BBF0585E0430A01A8C05459 PDB$SEED       READ ONLY

         3 426143573 F7C209EB1DFC0854E0430A01A8C0B787 PDBCNDBA        READ WRITE

 

SQL>ALTER PLUGGABLE DATABASE ALL CLOSE ;

Pluggabledatabase altered.

 

SQL>select con_id, dbid, guid, name , open_mode from v$pdbs;

 

    CON_ID      DBID GUID                            NAME            OPEN_MODE

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

         2 4088301206F7C1E3C96BBF0585E0430A01A8C05459 PDB$SEED       READ ONLY

         3  426143573 F7C209EB1DFC0854E0430A01A8C0B787PDBCNDBA        MOUNTED

 

SQL>alter session set container=pdbcndba;

 

Sessionaltered.

 

SQL>ALTER PLUGGABLE DATABASE OPEN;

 

Pluggabledatabase altered.

 

SQL>  select con_id, dbid, guid, name , open_modefrom v$pdbs;

 

    CON_ID      DBID GUID                            NAME            OPEN_MODE

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

         3  426143573 F7C209EB1DFC0854E0430A01A8C0B787PDBCNDBA        READ WRITE

 

 

 

3  設定Pluggable Database (PDB) 的自動startup

 

預設情況下,在CDB 啟動的時候,all 的PDB 都是mount狀態,也沒有預設的機制,在CDB啟動時自動啟動PDB。

 

但這裡可以通過觸發器來實現PDB的自動open:

 

CREATEOR REPLACE TRIGGER open_pdbs

  AFTER STARTUP ON DATABASE

BEGIN

   EXECUTE IMMEDIATE 'ALTERPLUGGABLE DATABASE ALL OPEN';

END open_pdbs;

/

 

樣本:

SQL>show con_name

 

CON_NAME

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

PDBCNDBA

SQL>alter session set container=CDB$ROOT;

 

Sessionaltered.

 

SQL>CREATE OR REPLACE TRIGGER open_pdbs

  2   AFTER STARTUP ON DATABASE

  3 BEGIN

  4    EXECUTE IMMEDIATE 'ALTER PLUGGABLE DATABASE ALL OPEN';

  5  ENDopen_pdbs;

  6  /

 

Triggercreated.

 

 

 

 

 

 

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

著作權,文章允許轉載,但必須以連結方式註明源地址,否則追究法律責任!

 

AboutDave:

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

QQ:      251097186

Email:    tianlesoftware@gmail.com

Blog:     http://blog.csdn.net/tianlesoftware

Weibo:    http://weibo.com/tianlesoftware

Twitter:  http://twitter.com/tianlesoftware

Facebook: http://www.facebook.com/tianlesoftware

Linkedin: http://cn.linkedin.com/in/tianlesoftware

 

Dave 的QQ群:

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

注意:加群必須註明資料表空間和資料檔案關係 | 不要重複加群

CNDBA_1: 104207940 (滿)    CNDBA_2: 62697716 (滿)   CNDBA_3: 283816689

CNDBA_4: 391125754   CNDBA_5: 62697850    CNDBA_6: 62697977   CNDBA_7: 142216823(滿)

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.