[英]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. 我们必须在dev中复制相同的场景并找到解决方案。 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. 所以我试图找到一种方法来从生产中选择单个用户数据并将其插入到dev区域。
We just have Java and Oracle. 我们只有Java和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.
2.在生产中使用这组选择,以便获得一组插入语句作为输出。
3. Use the insert statements in dev.
3.在dev中使用insert语句。
Problem:- The select queries are becoming huge. 问题: -选择查询变得越来越大。 Around 25 MB in total :( We cannot even execute that big query in production. 总共约25 MB :(我们甚至无法在生产中执行那个大问题。
Could you suggest any better approach for this usecase? 你能为这个用例建议更好的方法吗? Does oracle itself allow selective data exports? oracle本身是否允许选择性数据导出? Or any other way I should write my java code? 或者我应该编写我的java代码的任何其他方式?
我们使用这样的东西将记录从一个数据库移动到另一个数据库:
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. 使用数据泵移动所需表格的数据,并使用您想要的whereclause。 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. 如果两个DB都是Oracle,则可以在本地数据库中为远程数据库创建DBLINK,并在本地数据库中创建一个使用DBLINK查询来自远程数据库的所有数据的作业,并更新本地数据库中的表。 Or there are plenty of data migration API are availabe you can give a try to one of them. 或者有大量的数据迁移API可用,你可以尝试其中一个。
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://code.google.com/p/c5-db-migration/
http://flywaydb.org/documentation/migration/java.html http://flywaydb.org/documentation/migration/java.html
http://migrate4j.sourceforge.net/ http://migrate4j.sourceforge.net/
http://flywaydb.org/ --- its better to use http://flywaydb.org/ ---它更好用
http://www.operatornew.com/2012/11/automatic-db-migration-for-java-web.html http://www.operatornew.com/2012/11/automatic-db-migration-for-java-web.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.