Are expdp/impdp commands appropriate for daily schema sync?
-
29-09-2020 - |
Question
I've done following comands:
expdp system/password@localdb ^
schemas=SCH directory=dumps_dir dumpfile=SCH_%date%.dmp logfile=expdpSCH_%date%.log
It runs great, without errors. But when I use command:
impdp system/password@localdb ^
schemas=SCH directory=dumps_dir dumpfile=SCH_%date%.dmp logfile=impdpSCH_%date%.log
It gave me bunch of errors that tables, sequences and other stuff already exist. So I have a question, could I use such an approach or it's wrong and I should use something else?
Solution
Check the documentation for more information or type impdp help=y
. There is a parameter (TABLE_EXISTS_ACTION) that defines if you want to overwrite existing objects or if you want to append.
TABLE_EXISTS_ACTION
Action to take if imported object already exists.
Valid keywords are: APPEND, REPLACE, [SKIP] and TRUNCATE.
OTHER TIPS
No, that is not a possible way:
- Most of the non-table objects will already exist in your schema. You already get such error messages. The import will not overwrite it.
- You can configure how export should work if a table already exists but if there is a table that s referenced by another table then TRUNCATE and REPLACE will not work.
- Even if there is no foreign key reference to a table indexes will slow down the import dramatically
- A lot of other problems may occur (concerning triggers, partitions, references to other tables and maybe more)
So the only reasonable way to synchronize the schema using expdp/impdp is to drop the schema before you import.
If you don't want to drop the schema for some reason but replace the data of the tables a lot of additional operations are necessary.