Managing Db2 transaction logs

Transaction logs are stored for your Db2 database. You can use the prune history command to remove certain log files and create more storage space.

Before you begin

  • Wait for backup and restore operations to complete.
    You can run the following command to verify that no backup and restore operation is in progress:
    db2 list utilities
    Refer to the following example output to confirm:
    SQL1611W  No data was returned by Database System Monitor.  SQLSTATE=00000
  • Determine what log files can be deleted. For more information, see Managing diagnostic directories for Db2.

About this task

Note: If the Db2 database is returning an error due to a lack of space, you can edit the associated PVC and increase the allocated storage amount. The storage class that you are using must have allowVolumeExpansion set to true. For more information, see Enabling volume expansion support.
For more information on using the prune history command, see PRUNE HISTORY/LOGFILE command and Hands-on example for PRUNE HISTORY command.

Procedure

  1. Log in to the Db2 pod by running the following command:
    oc exec -it db2u-pod -- bash
  2. Switch to the db2inst1 user by running the following command:
    su - db2inst1
  3. Find the timestamp of the logs that you want to delete (up to and including) by running the following command:
    db2 list history all for <database-name> | egrep "B P|B D|X D"

    The command returns the timestamps for the following storage items:

    X D:log archive
    B P:tablespace backup
    B D:full backup
  4. Delete the log files with the following command:
    Warning: The following command deletes all log files with the included timestamp. Confirm which log files you want to delete before you run the command.
    db2 prune history <timestamp> and delete

    Replace <timestamp> with the time value of the log files that you want to delete.

    Note: For details on automating diagnostic log files management, see Automating tasks with the Administrative Task Scheduler (ATS) for the Db2 service.