Backend/Spring+Boot

[SpringBatch] SpringBatch 이력테이블 초기화 스크립트

findmypiece 2022. 3. 29. 21:09
728x90

1개월 이전 이력 삭제.

자세한 설명은 생략한다.

DELIMITER $$

DELETE 
FROM BATCH_STEP_EXECUTION_CONTEXT 
WHERE STEP_EXECUTION_ID IN (
	SELECT STEP_EXECUTION_ID 
	FROM BATCH_STEP_EXECUTION
	where JOB_EXECUTION_ID in(
		select JOB_EXECUTION_ID 
		from BATCH_JOB_EXECUTION
		where CREATE_TIME < DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH)
	)
); 

DELETE 
FROM BATCH_STEP_EXECUTION
where JOB_EXECUTION_ID in(
	select JOB_EXECUTION_ID 
	from BATCH_JOB_EXECUTION
	where CREATE_TIME < DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH)
);

DELETE 
FROM BATCH_JOB_EXECUTION_CONTEXT 
WHERE JOB_EXECUTION_ID in  (
	select JOB_EXECUTION_ID 
	from BATCH_JOB_EXECUTION
	where CREATE_TIME < DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH)
);

DELETE 
FROM BATCH_JOB_EXECUTION_PARAMS 
WHERE JOB_EXECUTION_ID in  (
	select JOB_EXECUTION_ID 
	from BATCH_JOB_EXECUTION
	where CREATE_TIME < DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH)
);

DELETE 
FROM BATCH_JOB_EXECUTION 
where CREATE_TIME < DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH);

DELETE 
FROM BATCH_JOB_INSTANCE 
WHERE JOB_INSTANCE_ID IN (
	select JOB_INSTANCE_ID 
	from BATCH_JOB_EXECUTION
	where CREATE_TIME < DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH)
);

DELIMITER ;
728x90

'Backend > Spring+Boot' 카테고리의 다른 글

spring-boot-maven-plugin 디버깅 하기  (0) 2022.05.31
WebClient SSL 설정  (0) 2022.04.19
@PathVariable vs @RequestParam  (0) 2022.03.07
[SpringBatch] 주의사항  (0) 2022.02.28
SpringBoot 환경에서 JAVA_OPTS, TOMCAT_OPTS  (0) 2022.02.22