Oracle 12.2.0.1.0 PDB随着CDB启动而启动

Oracle 12.2.0.1.0 PDB随着CDB启动而启动

 

Oracle 12.1和Oracle12.2版本,默认情况下PDB不会随着CDB启动而启动;

为了实现PDB随着CDB启动而启动;

Oracle 12.1版本里,可以使用触发器来实现,触发器如下:

CREATE TRIGGER open_all_pdbs

  AFTER STARTUP ON DATABASE

BEGIN

   EXECUTE IMMEDIATE 'ALTER PLUGGABLE DATABASE ALL OPEN';

END ;

/

Oracle 12.2版本里,除了可以使用触发器,也可以使用命令实现PDB随着CDB启动而启动,命令如下:

ALTER PLUGGABLE DATABASE ORCLPDB SAVE STATE;

实验如下:

一 :CDB启动后,ORCLPDB状态为MOUNTED

SQL> shutdown immediate

SQL> startup

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED

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

         2 PDB$SEED                       READ ONLY  NO

         3 ORCLPDB                        MOUNTED

SQL> col name for a10

SQL> select con_id,name,open_mode from v$containers;

    CON_ID NAME       OPEN_MODE

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

         1 CDB$ROOT   READ WRITE

         2 PDB$SEED   READ ONLY

         3 ORCLPDB    MOUNTED


二:手动启动ORCLPDB数据库

SQL> alter session set container=ORCLPDB;

SQL> show con_id con_name user

SQL> startup

或者

SQL> alter pluggable database orclpdb open;

SQL> alter pluggable database all open;


三:执行命令,保留当前ORCLPDB状态(open)

SQL> ALTER PLUGGABLE DATABASE ORCLPDB SAVE STATE;


四:重启数据库,查看PDB已经随着CDB启动而启动了

SQL> conn /as sysdba

SQL> shutdown immediate

SQL> startup

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED

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

         2 PDB$SEED                       READ ONLY  NO

         3 ORCLPDB                        READ WRITE NO

SQL>  col name for a10

SQL>  select con_id,name,open_mode from v$containers;

    CON_ID NAME       OPEN_MODE

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

         1 CDB$ROOT   READ WRITE

         2 PDB$SEED   READ ONLY

         3 ORCLPDB    READ WRITE


---查看警告日志也可以看到orclpdb数据库自动启动

[root@chenjch trace]# tail -f alert_orcl.log

2017-04-16T16:33:08.398561+08:00

ORCLPDB(3):Opening pdb with no Resource Manager plan active

Pluggable database ORCLPDB opened read write


五:也可以通过命令改回原来的状态,即启动CDBPDB不启动;

SQL> ALTER PLUGGABLE DATABASE ORCLPDB DISCARD STATE;

SQL> shutdown immediate

SQL> startup

SQL> col name for a10

SQL> select con_id,name,open_mode from v$containers;

    CON_ID NAME       OPEN_MODE

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

         1 CDB$ROOT   READ WRITE

         2 PDB$SEED   READ ONLY

         3 ORCLPDB    MOUNTED


SQL> col name for a10

SQL> select con_id,name,open_mode from v$containers;


    CON_ID NAME       OPEN_MODE

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

         1 CDB$ROOT   READ WRITE

         2 PDB$SEED   READ ONLY

         3 ORCLPDB    MOUNTED


How to Preserve Open Mode of PDBs When the CDB Restarts (文档 ID 1933511.1)


修改时间:

2015-8-3

类型:

HOWTO

In this Document

Goal

Solution

 

What is the default open mode for PDBs

 

How to save or discard the open mode of a PDB when the CDB restarts

 

How to monitor the save state of the PDBs

 

This document is being delivered to you via Oracle Support's Rapid Visibility (RaV) process and therefore has not been subject to an independent technical review.

APPLIES TO:

Oracle Database - Enterprise Edition - Version 12.1.0.1 to 12.1.0.1 [Release 12.1]
Oracle Database - Enterprise Edition - Version 12.1.0.2 and later
Information in this document applies to any platform.

GOAL

From version 12.1.0.2 it is possible to save or discard the open mode of one or more PDBs when the CDB restarts.

This article shows

 - what is the default open mode for PDBs

 - how to save or discard the open mode of one or more PDBs when the CDB restarts

 - how to monitor the save state of the PDBs.

SOLUTION

What is the default open mode for PDBs

The default open mode for a PDB is MOUNTED (except for PDB$SEED which is READ ONLY and cannot be opened READ WRITE by user).

SYS@cnt122> select CON_ID, NAME, OPEN_MODE, RESTRICTED, OPEN_TIME  from gv$containers;

    CON_ID NAME                 OPEN_MODE  RESTRICTED OPEN_TIME
---------- -------------------- ---------- ---------- -----------------------------------
         1 CDB$ROOT             READ WRITE NO         08-OCT-14 09.14.42.775 +01:00
         2 PDB$SEED             READ ONLY  NO         08-OCT-14 09.14.42.873 +01:00
         3 PDBP2                MOUNTED
         4 DB12C2PDB            MOUNTED

How to save or discard the open mode of a PDB when the CDB restarts

You use the ALTER PLUGGABLE DATABASE SQL statement with a pdb_save or discard_state clause.

The idea is that you can save the current open state of a PDB, so that when CDB restarts this is the open mode the PDB will be in.

When you discard the previously saved open mode for a PDB, then the PDB will be in MOUNTED mode when CDB restarts.

E.g. to save the current open state for PDBP2, execute the following:

SQL> ALTER PLUGGABLE DATABASE PDBP2 SAVE STATE;

Pluggable database altered.

 

E.g. to discard the saved state for PDBP2, execute the following:

SQL> ALTER PLUGGABLE DATABASE PDBP2 DISCARD STATE;

Pluggable database altered.

For Oracle RAC CDB you can use the instances clause together with the in the pdb_save or discard_state clause to specify the instances on which a PDB's open mode is preserved.

See more information is in the documentation.

How to monitor the save state of the PDBs

You can use the DBA_PDB_SAVED_STATES view to see the save state for PDBs, see details in the documentation.

In the following example we save the OPEN status of the PDBP2, so that next time CDB restarts PDBP2 will be opened instead of mounted.

SQL> STARTUP PLUGGABLE DATABASE PDBP2 open
Pluggable Database opened.
SQL> select CON_ID, NAME, OPEN_MODE, RESTRICTED, OPEN_TIME  from gv$containers;

    CON_ID NAME                 OPEN_MODE  RESTRICTED OPEN_TIME
---------- -------------------- ---------- ---------- ---------------------------------------------------------------------------
         1 CDB$ROOT             READ WRITE NO         08-OCT-14 09.14.42.775 AM +01:00
         2 PDB$SEED             READ ONLY  NO         08-OCT-14 09.14.42.873 AM +01:00
         3 PDBP2                READ WRITE NO         08-OCT-14 09.28.26.830 AM +01:00
         4 DB12C2PDB            MOUNTED

SQL> select con_name, state from dba_pdb_saved_states;

no rows selected

SQL> ALTER PLUGGABLE DATABASE PDBP2 SAVE STATE;

Pluggable database altered.

SQL> select con_name, state from dba_pdb_saved_states;

CON_NAME             STATE
-------------------- --------------
PDBP2                OPEN

Only the save state is recorded. Once the discard state command is executed for a PDB, the saved state entry for the pdb is removed from DBA_PDB_SAVED_STATES.

SQL> ALTER PLUGGABLE DATABASE PDBP2 DISCARD STATE;

Pluggable database altered.

SQL> select con_name, state from dba_pdb_saved_states;

no rows selected

 

As it was mentioned above saving the open state of a PDB is available since 12.1.0.2. 
For 12.1.0.1 you may create a database startup trigger to place PDB(s) into a particular open mode at DB startup.

e.g. To open all PDBs at CDB startup, create the following trigger in CDB:

CREATE TRIGGER open_all_pdbs 
  AFTER STARTUP ON DATABASE 
BEGIN 
   EXECUTE IMMEDIATE 'ALTER PLUGGABLE DATABASE ALL OPEN'; 
END ;
/

 

 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29785807/viewspace-2137362/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29785807/viewspace-2137362/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值