Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Delete data from Spring Batch Metadata tables that are 90 days old. [BATCH-1747] #1844

Closed
spring-projects-issues opened this issue May 10, 2011 · 6 comments
Labels
in: test status: declined Features that we don't intend to implement or Bug reports that are invalid or missing enough details type: task

Comments

@spring-projects-issues
Copy link
Collaborator

Mariam opened BATCH-1747 and commented

I want to write stored procedure to delete records that are created in spring batch metadata. Can you please let me know the query to do it. I need to delete data that are 90 days old. We are using oracle as DB.


Affects: 2.1.5

@spring-projects-issues
Copy link
Collaborator Author

Mariam commented

I want to delete records from all Batch_XXX tables based on last_updated date in batch_job_execution table.

@spring-projects-issues
Copy link
Collaborator Author

Lucas Ward commented

I'm closing as won't fix, as this issue is much more appropriate to ask on the forum(it's not an issue, it's a question). However, I'm assuming you're having issues because of the foreign key constraints. You have three options:

  1. remove the constraints
  2. Delete in the correct order, such that children are deleted before parent, in the case of SB it would be:
    batch_step_execution_context
    batch_step_execution
    batch_job_execution_context
    batch_job_execution
    batch_job_params
    batch_job_instance

As long as you remove from the bottom up, it will be fine.

  1. Update the constraints to support cascading delete.

@spring-projects-issues
Copy link
Collaborator Author

Elryk commented

For all interested people, I have published on Github a tasklet that removes the Spring Batch historic:
https://github.com/arey/spring-batch...ryTasklet.java
I hope that may help

@spring-projects-issues spring-projects-issues added status: declined Features that we don't intend to implement or Bug reports that are invalid or missing enough details in: test type: task labels Dec 16, 2019
@javaHelper
Copy link

@Elryk - https://github.com/arey/spring-batch...ryTasklet.java - This link is no more active now. Could you please share us the correct link or share code to delete Spring Batch Metadata tables 30 days old.

@hmojicag
Copy link

hmojicag commented Nov 8, 2021

Spring batch metadata is actually ephemeral and data that is in COMPLETED or FAILED status seem to not be used anymore by anything, I would recommend deleting it to free up storage space, unless you actually want to keep those 90 days of historic batch processes for audit reasons.

I implemented this script which basically deletes everything that is not in use in the right order to avoid dependency problems:

DELETE FROM BATCH_STEP_EXECUTION_CONTEXT WHERE STEP_EXECUTION_ID IN (SELECT BATCH_STEP_EXECUTION.STEP_EXECUTION_ID FROM BATCH_STEP_EXECUTION WHERE JOB_EXECUTION_ID IN (SELECT JOB_EXECUTION_ID FROM BATCH_JOB_EXECUTION WHERE STATUS IN ('COMPLETED','FAILED')));
DELETE FROM BATCH_STEP_EXECUTION WHERE JOB_EXECUTION_ID IN (SELECT JOB_EXECUTION_ID FROM BATCH_JOB_EXECUTION WHERE STATUS IN ('COMPLETED','FAILED'));
DELETE FROM BATCH_JOB_EXECUTION_CONTEXT WHERE JOB_EXECUTION_ID IN (SELECT JOB_EXECUTION_ID FROM BATCH_JOB_EXECUTION WHERE STATUS IN ('COMPLETED','FAILED'));
DELETE FROM BATCH_JOB_EXECUTION_PARAMS WHERE JOB_EXECUTION_ID IN (SELECT JOB_EXECUTION_ID FROM BATCH_JOB_EXECUTION WHERE STATUS IN ('COMPLETED','FAILED'));
DELETE FROM BATCH_JOB_EXECUTION WHERE STATUS IN ('COMPLETED','FAILED');
DELETE FROM BATCH_JOB_INSTANCE WHERE JOB_INSTANCE_ID NOT IN (SELECT BATCH_JOB_EXECUTION.JOB_INSTANCE_ID FROM BATCH_JOB_EXECUTION);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test status: declined Features that we don't intend to implement or Bug reports that are invalid or missing enough details type: task
Projects
None yet
Development

No branches or pull requests

4 participants