Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server Spring批处理SQL合并花费的时间太长_Sql Server_Spring_Oracle_Spring Boot_Spring Batch - Fatal编程技术网

Sql server Spring批处理SQL合并花费的时间太长

Sql server Spring批处理SQL合并花费的时间太长,sql-server,spring,oracle,spring-boot,spring-batch,Sql Server,Spring,Oracle,Spring Boot,Spring Batch,我正在尝试将数据从Oracle迁移到SQLServer数据库。我目前正在使用JDBCCursorItemReader读取Oracle数据,然后使用JDBCBatchItemWriter将数据写入SQLserver 我的问题是,这花的时间太长了。对于一个大约200000行的表,这几乎需要一个小时(我必须运行其中四个查询,每个查询大约200K行) @Bean 公共JdbcCursorItemReader dataReader()引发异常、ParseException、UnexpectedInputE

我正在尝试将数据从Oracle迁移到SQLServer数据库。我目前正在使用JDBCCursorItemReader读取Oracle数据,然后使用JDBCBatchItemWriter将数据写入SQLserver

我的问题是,这花的时间太长了。对于一个大约200000行的表,这几乎需要一个小时(我必须运行其中四个查询,每个查询大约200K行)

@Bean
公共JdbcCursorItemReader dataReader()引发异常、ParseException、UnexpectedInputException{
final JdbcCursorItemReader dataReader=新JdbcCursorItemReader();
setDataSource(oracleDataSource);
dataReader.setSql(Constants.DATA_QUERY);
setRowMapper(新的BeanPropertyRowMapper(DataPOJO.class));
返回数据读取器;
}
@豆子
public JdbcBatchItemWriter dataWriter()引发意外的PutException、ParseException、Exception{
JdbcBatchItemWriter dataWriter=新的JdbcBatchItemWriter();
setItemSqlParameterSourceProvider(新的BeanPropertyItemSqlParameterSourceProvider());
dataWriter.setSql(Constants.DATA_MERGE);
dataWriter.setDataSource(mssDataSource);
返回数据编写器;
}
有没有人有任何提高这类工作绩效的建议

有没有人有任何提高这类工作绩效的建议

我会以这种方式接近

1.查看我正在运行的进程的等待统计信息

select * from sys.dm_exec_requests where session_id=<< your session id>>

2.根据等待类型进行故障排除。

我会首先将您的记录插入源表(我个人会使用临时表),然后利用
MERGE
命令将记录从该“源”表推送到“目标”表中

两个关键性能问题:

  • 确保与目标表上的索引键匹配
  • 假设要更新匹配的行,请不要在
    update
    语句中更新索引列
  • 将提交间隔设置得相当高。您的数据库应该能够合并1000行而不必担心。过于频繁地提交将增加大量开销

现在要用SpringBatch完成这一点,您可能需要一个复合的
ItemWriter
(一个随框架一起提供)。委托编写器1将是您已经在使用的
JdbcBatchItemWriter
,并将插入到该源表中。委托编写器2是自定义的,只需执行
MERGE
命令。

这看起来肯定是数据库问题。如果直接在sql/db浏览器中运行Select查询,则返回该查询需要多长时间?此外,您是否已将自动提交设置为false?您的步骤的承诺是什么?一般来说,您应该能够每秒读写数千个条目。
select * from sys.dm_exec_requests where session_id=<< your session id>>
select spid,waittime,lastwaittype,status
hostname,     --below three columns help you identify your query/spid,
 program_name,--- you can replace spid in above query to get live status
nt_username
 from sys.sysprocesses