Tag Archives: startup cdb

STARTUP/SHUTDOWN CDB AND PDB

HOW TO STARTUP/SHUTDOWN CDB AND PDB ON LINUX

BEST PRACTICE:  ALWAYS PLEASE SWITCH TO PDB and then do your task to avoid accidental issues.

Contents
___________________________________________________________________________________________________

1. Startup CDB

2. Startup PDB
      2.1 Startup PDB from CDB
      2.2 Startup PDB with in PDB
      2.3 Startup ALL PDBs from CDB

3. Shutdown PDB
      3.1 Shutdown PDB from CDB
      3.2 Shutdown PDB with in PDB
      3.3 Shutdown ALL PDBs from CDB

4. Shutdown CDB
___________________________________________________________________________________________________


1. Startup CDB

[oracle@localhost ~]$ cat /etc/oratab | grep -i CDB2
CDB2:/u01/app/oracle/product/12.2.0.1:N
[oracle@localhost ~]$
[oracle@localhost ~]$ . oraenv
ORACLE_SID = [CDB2] ?
The Oracle base remains unchanged with value /u01/app/oracle
[oracle@localhost ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Sun Jul 15 17:30:11 2018

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> startup;
ORACLE instance started.

Total System Global Area 1577058304 bytes
Fixed Size                  8793208 bytes
Variable Size             503317384 bytes
Database Buffers         1056964608 bytes
Redo Buffers                7983104 bytes
Database mounted.
Database opened.
SQL>

SQL> select name,open_mode,cdb from v$database;

NAME      OPEN_MODE            CDB
--------- -------------------- ---
CDB2      READ WRITE           YES  <------

SQL>

SQL> show con_id con_name

CON_ID
------------------------------
1

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

SQL> 


2. Startup PDB


2.1 Startup PDB from CDB

SQL> col name for a30
SQL> select name,open_mode,con_id,dbid from v$containers;

NAME                           OPEN_MODE      CON_ID       DBID
------------------------------ ---------- ---------- ----------
CDB$ROOT                       READ WRITE          1  680230459
PDB$SEED                       READ ONLY           2 2993936271
PDB1                           MOUNTED             3  627484885
PDB2                           MOUNTED             4  891811039
PDB3                           MOUNTED             5  424568091
PDB4                           MOUNTED             6 2306285303

6 rows selected.

SQL>


SQL> show pdbs;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB1                           MOUNTED  <------
         4 PDB2                           MOUNTED
         5 PDB3                           MOUNTED
         6 PDB4                           MOUNTED

SQL>

SQL> ALTER PLUGGABLE DATABASE PDB1 OPEN;

Pluggable database altered.

SQL> 

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

NAME                           OPEN_MODE      CON_ID       DBID
------------------------------ ---------- ---------- ----------
CDB$ROOT                       READ WRITE          1  680230459
PDB$SEED                       READ ONLY           2 2993936271
PDB1                           READ WRITE          3  627484885 <----
PDB2                           MOUNTED             4  891811039
PDB3                           MOUNTED             5  424568091
PDB4                           MOUNTED             6 2306285303

6 rows selected.

SQL>


2.2 Startup PDB with in PDB

-- Switch to PDB from CDB
SQL> alter session set container=PDB2;  <----

Session altered.

SQL> show con_name

CON_NAME
------------------------------
PDB2
SQL> show con_id

CON_ID
------------------------------
4
SQL>

SQL> show pdbs;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         4 PDB2                           MOUNTED   <-----
SQL>

SQL> startup;
Pluggable Database opened.
SQL> 

-- OR --

SQL> ALTER DATABASE OPEN;

Database altered.

SQL> 

-- OR -- 

SQL> ALTER PLUGGABLE DATABASE OPEN;

Pluggable database altered.

SQL>

SQL> show pdbs;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         4 PDB2                           READ WRITE NO
SQL>

SQL> select CON_ID,NAME,OPEN_MODE from v$pdbs;

    CON_ID NAME                           OPEN_MODE
---------- ------------------------------ ----------
         4 PDB2                           READ WRITE <------

SQL>


2.3 Startup ALL PDBs from CDB

-- Switch to CDB from PDB

SQL> conn / as sysdba
Connected.
SQL> 

SQL>  select name,open_mode,cdb from v$database;

NAME                           OPEN_MODE            CDB
------------------------------ -------------------- ---
CDB2                           READ WRITE           YES <----

SQL> show con_id

CON_ID
------------------------------
1

SQL> show con_name

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

SQL>

SQL> ALTER PLUGGABLE DATABASE ALL OPEN;

Pluggable database altered.

SQL>
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 PDB3                           READ WRITE NO
         6 PDB4                           READ WRITE NO
SQL>


3. Shutdown PDB


3.1 Shutdown PDB from CDB

SQL> show con_name

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

SQL>

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 PDB3                           READ WRITE NO
         6 PDB4                           READ WRITE NO
SQL>

SQL> ALTER PLUGGABLE DATABASE PDB1 CLOSE IMMEDIATE;

Pluggable database altered.

SQL>

SQL> SHOW PDBS;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB1                           MOUNTED <-----
         4 PDB2                           READ WRITE NO
         5 PDB3                           READ WRITE NO
         6 PDB4                           READ WRITE NO
SQL>


3.2 Shutdown PDB with in PDB

-- Switch to PDB from CDB
SQL> ALTER SESSION SET CONTAINER=PDB2;   <----

Session altered.

SQL> SHOW CON_NAME

CON_NAME
------------------------------
PDB2 <-----

SQL>

SQL> SHOW PDBS;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         4 PDB2                           READ WRITE NO  <------ R/W
SQL>

SQL> ALTER DATABASE CLOSE;  <-- This command work only inside CDB
ALTER DATABASE CLOSE
*
ERROR at line 1:
ORA-65040: operation not allowed from within a pluggable database

SQL> 

SQL> ALTER PLUGGABLE DATABASE CLOSE IMMEDIATE;

Pluggable database altered.

SQL>

--- OR ---

SQL> SHUT IMMEDIATE;  -- PLEASE DO NOT RUN FROM CDB, IT WILL CLOSE CDB AND ALL PDBs inside CDB
Pluggable Database closed.
SQL>

SQL> SHOW PDBS;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         4 PDB2                           MOUNTED  <----
SQL>


3.3 Shutdown ALL PDBs from CDB

-- Switch to CDB from PDB
SQL> CONN / AS SYSDBA
Connected.
SQL>

SQL> SHOW CON_NAME

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

SQL>

SQL> SHOW PDBS;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB1                           MOUNTED
         4 PDB2                           MOUNTED
         5 PDB3                           READ WRITE NO
         6 PDB4                           READ WRITE NO
SQL>

SQL> ALTER PLUGGABLE DATABASE ALL CLOSE IMMEDIATE;

Pluggable database altered.

SQL>
SQL> SHOW PDBS;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB1                           MOUNTED
         4 PDB2                           MOUNTED
         5 PDB3                           MOUNTED
         6 PDB4                           MOUNTED
SQL>


4. Shutdown CDB

PLEASE DO NOT run SHUT IMMEDIATE OR ALTER DATABASE CLOSE command from CDB, it will shutdown ALL PDBs,PDB$SEED & CDB$ROOT inside CDB. Example for the same below

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

NAME                           OPEN_MODE      CON_ID       DBID
------------------------------ ---------- ---------- ----------
CDB$ROOT                       READ WRITE          1  680230459 <-- R/W
PDB$SEED                       READ ONLY           2 2993936271
PDB1                           MOUNTED             3  627484885
PDB2                           MOUNTED             4  891811039
PDB3                           MOUNTED             5  424568091
PDB4                           MOUNTED             6 2306285303

6 rows selected.

SQL>

SQL> SHOW CON_NAME

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

SQL>

SQL> SHUT IMMEDIATE;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>

SQL> !ps -ef | grep pmon
oracle   13612 12669  0 19:00 pts/0    00:00:00 /bin/bash -c ps -ef | grep pmon
oracle   13614 13612  0 19:00 pts/0    00:00:00 grep pmon

SQL>
SQL> col name for a30
SQL> select name,open_mode,con_id,dbid from v$containers;

NAME                           OPEN_MODE      CON_ID       DBID
------------------------------ ---------- ---------- ----------
CDB$ROOT                       READ WRITE          1  680230459
PDB$SEED                       READ ONLY           2 2993936271
PDB1                           READ WRITE          3  627484885
PDB2                           READ WRITE          4  891811039
PDB3                           READ WRITE          5  424568091
PDB4                           READ WRITE          6 2306285303

6 rows selected.

SQL> show con_name

CON_NAME
------------------------------
CDB$ROOT <----
SQL>
SQL> ALTER DATABASE CLOSE IMMEDIATE;

Database altered.

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

NAME                           OPEN_MODE      CON_ID       DBID
------------------------------ ---------- ---------- ----------
CDB$ROOT                       MOUNTED             1  680230459
PDB$SEED                       MOUNTED             2 2993936271
PDB1                           MOUNTED             3  627484885
PDB2                           MOUNTED             4  891811039
PDB3                           MOUNTED             5  424568091
PDB4                           MOUNTED             6 2306285303

6 rows selected.

SQL>
SQL> shut immediate;
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.
SQL>
SQL> !ps -ef | grep pmon
oracle   14495 12669  0 19:16 pts/0    00:00:00 /bin/bash -c ps -ef | grep pmon
oracle   14497 14495  0 19:16 pts/0    00:00:00 grep pmon

SQL>

Recommendation: ALWAYS PLEASE SWITCH TO PDB and then do your task

Caution: Your use of any information or materials on this website is entirely at your own risk. It is provided for educational purposes only. It has been tested internally, however, we do not guarantee that it will work for you. Ensure that you run it in your test environment before using.

Thank you,
Rajasekhar Amudala