DBA Hub

📋Steps in this guide1/6

Multitenant : Startup and Shutdown Container Databases (CDB) and Pluggable Databases (PDB) in Oracle Database 12c Release 1 (12.1)

Learn how to startup and shutdown container databases (CDB) and pluggable databases (PDB) in Oracle 12c Release 1 (12.1).

oracle 12cconfigurationintermediate
by OracleDba
13 views
1

Container Database (CDB)

Startup and shutdown of the container database is the same as it has always been for regular instances. The SQL*Plus and commands are available when connected to the CDB as a privileged user. Some typical values are shown below.

Code/Command (click line numbers to comment):

1
2
STARTUP [NOMOUNT | MOUNT | RESTRICT | UPGRADE | FORCE | READ ONLY]
SHUTDOWN [IMMEDIATE | ABORT]
2

Pluggable Database (PDB)

Pluggable databases can be started and stopped using SQL*Plus commands or the command.
3

SQL*Plus Commands

Some examples are shown below.

Code/Command (click line numbers to comment):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
STARTUP FORCE;
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

The command can be used from the CDB or the PDB. The following commands are available to open and close the current PDB when connected to the PDB as a privileged user. Some examples are shown below. The following commands are available to open and close one or more PDBs when connected to the CDB as a privileged user. The clause can be any of the following: - One or more PDB names, specified as a comma-separated list. - The keyword to indicate all PDBs. - The keywords, followed by one or more PDB names in a comma-separate list, to indicate a subset of PDBs. Some examples are shown below.

Code/Command (click line numbers to comment):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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 ONLY FORCE;
ALTER PLUGGABLE DATABASE CLOSE IMMEDIATE;

ALTER PLUGGABLE DATABASE OPEN READ WRITE;
ALTER PLUGGABLE DATABASE CLOSE IMMEDIATE;

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];

ALTER PLUGGABLE DATABASE pdb1, pdb2 OPEN READ ONLY FORCE;
ALTER PLUGGABLE DATABASE pdb1, pdb2 CLOSE IMMEDIATE;

ALTER PLUGGABLE DATABASE ALL OPEN;
ALTER PLUGGABLE DATABASE ALL CLOSE IMMEDIATE;

ALTER PLUGGABLE DATABASE ALL EXCEPT pdb1 OPEN;
ALTER PLUGGABLE DATABASE ALL EXCEPT pdb1 CLOSE IMMEDIATE;
5

Pluggable Database (PDB) Automatic Startup

The 12.1.0.2 patchset has introduced the ability to preserve the startup state of PDBs, so you probably shouldn't be implementing a trigger in the manner discussed in this section. Prior to 12.1.0.2, when the CDB is started, all PDBs remain in mounted mode. There is no default mechanism to automatically start them when the CDB is started. The way to achieve this is to use a system trigger on the CDB to start some or all of the PDBs. You can customise the trigger if you don't want all of your PDBs to start.

Code/Command (click line numbers to comment):

1
2
3
4
5
6
CREATE OR REPLACE TRIGGER open_pdbs 
  AFTER STARTUP ON DATABASE 
BEGIN 
   EXECUTE IMMEDIATE 'ALTER PLUGGABLE DATABASE ALL OPEN'; 
END open_pdbs;
/
6

Preserve PDB Startup State (12.1.0.2 onward)

The 12.1.0.2 patchset introduced the ability to preserve the startup state of PDBs through a CDB restart. This is done using the command. We will start off by looking at the normal result of a CDB restart. Notice the PDBs are in mode before the restart, but in mode after it. Next, we open both pluggable databases, but only save the state of PDB1. The view displays information about the saved state of containers. Restarting the CDB now gives us a different result. The saved state can be discarded using the following statement. Here is a brief list of some of the usage notes explained in the documentation . - The state is only saved and visible in the view if the container is in or mode. The command does not error when run against a container in mode, but nothing is recorded, as this is the default state after a CDB restart. - Like other examples of the command, PDBs can be identified individually, as a comma separated list, using the or keywords. - The clause can be added when used in RAC environments. The clause can identify instances individually, as a comma separated list, using the or keywords. Regardless of the clause, the commands only affect the current instance. For more information see: - Introduction to the Multitenant Architecture - Overview of the Multitenant Architecture - Managing a Multitenant Environment - ALTER PLUGGABLE DATABASE - Using the STARTUP SQL*Plus Command on a PDB - Preserving or Discarding the Open Mode of PDBs When the CDB Restarts - Multitenant : All Articles - Multitenant : Startup and Shutdown of CDBs and PDBs - Hybrid Read-Only Mode for PDBs in Oracle Database 23ai Hope this helps. Regards Tim...

Code/Command (click line numbers to comment):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
SELECT name, open_mode FROM v$pdbs;

NAME                           OPEN_MODE
------------------------------ ----------
PDB$SEED                       READ ONLY
PDB1                           READ WRITE
PDB2                           READ WRITE

SQL> 


SHUTDOWN IMMEDIATE;
STARTUP;


SELECT name, open_mode FROM v$pdbs;

NAME                           OPEN_MODE
------------------------------ ----------
PDB$SEED                       READ ONLY
PDB1                           MOUNTED
PDB2                           MOUNTED

SQL>

ALTER PLUGGABLE DATABASE pdb1 OPEN;
ALTER PLUGGABLE DATABASE pdb2 OPEN;
ALTER PLUGGABLE DATABASE pdb1 SAVE STATE;

COLUMN con_name FORMAT A20
COLUMN instance_name FORMAT A20

SELECT con_name, instance_name, state FROM dba_pdb_saved_states;

CON_NAME             INSTANCE_NAME        STATE
-------------------- -------------------- --------------
PDB1                 cdb1                 OPEN

SQL>

SELECT name, open_mode FROM v$pdbs;

NAME                           OPEN_MODE
------------------------------ ----------
PDB$SEED                       READ ONLY
PDB1                           READ WRITE
PDB2                           READ WRITE

SQL> 


SHUTDOWN IMMEDIATE;
STARTUP;


SELECT name, open_mode FROM v$pdbs;

NAME                           OPEN_MODE
------------------------------ ----------
PDB$SEED                       READ ONLY
PDB1                           READ WRITE
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 FROM dba_pdb_saved_states;

no rows selected

SQL>

Comments (0)

Please to add comments

No comments yet. Be the first to comment!