Showing posts with label Db2 for z OS. Show all posts
Showing posts with label Db2 for z OS. Show all posts

Saturday, 24 August 2013

Db2 DSN Command Reference: BIND, RUN, SPUFI, DCLGEN, and REBIND



Db2 DSN command reference flow from TSO to DSN subcommands and Db2

DSN runs Db2 commands from TSO.

A bind job can fail before a COBOL program ever reaches its first OPEN or FETCH. In many Db2 for z/OS shops, the first place to check is the TSO DSN command stream in SYSTSIN, because that is where BIND, REBIND, RUN, SPUFI, and related subcommands are issued.

DSN is the Db2 command processor that runs as a TSO command. It can be used in the foreground under TSO/ISPF or in batch through programs such as IKJEFT01. Once a DSN session starts, the subcommands tell Db2 what action to perform.

Where DSN fits

Db2 administration and application work uses several command paths. Some commands are Db2 system commands such as -DISPLAY DATABASE. Others are DSN subcommands used inside a DSN session, such as BIND PACKAGE or RUN PROGRAM. The old article mixed those categories together, so this refresh separates the common DSN work from general Db2 command usage.

  • DSN command: starts a Db2 command processor session from TSO.
  • DSN subcommands: run inside DSN, including BIND, REBIND, FREE, RUN, DCLGEN, SPUFI, END, and comments beginning with *.
  • Db2 system commands: can be issued through DSN or from operator/admin paths, usually beginning with a hyphen, such as -DISPLAY or -START.

Common DSN subcommands

SubcommandUsed forProduction note
DSNStarts the Db2 command processor session for a subsystem.Check SYSTEM(DB2P) or the subsystem name before running bind or run jobs.
BINDCreates or replaces an application package or plan from a DBRM.Review collection, qualifier, owner, validation timing, and isolation before release.
REBINDRefreshes an existing package or plan without using a new DBRM.Use with care after RUNSTATS or access-path changes; keep fallback steps clear.
FREEDeletes a package or plan.Confirm no active application depends on the object before removing it.
RUNRuns an application program under DSN.Check plan name, program load library, and runtime SQL errors together.
DCLGENGenerates host-language declarations for tables or views.Regenerate declarations when column definitions used by COBOL change.
SPUFIRuns SQL from an input file in an ISPF foreground session.Good for controlled testing, not for unattended production jobs.
ENDEnds the DSN session.Always close the command stream cleanly in batch SYSTSIN.
*Marks a DSN command-stream comment.Use comments to identify release number, package, and change ticket.

Batch DSN example with BIND PACKAGE

In batch, a DSN command stream is normally placed in SYSTSIN. The example below starts DSN for subsystem DB2P, binds package member ACCTUPD, and ends the session.

//BINDPKG  EXEC PGM=IKJEFT01
//STEPLIB  DD  DISP=SHR,DSN=DB2P.SDSNLOAD
//SYSTSPRT DD  SYSOUT=*
//SYSPRINT DD  SYSOUT=*
//SYSTSIN  DD  *
  DSN SYSTEM(DB2P)
  BIND PACKAGE(APP1COLL) -
       MEMBER(ACCTUPD) -
       ACTION(REPLACE) -
       ISOLATION(CS) -
       VALIDATE(BIND)
  END
/*

When this job fails, read SYSTSPRT and SYSPRINT before changing the bind cards. The messages usually show whether the problem is an authorization issue, missing DBRM, invalid option, unavailable subsystem, or SQL object problem.

RUN PROGRAM example

RUN can execute an application program through DSN. Many production sites use normal batch JCL or schedulers for application execution, but RUN is still useful in examples and controlled test jobs.

//RUNPGM   EXEC PGM=IKJEFT01
//STEPLIB  DD  DISP=SHR,DSN=DB2P.SDSNLOAD
//         DD  DISP=SHR,DSN=APP1.LOADLIB
//SYSTSPRT DD  SYSOUT=*
//SYSTSIN  DD  *
  DSN SYSTEM(DB2P)
  RUN PROGRAM(ACCTUPD) PLAN(ACCTPLAN)
  END
/*

If the program starts but fails during SQL execution, move from DSN diagnostics to application diagnostics: SQLCODE, SQLSTATE, SQLERRMC, package name, plan name, and the business key being processed.

DCLGEN and SPUFI usage

DCLGEN

DCLGEN creates host-variable declarations that match a table or view. For COBOL teams, it helps keep copybooks consistent with Db2 column names and data types. Regenerate and review DCLGEN output after table changes, especially nullable columns and decimal precision changes.

SPUFI

SPUFI is the SQL processor using file input under ISPF. It is practical for testing SQL, checking catalog rows, or validating a small query before it is added to a program. Keep production fixes in controlled jobs or approved tooling rather than ad hoc foreground edits.

Common mistakes

  • Running BIND against the wrong subsystem after copying JCL from test to production.
  • Binding a package into the wrong collection and then running a plan that does not reference it.
  • Using REBIND without recording the prior access path or fallback plan.
  • Deleting a package with FREE before checking dependent jobs and online transactions.
  • Ignoring SYSTSPRT and looking only at the job return code.

Quick troubleshooting checklist

SymptomFirst checks
Bind job failsSubsystem name, DBRM library, member name, package collection, owner, qualifier, and bind authority.
Program cannot find package or planCollection, package name, plan name, package list, and runtime JCL.
Access path changed after REBINDRUNSTATS timing, catalog statistics, bind options, and package copy/fallback procedure.
SPUFI SQL works but program failsHost variables, indicator variables, package bind options, authorization ID, and SQLCA handling.

Related Db2 topics

Use this reference with Db2 Binding Application, Db2 Binding and Rebinding, Db2 Packages, Db2 Commands Quick Reference, and Db2 Application Environment.

FAQ

What is the DSN command in Db2 for z/OS?

DSN is the Db2 command processor that runs as a TSO command. It starts a session where subcommands such as BIND, REBIND, RUN, DCLGEN, and SPUFI can be issued.

Can DSN run in batch?

Yes. DSN commands are often run in batch through IKJEFT01, with the command stream placed in SYSTSIN and output written to SYSTSPRT.

What is the difference between BIND and REBIND?

BIND creates or replaces a package or plan using DBRM input. REBIND refreshes an existing package or plan, often after catalog statistics or environment changes.

Db2 Commands Quick Reference: DISPLAY, START, STOP, ALTER, and CANCEL


Db2 commands quick reference with DISPLAY START STOP ALTER SET CANCEL and TERM command groups
Check status before changing Db2.

A Db2 command can change subsystem availability, stop distributed access, cancel a thread, or terminate a utility. Before an operator types -STOP DATABASE or -TERM UTILITY, the command target and scope must be clear. A missing database name, wrong member, or broad command scope can turn a small support action into a larger outage.

This Db2 commands quick reference groups common Db2 for z/OS commands by the job they do: checking status, starting and stopping resources, changing runtime values, managing logs, handling utilities, and diagnosing threads.

Where Db2 commands can be issued

Most Db2 commands begin with a hyphen, such as -DISPLAY DATABASE. Depending on site setup and authority, commands may be issued from a z/OS console, TSO or DB2I, an APF-authorized program, CICS or IMS paths, or an IFI application. -START DB2 is normally a console-level action; do not treat it like an ordinary application command.

  • Check whether the command is allowed from your interface.
  • Confirm whether the command acts on one object, one member, a data sharing group, or the whole subsystem.
  • Capture command output in the ticket or job log when it affects production.

DISPLAY commands

Use DISPLAY commands when you need current facts before taking action. In support work, this is usually the safest first step.

CommandUseCommon support question
-DISPLAY DATABASEShows database or table space status.Is the object stopped, restricted, copy-pending, or unavailable?
-DISPLAY THREADShows local or distributed thread information.Which plan, auth ID, correlation ID, or connection is holding work?
-DISPLAY DDFShows Distributed Data Facility status.Is distributed access active, stopped, or limited?
-DISPLAY BUFFERPOOLShows buffer pool status and activity.Is the buffer pool active, and what does the activity look like?
-DISPLAY LOGShows active log and offload status.Is logging healthy, or is archive/offload work falling behind?
-DISPLAY UTILITYShows Db2 utility execution status.Which utility ID is active, stopped, or waiting?
-DISPLAY GROUPShows data sharing group information.Which members are active, and what mode is the group using?

START and STOP commands

START and STOP commands change availability. Use the narrowest object scope that solves the problem.

CommandUseCheck first
-START DATABASEMakes a database or table space available.Object name, access mode, and whether utilities are still running.
-STOP DATABASEMakes a database or table space unavailable or restricted.Active threads, batch schedule, and online transaction impact.
-START DDFStarts distributed data access.Network, location, and security readiness.
-STOP DDFStops distributed data access.Remote applications, DRDA clients, and application owners.
-START TRACEStarts trace activity.Trace class, destination, expected volume, and stop plan.
-STOP TRACEStops trace activity.Trace identifier and whether diagnostic capture is complete.

ALTER and SET commands

ALTER and SET commands change runtime behavior. Keep the before-and-after values in the change record.

CommandUseProduction note
-ALTER BUFFERPOOLChanges buffer pool attributes.Coordinate with DBA performance checks before changing size or thresholds.
-ALTER GROUPBUFFERPOOLChanges group buffer pool attributes in data sharing.Check coupling facility impact and data sharing member scope.
-ALTER UTILITYChanges selected utility processing values.Verify the utility ID and current phase before changing behavior.
-SET ARCHIVEControls archive log allocation behavior.Use with storage and operations awareness.
-SET LOGChanges logging checkpoint-related values.Record the reason and expected duration of the change.
-SET SYSPARMLoads selected subsystem parameter values.Confirm site procedures; not every subsystem parameter can be changed casually.

Thread and utility commands

Commands such as -CANCEL THREAD and -TERM UTILITY can interrupt work. They should be driven by command output, not guesswork.

-DISPLAY THREAD(*) TYPE(ACTIVE)
-CANCEL THREAD(token)

-DISPLAY UTILITY(*)
-TERM UTILITY(utility-id)

Before canceling a thread, identify the connection, correlation ID, authorization ID, and unit of work. Before terminating a utility, capture the utility ID, phase, object name, and restart instructions.

Archive and log commands

Log commands affect recovery posture. -ARCHIVE LOG closes the current active log and starts use of the next available log data set. -DISPLAY LOG helps confirm logging and offload state before and after action.

  • Use -DISPLAY LOG before forcing archive activity.
  • Confirm archive destinations and offload health.
  • Record log-related messages in the incident or change ticket.

Command safety checklist

  • Confirm the subsystem ID and data sharing member.
  • Confirm the object name, utility ID, thread token, or trace number.
  • Run a matching DISPLAY command first when possible.
  • Check authority and site operations rules.
  • Know how to reverse the command or restore availability.
  • Save the command output for the ticket.

Related Db2 topics

Use this reference with Db2 DSN Command Reference, Db2 Utilities, Db2 Buffer Pool, Db2 Packages, and Db2 Application Environment.

FAQ

What is a Db2 command on z/OS?

A Db2 command is an operational command used to display or change Db2 subsystem, object, thread, log, utility, trace, or distributed access state. Many Db2 commands begin with a hyphen.

Which Db2 command should I run first during an incident?

Use a matching DISPLAY command first when possible, such as -DISPLAY THREAD, -DISPLAY DATABASE, -DISPLAY UTILITY, or -DISPLAY LOG.

Are Db2 commands the same as DSN subcommands?

No. DSN starts the Db2 command processor and supports subcommands such as BIND and RUN. Db2 commands such as -DISPLAY DATABASE and -STOP DDF are operational subsystem commands.

Db2 Catalog Guide: SYSIBM Tables, Packages, Indexes, and Statistics


Db2 catalog flow from DDL to SYSIBM catalog tables and support queries
Query catalog tables before changing objects.

When a COBOL Db2 job fails with an object, privilege, or package problem, the catalog is often the fastest place to confirm the facts. It can show whether a table exists, which columns it has, which indexes support it, when statistics were collected, and which package or plan is tied to application SQL.

The Db2 catalog is a set of Db2 tables, mostly under the SYSIBM schema, that records metadata about objects, authorizations, packages, plans, constraints, routines, communications, and optimizer statistics. Db2 updates many catalog rows when DDL, DCL, bind, or utility work changes the system.

Catalog versus directory

The catalog and directory are both used by Db2, but they serve different support roles. The catalog is queryable through SQL and is useful for developers, DBAs, and support teams. The directory contains internal control information that Db2 uses to run and recover the subsystem; it is not a normal application query target.

AreaWhat it containsHow support teams use it
Db2 catalogMetadata about tables, columns, indexes, views, privileges, packages, plans, routines, constraints, and statistics.Query with SQL to investigate object definitions, authorization, bind status, and access-path inputs.
Db2 directoryInternal Db2 control information needed for operation and recovery.Managed by Db2 and DBA utilities; do not treat it as a normal reporting source.

Catalog tables developers often use

Catalog tableTypical question it answers
SYSIBM.SYSTABLESDoes this table, view, alias, or synonym exist, and who owns it?
SYSIBM.SYSCOLUMNSWhat are the column names, data types, lengths, null rules, and column order?
SYSIBM.SYSINDEXESWhich indexes exist for a table, and are they unique or clustering indexes?
SYSIBM.SYSKEYSWhich columns form an index key, and in what order?
SYSIBM.SYSTABLESPACEWhich table spaces exist, and which database owns them?
SYSIBM.SYSTABAUTHWhich table or view privileges are granted?
SYSIBM.SYSUSERAUTHWhich system-level authorities are recorded for an authorization ID?
SYSIBM.SYSPACKAGEWhich packages exist for an application, collection, or version?
SYSIBM.SYSPACKSTMTWhich SQL statements are associated with a package?
SYSIBM.SYSROUTINESWhich stored procedures and user-defined functions exist?

Catalog queries for daily support

Find columns for a table

SELECT NAME,
       COLTYPE,
       LENGTH,
       NULLS,
       COLNO
  FROM SYSIBM.SYSCOLUMNS
 WHERE TBOWNER = 'APP1'
   AND TBNAME  = 'ACCOUNT'
 ORDER BY COLNO;

This is a quick check before changing a COBOL copybook, DCLGEN member, or host variable definition.

List indexes for a table

SELECT I.NAME,
       I.CREATOR,
       I.UNIQUERULE,
       I.CLUSTERING
  FROM SYSIBM.SYSINDEXES I
 WHERE I.TBCREATOR = 'APP1'
   AND I.TBNAME    = 'ACCOUNT'
 ORDER BY I.NAME;

Use this before reviewing an access path or explaining why a predicate is not using the expected index.

Check package existence

SELECT COLLID,
       NAME,
       VERSION,
       VALID,
       OPERATIVE
  FROM SYSIBM.SYSPACKAGE
 WHERE COLLID = 'APP1COLL'
   AND NAME   = 'ACCTUPD';

This helps when a runtime failure points to a missing, invalid, or wrong collection package.

Catalog data used by the optimizer

Db2 uses catalog statistics when it chooses access paths for static and dynamic SQL. RUNSTATS updates statistics such as table cardinality, index cardinality, column distribution, and partition-level information. Stale statistics can lead Db2 to pick a poor access path even when the SQL text has not changed.

Catalog areaWhy it matters
SYSTABLES and related statistics rowsTable size and organization influence access-path choice.
SYSINDEXES and key statisticsIndex availability, uniqueness, and clustering affect predicate access.
SYSCOLDISTColumn distribution data can help Db2 estimate filter factors for skewed values.
History statistics tablesUseful for comparing recent statistics changes when a query changed behavior after maintenance.

Catalog safety rules

  • Use catalog SELECT queries for investigation; do not update catalog tables directly unless IBM documentation and site procedure explicitly allow a specific task.
  • Prefer Db2 DDL, DCL, BIND, REBIND, RUNSTATS, and utilities to make supported changes.
  • Use qualified names, especially owner, creator, database, table space, collection, and package name.
  • Check the Db2 subsystem before comparing test and production catalog rows.
  • Save catalog query output when it explains a production incident or release issue.

Common support scenarios

SQLCODE says an object is not found

Check SYSTABLES, SYSTABLESPACE, package collection, qualifier, and bind options. A table can exist in one subsystem or schema while the program is bound to another.

A query changed after RUNSTATS

Check catalog statistics and package bind time. If a rebind occurred after statistics changed, the package might have a new access path.

A user cannot run a query

Check table privileges, system privileges, role or group handling, and whether the application runs under a different authorization ID than the interactive user.

Related Db2 topics

Use this guide with Db2 Directory, Db2 Packages, Db2 Indexing, Db2 Utilities, and Db2 Optimizer.

FAQ

What is the Db2 catalog?

The Db2 catalog is a set of Db2 tables that stores metadata about objects, columns, indexes, privileges, packages, plans, routines, constraints, communications, and optimizer statistics.

Can developers query the Db2 catalog?

Yes, when they have the required authority. Catalog SELECT queries are common for checking object definitions, package status, privileges, and statistics.

Should catalog tables be updated manually?

No for normal work. Use supported Db2 statements, bind commands, utilities, and DBA procedures. Direct catalog updates are dangerous unless a documented IBM or site procedure specifically requires them.

Db2 Directory Guide: SPT01, SCT02, DBD01, SYSLGRNX, and SYSUTILX


Db2 directory guide showing SPT01 SCT02 DBD01 SYSLGRNX and SYSUTILX internal control data
Db2 manages the directory internally.

A Db2 package can be present in the catalog and still fail at execution time if the internal execution structures are damaged, unavailable, or out of sync. When recovery, bind, or utility processing is involved, Db2 uses directory objects that normal application SQL does not query.

The Db2 directory stores internal control information used by Db2 for operation, package and plan execution, database descriptors, log range tracking, and utility restart. Unlike the catalog, the directory is not a normal SQL reporting source. Db2 and supported utilities maintain it.

What the Db2 directory does

The directory supports Db2 execution and recovery work that must be fast and controlled. It stores internal forms of packages and plans, database descriptors, log ranges used for recovery, and utility status needed for restart. Developers usually learn about it when a bind, run, utility, or recovery problem points below normal catalog metadata.

Directory versus catalog

AreaPurposeNormal access
Db2 catalogStores queryable metadata about objects, privileges, packages, plans, routines, and statistics.Read with SQL when authorized.
Db2 directoryStores internal control data used by Db2 for execution, recovery, utility restart, and package or plan processing.Managed by Db2 and supported utilities, not normal application SQL.

Important Db2 directory objects

Directory objectWhat it supportsWhy it matters
SPT01Skeleton package table, often called SKPT.Contains internal package information and access-path data created by BIND PACKAGE and removed by FREE PACKAGE.
SCT02Skeleton cursor table, often called SKCT.Contains internal plan information and access-path data created by BIND PLAN and removed by FREE PLAN.
DBD01Database descriptors.Stores internal database descriptor information for table spaces, indexes, tables, constraints, and related structures.
SYSLGRNXLog range tracking.Helps Db2 locate log ranges needed for recovery of updated table spaces or partitions.
SYSUTILXUtility execution and restart state.Stores utility status so Db2 can restart, recover, or terminate utility work correctly.

How directory objects show up in support work

Package or plan execution

When a static SQL program runs, Db2 uses package or plan structures created at bind time. Catalog rows help you identify the package, collection, and validity, but execution also depends on internal structures in the directory. If a bind or free operation fails, support teams often check both catalog state and Db2 messages tied to directory processing.

Recovery and log ranges

SYSLGRNX helps Db2 find the log ranges needed for recovery. If an object has been updated, Db2 can use recorded ranges instead of searching all log data blindly. This matters during RECOVER, restart, and problem diagnosis after an outage.

Utility restart

SYSUTILX is involved when utilities such as REORG, LOAD, COPY, or RECOVER need restart or cleanup handling. If a utility stops, do not delete anything by hand. Use supported commands such as -DISPLAY UTILITY, restart procedures, or -TERM UTILITY only when site rules allow it.

-DISPLAY UTILITY(*)
-TERM UTILITY(utility-id)

Safe handling rules

  • Do not update or delete Db2 directory data manually.
  • Use supported Db2 commands, bind actions, utilities, and recovery procedures.
  • Check the catalog first when the question is about object names, package names, privileges, or statistics.
  • Check Db2 messages, utility output, and recovery documentation when the problem points to directory-managed state.
  • Escalate directory damage, utility restart confusion, or recovery inconsistencies to the DBA or systems programmer team.

Common mistakes

Treating the directory like catalog tables

The catalog is meant to be queried for metadata. The directory is internal. Treating both as ordinary application data is a support risk.

Terminating utilities without restart context

A utility entry can represent recoverable work. Capture the utility ID, phase, object name, and messages before taking action.

Looking only at package catalog rows

Package catalog rows help identify the package, but a runtime issue may also involve bind output, plan references, load libraries, directory-managed structures, or subsystem messages.

Related Db2 topics

Use this guide with Db2 Catalog, Db2 Packages, Db2 Utilities, Db2 Commands Quick Reference, and Db2 Binding and Rebinding.

FAQ

What is the Db2 directory?

The Db2 directory stores internal control information used by Db2 for package and plan execution, database descriptors, log range tracking, utility restart, and recovery processing.

Can I query the Db2 directory with SQL?

No for normal application or support work. The catalog is the SQL-queryable metadata source. The directory is maintained by Db2 and supported utilities.

What is SYSUTILX used for?

SYSUTILX stores Db2 utility execution and restart information. It helps Db2 restart or clean up utility work after interruption.

Db2 Sort Pool and DSNDB07: Work Files, Sort Spills, and Tuning Checks


Db2 sort pool and DSNDB07 work file flow for SQL sorting
Sorts spill to DSNDB07 when memory is not enough.



A query with ORDER BY, GROUP BY, DISTINCT, or a join that cannot use a useful index may force Db2 to sort rows. If the sort cannot stay in memory, Db2 writes intermediate ordered runs to work files in DSNDB07, then reads them back and merges them. That extra write and read path is where many slow reports and batch steps start to hurt.

The Db2 sort pool is memory in the DBM1 address space used during sort processing. It works with sort algorithms, work files, buffer pools, SQL access paths, and catalog statistics. Tuning sort problems means checking more than one knob.

What the Db2 sort pool does

At startup, Db2 allocates sort-related memory in the private area of DBM1. Db2 can sort data in memory when the input size and access path allow it. If the sort is too large, Db2 creates sorted intermediate runs and uses work files, commonly associated with DSNDB07, to complete the merge work.

The goal is not to remove every sort. Some sorts are expected. The goal is to avoid unnecessary large sorts, give required sorts enough resources, and prevent work files from becoming a bottleneck.

SQL patterns that often cause sorts

SQL patternWhy Db2 may sortWhat to check
ORDER BYRows must be returned in a requested order.Index key order, descending columns, and whether the access path already provides order.
GROUP BYRows must be grouped before aggregate output can be produced.Grouping columns, filter predicates, and matching indexes.
DISTINCTDuplicate rows must be removed.Whether duplicate removal is needed or can be avoided by better predicates.
Join processingCertain join methods may need sorted input.Join columns, statistics, join order, and available indexes.
Union processingUNION removes duplicates, unlike UNION ALL.Whether duplicate removal is required by the business rule.

Example: avoiding an unnecessary sort

This query may sort if no useful index supports the predicate and requested order:

SELECT ACCT_NO,
       ACCT_STATUS,
       OPEN_DATE
  FROM ACCOUNT
 WHERE BRANCH_ID = :WS-BRANCH
 ORDER BY OPEN_DATE;

An index such as (BRANCH_ID, OPEN_DATE) may let Db2 filter and return rows in order, depending on the rest of the access path and statistics. Do not add indexes blindly; confirm with EXPLAIN, cardinality, update cost, and workload impact.

What happens when the sort spills

When the sort pool is not enough, Db2 writes sorted runs to work files. Later, Db2 reads the runs back and merges them. If work files are undersized, poorly distributed, or backed by slow I/O, the query can spend much of its time outside the core table access path.

  • More rows entering the sort means more memory and work-file pressure.
  • Bad statistics can cause Db2 to choose an access path that sorts more data than expected.
  • Missing or mismatched indexes can force sorts for ordering or grouping.
  • Work-file contention affects other SQL running at the same time.

Tuning checks for sort problems

CheckWhy it matters
EXPLAIN outputShows whether the access path needs a sort and which predicates drive the row count.
RUNSTATS freshnessStale statistics can make Db2 underestimate sort size or pick a poor join order.
Index designIndex key order can reduce or remove sorts for common ORDER BY and GROUP BY paths.
DSNDB07 sizingWork files need enough space and distribution for concurrent sort and temporary table work.
Buffer pool behaviorWork-file I/O can stress related buffer pools and storage paths.
SQL row reductionFiltering earlier means fewer rows enter the sort.

Signs the work files are hurting performance

  • A report or batch cursor runs fast for small input but slows sharply for large date ranges.
  • EXPLAIN shows a sort where the developer expected an index-ordered result.
  • Multiple large queries run at the same time and contend for work-file resources.
  • Utility, temporary table, and SQL sort work overlap during a busy batch window.

Safe support workflow

  1. Confirm the SQL text and host variable values used by the slow job.
  2. Run or review EXPLAIN for the package or dynamic statement.
  3. Check whether RUNSTATS is current for the table spaces and indexes involved.
  4. Review whether an index can support filtering, joining, ordering, or grouping.
  5. Ask the DBA team to check work-file sizing and buffer pool pressure when spills are likely.

Related Db2 topics

Use this article with Db2 Optimizer, Db2 Indexing, Db2 Utilities, Db2 Catalog, and Db2 SQL Optimization Tips.

FAQ

What is the Db2 sort pool?

The Db2 sort pool is memory used by Db2 during SQL sort processing. If a sort cannot complete in memory, Db2 can write intermediate runs to work files and merge them later.

What is DSNDB07 used for?

DSNDB07 is commonly associated with Db2 work-file processing, including sort runs and other temporary work needed by SQL and utilities.

How can I reduce large Db2 sorts?

Review EXPLAIN output, update statistics with RUNSTATS where needed, filter rows earlier, check index key order, and confirm work-file capacity with the DBA team.

Saturday, 17 August 2013

Db2 Utilities Guide: COPY, RUNSTATS, REORG, LOAD, UNLOAD, and RECOVER


Db2 utilities for z OS including COPY RUNSTATS REORG LOAD and RECOVER
Use the right utility for the table space state.

A Db2 table space can be perfectly designed and still cause trouble if utilities are skipped. A missing image copy can block recovery, old statistics can lead to bad access paths, and a badly timed REORG can collide with batch work that needs the same object.

Db2 utilities are the operational tools used to load data, collect statistics, reorganize objects, create recovery copies, check consistency, and recover damaged or lost data. On z/OS, these jobs are usually controlled through JCL and utility control statements.

Common Db2 utilities and when to use them

Utility Main purpose Typical trigger
COPY Create an image copy for recovery Before risky change, after load, or on a backup schedule
RUNSTATS Update catalog statistics for the optimizer After large data change, new index, load, or REORG
REORG Reorganize data or indexes and reclaim space Poor clustering, high disorganization, or space issues
LOAD Load high-volume input data into a table Initial load, refresh, conversion, or warehouse feed
UNLOAD Extract table data into a sequential data set Archive, migration, test data, or reload process
RECOVER Restore an object using image copies and logs Object damage, application error, or point-in-time recovery plan
CHECK DATA Check referential and table check constraints After load, repair, or data movement where integrity needs proof
REBUILD INDEX Rebuild index structures Damaged index, recovery action, or index rebuild requirement

COPY is for recovery images

The Db2 COPY utility creates image copies of table spaces or index spaces. It is not the same thing as copying rows from one table to another with SQL. A recovery plan depends on these image copies and the logs that follow them.

//COPYTS  EXEC DSNUPROC,SYSTEM=DSN1,UID='MF.COPY'
//SYSIN   DD *
  COPY TABLESPACE APPDB.TSORD
       FULL YES
       SHRLEVEL CHANGE
/*

Schedule image copies around business risk. For example, take a copy after a successful high-volume load so recovery does not have to replay a large amount of log activity from an older copy.

RUNSTATS supports access path choices

RUNSTATS updates catalog statistics that the Db2 optimizer uses for access path selection. A COBOL program with static SQL normally needs bind or rebind activity before changed statistics can affect the package access path.

//RSTAT   EXEC DSNUPROC,SYSTEM=DSN1,UID='MF.RUNSTATS'
//SYSIN   DD *
  RUNSTATS TABLESPACE APPDB.TSORD
       TABLE(ALL)
       INDEX(ALL)
       SHRLEVEL CHANGE
/*

Run it after major data shifts, new indexes, table reorganizations, and bulk loads. Do not treat it as decoration at the end of a job stream; stale statistics can send the optimizer toward a costly path.

REORG cleans up physical layout

REORG can restore clustering order, reclaim space, and rebuild object layout. It is often paired with RUNSTATS and sometimes followed by package rebind when access paths should be reviewed.

//REORG   EXEC DSNUPROC,SYSTEM=DSN1,UID='MF.REORG'
//SYSIN   DD *
  REORG TABLESPACE APPDB.TSORD
       SHRLEVEL CHANGE
/*

Plan REORG around availability and logging impact. A small reference table and a multi-billion-row transaction table do not have the same utility window.

LOAD and UNLOAD move data at scale

LOAD is used when a large input data set has to be inserted into Db2 faster than ordinary row-by-row application processing. UNLOAD extracts data to a sequential data set for archive, migration, testing, or reload processing.

//LOADTS  EXEC DSNUPROC,SYSTEM=DSN1,UID='MF.LOAD'
//SYSREC  DD DSN=APP.INPUT.ORDERS,DISP=SHR
//SYSIN   DD *
  LOAD DATA INDDN SYSREC
       INTO TABLE APP.ORDERS
/*

After a LOAD, check whether the object needs COPY, RUNSTATS, constraint checks, and package rebind. The right answer depends on the options used and local recovery rules.

RECOVER is the restore path

RECOVER uses image copies and logs to restore Db2 objects. It should be rehearsed before the outage, not first learned during one. Keep utility JCL, copy availability, log retention, and recovery point rules visible in the runbook.

//RECOV   EXEC DSNUPROC,SYSTEM=DSN1,UID='MF.RECOVER'
//SYSIN   DD *
  RECOVER TABLESPACE APPDB.TSORD
/*

For point-in-time work, coordinate application owners, dependent objects, RI relationships, and downstream files. Recovering one object can be technically correct and still break a business process if related data is out of sync.

Utility checklist before production

  • Confirm object name, database, table space, and subsystem before submitting utility JCL.
  • Check whether the utility needs outage time or can run with SHRLEVEL CHANGE.
  • Review image copy requirements before and after high-risk utilities.
  • Run or schedule RUNSTATS when data distribution or indexes changed.
  • Check whether static SQL packages need rebind after statistics or index changes.
  • Keep utility output with the change record so failures and warnings are not lost.

Related DB2 topics

Utilities connect directly to Db2 Table Spaces, Db2 Indexing, Db2 Optimizer, Db2 Binding and Rebinding, and Db2 Commands Quick Reference.

FAQ

Is Db2 COPY used to copy rows between tables?

No. In the Db2 utility context, COPY creates image copies used for recovery. Row movement between tables is handled by SQL, LOAD/UNLOAD processes, or application logic.

Should RUNSTATS be run after every LOAD?

Often yes, especially when row counts or data distribution changed. The exact schedule depends on local standards, LOAD options, and whether related static packages will be rebound.

Does REORG always improve SQL performance?

No. REORG can help when physical layout, clustering, or space use is hurting access paths, but the value depends on the object and workload. Review utility reports and EXPLAIN evidence.

For utility work, the safest habit is simple: know the object state before the job, read the utility output after the job, and record what changed.

Db2 History: System R, SQL, MVS, z/OS, and Db2 UDB


Db2 history timeline from IBM relational research to DB2 for MVS and Db2 for z OS
Db2 grew from SQL research into mainframe production data.

A COBOL program that runs EXEC SQL today is using ideas IBM researchers worked on before DB2 had a product name. The history matters because many current Db2 for z/OS habits still come from that path: static SQL, precompile, DBRMs, packages, plans, catalog metadata, and cost-based access paths.

This article keeps the timeline practical. It is not a museum tour. It explains how Db2 moved from relational research to the mainframe database system used by batch jobs, CICS transactions, IMS programs, and reporting workloads.

Db2 history at a glance

Period Milestone Why mainframe developers still care
1970s IBM relational database research, including System R and SQL work The SQL model used by COBOL programs, SPUFI, QMF, and application tools traces back to this work.
1981 SQL/DS for VM and VSE IBM had a commercial relational database before DB2 for MVS became the mainframe name most developers know.
1983 DB2 for MVS Version 1 announced This is the mainframe line that later became Db2 for z/OS.
1990s DB2 expanded across distributed platforms and used the DB2 Universal Database name Teams began seeing DB2 across mainframe and non-mainframe systems, with different platform behavior under a shared product family.
2000s onward Db2 for z/OS evolved with 64-bit z/OS, data sharing, XML, security, and newer SQL features The mainframe version kept its own operational model: subsystems, buffer pools, packages, plans, utilities, and workload controls.

Relational database research came first

Before DB2, IBM research work on the relational model changed how application data could be described. Instead of making every program navigate physical record chains, the relational approach let developers ask for rows and columns through SQL.

That sounds ordinary now, but it was a major change for mainframe teams used to hierarchical and network-style access. A program could ask for customer rows that match account status, branch number, and date criteria without coding every physical navigation step.

System R helped prove SQL could work

System R was an IBM research project that tested relational database ideas and SQL. It influenced later commercial systems because it showed that SQL did not have to be only a research language; it could be compiled, planned, and run with usable performance.

The cost-based access path idea is especially important for Db2 developers. When a COBOL program uses static SQL, Db2 can evaluate access paths during bind. That is why catalog statistics, indexes, and bind output matter so much for production performance.

SQL/DS came before DB2 for MVS

IBM's SQL/DS product ran on VM and VSE environments before DB2 for MVS became the better-known mainframe relational database. SQL/DS matters in the history because it shows that IBM relational database work was not a single product jump from research directly to DB2 for z/OS.

Many older sites had mixed platform histories. A team might have VM/VSE SQL/DS background, MVS DB2 workloads, and later distributed DB2 systems that shared SQL concepts but differed in operations, utilities, and tuning.

DB2 for MVS arrived in 1983

DB2 for MVS Version 1 gave the MVS mainframe a relational database product built for enterprise workloads. The name DB2 marked a move from older data access styles toward SQL-based relational processing on the mainframe.

For application programmers, this created the work pattern that still appears in many shops: write embedded SQL in COBOL or PL/I, precompile the source, bind the DBRM, run the program under a plan, and tune access paths when the batch window starts to hurt.

DB2 UDB widened the product family

In the 1990s, IBM used the DB2 Universal Database name across mainframe and distributed products. The phrase "Universal" reflected support for more data types and platforms, including AIX, Windows, OS/2, HP-UX, Solaris, and parallel processing environments.

This is where some confusion starts for learners. DB2 on distributed platforms and Db2 for z/OS share SQL heritage, but the day-to-day administration is not identical. A mainframe developer still has to know about subsystems, buffer pools, table spaces, plans, packages, utilities, and z/OS job control.

Db2 for z/OS kept the mainframe operating model

Modern Db2 for z/OS runs as a major subsystem on z/OS. It works with address spaces, workload controls, buffer pools, logging, utilities, security rules, and data sharing groups. CICS, IMS, batch, and distributed requesters can all reach Db2, but each path has its own operational checks.

The product name is now styled as Db2, but older posts, JCL comments, bind decks, and manuals often say DB2. In practice, mainframe teams still use both spellings in conversation. For current writing, Db2 is the cleaner style; for old job names and historic product names, DB2 may still be accurate.

Why the history helps in daily DB2 work

  • Relational design explains why tables, keys, predicates, and joins are central to application logic.
  • System R explains why the optimizer and access path selection became part of Db2's identity.
  • DB2 for MVS explains why static SQL, DBRMs, packages, and plans remain visible in mainframe build pipelines.
  • DB2 UDB explains why the same product family can behave differently across z/OS and distributed platforms.
  • Db2 for z/OS explains why database work is tied to JCL, security, utilities, and subsystem operations.

Related DB2 topics

After the history, the practical next steps are Db2 Origins of SQL, Db2 Early Vendor Implementations, Db2 Objects, Db2 Binding an Application, and Db2 Optimizer.

For current product positioning, see IBM's Db2 for z/OS product page.

FAQ

Is DB2 the same as Db2?

They refer to the same IBM database family in most mainframe conversations. DB2 is the older styling, while Db2 is IBM's current styling. Historic product names and old JCL comments may still use DB2.

Did Db2 start on z/OS?

No. The relational database work started before z/OS existed. DB2 for MVS was announced in 1983, and the mainframe line later became Db2 for z/OS.

Why does Db2 history matter to COBOL developers?

It explains why embedded SQL programs still use precompile, DBRMs, packages, plans, and bind-time access path choices. Those are not random build steps; they come from Db2's static SQL design.

When you read old DB2 material, map the history back to the job in front of you: subsystem, table space, package, plan, SQLCODE, and access path.

New In-feed ads