DBA Hub

📋Steps in this guide1/2

How to open the PDBS automatically when CDB restarts DBACLASS

How to open the PDBS automatically when CDB restarts . From oracle 12.1.0.2 , saved state feature introduced, which can helps in ..

oracle clusteringintermediate
by OracleDba
14 views
1

DEMO:

1.  Restart the container database: 2. Check the status of PDBS: We can see the PDBS are in MOUNTED stage after starting CDB. Lets open them 3. Open the PDBS: Now use save state command to save the states, so that next time ,when container db restarts, PDBs will in READ WRITE MODE automatically. 4. Save the PDB state: 5. check the saved state in dba_pdb_saved_states 6.Bounce the container database, to check the PDB state: We can observed that PDBs are in READ WRITE mode automatically. DISCARD STATE OPTION: We can discard the saved state, so that next time CDB restarts, PDBs will start with MOUNT STATE only. Lets discard state for PDB2 . 1. Bounce the CDB to check the PDB State: We can observe that, only PDB2 started in MOUNTED stage, because we have discarded the saved state for PDB2 . > As this feature is not available in 12.1.0.1 , we can create a trigger to open the PDBs automatically, with container database startup. CREATE TRIGGER open_all_pdbs AFTER STARTUP ON DATABASE BEGIN EXECUTE IMMEDIATE ‘ALTER PLUGGABLE DATABASE ALL OPEN’; END ; / As this feature is not available in 12.1.0.1 , we can create a trigger to open the PDBs automatically, with container database startup. CREATE TRIGGER open_all_pdbs AFTER STARTUP ON DATABASE BEGIN EXECUTE IMMEDIATE ‘ALTER PLUGGABLE DATABASE ALL OPEN’; END ; /

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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
SQL> show con_name

CON_NAME
------------------------------
CDB$ROOT

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.


SQL> startup
ORACLE instance started.

Total System Global Area 1.4529E+10 bytes
Fixed Size                  7649368 bytes
Variable Size            8489273256 bytes
Database Buffers         5939134464 bytes
Redo Buffers               93011968 bytes
Database mounted.
Database opened.

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB1                           MOUNTED
         4 PDB2                           MOUNTED
         5 NONCDB                         MOUNTED

SQL> alter pluggable database NONCDB open;

Pluggable database altered.

SQL>  alter pluggable database PDB1 open;

Pluggable database altered.

SQL> alter pluggable database PDB2 open;

Pluggable database altered.

SQL>  show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB1                           READ WRITE NO
         4 PDB2                           READ WRITE NO
         5 NONCDB                         READ WRITE NO

SQL> alter pluggable database NONCDB save state;

Pluggable database altered.

SQL>  alter pluggable database PDB1 save state;

Pluggable database altered.

SQL> alter pluggable database PDB2 save state;

Pluggable database altered.

SQL> select con_name, state from dba_pdb_saved_states;

CON_NAME                STATE
----------------------- --------------
NONCDB                  OPEN
PDB1                    OPEN
PDB2                    OPEN

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area 1.4529E+10 bytes
Fixed Size 7649368 bytes
Variable Size 8489273256 bytes
Database Buffers 5939134464 bytes
Redo Buffers 93011968 bytes
Database mounted.
Database opened.

SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB1 READ WRITE NO
4 PDB2 READ WRITE NO
5 NONCDB READ WRITE NO

SQL> select con_name, state from dba_pdb_saved_states;

CON_NAME                STATE
----------------------- --------------
NONCDB                  OPEN
PDB1                    OPEN
PDB2                    OPEN


SQL> alter pluggable database PDB2 discard state;

Pluggable database altered.

SQL>   select con_name, state from dba_pdb_saved_states;

CON_NAME                STATE
----------------------- --------------
NONCDB                  OPEN
PDB1                    OPEN

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB1                           READ WRITE NO
         4 PDB2                           READ WRITE NO
         5 NONCDB                         READ WRITE NO

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup
ORACLE instance started.

Total System Global Area 1.4529E+10 bytes
Fixed Size                  7649368 bytes
Variable Size            8489273256 bytes
Database Buffers         5939134464 bytes
Redo Buffers               93011968 bytes
Database mounted.
Database opened.

SQL>  show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB1                           READ WRITE NO
         4 PDB2                           MOUNTED
         5 NONCDB                         READ WRITE NO
2

SEE ALSO:

How to convert non-cdb to pdb in oracle 12c

Comments (0)

Please to add comments

No comments yet. Be the first to comment!