Personal tools
You are here: Home DB2 How To's How to set database to archive logs
Navigation
Log in


Forgot your password?
 
Document Actions

How to set database to archive logs

archived logs are logs that were active but are no longer required for crash recovery

Before we learn how to set database to archive logs , let's see some concepts about logs.


1 Transaction Logging


  • Transaction logging is a process that is used to keep track of changes made to a database (by transactions), as they are made. Each time an update or a delete is performed, the page containing the record to be updated/deleted is copied to the appropriate buffer pool, where it is then modified (if a new record is created by an insert operation, that record is created directly in the appropriate buffer pool).

  •  Once the record has been modified (or inserted), a record reflecting the modification/insertion is written to the log buffer, which is another storage area in memory. Records that indicate whether the transactions that made the changes were committed or rolled back, are also stored in the log buffer.

  • Whenever buffer pool I/O page cleaners are activated, the log buffer becomes full, or a transaction is terminated, all records stored in the log buffer are written to one or more log files stored on disk. This process is referred to as write-ahead logging and it ensures that log records are always flushed to log files before data changes are recorded in the database. Different transactions can write into the same log file (a transaction Id is also written into the log file).

  • Log files are necessary to perform recovery operations.


2 Logging Strategies


  • The way in which all primary log files are used is determined by the logging strategy chosen for the database. The type of logging used is setup on database configuration file. Two different strategies are available in Db2:

  • Circular logging : LOGRETAIN and USEREXIT database configuration parameters are set to OFF (Db2 V8.1, Db2 V7). LOGARCHMETH1 and LOGARCHMETH2 database configuration parameters are set to OFF (Db2 v8.2).
  • Archival logging : archived logs are logs that were active but are no longer required for crash recovery. Set USEREXIT to ON or LOGRETAIN to RECOVERY to enable archive logging . On Db2 V8.2 two new database configuration parameters are used to enable log archiving (LOGARCHMETH1 and LOGARCHMETH2)

    db2 update db cfg for dbquiz using LOGRETAIN on

    or

    db2 update db cfg for dbquiz using USEREXIT on

    or

    db2 update db cfg for dbquiz using LOGARCHMETH1 <value>

    or

    db2 update db cfg for dbquiz using LOGARCHMETH2 <value>

EXAMPLE: The <value> on LOGARCHMETH1 can set as: TSM or D:\DATABASE\LOGS

  • In both strategies, the active logs (logs that are required by crash recovery) are stored in the path described in “Path to log files”. To change this path, update the db cfg parameter NEWLOGPATH. On the next time the database is activated, the path to log files will change.

  • The active log space available is determined by the maximum number of primary (LOGPRIMARY) and secondary (LOGSECOND) log files allowed and the log file size used (LOGFILSIZ). These three parameters are setup on the database configuration file.

More Details about Circular Loggging and Archive Logs are in the next two section:


3 Circular Logging



  • Uses a "ring" of online logs to provide recovery from transaction failures and system crashes.
  • Logs that are no longer needed for recovery are marked as being “reusable” and will be overwritten.
  • Is the default Db2 logging method.
  • Does not allow you to roll a database forward through transactions performed after the last full backup operation.
  • With this type of logging, only full, offline backups of the database are allowed.
  • If the next primary log in the sequence remains “unusable”, secondary log files are allocated and used.
  • Databases that use circular logging are called non-recoverable. This option is usually used in read-only operations that don’t need roll-forward recovery.


4 Archive Logging



  • Unlike with circular logging, these log files are stored in sequence and never reused. When all records stored in an individual log file are released, that file is marked as being "archived" rather than as being "reusable" and the only time it is used again is if it is needed to support a roll-forward recovery operation.

  • Archived logs should be moved to an archive log path or different media like TSM. In Db2 V8.1 this could be done manually or by a userexit program. In Db2 V8.2 this can be done easier with the new “LOGARCHMETH” parameters. For example, if LOGARCHMETH1 is setup as TSM, db2 will move the logs to TSM automatically without need of using a userexit program. When logs are moved to the archive log path or TSM they are removed from the active log path, releasing the space.

  • When using archive logging, the first active log file is shown on the database configuration file as “First active log file”. All files with a sequence number lower than the active log can be archived.

  • With this type of logging, both offline and online backups of the database are allowed.

  • Databases that use archive logging are called recoverable.
Security Awareness
Would you like your company to implement gamification into your security awareness program?





Polls