Reputation: 3649
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:-
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?
Upvotes: 8
Views: 3616
Reputation: 1011
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
Upvotes: 0
Reputation: 197
Use datapump to move data for the tables you need and with the whereclause you want. Straight forward and standard functionality of the database.
Upvotes: 5
Reputation: 2596
We use something like this to move records from one database to another:
copy from username/password@database1 to username/password@database2 insert target_table using select * from source_table where where_clause_goes_here;
Upvotes: 5