What is journaling ?
Journaling is a mechanism used in database systems to log all data modification operations (such as INSERT, UPDATE, and DELETE) to a sequential transaction log (journal) separate from the base tables. This log provides a reliable, auditable trail of changes, supports crash recovery, and enables data consistency across system failures. For mission-critical environments, proper journaling setup and receiver management are essential to ensure data integrity and minimize downtime.What is Change Data Capture ? (CDC)
Change data capture is a technique involving listening to a DB journal to extract the changes since a certain point in time and apply these changes to an external system. This is a particularly efficient way to replicate (i.e. synchronize) one database onto another. No need for a sophisticated setup on the source database, a pre-existing journal can be used as it’s often the case on critical databases. The synchronization doesn’t need to periodically scan a list of tables as the journal centralizes the changes.How is Journaling implemented on IBMi DB2 ?
DB2 tracks multiple tables with a designated journal witch itself delegates the storage to a receiver. While it’s possible to have multiple journals assigned to tables belonging to the same library (or schema), it’s recommended to create a single journal for an entire DB2 instance or a single journal per schema. A schema often reflects a single unit of work with few transactions overlapping schemas.
Configure DB2 Journal
On IBMi, everything is an object, that is a file under a library. Consider libraries as the equivalent of folders in recent systems. In the following examples, use your own library name as defined by your DB2 setup. Use a tn5250 terminal emulator to connect to your IBMi environment and run the following commands.1. Create a Journal Receiver
This command creates a receiver named MY_RCVER under the library POPSINK1 :CRTJRNRCV POPSINK1/MY_RCVER
2. Create a Journal
This command creates a journal named MY_JOURNAL attached to MY_RCVER under the library POPSINK1 :CRTJRN POPSINK1/MY_JOURNAL POPSINK1/MY_RCVER
3. Enable Journaling on source tables
For each table to replicate named $TABLE, run the command :STRJRNPF POPSINK1/${TABLE} POPSINK1/MY_JOURNAL
That is, based on the tables created previously in DB2 setup :