简体   繁体   中英

How to copy selective data from one database to another (ORACLE)

We have a need to find a way to copy certain data from production into our dev regions so that we can debug/fix any issue. Sometimes single user related data gets impacted. We have to replicate the same scenario in dev and find a solution. Presently we follow two approaches:-

 1. Check the audit history and try to recreate the similar scenario
    in  dev. <50% sucess rate in recreating the exact same scenario.
 2. Restore+Encrypt the "whole" production into dev and then continue
    on  the work. It is an overkill if issue impacts only a single user.

So I am trying to find a way to just select a single user data from production and insert it into dev region.

We just have Java and Oracle. Can't use any external tools. Because we dont have license and cannot download freeware due to security issues.

I tried the follwing:-

  1. Write a java code which will query the informaition schema tables to find the relationships between the tables and create select statements like below:-

select 'insert into TABLE1(C1,C2,C3,C4) values ('||''''||C1||''''||','||coalesce(to_char(C2),'null')||','||''''||C3||''''||','||coalesce(to_char(C4),'null'));'
from TABLE1 where ID='1006' union all 
select 'insert into TABLE2(C1,C2,C3,C4) values ('||''''||C1||''''||','||coalesce(to_char(C2),'null')||','||''''||C3||''''||','||coalesce(to_char(C4),'null'));'
from TABLE2 WHERE TABLE1ID in ( select ID FROM TABLE1 where ID='1006') union all 
select 'insert into TABLE3(C1,C2,C3,C4) values ('||''''||C1||''''||','||coalesce(to_char(C2),'null')||','||''''||C3||''''||','||coalesce(to_char(C4),'null'));'
from TABLE3 WHERE TABLE2ID in ( select ID FROM TABLE2 WHERE TABLE1ID in ( select ID FROM TABLE1 where ID='1006'));
2. Use this set of selects in production, so that you get a set of insert statements as output. 3. Use the insert statements in dev.

Problem:- The select queries are becoming huge. Around 25 MB in total :( We cannot even execute that big query in production.

Could you suggest any better approach for this usecase? Does oracle itself allow selective data exports? Or any other way I should write my java code?

我们使用这样的东西将记录从一个数据库移动到另一个数据库:

copy from username/password@database1 to username/password@database2 insert target_table using select * from source_table where where_clause_goes_here;

Use datapump to move data for the tables you need and with the whereclause you want. Straight forward and standard functionality of the database.

If both the DBs are Oracle, you can create a DBLINK in your local database for the remote DB and Create a job in your local DB that queries all the data from remote DB using the DBLINK, and update the tables in your local database. Or there are plenty of data migration API are availabe you can give a try to one of them.

Below are the some link,have a look in to them,may be it will solve your problem

http://code.google.com/p/c5-db-migration/

http://flywaydb.org/documentation/migration/java.html

http://migrate4j.sourceforge.net/

http://flywaydb.org/ --- its better to use

http://www.operatornew.com/2012/11/automatic-db-migration-for-java-web.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM