In some cases, it may be desirable to make a copy of an existing schema or to transfer a schema from one database to another. In this case we can use the Remap Schema property.
We can use the REMAP SCHEMA feature for two different jobs.
-We can move an existing schema to another database with the same schema name.
-We can create a copy of an existing schema with a different schema name.
1. First, let’s apply the first scenario.
Let’s check if there is “OE” schema (database name: catalog).
1 2 3 | SQL> select * from dba_users where username='OE'; no rows selected |
Let’s “export” from the database where the “OE” schema is (database name: cc).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | $ expdp directory=expimp_dump schemas=OE dumpfile=oe.dmp logfile=oe.log; Export: Release 11.2.0.4.0 - Production on Mon Nov 3 16:52:33 2014 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. Username: sys as sysdba Password: Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Oracle Label Security, OLAP, Data Mining, Oracle Database Vault and Real Application Testing options Starting "SYS"."SYS_EXPORT_SCHEMA_01": sys/******** AS SYSDBA directory=expimp_dump schemas=OE dumpfile=oe.dmp logfile=oe.log Estimate in progress using BLOCKS method... Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA Total estimation using BLOCKS method: 4.687 MB Processing object type SCHEMA_EXPORT/USER Processing object type SCHEMA_EXPORT/SYSTEM_GRANT Processing object type SCHEMA_EXPORT/ROLE_GRANT Processing object type SCHEMA_EXPORT/DEFAULT_ROLE Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA Processing object type SCHEMA_EXPORT/SYNONYM/SYNONYM Processing object type SCHEMA_EXPORT/TYPE/INC_TYPE Processing object type SCHEMA_EXPORT/TYPE/TYPE_SPEC Processing object type SCHEMA_EXPORT/TYPE/GRANT/OWNER_GRANT/OBJECT_GRANT Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE Processing object type SCHEMA_EXPORT/XMLSCHEMA/XMLSCHEMA Processing object type SCHEMA_EXPORT/TABLE/TABLE Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT Processing object type SCHEMA_EXPORT/TABLE/COMMENT Processing object type SCHEMA_EXPORT/FUNCTION/FUNCTION Processing object type SCHEMA_EXPORT/FUNCTION/ALTER_FUNCTION Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX Processing object type SCHEMA_EXPORT/TABLE/INDEX/FUNCTIONAL_INDEX/INDEX Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/FUNCTIONAL_INDEX/INDEX_STATISTICS Processing object type SCHEMA_EXPORT/VIEW/VIEW Processing object type SCHEMA_EXPORT/VIEW/GRANT/OWNER_GRANT/OBJECT_GRANT Processing object type SCHEMA_EXPORT/TYPE/TYPE_BODY Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT Processing object type SCHEMA_EXPORT/TABLE/TRIGGER Processing object type SCHEMA_EXPORT/VIEW/TRIGGER Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS . . exported "OE"."PRODUCT_DESCRIPTIONS" 2.379 MB 8640 rows . . exported "OE"."PURCHASEORDER" 243.9 KB 132 rows . . exported "OE"."WAREHOUSES" 12.45 KB 9 rows . . exported "OE"."CUSTOMERS" 77.96 KB 319 rows . . exported "OE"."PRODUCT_INFORMATION" 72.77 KB 288 rows . . exported "OE"."PRODUCT_REF_LIST_NESTEDTAB" 12.51 KB 288 rows . . exported "OE"."SUBCATEGORY_REF_LIST_NESTEDTAB" 6.585 KB 21 rows . . exported "OE"."CATEGORIES_TAB" 14.15 KB 22 rows . . exported "OE"."INVENTORIES" 21.67 KB 1112 rows . . exported "OE"."ORDERS" 12.39 KB 105 rows . . exported "OE"."ORDER_ITEMS" 20.88 KB 665 rows . . exported "OE"."PROMOTIONS" 5.5 KB 2 rows Master table "SYS"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded ****************************************************************************** Dump file set for SYS.SYS_EXPORT_SCHEMA_01 is: /u01/app/oracle/admin/cc/expimp_dir/oe.dmp Job "SYS"."SYS_EXPORT_SCHEMA_01" successfully completed at Mon Nov 3 16:53:40 2014 elapsed 0 00:00:53 |
Let’s transfer the “dump files” obtained from the “export” result to the database server where we will import (database name: cc).
1 2 3 4 | $ scp /u01/app/oracle/admin/cc/expimp_dir/oe.dmp oracle@172.20.31.232:/u01/app/oracle/admin/catalog/dpdump/ oracle@172.20.31.232's password: oe.dmp 100% 3656KB 3.6MB/s 00:00 |
Now we can perform the “import” operation (database name: catalog).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | $ impdp directory=data_pump_dir remap_schema=OE:OE dumpfile=oe.dmp logfile=oe.log Import: Release 11.2.0.1.0 - Production on Mon Nov 3 16:48:47 2014 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. Username: sys as sysdba Password: Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options Master table "SYS"."SYS_IMPORT_FULL_01" successfully loaded/unloaded Starting "SYS"."SYS_IMPORT_FULL_01": sys/******** AS SYSDBA directory=data_pump_dir remap_schema=OE:OE dumpfile=oe.dmp logfile=oe.log Processing object type SCHEMA_EXPORT/USER Processing object type SCHEMA_EXPORT/SYSTEM_GRANT Processing object type SCHEMA_EXPORT/ROLE_GRANT Processing object type SCHEMA_EXPORT/DEFAULT_ROLE Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA Processing object type SCHEMA_EXPORT/SYNONYM/SYNONYM Processing object type SCHEMA_EXPORT/TYPE/INC_TYPE Processing object type SCHEMA_EXPORT/TYPE/TYPE_SPEC Processing object type SCHEMA_EXPORT/TYPE/GRANT/OWNER_GRANT/OBJECT_GRANT Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE Processing object type SCHEMA_EXPORT/XMLSCHEMA/XMLSCHEMA Processing object type SCHEMA_EXPORT/TABLE/TABLE Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA . . imported "OE"."PRODUCT_DESCRIPTIONS" 2.379 MB 8640 rows . . imported "OE"."PURCHASEORDER" 243.9 KB 132 rows . . imported "OE"."WAREHOUSES" 12.45 KB 9 rows . . imported "OE"."CUSTOMERS" 77.96 KB 319 rows . . imported "OE"."PRODUCT_INFORMATION" 72.77 KB 288 rows . . imported "OE"."PRODUCT_REF_LIST_NESTEDTAB" 12.51 KB 288 rows . . imported "OE"."SUBCATEGORY_REF_LIST_NESTEDTAB" 6.585 KB 21 rows . . imported "OE"."CATEGORIES_TAB" 14.15 KB 22 rows . . imported "OE"."INVENTORIES" 21.67 KB 1112 rows . . imported "OE"."ORDERS" 12.39 KB 105 rows . . imported "OE"."ORDER_ITEMS" 20.88 KB 665 rows . . imported "OE"."PROMOTIONS" 5.5 KB 2 rows Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT Processing object type SCHEMA_EXPORT/TABLE/COMMENT Processing object type SCHEMA_EXPORT/FUNCTION/FUNCTION Processing object type SCHEMA_EXPORT/FUNCTION/ALTER_FUNCTION Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX Processing object type SCHEMA_EXPORT/TABLE/INDEX/FUNCTIONAL_INDEX/INDEX Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS ORA-39083: Object type INDEX_STATISTICS failed to create with error: ORA-20000: INDEX "OE"."LINEITEM_TABLE_MEMBERS" does not exist or insufficient privileges Failing sql is: DECLARE I_N VARCHAR2(60); I_O VARCHAR2(60); c DBMS_METADATA.T_VAR_COLL; df varchar2(21) := 'YYYY-MM-DD:HH24:MI:SS'; BEGIN DELETE FROM "SYS"."IMPDP_STATS"; i_n := 'LINEITEM_TABLE_MEMBERS'; i_o := 'OE'; INSERT INTO "SYS"."IMPDP_STATS" (type,version,flags,c1,c2,c3,c5,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,d1,cl1) VALUES ('I' ORA-39083: Object type INDEX_STATISTICS failed to create with error: ORA-20000: INDEX "OE"."ACTION_TABLE_MEMBERS" does not exist or insufficient privileges Failing sql is: DECLARE I_N VARCHAR2(60); I_O VARCHAR2(60); c DBMS_METADATA.T_VAR_COLL; df varchar2(21) := 'YYYY-MM-DD:HH24:MI:SS'; BEGIN DELETE FROM "SYS"."IMPDP_STATS"; i_n := 'ACTION_TABLE_MEMBERS'; i_o := 'OE'; INSERT INTO "SYS"."IMPDP_STATS" (type,version,flags,c1,c2,c3,c5,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,d1,cl1) VALUES ('I',5,2 Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/FUNCTIONAL_INDEX/INDEX_STATISTICS Processing object type SCHEMA_EXPORT/VIEW/VIEW Processing object type SCHEMA_EXPORT/VIEW/GRANT/OWNER_GRANT/OBJECT_GRANT Processing object type SCHEMA_EXPORT/TYPE/TYPE_BODY ORA-39082: Object type VIEW:"OE"."ACCOUNT_MANAGERS" created with compilation warnings ORA-39082: Object type VIEW:"OE"."CUSTOMERS_VIEW" created with compilation warnings Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT ORA-39083: Object type REF_CONSTRAINT failed to create with error: ORA-00942: table or view does not exist Failing sql is: ALTER TABLE "OE"."ORDERS" ADD CONSTRAINT "ORDERS_SALES_REP_FK" FOREIGN KEY ("SALES_REP_ID") REFERENCES "HR"."EMPLOYEES" ("EMPLOYEE_ID") ON DELETE SET NULL ENABLE ORA-39083: Object type REF_CONSTRAINT failed to create with error: ORA-00942: table or view does not exist Failing sql is: ALTER TABLE "OE"."WAREHOUSES" ADD CONSTRAINT "WAREHOUSES_LOCATION_FK" FOREIGN KEY ("LOCATION_ID") REFERENCES "HR"."LOCATIONS" ("LOCATION_ID") ON DELETE SET NULL ENABLE ORA-39083: Object type REF_CONSTRAINT failed to create with error: ORA-00942: table or view does not exist Failing sql is: ALTER TABLE "OE"."CUSTOMERS" ADD CONSTRAINT "CUSTOMERS_ACCOUNT_MANAGER_FK" FOREIGN KEY ("ACCOUNT_MGR_ID") REFERENCES "HR"."EMPLOYEES" ("EMPLOYEE_ID") ON DELETE SET NULL ENABLE Processing object type SCHEMA_EXPORT/TABLE/TRIGGER Processing object type SCHEMA_EXPORT/VIEW/TRIGGER Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS Job "SYS"."SYS_IMPORT_FULL_01" completed with 7 error(s) at 16:49:25 |
2. Let’s apply the second scenario.
First, let’s check the tables under the schema we want to transfer.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | SQL> select table_name, owner from dba_tables where owner='EMRAH'; TABLE_NAME OWNER ------------------------------ ------------------------------ ORDERS EMRAH ORDER_ITEMS EMRAH PRODUCT_DESCRIPTIONS EMRAH PROMOTIONS EMRAH PRODUCT_INFORMATION EMRAH INVENTORIES EMRAH WAREHOUSES EMRAH YERLER EMRAH DEPARTMANLAR EMRAH PERSONEL EMRAH PERS EMRAH PERT EMRAH 12 rows selected. |
Now let’s export the schema.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | $ expdp directory=data_pump_dir schemas=EMRAH dumpfile=emrah.dmp logfile=emrah.log Export: Release 11.2.0.1.0 - Production on Mon Nov 3 17:14:13 2014 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. Username: sys as sysdba Password: Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options Starting "SYS"."SYS_EXPORT_SCHEMA_01": sys/******** AS SYSDBA directory=data_pump_dir schemas=EMRAH dumpfile=emrah.dmp logfile=emrah.log Estimate in progress using BLOCKS method... Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA Total estimation using BLOCKS method: 4 MB Processing object type SCHEMA_EXPORT/USER Processing object type SCHEMA_EXPORT/SYSTEM_GRANT Processing object type SCHEMA_EXPORT/ROLE_GRANT Processing object type SCHEMA_EXPORT/DEFAULT_ROLE Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA Processing object type SCHEMA_EXPORT/SYNONYM/SYNONYM Processing object type SCHEMA_EXPORT/DB_LINK Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE Processing object type SCHEMA_EXPORT/TABLE/TABLE Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS Processing object type SCHEMA_EXPORT/TABLE/COMMENT Processing object type SCHEMA_EXPORT/FUNCTION/FUNCTION Processing object type SCHEMA_EXPORT/FUNCTION/ALTER_FUNCTION Processing object type SCHEMA_EXPORT/VIEW/VIEW Processing object type SCHEMA_EXPORT/VIEW/GRANT/OWNER_GRANT/OBJECT_GRANT Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT Processing object type SCHEMA_EXPORT/TABLE/TRIGGER Processing object type SCHEMA_EXPORT/VIEW/TRIGGER Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS . . exported "EMRAH"."PRODUCT_DESCRIPTIONS" 2.379 MB 8640 rows . . exported "EMRAH"."WAREHOUSES" 12.46 KB 9 rows . . exported "EMRAH"."PRODUCT_INFORMATION" 72.77 KB 288 rows . . exported "EMRAH"."DEPARTMANLAR" 7.015 KB 27 rows . . exported "EMRAH"."INVENTORIES" 21.67 KB 1112 rows . . exported "EMRAH"."ORDERS" 12.39 KB 105 rows . . exported "EMRAH"."ORDER_ITEMS" 20.88 KB 665 rows . . exported "EMRAH"."PERS" 16.80 KB 107 rows . . exported "EMRAH"."PERSONEL" 16.81 KB 107 rows . . exported "EMRAH"."PERT" 5.054 KB 1 rows . . exported "EMRAH"."PROMOTIONS" 5.507 KB 2 rows . . exported "EMRAH"."YERLER" 8.273 KB 23 rows Master table "SYS"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded ****************************************************************************** Dump file set for SYS.SYS_EXPORT_SCHEMA_01 is: /u01/app/oracle/admin/catalog/dpdump/emrah.dmp Job "SYS"."SYS_EXPORT_SCHEMA_01" successfully completed at 17:15:23 |
Let’s create a new schema from our existing “EMRAH” schema. Before doing this, we do not need to create a new schema with the “create user” command.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | $ impdp directory=data_pump_dir remap_schema=EMRAH:SEZIN dumpfile=emrah.dmp logfile=emrah.log Import: Release 11.2.0.1.0 - Production on Mon Nov 3 17:18:18 2014 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. Username: sys as sysdba Password: Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options Master table "SYS"."SYS_IMPORT_FULL_01" successfully loaded/unloaded Starting "SYS"."SYS_IMPORT_FULL_01": sys/******** AS SYSDBA directory=data_pump_dir remap_schema=EMRAH:SEZIN dumpfile=emrah.dmp logfile=emrah.log Processing object type SCHEMA_EXPORT/USER Processing object type SCHEMA_EXPORT/SYSTEM_GRANT Processing object type SCHEMA_EXPORT/ROLE_GRANT Processing object type SCHEMA_EXPORT/DEFAULT_ROLE Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA Processing object type SCHEMA_EXPORT/SYNONYM/SYNONYM Processing object type SCHEMA_EXPORT/DB_LINK Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE Processing object type SCHEMA_EXPORT/TABLE/TABLE Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA . . imported "SEZIN"."PRODUCT_DESCRIPTIONS" 2.379 MB 8640 rows . . imported "SEZIN"."WAREHOUSES" 12.46 KB 9 rows . . imported "SEZIN"."PRODUCT_INFORMATION" 72.77 KB 288 rows . . imported "SEZIN"."DEPARTMANLAR" 7.015 KB 27 rows . . imported "SEZIN"."INVENTORIES" 21.67 KB 1112 rows . . imported "SEZIN"."ORDERS" 12.39 KB 105 rows . . imported "SEZIN"."ORDER_ITEMS" 20.88 KB 665 rows . . imported "SEZIN"."PERS" 16.80 KB 107 rows . . imported "SEZIN"."PERSONEL" 16.81 KB 107 rows . . imported "SEZIN"."PERT" 5.054 KB 1 rows . . imported "SEZIN"."PROMOTIONS" 5.507 KB 2 rows . . imported "SEZIN"."YERLER" 8.273 KB 23 rows Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS Processing object type SCHEMA_EXPORT/TABLE/COMMENT Processing object type SCHEMA_EXPORT/FUNCTION/FUNCTION Processing object type SCHEMA_EXPORT/VIEW/VIEW Processing object type SCHEMA_EXPORT/VIEW/GRANT/OWNER_GRANT/OBJECT_GRANT Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT Processing object type SCHEMA_EXPORT/TABLE/TRIGGER Processing object type SCHEMA_EXPORT/VIEW/TRIGGER Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS Job "SYS"."SYS_IMPORT_FULL_01" completed with 0 error(s) at 17:18:35 |
Let’s check the tables.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | SQL> select table_name from dba_tables where owner='SEZIN'; TABLE_NAME ------------------------------ PERS PERT ORDERS ORDER_ITEMS PRODUCT_DESCRIPTIONS PROMOTIONS PRODUCT_INFORMATION INVENTORIES YERLER DEPARTMANLAR PERSONEL WAREHOUSES 12 rows selected. |
“remap schema” is used to move all schema objects, not just tables.