Switching between pluggable database – alter session set container
Alter session set container - <pdb_name> can be used
to switch between pluggable databases of multitenant Oracle setup.
With Oracle multitenant being Oracles preferred
implementation method with non-cdb architecture is deprecated in Oracle 12c - (Refer screen below , https://docs.oracle.com/database/121/UPGRD/deprecated.htm#BABDBCJI),
alter session set container does become a common command to use.
Alter session set container example
oracle@pcitdb:~$ sqlplus sys as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Wed Jul 22 16:57:54 2020
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Enter password:
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL> set lines 1000
SQL> show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PRMUATPDB READ WRITE NO
4 PRMGLD31 MOUNTED
5 PRMDEVPDB MOUNTED
7 PRMINTGR READ WRITE NO
SQL> alter session set container=PRMINTGR;
Session altered.
SQL> show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
7 PRMINTGR READ WRITE NO
SQL> show user;
USER is "SYS"
SQL>
Also if you are too lazy to type the whole command every
time you switch between pdbs, best option is to have sql files created with
alter sessions set container command in home directory so script can be
executed to switch to PDB.
oracle@pcitdb:~$ cat PRMINTGR.sql
alter session set container=PRMINTGR;
oracle@pcitdb:~$ sqlplus sys as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Wed Jul 22 23:36:17 2020
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Enter password:
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL> @PRMINTGR
Session altered.
SQL> show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
7 PRMINTGR READ WRITE NO
SQL>
Comments
Post a Comment