FREE commands in DB2 for z/OS

FREE is the DSN opposite of BIND: it deletes a package, plan, REST service, query hint, or stabilized dynamic statement from DB2 for z/OS. The subcommands are FREE PACKAGE, FREE PLAN, FREE QUERY, FREE SERVICE, and FREE STABILIZED DYNAMIC QUERY. This page covers wildcards, PLANMGMTSCOPE copies, authorization (BIND is not enough to free a package), and the difference between hints and stabilized dynamic SQL.

DSN subcommands
Progress0 of 0 lessons

The FREE family

Like BIND and REBIND, FREE runs under TSO DSN or DB2I (except as noted for your release). Data sharing scope is group. Freeing an object on one member removes it for the whole group.

FREE subcommands
SubcommandWhat it removes
FREE PACKAGEPackage versions or PLANMGMT copies from catalog and directory
FREE PLANApplication plans (not the packages they listed)
FREE QUERYSYSQUERY* hint rows; purges matching dynamic cache entries
FREE SERVICENative REST service package (active copy)
FREE STABILIZED DYNAMIC QUERYStabilized dynamic SQL catalog rows and matching cache entries

FREE PACKAGE

FREE PACKAGE deletes a version, all versions of a package, or whole collections. Catalog rows go away. The package-id becomes available for a new BIND PACKAGE. Phased-out copies are deleted as well. Authorization for the package name is removed only when no versions remain.

For the current copy, FREE waits until applications that are using the package finish. PLANMGMTSCOPE lets you free inactive copies without that wait.

text
1
2
3
4
5
6
7
FREE PACKAGE(PAYROLL.PAYCALC.(V1)) FREE PACKAGE(PAYROLL.*) FREE PACKAGE(*.PAYCALC) FREE PACKAGE(LOCATIONX.COLL.PKG.(V2)) FREE PACKAGE(PAYROLL.PAYCALC) PLANMGMTSCOPE(INACTIVE) FREE PACKAGE(PAYROLL.PAYCALC) PLANMGMTSCOPE(PREVIOUS) FREE PACKAGE(PAYROLL.PAYCALC) INVALIDONLY(YES) PLANMGMTSCOPE(PREVIOUS)
  • location — default local; remote names must exist in SYSIBM.LOCATIONS
  • collection / package / version — * allowed locally only; () is the empty version string
  • FLAG(I|W|E|C) — how chatty the messages are
  • INVALIDONLY(YES) — restrict to invalid copies; not valid with PLANMGMTSCOPE(ALL); ignored with INACTIVE or PHASEOUT
PLANMGMTSCOPE
ValueMeaning
ALLEntire package including copies (default). Not for trigger packages, SQL routines, or active native REST
INACTIVEPrevious, original, or eligible phased-out copies; OK while current copy runs
PREVIOUSOnly the previous copy
ORIGINALOnly the original copy
PHASEOUTPhased-out copies from plan management

PLANMGMTSCOPE(ALL) is not supported for trigger packages, SQL routines, or native REST services. FREE PACKAGE of inactive REST copies is allowed; the active REST package is FREE SERVICE.

Authorization: ownership, BINDAGENT from the owner, PACKADM, SYSADM, SYSCTRL, or System DBADM. The BIND privilege on the package is not sufficient. That surprises people who can BIND REPLACE all day but cannot FREE.

FREE PLAN

FREE PLAN deletes application plans. It does not free the packages on the PKLIST. After FREE PLAN, a RUN or CAF OPEN using that plan name fails until you BIND PLAN again. EXECUTE grants on the plan disappear with the plan.

text
1
2
FREE PLAN(PAYPLAN) FREE PLAN(*)

You need ownership of the plan, BINDAGENT from the owner, or SYSADM/SYSCTRL/System DBADM (BIND on the plan is not the documented FREE authority—match the Command Reference for your release, which lists ownership and system authorities similarly to packages). Do not FREE the plans your CICS region still names in RCT/DB2CONN.

FREE SERVICE

FREE SERVICE deletes the application package that represents a Db2 native REST service, including the SYSIBM.DSNSERVICE association. Clients that POST to that service name get an error until you BIND SERVICE again. Versioning, if enabled, means you free a specific service version—check the NAME and VERSION operands on your function level.

text
1
FREE SERVICE(PAYROLL.getEmp)

FREE QUERY

FREE QUERY removes rows from the catalog tables that BIND QUERY populated (SYSIBM.SYSQUERY, SYSQUERYPLAN, SYSQUERYOPTS) for one or more queries. If those statements sit in the dynamic statement cache, FREE QUERY purges them so the next PREPARE is a fresh prepare without the hint.

You identify queries by QUERYID from the catalog or by the matching text/schema rules documented for the subcommand. After a bad hint, FREE QUERY then BIND QUERY with a corrected DSN_USERQUERY_TABLE row is the cleanup path—not REBIND PACKAGE, unless the hint was package-scoped via OPTHINT.

FREE STABILIZED DYNAMIC QUERY

Dynamic SQL can be stabilized so a prepared statement keeps a known access path across cache eviction (START DYNQUERYCAPTURE / catalog stabilization). FREE STABILIZED DYNAMIC QUERY removes those stabilized rows from the catalog and purges matching statements from the dynamic statement cache. Application compatibility changes, invalidation, or this FREE are how stabilized statements pick up new behavior.

Do not confuse this with FREE QUERY. Hints (BIND QUERY) are “use this path.” Stabilization is “keep this already-chosen path for this dynamic text.” Both can coexist; free the one you actually created.

Safety habits

  • DISPLAY or query SYSPACKAGE before FREE PACKAGE(*.*) — wildcards are local and powerful
  • Prefer PLANMGMTSCOPE(INACTIVE) to reclaim disk after PLANMGMT(EXTENDED) rebinds
  • Never FREE the package a CICS/IMS region is about to call without a change window
  • FREE PLAN does not replace FREE PACKAGE; orphan packages still occupy the directory
  • After FREE QUERY, confirm SYSQUERY and the cache with EXPLAIN / DISPLAY-related monitors your shop uses

Explain It Like I'm Five

FREE PACKAGE is throwing away a frozen meal (or just the leftover copies in the back of the freezer). You cannot throw away the meal someone is still eating unless you wait (ALL), but you can throw away yesterday’s extra copy (INACTIVE). FREE PLAN throws away the dinner ticket, not the meals on the shelf. FREE SERVICE throws away the QR-code meal. FREE QUERY peels off the sticky note that said “use this oven.” FREE STABILIZED DYNAMIC QUERY forgets a memorized shortcut for a sentence people type on the fly.

Exercises

  1. Write FREE PACKAGE to delete only previous copies of PAYROLL.PAYCALC while payroll stays up.
  2. A binder with BIND on the package tries FREE PACKAGE and fails. Which authorities would succeed?
  3. After FREE PLAN(PAYPLAN), can a COBOL program still use package PAYROLL.PAYCALC if another plan lists it?
  4. Contrast FREE SERVICE with FREE PACKAGE PLANMGMTSCOPE(INACTIVE) for a REST service.
  5. You used BIND QUERY LOOKUP(NO) and performance got worse. Which FREE command removes the hint, and what else does it purge?

Quiz

Test Your Knowledge

1. Does BIND privilege allow FREE PACKAGE?

  • Yes, always
  • No—ownership, BINDAGENT from the owner, PACKADM, SYSADM, SYSCTRL, or System DBADM. BIND on the package is not enough
  • Yes, if you have SELECT
  • Only on Sundays

2. What does PLANMGMTSCOPE(INACTIVE) free?

  • The current executing copy and the plan
  • Previous, original, or eligible phased-out copies while applications can keep running the current copy
  • Only SYSCOPY rows
  • The DBRM on disk

3. How do you free the active package of a native REST service?

  • FREE PACKAGE PLANMGMTSCOPE(ALL) only
  • FREE SERVICE — FREE PACKAGE is for inactive REST copies; the active service package is freed with FREE SERVICE
  • TERM UTILITY
  • DROP DATABASE

4. What does FREE QUERY do besides catalog rows?

  • Stops IRLM
  • If the query is in the dynamic statement cache, it is also purged from the cache
  • Drops the table
  • Rebinds the plan

5. When are package EXECUTE privileges removed?

  • After freeing any one version
  • Only when no more versions of that package name exist
  • Never
  • At every REBIND

Frequently Asked Questions