A DB2 for z/OS package is more than a name in a collection. It has a version, a consistency token, VALID/OPERATIVE status, PLANMGMT copies, and a long list of bind options that decide locking, authorization, and access paths. This page walks through PKLIST, BIND versus REBIND versus FREE, access-path retention, and each option in the checklist: APREUSE, APCOMPARE, REOPT, DEGREE, CURRENTDATA, ISOLATION, VALIDATE, RELEASE, DYNAMICRULES, QUALIFIER, OWNER, SQLERROR, EXPLAIN, and QUERYACCELERATION.
Version comes from the precompiler/coprocessor VERSION option (or the empty-string default). SYSPACKAGE shows NAME, COLLID, VERSION, CONTOKEN, VALID, OPERATIVE, and the bind options last used. Typical VALID values:
OPERATIVE tells you whether the last autobind succeeded. Inoperative packages need an explicit REBIND. LASTUSED helps you find packages nobody runs before you FREE them.
The plan’s package list is how a version gets executed at all. Wildcards on REBIND PACKAGE (collection.*, *.*, and so on) are a different wildcard language from PKLIST, but the idea is the same: name a set of packages. PKLIST entries can be:
Db2 does not pick “the latest VERSION string” by sorting names. It picks the package whose consistency token matches the program. Keep old versions bound until every load module that still uses them is gone, then FREE the obsolete version.
BIND PACKAGE reads a DBRM (MEMBER) or copies an existing package (COPY). Use it when SQL changed or when you add a collection/version. ACTION(ADD) versus ACTION(REPLACE) decides whether you create or overlay. BIND also deletes phased-out PLANMGMT copies.
REBIND PACKAGE does not read a DBRM. Use it when something that affects access paths or bind options changed: new index, RUNSTATS, isolation, APPLCOMPAT, invalid package. You may change any ordinary package bind option on REBIND. Trigger packages are special: basic triggers use REBIND TRIGGER PACKAGE with a limited option set; advanced SQL PL triggers use REBIND PACKAGE.
FREE PACKAGE removes the package from the catalog and directory. FREE PLAN removes the plan. FREE SERVICE drops an active REST service package. PLANMGMTSCOPE(INACTIVE) can free leftover copies without dropping the current package.
123BIND PACKAGE(APP) MEMBER(ORDS01) ACTION(REPLACE) VERSION(V3) REBIND PACKAGE(APP.ORDS01.(V3)) APREUSE(WARN) PLANMGMT(EXTENDED) FREE PACKAGE(APP.ORDS01.(V2))
Production rebinds are scary because the optimizer might pick a worse path. PLANMGMT(EXTENDED) keeps original and previous copies so you can SWITCH. APREUSE asks Db2 to keep the old path:
APCOMPARE(NONE | WARN | ERROR) compares the newly chosen path with the saved one. Packages bound before DB2 9 cannot reuse until they have been rebound once on a current release. APREUSESOURCE can name CURRENT, PREVIOUS, or ORIGINAL as the reuse source.
REBIND accepts the same option set as BIND PACKAGE for ordinary packages. Trigger rebinds allow only a documented subset. Know every value below.
| Value | Meaning |
|---|---|
| CS | Cursor stability — usual OLTP; row lock while the cursor is on the row |
| UR | Uncommitted read — no row locks for read; dirty read possible |
| RS | Read stability — keep locks on qualified rows until commit |
| RR | Repeatable read — plus protection against phantoms in the scan |
| NC | No commit — IMS; commit is under IMS control |
With isolation CS, CURRENTDATA(NO) is the common setting: Db2 can avoid locking the current row in some read cases and use block fetching more aggressively. CURRENTDATA(YES) keeps the data the cursor just fetched current — more locking, sometimes required for correctness with positioned updates. Know your shop default before you copy JCL from another system.
VALIDATE(BIND) — missing objects or privileges fail the bind, except LOCK TABLE and some CREATE/ALTER/DROP checks that wait until run time. VALIDATE(RUN) — warnings at bind, recheck at run time using the owner authorization ID. SQLERROR(CONTINUE) can still produce a package whose failing statements cannot execute.
OWNER owns the package and must be able to execute the embedded static SQL (SYSADM and DATAACCESS include that). BINDAGENT and trusted-context roles change who you may name. QUALIFIER is prepended to unqualified tables, views, indexes, and aliases in static SQL. Changing QUALIFIER on REBIND can retarget a package from TEST to PROD schemas without changing source — if the SQL is fully unqualified.
| Value | Meaning |
|---|---|
| RUN | Dynamic SQL uses the runner’s privileges and qualifier at run time |
| BIND | Dynamic SQL uses the package owner’s privileges (bind behavior) |
| DEFINEBIND / DEFINERUN | For packages used to define routines — bind vs run behavior |
| INVOKEBIND / INVOKERUN | For packages invoked as routines — bind vs run behavior |
DYNAMICRULES also affects how dynamic SQL gets a qualifier and SQL path. BIND behavior for dynamic SQL is a security feature: the runner cannot use the package as a general SQL engine with their own table privileges.
NO — do not populate EXPLAIN tables. YES — write PLAN_TABLE (and related) rows for the statements. ONLY — explain without replacing the executable package (binder needs the EXPLAIN privilege). Use EXPLAIN(YES) on important production binds so you can compare paths after the next REBIND.
| Value | Meaning |
|---|---|
| NONE | Optimize at bind with default estimates for host variables |
| ALWAYS | Reoptimize each execution with the actual host-variable values |
| ONCE | Reoptimize once per thread with the first values |
| AUTO | Db2 decides when reoptimization is worth it |
DEGREE(1) disables query I/O parallelism for the package. DEGREE(ANY) allows Db2 to consider parallelism. Parallelism helps large queries; it is usually wrong for short OLTP packages.
Controls whether static SQL is eligible for IBM Db2 Analytics Accelerator: NONE, ENABLE, ENABLE WITH FAILBACK, ELIGIBLE, ALL. Pair with GETACCELARCHIVE when archive accelerator data matters. This is a bind-time eligibility setting, not a substitute for accelerator configuration.
12345678BIND PACKAGE(APP) MEMBER(ORDS01) - ACTION(REPLACE) OWNER(APPBIND) QUALIFIER(ORD) - ISOLATION(CS) CURRENTDATA(NO) RELEASE(COMMIT) - VALIDATE(BIND) DYNAMICRULES(BIND) - SQLERROR(NOPACKAGE) EXPLAIN(YES) - DEGREE(1) REOPT(NONE) - PLANMGMT(EXTENDED) APREUSE(NONE) - QUERYACCELERATION(NONE)
That is a conservative OLTP package: CS, no parallelism, no accelerator, fail on bind errors, explain on, plan management on so later REBINDs can SWITCH. Your shop standard may add APPLCOMPAT, ENCODING, PATH, and CONCURRENTACCESSRESOLUTION.
A package version is a labeled lunchbox. The stamp inside must match the stamp on your schoolbag (consistency token) or the cafeteria will not give you food. VALID is a sticker that says “still edible.” If someone throws away the fridge the lunch depended on (DROP INDEX), the sticker becomes “not edible” until a cook remakes it (REBIND). BIND is cooking from a new recipe card. FREE is throwing the lunchbox away. The option list is the cook’s instructions: how carefully to lock the fridge door, whose name is on the permission slip, and whether to reuse last week’s oven settings.
1. When do you BIND PACKAGE instead of REBIND PACKAGE?
2. What does VALIDATE(BIND) do?
3. Which ISOLATION value is the usual OLTP default?
4. What does APREUSE(ERROR) request?
5. What does FREE PACKAGE do?