{"id":57,"date":"2012-10-12T16:47:13","date_gmt":"2012-10-12T14:47:13","guid":{"rendered":"http:\/\/www.dolicapax.org\/?p=57"},"modified":"2012-10-19T14:09:41","modified_gmt":"2012-10-19T12:09:41","slug":"import-data-to-a-different-tablespace-using-imp","status":"publish","type":"post","link":"https:\/\/www.dolicapax.org\/?p=57","title":{"rendered":"Import data to a different tablespace using imp"},"content":{"rendered":"<p>In the old days, it was common to store objects from assorted users in the USERS tablespace. In more modern days, it sometimes seems more\u00a0appropriate\u00a0to store user objects in a tablespace dedicated to that schema.<\/p>\n<p>So, as I was transferring data to a new Oracle server, I found myself wishing to import data into a different tablespace than on the source database.<\/p>\n<p>While the\u00a0<em>impdp\u00a0<\/em>tool includes a <em>remap<\/em> option to take care of such a scenario, the traditional\u00a0<em>imp<\/em> tool does not. A workaround is to force all user objects into the default tablespace of that user, however this only works if the source tablespace does not exist.<\/p>\n<p>As an example, I have a user\u00a0<em>blog_data<\/em> on\u00a0<em>OLDDB\u00a0<\/em>with it&#8217;s objects (in this case, a single table with a single row, and the associated primary key index) stored in the <em>users<\/em> tablespace.<\/p>\n<p>I&#8217;ll export the schema using something like:<\/p>\n<blockquote><p>exp blog_data\/secret@OLDDB file=blog_data.dmp<\/p><\/blockquote>\n<p>Then on the destination database, I need to create a user with\u00a0appropriate privileges, default tablespace and make sure the USERS tablespace does not exist. Assuming this is a new installation, I can simply set a new default permanent tablespace for the database and delete the empty &#8220;USERS&#8221; tablespace:<\/p>\n<blockquote><p>CREATE TABLESPACE users2 DATAFILE SIZE 100M;<\/p>\n<p>ALTER DATABASE DEFAULT TABLESPACE users2;<\/p>\n<p>DROP TABLESPACE USERS;<\/p>\n<p>CREATE TABLESPACE blog_data DATAFILE SIZE 1M;<\/p>\n<p>CREATE USER blog_data IDENTIFIED BY secretpassword DEFAULT TABLESPACE blog_data QUOTA UNLIMITED ON blog_data;<\/p>\n<p>GRANT connect,resource TO blog_data;<\/p><\/blockquote>\n<p>Now I can simply import the schema into my new user, forcing imp to place all data in the default tablespace:<\/p>\n<blockquote><p>[oracle@oratest1 impexptest]$ imp blog_data\/secretpassword@NEWDB file=blog_data.dmp<\/p>\n<p>Import: Release 11.2.0.3.0 &#8211; Production on Fri Oct 12 23:15:44 2012<\/p>\n<p>&#8230;<\/p>\n<p>Export file created by EXPORT:V11.02.00 via conventional path<br \/>\nimport done in AL32UTF8 character set and AL16UTF16 NCHAR character set<br \/>\n. importing BLOG_DATA&#8217;s objects into BLOG_DATA<br \/>\n. . importing table &#8220;PEOPLE&#8221; 1 rows imported<br \/>\nImport terminated successfully without warnings.<\/p><\/blockquote>\n<p>The import completes without warnings, and we can then see that the table is in the right place:<\/p>\n<blockquote><p>[oracle@oratest1 impexptest]$ sqlplus &#8220;blog_data\/secretpassword&#8221;<\/p>\n<p>&#8230;<\/p>\n<p>SQL&gt; select table_name,tablespace_name from user_tables;<\/p>\n<p>TABLE_NAME TABLESPACE_NAME<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\nPEOPLE BLOG_DATA<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>In the old days, it was common to store objects from assorted users in the USERS tablespace. In more modern days, it sometimes seems more\u00a0appropriate\u00a0to store user objects in a tablespace dedicated to that schema. So, as I was transferring &hellip; <a href=\"https:\/\/www.dolicapax.org\/?p=57\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,4],"tags":[23,24],"class_list":["post-57","post","type-post","status-publish","format-standard","hentry","category-oracle","category-tech","tag-import","tag-oracle-2"],"_links":{"self":[{"href":"https:\/\/www.dolicapax.org\/index.php?rest_route=\/wp\/v2\/posts\/57","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dolicapax.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dolicapax.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dolicapax.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dolicapax.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=57"}],"version-history":[{"count":14,"href":"https:\/\/www.dolicapax.org\/index.php?rest_route=\/wp\/v2\/posts\/57\/revisions"}],"predecessor-version":[{"id":89,"href":"https:\/\/www.dolicapax.org\/index.php?rest_route=\/wp\/v2\/posts\/57\/revisions\/89"}],"wp:attachment":[{"href":"https:\/\/www.dolicapax.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=57"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dolicapax.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=57"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dolicapax.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=57"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}