Once you connect as a common user to any container within the database (either the root or a PDB), you can use the ALTER SESSION command to switch to another container for which you have been granted access. For example, to set the current container to a PDB named SALESPDB, you would do as follows:
SQL> alter session set container = salespdb;
You can switch back to the root container by specifying the CDB$ROOT:
SQL> alter session set container = cdb$root;
You do not need a listener to be up and running or a password file to switch containers. As long as the common user has privileges, then the user is successfully switched to the new container context.
Having the ability to switch containers is especially useful when you need to connect to a PDB to troubleshoot issues and then connect back to the root container.
PDB Open Modes
PDBs are opened or closed after the CDB is started. It can be opened in one of the following modes:
• Read/write
• Read only
• Hybrid read-only (new 23c)
• Migrate mode
The first two modes make sense, as you can open the database for reading and transactions. Some PDBs can be set to read-only for reporting or snapshots.
New in 23 is the hybrid read-only mode, which you can see from v$pdbs shows the database as able to read and write; however, depending on the user connected to the database, it will act as a read-only PDB.
The common user would be permitted to write, and the application or local users would still be able to read. This helps for patching and performing maintenance to still allow access to the PDB as it is in a safe mode for the operations of the common user.
Since the V$PDBS does not show if the pluggable is in hybrid mode, you can use the V$CONTAINER_TOPOLOGY view.
SQL> select con_name, open_mode, is_hybrid_read_only from v$container_topology;
To modify the PDB open mode, you can use the ALTER PLUGGABLE DATABASE … FORCE statement while the database is open. If the database is closed, you do not need the FORCE.
SQL> alter pluggable database HYBRIDPDB open read write force;
SQL> alter pluggable database HYBRIDPDB open hybrid read only force;
UPGRADE is another open mode to place the PDB into migration mode. In this mode, you can run upgrade scripts or migrate the pluggable database.
To put a PDB in mounted mode, run the close statement. This basically shuts down the PDB, but shutdown is at the CDB level. By closing the PDB, it cannot read from or write to data files. Any changes made through the CDB will be applied when the PDB is opened the next time.