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.
Figure 20. Rolling Back Units of Work
![]() |
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.
Figure 21. Restoring a Database
![]() |
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.
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:
Figure 22. Database Roll-Forward Recovery
![]() |
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.
Notes:
Figure 23. Restoring One or More Table Spaces
![]() |
Table space roll-forward recovery can be required in the following two situations:
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
![]() |
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.