{"id":18930,"date":"2020-04-26T15:36:17","date_gmt":"2020-04-26T15:36:17","guid":{"rendered":"https:\/\/www.testingdocs.com\/questions\/?p=18930"},"modified":"2024-12-14T05:40:13","modified_gmt":"2024-12-14T05:40:13","slug":"how-to-connect-to-pluggable-database-pdb-using-sqlplus","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/how-to-connect-to-pluggable-database-pdb-using-sqlplus\/","title":{"rendered":"Connect to Pluggable Database (PDB)"},"content":{"rendered":"<h1>Connect to Pluggable Database (PDB)<\/h1>\n<p>This tutorial will teach us how to create and connect the pluggable database (PDB) using the SQL*Plus command line tool. The general steps are:<\/p>\n<ul>\n<li>Launch SQL*Plus command line.<\/li>\n<li>Issue SQL commands.<\/li>\n<\/ul>\n<p>This tutorial is based on <strong>Oracle 19c<\/strong>\u2014the steps for installing Oracle 19c on the Windows operating system.<\/p>\n<p>First, let&#8217;s understand the two different types of database architectures in Oracle:<\/p>\n<ul>\n<li>CDB (Container Database)<\/li>\n<li>PDB (Pluggable Database)<\/li>\n<\/ul>\n<h2>Container Database( CDB )<\/h2>\n<p>CDB is a single physical database that contains multiple PDBs. Each PDB functions as an independent database with its own data dictionary, schema objects, and users. CDB&#8217;s advantage is that it allows you to manage multiple databases as if they were separate entities while efficiently sharing resources like memory and CPU. This makes it ideal for large-scale deployments where you need to isolate different applications or teams but still want to benefit from shared infrastructure costs.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-21539\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Pluggable-Databases-Oracle.png\" alt=\"Pluggable Databases Oracle\" width=\"1711\" height=\"908\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Pluggable-Databases-Oracle.png 1711w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Pluggable-Databases-Oracle-300x159.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Pluggable-Databases-Oracle-1024x543.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Pluggable-Databases-Oracle-768x408.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Pluggable-Databases-Oracle-1536x815.png 1536w\" sizes=\"auto, (max-width: 1711px) 100vw, 1711px\" \/><\/p>\n<h2>Pluggable Database( PDB )<\/h2>\n<p>Each pluggable database has its background processes running on dedicated threads within the same process space (as opposed to separate processes).<br \/>\nPDB provides more flexibility when managing your data by allowing you to create new schemas within an existing container without affecting other parts of the system or requiring downtime for maintenance operations such as upgrading software or patching security vulnerabilities across all containers simultaneously.PDBs enhance performance by reducing context switching overhead between tasks associated with different databases within a single instance of Oracle Server.<\/p>\n<h2>Commands<\/h2>\n<p>Open the PDB if the database is not open. The name of the PDB in this example is: <strong>orclpdb<\/strong><\/p>\n<p>Error indication:<\/p>\n<p><em>ERROR:<\/em><br \/>\n<em>ORA-01109: database not open<\/em><\/p>\n<p>Warning: You are no longer connected to ORACLE.<\/p>\n<p>Connect as SYS<\/p>\n<p><em>\\&gt;sqlplus \/ as SYSDBA<\/em><\/p>\n<h2>List PDBs Command<\/h2>\n<p>List the pluggable database instances, and type the following command at the SQL prompt:<\/p>\n<p><em>SQL&gt; SHOW pdbs;<\/em><\/p>\n<p>On Single Instance database:<\/p>\n<p>Issue the following command to open the database:<\/p>\n<pre><em>SQL&gt; ALTER PLUGGABLE DATABASE orclpdb OPEN;<\/em><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-18935\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Connect-Pluggable-Database-Oracle.png\" alt=\"Connect Pluggable Database Oracle\" width=\"1383\" height=\"886\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Connect-Pluggable-Database-Oracle.png 1383w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Connect-Pluggable-Database-Oracle-300x192.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Connect-Pluggable-Database-Oracle-1024x656.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Connect-Pluggable-Database-Oracle-768x492.png 768w\" sizes=\"auto, (max-width: 1383px) 100vw, 1383px\" \/><\/p>\n<p>On multi-tenancy RAC environment:<\/p>\n<p>We need to open on all instances:<\/p>\n<p><em>SQL&gt; ALTER PLUGGABLE DATABASE orclpdb OPEN instances=all;<\/em><\/p>\n<h3>Common Error<\/h3>\n<p>We need to have sufficient privileges to execute this command. Error when we execute this command with insufficient privileges. For example, connect as <strong>SYSDBA<\/strong> role to rectify this error.<\/p>\n<p>&nbsp;<\/p>\n<pre>SQL&gt; ALTER PLUGGABLE DATABASE orclpdb OPEN;\r\nALTER PLUGGABLE DATABASE orclpdb OPEN\r\n*\r\nERROR at line 1:\r\nORA-01031: insufficient privileges<\/pre>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-18986\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/ORacle-Error-Insufficient-.png\" alt=\"Oracle Error Insufficient\" width=\"1451\" height=\"441\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/ORacle-Error-Insufficient-.png 1451w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/ORacle-Error-Insufficient--300x91.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/ORacle-Error-Insufficient--1024x311.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/ORacle-Error-Insufficient--768x233.png 768w\" sizes=\"auto, (max-width: 1451px) 100vw, 1451px\" \/><\/p>\n<p>Connect to the database:<\/p>\n<pre>SQL&gt; ALTER SESSION SET container=orclpdb;\r\n\r\nSession altered.<\/pre>\n<p>We can now work with the database by creating local users and objects. Add the information of the PDB to the <strong>tnsnames.ora<\/strong> file.<\/p>\n<p>Locate the <strong>tnsnames.ora<\/strong> file. Path to the file<\/p>\n<p><em>ORACLE_HOME\\network\\admin<\/em><\/p>\n<p>ORACLE_HOME is an environment variable set to the Oracle install home location. The steps to set the environment variable are<a href=\"https:\/\/www.testingdocs.com\/set-oracle_home-environment-variable-on-windows\/\"> listed here<\/a>.<\/p>\n<p>Add the host string to the file.<\/p>\n<p>Save the file.<\/p>\n<pre><code class=\"language-sql\" data-line=\"\">ORCLPDB =\n  (DESCRIPTION =\n    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))\n    (CONNECT_DATA =\n      (SERVER = DEDICATED)\n      (SERVICE_NAME = orclpdb)\n    )\n  )\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>Check the connection to the pluggable database using the following command:<\/p>\n<p><em>SQL&gt; SHOW con_name;<\/em><\/p>\n<p><em>CON_NAME<\/em><br \/>\n<em>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/em><br \/>\n<em>ORCLPDB<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-23278\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Oracle-SHOW-Connection-Name.png\" alt=\"Oracle SHOW Connection Name\" width=\"1590\" height=\"1027\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Oracle-SHOW-Connection-Name.png 1590w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Oracle-SHOW-Connection-Name-300x194.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Oracle-SHOW-Connection-Name-1024x661.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Oracle-SHOW-Connection-Name-768x496.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Oracle-SHOW-Connection-Name-1536x992.png 1536w\" sizes=\"auto, (max-width: 1590px) 100vw, 1590px\" \/><\/p>\n<h2>Create User to connect<\/h2>\n<p>Create a user in the pluggable database:<\/p>\n<p>SQL&gt; CREATE USER scott IDENTIFIED BY tiger;<\/p>\n<p>Grant privileges to the user.<\/p>\n<p>SQL&gt; GRANT CONNECT,RESOURCE,UNLIMITED TABLESPACE TO scott;<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-21532\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Create-Scott-user-PDB.png\" alt=\"Create Scott user PDB\" width=\"1920\" height=\"1080\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Create-Scott-user-PDB.png 1920w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Create-Scott-user-PDB-300x169.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Create-Scott-user-PDB-1024x576.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Create-Scott-user-PDB-768x432.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Create-Scott-user-PDB-1536x864.png 1536w\" sizes=\"auto, (max-width: 1920px) 100vw, 1920px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h1>Connect to Pluggable Database<\/h1>\n<p>We can connect to the database using the CONNECT command. For example, to connect as the <em>scott<\/em> database user:<\/p>\n<p><em>CONNECT username\/password@pdbdatabase<\/em><\/p>\n<p><em>SQL&gt; CONNECT scott\/tiger@orclpdb;<\/em><br \/>\n<em>Connected.<\/em><br \/>\n<em>SQL&gt;<\/em><\/p>\n<figure id=\"attachment_23284\" aria-describedby=\"caption-attachment-23284\" style=\"width: 1582px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-23284 size-full\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Connect-to-Pluggable-Database.png\" alt=\"Connect to Pluggable Database\" width=\"1582\" height=\"945\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Connect-to-Pluggable-Database.png 1582w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Connect-to-Pluggable-Database-300x179.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Connect-to-Pluggable-Database-1024x612.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Connect-to-Pluggable-Database-768x459.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Connect-to-Pluggable-Database-1536x918.png 1536w\" sizes=\"auto, (max-width: 1582px) 100vw, 1582px\" \/><figcaption id=\"caption-attachment-23284\" class=\"wp-caption-text\">Connect to Pluggable Database<\/figcaption><\/figure>\n<p>That&#8217;s it. You are now connected to the database. Following the steps mentioned in this tutorial, you should be able to connect to an Oracle Database using <strong>SQL*Plus<\/strong> and perform various database operations.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Pluggable Database (PDB) using SQL*Plus : In this tutorial, we will learn how to create the pluggable database (PDB) using the SQL*Plus <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[207],"tags":[],"class_list":["post-18930","post","type-post","status-publish","format-standard","hentry","category-database","has-post-title","has-post-date","has-post-category","has-post-tag","has-post-comment","has-post-author",""],"_links":{"self":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/18930","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/comments?post=18930"}],"version-history":[{"count":68,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/18930\/revisions"}],"predecessor-version":[{"id":26451,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/18930\/revisions\/26451"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=18930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=18930"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=18930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}