+ All Categories
Home > Documents > DB2UDB_the_Basics Day 5

DB2UDB_the_Basics Day 5

Date post: 24-Jan-2017
Category:
Upload: pranav-prakash
View: 170 times
Download: 0 times
Share this document with a friend
33
IBM Software Group © 2005 IBM Corporation DB2 UDB Intermediate Day5
Transcript

IBM Software Group

© 2005 IBM Corporation

DB2 UDB Intermediate

Day5

IBM Software Group

© 2005 IBM Corporation

Topics

Backup Restore Load Import

2

IBM Software Group

© 2005 IBM Corporation

BACKUP

You can choose to backup entire database or one or more table spaces from within the database.

You can also choose whether you want the backup to be taken online or offline.

These options can be combined to give you a very flexible recovery mechanism for your databases.

3

IBM Software Group

© 2005 IBM Corporation

Online and Offline Backup

An online backup allows other applications or processes to connect to the database as well as read modify the data while the operation is running.

An offline backup does not allow other applications or processes to access the database and their objects while the operation is being performed.

4

IBM Software Group

© 2005 IBM Corporation

Database Backup

5

A database backup is a complete copy of your database objects. In addition to the data, a backup copy contains information about the table spaces, containers, the system catalog,database config file, the log control file, and the recovery history file.

Important note is that a backup does not contain the dbm cfg file or the value of registry variables.

You must have SYSADM, SYSCTRL, or SYSMAINT authority to perform a backup.

IBM Software Group

© 2005 IBM Corporation

Commands for Backup

6

db2 backup db dbname

Db2 backup sample

to /db2backup/dir1, /db2backup/dir2

WITH 4 BUFFERS

BUFFER 4096

PARALLELISM 2

• There is no keyword for OFFLINE in the syntax, as this is the default mode.

IBM Software Group

© 2005 IBM Corporation

Db2 BACKUP DATABASE sample ONLINE TO /dev/rdir1, /dev/rdir2

INCLUDE LOGS

db2 backup db test on all dbpartitionnums db2 backup db test on dbpartitionnums (0, 3) db2 backup db test on all dbpartitionnums except dbpartitionnums

(1,2) db2 backup db test on all dbpartitionnums online INCLUDE LOGS

7

IBM Software Group

© 2005 IBM Corporation

Table Space Backup

8

In a database where only some of your table spaces change considerably, you may opt not to back up the entire database but only specific table spaces. To perform a table space backup, you can use the following syntax.

Db2 BACKUP DATABASE sample TABLESPACE (syscatspace, userspace1, userspace2) ONLINE TO /db2tbsp/backup1, /db2tbsp/backup2

IBM Software Group

© 2005 IBM Corporation

Types of Backup

An incremental backup is a backup image that contains only pages that have been updated since the previous backup was taken.

In delta backups, DB2 backs up only the data that has changed since the last successfull, cumulative, or delta backup.

For incremental backups, if there was a crash after the incremental backup on Friday, you would restore the first Sunday’s full backup, followed by the incremental backup taken on Friday.

For delta backups, if there was a crash after the delta backup on Friday, you would restore the first Sunday’s full backup, followed by each of the delta backups taken on Monday through Friday inclusive.

9

IBM Software Group

© 2005 IBM Corporation

Incremental and Delta Backup

10

IBM Software Group

© 2005 IBM Corporation

Trackmod Parameter

To enable incremental and delta backups, the TRACKMOD database configuration parameter must be set to YES. This allows DB2 to track database modifications so that the backup utility can detect which database pages must be included in the backup image. After setting this parameter to YES, you must take a full database backup to have a baseline against which incremental backups can be taken.

BACKUP DB sample INCREMENTAL TO /dev/ BACKUP DB sample INCREMENTAL DELTA TO /dev/rdir1

11

IBM Software Group

© 2005 IBM Corporation

Backup Files

The backup images are stored as files. The name of the backup file contains the following parts:

• Database alias

• Type of backup (0=Full database, 3=Table space, 4=Copy from LOAD)

• Instance name

• Database partition (always NODE0000 for a single-partition database)

• Catalog partition number (always CATN0000 for a single-partition database)

• Timestamp of the backup

• The image sequence number

12

IBM Software Group

© 2005 IBM Corporation

Backup file sample

13

IBM Software Group

© 2005 IBM Corporation

Restore

You can restore a database backup image and create a new database or you can restore over top of an existing database. You need SYSADM, SYSCTRL, or SYSMAINT authority to restore into an existing database, and SYSADM or SYSCTRL authority restore to a new database.

RESTORE DATABASE sample FROM C:\DBBACKUP

TAKEN AT 20070428131259

WITHOUT ROLLING FORWARD

WITHOUT PROMPTING

14

IBM Software Group

© 2005 IBM Corporation

If database has archival log enabled .a restore operation puts the database in to roll forward pending state. Regardless of whether the backup was online or offline .

RESTORE DATABASE sample FROM C:\DBBACKUP

LOGTARGET C:\DB2\NODE0000\SQL00001\SQLOGDIR

Table space Restore : RESTORE DATABASE sample (1) TABLESPACE ( mytblspace1 ) (2) ONLINE (3) FROM /db2tbsp/backup1, /db2tbsp/backup2 (4)

15

IBM Software Group

© 2005 IBM Corporation

DB2 IMPORT UTILITY

The import utility inserts data from an input file into a table or a view. The utility performs inserts as if it was executing INSERT statements.

import from employee.ixf of ixf

messages employee.out

insert into employee

Messages option is used to record error, warning messages as well as the import status.

16

IBM Software Group

© 2005 IBM Corporation

Import Modes

17

IBM Software Group

© 2005 IBM Corporation

Some useful options for Import Utility

warningcount Rowcount

1. import from employee.del of del messages empsalary.out

warningcount 10 replace into empsalary (salary, bonus, comm)

2. import from employee.ixf of ixf messages employee.out

rowcount 1000 replace_create into newemployee

3. import from employee.ixf of ixf messages newemployee.out

create into newemployee in datats index in indexts

18

IBM Software Group

© 2005 IBM Corporation

More Useful options for Import

allow write access – to allow concurrent read/write access to tables.

allow no access- table will be locked exclusively. commit count – to enforce a commit after every n records imported.

Example :import from employee.ixf of ixf

commitcount 1000

messages newemp.out

create into newemployee in datats index in indexts

19

IBM Software Group

© 2005 IBM Corporation

Output of log file

20

IBM Software Group

© 2005 IBM Corporation

Restarting failed Import

If you have import failures due to invalid input, for example, you can use the message file generated from an import command that uses the commitcount and messages options to identify which record failed. Then you could issue the same import command with restartcount n or skipcount n to start the import from record n+1. This is a very handy

method to restart a failed import. Here is an example:

import from employee.ixf of ixf commitcount 1000

skipcount 550

messages newemployee.out

create into newemployee in datats index in indexts

21

IBM Software Group

© 2005 IBM Corporation

Load Utility

In db2, Load process completes in 4 phases:

• Load

• Build

• Delete

• Index copy

22

IBM Software Group

© 2005 IBM Corporation

Load Phase

During the load phase, the load utility scans the input file for any invalid data rows that do not comply with the table definition; for example, if a table column is defined as INTEGER but the input data is stored as “abcd”. Invalid data will not be loaded into thetable. and index keys are also collected.

23

IBM Software Group

© 2005 IBM Corporation

Build Phase

During the build phase, indexes are produced based on the index keys collected during the load phase. The index keys are sorted during the load phase, and index statistics are collected (if the statistics use profile option was specified).

24

IBM Software Group

© 2005 IBM Corporation

Delete Phase

In the load phase, the utility only rejects rows that do not comply with the column definitions.

Rows that violated any unique constraint will be deleted in the delete phase.

Note that only unique constraint violated rows are deleted. Other constraints are not checked during this phase or during any load phase. You have to manually check it after the load operation is complete.

25

IBM Software Group

© 2005 IBM Corporation

Index Copy Phase

During the index copy phase, index data is copied from a system temporary table space to the original table space. This will only occur if a system temporary table space was specified for index creation during a load operation with the read access option

26

IBM Software Group

© 2005 IBM Corporation

Messages , Savecount and Warning count Option

messages option is used to record warnings and errors encountered during the load operation.

The savecount option establishes consistency points after every 1,000 rows are loaded.

Warningcount option will stop when the threshold of warnings is encountered.

load from stock.del of del

savecount 1000

warningcount 10 messages stock.out

insert into stock(itemid, itemdesc, cost, inventory)

27

IBM Software Group

© 2005 IBM Corporation

Restart and Termination of Load Utility

Consistency points are established during the load phase. You can use them to restart a failed or terminated load operation. By specifying the same load command but replacing insert with the restart option, the load operation will automatically continue from the last consistency point.

To terminate a load, issue the same load command but use the terminate option in place of insert;

load from stock.del of del

savecount 1000

warningcount 10

messages stock.out terminate

28

IBM Software Group

© 2005 IBM Corporation

Modified by dumpfile option

load from stock.ixf of ixf modified by dumpfile=stockdump.dmp messages stock.out replace into stock

29

IBM Software Group

© 2005 IBM Corporation

As mentioned earlier, the load process goes through four phases. During the load phase, data that does not comply with the column definition will not be loaded. Rejected records can be saved in

a dump file by using the modified by dumpfile modifier. If dumpfile is not specified,

rejected records are not saved. Since the load utility will not stop unless it reaches the warning

threshold if one is specified, it is not easy to identify the rejected records. Hence, it is always a good practice to use the modifier and validate the message file after a load is completed.

30

IBM Software Group

© 2005 IBM Corporation

Important Point

The load utility checks for invalid data and unique constraints during the load process. However, other constraints such as referential integrity and check constraints are not validated. DB2 therefore puts target tables defined with these constraints in check pending state. This forces you to manually validate the data before the tables are available for further processing

31

IBM Software Group

© 2005 IBM Corporation

The COPY YES/NO Options

Recall that changes made to the target tables during the load are not logged. This is one of the characteristics of the load utility that improves performance. However, it also takes away the ability to perform roll forward recovery for the load operation. DB2 puts the table space where the target table resides in backup pending state when the load operation begins.

After the load completes, you must back up the table space or database. This ensures that the table space can be restored to the point where logging is resumed . This is the behavior of the load option copy no.

You can also specify copy yes if archival logging is enabled. With copy yes, a copy of the loaded data will be saved and the table space will not be in backup pending state upon load completion.

32

IBM Software Group

© 2005 IBM Corporation

Thank You

33


Recommended