IBM Books

Administration Guide


Overview of Recovery

You need to know the strategies available to you to help when there are problems with the database. Typically you will deal with media and storage problems, power interruptions, and application failures. You need to know that you can back up your database, or individual table spaces, and then rebuild them should they be damaged or corrupted in some way. The rebuilding of the database is called recovery. There are three ways recovery of a damaged database can take place: crash recovery, restore, and roll-forward.

  1. Crash recovery is the method that protects a database from being left in an inconsistent, or unusable, state. Transactions, or units of work, against the database can be interrupted unexpectedly. For example, should a failure (power interruption, application failure) occur before all of the changes that are part of the unit of work are completed and committed, the database is left in an inconsistent and unusable state.

    Figure 20. Rolling Back Units of Work


    * Figure SQLD0RLB not displayed.


    The database then needs to be moved to a consistent and usable state. This is done by rolling back incomplete transactions and completing committed transactions that were still in memory when the crash occurred.

    You can do this by entering a RESTART DATABASE command. If you want this done in every case of a failure, then you should consider the use of the automatic restart enable (autorestart) configuration parameter. The default for this configuration parameter is that the RESTART DATABASE routine will be started every time it is needed. When (autorestart) is enabled, the next connect request to the database after the failure causes RESTART DATABASE to be executed.

    Crash recovery always moves the database to a consistent and usable state. If crash recovery occurs for a database that is enabled for forward recovery (that is, the logretain or userexit configuration parameter is on for the database), and an error occurs during crash recovery that is attributable to an individual table space, that table space is taken off-line. Crash recovery continues. The table space taken off-line is placed in a roll-forward pending state.

    At the completion of crash recovery, the other table spaces in the database are still usable and connections to the database can be established. (There are exceptions involving the table spaces that have the temporary tables or the system catalog tables. These will be discussed under roll-forward recovery.)

    Following crash recovery, you may need to take additional action. You may need to work with the table spaces taken off-line as mentioned above. You may need to conduct a restore recovery and/or a roll-forward recovery depending on the error.

  2. Restore recovery (also known as version control) allows for the restoration of previous version or image of the database that was made using the BACKUP command.

    Figure 21. Restoring a Database


    * Figure SQLD0RST not displayed.


    A database restore will rebuild the entire database using a backup of the database made at some point earlier. A backup of the database allows you to restore a database to a state identical to the time when the backup was made. Every unit of work from the time of the backup to the time of the failure is lost. (The need to re-create these units of work introduces the possibility of the next recovery method, roll-forward recovery, which is discussed later.)

    Using the database restore recovery method, you must schedule and perform a full backup of the database on a regular basis.

    In a partitioned database environment, the database is located across many database partition servers (or nodes). You must restore all database partitions, and the backups that you use for the RESTORE must all have been taken at the same time. (Each database partition is backed up and restored separately.) A backup of each database partition taken at the same time is known as a version backup.

  3. Roll-forward recovery may be the next task to be done following a restore depending on the state of the database. For roll-forward recovery to be possible on a database, the database must be recoverable, and must be in the roll-forward pending state at the end of the restore.

    Recoverable databases have either the logretain or userexit (or both) database configuration parameters turned "on". This allows for active and archived logs to be kept and results in the ability for the database to have roll-forward recovery. Table space BACKUP and RESTORE, and online BACKUP and RESTORE, are applicable to recoverable databases only.

    Non-recoverable databases have both logretain and userexit turned "off". Only active logs are kept for crash recovery; no roll-forward recovery is allowed. Restore recovery using offline backups is the primary means of recovery for problems with this mode of database.

    The scenarios that you need consider at this point are:

    1. Database roll-forward recovery, which follows the restore of the database with the application of database logs. The database logs record all changes made to the database. This method completes the recovery of the database to a state identical to the time just before the failure.

      Figure 22. Database Roll-Forward Recovery


      * Figure SQLD0RLF not displayed.


      To use the database roll-forward recovery method, you must have created a backup of the database as well as archiving the logs by enabling either logretain or userexit. There are decisions that you must make regarding the logging procedure that you use. (Logging is discussed in more detail later. See the section on "Database Logs".)

      In a partitioned database system, the database is located across many database server partitions. In this environment, if you are performing point-in-time roll-forward recovery, all database partitions must be rolled forward to ensure that all partitions are at the same level. If you need to restore a single database partition, you can perform roll-forward recovery to the end of the logs to bring it up to the same level as the other database partitions in the database.

    2. When the database is enabled for forward recovery, it is also possible to back up and restore table spaces. Table space restore requires a backup made using BACKUP. This backup can be of the entire database (all of the table spaces) or of one or more individual table spaces. This method restores the selected table spaces to a state identical to the time the backup was made.

      Notes:

      1. Those table spaces not selected at the time of the BACKUP will not be in the same state as those that were restored.

      2. Using the table space restore recovery method, you must identify "key" table spaces in the database to be recovered as well as schedule and perform a backup of the database or the "key" table spaces on a regular basis.

Figure 23. Restoring One or More Table Spaces


* Figure SQLD0TSR not displayed.


Table space roll-forward recovery can be required in the following two situations:

  1. If one or more table spaces are in a roll-forward pending state because of crash recovery, you can use the ROLLFORWARD command to apply the logs against the table spaces.
    Note:If the table space in error contains the system catalog tables, you will not be able to start the database. You must restore the SYSCATSPACE table space, then perform roll-forward recovery on it to the end of the logs.

    Figure 24. Table Space Roll-Forward Recovery


    * Figure SQLD0RFT not displayed.


  2. The second scenario occurs after a table space restore. A table space is always in the roll-forward pending state after it is restored, and it must be rolled forward. Again, use the ROLLFORWARD command to apply the logs against the table spaces.

In a partitioned database system, if you are rolling forward a table space to a point in time, you do not have to supply the list of nodes (database partitions) on which the table space resides. The database manager submits the ROLLFORWARD request to all database partitions. If you are rolling forward a subset of the table spaces to the end of the logs, you must supply the list of nodes. If you want to roll forward all table spaces to the end of the logs, you do not have to supply the list of nodes. By default, the ROLLFORWARD request is sent to all database partitions.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]

[ DB2 List of Books | Search the DB2 Books ]