{
  "date": "2015-11-30T17:45:09",
  "slug": "ocm-12c-preparation-manage-pdb",
  "link": "https://www.dbi-services.com/blog/ocm-12c-preparation-manage-pdb/",
  "title": {
    "rendered": "OCM 12c preparation: Manage PDB"
  },
  "content": {
    "rendered": "<h2>By Franck Pachot</h2>\n<p>.<br />\nLet&#8217;s see the different ways to create a PDB, with different tools.<br />\nSame disclaimer here as in the <a href=\"http://dbi-services.com/blog/ocm-12c-preparation-create-cdb-in-command-line/\">first post of the series</a>: don&#8217;t expect to get those posts close to what you will have at the exam, but they cover important points that matches the exam topics. </p>\n<h3>Documentation</h3>\n<p>Information about the exam says: <i>Be prepared to use the non-searchable documentation during the exam, to help you with correct syntax.</i><br />\nDocumentation about the &#8216;Create and manage pluggable databases&#8217; topic is mostly in the Oracle® Database Administrator&#8217;s Guide. Search for &#8216;multitenant&#8217;, expand &#8216;Creating and Removing PDBs with SQL*Plus&#8217;</p>\n<p>You find all examples there. Remember that creating a PDB is always done from another one:</p>\n<ul>\n<li>from PDB$SEED</li>\n<li>from another PDB in your CDB</li>\n<li>from another PDB in a remote CDB (need to create a db link)</li>\n<li>from an unplugged PDB</li>\n<li>from a non-CDB</li>\n</ul>\n<p>and the you will name your datafiles with a conversion from the original ones.</p>\n<p>Don&#8217;t forget to create the directories if you are not in OMF.</p>\n<h3>SQL Developer</h3>\n<p>SQL Developer is your friend. It is designed to help you. I use it in the following way:</p>\n<ul>\n<li>SQL Worksheet is a nice notepad. Even if you finally paste the statements into sqlplus, the SQL Woksheet is graphical, has colors, and can also run statements from there 😉</li>\n<li>SQL Reference documentation is classified by statements. SQL Developer is classified by objects. Right clock context menu shows you what you can do on a table, on a materialized view, etc</li>\n<li>It shows what are your options and can show you the generated SQL statement if you finally want it</li>\n</ul>\n<p>I&#8217;ll show you an example. You have several ways to name the files when you create a pluggable database, using the convert pairs. But if you have more than one pattern to replace, it&#8217;s not easy. Let&#8217;s use SQL Developer for that.</p>\n<p>In the DBA tab, right click on the Container Database and you have all possible actions on it:</p>\n<p><a href=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/Capture12COCMU-CreatePDB-000.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/Capture12COCMU-CreatePDB-000.jpg\" alt=\"Capture12COCMU-CreatePDB-000\" width=\"436\" height=\"311\" class=\"alignnone size-full wp-image-5610\" /></a></p>\n<p>Here are all option for the CREATE PLUGGABLE DATABASE statement. Easier that going to documentation:</p>\n<p><a href=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/Capture12COCMU-CreatePDB-001.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/Capture12COCMU-CreatePDB-001.jpg\" alt=\"Capture12COCMU-CreatePDB-001\" width=\"600\" height=\"406\" class=\"alignnone size-full wp-image-5614\" /></a></p>\n<p>Above I&#8217;ve chosen &#8216;Custom Names&#8217; to list all files. Then let&#8217;s get the SQL:</p>\n<p><a href=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/Capture12COCMU-CreatePDB-002.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/Capture12COCMU-CreatePDB-002.jpg\" alt=\"Capture12COCMU-CreatePDB-002\" width=\"603\" height=\"410\" class=\"alignnone size-full wp-image-5613\" /></a></p>\n<p>Now, I prefer to continue in the SQL Worksheet and I can paste it there. I&#8217;ve a file_name_convert pair for each files, so that I can change what I want:</p>\n<p><a href=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/Capture12COCMU-CreatePDB-003.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/Capture12COCMU-CreatePDB-003.jpg\" alt=\"Capture12COCMU-CreatePDB-003\" width=\"799\" height=\"338\" class=\"alignnone size-full wp-image-5612\" /></a></p>\n<p>SQL Developer is really a good tool.<br />\nWhen you unplug a PDB, it is still referenced by the original database. Then is you plug it elsewhere without renaming the files, the risk is that you drop it&#8217;s datafiles from the original container database.<br />\nBest recommendation is to immediately remove it from the original CDB and this is exactly what SQL Developer is doing:</p>\n<blockquote class=\"twitter-tweet\" data-width=\"500\" data-dnt=\"true\">\n<p lang=\"en\" dir=\"ltr\"><a href=\"https://twitter.com/hashtag/12COCMU?src=hash&amp;ref_src=twsrc%5Etfw\">#12COCMU</a> Good point <a href=\"https://twitter.com/OracleSQLDev?ref_src=twsrc%5Etfw\">@OracleSQLDev</a><br />A safe unplug must immediately remove the PDB from the original CDB <a href=\"https://t.co/Cdh1k7fpio\">pic.twitter.com/Cdh1k7fpio</a></p>\n<p>&mdash; Franck Pachot (@FranckPachot) <a href=\"https://twitter.com/FranckPachot/status/671340731638923264?ref_src=twsrc%5Etfw\">November 30, 2015</a></p></blockquote>\n<p><script async src=\"https://platform.twitter.com/widgets.js\" charset=\"utf-8\"></script></p>\n<h3>dbca</h3>\n<p>DBCA is not my preferred tool to create a PDB, but let&#8217;s try it.</p>\n<p>Let&#8217;s start by some troubleshooting (which is <u>not</u> what you want to do at an exam):<br />\n<a href=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/Capture12COCMU-CreatePDB-005.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/Capture12COCMU-CreatePDB-005.jpg\" alt=\"Capture12COCMU-CreatePDB-005\" width=\"346\" height=\"183\" class=\"alignnone size-full wp-image-5617\" /></a></p>\n<p>Well it is open. Let&#8217;s troubleshoot. dbca log is in $ORACLE_BASE/cfgtoollogs/dbca and I found the following:</p>\n<pre><code>\n[pool-1-thread-1] [ 2015-11-29 19:22:42.910 CET ] [PluggableDatabaseUtils.isDatabaseOpen:303]  Query to check if DB is open= select count(*) from v$database where upper(db_unique_name)=upper('CDB') and upper(open_mode)='READ WRITE'\n...\n[pool-1-thread-1] [ 2015-11-29 19:22:43.034 CET ] [PluggableDatabaseUtils.isDatabaseOpen:334]  DB is not open\n</code></pre>\n<p>Actually, I&#8217;ve no DB_UNIQUE_NAME in v$database:</p>\n<pre><code>\nSQL&gt; select db_unique_name from v$database;\n\nDB_UNIQUE_NAME\n------------------------------\n\n</code></pre>\n<p>I&#8217;ve the db_unique_name for the instance:</p>\n<pre><code>\nSQL&gt; show parameter uniq\n&nbsp;\nNAME                                 TYPE        VALUE\n------------------------------------ ----------- ------------------------------\ndb_unique_name                       string      CDB\n</code></pre>\n<p>but it&#8217;s the default (equals the db_name) as I didn&#8217;t set it in the init.ora when I created the CDB manually.<br />\nLet&#8217;s try to set it:</p>\n<pre><code>\nSQL&gt; alter system set db_unique_name='CDB' scope=spfile;\nalter system set db_unique_name='CDB' scope=spfile\n*\nERROR at line 1:\nORA-32001: write to SPFILE requested but no SPFILE is in use\n</code></pre>\n<p>Ok, now I understand. I&#8217;ve created the spfile but didn&#8217;t restart the instance since then.</p>\n<pre><code>\nSQL&gt; startup force\nORACLE instance started.\n\nTotal System Global Area 1073741824 bytes\nFixed Size                  2932632 bytes\nVariable Size             335544424 bytes\nDatabase Buffers          729808896 bytes\nRedo Buffers                5455872 bytes\nDatabase mounted.\nshow parameter Database opened.\nSQL&gt; show spparameter unique\nSQL&gt; select db_unique_name from v$database;\n\nDB_UNIQUE_NAME\n------------------------------\nCDB\n&nbsp;\n</code></pre>\n<p>Here it is. It&#8217;s not set in spfile, but takes the default. When we start with a pfile where it&#8217;s not set, it is not there in V$DATABASE.</p>\n<p>My conclusion for the moment is: if you didn&#8217;t create the database with DBCA there is no reason to try to use it later.</p>\n<p>And the most important when you create a PDB is written in the doc: </p>\n<blockquote class=\"twitter-tweet\" data-width=\"500\" data-dnt=\"true\">\n<p lang=\"en\" dir=\"ltr\"><a href=\"https://twitter.com/hashtag/12COCMU?src=hash&amp;ref_src=twsrc%5Etfw\">#12COCMU</a> backup the PDB after creation (suppose CDB has a backup already) <a href=\"https://t.co/p8I08p3boO\">pic.twitter.com/p8I08p3boO</a></p>\n<p>&mdash; Franck Pachot (@FranckPachot) <a href=\"https://twitter.com/FranckPachot/status/670925064972468225?ref_src=twsrc%5Etfw\">November 29, 2015</a></p></blockquote>\n<p><script async src=\"https://platform.twitter.com/widgets.js\" charset=\"utf-8\"></script></p>\n",
    "protected": false
  }
}
