A log record is written for any changes made to the database system (except for some operations like LOAD that are not logged fully). The log record contains information like:
- which component in DB2 wrote the log record (e.g. data manager, index manager, LOB manager, ...)
- which operation was performed
- which database object was affected (OBID)
- which tablespace and which page was affected
- which exact changes were made, e.g. before/after images of inserted/deleted rows
- in which transaction did the change occur (internal transaction ID)
DB2 can simply read and interpret the log record and, thus, knows which operation was done. So it can redo the operation or undo it (by compensating it, for example running a delete to compensate an insert).
In DB2 z/OS data sharing mode, DB2 does not use RBA (relative byte addresses) into the log file but LRSN (log record sequence number). The basic idea is the same: LRSNs are synchronized across data sharing members using the sysplex timer. That guarantees that all log records are written in the proper sequence.
Logs are used for the following purposes:
- track changes for recovery and rollforward (hopefully you will never need it, but if you do need it, you won't do without logging)
- rollback transactions - if a transaction abends or is rolled back explicitly, all changes made so far in the transaction have to be undone. In order to figure out what has done, DB2 scans backwards through the logs to find all log records for the transaction. Then it analyzes each log record and compensates it.
- replication - data changes are written to the log and the Capture process of replication reads the logs asynchronously to find all changes made to the system and extract the changes for committed transactions so that those changes can be applied to another database system.
This is just a very basic description of logging. If you have any specific questions, feel free to ask. I don't want to go into more details because this is a rather broad topic.