During the life of a database, you may occasionally need to change the physical configuration of the logs. You can use SQLCDBEX to move the logs. See Moving Log Disks for more information. At other times, you will need to reset the contents of the log logically. This is referred to as log reformatting and is required, for example, when you switch from LOGMODE=A or L to LOGMODE=Y or N.
log reconfiguration and reformatting |
---|
In this section, the term log reconfiguration means that the history area has been erased. Log reformatting means that history area has not been erased. Both erase the current database updates saved in the log. |
The operation that performs both log reconfiguration and log reformatting is called a COLDLOG. To do a COLDLOG, run the IBM-supplied SQLLOG EXEC, For more information, see Running the SQLLOG EXEC.
You must reconfigure the logs if you do any of the following.
To reconfigure the logs:
If you are using archiving (LOGMODE=A or L), you must create a new database archive immediately after running the SQLLOG EXEC. This ensures that the archive copy of the database correctly reflects the size of the logs and whether or not dual logging is in effect. Since the SQLLOG EXEC changes the LOGMODE to Y, you cannot set LOGMODE to L or A until you have taken a database archive. To create the new archive:
You must reformat the logs if you do any of the following:
To reformat the logs:
The SQLLOG EXEC begins the COLDLOG operation by starting the application server (with the SQLSTART EXEC) in single user mode (SYSMODE=S) with STARTUP=L, LOGMODE=Y, and DUALLOG=Y (if two logs are defined) or DUALLOG=N (if one log is defined).
This EXEC resides on the service minidisk (V-disk); it can be run only from a database machine. Its format is:
The AMODE(24) option only needs to be specified when user-written exits do not support 31-bit addressing. In this case, AMODE(24) must be specified when running the SQLLOG EXEC. For a description of this parameter, see AMODE.
Notes:
Respond CONTINUE to message ARI0688D (for single logging) or ARI6129D (for dual logging). Respond 0 to message ARI0944D to reformat the log, or 1 to reconfigure the log.
Respond 1 to message ARI0944D only if:
Attention: Be sure that you are accessing the correct minidisk before you respond 1 to message ARI0944D to reconfigure the log minidisk.
For example, suppose you are using database archiving (LOGMODE=A) and dual logging. Your userid is USER1. Another user of the database, USER2, has committed a LUW that made many erroneous updates to the database, and you want to restore the database from a back-level database archive copy. To avoid the log recovery processing that this would entail, you decide to reformat the logs:
SQLEND ARCHIVE DVERIFY
SQLLOG DB(USER1DB)
Now suppose that USER2 makes many changes to the database and consistently causes the database manager to take online archives because the log has been filled. You decide to increase the size of the logs:
SQLLOG DB(USER1DB) LOG1(502) LOG2(503)
Now suppose that USER2 has added so much data to the database that you must add more dbextents to the database. Unfortunately, your computer center does not allow use of any more DASD space. You therefore decide to switch to single logging temporarily and use the freed DASD space for another dbextent. To reduce the risk of DASD failure on the remaining log, you switch to log archiving and take frequent log archives:
SQLEND ARCHIVE DVERIFY
SQLLOG DB(USER1DB) LOG1(502)
If you are recovering using dual logging, and the primary log does not contain readable data, the database manager automatically switches to the secondary log. If the primary log can be read but it is corrupt, follow these steps to recover using the data on the secondary log:
This will cause it to compare the two logs, and copy the contents of the secondary log onto the primary log minidisk.
If this procedure fails to recover the database, you must restore it from the last database archive, or do a COLDLOG operation to reformat the logs.
The distinction between a log reconfiguration and log reformatting is the effect each has on an internally used portion of the log known as the history area. This is a portion of the log that the database manager uses to keep track of recovery events such as database archives, log archives, restores, COLDLOGs, and the switching of log modes. Log reconfiguration causes the history area to be erased; log reformatting does not.
If the history area is erased, the database manager cannot tell which log archives belong with which database archives, or if the continuity of log archiving was broken. In fact, it cannot tell whether you were using log archiving at all, so the database manager cannot allow you to restore the database using a database archive and subsequent log archives.
As the final step in a database, user, or log archive, the database manager archives the newly updated history area into the archive file ARIHSDS ARCHIVE on the database machine work disk. This copy will be used to restore the history area in the event that it is corrupted. This reduces the risk of not being able to do a restore using log archives because of an unrecoverable error in the history area.
Before doing a log reconfiguration, the database manager saves the history area in file ARIHSDS PRECLDLG on its work disk. If a restore is done immediately after a log reconfiguration (meaning that the new history area is empty), this old history area will automatically be restored. This area may also be used for restoring back-level databases: if the database to be restored is found here, not in the current history area, you may choose to restore the old area to the current log. If you do so, associated log archives may be applied because they will now be found in the log's history area. Note that, because the old history area is restored to the log, no records of any archives taken after the COLDLOG reconfiguration will be available.
You can always restore the database from a back-level or a current database archive. But if the history area is erased, you lose the ability to restore the database using any log archive taken prior to this erasure. Also, if the database archive was taken online (with the ARCHIVE command), the database could be restored to an inconsistent state. For example, a LUW could have made changes before the archive was taken, and then be rolled back after the archive finished. When the database archive is restored, the changes made before the archive was taken are in the database, but any changes made after the archive will be lost.
Whenever a log minidisk is reconfigured, by you directly or by the SQLLOG EXEC, the history area is lost. (The SQLLOG EXEC always prompts you with message ARI0944D before erasing the history area.)
The following description is not intended to be comprehensive; it only provides general background information about log archive recovery processes using the history area.
To display the history area, issue the operator command SHOW LOGHIST. For a discussion of this command, see the DB2 Server for VSE & VM Operation manual.
Suppose that you take a database archive (using either database manager or user facilities), followed by four log archives. The history area of the log would contain one record for each of these events:
Database Archive 1 Log Archive 1 Log Archive 2 Log Archive 3 Log Archive 4
The records in the history area itself would be in an internal (unreadable) format. For ease of description, the records of the history area are shown in an externalized form.
If you now request another database archive, then because the database manager is running with LOGMODE=L, it first takes another log archive of the current log (Log Archive 5 in the example below). If you then take three subsequent log archives the history area would contain the following records:
Database Archive 1 Log Archive 1 Log Archive 2 Log Archive 3 Log Archive 4 Log Archive 5 Database Archive 2 Log Archive 6 Log Archive 7 Log Archive 8
When you take an archive, the database manager generates identification information based on the processor's time-of-day clock. When you restore the database, the database manager reads this information in the database archive tape file before it looks at the history area.
During a restore, you may be requested to take a log archive of the current log to save the changes up to the point of the restore. When you restore the database from the restore set containing this log archive (and actually restore the log archive), it is erased from the log history's restore set because it is put back into the current log.
When the database manager identifies the database archive tape that is being restored, it writes a record in the history area to indicate that a restore is being done. Next it looks for the corresponding database archive record in the history area.
For example, suppose you start the application server with STARTUP=R, and mount the Database Archive 2 tape file. The database manager looks for the corresponding record in the history area (by searching in reverse chronological order, from the most recent to the least recent entries). When it finds it, it determines the log archives associated with the database archive by reading forward in the history area until the RESTORE record is reached. Log Archive 9 is taken before the restore set is determined. This set of records is referred to as the restore set.
Read back to the Read forward to Database Archive identify associated Write a RESTORE record: Record: log records: Database Archive 1 Database Archive 1 Database Archive 1 Log Archive 1 Log Archive 1 Log Archive 1 Log Archive 2 Log Archive 2 Log Archive 2 Log Archive 3 Log Archive 3 Log Archive 3 Log Archive 4 Log Archive 4 Log Archive 4 Log Archive 5 Log Archive 5 Log Archive 5 Database Archive 2 Database Archive 2 <--- Database Archive 2 <--- Log Archive 6 Log Archive 6 Log Archive 6 <--- Log Archive 7 Log Archive 7 Log Archive 7 <--- Log Archive 8 Log Archive 8 Log Archive 8 <--- Log Archive 9 Log Archive 9 Log Archive 9 <--- RESTORE RESTORE RESTORE
The database manager copies the restore set records after the RESTORE record:
Database Archive 1 Log Archive 1 Log Archive 2 Log Archive 3 Log Archive 4 Log Archive 5 Database Archive 2 <--- Log Archive 6 <--- Restore set Log Archive 7 <--- Log Archive 8 <--- Log Archive 9 <--- RESTORE Database Archive 2 <--- Log Archive 6 <--- Restore set copied forward Log Archive 7 <--- Log Archive 8 <--- Log Archive 9 <---
The database manager then displays the restore set to the console using messages. If you restore all the log archives associated with the database archive, the history area remains as shown above, except that Log Archive 9 is erased from the restore set copied forward when it is restored to the current log. If you respond END RESTORE to one of the prompts, the database manager deletes the remaining log archive records from the history area. For example, suppose you respond END RESTORE after only two of the log archives are processed. The final two log archives in the history area are deleted:
Database Archive 1 Log Archive 1 Log Archive 2 Log Archive 3 Log Archive 4 Log Archive 5 Database Archive 2 Log Archive 6 Log Archive 7 Log Archive 8 Log Archive 9 RESTORE Database Archive 2 Log Archive 6 <--- Only two log archives are restored Log Archive 7 <---
After the restore is ended, processing continues and two more log archives are taken. Now the history area looks like this:
Database Archive 1 Log Archive 1 Log Archive 2 Log Archive 3 Log Archive 4 Log Archive 5 Database Archive 2 Log Archive 6 Log Archive 7 Log Archive 8 Log Archive 9 RESTORE Database Archive 2 Log Archive 6 Log Archive 7 Log Archive 10 <--- New log archives Log Archive 11 <---
If you must again restore the database and use Database Archive 2, the restore set will contain Log Archives 6, 7, 10, and 11. Because the database manager determines the restore set by scanning backwards in the history area until it finds a corresponding database archive record, the original Database Archive 2 record (the one before the RESTORE) is never reached. Consequently, it is impossible to use Log Archive 8 or 9 when restoring the database from Database Archive 2.
The only way to restore Log Archive 8 or 9 after you responded END RESTORE is to restore from a back-level database archive. This archive must have continuous log archives to the log archive you want to restore.
In our example, to restore the database to its status immediately before the restore, start the application server to do a restore, and restore Database Archive 1. The database manager scans backwards to the first occurrence of a Database Archive 1 record. (There is only one occurrence.) When it finds the record, it scans forward in the history area until it either reaches the end of the history area or until it finds:
These records indicate a break in the continuity of the log archives. If you restore Database Archive 1 in our example, the restore set copied forward in the history area includes Log Archive 9:
Database Archive 1 <--- Log Archive 1 <--- Log Archive 2 <--- Log Archive 3 <--- New Log Archive 4 <--- Restore Log Archive 5 <--- Set Database Archive 2 <--- Log Archive 6 <--- Log Archive 7 <--- Log Archive 8 <--- Log Archive 9 <--- RESTORE <--- Indicates end of restore set Database Archive 2 Log Archive 6 Log Archive 7 Log Archive 10 Log Archive 11 RESTORE Database Archive 1 <--- Log Archive 1 <--- Log Archive 2 <--- Log Archive 3 <--- Log Archive 4 <--- Restore Set Copied Forward Log Archive 5 <--- Log Archive 6 <--- Log Archive 7 <--- Log Archive 8 <--- Log Archive 9 <---
During the actual restore, only the log archives are applied. Database Archive 2 is skipped because all the change activity is recorded in the continuous log archives.
When the database is restored, it reverts to the state it was in before the first restore. The changes recorded in Log Archives 10 and 11 are lost.
The important points to remember from this discussion are:
If the database manager cannot find the database archive in the current history area or in the history area saved by the last COLDLOG reconfiguration (if one exists), a message is displayed saying the database archive is unknown. You are given the opportunity to do a COLDLOG (if one has not yet been done) to reformat the log. The COLDLOG is necessary because, since the database manager cannot determine a recovery set, none of the log archive records in the history area applies, and hence the database manager cannot confirm that the current log applies.
The lack of a database archive record in the history area implies either that the database archive is very old, or that you have mounted the wrong database archive tape file. If you are intentionally restoring an old database archive, you must do a COLDLOG to avoid applying changes recorded in the current log.