Skip to Main Content
  • Questions
  • Import db dump to production existing schema

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Gabriel.

Asked: January 09, 2019 - 9:31 pm UTC

Last updated: January 10, 2019 - 7:41 am UTC

Version: 12

Viewed 10K+ times! This question is

You Asked

Hi Experts,

Is it possible to import a db backup dump, into an existing production schema with data, without loosing the existing information? will that generate tons of duplicates?

Ie

Backup (dev) Current Production

Test back up Test Prod
------------------------- -------------------------
info1757jan info1757jan2
info1757jan2 PROD7857jan2
info1757jan3 PROD7857jan3
info1 PRODCANXAAS
info1_06OLD_DLYD info1_06OLD_DLYD


should i modify the dump first?

We are using Oracle 12

Thank you very much.

Gabriel.

and Connor said...

You have degree of flexibility on what you can do here. First a couple of tables in a schema, one with a primary key and then we'll export the schema

SQL> create user demo identified by demo;

User created.

SQL> alter user demo quota 500m on users;

User altered.

SQL>
SQL> create table demo.t1 as select * from dba_objects where object_id is not null;

Table created.

SQL> create table demo.t2 as select * from demo.t1;

Table created.

SQL> alter table demo.t2 add primary key ( object_id );

Table altered.


C:\oracle\ords181>expdp system/admin directory=TEMP schemas=demo dumpfile=demo.dmp

Export: Release 12.2.0.1.0 - Production on Thu Jan 10 15:36:19 2019

Copyright (c) 1982, 2018, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
Starting "SYSTEM"."SYS_EXPORT_SCHEMA_01":  system/******** directory=TEMP schemas=demo dumpfile=demo.dmp
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/STATISTICS/MARKER
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
. . exported "DEMO"."T1"                                 10.67 MB   83574 rows
. . exported "DEMO"."T2"                                 10.67 MB   83574 rows
Master table "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:
  C:\TEMP\DEMO.DMP
Job "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully completed at Thu Jan 10 15:36:38 2019 elapsed 0 00:00:19


By default, an import will skip (totally) anything that exists already


C:\oracle\ords181>impdp system/admin directory=TEMP schemas=demo dumpfile=demo.dmp

Import: Release 12.2.0.1.0 - Production on Thu Jan 10 15:36:57 2019

Copyright (c) 1982, 2018, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
Master table "SYSTEM"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_SCHEMA_01":  system/******** directory=TEMP schemas=demo dumpfile=demo.dmp
Processing object type SCHEMA_EXPORT/USER
ORA-31684: Object type USER:"DEMO" already exists

Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
ORA-39151: Table "DEMO"."T1" exists. All dependent metadata and data will be skipped due to table_exists_action of skip

ORA-39151: Table "DEMO"."T2" exists. All dependent metadata and data will be skipped due to table_exists_action of skip

Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/STATISTICS/MARKER
Job "SYSTEM"."SYS_IMPORT_SCHEMA_01" completed with 3 error(s) at Thu Jan 10 15:37:00 2019 elapsed 0 00:00:02


You can see that the tables are left unchanged


SQL> select count(*) from demo.t1;

  COUNT(*)
----------
     83574

SQL> select count(*) from demo.t2;

  COUNT(*)
----------
     83574
<code>

I can control that using the table_exists_action parameter. In this case, I'm going to say append the data

<code>
     
C:\oracle\ords181>impdp system/admin directory=TEMP schemas=demo dumpfile=demo.dmp table_exists_action=append

Import: Release 12.2.0.1.0 - Production on Thu Jan 10 15:38:03 2019

Copyright (c) 1982, 2018, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
Master table "SYSTEM"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_SCHEMA_01":  system/******** directory=TEMP schemas=demo dumpfile=demo.dmp table_exists_action=append
Processing object type SCHEMA_EXPORT/USER
ORA-31684: Object type USER:"DEMO" already exists

Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Table "DEMO"."T1" exists. Data will be appended to existing table but all dependent metadata will be skipped due to table_exists_action of append
Table "DEMO"."T2" exists. Data will be appended to existing table but all dependent metadata will be skipped due to table_exists_action of append
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "DEMO"."T1"                                 10.67 MB   83574 rows
ORA-31693: Table data object "DEMO"."T2" failed to load/unload and is being skipped due to error:
ORA-00001: unique constraint (DEMO.SYS_C0049482) violated

Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/STATISTICS/MARKER
Job "SYSTEM"."SYS_IMPORT_SCHEMA_01" completed with 2 error(s) at Thu Jan 10 15:38:08 2019 elapsed 0 00:00:04


If we look at the tables now, you can see we doubled up the rows in T1 but we could not in T2, because to do so would have violated the primary key


SQL> select count(*) from demo.t1;

  COUNT(*)
----------
    167148

SQL> select count(*) from demo.t2;

  COUNT(*)
----------
     83574
     



Is this answer out of date? If it is, please let us know via a Comment

More to Explore

Utilities

All of the database utilities are explained in the Utilities guide.