Choosing a target image for database rebuild
The rebuild target image should
be the most recent backup image that you want to use as the starting
point of your restore operation.
This image is known as
the target image of the rebuild operation, because it defines the
structure of the database to be restored, including the table spaces
that can be restored, the database configuration, and the log sequence.It
can be any type of backup (full, table space, incremental, online
or offline).
The target image sets the log sequence (or log chain) that determines what images can be used for the remaining restores during the rebuild phase. Only images on the same log chain can be used.
The following examples illustrate how to choose the image you should use as the target image for a rebuild operation.
Suppose there is a database called SAMPLE that has the following
table spaces in it:
- SYSCATSPACE (system catalogs)
- USERSP1 (user data table space)
- USERSP2 (user data table space)
- USERSP3 (user data table space)
Figure 1 shows that the following
database-level backups and table space-level backups that have been
taken, in chronological order:
- Full database backup DB1
- Full table space backup TS1
- Full table space backup TS2
- Full table space backup TS3
- Database restore and roll forward to a point between TS1 and TS2
- Full table space backup TS4
- Full table space backup TS5

Example 1
The following example demonstrates
the CLP commands you need to issue to rebuild database SAMPLE to the
current point of time. First you need to choose the table spaces you
want to rebuild. Since your goal is to rebuild the database to the
current point of time you need to select the most recent backup image
as your target image. The most recent backup image is image TS5, which
is on log chain 2:
db2 restore db sample rebuild with all tablespaces in database taken at
TS5 without prompting
db2 rollforward db sample to end of logs
db2 rollforward db sample stop
This restores
backup images TS5, TS4, TS1 and DB1 automatically, then rolls the
database forward to the end of log chain 2.
Note: All logs belonging
to log chain 2 must be accessible for the rollforward operations to
complete.
Example 2
This second example demonstrates
the CLP commands you need to issue to rebuild database SAMPLE to
the end of log chain 1. The target image you select should be the
most recent backup image on log chain 1, which is TS3:
db2 restore db sample rebuild with all tablespaces in database
taken at TS3 without prompting
db2 rollforward db sample to end of logs
db2 rollforward db sample stop
This restores
backup images TS3, TS2, TS1, and DB1 automatically, then rolls the
database forward to the end of log chain 1.
Note:
- All logs belonging to log chain 1 must be accessible for the rollforward operations to complete.
- This
command may fail because a log file is retrieved from a higher log
chain (the rollforward utility always attempts to get log files from
the highest log chain), you need to do the following steps:
- Extract the log files manually to the overflow log path.
- Run the ROLLFORWARD command. Include the parameters -OVERFLOW LOG PATH, to specify the location of the extracted log files, and -NORETRIEVE, to disable the retrieval of archived logs.
Choosing the wrong target image for rebuild
Suppose
there is a database called SAMPLE2 that has the following table spaces
in it:
- SYSCATSPACE (system catalogs)
- USERSP1 (user data table space)
- USERSP2 (user data table space)
Figure 2 shows the backup
log chain for SAMPLE2, which consists of the following backups:
- BK1 is a full database backup, which includes all table spaces
- BK2 is a full table space backup of USERSP1
- BK3 is a full table space backup of USERSP2

The following example demonstrates the CLP command you
need to issue to rebuild the database from BK3 using table spaces
SYSCATSPACE and USERSP2:
db2 restore db sample2 rebuild with tablespace (SYSCATSPACE,
USERSP2) taken at BK3 without prompting
Now
suppose that after this restore completes, you decide that you also
want to restore USERSP1, so you issue the following command:
db2 restore db sample2 tablespace (USERSP1) taken at BK2
This
restore fails and provides a message that says BK2 is from the wrong
log chain (SQL2154N). As you can see in Figure 2, the only image that can be used
to restore USERSP1 is BK1. Therefore, you need to type the following
command:
db2 restore db sample2 tablespace (USERSP1) taken at BK1
This succeeds so that database can be rolled forward accordingly.