You are on page 1of 5

desc v$pdbs,

================================================================================
=======================================================

sudo su - oracle --> NUID password


cskpcloudxp0330:cdb330:/users/oracle>
cskpcloudxp0330:cdb330:/users/oracle> sqlplus / as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on Thu Mar 17 13:53:28 2016
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Advanced Analytics
and Real Application Testing options
SQL> SHOW CON_NAME
CON_NAME
-----------------------------CDB$ROOT
SQL> ALTER SESSION SET container = cmsprd01;
Session altered.
SQL> SHOW CON_NAME
CON_NAME
-----------------------------CMSPRD01
SQL>ALTER SESSION SET CONTAINER=CDB$ROOT;
Session altered.
SQL> SHOW CON_NAME
CON_NAME
-----------------------------CDB$ROOT
SQL> set pages 200 lines 200;
SQL> /
Session altered.
SQL> select USERNAME,ACCOUNT_STATUS,EXPIRY_DATE,PROFILE from dba_users;
==========================================

Basic Monitoring Command Line Instructions


==========================================
To find If a Database is CDB or Non-CDB
==========================================
SQL> SELECT NAME, CDB, CON_ID FROM V$DATABASE;
NAME CDB CON_ID
--------- --- ---------CONDB YES
0
[OR]
SQL> SHOW PARAMETER enable_pluggable_database
NAME
TYPE
VALUE
---------------------------------------------enable_pluggable_database
boolean TRUE

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

To find the Current Database that we are logged in


===================================================
SQL> SELECT SYS_CONTEXT ('USERENV', 'CON_NAME') FROM DUAL;
SYS_CONTEXT('USERENV','CON_NAME')
-------------------------------------------------------------------------------CDB$ROOT

To find the information about Pluggable Databases


=================================================
COL PDB_NAME FOR A30
SQL> SELECT PDB_ID,PDB_NAME,STATUS,CON_ID FROM CDB_PDBS order by 1;
PDB_ID
---------2
3
4
5
6

PDB_NAME
-----------------------------PDB$SEED
CMSPRD01
AUDPRD01
APOPRD01
MONPRD01

STATUS
CON_ID
--------- ---------NORMAL
2
NORMAL
3
NORMAL
4
NORMAL
5
NORMAL
6

To login to a Container or a specific PDB


There are two ways we can login into a Container or PDB
================================================================================
====
1. SQLPLUS/CONNECT - This requires a TNS entry to login to a specific PDB locall
y or remotely

oracle@ora12c ~]$ sqlplus sys/123@PDB as sysdba


SQL*Plus: Release 12.1.0.1.0 Production on Sat Jun 29 12:35:02 2013
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing opt
ions
SQL> SELECT SYS_CONTEXT ('USERENV', 'CON_NAME') FROM DUAL;
SYS_CONTEXT('USERENV','CON_NAME')
-------------------------------------------------------------------------------PDB
2. ALTER SESSION
SQL> ALTER SESSION SET CONTAINER=SALESPDB;
Session altered.
SQL> SELECT SYS_CONTEXT ('USERENV', 'CON_NAME') FROM DUAL;
SYS_CONTEXT('USERENV','CON_NAME')
-------------------------------------------------------------------------------SALESPDB

To switch between Containers using ALTER SESSION,


=================================================
1. To switch to SEED Container,
SQL> ALTER SESSION SET CONTAINER=PDB$SEED;
Session altered.
SQL> SELECT SYS_CONTEXT ('USERENV', 'CON_NAME') FROM DUAL;
SYS_CONTEXT('USERENV','CON_NAME')
-------------------------------------------------------------------------------PDB$SEED

2. To switch to ROOT Container,


==========================================
SQL> ALTER SESSION SET CONTAINER=CDB$ROOT;
Session altered.
SQL> SELECT SYS_CONTEXT ('USERENV', 'CON_NAME') FROM DUAL;
SYS_CONTEXT('USERENV','CON_NAME')
-------------------------------------------------------------------------------CDB$ROOT
To mount or dismount and find the status of a PDB,
==================================================
SQL> ALTER PLUGGABLE DATABASE PDB OPEN;
Pluggable database altered.

SQL> ALTER PLUGGABLE DATABASE PDB CLOSE IMMEDIATE;


Pluggable database altered.
[OR]
SQL> SHUT IMMEDIATE
Pluggable Database closed.
For multiple PDBs,
SQL> ALTER PLUGGABLE DATABASE PDB,PDB1,SALESPDB OPEN;
Pluggable database altered.
SQL> ALTER PLUGGABLE DATABASE PDB,PDB1,SALESPDB CLOSE;
Pluggable database altered.

SQL> SELECT NAME,OPEN_MODE,TOTAL_SIZE/1024/1024/1024 FROM V$PDBS;


NAME
OPEN_MODE TOTAL_SIZE/1024/1024/1024
------------------------------ ---------- ------------------------PDB$SEED
READ ONLY .263671875
PDB
READ WRITE .424804688
SALESPDB
MOUNTED
0

To modify any PDB Characteristics,


==================================
"ALTER PLUGGABLE DATABASE" is the command replaces "ALTE DATABASE" command in a
CDB Environment. For example If the goal is to change the default tablespace of
a PDB,
1. Tablespace must be created within the PDB
2. Use the below command to change it,
SQL> SELECT SYS_CONTEXT ('USERENV', 'CON_NAME') FROM DUAL;
SYS_CONTEXT('USERENV','CON_NAME')
-------------------------------------------------------------------------------PDB
SQL> CREATE TABLESPACE TS_PDB DATAFILE '/dbs/CONDB/PDB/ts_pdb_01.dbf' SIZE 10M;
Tablespace created.
SQL> ALTER PLUGGABLE DATABASE PDB DEFAULT TABLESPACE TS_PDB;
Pluggable database altered.

To set an initialization Parameter :


==================================
A Parameter can be set exclusive to a PDB, or for all current and future PDBs us
ing "ALTER SYSTEM" command.
On the root container:
SQL> ALTER SYSTEM SET RESOURCE_LIMIT=TRUE CONTAINER=ALL;
System altered.
On a specific container or PDB:

SQL> ALTER SYSTEM SET RESOURCE_LIMIT=TRUE;


System altered.

To create a user in the ROOT Container and accessing other PDBs:


===============================================================
A CDB has common user environment. A User exists in the ROOT Container can login
to any PDB with the privileges given and by default it is mapped to all availab
le PDBs and future PDBs. A CDB also has local users exclusive to PDBs.
A Common user and role name must start with C## or c## and consists only of ASCI
I characters.
To login to a specific PDB, A Common user must have CREATE SESSION Privilege on
the PDB.
SQL> SELECT SYS_CONTEXT ('USERENV', 'CON_NAME') FROM DUAL;
SYS_CONTEXT('USERENV','CON_NAME')
-------------------------------------------------------------------------------CDB$ROOT
SQL> CREATE USER C##PDB IDENTIFIED BY PDB;
User created.
SQL> GRANT CREATE SESSION TO C##PDB;
Grant succeeded.
SQL> GRANT CREATE SESSION TO C##PDB CONTAINER=ALL; (ALL Specifies all Containers
or PDBs)
Grant succeeded.
SQL> CONNECT C##PDB@PDB
Enter password:
Connected.
SQL> SELECT SYS_CONTEXT ('USERENV', 'CON_NAME') FROM DUAL;
SYS_CONTEXT('USERENV','CON_NAME')
-------------------------------------------------------------------------------PDB
SQL> SHOW USER
USER is "C##PDB"

You might also like