{"id":1062,"date":"2014-11-07T14:58:06","date_gmt":"2014-11-07T17:58:06","guid":{"rendered":"http:\/\/dev.dbarj.com.br\/?p=1062"},"modified":"2014-11-10T15:02:17","modified_gmt":"2014-11-10T18:02:17","slug":"rename-schema-oracle-11g-loopback-dblink","status":"publish","type":"post","link":"https:\/\/dev.dbarj.com.br\/en\/2014\/11\/rename-schema-oracle-11g-loopback-dblink\/","title":{"rendered":"Rename schema in Oracle 11g with Loopback DBLink"},"content":{"rendered":"<p>In this article, we will deal a very common situation where the DBA is tasked to rename or clone a user into the same database. In the following lines, I will explain how to make this copy without higher complexities and with no need to generate intermediate dump files, using DataPump import utility with a loopback dblink.<\/p>\n<p>This task can be done in 3 easy steps:<\/p>\n<ol>\n<li>Create a temporary loopback dblink.<\/li>\n<li>Run the Import DataPump to clone the user.<\/li>\n<li>Remove the temporary dblink created in item 1.<\/li>\n<\/ol>\n<p>Let&#8217;s start:<\/p>\n<h2>1) Create a temporary loopback dblink.<\/h2>\n<p>In this example, we will clone the whole user <strong><span style=\"color: #0000ff;\">SCOTT<\/span><\/strong> with its objects and data to a new, <strong><span style=\"color: #0000ff;\">SCOTT_BKP<\/span><\/strong>. We will do this task with the user &#8220;DBADMIN&#8221;, which is a DBA this database.<\/p>\n<p>The first step is to create a temporary loopback dblink. Assuming that the <strong>SERVICE_NAME<\/strong> DB is &#8220;<strong>ORCL<\/strong>&#8221; and he is running on port &#8220;<strong>1521<\/strong>&#8220;:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"oracledb\">create database link TMP_DBLINK\r\nusing '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL= TCP) (HOST=127.0.0.1)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=ORCL)))';<\/pre>\n<p>You could also just use the TNS entry name, if there is one that already locally point to this DB. Assuming, for example, that there one TNS Names &#8220;ORCL&#8221;:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"oracledb\">create database link TMP_DBLINK using 'ORCL';\r\n<\/pre>\n<p>Note\u00a0that on both cases I\u00a0do omit the &#8220;connect to&#8221; clause to force connection\u00a0to the database as the locally connected user (DBADMIN, in this example).\u00a0Once you create it, test it by running:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"oracledb\">SQL&gt; select * from dual@TMP_DBLINK;\r\n\r\nD\r\n-\r\nX<\/pre>\n<h2>2)\u00a0Run the Import DataPump to clone the user.<\/h2>\n<p>The next step is to clone the user.\u00a0If you are using this tutorial to rename a user, ensure that there is no transaction, DDL or DML in its objects.<\/p>\n<p>Run the PL\/SQL block:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">DECLARE\r\n\tH1 NUMBER;\r\n\tHSTATUS VARCHAR2(200);\r\n\tFROMUSER VARCHAR2(30);\r\n\tTOUSER VARCHAR2(30);\r\nBEGIN\r\n\tFROMUSER := 'SCOTT';\r\n\tTOUSER := 'SCOTT_BKP';\r\n\tH1 := DBMS_DATAPUMP.OPEN(OPERATION =&gt; 'IMPORT', JOB_MODE =&gt; 'SCHEMA', REMOTE_LINK =&gt; 'TMP_DBLINK');\r\n\tDBMS_DATAPUMP.METADATA_FILTER(HANDLE =&gt; H1, NAME =&gt; 'SCHEMA_LIST', VALUE =&gt; '''' || FROMUSER || '''');\r\n\tDBMS_DATAPUMP.METADATA_REMAP(HANDLE =&gt; H1, NAME =&gt; 'REMAP_SCHEMA', OLD_VALUE =&gt; FROMUSER, VALUE =&gt; TOUSER);\r\n\tDBMS_DATAPUMP.START_JOB(HANDLE =&gt; H1);\r\n\tDBMS_DATAPUMP.WAIT_FOR_JOB(HANDLE =&gt; H1, JOB_STATE =&gt; HSTATUS);\r\n\tDBMS_OUTPUT.PUT_LINE('STATUS = ' || HSTATUS);\r\nEND;\r\n\/<\/pre>\n<p>The runtime of the script varies depending on the amount of objects and user data.\u00a0Check whether the output was &#8220;<strong>STATUS = COMPLETED<\/strong>&#8220;. If not, follow the steps in the last part of this article.<\/p>\n<h2>3)\u00a0Remove the temporary dblink created in item 1.<\/h2>\n<p>Finally, check that all objects were duplicated with the SQL below:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"oracledb\">select   owner,object_type,status,count(*)\r\nfrom     dba_objects\r\nwhere    owner in ('SCOTT','SCOTT_BKP')\r\ngroup by owner,object_type,status\r\norder by 2,1,3;<\/pre>\n<p>If everything is similar, remove the temporary dblink created:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"oracledb\">drop database link TMP_DBLINK;<\/pre>\n<p>Okay, now you have an identical copy of your schema in your database!\u00a0If you are using this tutorial to rename a user, you can now remove the old user or keep\u00a0it as a backup.<\/p>\n<h2><span style=\"color: #800000;\">Checking in case of Failures<\/span><\/h2>\n<p>If you have problems during the checking of objects, it is possible to enable logging of import DataPump to identify the cause of failure. To do so, you must create a temporary directory for the log:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"oracledb\">create directory TMP_DIR as '\/tmp';<\/pre>\n<p>Then add the following statement below the line of PL\/SQL with DBMS_DATAPUMP.OPEN command:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"oracledb\">DBMS_DATAPUMP.ADD_FILE(\r\n\tHANDLE =&gt; H1,\r\n\tFILENAME =&gt; 'imp.log',\r\n\tDIRECTORY =&gt; 'TMP_DIR',\r\n\tFILETYPE =&gt; DBMS_DATAPUMP.KU$_FILE_TYPE_LOG_FILE\r\n);<\/pre>\n<p>Finally, after correcting the error and run the command correctly, do not forget to remove the temporary directory:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"oracledb\">drop directory TMP_DIR;\r\n<\/pre>\n<b>Have you enjoyed? Please leave a comment or give a ?!<\/b>\n<div class='watch-action'><div class='watch-position align-left'><div class='action-like'><a class='lbg-style2 like-1062 jlk' href='javascript:void(0)' data-task='like' data-post_id='1062' data-nonce='b7aaf4ff99' rel='nofollow'><img class='wti-pixel' src='https:\/\/dev.dbarj.com.br\/wp-content\/plugins\/wti-like-post\/images\/pixel.gif' title='Like' \/><span class='lc-1062 lc'>+22<\/span><\/a><\/div><\/div> <div class='status-1062 status align-left'><\/div><\/div><div class='wti-clear'><\/div>","protected":false},"excerpt":{"rendered":"<p>In this article, we will deal a very common situation where the DBA is tasked to rename or clone a user into the same database. In the following lines, I will explain how to make this copy without higher complexities and with no need to generate intermediate dump files, using DataPump import utility with a &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"https:\/\/dev.dbarj.com.br\/en\/2014\/11\/rename-schema-oracle-11g-loopback-dblink\/\">Continue reading<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"class_list":["post-1062","post","type-post","status-publish","format-standard","hentry","category-database-en","item-wrap"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Rename schema in Oracle 11g with Loopback DBLink - DBA - Rodrigo Jorge - Oracle Tips and Guides<\/title>\n<meta name=\"description\" content=\"How to quickly rename a user in Oracle 11g through DBLink Loopback\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/dev.dbarj.com.br\/en\/2014\/11\/rename-schema-oracle-11g-loopback-dblink\/\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DBA RJ\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/dev.dbarj.com.br\\\/en\\\/2014\\\/11\\\/rename-schema-oracle-11g-loopback-dblink\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/dev.dbarj.com.br\\\/en\\\/2014\\\/11\\\/rename-schema-oracle-11g-loopback-dblink\\\/\"},\"author\":{\"name\":\"DBA RJ\",\"@id\":\"https:\\\/\\\/dev.dbarj.com.br\\\/en\\\/#\\\/schema\\\/person\\\/28a44ca3a6633fe4156ad1ea209d40a9\"},\"headline\":\"Rename schema in Oracle 11g with Loopback DBLink\",\"datePublished\":\"2014-11-07T17:58:06+00:00\",\"dateModified\":\"2014-11-10T18:02:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/dev.dbarj.com.br\\\/en\\\/2014\\\/11\\\/rename-schema-oracle-11g-loopback-dblink\\\/\"},\"wordCount\":443,\"commentCount\":8,\"publisher\":{\"@id\":\"https:\\\/\\\/dev.dbarj.com.br\\\/en\\\/#\\\/schema\\\/person\\\/28a44ca3a6633fe4156ad1ea209d40a9\"},\"articleSection\":[\"Oracle Database General\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/dev.dbarj.com.br\\\/en\\\/2014\\\/11\\\/rename-schema-oracle-11g-loopback-dblink\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/dev.dbarj.com.br\\\/en\\\/2014\\\/11\\\/rename-schema-oracle-11g-loopback-dblink\\\/\",\"url\":\"https:\\\/\\\/dev.dbarj.com.br\\\/en\\\/2014\\\/11\\\/rename-schema-oracle-11g-loopback-dblink\\\/\",\"name\":\"Rename schema in Oracle 11g with Loopback DBLink - DBA - Rodrigo Jorge - Oracle Tips and Guides\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/dev.dbarj.com.br\\\/en\\\/#website\"},\"datePublished\":\"2014-11-07T17:58:06+00:00\",\"dateModified\":\"2014-11-10T18:02:17+00:00\",\"description\":\"How to quickly rename a user in Oracle 11g through DBLink Loopback\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/dev.dbarj.com.br\\\/en\\\/2014\\\/11\\\/rename-schema-oracle-11g-loopback-dblink\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/dev.dbarj.com.br\\\/en\\\/2014\\\/11\\\/rename-schema-oracle-11g-loopback-dblink\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/dev.dbarj.com.br\\\/en\\\/2014\\\/11\\\/rename-schema-oracle-11g-loopback-dblink\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/dev.dbarj.com.br\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Rename schema in Oracle 11g with Loopback DBLink\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/dev.dbarj.com.br\\\/en\\\/#website\",\"url\":\"https:\\\/\\\/dev.dbarj.com.br\\\/en\\\/\",\"name\":\"DBA - Rodrigo Jorge - Oracle Tips and Guides\",\"description\":\"Blog about Databases, Security and High Availability\",\"publisher\":{\"@id\":\"https:\\\/\\\/dev.dbarj.com.br\\\/en\\\/#\\\/schema\\\/person\\\/28a44ca3a6633fe4156ad1ea209d40a9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/dev.dbarj.com.br\\\/en\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/dev.dbarj.com.br\\\/en\\\/#\\\/schema\\\/person\\\/28a44ca3a6633fe4156ad1ea209d40a9\",\"name\":\"DBA RJ\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/dev.dbarj.com.br\\\/wp-content\\\/uploads\\\/2019\\\/09\\\/RodrigoJorgePOUG19.png\",\"url\":\"https:\\\/\\\/dev.dbarj.com.br\\\/wp-content\\\/uploads\\\/2019\\\/09\\\/RodrigoJorgePOUG19.png\",\"contentUrl\":\"https:\\\/\\\/dev.dbarj.com.br\\\/wp-content\\\/uploads\\\/2019\\\/09\\\/RodrigoJorgePOUG19.png\",\"width\":712,\"height\":712,\"caption\":\"DBA RJ\"},\"logo\":{\"@id\":\"https:\\\/\\\/dev.dbarj.com.br\\\/wp-content\\\/uploads\\\/2019\\\/09\\\/RodrigoJorgePOUG19.png\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Rename schema in Oracle 11g with Loopback DBLink - DBA - Rodrigo Jorge - Oracle Tips and Guides","description":"How to quickly rename a user in Oracle 11g through DBLink Loopback","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/dev.dbarj.com.br\/en\/2014\/11\/rename-schema-oracle-11g-loopback-dblink\/","twitter_misc":{"Written by":"DBA RJ","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/dev.dbarj.com.br\/en\/2014\/11\/rename-schema-oracle-11g-loopback-dblink\/#article","isPartOf":{"@id":"https:\/\/dev.dbarj.com.br\/en\/2014\/11\/rename-schema-oracle-11g-loopback-dblink\/"},"author":{"name":"DBA RJ","@id":"https:\/\/dev.dbarj.com.br\/en\/#\/schema\/person\/28a44ca3a6633fe4156ad1ea209d40a9"},"headline":"Rename schema in Oracle 11g with Loopback DBLink","datePublished":"2014-11-07T17:58:06+00:00","dateModified":"2014-11-10T18:02:17+00:00","mainEntityOfPage":{"@id":"https:\/\/dev.dbarj.com.br\/en\/2014\/11\/rename-schema-oracle-11g-loopback-dblink\/"},"wordCount":443,"commentCount":8,"publisher":{"@id":"https:\/\/dev.dbarj.com.br\/en\/#\/schema\/person\/28a44ca3a6633fe4156ad1ea209d40a9"},"articleSection":["Oracle Database General"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/dev.dbarj.com.br\/en\/2014\/11\/rename-schema-oracle-11g-loopback-dblink\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/dev.dbarj.com.br\/en\/2014\/11\/rename-schema-oracle-11g-loopback-dblink\/","url":"https:\/\/dev.dbarj.com.br\/en\/2014\/11\/rename-schema-oracle-11g-loopback-dblink\/","name":"Rename schema in Oracle 11g with Loopback DBLink - DBA - Rodrigo Jorge - Oracle Tips and Guides","isPartOf":{"@id":"https:\/\/dev.dbarj.com.br\/en\/#website"},"datePublished":"2014-11-07T17:58:06+00:00","dateModified":"2014-11-10T18:02:17+00:00","description":"How to quickly rename a user in Oracle 11g through DBLink Loopback","breadcrumb":{"@id":"https:\/\/dev.dbarj.com.br\/en\/2014\/11\/rename-schema-oracle-11g-loopback-dblink\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/dev.dbarj.com.br\/en\/2014\/11\/rename-schema-oracle-11g-loopback-dblink\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/dev.dbarj.com.br\/en\/2014\/11\/rename-schema-oracle-11g-loopback-dblink\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/dev.dbarj.com.br\/en\/"},{"@type":"ListItem","position":2,"name":"Rename schema in Oracle 11g with Loopback DBLink"}]},{"@type":"WebSite","@id":"https:\/\/dev.dbarj.com.br\/en\/#website","url":"https:\/\/dev.dbarj.com.br\/en\/","name":"DBA - Rodrigo Jorge - Oracle Tips and Guides","description":"Blog about Databases, Security and High Availability","publisher":{"@id":"https:\/\/dev.dbarj.com.br\/en\/#\/schema\/person\/28a44ca3a6633fe4156ad1ea209d40a9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/dev.dbarj.com.br\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/dev.dbarj.com.br\/en\/#\/schema\/person\/28a44ca3a6633fe4156ad1ea209d40a9","name":"DBA RJ","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/dev.dbarj.com.br\/wp-content\/uploads\/2019\/09\/RodrigoJorgePOUG19.png","url":"https:\/\/dev.dbarj.com.br\/wp-content\/uploads\/2019\/09\/RodrigoJorgePOUG19.png","contentUrl":"https:\/\/dev.dbarj.com.br\/wp-content\/uploads\/2019\/09\/RodrigoJorgePOUG19.png","width":712,"height":712,"caption":"DBA RJ"},"logo":{"@id":"https:\/\/dev.dbarj.com.br\/wp-content\/uploads\/2019\/09\/RodrigoJorgePOUG19.png"}}]}},"_links":{"self":[{"href":"https:\/\/dev.dbarj.com.br\/en\/wp-json\/wp\/v2\/posts\/1062","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.dbarj.com.br\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.dbarj.com.br\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.dbarj.com.br\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.dbarj.com.br\/en\/wp-json\/wp\/v2\/comments?post=1062"}],"version-history":[{"count":0,"href":"https:\/\/dev.dbarj.com.br\/en\/wp-json\/wp\/v2\/posts\/1062\/revisions"}],"wp:attachment":[{"href":"https:\/\/dev.dbarj.com.br\/en\/wp-json\/wp\/v2\/media?parent=1062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.dbarj.com.br\/en\/wp-json\/wp\/v2\/categories?post=1062"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.dbarj.com.br\/en\/wp-json\/wp\/v2\/tags?post=1062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}