DB2 Utilities

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

All rights reserved.

Reproduction and/or distribution in whole or in


part in electronic, paper or other forms without written permission
is prohibited.

DB2 ReferencePoint Suite


SkillSoft Corporation. (c) 2002. Copying Prohibited.

Reprinted for Juan Carlos Viera, EDS Web Universities/Training


[email protected]

Reprinted with permission as a subscription benefit of Books24x7,


http://www.books24x7.com/
i

Table of Contents
Point 2: DB2 Utilities........................................................................................................................1

Online Utilities...................................................................................................................................2
Data Consistency Utilities.......................................................................................................2
Data Organization Utilities......................................................................................................6
Backup and Recovery Utilities................................................................................................8
Catalog Manipulation Utilities................................................................................................12

Offline Utilities................................................................................................................................15
Change Log Inventory Utility.................................................................................................15
Print Log Map Utility..............................................................................................................15
The DB2 Log Preformat Utility..............................................................................................16

Miscellaneous Utilities...................................................................................................................17
Online Utilities.......................................................................................................................17
Offline Utilities.......................................................................................................................19

Related Topics................................................................................................................................20
Point 2: DB2 Utilities
Shweta Bashani
DB2 provides utilities that help structure data in its databases. These utilities also help create
backup and recover application data. You can also use these utilities to assemble statistical
information about DB2 databases.

DB2 provides both online and offline utilities. Online utilities work only when the DB2 environment is
active. The offline utilities do not require DB2 to be active at the time of execution.

This ReferencePoint explains the various DB2 utilities with their syntax. In addition, it covers various
scenarios in which these utilities can be put to use.

Reprinted for dzpkhz, EDS Web Universities/Training SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited
Online Utilities
The DB2 environment should be active during the execution of an online utility. Online utilities use
individual attach mechanisms to connect with DB2, instead of running under the Terminal Monitor
Program (TMP) of DB2.

To run a utility, you need to generate a control statement that identifies the task that the utility has to
perform. When an online utility is running, the SYSIN DD input statement obtains the control
statement for the utility.

DB2 utilities allow the concatenation of input datasets with varying block sizes, record lengths, or
applied formats. This is not permitted for output datasets.

There are four types of online utilities:

• Data consistency utilities

• Data organization utilities

• Backup and recovery utilities

• Catalog manipulation utilities

Data Consistency Utilities


Data consistency utilities are used to check and maintain data consistency of a database to ensure
referential integrity between DB2 tables. You can use data consistency utilities to ensure that data
values remain within the domains and the indexes correspond to the values in a DB2 table.

There are four data consistency utilities:

• CHECK

• REPAIR

• REPORT

• DIAGNOSE

The CHECK Utility

The CHECK utility verifies the integrity of DB2 data structures. It also verifies that the data values
adhere to the specified table constraints, the joined tables follow the specified rules, and the
indexes correspond to the data. For example, you could specify that a field as not NULL while
designing a table. This means the column corresponding to that field in the table cannot have any
NULL values.

The CHECK utility is used to check whether the data in the table matches the specified criteria and
the applied restriction. This utility is used with two options − CHECK DATA and CHECK INDEX.

Reprinted for dzpkhz, EDS Web Universities/Training SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited
DB2 ReferencePoint Suite 3

The CHECK DATA option checks the violation of the referential integrity rules between two tables. It
also checks whether data values conform to the data validation constraints applied to the table
space that is specified with the utility command. For example, if two tables EMP and DEPT are
joined with the data field dept_no, the utility will check whether the values in both tables correspond
with each other. If the utility detects any error, it will report the error and possibly resolve it.

The utility can be run for a single or multiple table space or for a specific partition of a table space. If
the utility encounters any violation, it deletes the invalid rows of data or copies them to an exception
table. The table space being checked is placed in the CHECK−pending status. After reporting and
solving the errors, the CHECK−pending status is reset.

The CHECK DATA option runs after a conditional restart or when the base tables do not correspond
to each other. Some scenarios in which this utility works are:

• When a table is loaded without the ENFORCE CONSTRAINT option. This option of the
LOAD utility implements the constraints that were defined when the table was created.

• When a check constraint is added in an existing table and it violates the existing data.

• When the CHECK DATA utility detects any violation of the data integrity rules, while deleting
rows of erroneous data during its execution. You can run the utility again to fix the problem.

• When you need to perform partial recovery of the table spaces that are referentially joined.

• When the reliability of data that binds the table spaces referentially needs to be checked.

• When the CHECK−pending status of the table space is to be removed for future access and
use of data.

Listing 5−2−1 shows an example of the CHECK DATA utility:

Listing 5−2−1: CHECK DATA Utility


//SYSIN DD *
CHECK DATA TABLESPACE DSN9D41A.DSN9S41D
FOR EXCEPTION IN DSN9410.DESIG
USE DSN9410.DESIG_EXCPTN
SCOPE ALL DELETE YES
//*

The above CHECK DATA statement works on the DSN9D41A.DSN9S41D table space. The utility
checks that the DSN9410.DESIG dataset meets all the referential constraints. If a violation is
encountered, the utility deletes all improper rows and puts them into the exception table
DSN9410.DESIG_EXCPTN.

Reprinted for dzpkhz, EDS Web Universities/Training SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited
DB2 ReferencePoint Suite 4

Note The CHECK DATA utility run parallel to the DIAGNOSE, MERGECOPY, MODIFY,
REPORT, and STOSPACE utilities.

The CHECK INDEX option is applied while checking the consistency of index data with its
corresponding table data. It detects and states the Record ID (RID) pointer errors if index keys are
absent or if they do not match with the table data. CHECK INDEX can function in the case of a full
index or a single index partition. You have to fix the problem using the RECOVER INDEX utility
because CHECK INDEX only detects and reports the invalid index entries.

You need to execute the CHECK INDEX option after every conditional restart or partial recovery
and before running CHECK DATA to ensure that the indexes that CHECK DATA uses are valid,
especially when the DELETE YES option is specified.

Listing 5−2−2 shows an example of the CHECK INDEX utility:

Listing 5−2−2: CHECK INDEX Utility


//SYSIN DD *
CHECK INDEX (ALL)TABLESPACE DSN9D41A.DSN9S41D
CHECK INDEX NAME (DSN9410.XDES1)
CHECK INDEX NAME (DSN9410.XDES2)
//*

In the above example, the first CHECK INDEX statement checks all the indexes for the
DSN9D41A.DSN9S41D table space. Subsequent CHECK INDEX statements check only specified
indexes, such as DSN9410.XDES1 and DSN9410.XDES2.

Note The CHECK INDEX utility is compatible with the CHECK DATA, LOAD, RECOVER,
REORG INDEX, REPAIR REPLACE, and REPAIR DELETE utilities.

The REPAIR Utility

The REPAIR utility repairs or fixes data in tables and their related data structures. The data can be
of any type, such as data contained in a table or data that is generally not accessed, such as map
pages and index entries. The options of the REPAIR utility are:

• REPAIR DBD: Tests Database Descriptors (DBDs) that point to corresponding data items in
the DB2 catalog database.

• REPAIR SET: Resets pending flags that are no longer necessary.

• REPAIR LOCATE: Changes the data at specified locations of a dataset. The result of a
REPAIR utility usually contains the altered page or pages in the specified DB2 table or index
and a dump of the contents. The REPAIR utility with the Log YES option can be used to
ensure that all changes made are logged and recovered. The REPAIR utility should be
carefully used because it substitutes the existing data with new data.

Listing 5−2−3 shows an example of the REPAIR utility:

Listing 5−2−3: REPAIR Utility


//SYSIN DD *
Reprinted for dzpkhz, EDS Web Universities/Training SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited
DB2 ReferencePoint Suite 5

REPAIR OBJECT
LOCATE TABLESPACE DSN9D41A.DSN9S41D PAGE X'05'
VERIFY OFFSET 50 DATA X'A00'
REPLACE OFFSET 50 DATA X'D11'
DUMP OFFSET 50 LENGTH 4
//*

The above REPAIR statement alters the data on the fifth page at offset 50 from its initial value
XA00 to XD11. The utility statement first checks whether or not the location matches the value
XA00 and then modifies the data by replacing it with the new data specified. The four characters
are dumped to ensure that the changes made are correct.

The REPORT Utility

The REPORT utility produces two types of reports:

• Tablespace set report: Contains the names of the table spaces and the tables joined by
referential integrity.

• Recovery report: Contains information that is fundamental for the recovery of tables and its
indexes.

REPORT TABLESPACESET is useful for documentation as well as the validation of DB2 objects
according to referential integrity rules.

REPORT RECOVERY is useful when information related to the recovery of a table space is
required.

Listing 5−2−4 shows an example of the REPORT TABLESPACESET option:

Listing 5−2−4: REPORT TABLESPACESET Option


//STEP1 EXEC DSNUPROC,UID='REPORT02',
// UTPROC='',SYSTEM='DSN'
//SYSIN DD *
REPORT TABLESPACESET TABLESPACE DSN9D41A.DSN9S41D
//*

The above REPORT statement operates on DSN9D41A.DSN9S41D table space. The utility
produces a report of names of all table spaces that are referentially linked with the specified table
space.

THE DIAGNOSE Utility

The DIAGNOSE utility is useful in identifying problems with other utilities. It is used to format the
information in SYSIBM.SYSUTILX for printing.

An example of the DIAGNOSE utility is:


//DSNUPROC.SYSIN DD *
DIAGNOSE DISPLAY SYSUTILX
//*

The preceding DIAGNOSE statement displays all rows in the SYSIBM.SYSUTIL DB2 Directory
table.

Reprinted for dzpkhz, EDS Web Universities/Training SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited
DB2 ReferencePoint Suite 6

Data Organization Utilities


Data organization utilities control the physical structuring of DB2 objects and the datasets
associated with these objects. The utilities affect the actual rows of data and the sequence of data
in a table space, or dataset of a table space. Two data organization utilities are LOAD and REORG.

The LOAD Utility

The LOAD utility loads data in a table space or in the dataset of a table space. It also performs the
following tasks:

• Loading bulk data in a new table of a table space.

• Inserting data into an existing table to preserve the existing data integrity.

• Appending the existing table with fresh rows of data.

The LOAD utility is governed by two principles. The first principle sets aside sufficient Direct Access
Storage Device (DASD). This is used to record the LOAD work datasets that are useful when the
execution of a utility is stopped. The second principle does not allow additional DASD and the work
datasets are treated as temporary, resulting in loss of datasets.

The LOAD utility can work in the following scenarios:

• To append or replace bulk rows by using the REPLACE option or the RESUME (YES)
option, respectively.

• To delete all rows from a non−segmented table space by specifying an empty input dataset.

• To insert data in a DB2 table for the first time by using LOAD in place of lengthy application
program code.

Listing 5−2−5 shows a sample JCL coding of the LOAD utility:

Listing 5−2−5: LOAD Utility


//SYSIN DD *
LOAD DATA INDDN(SYSRECAC) RESUME YES
INTO TABLE DSN9D41A.ACT
(ACTNO POSITION( 1) INTEGER EXTERNAL(3),
ACTKWD POSITION( 5) CHAR(6),
ACTDESC POSITION(13) VARCHAR)
ENFORCE NO
//*

The above LOAD DATA statement adds the data from the SYSRECAC file to the table
DSN9D41A.ACT. The RESUME YES option is used to load records in a nonempty table. If the table
space is empty, the loading is resumed after a warning message.

Reprinted for dzpkhz, EDS Web Universities/Training SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited
DB2 ReferencePoint Suite 7

Note The LOAD utility can run simultaneously with the DIAGNOSE, MODIFY
STATISTICS, REPORT, and STOSPACE utilities.

The REORG Utility

The REORG utility is used to reorganize table spaces and indexes to increases the efficiency of
accessing DB2 objects. The utility includes:

• A RUNSTAT job for registering information on the active table space or indexes in the DB2
catalog so that the DB2 optimizer can determine the access path.

• Two copy jobs − one before running the REORG utility and the other after running the
REORG utility to ensure that the data can be recovered.

• A REBIND job to set a new access path based on the latest statistics supplied by
RUNSTATS.

The REORG utility works at two levels − index and table space.

The REORG INDEX utility reorganizes index space, which improves data accessibility and the
ability to retrieve fragmented space. The STATISTICS keyword helps define the statistics for
accessing and assembling online statistics.

The REORG TABLESPACE utility reorganizes a table space to enhance the access and retrieval of
data. The utility can work on a single partition or an array of partitions of the partitioned table space.
The utility can also delete rows if the DISCARD option is specified using REORG TABLESPACE.

The REORG utility is used when you to need to:

• Reorganize several partitions of a partitioned table space concurrently. Using the REORG
utility on different partitions requires less time than the time taken to run a single REORG
utility for the entire partitioned table space.

• Reallocate and move datasets that are classified in STOGROUP.

• Ensure a cost−effective system performance, REORG INDEX can be run on a table space.

Listing 5−2−6 shows an example of the REORG utility:

Listing 5−2−6: REORG Utility


//DSBUPROC.SYSIN DD *
REORG TABLESPACE DSN9D41A.DSN9S41D SORTDATA
REORG INDEX DSN9D41A.XACTL1
SHRLEVEL REFERENCE STATISTICS
//*

The first REORG statement reorganizes the table space DSN9D41A.DSN9S41D while the second
statement reorganizes the specified index. The option SHRLEVEL REFERENCE allows
simultaneous read access during both the UNLOAD and RELOAD phases of the REORG utility.
The STATISTICS keyword enables the utility to collect the online statistics of the specified index.
Reprinted for dzpkhz, EDS Web Universities/Training SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited
DB2 ReferencePoint Suite 8

Note REORG is governed by the same principles as the LOAD utility. The first principle is
recommended for the REORG facility also.

Backup and Recovery Utilities


The backup and recovery utilities include the COPY utility, the MERGECOPY utility, the QUIESCE
utility, the RECOVER utility, and the REPORT RECOVERY utility.

The COPY Utility

The COPY utility produces image copies or backup datasets for DB2 objects, such as table spaces,
table space partitions, datasets of table spaces, and index space or index partitions. You can create
two types of image copies:

• Full image copy: A complete copy of all the pages of data that are stored in the table space,
partition, dataset, or index that is being copied.

• Incremental image copy: A copy of only those pages of data that have been modified since
the last full or incremental image copy was generated.

The COPY utility generates up to four image copies of the dataset. After each image copy is
created, the SYSIBM.SYSCOPY catalog table is updated with the information specifying the status
of the image copy. This information can later be used by the RECOVER utility to recover objects.

If a full image copy is made, the COPY−pending status is set to off. DB2 does not reset this status if
only a single piece of a dataset is copied. If a single partitioned table space is copied, the
COPY−pending status is reset only for the partition that is copied and not the entire table space.

Before issuing a COPY utility, you should:

• Check the table space status because a table cannot be copied if it is in a COPY−pending or
RECOVER−pending status.

• Reset the status, if a table space is in a COPY−pending status or an index is in informational


COPY−pending status. To do this, take a full image copy of the entire table space with all its
partitions and indexes.

• Create a full image copy of the entire table space, if a non−partitioned table space is in a
COPY−pending status. This is a better approach than making full image copies of individual
datasets to fix the problem.

You can generate copies using the COPY utility in the following situations:

• If the table space is large and the number of modifications made is less, an incremental
image copy works well.

• If 40 percent or more pages of a table space need to be modified, a full image copy can be
used.

Reprinted for dzpkhz, EDS Web Universities/Training SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited
DB2 ReferencePoint Suite 9

• If data has to be accessed in a sequence, a full image copy works faster than an incremental
image copy by sequentially reading the pages of a table space.

An example of the COPY utility is:


//DSNUPROC.SYSIN DD *
COPY TABLESPACE DSN9D41A.DSN9S41D
//*

The above example creates a full image copy of the table space DSN9D41A.DSN9S41D.
//DSNUPROC.SYSIN DD *
COPY TABLESPACE DSN9D41A.DSN9S41D
SHARELEVEL REFERENCE FULL NO
//*

The example above produces an incremental image copy. The use of the SHARELEVEL
REFERENCE option reduces the time required for table space recovery.

The MERGECOPY Utility

The MERGECOPY utility merges or unites several image copies to generate a new image copy.
The utility can make image copies produced by the COPY utility or inline copies produced by LOAD
or the REORG utility as input. It can accept inputs in two ways to provide different results:

• Numerous incremental image copies to give a new incremental image copy.

• Numerous incremental image copies with a full image copy to create a new full image copy.

The MERGECOPY utility does not run on original table spaces but only on the image copy datasets
of table spaces. Listing 5−2−7 shows an example of the MERGECOPY utility:

Listing 5−2−7: MERGECOPY Utility


//DSNUPROC.SYSIN DD *
MERGECOPY TABLESPACE DSN9D41A.DSN9S41D
NEWCOPY YES COPYDDN COPY1
//*
//DSNUPROC.SYSIN DD *
MERGECOPY TABLESPACE DSN9D41A.DSN9S41D
NEWCOPY NO COPYDDN COPY2
//*

The above MERGECOPY statements create a full and an incremental copy for the DSN9D41A
table space, respectively. The NEWCOPY option with a YES creates a full image copy. An
incremental image copy is made when NO is specified.

Reprinted for dzpkhz, EDS Web Universities/Training SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited
DB2 ReferencePoint Suite 10

Note The utility can run parallel with the COPY, MERGECOPY, MODIFY RECOVERY,
and RECOVER utilities.

The QUIESCE Utility

The QUIESCE utility determines a consistency point known as the quiesce point for related table
spaces and updates this information in the catalog table SYSIBM.SYSCOPY. A quiesce point refers
to the current RBA log information of a table space, datasets of a table space, or a partition of a
table space. The successful completion of this utility makes it easier to ascertain the referential
integrity between the table spaces. The RECOVER or COPY utility can utilize the recovery points
documented by the QUIESCE utility for future recoveries.

The QUIESCE utility can be used to:

• Set up provisional points of recovery between frequently planned image copies, which will
help the RECOVER and COPY utilities.

• Ensure that referentially joined tables maintain data integrity. The tables may possibly be
combined using the rules determined by DB2 or by the application code.

• Facilitate the recovery of table spaces that are regularly modified online until the last full
image copy is made.

• Regulate the backup and recovery policy of a DBA and execute the QUIESCE utility at the
partition level.

An example of the QUIESCE utility is:


//DSNUPROC.SYSIN DD *
QUIESCE TABLESPACESET TABLESPACE DSN9D41A.DSN9S41D
//*

The above QUIESCE statement establishes a quiesce point for the table space set specified in the
statement.

Note QUIESCE is compatible with the CHECK INDEX, DIAGNOSE, MERGECOPY, MODIFY,
REORG UNLOAD ONLY, REPORT, RUNSTATS, STOSPACE, and REPAIR LOCATE
utilities.

The RECOVER Utility

The RECOVER utility helps recover data from the current or previous positions. This is done by
using the information related to data recovery. In addition, it helps make the desired changes with
respect to the directions of DBMS and the parameters specified with the RECOVER utility
command.

The utility can recover many DB2 objects, such as a single page, a complete table space, index or
index spaces, partitions, or datasets. While recovering an object, it uses the latest full image copy of
the object and the log records along with all the modifications. If the recent image copy is not
available, the utility uses the image copies prior to the latest copy.

The RECOVER utility can be applied at two levels, table space and index. The RECOVER
TABLESPACE option recovers or restores a table space back to its current state. The utility first
examines the DB2 catalog for a full or incremental image copy of the table space. It then studies the
DB2 logs to identify the changes and apply them to the table space.

Reprinted for dzpkhz, EDS Web Universities/Training SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited
DB2 ReferencePoint Suite 11

The RECOVER INDEX option restores or rebuilds indexes from the present data. The utility works
on the original table spaces or datasets and not on the image copies and log data. It examines the
entire table in which the index originates and recreates the index pertaining to the existing data.

The RECOVER INDEX utility needs to be executed regularly to check the validity of indexes,
especially when partial recovery has been made. Even if the DB2 catalog and DB2 Directory table
spaces and indexes are not rearranged, the RECOVER INDEX can be used to recover the indexes.

An example of the RECOVER utility is:


//DSNUPROC.SYSIN DD *
RECOVER TABLESPACE DSN9D41A.DSN9S41D
TOCOPY CAT.FULLCOPY.DATASET.G0002V00
//*

The RECOVER TABLESPACE utility statement above recovers the DSN9D41A.DSN9S41D table
space to the specified image copy dataset.
//DSNUPROC.SYSIN DD *
RECOVER INDEX (ALL) TABLESPACE DSN9D41A.DSN9S41D
RECOVER INDEX (DSN9410.XMNGR1)
//*

The first RECOVER INDEX statement rebuilds the indexes on tables in the DSN9D41A.DSN9S41D
table space and the next statement restores only the DSN9410.XMNGR1 index.

Note RECOVER TABLESPACE can run along with the DIAGNOSE, MODIFY
STATISTICS, REPORT, and STOSPACE utilities. RECOVER INDEX can execute
in parallel with the COPY SHRLEVEL REFERENCE, DIAGNOSE, MERGECOPY,
MODIFY, REPORT, RUNSTATS TABLESPACE, and STOSPACE utilities.

The REPORT RECOVERY Utility

The REPORT RECOVERY utility is the second type of the REPORT utility. This utility generates a
report on the recovery information of a table space present in the DB2 catalog, the DB2 Directory,
and the Boot Start Dataset (BSDS). The utility can work on a table space or within a single partition
of a table space.

In addition to the recovery information, the report includes information related to the image copies,
log RBA, and archive log of the specified table spaces. The report produced can be instrumental in
establishing the availability of backups for a table space and analyzing the requirements for making
backups and recovering table spaces.
The REPORT RECOVERY utility can run concurrently with all other DB2 utility. It is best suited
when the datasets required by the RECOVER utility have to be chosen and checked for availability.

Listing 5−2−8 shows an example of the REPORT RECOVERY utility:

Listing 5−2−8: REPORT RECOVERY Utility


//STEP1 EXEC DSNUPROC,UID='REPORT02',
// UTPROC='',SYSTEM='DSN'
//SYSIN DD *
REPORT RECOVERY TABLESPACE DSN9D41A.DSN9S41D
//*

The REPORT RECOVERY statement in the above example reports all the DB2 recovery
information related to the table space DSN9D41A.DSN9S41D.

Reprinted for dzpkhz, EDS Web Universities/Training SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited
DB2 ReferencePoint Suite 12

Catalog Manipulation Utilities


The DB2 catalog and the DB2 directory are essential parts of DB2. The DB2 catalog is the system
catalog on which DBMS places all its requirements for the description of every DB2 object. DB2
Directory stores all the necessary technical details pertaining to DB2 procedures.

The CATMAINT Utility

The CATMAINT utility updates the DB2 catalog while changing from one version or release of DB2
to another. The utility amends the organization of DB2 catalog by creating tables and indexes using
particular hashes and links in the DB2 catalog database.

While running this utility, it may succeed or fail. Changes are implemented, only after the utility runs
successfully. Changes are not implemented if the utility fails.

While executing the CATMAINT utility, the task of sorting is done by work file database. As a result,
to run the CATMAINT utility, you need to estimate the size of the work file database. The result of
the utility is usually an updated catalog. The catalog or directory indexes are not accessible to any
other task or utility during the execution of CATMAINT utility.

The MODIFY Utility

The MODIFY utility is used to clear the DB2 catalog and DB2 Directory tables by erasing
unnecessary and obsolete data rows. The utility can be used with two elements − MODIFY
RECOVERY and MODIFY STATISTICS.

MODIFY RECOVERY deletes rows containing information related to data recovery from both DB2
catalog and DB2 Directory. The utility either removes rows that are older than the number of days
specified, or the rows having date that is earlier than the specified date.

The MODIFY RECOVERY utility is run regularly to filter old recovery data that is no longer required.
The utility only deletes rows from the catalog tables SYSIBM.SYSCOPY and SYSIBM.SYSLGRNX.
As a result, the corresponding Log and image copy dataset are deleted separately.

Listing 5−2−9 shows an example of the MODIFY RECOVERY utility:

Listing 5−2−9: MODIFY RECOVERY Utility


//DSNUPROC.SYSIN DD *
MODIFY RECOVERY TABLESPACE DSN9D41A.DSN9S41D AGE(75)
MODIFY RECOVERY TABLESPACE
DSN9D41A.DSN9S41D DATE(921021)
//*

In the above code, the first statement deletes all the SYSCOPY information pertaining to the
DSN9D41A.DSN9S41D table space older than 75 days. The second statement deletes all the
information where the DATE is before October 21, 1992 for the specified table space.

Note MODIFY RECOVERY can run with the COPY, LOAD, MERGECOPY, MODIFY
RECOVERY, RECOVER, and REORG utilities.

MODIFY STATISTICS deletes Non−Uniform Distribution Statistics (NUDS) from relevant catalog
tables. NUDS are accumulated in SYSCOLDIST and SYSCOLDISTATS (version 3 onwards) or
SYSFIELDS (prior to version 3) system file(s).

The utility can work on the whole table space, index space, or index of a table space. It can delete
statistics that appear before a specified date.

Reprinted for dzpkhz, EDS Web Universities/Training SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited
DB2 ReferencePoint Suite 13

The MODIFY STATISTICS utility is of no use for DB2 version 3 and later because the system files
updated by the utility can be directly accessed using SQL. If a table space is in the
RECOVER−pending or CHECK−pending state, running the utility on the table space is not possible.

An example of the MODIFY STATISTICS utility is:


//DSNUPROC.SYSIN DD *
MODIFY STATISTICS TABLE DSN9410.DEPT
COLUMN (DEPTNO) DELETE NONUNIFORM
//*

In the code above, the utility statement deletes all SYSFIELDS information from the DEPTNO
column of the DSN9410.DEPT table.

The RUNSTATS Utility

The RUNSTATS utility is used to accumulate facts or information about DB2 objects, such as
tables, table spaces, partitions, and indexes. The RUNSTATS utility places this information in DB2
catalog tables to be used by DBA or the system administrator. At times, it generates only a report
containing these particulars.

The statistics recorded are useful in providing information about the organization to the DBA and in
assisting the DB2 optimizer to select an optimum access path for SQL queries.

RUNSTATS works with two formats, RUNSTATS TABLESPACE and RUNSTATS INDEX.

RUNSTATS TABLESPACE gathers information about tables for table spaces, indexes, and
columns. The RUNSTATS INDEX collects information of indexes only.

The RUNSTATS utility runs:

• After inserting new data or building a new index in a table.

• After a new column is added to a table that already contains data.

• After restructuring a table space.

• After modifying a particular table when many update, delete, and insertion commands are to
be issued.

• After the RECOVER utility is run on a table space or an index.

Listing 5−2−10 shows an example of the RUNSTATS utility:

Listing 5−2−10: RUNSTATS Utility


//SYSIN DD *
RUNSTATS TABLESPACE DSN9D41A.DSN9S41D TABLE (ALL)
INDEX(ALL)SHRLEVEL REFERENCE
RUNSTATS TABLESPACE DSN9D41A.DSN9S41E
TABLE(DSN9410.EMPDET)
COLUMN(FIRSTNM,LASTNM,SALARY,BONUS)
SHRLEVEL REFERENCE
/*
//

Reprinted for dzpkhz, EDS Web Universities/Training SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited
DB2 ReferencePoint Suite 14

In the above example, the first RUNSTATS statement collects statistics for all the tables in the
DSN9D41A.DSN9S41D table space. The second statement accumulates statistics related to the
specified columns of the DSN9410.EMPDET table in the table space.
//SYSIN DD *
RUNSTATS INDEX (DSN9410.XEMPDT)
/*
//

The preceding RUNSTATS INDEX statement gathers statistics for the DSN9410.XEMPDT index.

Note The RUNSTATS utility can run along with the CHECK INDEX, COPY, DIAGNOSE,
MERGECOPY, MODIFY, QUIESCE, REORG UNLOAD ONLY, REPAIR, REPORT,
RUNSTATS, and STOSPACE utilities.

The STOSPACE Utility

The STOSPACE utility operates on a DB2 storage group or a number of groups known as
STOGROUP. The utility updates DB2 catalog with the information of the storage space allotted to
STOGROUP along with the corresponding table spaces and indexes. The data is collected from the
ICF Catalog indicated in the STOGROUP. The STOSPACE utility is executed for this STOGROUP.

Listing 5−2−11 shows an example of the STOSPACE utility:

Listing 5−2−11: STOSPACE Utility


//UTIL EXEC DSNUPROC,SYSTEM=DSN,
// UID='STOSPCE',UTPROC='',
// DSNUPROC.SYSIN DD *
STOSPACE STOGROUP (*)
/*
//

The above STOSPACE statement fills the DB2 catalog with storage statistics of all the
STOGROUPs.

The STOSPACE can run parallel with all utilities of DB2. The STOGROUPS associated with table
spaces and indexes should run this utility at regular intervals. You can run the utility every month for
all existing STOGROUPs to increase the system efficiency.

Reprinted for dzpkhz, EDS Web Universities/Training SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited
Offline Utilities
Offline utilities are also known as stand−alone utilities. The utilities in this category can run without
running the DB2 environment. These do not require DB2 to be active during execution. To start with
the process of running the utility, a utility control statement along with the parameters are set, which
identifies the basic function of the utility. Most offline utilities can scan this statement through an
input stream to identify their definitions while other utilities parse the JCL EXEC PARAM parameters
supplied with the utility to acquire their task descriptions.

Change Log Inventory Utility


DSNJU003, commonly identified as change log inventory utility, alters or changes the Bootstrap
Datasets (BSDS). It provides the following services:

• Adds or deletes the archive logs of datasets.

• Generates a control record pertaining to the conditional restart that helps in controlling the
next initiation of DB2 subsystems.

• Modifies catalog name items in the BSDS.

• Changes communication entries of the BSDS.

An example of the DSNJU003 utility is:


//SYSIN DD *
DELETE DSNAME = DSNEMPL.A0001198 COP1VOL = DSNV03
//*

Print Log Map Utility


The print log map (DSNJU004) utility prints or reports the status of logs in the BSDS. The utility can
display the following statistical information:

• Log datasets that are currently available for new log data.

• Positions of all control records indicating a conditional restart in the BSDS.

• The communication record of the BSDS.

• Records from QUIESCE history.

• Content of checkpoint queue and system and utility timestamps.

If the utility is working in a data sharing condition, the utility can provide information from all BSDSs
that make up the data−sharing group.

An example of the DSNJU004 utility is:


//DSNJU004 EXEC PGM=DSNJU004
//SYSUT1 DD DSN =DSNEMPL.A0001198, DISP=SHR

Reprinted for dzpkhz, EDS Web Universities/Training SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited
DB2 ReferencePoint Suite 16

//SYSPRINT DDSYSOUT=*
//

The print log map utility is useful before and after the instances of the change log utility. The output
of the first utility, DSNJU004, can be utilized when recording the log changes being applied.

The DB2 Log Preformat Utility


The DB2 Log Preformat utility (DSNJLOGF) pre−formats the active or current log datasets.
DSNJLOGF pre−formats the log dataset areas before activating them and placing them to be used
by DB2. This prevents the delay, which occurs if the dataset is preformatted at the time of usage.

An example of the DSNJLOGF utility:


//PREF1 EXEC PGM=DSNJLOGF
//SYSPRINT DDSYSOUT=*
//SYSDUMP DDSYSOUT=*
//SYSUT1 DD DSN = DSN9410.LOGCOPY1.DS01, DISP=SHR
//*

The DSNJLOGF utility can be utilized to avoid delays that occur because log datasets are
preformatted at the time of execution.

Reprinted for dzpkhz, EDS Web Universities/Training SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited
Miscellaneous Utilities
Some new utilities that DB2 offers with its latest version are used interchangeably with the other
utilities that are a part of DBMS. The utilities enhance the subsystem and supervise data
management processes.

Online utilities have been introduced in version 7 of DB2 and compiled primarily for OS/390. Other
supporting aids and tools that function like offline utilities are also discussed in this section.

Online Utilities
These utilities work only when the DB2 environment is active. Some of these utilities are an
improvement on the existing utilities and function similar to the utilities of earlier versions.

EXEC SQL

The control statement of the EXEC SQL utility is used to declare a cursor or carry out dynamic SQL
statements within the DB2 family functions.

While executing a dynamic SQL statement, the string contained in the statement is parsed and
verified for errors. If the statement is invalid, stop the execution of the utility and describe the error
condition. If the statement is valid, but an error has occurred during the execution of the statement,
report the error condition and quit the utility.

For example, the following code inserts the data in the table DSN9410.EMP to a new file MYEMP:
EXEC SQL
INSERT INTO MYEMP SELECT * FROM DSN9410.EMP
ENDEXEC

The following code creates a cursor, C1, with the data from the table DSN9410.DEPT:
EXEC SQL
DECLARE C1 CURSOR FOR SELECT * FROM DSN9410.DEPT
ENDEXEC

LISTDEF

In the earlier versions of DB2, you needed to execute utilities for the proper management of the
system. In the new version of DB2, you do not need to query the catalog table to identify objects
and change the utility control statement to specify the appropriate utility to be run. The new version
allows the administrator to insert the objects into re−utilizable lists. These lists can be dynamically
appended to the utility datasets required to process them.

The LISTDEF control statement combines a number of DB2 objects to define a list and assign a
name to it. An example of the code that creates a list, LST1 is:
LISTDEF LST1 INCLUDE TABLESPACES DATABASE EMPLOYEE
INCLUDE INDEXSPACES DATABASE EMPLOYEE

The list LST1 contains all the table spaces and the index spaces of the database named
EMPLOYEE.

REBUILD INDEX

REBUILD INDEX rebuilds or recreates indexes of the table they refer. Earlier versions of DB2 use
RECOVER INDEX for this job.

An example of the REBUILD INDEX utility is:


//SYSIN DD *
REBUILD INDEX (DSN9410.XDEPT1)
//*

Reprinted for dzpkhz, EDS Web Universities/Training SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited
DB2 ReferencePoint Suite 18

OPTIONS

The OPTIONS utility is used to enumerate the processing options available for various utilities. This
utility can be used to:

• Preview utility control statements.

• See the definitions of LISTDEF and TEMPLATE.

• Modify the conventions used for warning messages.

• Denote tasks to be performed when an error occurs at the time of processing.

• Re−establish the default settings or options.

Listing 5−2−12 shows an example of the OPTIONS utility:

Listing 5−2−12: OPTIONS Utility


OPTIONS EVENT (WARNING,RC0)
MODIFY RECOVERY TABLESPACE DSN9D41A.DSN9S41E
DELETE AGE(*)
OPTIONS OFF
MODIFY RECOVERY TABLESPACE DSN9D41B.DSN9S41D
DELETE AGE(30)

TEMPLATE

The TEMPLATE utility is used to allocate datasets dynamically while the list defined by LISTDEF is
being processed. The utility does not use JCL DD cards like other utilities. The utility control
statement produces a dynamic allocation template, which is allotted a name to be used in the future.

An example of the TEMPLATE utility is:


TEMPLATE COPYDS DSN &DB..&TS..COPY&IC.&LR.&PB..D&DATE..T&TIME.

UNLOAD

The UNLOAD utility is an improved version of the REORG UNLOAD EXTERNAL utility option. The
utility unloads data from one DB2 object to other sequential datasets in a format that is external to
DB2. The utility can be performed on objects like table spaces or image copy datasets. You need to
run the utility on the same computer containing the definitions of DB2 objects for which the utility is
being run.

Listing 5−2−13 shows an example of the UNLOAD utility:

Listing 5−2−13: UNLOAD Utility


//SYSIN DD *
UNLOAD TABLESPACE DSN9D41A.DSN9S41E
FROM TABLE DSN9410.EMP
WHEN (DEPT = 'D1' AND SALARY > 30000)
//

Reprinted for dzpkhz, EDS Web Universities/Training SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited
DB2 ReferencePoint Suite 19

This utility statement unloads rows where the DEPT column matches D1 and SALARY is greater
than 30000 from the DSN9410.EMP table of the DSN9D41A.DSN9S41E table space.

Offline Utilities
Some service tools or programs offered by DB2 run like batch utilities and are independent of the
DB2 subsystem. These programs or utilities are useful when the DB2 system is inactive.

DSN1CHKR

The DSN1CHKR utility verifies and authenticates the integrity of DB2 catalog and DB2 Directory,
the two most eminent parts of DB2. If this utility is performed at uniform intervals, problems can be
detected at an early stage.

DSN1COMP

The DSN1COMP utility, also called a compression analyzer aid, evaluates and estimates the
outcome accomplished by DB2 data compression in table spaces. The utility can work on table
space datasets, sequential datasets having a DB2 table space or partitions, and full or incremental
image copy datasets.

DSN1COPY

The DSN1COPY utility is a copy tool or a program that offers DB2 with several benefits:

• Copies datasets and verifies the authenticity of table space and index pages.

• Converts DB2 object descriptors (OBIDs) into an appropriate form when the objects are
transferred to another version of DB2 and retrieves data from objects that are dropped by
mistake.

• Produces hexadecimal dumps of DB2 table space and index datasets.

DSN1LOGP

The DSN1LOGP utility is a recovery log extractor that generates a formatted citation of the recovery
log of a particular DB2 object. The utility can produce two types of reports:

• A detailed report that presents complete information of the log records.

• A summary report that specifies only the relevant information of the log records.

DSN1PRNT

The DSN1PRNT utility is used to print hexadecimal and formatted dumps of a table space, indexes,
and image copies. The utility is useful when the values contained in the table space are to be
examined and dumped according to a specified value.

DSN1SDMP

The DSN1SDMP utility is a selective dump utility. The utility is an application program of DB2
although IBM has labeled it as a service aid. The utility can trace records to a dataset indicated in
the input statement of the utility and influence the dumping of DB2 objects on instances of a
particular event. The utility has to be used under the guidance of IBM Support Centre.

Reprinted for dzpkhz, EDS Web Universities/Training SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited
Related Topics
For related information on this topic, you can refer to:

• Installing and Configuring DB2

• Query Tools in DB2

• DB2 Programming

Reprinted for dzpkhz, EDS Web Universities/Training SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

You might also like