You are on page 1of 19

DB2 UTILITIES

DB2 ONLINE UTILITIES


DB2 Online Utilities

• UNLOAD
• LOAD
• REBUILD
• COPY
• RECOVER
• RUNSTATS
• MODIFY RECOVERY
• QUIESCE
• REORG
UNLOAD Utility:
Following are the tasks of the UNLOAD utility

Unload the data from Table


Unload the data from Image copy data set
Select the data by using SQL Select statement

Unload Utility : Example

• UNLOAD TABLESPACE DSN8D71A.DSN8S71E


FROM TABLE DSN8710.EMP

• UNLOAD TABLESPACE DSN8D71A.DSN8S71E


FROM TABLE DSN8710.EMP
(EMPNO, LASTNAME, SALARY DECIMAL EXTERNAL)
• Unloading data from an image copy:

UNLOAD TABLESPACE DATABASE.TABLESPACE


FROMCOPY (image copy DATASET)
PUNCHDDN SYSPUNCH UNLDDN SYSREC

SAMPLE UNLOAD JCL

• //SYSREC00 DD DSN=UD330574.UNLOAD.REC,
// DISP=(,CATLG),
// SPACE=(TRK,(100,20),RLSE),
// UNIT=SYSDA
//SYSPUNCH DD DSN=UD330574.UNLOAD.PUN,
// DISP=(,CATLG),
// SPACE=(CYL,(5,1),RLSE),
// UNIT=SYSDA
//SYSIN DD *
SELECT * FROM DB0KNRX0.TABLE24;
CREATOR NAME.TABLE NAME.
LOAD :

• Use Load utility to load one or more tables of a tablespace. The load utility loads
records into the tables and builds or extends any indexes that are defined on them .

• If the table space already contains data , you can choose whether you want to add the
new data to the existing data or replace the existing date

• LOAD operates on a table space level, so you must have authority for all tables in the
table space when you perform LOAD.

• NOCOPYPEND
Specifies that LOAD is not to set the table space in the COPY-pending status
• RESUME
Indicates whether records are to be loaded into an empty or non-empty table
Space
• RESUME YES
Loads records into a non-empty table space.

• RESUME NO
Loads records into an empty table space.

• REPLACE
Indicates whether the table space and all its indexes need to be reset to empty
before NEW records are loaded.
• 7 Example 1:

• Example of a LOAD statement that specifies field positions RESUME YES

• Sample JCL :

• LOAD DATA
• RESUME YES
• INTO TABLE DSN8910.DEPT
(DEPTNO POSITION (1:3) CHAR(3),
• DEPTNAME POSITION (4:39) CHAR(36),
MGRNO POSITION (40:45) CHAR(6),
ADMRDEPT POSITION (46:48) CHAR(3),
LOCATION POSITION (49:64) CHAR(16))
• Example 2:

• Example of a LOAD statement that specifies REPLACE

o The following control statement specifies that data from the data set that is defined
by the SYSREC DD statement is to be loaded into the table DSN8810.DEPT.

• LOAD DATA INTO TABLE DSN8910.DEPT REPLACE


REBUILD INDEX :
The REBUILD INDEX utility reconstructs indexes

• Rebuilding all the indexes of a Table space:

REBUILD INDEX (ALL) TABLESPACE DSNAME.TSNAME

• Rebuilding index:

REBUILD INDEX (DSN8810.XDEPT1)


COPY Utility
Creates backup copies of a tablespace

Reset copy pending status

Two types:
Full image copy
Incremental image copy

• Full Image copy – Which is a copy of all pages in table space, index
space

• Incremental Image copy – Which is a copy only of those data pages that
have been modified since the last use of the copy utility and system pages
• Rows will be inserted into SYSIBM.SYSCOPY catalog table that describes the image
copy data sets that are available to the RECOVER utility .
• The RECOVER utility uses these copies when recovering a table space or index space
to the most recent time
• Before running COPY, check that the table spaces and index spaces that you
want to copy are not in any restricted states.
Example Full image copy

Sample JCL :

//STEP1 EXEC DSNUPROC,UID='IUJMU111.COPYTS',


//SYSTEM='DDDD'
//SYSCOPY DD DSN=COPY001F.IFDY01,UNIT=SYSDA,
// SPACE=(CYL,(15,1)),DISP=(NEW,CATLG,CATLG)
//SYSIN DD *

COPY TABLESPACE DSN8D91A.DSN8S91E FULL YES


/*
Example Incremental image copy

Sample JCL :

//STEP1 EXEC DSNUPROC,UID='IUJMU111.COPYTS',


//SYSTEM='DDDD'
//SYSCOPY DD DSN=COPY001F.IFDY01,UNIT=SYSDA,
// SPACE=(CYL,(15,1)),DISP=(NEW,CATLG,CATLG)
//SYSIN DD *

COPY TABLESPACE DSN8D91A.DSN8S91E FULL NO


/*
RECOVER Utility
• The online RECOVER utility recovers data to the current state or to a previous
point in time by restoring a copy and then applying log records.

• Recovering Tablespace to a Image copy specified by the user

RECOVER TABLESPACE DSNAME.TSNAME

TOCOPY DB2P.FULLCOPY.DATASET.D090909

• Recovering a table space to the last image copy that was taken

RECOVER TABLESPACE DSN8D81A.DSN8S81D TOLASTCOPY

• Recovering Tablespace to a last full image copy Image copy.

RECOVER TABLESPACE DSN8D81A.DSN8S81D TOLASTFULLCOPY


• RUNSTATS

• The RUNSTATS utility gathers summary information about the characteristics of data
in table spaces, indexes, and partitions.

• DB2 records these statistics in the DB2 catalog and uses them to select access paths
to data during the bind process.

• Need to run RUNSTATS when


o a table is loaded
o a table is reorganized
o an index is created
o extensive modifications done on tablespace
Example 1:

Updating catalog statistics for a table space

• RUNSTATS TABLESPACE DSNAME.TSNAME1 TABLE(ALL)


INDEX(ALL)

• Example 2:
Updating index statistics

• RUNSTATS INDEX (DSNAME.INDEX1)

• Example 3:

Updating all statistics and generating a report.

• RUNSTATS TABLESPACE DSNAME.TSNAME1 REPORT YES UPDATE ALL


MODIFY RECOVERY :

• The MODIFY utility with the RECOVERY option deletes records from the
SYSIBM.SYSCOPY catalog table, related log records from the
SYSIBM.SYSLGRNX directory table.

• Run Modify regularly to remove outdated information from SYSIBM.SYSCOPY and


SYSIBM.SYSLGRNX . By deleting outdated information from these tables, you can
help improve performance for processes that access data from these tables.

• You can remove records that were written before a specific date, or you can
remove records of a specific age. You can delete records for an entire table
space, partition, or data set.

• Does not delete any “IC dataset “


• Example 1:

• Deleting SYSCOPY records that are older than a certain date.

• MODIFY RECOVERY TABLESPACE DBNAME.TSNAME DSNUM 3 DELETE


DATE(20090310)

• Any records in partition 3 that were written before 10 March 2009

• Example 2 :

• Deleting SYSCOPY records for partitions.

• MODIFY RECOVERY TABLESPACE DBNAME.TSNAME DSNUM 2 DELETE AGE(5)

• Any records in partition 2 that are older than 5 days


QUIESCE :
• The online QUIESCE utility establishes a Quiesce point for a tablespace
partition , tablespace set or list of tablespaces and tablespace sets.

• A Quiesce point is the current log RBA or Log Record Sequence Number(LRSN)
Quiesce then records the Quiesce point in the SYSIBM.SYSCOPY catalog table.

• A successful Quiesce improves the probability of a successful RECOVER or COPY.


You should run Quiesce frequently between regular executions of COPY to
establish regular recovery points

• A row with ICTYPE = ‘Q’ is inserted into SYSIBM.SYSCOPY for each tablespace that is
quiesced.
QUIESCE

• Example 1 :

• Sample JCL :

o //STEP1 EXEC DSNUPROC,UID='IUIQU2UD.QUIESC2', //


UTPROC='',SYSTEM='DSN'
o //SYSIN DD *
QUIESCE TABLESPACE DSN8D91A.DSN8S91D
o //*

o DSNU000I DSNUGUTC - OUTPUT START FOR UTILITY, UTILID = TEMP


o DSNU1044I DSNUGTIS - PROCESSING SYSIN AS EBCDIC
o DSNU050I DSNUGUTC - QUIESCE TABLESPACE DSN8D91A.DSN8S91D
o DSNU477I = DSNUQUIA - QUIESCE SUCCESSFUL FOR TABLESPACE DSN8D91A.DSN8S91D
o DSNU474I = DSNUQUIA - QUIESCE AT RBA 000004E43B78 AND AT LRSN 000004E43B78
DSNU475I DSNUQUIB - QUIESCE UTILITY COMPLETE, ELAPSED TIME= 00:00:02
o DSNU010I DSNUGBAC - UTILITY EXECUTION COMPLETE, HIGHEST RETURN CODE=

Log Record Sequence Number(LRSN)


Relative byte address (RBA)
REORG utility

• The online REORG TABLESPACE utility reorganizes a table space to


improve access performance and to reclaim fragmented space.
• You can specify the degree of access to your data during reorganization,
and you can collect inline statistics by using the STATISTICS keyword
• Alter the physical space parameters for the tablespace

REORG Utility : Example

Reorganizing a table space

REORG TABLESPACE DSN8D81A.DSN8S81D

Reorganizing a tablespace partition :

REORG TABLESPACE DSN8D81A.DSN8S81E


PART 3

REORG TABLESPACE DSN8D81A.DSN8S81E


PART 3:5
• Reorganizing a table space and specifying the unload data set.

REORG TABLESPACE (DSNAME.TSNAME1) UNLDDN (UNLD)

• Reorganizing a range of partitions and taking the Inline copies

REORG TABLESPACE DSNNAME.TSNAME1 PART 3:5


COPYDDN SYSCOPY

• Reorganizing a partition and updating the statistics.

REORG TABLESPACE DSNAME.TSNAME1 STATISTICS PART

You might also like