Module 14: DB2 Locking, Recovery and Performance
DB2 Logs
The DB2 log is the diary of every change made to the database. Without it, there would be no rollback and no recovery. Every serious DB2 concept, from COMMIT to RECOVER, depends on the log.
Active logs and archive logs
- DB2 first writes every change to the active logs, which are a small set of datasets reused in a ring.
- When an active log fills up, DB2 copies its content to an archive log and reuses the active dataset. In case of failure, DB2 uses the archive log to recover lost data.
- Archive logs are kept much longer than active logs. They are what makes point-in-time recovery possible.
- The DBA sizes the active logs so that normal peaks fit without constant archiving, which slows the system.
What DB2 writes to the log
- Before and after images of every changed page, so DB2 can undo or redo the change later.
- Begin, commit and rollback records marking the boundaries of each unit of work.
- Checkpoint records that help DB2 restart faster by marking a known good point.
- Utility records for LOAD, REORG and COPY so recovery knows what the utilities did.
How logs support recovery and rollback
- ROLLBACK reads the log backwards and applies the before-images, undoing the unit of work.
- Crash recovery at DB2 restart redoes committed changes (after-images) and undoes uncommitted ones.
- The RECOVER utility restores an image copy and then rolls the log forward to replay changes made after the copy.
- Operators can force the current active log to archive with a console command. Example:--ARCHIVE LOG MODE(QUIESCE)
