Dear Readers,
In this article, we will see the following Multitenant Database Introduction
A Container database (CDB) is made up of the following containers:
There is one root container which stores the Oracle supplied metadata like the PL/SQL data dictionary packages and the common users. This root container is referred to as CDB$ROOT. One seed Pluggable Database (PDB) which is a system supplied template which can be used to create new PDB’s. This seed PDB is called PDB$SEED.
To find out if the database has been created as a CDB or not, just check the column called CDB in the view V$DATABASE.
1 2 3 4 |
SQL> select cdb from v$database; CDB --- YES |
Let’s check the ORACLE_SID:
1 2 |
[oracle@prosrv1 ~]$ echo $ORACLE_SID CONA |
There is just one SID; not one for each PDB. Now, let’s check for the processes “pmon”:
1 2 3 |
[oracle@prosrv1 ~]$ ps -aef|grep pmon oracle 7672 7323 0 11:18 pts/2 00:00:00 grep pmon oracle 21390 1 0 Feb19 ? 00:00:00 ora_pmon_CONA |
1 2 3 |
[oracle@prosrv1 ~]$ ps -aef|grep pmon oracle 7672 7323 0 11:18 pts/2 00:00:00 grep pmon oracle 21390 1 0 Feb19 ? 00:00:00 ora_pmon_CONA |
As you can see, the only instance running is CONA (the CDB). There is no instance for the PDB named PDB1. You can create as many of these PDBs on this CDB called CONA. There will be no additional instance. PDBs are simply hosted on the CDBs. So in effect these PDBs are like virtual machines running on a physical machine in a virtual machine context.
Since the CDB is the only real database, all the physical database components such as the Automatic Diagnostic Repository (ADR) is associated with it.
Let’s check the ADR using the ADRCI command line utility:
1 2 3 4 5 6 7 |
[oracle@prosrv1 trace]$ adrci ADRCI: Release 12.1.0.1.0 - Production on Sun Feb 24 12:18:12 2013 Copyright (c) 1982, 2013, Oracle and/or its affiliates. All rights reserved. ADR base = "/u02/oradb" adrci> show homes ADR Homes: diag/rdbms/cona/CONA |
As you see from the output, there is only one ADR home – that for CONA (the CDB). There is no separate ADR for the PDBs.
You can check the containers (or PDBs) created in a database in a view named V$PDBS, which is new in Oracle Database 12c.
1 2 3 4 5 6 7 8 |
select con_id, dbid, name from v$pdbs; CON_ID DBID NAME ---------- ---------- ------------------------------ 2 4050437773 PDB$SEED 3 3315520345 PDB1 4 3874438771 PDB2 5 3924689769 PDB3 |
Note how the DBIDs are also different for each PDB. There are two striking oddities in this output:
- There is no CON_ID of 1. There is a special container called the “root” container, known as CDB$Root that is created to hold the metadata. This container has the CON_ID of 1.
- There is a PDB called PDB$SEED, which is something we didn’t create. There are new built-in functions to identify PDBs from their details without querying the V$PDBS view. Here is an example how to identify the container ID from the name:
1 2 3 4 |
SQL> select con_name_to_id('PDB2') from dual; CON_NAME_TO_ID('PDB2') ---------------------- 4 |
And, here is how you can get the container ID from the DBID:
1 2 3 4 5 |
SQL> select con_dbid_to_id(3924689769) from dual; CON_DBID_TO_ID(3924689769) -------------------------- 5 |
Operating on Specific PDBs
The next big question is considering the unusual nature of the PDBs (they are virtual inside a real database) how you can operate on a specific PDB.
Below are the different types:
- 1. Session Variable: You can set a session variable called container to the name of the PDB you want to operate on. First connect to the CDB as usual. Here is how I connected as the SYSDBA user:
-
123[oracle@prosrv1 pluggable]$ sqlplus sys/***** as sysdbaSQL> alter session set container = pdb1;Session altered.
Now all commands in this session will be executed in the context of the PDB called PDB1. For instance suppose you want to shutdown the PDB named PDB1, you would issue:
1 2 |
SQL> shutdown immediate Pluggable Database closed. |
Only the PDB called PDB1 will be shut down, other PDBs will not be affected.
- 2. Service Name: When you create a PDB, Oracle automatically adds it as a service in the listener. You can confirm it by looking at the listener status:
123456789101112131415[oracle@prosrv1 trace]$ lsnrctl statusLSNRCTL for Linux: Version 12.1.0.1.0 - Production on 24-FEB-2013 12:20:14Copyright (c) 1991, 2013, Oracle. All rights reserved.Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))STATUS of the LISTENER------------------------Services Summary...Service "CONA" has 1 instance(s).Instance "CONA", status READY, has 1 handler(s) for this service...Service "CONAXDB" has 1 instance(s).Instance "CONA", status READY, has 1 handler(s) for this service...Service "pdb1" has 1 instance(s).Instance "CONA", status READY, has 1 handler(s) for this service...The command completed successfully
The service “pdb1” actually points to the PDB called PDB1. It’s very important to note that that this is not a service name in initialization parameter of the database, as you can see from the service_names parameter of the database.
1 2 3 4 |
SQL> show parameter service NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ service_names string CONA |
You can place that service name in an entry in the TNSNAMES.ORA file. Then you can connect to PDB1 using the connect string:
1 |
[oracle@prosrv1 ~]$ sqlplus system/*****@pdb1 |
- Using TWO_TASK: A third way is by defining the TWO_TASK operating system variable to point to the PDB you want to connect to:
[oracle@prosrv1 schema]$ export TWO_TASK=PDB1
And, then you can connect as usual without giving a connect string:
1 2 3 4 5 6 7 8 9 10 |
[oracle@prosrv1 schema]$ sqlplus system/****** To know which PDB you are connected right now in SQL*Plus SQL> show con_id CON_ID ------------------------------ 5 SQL> show con_name CON_NAME ------------------------------ PDB1 |
Thank you for giving your valuable time to read the above information. Please click here to subscribe for further updates
KTEXPERTS is always active on below social media platforms.
Facebook : https://www.facebook.com/ktexperts/
LinkedIn : https://www.linkedin.com/company/ktexperts/
Twitter : https://twitter.com/ktexpertsadmin
YouTube : https://www.youtube.com/c/ktexperts
Instagram : https://www.instagram.com/knowledgesharingplatform