Description of Oracle 12c CDB and PDB database startup and shutdown, 12 cpdb
In Oracle 12c, it is divided into CDB and PDB. Their startup and shutdown operations are as follows.
1 Container Database (CDB)
For CDB, the startup and shutdown methods are the same as the traditional ones. The specific syntax is as follows:
STARTUP [NOMOUNT | MOUNT | RESTRICT | UPGRADE | FORCE | read only]
SHUTDOWN [IMMEDIATE | ABORT]
Note that after the 12c database is created, the connection to CDB is logged on by default using sqlplus/as sysdba.
[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,201 3, 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
We are now connected to CDB, that is, root container.
We disable CDB:
SQL> shutdown immediate
Databaseclosed.
Databasedismounted.
ORACLEinstance shut down.
Before we disable CDB, PDB is not closed, so this operation will also disable 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
Note that PDB is started in CDB, and PDB is automatically started to the mount State rather than OPEN. Therefore, we also need to open it manually. Of course, we can also configure the trigger in CDB to automatically open it.
2 Pluggable Database (PDB)
PDB operations can be performed through SQL * PLUS, or through the ALTER PLUGGABLE DATABASE command.
2.1 use the SQL * Plus command
Because CDB is connected by default, you must specify PDB before using sqlplus to start and close PDB,
The syntax is the same as that of a common instance:
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
Note that this is mount, indicating that PDB is disabled.
-- Specify the PDB database:
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>
Started successfully. When we switch to PDB, we cannot see the seed PDB information.
2.2 run the alter pluggable database Command
The following syntax can be used in PDB:
Alterpluggable database open read write [RESTRICTED] [FORCE];
Alterpluggable database open read only [RESTRICTED] [FORCE];
Alterpluggable database open upgrade [RESTRICTED];
Alterpluggable database close [IMMEDIATE];
If it is in CDB, you can use the following syntax:
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> indicates multiple PDBs. If multiple PDBs exist, separate them with commas. You can also use the ALL or ALL distinct T keyword instead.
ALL: all pdbs.
ALLEXCEPT indicates the PDBS to be excluded.
For example:
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 privileges t pdb1 OPEN;
Alterpluggable database all privileges t pdb1 close immediate;
Example:
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. Set Automatic startup for Pluggable Database (PDB)
By default, when CDB is started, all PDB is in the mount status and there is no default mechanism. PDB is automatically started when CDB is started.
But here we can use triggers to achieve automatic open of PDB:
Createor replace trigger open_pdbs
AFTER STARTUP ON DATABASE
BEGIN
Execute immediate 'alterpluggable database all open ';
END open_pdbs;
/
Example:
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.
Bytes --------------------------------------------------------------------------------------------
All rights reserved. reprinted articles are allowed, but source addresses must be indicated by links. Otherwise, the documents will be held legally responsible!
AboutDave:
Bytes --------------------------------------------------------------------------------------------
QQ: 251097186
Email: tianlesoftware@gmail.com
Blog: http://blog.csdn.net/tianlesoftware
WEAVER: http://weibo.com/tianlesoftware
Twitter: http://twitter.com/tianlesoftware
Facebook: http://www.facebook.com/tianlesoftware
Linkedin: http://cn.linkedin.com/in/tianlesoftware
Dave's QQ group:
Bytes --------------------------------------------------------------------------------------------
Note: The relationship between tablespaces and data files must be specified for grouping. | do not add groups repeatedly.
CNDBA_1: 104207940 (full) CNDBA_2: 62697716 (full) CNDBA_3: 283816689
CNDBA_4: 391125754 CNDBA_5: 62697850 CNDBA_6: 62697977 CNDBA_7: 142216823 (full)