Talking about the backup and recovery of DB2 databases (below)

zhaozj2021-02-11  190

Second, DB2 database recovery

The DB2 database provides three recovery types:

1. Crash recovery: Crash recovery is used to recover immediately after failure, restore the database to a consistent state, and all changes in this status are only effective after the transaction is executed. Crash Recovery Using Command RESTART.

2. Backup Recovery: Backup recovery can restore the content of the database from the backup of the last time. Backup Restore uses the restore command.

3, forward recovery: After a database is restored from the backup, the forward recovery can re-execute the operations of the database after the backup is changed. In this case, the database can be restored to any time break between the backup and the current time. Restore before using the ROLLFORWORD command.

Crash Recovery and Backup Recovery Applicable to any database, and forward recovery is only used by using this feature in the database. Table 1 shows the impact of this function.

The impact of the table one database can be made forward recovery

If not allowing forward recovery If the forward recovery is allowed, the database can be restored to the last transaction before failure after failure. Similarly, it also supports restoring to the status consistent with the last transaction. You can restore the database to any valid backup status, but you cannot re-execute transactions after the backup. You can restore the database to any valid backup status and you can re-execute transactions that fail to the currently submitted. You can only make a backup when there is no application to the database (this is called offline backup). You can make a backup when the application is connected to the database (this is called online backup). Also support offline backup. Each backup must contain the current status of the entire database. A backup may contain the current state of the entire database, or one or more tablespaces. The tablespace of the database can be backed up and restored separately.

The forward resume can be taken effect by setting the database configuration parameter logretain or useXIT to YES. The log will increasing due to generating new files, and they are unlimited. In this case, some ways must be taken to save the old log files to the document to prevent the file system from being covered by the log.

1, restart command

This command is the first command to be issued when some operations are still out of power failure or software crashes. It creates a database connection and uses logs to restore databases to transaction. All database changes caused by submission operations before failure occur. All transactions that are being processed during failure and failure are revoked.

Below is an example of the restart command:

Restart Database MYDB

2, restore command

This command uses the content stored in the backup to restore the contents of the database. The restore command can create a new database. The restore command requires sysadm, sysctrl, or sysmaint privilege. The restore command to use may contain the entire database or a set of tablespaces. Recovering the entire database must be done offline, and the recovery table space can be made online, that is, when there is also an application to connect to the database. The restore command syntax is:

RESTORE DB Target Database Bear Name [TableSpace Table Space Name] [FROM Media] [Taken At Time]

Here is some examples of restore commands:

(1) Recover the MYDB database from a backup in a specific directory (/ backup / mydb). If the MyDB is not able to recover forward, the database will be restored to the backup status, and can be used immediately. If it is possible to recover forward, the database will be set to the PENDING state until it is executed after the forward recovery command can be used.

RESTORE DATABASE MYDB FROM / BACKUP / MYDB (2) The following command is to recover the database MYDB, and the database can be used immediately, and the database can be used immediately.

RESTORE DATABASE MYDB FROM / BACKUP / MYDB WITHOUT ROLLING FORWARD

(3) The following example is to restore a specified table space of the MYDB database from a specified directory (/ backup / mydb). This recovery is to use the specified date and time:

RESTORE DATABASE MYDB TABLESPACE TABLESPASP / MYDB TAKEN AT 20000926201226

3, ROLLFORWARD command

The ROLLFORWARD command is performed after executing a restore command to recover the database or its table space. The rollforward command requires sysadm, sysctrl, or sysmaint privileges, and the database must be able to recover forward.

The ROLLFORWARD command can be applied to the entire database or one or more tablespaces, and their status is ponding. If the entire database is returned forward, this process must be offline, and the database can be restored to any time period in the backup time and the current time. If only separate tablespaces are only recovering, this process can be both online or offline, but the table space must be returned to the current time, and the submission operation that causes changes will be re-executed, which ensures The restored table space and other parts in the database are consistent. The ROLLFORWARD command syntax is:

Rollforward Database Database Name [to {Time, End of Logs] [TableSpace {Online, Table Space Name]

Here is some examples of rollforward commands:

(1) This example restores the MYDB database to the current time. The words and stop is to let the database are not set to the ROLLFORWARD PENDING state, and can be accessed:

Rollforward Database Mydb to End of Logs and Stop

(2) The following example restores the MYDB database forward and re-executes all the transactions submitted before the specified date and time:

Rollforward Database MyDB to 2000-09-26-10.3059 and stop

(3) The following example only restores a table space in the database myDB. This command is issued after executing a tablespace level, which is only applicable to the recovered table space. This command indicates that the forward recovery is online, and to the current time (the end of the log):

Rollforward Database Mydb to End of Logs and Stop TableSpace Online

Note: If there are some columns in the database, they are created with the NOT Logged option, then the update operations for these columns are not recorded in the log, and the forward recovery will not do these columns. operating. If you encounter a column without a log in the forward recovery process, their values ​​are set to zero 0.

转载请注明原文地址:https://www.9cbs.com/read-5356.html

New Post(0)