Startup and shutdown of container database (CDB) and pluggable database (PDB) with new features of Oracle12cr1

 

 

The multitenant option introduced in Oracle12c allows a single container database to host multiple independent pluggable databases (PDBs). This article will explain how to start and shut down Container Database (CDB) and Pluggable Database (PDB).

1. Container Database (CDB)

Starting and shutting down the container database is the same as ever. The STARTUP and SHUTDOWN commands are available in SQL*Plus when connecting to the CDB as an authorized user. The specific syntax is as follows:

STARTUP [NOMOUNT | MOUNT | RESTRICT | UPGRADE| FORCE | READ ONLY]

SHUTDOWN [IMMEDIATE | ABORT]

2. Pluggable Database (PDB)

Pluggable databases can be started and shut down with the SQL*Plus command or the ALTER PLUGGABLEDATABASE command.

3. SQL*Plus command

When connected to a pluggable database as an authorized user, the following commands can be used to start and shut down the database:

STARTUP FORCE;

STARTUP OPEN READ WRITE [RESTRICT];

STARTUP OPEN READ ONLY [RESTRICT];

STARTUP UPGRADE;

SHUTDOWN [IMMEDIATE];

 

An example is as follows:

STARTUP FORCE;

SHUTDOWN IMMEDIATE;

 

STARTUP OPEN READ WRITE RESTRICT;

SHUTDOWN;

 

STARTUP;

SHUTDOWN IMMEDIATE;

4.        ALTER PLUGGABLE DATABASE

The ALTER PLUGGABLE DATABASE command can be used in CDB or PDB.

When connected to a PDB as an authorized user, the following commands can be used to open and close the current PDB.

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

Examples are as follows.

ALTER PLUGGABLE DATABASE OPEN READ ONLYFORCE;

ALTER PLUGGABLE DATABASE CLOSE IMMEDIATE;

 

ALTER PLUGGABLE DATABASE OPEN READ WRITE;

ALTER PLUGGABLE DATABASE CLOSE IMMEDIATE;

When connected to a CDB as an authorized user, the following commands can be used to open and close one or more PDBs.

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

 The <pdb-name-clause> clause can be the following values:

One or more comma-separated PDB names.

 The ALL keyword refers to all PDBs.

The ALL EXCEPT keyword, followed by one or more comma-separated PDBs, refers to a subset of PDBs.

An example is as follows:

ALTER PLUGGABLE DATABASE pdb1, pdb2 OPEN READONLY FORCE;

ALTER PLUGGABLE DATABASE pdb1, pdb2 CLOSEIMMEDIATE;

 

ALTER PLUGGABLE DATABASE ALL OPEN;

ALTER PLUGGABLE DATABASE ALL CLOSE IMMEDIATE;

 

ALTER PLUGGABLE DATABASE ALL EXCEPT pdb1OPEN;

ALTER PLUGGABLE DATABASE ALL EXCEPT pdb1CLOSE IMMEDIATE;

5. Pluggable Database (PDB) auto-start

The Oracle12.1.0.2 patch set has introduced the ability to maintain the PDB startup state, so it is no longer necessary to automatically open the PDB through the following trigger method.

Before Oracle12.1.0.2, after CDB is started, all PDBs are in the loaded state. There is no default mechanism to automatically start the PDB when the CDB starts. Some or all PDBs can only be automatically started by establishing a system trigger on the CDB.

CREATE OR REPLACE TRIGGER open_pdbs

  AFTERSTARTUP ON DATABASE

BEGIN

  EXECUTE IMMEDIATE 'ALTER PLUGGABLEDATABASE ALL OPEN';

END open_pdbs;

/

If you don't want to start all PDBs, you can customize this trigger.

6. Keep PDB up (after 12.1.0.2)

The Oracle 12.1.0.2 patch set allows the PDB to remain up when the CDB is restarted. This can be achieved with the ALERPLUGGABLE DATABASE command.

We can observe the whole process of CDB restart. Note that the PDB is in read-write mode before reboot, but in load mode after reboot.

SELECT name, open_mode FROM v$pdbs;

 

NAME                          OPEN_MODE

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

PDB$SEED                       READ ONLY

PDB1                           READWRITE

PDB2                           READWRITE

 

SQL>

SHUTDOWN IMMEDIATE;

STARTUP;

 

SELECT name, open_mode FROM v$pdbs;

 

NAME                          OPEN_MODE

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

PDB$SEED                       READONLY

PDB1                          MOUNTED

PDB2                          MOUNTED

 

SQL>

Next, we open both PDBSs, but only save the state of PDB1.

ALTER PLUGGABLE DATABASE pdb1 OPEN;

ALTER PLUGGABLE DATABASE pdb2 OPEN;

ALTER PLUGGABLE DATABASE pdb1 SAVE STATE;

The view DBA_PDB_SAVED_STATES displays information about the save state of the container.

COLUMN con_name FORMAT A20

COLUMN instance_name FORMAT A20

 

SELECT con_name, instance_name, state FROMdba_pdb_saved_states;

 

CON_NAME            INSTANCE_NAME        STATE

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

PDB1                 cdb1                 OPEN

 

SQL>

 

Restarting CDB will give a different result.

SELECT name, open_mode FROM v$pdbs;

NAME                          OPEN_MODE

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

PDB$SEED                       READONLY

PDB1                           READWRITE

PDB2                           READWRITE

 

SQL>

 

 

SHUTDOWN IMMEDIATE;

STARTUP;

 

 

SELECT name, open_mode FROM v$pdbs;

 

NAME                         OPEN_MODE

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

PDB$SEED                       READONLY

PDB1                           READWRITE

PDB2                          MOUNTED

 

SQL>

The saved state can be discarded with the following commands.

ALTER PLUGGABLE DATABASE pdb1 DISCARD STATE;

 

COLUMN con_name FORMAT A20

COLUMN instance_name FORMAT A20

 

SELECT con_name, instance_name, state FROMdba_pdb_saved_states;

 

no rows selected

 

SQL>

7. Note:

Ø Only the container is in read-only or read-write mode, the state can be saved and explicit in the view DBA_PDB_SAVED_STATES. When running the ALTER PLUGGABLE DATABASE ... SAVE STATE command on a container with a loaded state, neither an error is reported nor the state is logged, because this is the default state after a CDB restart.

Ø Like other examples of the ALTER PLUGGABLEDATABASE command, PDBs can be listed individually, or as comma-separated PDB columns, or with the ALL or ALL EXCEPT keywords.

Ø In the RAC environment, the INSTANCES clause can be added. This clause can write a single instance, comma-separated instance columns, ALL or ALL EXCEPT keywords. Regardless of the INSTANCES clause, the SAVE/DISCARD STATE command affects only the current instance.

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325117122&siteId=291194637