Announcement Announcement Module
Collapse
No announcement yet.
Clean spring batch metadata tables Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Clean spring batch metadata tables

    How can I clean up spring batch metadata tables?

    Thanks.

  • #2
    Originally posted by Tiago Melo View Post
    How can I clean up spring batch metadata tables?

    Thanks.
    * See issue BATCH-1747.
    * See RemoveSpringBatchHistoryTasklet @ https://github.com/arey/spring-batch-toolkit
    * Read blog entry (french): Sprint Batch s'auto-nettoie

    Comment


    • #3
      Originally posted by Tiago Melo View Post
      How can I clean up spring batch metadata tables?

      Thanks.
      I've used this with v2.1.7.RELEASE

      Code:
      DELETE FROM BATCH_STEP_EXECUTION_CONTEXT ;
      DELETE FROM BATCH_JOB_EXECUTION_CONTEXT ;
      DELETE FROM BATCH_STEP_EXECUTION ;
      DELETE FROM BATCH_JOB_EXECUTION ;
      DELETE FROM BATCH_JOB_PARAMS ;
      DELETE FROM BATCH_JOB_INSTANCE ;
      
      DELETE FROM BATCH_STEP_EXECUTION_SEQ ;
      DELETE FROM BATCH_JOB_EXECUTION_SEQ ;
      DELETE FROM BATCH_JOB_SEQ ;

      Comment


      • #4
        Originally posted by johnmmcparland View Post
        I've used this with v2.1.7.RELEASE

        Code:
        DELETE FROM BATCH_STEP_EXECUTION_CONTEXT ;
        DELETE FROM BATCH_JOB_EXECUTION_CONTEXT ;
        DELETE FROM BATCH_STEP_EXECUTION ;
        DELETE FROM BATCH_JOB_EXECUTION ;
        DELETE FROM BATCH_JOB_PARAMS ;
        DELETE FROM BATCH_JOB_INSTANCE ;
        
        DELETE FROM BATCH_STEP_EXECUTION_SEQ ;
        DELETE FROM BATCH_JOB_EXECUTION_SEQ ;
        DELETE FROM BATCH_JOB_SEQ ;

        That's it. Thanks!

        Comment


        • #5
          Originally posted by Tiago Melo View Post
          That's it. Thanks!
          Yikes I made a big mistake here...

          Code:
          DELETE FROM BATCH_STEP_EXECUTION_CONTEXT ;
          DELETE FROM BATCH_JOB_EXECUTION_CONTEXT ;
          DELETE FROM BATCH_STEP_EXECUTION ;
          DELETE FROM BATCH_JOB_EXECUTION ;
          DELETE FROM BATCH_JOB_PARAMS ;
          DELETE FROM BATCH_JOB_INSTANCE ;
          
          DELETE FROM BATCH_STEP_EXECUTION_SEQ ;
          DELETE FROM BATCH_JOB_EXECUTION_SEQ ;
          DELETE FROM BATCH_JOB_SEQ ;
          
          -- These are needed
          INSERT INTO BATCH_STEP_EXECUTION_SEQ values(0);
          INSERT INTO BATCH_JOB_EXECUTION_SEQ values(0);
          INSERT INTO BATCH_JOB_SEQ values(0);
          Those insertions at the end are very important! As I found out here

          Please do use the updated version!

          Comment


          • #6
            Originally posted by johnmmcparland View Post
            Yikes I made a big mistake here...

            Code:
            DELETE FROM BATCH_STEP_EXECUTION_CONTEXT ;
            DELETE FROM BATCH_JOB_EXECUTION_CONTEXT ;
            DELETE FROM BATCH_STEP_EXECUTION ;
            DELETE FROM BATCH_JOB_EXECUTION ;
            DELETE FROM BATCH_JOB_PARAMS ;
            DELETE FROM BATCH_JOB_INSTANCE ;
            
            DELETE FROM BATCH_STEP_EXECUTION_SEQ ;
            DELETE FROM BATCH_JOB_EXECUTION_SEQ ;
            DELETE FROM BATCH_JOB_SEQ ;
            
            -- These are needed
            INSERT INTO BATCH_STEP_EXECUTION_SEQ values(0);
            INSERT INTO BATCH_JOB_EXECUTION_SEQ values(0);
            INSERT INTO BATCH_JOB_SEQ values(0);
            Those insertions at the end are very important! As I found out here

            Please do use the updated version!
            Oh that's right. Thank you very much for your help!

            Cheers!

            Comment


            • #7
              I'm using 2.2.3 and ran into a slight problem with the queries. The table BATCH_JOB_PARAMS is BATCH_JOB_EXECUTION_PARAMS. Here are queries that worked for me in both MySQL and Oracle. Also going to include the beans used to execute the scripts on startup for reference.

              Oracle
              Code:
              alter table batch_job_execution disable constraint job_inst_exec_fk;
              alter table batch_job_execution_context disable constraint job_exec_ctx_fk;
              alter table batch_job_execution_params disable constraint job_exec_params_fk;
              alter table batch_step_execution disable constraint job_exec_step_fk;
              alter table batch_step_execution_context disable constraint step_exec_ctx_fk;
              
              delete from batch_step_execution_context;
              delete from batch_job_execution_context;
              delete from batch_step_execution;
              delete from batch_job_execution;
              delete from batch_job_execution_params;
              delete from batch_job_instance;
              
              alter table batch_job_execution enable constraint job_inst_exec_fk;
              alter table batch_job_execution_context enable constraint job_exec_ctx_fk;
              alter table batch_job_execution_params enable constraint job_exec_params_fk;
              alter table batch_step_execution enable constraint job_exec_step_fk;
              alter table batch_step_execution_context enable constraint step_exec_ctx_fk;
              MySQL
              Code:
              set foreign_key_checks = 0;
              
              delete from batch_step_execution_context;
              delete from batch_job_execution_context;
              delete from batch_step_execution;
              delete from batch_job_execution;
              delete from batch_job_execution_params;
              delete from batch_job_instance;
              
              delete from batch_step_execution_seq;
              delete from batch_job_execution_seq;
              delete from batch_job_seq;
              
              insert into batch_step_execution_seq values(0, '0');
              insert into batch_job_execution_seq values(0, '0');
              insert into batch_job_seq values(0, '0');
              
              set foreign_key_checks = 1;
              Use the following bean to run the queries if desired. Update the location to yours.
              Code:
              <jdbc:initialize-database data-source="dataSource" ignore-failures="ALL">
                  <jdbc:script location="classpath:sql/clean-batch-metadata.sql" />
              </jdbc:initialize-database>
              Last edited by wsams; May 27th, 2014, 02:54 PM. Reason: The Oracle example didn't work with constraints enabled. Updated the Oracle queries to include temporarily disabling constraints.

              Comment

              Working...
              X