国内最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2
您当前位置:首页 > 数据库 > 数据库应用 > Oracle 12c CDB 和PDB 数据库的启动与关闭 说明

Oracle 12c CDB 和PDB 数据库的启动与关闭 说明

来源:程序员人生   发布时间:2014-12-16 08:21:55 阅读次数:3203次


 

 

Oracle 12c中,分CDB 和PDB,他们的启动和关闭操作整理以下。

 

1  Container Database (CDB)

 

对CDB,启动和关闭与之前传统的方式1样,具体语法以下:

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,

 

具体语法和普通实例1样:

 

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(满)

生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
程序员人生
------分隔线----------------------------
分享到:
------分隔线----------------------------
关闭
程序员人生