sqldatabasedb2archiving

How to move records from one DB2 database to another DB2 database?


At regular times we want to clean up (delete) records from our production DB (DB2) and move them to an archive DB (also DB2 database having the same schema).

To complete the story there are plenty of foreign key constraints in our DB. So if record b in table B has a foreign key to record a in table A and we are deleting record a in production DB then also record b must be deleted in the production B and both records must be created in the archive DB.

Of course it is very important that no data gets lost. So that it is not possible that we delete records in the production DB while these records will never be inserted in the archive DB.

What is the best approach to do this ?

FYI I have checked https://www.ibm.com/support/knowledgecenter/SSEPGG_10.5.0/com.ibm.db2.luw.admin.dm.doc/doc/r0024482.html and the proposed solutions have following short comings.

So based on my research, the current best solution seems to be a kind of in-house developed script that is

  1. Exporting the records to move in IXF format
  2. Importing those exported records in the archive DB
  3. deleting those records in the production DB

In order to cause no transaction log full errors, this script should do this in batches (e.g. of 50000 records)

In order to have no foreign key constraint errors in step 3: we must also assure that in step 1 we are also exporting all records having foreign key constraint to the exported records and all records having a foreign key constraint to these records ...


Solution

  • Questions that ask the "best" approach have limited use because the assessment criteria are omitted. Sometimes the assessment criteria differ between technicians and business people.

    Sometimes multiple policies of the client company can determine such criteria, so awareness of local policies and procedures or patterns is crucial .

    Often the operational-requirements and security-requirements and licensing-requirements will influence the approach, apart from the skill level and experience of the implementation-team.

    Occasionally corporates have specific standardised tools for archival and deletion, or specific patterns sometimes influenced by the industry-sector or even industry-specific regulatory requirements.

    As stackoverflow is a programming oriented website, questions like yours can be considered off-topic because you are asking for advice about which design-approach are possible while omitting lots of context that is specific to your company/industry-sector that may well influence the solution pattern.

    Some typical requirements or questions that influence the approach are below: