r/SQL • u/Think_Percentage_959 • 5h ago
DB2 Need help on DB2 design
/r/learnprogramming/comments/1ya23oi/need_help_on_db2_design/Problem Statement
We have a transaction history table (CARDTXNHIST) used by a banking application to display customer transactions.
The daily batch process consists of two stages:
Unstatemented Transactions (Code = 2)
batch file → TEMP table → View → CARDTXNHIST
Existing Code=2 records are deleted and refreshed
Statemented Transactions (Code = 3)
Separate batch file → TEMP table → View → CARDTXNHIST
Statemented records are loaded after unstatemented processing
The batch window runs approximately between 4 AM and 9 AM.
Observed Issue
On statement cycle dates, the incoming unstatemented dataset may be empty because all eligible transactions have been statemented.
As a result:
Code=2 transactions are removed/refreshed
Code=3 transactions are still being processed
During this period, customers may see no transaction history in the application, even though the transactions still exist within the batch pipeline.
Objective
We are looking for database/application architecture approaches that can eliminate or minimize this visibility gap while the batch is in progress.
Solutions Under Consideration
Retaining Code=2 records until Code=3 processing completes
Shadow table / table-swap approach
Composite views
Deferred commit strategy
Reading from staging/view sources during batch processing
Data archival and performance optimization
Other database design recommendations
Questions
What would be the recommended design pattern to ensure customers always see a consistent transaction history?
How have similar large-scale batch processing systems solved this "delete-before-republish" visibility gap?
Are there DB2-specific approaches (isolation levels, shadow tables, transition tables, view-switching, etc.) that would be suitable for this scenario?
If you'd like to adjust the length or add any extra context (like table volume or specific DB2 version) before posting, let me know!
1
u/Warm-Republic-1913 3h ago
The simplest fix is to make the refresh atomic so readers never see the gap: do the Code=2 delete and reload and the Code=3 load in one unit of work and commit once at the end, and since DB2 readers at cursor stability only see committed rows, customers keep seeing the old data until that commit. If the transaction would get too big for your batch window, add a batch_id (or load_version) column instead, load the new rows under a new id while the old ones stay in place, and have the view read only the latest completed id, then flip that id in a tiny control table once both stages are done. A shadow table with a rename or view switch at the end also works, but the batch_id approach avoids DDL and locking during the swap. Either way, an empty Code=2 file shouldn't mean delete everything until Code=3 is also loaded.