Top Banner
May 20, 2008 • 09:15 a.m. – 10:15 a.m. Platform: DB2 for z/OS Rob Crane II FedEx Freight System Session: F05 I Love Packages & Collections So put another dime in the jukebox baby!
70
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: I love packages and SQLJ

May 20, 2008 • 09:15 a.m. – 10:15 a.m.Platform: DB2 for z/OS

Rob Crane IIFedEx Freight System

Session: F05

I Love Packages & Collections So put another dime in the jukebox baby!

Page 2: I love packages and SQLJ

Page 2I love Packages & Collections So put another dime in the jukebox baby! Page 2IDUG North America 2008

FedEx Freight Production DB2 Overview

CICS

PIPES

DB2 Subsystem DBP1

AFW1 (15)

BATCH

CF01 (1)

Group Buffer Pools

AFWC (1)

CA SPOOL

JHS

CF02 (1)

Shared Com Area

Lock Structure

1,127 MIPS

z9 – 2094-715 z9 – 2094-702

ESS Shark

SAN

6 TB data 4 billion SQL

every 24 hrs

DSNDS Group

DRDA

DB2 Subsystem DBP2

AFW2 (2)

BATCH

JMS

DRDA

CDC

6,143 MIPS

Virtual Tape Server

128/12 Drives

Automated Tape Library

22 Drives | 3592, 3590

800

8008100

Page 3: I love packages and SQLJ

Page 3I love Packages & Collections So put another dime in the jukebox baby! Page 3IDUG North America 2008

Presentation Overview Program Preparation

Relationship between plans, collections and packages with numerous examples Understanding the Big Picture (Compile, Precompile, Bind, Link, Execute) Precompile & Bind processes described Explain process with Optimization Hints described, along with discussion on reoptimization

Package Execution Flow and System & Catalog Table Overview Package execution flow, review of the skeleton cursor and package tables Review DSNDB01 & DSNDB06 tables and purpose, with V8 updates

Recommendations for Implementing and Maintaining Packages Ensuring only package based SQL Naming standards suggestions and examples How many plans and collections should we implement? Standards for package and explain table clean up Free package fallback for performance stability

Advanced Package Topics & Problem Resolution Java & SQLJ package deployment Deprecating obsolete packages What makes a package invalid and inoperative? Consistency token investigation, solve your -805s

Reference Material Read only package implementation for developer access in production Queries & Scripts to help you Security Issues and recommendations Other package topics (stored procedures, triggers, bind options, packageset)

Page 4: I love packages and SQLJ

Page 4I love Packages & Collections So put another dime in the jukebox baby! Page 4IDUG North America 2008

Many Benefits to Packages! Enhances application enabling Reduces bind time, only bind changed DBRMs Allows multiple versions of programs Flexible naming conventions & QUALIFIER keyword Increases bind availability Granularity in bind options Access to mirror tables, set current packageset Allows remote statically bound SQL SQLJ, stored procedures and triggers Supports built in performance fallback from rebind activity due to

database upgrade/maintenance and general rebind performance work. Free the package(s) in the high order collection. (FPF – free package

fallback)

Page 5: I love packages and SQLJ

Page 5I love Packages & Collections So put another dime in the jukebox baby! Page 5IDUG North America 2008

Understanding the Relationship

plan(s) package path

collection(s)

package(s)

A plan points at one to many collections

A collection contains one to many packages and package versions

PACKAGE PATH points to one to many collections (for SQLJ, SP, Triggers who do not have/need plan ties)

PACKAGE SET points to only one collection (not shown - as package path should be used for flexibility)

BATCH EXECUTE PLAN(xxxxxxxx) PROGRAM(pppppppp)

CICS RDO ties TRANid to PLAN

SQLJ PACKAGE PATH denotes which collections to search for package execution. If not used (in program or connection pool), the collection tied to the db2customization/db2sqljbind is used. In order to have more than one collection scope for a java program, SET CURRENT PACKAGE PATH must be used. Contoken match drives execution.

Plan, collection and package relationship

Execution ties, how DB2 finds your COLLID and package

Page 6: I love packages and SQLJ

Page 6I love Packages & Collections So put another dime in the jukebox baby! Page 6IDUG North America 2008

The Big PicturePRECOMPILE

Syntax checks SQL statements and :host variables referenced by them, including DCLGEN variables. Translates SQL into host language calls and comments out SQL, creating a parameter list . The consistency token is introduced x’487A7C9E87E7Y68E’

Stores the VERSION value in the DBRM and modified source code (VERSION(AUTO) for packages). Does not validate DB2 objects against the catalog tables! (DSNDB06)

BINDTranslates SQL into executable instructions. Validates objects against the DB2 catalog tables. Optimizes SQL - Access Path Selection. Validates security / authorizations.

REBINDValidates objects against the DB2 catalog tables. Optimizes SQL - Access Path Selection. Validates security / authorizations.Does not reference DBRMLIB pds, gets SQL from the directory and catalog [DSNDB01/DSNDB06].

SOURCE

PreCompile

Mod-SourceCONTOKEN

Compile

Link

Load

executes in

executes in

App Address Space CICS/BATCH/TSO

DB2 Address Space

THREADDBRM name CONTOKEN Section # Statement #

SQL call DSNHLI

CONTOKEN

DBRM

BIND

REBINDpackageplan

Page 7: I love packages and SQLJ

Page 7I love Packages & Collections So put another dime in the jukebox baby! Page 7IDUG North America 2008

Execution Flow – One Layer Deeper

DSNDB01

SKCT & SKPT pages are read into the database buffer pool

BP0

Pages copied into EDM pool, which is in DBM1 below the 2 GB bar.

DBM1

SKCT

Global Dynamic Statement Cache

EDM DBD Pool

DSNHLI Entry PointParm list (DBRM name, contoken, Section #, Statement #)

SQL Call

SKPTCT

Thread Storage

2 GB bar

EDM Pool

LOB

Sort PoolRid Pool

Buffer Pool

Compression Dictionary

Castout Engine Work Area

Buffer ControlBlocks

Application Copy

Page 8: I love packages and SQLJ

Page 8I love Packages & Collections So put another dime in the jukebox baby! Page 8IDUG North America 2008

Plan and Package Bind

Bind plan with PKLIST Bind package

BIND PLAN(PLAN_NAME)

PKLIST(list of collections or individual DBRMs)

DSNDB01

SYSPLAN *REMARKS

SYSPACKLIST

SYSPLANAUTH

SYSPLANSYSTEM

SCT02

DSNDB06

BIND PACKAGE(collection name)

MEMBER(DBRM aka package / program name)

DSNDB06 DSNDB01

SYSPACKAGE *

SYSPACKSTMT

SYSPACKAUTH

SYSPACKDEP

SYSPKSYSTEM

SPT01

catalog directory catalog directory

Page 9: I love packages and SQLJ

Page 9I love Packages & Collections So put another dime in the jukebox baby! Page 9IDUG North America 2008

Joan Jett Loves Package Based SQL!

DB2

DB2

plan

Package

DBRM A CONTOKEN

DBRM B CONTOKEN

BIND PACKAGE(s_SH) MEMBER(A) LIBRARY(‘FXes.DBRMLIB’) ;

BIND PACKAGE(s_SH) MEMBER(B) LIBRARY(‘FXes.DBRMLIB’);

DB2

DB2

plan

Package

DBRM B CONTOKEN

DBRM A CONTOKEN

BIND PACKAGE(s_SH) MEMBER(B) LIBRARY(‘FXes.DBRMLIB’);

DB2

plan

DBRM A CONTOKEN

DBRM B CONTOKEN

BIND PLAN OSHDE19 MEMBER(A,B) LIBRARY(‘FXes.DBRMLIB’);

BIND PLAN OSHDE19 PKLIST( *.s_SH.*, *.s_CM);

BIND PLAN OSHDE19 MEMBER(A) LIBRARY(‘FXes.DBRMLIB’) PKLIST( *.s_SH.*, *.s_CM);

Plan based SQL

No versioning allowed

Plan & Package based SQL Versioning only allowed for packaged based dbrm

Packaged based SQL

Versioning allowed

Page 10: I love packages and SQLJ

Page 10I love Packages & Collections So put another dime in the jukebox baby! Page 10IDUG North America 2008

Precompile Steps and Activity

Syntax checks SQL statements and :host variables referenced by them, including DCLGEN variables

Translates SQL into host language calls and comments out SQL, creating a parameter list

The consistency token is introduced x’487A7C9E87E7Y68E’ Stores the VERSION value in the DBRM and modified source code Does not validate DB2 objects against the catalog tables

(DSNDB06) NEWFUN YES / IBMREQD = ‘L’

Page 11: I love packages and SQLJ

Page 11I love Packages & Collections So put another dime in the jukebox baby! Page 11IDUG North America 2008

Precompile – NEWFUN YES

Package / Plan

Unicode Database Request ModuleDBRM, all SQL statements in UNICODE - UTF 8 - CCSID(1208)

Bind with EXPLAIN(YES)

executes in

DB2 Address Space

V8 in New Function Mode (NFM)

PLAN_TABLE

Performance Tuning

DSN_FUNCTION_TABLE DSN_STATEMNT_TABLE

OPTHINT

DSN_DETCOST_TABLE DSN_FILTER_TABLE

DSN_PGRANGE_TABLE DSN_PGROUP_TABLE

DSN_PREDICAT_TABLE DSN_PTASK_TABLE

DSN_SORT_TABLE DSN_SORTKEY_TABLE

DSN_STRUCT_TABLE DSN_VIEWREF_TABLE

Page 12: I love packages and SQLJ

Page 12I love Packages & Collections So put another dime in the jukebox baby! Page 12IDUG North America 2008

Bind Steps and Processes

Translates SQL into executable instructions Validates tables, columns, etc., against the DB2 catalog tables to

verify these objects exist in the subsystem you are binding to Resolves all view, alias and synonym references to the

underlying table Optimizes SQL - Access Path Selection Validates security / authorizations Explain – externalizing the access path

Page 13: I love packages and SQLJ

Page 13I love Packages & Collections So put another dime in the jukebox baby! Page 13IDUG North America 2008

Bind Versus Rebind

Bind - creates a new plan or package from one or more DBRMs

Rebind - replaces an existing plan or package with input only from the old plan or package found in the DB2 catalog (the source code is not referenced)

Rebinds are typically used when access path information needs to be updated due to statistical changes in data (volume & distribution); do not be afraid of REBIND

When should rebinds occur? (do not forget trigger packages)

Page 14: I love packages and SQLJ

Page 14I love Packages & Collections So put another dime in the jukebox baby! Page 14IDUG North America 2008

EXPLAIN (YES) Keep your explain data current and accurate. Compare explain output from one software release

to the next, looking for changes. See notes for clean up tips on the PLAN_TABLE. If output from previous explains is available, use Optimization Hints to return to the previous

access path if the REBIND drastically changed your access path in a harmful manner. Try to do this at the statement level vs. DBRM level.

Only use optimization hints if beneficial (use should be limited). Previous explain output and performance data will help you make this decision. Have you opened ETRs on your current access paths using hints?

Stats Advisor and Runstats with COLGROUP functionality will slay the overuse of opthints. Add new V8 columns, update columns to match V8 lengths. Or unload/load into new V8

PLAN_TABLE, DSN_STATEMNT_TABLE to preserve your performance data and optimization hints. Nine columns change to VARCHAR(128) and seven columns were added to increase the PLAN_TABLE to 58 columns. See notes for column details.

Preserve your explain table data prior to DB2 migrations.V7.PLAN_TABLE, V8CM_PLAN_TABLE, V8NFM.PLAN_TABLE

Ability to EXPLAIN from statements in the dynamic statement cache once in V8 NFM.DSN_STATEMENT_CACHE_AUXDSN_STATEMENT_CACHE_TABLE

V8 supports ALIASes in the OWNER key word of bind and rebind. This is helpful for directing explain output to a common set of explain tables.

Page 15: I love packages and SQLJ

Page 15I love Packages & Collections So put another dime in the jukebox baby! Page 15IDUG North America 2008

Reoptimization | What is it? REOPTIMIZATION Evaluate data values and access path at runtime

When two or more access paths are needed based on the content of the :HostVariables Allow the optimizer to make a different decision based on knowing the data values of the filtering predicates When the optimizer’s estimate of qualifying rows does not yield the desired access path DB2 would select if it knew the content of the host

variables prior to execution Limit parts for partition scans and influence join sequence The REOPT code path does not invoke Automatic Query Rewrite, AQR is currently only available for dynamic read-only SQL

REOPT(ALWAYS) Available for static and dynamic SQL Carry over of REOPT(VARS) from V7

REOPT(ONCE) Available for dynamic SQL How do you seed the correct values in the :HostVariables for the first execution? This will set the access path tied to the SQL statement in

the dynamic statement cache. Don’t forget about resetting due to actions like IPL, runstats report no update none. Static SQL | package level granularity

Consider isolating and consolidating your reopt statements to a few static packages Document which objects the reoptimized access path uses and be aware of other access paths needing the same objects Plan based SQL can also have reoptimization, although the best practice is to implement at the lower package granularity

Dynamic SQL | statement level granularity allowing smaller scope and scale of impact Did reoptimization benefit the SQL statement?

IFCID 0022 SQL object monitoring what got touched for this access path (Detector/Subsystem Analyzer, Query Monitor, Apptune, etc.)

Page 16: I love packages and SQLJ

Page 16I love Packages & Collections So put another dime in the jukebox baby! Page 16IDUG North America 2008

Caveats with REOPT13.16.08 STC13637 DSNI031I -DBP2 DSNILKES - LOCK ESCALATION HAS OCCURRED FOR RESOURCE NAME = DSNDB06.SYSPLAN LOCK STATE = X PLAN NAME : PACKAGE NAME = DSNBIND : N/A COLLECTION-ID = N/A STATEMENT NUMBER = N/A CORRELATION-ID = CGARPOST CONNECTION-ID = BATCH LUW-ID = USARFW01.LUDSNP2.C0079D34792B THREAD-INFO = STCUSER : *13.20.36 STC13736 DSNT501I -DBP1 DSNILMCL RESOURCE UNAVAILABLE CORRELATION-ID=POOLEQ030135 CONNECTION-ID=CICSCOM2 LUW-ID=USARFW01.LUDSNP.C0079DA6108D=0 REASON 00C9008E TYPE 00000200 NAME DSNDB06 .SYSPLAN 13.20.36 STC13736 DSNT501I -DBP1 DSNILMCL RESOURCE UNAVAILABLE CORRELATION-ID=IV710DO CONNECTION-ID=BATCH LUW-ID=USARFW01.LUDSNP.C0079D47A4A2=0 REASON 00C9008E TYPE 00000200 NAME DSNDB06 .SYSPLAN 13.20.36 STC13736 DSNT501I -DBP1 DSNILMCL RESOURCE UNAVAILABLE CORRELATION-ID=POOLIV780100 CONNECTION-ID=CICSWEBB LUW-ID=USARFW01.LUDSNP.C0079D9E0E81=0 REASON 00C9008E TYPE 00000200 NAME DSNDB06 .SYSPLAN 13.20.48 CGARPOST BIND Completed, RC=013.21.32 CICS Transaction RQ06 enabled

13.05.43 STC13637 DSNT375I -DBP2 PLAN=DSNBIND WITH CORRELATION-ID=CGARPOST CONNECTION-ID=BATCH LUW-ID=USARFW01.LUDSNP2.C0079AC395F7=15307 THREAD-INFO=STCUSER:*:*:* IS DEADLOCKED WITH PLAN=RQ06SGL WITH CORRELATION-ID=ENTRRQ060037 CONNECTION-ID=CICSCOM2 LUW-ID=USARFW01.LUDSNP.C0079A5B8C70=122665 THREAD-INFO=CICSUSER:*:*:* ON MEMBER DBP1 13.05.43 STC13637 DSNT501I -DBP2 DSNILMCL RESOURCE UNAVAILABLE CORRELATION-ID=CGARPOST CONNECTION-ID=BATCH LUW-ID=USARFW01.LUDSNP2.C0079AC395F7=0 REASON 00C90088 TYPE 00000302 NAME DSNDB06 .SYSDBASE.X'0007B3' 13.08.11 CICS Transaction RQ06 is disabled tied to PLAN RQ06SGL using REOPT 13.08.13 CGARPOST BIND Begins

BIND 177 DBRMsSYSPLAN

SYSDBASE

DSNDB06

Executing a REOPT TRAN

REOPT Contention

SYSPLAN Contention

DISABLE

Plan EDMPOOL Load Failure

ENABLE

BIND RC=0

CIC

S Tr

anID

Out

age

SYSP

LAN

Out

ages

ARPOSTQ Outage 15 minutes, 5 seconds RQ06 Outage 13 minutes, 21 seconds Other Plan Outages 4 minutes, 40 seconds

Page 17: I love packages and SQLJ

Page 17I love Packages & Collections So put another dime in the jukebox baby! Page 17IDUG North America 2008

Optimization Hints Sounds good! Difficult to implement and maintain. Use for temporary relief of

performance degradation. Solve the root cause, do not rely on hints as part of the performance strategy.

DSNZPARM change to activate. Programmers should add QUERYNO to their code. Limit scope and use meaningful names.

Hint only those statements needing it, not all statements or query blocks tied to the package. How are you going to name and manage your opthints? Consider hint names tied to your DB2

maintenance release to better track and resolve issues tied to DB2 code releases. With V8, the hint name changed from CHAR(8) to VARCHAR(128).

After code has been bound with explain yes, need to update plan_table rows to add a OPTHINT name (see next slide for sequence).

To return to the good access path previously established, rebind the package with OPTHINT(‘V8RSU0712_H1’).

Verify hints are in use! SQLcode +394 HINT_USED column of PLAN_TABLE Query the special register: CURRENT OPTIMIZATION HINT

Page 18: I love packages and SQLJ

Page 18I love Packages & Collections So put another dime in the jukebox baby! Page 18IDUG North America 2008

A Day in the Life of an Optimization Hint UPDATE PROD.PLAN_TABLE SET OPTHINT = ‘V8RSU0702_H1’ WHERE PROGNAME = ‘LIKESRCH’ AND VERSION = ‘2006-10-26-23.14.02.002004’ AND COLLID = ‘CS_MATCH’ AND QUERYNO IN (7448);

PROD.DX1HINT QUERYNO, APPLNAME, PROGNAME, VERSION, COLLID, OPTHINT

DBUSXPTB.USTSPLTB

RScan Index Access

Is this Index on your PLAN_TABLE?

PLAN_TABLE | before the OPTHINT is sourcedQUERYNO APPLNAME PROGNAME VERSION COLLID OPTHINT HINT_USED

7448 LIKESRCH 2007-02-28-13.22.01.003007 CS_MATCH

7448 LIKESRCH 2006-10-31-13.07.04.004008 CS_MATCH

7448 LIKESRCH 2006-10-26-23.14.02.002004 CS_MATCH

PLAN_TABLE | After the OPTHINT is sourced QUERYNO APPLNAME PROGNAME VERSION COLLID OPTHINT HINT_USED

7448 LIKESRCH 2007-02-28-13.22.01.003007 CS_MATCH

7448 LIKESRCH 2006-10-31-13.07.04.004008 CS_MATCH

7448 LIKESRCH 2006-10-26-23.14.02.002004 CS_MATCH V8RSU0702_H1

PLAN_TABLE | After REBIND OPTHINT('V8RSU0702_H1')QUERYNO APPLNAME PROGNAME VERSION COLLID OPTHINT HINT_USED

7448 LIKESRCH 2007-02-28-13.22.01.003007 CS_MATCH V8RSU0702_H1

7448 LIKESRCH 2006-10-31-13.07.04.004008 CS_MATCH

7448 LIKESRCH 2006-10-26-23.14.02.002004 CS_MATCH V8RSU0702_H1

REBIND PACKAGE(CS_MATCH) MEMBER(LIKESRCH)VERSION(‘2007-02-28-13.22.01.003007’)OPTHINT(‘V8RSU0702_H1’)

Once the hint is statically bound, the optimizer does not have to access the PLAN_TABLE to retrieve the access path which is hinted, it can just run.

YesNo

1

3

2

1

2

Page 19: I love packages and SQLJ

Page 19I love Packages & Collections So put another dime in the jukebox baby! Page 19IDUG North America 2008

Simplify Plan Binds with Package Lists

Package List - the order in which you specify packages. The order can affect performance to a slight degree. Searching for a package involves searching the DB2 directory.

*.collection.* in PKLIST - order collections in the PKLIST by the collections in which DB2 is most likely to find the packages first. Wildcarding everything except the collection can significantly reduce or eliminate the number of plan binds needed.

location.collection.package.version - full naming convention for a package. Specifying beyond collection in your PKLIST is overkill, (with a few exceptions).

Use PKLIST strategy for ease of fallback when migrating to V8. See following slide for details on “free package fallback”.

Package based SQL

Page 20: I love packages and SQLJ

Page 20I love Packages & Collections So put another dime in the jukebox baby! Page 20IDUG North America 2008

Bind a Plan Once and be DONE

BIND(OSHLH)

PKLIST(*.P_SH_LINEHAUL.*, *.P_SH.*,

*.P_CM.*) BIND(SCUMAINT)

PKLIST(*.P_CU.*,

*.P_SH.ML01A11,

*.P_SH.ML01A24,

*.P_CM.*)BIND(BSHLH)

PKLIST(*.P_SH_LINEHAUL.*,

*.P_CM.*)

COLLID (collection name) has increased from CHAR(18) to VARCHAR(128) with V8.

Page 21: I love packages and SQLJ

Page 21I love Packages & Collections So put another dime in the jukebox baby! Page 21IDUG North America 2008

Plan Naming Options

-Less Administration

-More Thread Reuse

-Less Granularity in Ownership & Security

-Greater Control

-Easier Identification of Packages Running

-More Granularity in Ownership & Security

• One per Environment (Batch, OLTP, STC)

• One per Data Focus Area (DFA) | Business Area

• One per DFA | Business Area | Environment

• One per Application

• One per Application | Environment

• One per Program

More than one option may be needed to meet your organization’s needs. Be consistent with your standard.

Page 22: I love packages and SQLJ

Page 22I love Packages & Collections So put another dime in the jukebox baby! Page 22IDUG North America 2008

Naming Standards with Enforcement & ConsistencyObject Physical

Limit & Usage Naming Convention

Description

Collection ID 18 character limit due to CA-Gen limitations. V8 allows 128 Logical container for packages. Specified in plan bind pklist Specified in PACKAGEPATH strings for packages which do not need PLAN ties (SQLJ, SP, Triggers, UDF)

S_DF_xxxxxxxxxx_Z S = Segment P -- Prime segment A -- Acceptance segment F -- break Fix segment M -- Maintenance segment S -- Secondary segment DF = Data Focus area (DFA) CU CV FC FN GO OF PR RG RT RV SH SL IT CM xxxxxxxxxx = Up to 10 characters _Z = Last 2 positions or position 17 & 18 reserved for database team performance work tied to FPF. EXAMPLES: P_CU P_PR_HR_TC P_RV_AR P_SH P_SH_LINEHAUL P_CM Read Only Pattern: RO_S_DF_Z RO = Read Only S = Segment DF = Data Focus area (DFA) _Z = Last 2 positions or Position 17 & 18 reserved for database team performance work tied to free package fallback. Examples: RO_P_RV_Z, RO_P_RV

The DFA pattern in the collection ID enables association and ease of use for package management.

Application granularity through collection encapsulation/isolation is useful when controlling and limiting the scope of execution at a collection container level. This is a common practice for packages with no plan ties. For example, the HRIS SQLJ application using collid PR_HR_HRIS.

FPF = Free Package Fallback. Ability to seed performance rebinds to the high order collection in the PKLIST. Useful for performance work associated to tuning, DB2 maintenance rebinds and DB2 upgrade rebinds. DBA team can free the package from the high order collection, and the package & access path tied the non-high order collection will then be used for that package version.

See table APPCD_DFA_COLLID for relationship between program code, data focus area and collection ID. This table will be integrated into package & plan bind interfaces.

Note special DF patterns: IT - Information Technology, non-business facing development. Typically home grown programs supporting IT back end functions, not business functions. CM - Common Collection. The common collection is for any packages that are shared / executed by more than three DFA. Use when DBRM shared by more than 3 collections.

Page 23: I love packages and SQLJ

Page 23I love Packages & Collections So put another dime in the jukebox baby! Page 23IDUG North America 2008

Free Package Fallback

Bind plan with PKLIST Setup once, and be done

Bind or Rebind package to “_Z” collection Seed performance work to “_Z” collection Rebind after DB2 version and maintenance

upgrades to “_Z” collection

Free package from “_Z” collection for immediate fallback Fallback to previous access paths tied to

base collection(s) Safely manage risk tied to performance Achieve business value from performance

improvements and DB2 maintenance

When satisfied with the “_Z” package performance Bind Copy package(s) to the base collection Free package(s) from the “_Z” collection Keep the “_Z” collections lean and protect

the business from performance degradation

plan

OARCASH *.AR.*

*.CM.*Plan bound to two collections

pklist

plan

OARCASH *.AR_Z.*

*.AR.*

*.CM_Z.*

*.CM.*

Plan bound to four collections

pklist

PKLIST setup for free package fallback

Page 24: I love packages and SQLJ

Page 24I love Packages & Collections So put another dime in the jukebox baby! Page 24IDUG North America 2008

Package & PLAN_TABLE Clean Up

Reduce the size of DSNDB01-SKPT01 (Skeleton Package Table), as well as space associated to DSNDB06 package objects and explain tables.

SCT02 & SPT01 typically on A002 datasets for large catalogs. Quarterly online reorg of DSNDB06/DSNDB01. Do not forget to create the

J0001/I0001 datasets for the .A002 objects to grow into during reorg. Consider the data backup and recovery requirements for the application. If the

old explain data is needed for a recovery or special run, the old DBRM associated to that data is also needed.

Tie package clean up to application releases. Remember to not remove active OPTHINT rows.

For vendor software, consider using version/release naming patterns in the plans and collections to simplify clean up.

Be aware of package free scripts and commands with no where clauses or with wildcarding. Scope creep is not helpful!

Page 25: I love packages and SQLJ

Page 25I love Packages & Collections So put another dime in the jukebox baby! Page 25IDUG North America 2008

SQLJ Overview Static security model

User of application does not need authority on the tables/views Helps guard the data from access outside the application layer

Static performance model Eliminate access path changes at runtime No prepare or dynamic statement cache tuning needed It’s a package

Accounting detail for reliable metrics and workload planning Versioning, built in fallback with known performance characteristics 4 R’s (Real time stats, Reorg with inline Runstats, Rebind)

SQL is the industry standard for RDBMS access layer Less code to write, store, maintain Portable, write once and deploy to multiple applications and RDBMS

Page 26: I love packages and SQLJ

Page 26I love Packages & Collections So put another dime in the jukebox baby! Page 26IDUG North America 2008

Static vs. Dynamic SQL

Performance Prepare time not incurred during runtime execution of static SQL. Ability to lock in access paths and have performance fallback with package versioning. Access path management is externalized into the explain tables as part of the implementation procedures, including flagging of poor

access paths (“DBRM review”) and comparing to prior/future access paths (“DB130 access path compare process”). What if analysis with home grown “programC” interface allows access path evaluation for all static SQL statements tied to a program prior to the program launching into production.

Standard accounting class data available for static SQL. Accounting trace classes (1,2,3,7,8,10). Additional dynamic SQL memory caching requirements in DBM1 not needed for static SQL.

Security Static security model, access to the application vs. the data Supports individual RACF id authentication in addition to application/process id authentication. Supports role based authority application orientation.

Audit Static statements are retrievable from both the source code and DB2’s catalog, providing accountability back to the individual SQL

statement/query number.

Check auth for plan/pkg execute

Execute Statement

Parse SQL statement

Check table/view authority

Determine access path

Check auth for plan/pkg execute

Execute Statement

Dynamic SQL Static SQL

Static SQL minimizes CPU cost during runtime

SQLJ: #sql [con] { SELECT address INTO :address FROM employee WHERE empid =:empId }; JDBC: java.sql.PreparedStatement ps = con.prepareStatement( "SELECT address FROM employee WHERE empid = ?"); ps.setInt(1, empid); java.sql.ResultSet rs = ps.executeQuery(); if (rs.next()) address = rs.getString(1); rs.close();

Page 27: I love packages and SQLJ

Page 27I love Packages & Collections So put another dime in the jukebox baby! Page 27IDUG North America 2008

Source Code - .sqlj

SQLJ Translator

Package

SQLJ Conceptual Picture

Serialized Profile(s) - .ser

Java Class File(s) - .class

db2sqljcustomize

Modified Source - .java

Java Interpreter

contoken generated & encapsulated in .ser

customize options (-collection XX –pkgversion AUTO)

-bindoptions Package Bind

online check, -storebindoptions YES

Customized Serialized Profile - .ser

.class

.ser

.class

.ser

type 4 driver

type 4 driver

prepare / execute

Dynamic Execution Static Execution

contoken match

Page 28: I love packages and SQLJ

Page 28I love Packages & Collections So put another dime in the jukebox baby! Page 28IDUG North America 2008

db2sqljcustomize

Online Check Syntax & semantic validity Check HV data types to target DB data types -qualifier PROD Don’t hard code table/view owners!

-collection FC Default collection is NULLID, recommend avoiding the use of

NULLID for SQLJ application based packages. Treat them like you would your normal packages.

Recommend upper case collection names, using DFA pattern -pkgversion AUTO

Support multiple versions of .sqlj program Inverted timestamp (ascii collating sequence)

-singlepkgname SQLJCustomerCenterDAO Generate 1 package using isolation level specified in the

–bindpotions.. DROP vs. FREE for mixed case package names

-storebindoptions YES Ensures binds to other environments are consistent based on

bindoptions stored in the customized .ser -longpkgname

Full circle (mixed case, map to .class name better) Name is specified after –singlepkgname parm. -longpkgname tells the customizer you are using a name which is

greater than 8 characters in length.

QUALIFIER(TEST) | QUAL(QA) OWNER(@BNDTA) | OWNER(@BNDQA

Value specified needs authority to perform the SQL in the SQLJ program.

Person/Process doing the bind will need create in or packadm on the collection (FC) which will contain the package being bound.

Binder willl need bindagent to the OWNER ID V8 allows ALIAS for explain table resolution. Very helpful for binding

with an owner different from the explain tables you want populated. EXPLAIN(YES) VALIDATE(BIND) COLLECTION(FC) ISOLATION(UR/CS) CURRENTDATA(NO/YES) RELEASE(COMMIT) PROTOCOL(DRDA)

Set in DSNZPARM (DSN6SYSP DBPROTCL=DRDA) JCC Type 4 driver, DRDA connections z9 and zIIP

REOPT(NEVER)

Customize Options -bindoptions

Page 29: I love packages and SQLJ

Page 29I love Packages & Collections So put another dime in the jukebox baby! Page 29IDUG North America 2008

SQLJ Issuance & Runtime Flow

db2sqljcustomize

.ser

.ser

DBT2

BIND PACKAGE

OWNER(@BNDTA) QUAL(FFTA)

.sqlj .java.ser

Code Repository

jcc driver

Test Server

.class

.serJava Interpreter (compile).java .class

DBX1

BIND PACKAGE

OWNER(@BNDQA) QUAL(FFQA)

jcc driver

QA Server

.class

.ser

RuntimeCode Push

.class

.ser

RuntimeCode Push

.class

.ser

Connection url, applid $CSRTA

Connection url, applid $CSRQA

db2sqljbind

db2sqljbind

RACF

FML1234 @APPTFA @BNDTFG @APPTFA $CSRTA @CSRTAE $CSRQA @CSRQAE

@CSRTAE only has Execute on packages in collection A_FC

@APPTFA has bindagent to @BNDTA

@CSRQAE only has Execute on packages in collection A_FC.

jcc driver

Developer laptop

.class

.ser

.ser

ClientUser client user ID [‘FML1234’]

ClientWorkStation client workstation name [‘10.10.86.167’]

ClientAccountingInformation client accounting string [‘Java SQLJ DRDA’]

ClientApplicationInformation client application name [‘Terminal ID Lookup’]

TEST QA

Page 30: I love packages and SQLJ

Page 30I love Packages & Collections So put another dime in the jukebox baby! Page 30IDUG North America 2008

SQLJ Package Promotion Source Code Repository

.SQLJ, .ser, .java

db2sqljprintGrep for required db2sqljbind, bind avoidance, packreview and DB2Binder information.

BindAvoidance SP CallInput: collid, name, version, “B” Output: Exists/Not Exists

.ser file

Not Exists

CLEAN

db2sqljbind

Tuning Loop

PackReview SP CallInput: collid, name, version, “R” Output: Clean/Not Clean

Build PushBuild pushed after db2sqljbind

so no -805 possiblities.

Sqlj package implemented.

Java interpreterInput: .java files

Output: .class filesMultiple builds; only 1 db2sqljbind per sqlj package (location.collid.name.version)

Not clean

EXISTSSqlj package implemented.

Ant script for SQLJ package promotion

Page 31: I love packages and SQLJ

Page 31I love Packages & Collections So put another dime in the jukebox baby! Page 31IDUG North America 2008

SQLJ Performance Tuning Flow

Source Code Repository.SQLJ, .ser, .java

db2sqljprintGrep for required DB2Binder

API and packreview information.

.ser file

CLEAN

com.ibm.db2.jcc.DB2Binder-action REBIND-generic

-package terminalIDLookUp

Tuning Loop

PackReview SP CallInput: collid, name, version, “R” Output: Clean/Not Clean

Sqlj package rebound.

Not clean

Only the collid, name, version will be needed, access to the .ser not required.

Rebind path

RebindBatch Script or User Interface

Page 32: I love packages and SQLJ

Page 32I love Packages & Collections So put another dime in the jukebox baby! Page 32IDUG North America 2008

SQLJ Items to Understand These areas currently support longname packages:

Db2sqljcustomize, db2sqljbind, db2sqljrebind, db2sqljprint DSN6SPRM, ABIND=YES - automatic rebind handles these longname packages SMF data - account data captures longname package execution, etc. SPT01, SYSPACKAGE, etc - Directory and Catalog store, retrieval, execution all work DROP PACKAGE works for longname packages Visual Explain Version 8, V1.0.10 finds and explains packages using longnames

The following z/OS based/sourced code paths do not support longname packages: rebind package bind package copy (to promote sqlj packages from one subsystem to another). In addition to not supporting

greater than 8 character package names, bind/copy also fails to populate the SYSIBM.SYSPACKAGE.REMARKS column of syspackage. db2sqljcustomize and db2sqljbind populate the remarks section using the comment on package to push the sqljprofile name into the remarks column. The package name can be wildcarded as a work around (REBIND PACKAGE HRO_DBP1.SH.*. LBOrQGBs).

FREE PACKAGE does not work for longname packages, need to use drop package syntax

The following is no longer missing from the SQLJ JCC side: DB2Binder sqlj package “rebind” ability (having to checkout the customized .ser from your source code repository

to do a bind, rather than having a native client rebind support is not a good solution. IBM delivered rebind with DB2Binder API and DB2 9 FP3 of DB2 connect, which is compatible with DB2 V8.

Comment on package, bindagent authority should suffice (IBM fixed this)

Related ETR’s open: 35087,370,000 - bind/copy package longname support (requesting IBM to support DSN commands for long name

packages).

Page 33: I love packages and SQLJ

Page 33I love Packages & Collections So put another dime in the jukebox baby! Page 33IDUG North America 2008

Deprecate Obsolete Packages Several packages no longer needed by the business have been identified. How can users

safely remove these packages while having fallback that does not require code being moved into production?

Verify the list of obsolete packages against the accounting data to ensure the package was not active during the previous quarter.

REBIND DISABLE(BATCH,CICS,DB2CALL,DLIBATCH,IMSBMP,IMSMPP,REMOTE,RRSAF) SYSPKSYSTEM, SYSPLSYSTEM

If an application receives an SQLCODE -807, simply rebind the package enabling the environment it runs in. REBIND ENABLE(CICS) – off to the races. SQLCODE -923 for plan based DBRMs.

DSNT408I SQLCODE = -807, ERROR: ACCESS DENIED: PACKAGE FMR7448 IS NOT ENABLED FOR ACCESS FROM BATCH DSNT418I SQLSTATE = 23509 SQLSTATE RETURN CODE

DSNT408I SQLCODE = -923, ERROR: CONNECTION NOT ESTABLISHED: DB2 ACCESS, REASON 00E3001B, TYPE 00000800, NAME FMR7448 DSNT418I SQLSTATE = 57015 SQLSTATE RETURN CODE

Update package dependency rebind queries to exclude packages not enabled for any environment by adding a subselect not exists to SYSPKSYSTEM.

Free obsolete packages after they have been disabled for xx days. Package Invalidator enhancement request (MR102805442).

Page 34: I love packages and SQLJ

Page 34I love Packages & Collections So put another dime in the jukebox baby! Page 34IDUG North America 2008

Valid Versus Operative

The following occurs when a table is dropped that a package depends on: Prior to the drop, the package is both valid and operative.

VALID=Y, OPERATIVE=Y After the drop, the package is invalid and operative.

VALID=N, OPERATIVE=Y Using autobind (dsnzparm) at next execution, the package is marked invalid and

inoperative. VALID=N, OPERATIVE=N. Also applies to an explicit bind. The table has to be created or the source code must be changed to correct the

problem. BINDs (not REBINDs) will pick up the source code changes. Online schema changes will invalidate packages and flush the dynamic SQL statement

cache for the altered object(s). Package invalidator command (see notes for details).

Page 35: I love packages and SQLJ

Page 35I love Packages & Collections So put another dime in the jukebox baby! Page 35IDUG North America 2008

Contoken Query

SELECT COLLID AS COLLECTION, NAME AS PACKAGE,

HEX(CONTOKEN) AS DBRM_TOKEN,

SUBSTRING(HEX(CONTOKEN),9,8) ||

SUBSTRING(HEX(CONTOKEN),1,8) AS LOADLIB_TOKEN,

VERSION, PDSNAME

FROM SYSIBM.SYSPACKAGE

WHERE A.NAME = ‘ML01A24’

ORDER BY NAME, COLLID, VERSION WITH UR;

-------------------------------------------OUTPUT-------------------------------------------------

COLLECTION PACKAGE DBRM_TOKEN LOADLIB_TOKEN

P_SH ML01A24 15D1906116E27DD8 16E27DD815D19061

P_SH ML01A24 15D1906116EF8EC8 16EF8EC815D19061

-805 | package

-818 | plan

Page 36: I love packages and SQLJ

Page 36I love Packages & Collections So put another dime in the jukebox baby! Page 36IDUG North America 2008

Reference Material Naming standards examples for DB2 objects (plans, collections, etc.) Read only package implementation for developer access in production Queries & scripts to help you (see slides that follow)

Packages to monitor and correct Automating the script into a batch job (example) SQLJ scripts, currentdata script

Security issues (see slides that follow) What security is required (use the “least privilege” approach to protect your data) Understand what is needed versus what is easiest Recommended use of Roles and 2nd authid to manage packages effectively

Other package topics Stored procedures and triggers, packageset example (for use on V2.3 - V7) Bind options (acquire, release, isolation, currentdata)

DB2 Listserv (info on lister at www.idug.org) SP Redbook (www.ibm.com/redbooks)

DB2 Packages: Implementation and Use - GG24-4001-00 DB2 9 for z/OS Technical Overview - SG247330 DB2 9 for z/OS Performance Topics - SG247473

SQLJ Development and Deployment DB2 for z/OS Application Programming and SQL Guide DB2 for z/OS Java Application Programming and SQL Guide

Page 37: I love packages and SQLJ

37

Rob CraneFedEx Freight System

[email protected]

[email protected]

Session: F05

I love Packages & Collections So put another dime in the jukebox baby!

Questions?Thanks f

or coming!!!

Page 38: I love packages and SQLJ

Page 38I love Packages & Collections So put another dime in the jukebox baby! Page 38IDUG North America 2008

SET CURRENT PACKAGE PATH PKLIST functionality for packages executed without a plan, allows

collection lists to be searched. No PKLIST associated to DISTSERV (for remote access via DDF

only packages executed on remote server), package path allows us to cross the server one time and resolve package collection lists at the server.

Very useful for applications accessing stored procedure packages from a wide variety of business areas (schemas).

Increases stored procedure nesting flexibility. User defined functions containing multiple programs with multiple

schemas in use, current path can be set to current package path. Special register. Easily implement user selectable isolation level logic. Enables more flexibility with managing shared SQLJ packages.

V8 featu

re

Page 39: I love packages and SQLJ

Page 39I love Packages & Collections So put another dime in the jukebox baby! Page 39IDUG North America 2008

Which collection will a SP use to find the package?

1) Was coll_id denoted on the Create Procedure statement?

2) Was the current package path special register set?

4) Use PKLIST collections’ of calling program

NO

NO

Yes

Yes

Use SP’s catalog entry

Use collections specified by SET CURRENT PACKAGE PATH statement

3) Was the current packageset special register set?

NO Yes Use collection specified by SET CURRENT PACKAGESET statement

Page 40: I love packages and SQLJ

Page 40I love Packages & Collections So put another dime in the jukebox baby! Page 40IDUG North America 2008

Stored Procedures & PACKAGE PATH

BEGIN OUTFITTER SCHEDULER

:in1 = ‘ELK’ :in2 = ‘HORSE BACK’ :in3 = ‘MOUNTAINS’ :in4 = ‘2 HORSES’ :HUNTER = ‘JACQUE PASQUINEL’

:SP_PKLIST = “HUNT_TRIPS”, “HORSE_STOCK”, “REGULATIONS” SET CURRENT PACKAGE PATH = :SP_PKLIST

CALL HNTGUIDE ( in1, in2, in3, in4, tripID)

CHECK GET SQLCODE-ROUTINE

/*Populate HUNT_TABLE */ SELECT OUTFITTER_NAME INTO :OUTFITTER FROM FINAL TABLE (INSERT INTO HUNT_TABLE (OUTFITTER_NAME, HUNTER_NAME, TRIP_ID) VALUES (:OUTFITTER, :HUNTER, :TRIPID) CHECK GET DIAGNOSTICS-ROUTINE

/* Multirow Fetch to populate hunting party array */ DECLARE HUNT_PARTY CURSOR WITH ROWSET POSITIONING FOR SELECT HUNTER, HUNTER_DOB, HUNTER_EXPERIENCE FROM HUNT_TABLE WHERE TRIPID = :TRIPID;

FETCH NEXT ROWSET FROM HUNT_PARTY FOR 10 ROWS INTO :ARRARY_HUNTER, :ARRARY_DOB, :ARRAY_EXPERIENCE; CHECK SQLCODE-ROUTINE

EXIT OUTFITTER SCHEDULER…

PRGMHUNT

HUNT_TRIPS.HNTGUIDE

WHEN(:in2) = HORSE BACK CALL HORSE (in4,horse_resID) SET :TRIP_ID = :horse_resID WHEN(:in2) = ATV CALL REGSATV(in2, atv_resID) SET :TRIP_ID = :atv_resID

WITH RETURN

HORSE_STOCK.HORSE

Reserve :in4 HORSES UPDATE HORSE_TABLE SET :horse_resID = ‘HH-E-M-001’WITH RETURN

REGULATIONS.REGSATV

Validate :in2 SET :atv_resID = ‘not valid’WITH RETURN

WLM SPAS

OUTFITTER_NAME defined as NOT NULL WITH DEFAULT “SELF GUIDED HUNT”

Page 41: I love packages and SQLJ

Page 41I love Packages & Collections So put another dime in the jukebox baby! Page 41IDUG North America 2008

SET CURRENT PACKAGESET

Consider using this option to limit the package search process to a specific collection.

An effective way to handle testing sets and verification of new application releases.

Production applications that implement mirror tables. If you bound your plan with PKLIST (*.package), it is required. This

also implies that run authorization is used since the exact package is not known at bind time.

Use from within the SP package to set collection used. Limitation, only one collection can be specified.

Page 42: I love packages and SQLJ

Page 42I love Packages & Collections So put another dime in the jukebox baby! Page 42IDUG North America 2008

Stored Procedures

BEGIN FISHTRIP SCHEDULER

:in1 = ‘brook trout’

:in2 = ‘horse back’

:in3 = ‘mountains’

SET CURRENT PACKAGESET=‘SCHEMA1’

CALL PBESTFDT( in1, in2, in3, out4)

CHECK SQLCODE-ROUTINE

WHEN(OUT4) >= 7 DAYS

SET VACATION 2 WEEKS

WHEN(OUT4) < 7 DAYS AND >= 4

SET VACATION 1 WEEK

WHEN(OUT4) <= 3 DAYS and > 0

SET VACATION 3 DAYS

EXIT FISHTRIP SCHEDULER

PRGMFISH

WLM SPAS

SCHEMA1. PBESTFDT

RRSAF - attachment calls

Type 2 driver

DB2

DBM1 locates stored procedure, verifies caller can execute, loads SP from the loadlib, executes SP in WLM SPAS.

DSNDB06.SYSOBJ DSNDB06.SYSPAKGE WITH RETURN

EXEC

Page 43: I love packages and SQLJ

Page 43I love Packages & Collections So put another dime in the jukebox baby! Page 43IDUG North America 2008

Triggers are Packages

Triggers based on events that can occur to a table; insert, update, delete. Not fired for utilities.

Triggers can take action BEFORE or AFTER that event. Triggers could invoke a UDF or SP that may take action outside of DB2. Before triggers typically used to validate data. After triggers ensure business rules are met. Salary cannot be updated

more than 20% unless the job role is DBA. Ensure action text is limited with the appropriate WHERE clause. The

“firing” predicates do not limit the action scope. Do not forget REBINDs of trigger packages. (REBIND TRIGGER PACKAGE)

Page 44: I love packages and SQLJ

Page 44I love Packages & Collections So put another dime in the jukebox baby! Page 44IDUG North America 2008

Read-Only Objectives

Provide a mechanism for developers to propagate read-only programs into production without impact to production systems, processes and data.

No outages to production transactions and batch processes as a result of read-only programs. Program access must not conflict or cause production programs to

abend due to locking conflicts. Offer a solution that is segregated from production plans, collections,

packages, load libraries and DBRM libraries. Easily identify the read-only access to ensure impact to business is

acceptable. Cancel the read-only processes that do not achieve that goal.

RO SQL must be tuned; there are better ways to flush a buffer pool.

Not intended for business reporting or deliverables. Not for data zapping.

Page 45: I love packages and SQLJ

Page 45I love Packages & Collections So put another dime in the jukebox baby! Page 45IDUG North America 2008

Read-Only Developer Programs Ability for developers to execute read-only programs against production data using

DB2 packages. Developers read-only 2nd authid will be the owner of the package (@APPPFR). As the

owner, explicit privileges are inherited (bind, execute, free and granting those authorities to others).

Developers will need: PACKADM on the read-only data focus area collection(s) tied to their program codes. Execute on their groups read-only plan(s). Explain tables alias in production for @APPPFR to common set of explain tables. SELECT authority for objects the DBRM (SQL from your program) touches. Obtained through 2nd authid associated to @APPPFR,

which has Select to all non-sox sensitive tables in production.

Developers will perform the following tasks: Program compile, precompile and package binds with EXPLAIN(YES). Follow read-only guidelines. Collaborate with DBA team to establish necessary plan/collection naming standards for developer read-only programs. Ensure COMMIT logic for read-only packages exists!

DBAs will perform the following tasks: Plan bind to appropriate collections, with OWNER(READONLY). Creation of explain tables aliases. (needed only once for @APPPFR) Granting developers PACKADM to appropriate collection(s). Granting of EXECUTE on the read-only plan to the developers. Granting of EXECUTE on the read-only collection(s) to READONLY. Zparm BINDNV set to BIND. Creation of required “PROD” aliases.

Page 46: I love packages and SQLJ

Page 46I love Packages & Collections So put another dime in the jukebox baby! Page 46IDUG North America 2008

Read-Only Plan and Package Bind

Bind plan with PKLIST Bind package

BIND PLAN(PLAN_NAME)

PKLIST(list of collections or individual DBRMs)

RODF####

BIND PACKAGE(collection name)

MEMBER(DBRM aka package / program name)

plan

*.RO_DF_##########.*

.* *.collection.*

*.RO_DF_##########.* PC######

program/package

ROAR *.RO_AR.*,

ROSH *.RO_SH.*,

*.RO_PR_HR_TC.*,

*.RO_CM.*

*.RO_AR.*CV200805

CV000086

CV000067

*.RO_PR_HR_TC.*

TC000925

TC000928

packages

bound to a collection

packages

bound to a collection

Plan bound to three collections

*.collection.*

*.RO_CM.*Plan bound to two collections

Page 47: I love packages and SQLJ

Page 47I love Packages & Collections So put another dime in the jukebox baby! Page 47IDUG North America 2008

Packages to Monitor / Correct

Packages using RR or RS for isolation level. Packages using CURRENTDATA(YES). Packages using DYNAMICRULES(BIND) with OWNER(SYSADM). Packages deferring Validity Checking until run time. Packages using REOPT(VARS). Packages that are Invalid (require BIND/REBIND). Packages that are Inoperative (require explicit BIND/REBIND). Packages bound with EXPLAIN(NO). Packages bound with DEGREE(ANY) if not wanting parallelism

overhead.

Page 48: I love packages and SQLJ

Page 48I love Packages & Collections So put another dime in the jukebox baby! Page 48IDUG North America 2008

Queries to View the Catalog

View all packages dependent on V8 DB2 for z/OS. (1)

View all packages for a given collection and look at the validity of the packages. (2)

View users’ privileges held on a package. (3)

Use WITH UR on all catalog queries!

Page 49: I love packages and SQLJ

Page 49I love Packages & Collections So put another dime in the jukebox baby! Page 49IDUG North America 2008

Are you using only packaged based DBRMs?

Determine which plans are not using collections. Look for AVGSIZE = 0 means package use only. This is what you want, do not use plan based SQL. (4)

Find all packages tied to a plan. (5)

Find all collections tied to a package. (6)

Page 50: I love packages and SQLJ

Page 50I love Packages & Collections So put another dime in the jukebox baby! Page 50IDUG North America 2008

Plan & Package Dependency Queries

Which packages need to be rebound if the SHIPMENT and SHIPMENT_ITEM tables have an online schema evolution column alters performed? (7)

Which programs Insert, Update, Delete rows from the

SHIPMENT_ITEM table? (8)

Page 51: I love packages and SQLJ

Page 51I love Packages & Collections So put another dime in the jukebox baby! Page 51IDUG North America 2008

Package Security

The execute privilege allows the authid with that privilege to include the package in the PKLIST of the plan bind.

Packages are normally not accessed without a plan. Triggers, Stored Procedures and DRDA connections (SQLJ packages) can access packages directly. For these packages, DB2 checks the execute privilege at run time for packages with no plan ties.

For traditional batch and CICS programs, the plan is what is run. The execute privilege on the plan denotes which authid can run the plan, with the SQL found inside the package.

Package operations (Bind Add, Bind Replace, Rebind, Copy, Free, Drop, Execute, Grant All)

Page 52: I love packages and SQLJ

Page 52I love Packages & Collections So put another dime in the jukebox baby! Page 52IDUG North America 2008

Package Privileges - Who & What

Based on DB2 install parameter. Either BINDADD or BIND. BINDADD is more restrictive and is required by the user to add(bind) a package and new versions. BIND is required by the user to add new versions of a package, not to create the first occurrence of a package. DSNZPARM BINDNV.

BIND, REBIND, COPY, EXECUTE granted to authid’s. Either primary or secondary. Use secondary.

DROP - the owner of the package and SYSCTRL. DROP can be useful for freeing mixed case and lower case SQLJ packages.

DROP PACKAGE “NULLID”.”BenefitEnrollements” FREE - the owner of the package, PACKADM and SYSCTRL.

Page 53: I love packages and SQLJ

Page 53I love Packages & Collections So put another dime in the jukebox baby! Page 53IDUG North America 2008

Collection Privileges PACKADM - Easy way to give all package privileges for each package

tied to a collection to an authid. Also gives the CREATE IN privilege. The user gets privileges for the specified collection(s).

CREATE IN - Allows users to bind a package into the specified collection.

Granting at the collection level is an effective way to simplify tasks associated with adding new packages. Grant at the collection level versus individual packages. Execute on collection.* .

Page 54: I love packages and SQLJ

Page 54I love Packages & Collections So put another dime in the jukebox baby! Page 54IDUG North America 2008

Plan & Package Privileges

Who can bind a new plan or package?SYSADM, SYSCTRL authorityBINDADD authority granted to your authidCREATE IN also needed with BINDADD for packages

Who can REBIND or do a BIND(REPLACE)? SYSADM, SYSCTRL authorityBINDAGENT granted by the plan/package ownerPACKADM authority on the collection for packages or BIND

privilege for plans Who can Drop or Free a plan / package?

Page 55: I love packages and SQLJ

Page 55I love Packages & Collections So put another dime in the jukebox baby! Page 55IDUG North America 2008

Plan Specific Privileges

What is needed to execute a Plan?SYSADMOwnership of the planExecute privilege granted to your authid for the plan

Who can include packages in the PKLIST?SYSADM, PACKADM on the collectionOwnership of the packageExecute privilege granted to your authid for the package

Page 56: I love packages and SQLJ

Page 56I love Packages & Collections So put another dime in the jukebox baby! Page 56IDUG North America 2008

Catalog and System Tables

Database Services Component

DB2 Catalog (DSNDB06) DB2 Directory (DSNDB01)

Internal Table Information

Backup Information

DB2 Object Definitions

Plan Information

Package Information

Authorization Permissions

RI Relationships

Stored Procedure Information

Database Information (DBD01)

Log Information (SYSLGNRX)

Plan Information (SCT02)

Package Information (SPT01)

Utility Information (SYSUTILX)

See Appendix F – DB2 Catalog Tables of the SQL Reference for details on catalog table changes associated to V8.

V8

TS TB IX

20 82 119

22 85 138

V7

DSNDB06

Page 57: I love packages and SQLJ

Page 57I love Packages & Collections So put another dime in the jukebox baby! Page 57IDUG North America 2008

Bind Parameters LIBRARY(pds name) - library containing the DBRMs generated from

the precompile MEMBER(dbrm name) - package name OWNER(authid) - owner of the package, explicit rights QUALIFIER(string) - identifies what variable to use for unqualified

names in the package (tables, views, etc.) ENABLE/DISABLE(specify or *) - specify environments where the

package can execute (a must for online transactions where access is usually granted to PUBLIC)

VALIDATE(bind/run) - specify BIND DYNAMICRULES(RUN) - understand the affect of BIND, particularly in

relationship to the owner of the package and the authid’s system privileges. Having SYSADM as the owner in conjunction with DYNAMICRULES(BIND) creates a security exposure for dynamic SQL.

DBPROTCOL(DRDA) - do not use private (zIIP workload)

Page 58: I love packages and SQLJ

Page 58I love Packages & Collections So put another dime in the jukebox baby! Page 58IDUG North America 2008

ACQUIRE

Recommend using ACQUIRE(USE) on all plans. USE is the only option for packages.

Tells DB2 when to acquire the intent locks and what type of lock is needed (IS or IX).

If ACQUIRE(ALLOCATE) is needed, consider using LOCK TABLE IN EXCLUSIVE MODE instead. If the application intends to update every row, denote that in the application versus the bind parameter.

Page 59: I love packages and SQLJ

Page 59I love Packages & Collections So put another dime in the jukebox baby! Page 59IDUG North America 2008

RELEASE(COMMIT)

The old stand-by. Most recognized, understood and used. Allows DB2 to release locks as soon as possible.

Use if the application uses lock escalation, repeatable read isolation level, or mass deleting (this is the only choice).

Prepackaged software with a large number of packages tied to one plan will typically use (COMMIT).

Exclusive (X) page locks are released at commit regardless of the release parameter.

V8 implemented changes to reduce locks passed to XCFAS.

DURATION

Page 60: I love packages and SQLJ

Page 60I love Packages & Collections So put another dime in the jukebox baby! Page 60IDUG North America 2008

RELEASE(DEALLOCATE)

Prior to V8, data sharing systems were recommended to use RELEASE(DEALLOCATE) to reduce tablespace lock activity. V8 changes increased performance of plans and packages bound with RELEASE(COMMIT) by reducing global and false contention for pageset / partition locks.

Good for batch flows with frequent commits. Let batch work take advantage of sequential detection and list prefetch.

Use for a small percentage of protected on-line threads (20%). Persistent threads (those that remain across commits) make this choice more attractive. Determine which on-line threads/packages should use deallocate.

Eliminates traffic to the coupling facility lock structure. Good for data sharing environments and high performance oriented applications.

Thread reuse needs to occur - MONITOR this! An increase in the EDM Pool size is needed due to packages being held longer in the

pool. This can create issues during performance rebinds.

Page 61: I love packages and SQLJ

Page 61I love Packages & Collections So put another dime in the jukebox baby! Page 61IDUG North America 2008

ISOLATION - Lots of Options

Cursor Stability (CS) is the most commonly used option. Locks with the movement of the cursor; only locks qualified data and dirty data if updateable. Releases U locks when DB2 moves off the page or changes to an S or X lock. Acquires and releases Shared locks in the same fashion except when CURRENTDATA(NO) is specified, then S locks are not acquired.

Repeatable Read (RR) reads the data multiple times within the same unit of work with the exact same results. Locks entire page and keeps them locked until commit. Cursors using WITH HOLD retain one page lock for positioning after commit. Resource intensive option.

Read Stability (RS) is very similar to repeatable read with the exception of when the pages are released (similar to a combination between CS and RR). If the page contains no qualifying rows, it will release the lock when it moves off the page. If the page had qualifying rows, it is not released until commit. Data can be reread in the same unit of work with the same result (including additional rows that may now qualify).

SCOPE

Page 62: I love packages and SQLJ

Page 62I love Packages & Collections So put another dime in the jukebox baby! Page 62IDUG North America 2008

Try Uncommitted Read (UR)

Encourage use of ISOLATION(UR) through the statement level. Good choice in most instances, especially decision support applications. What is the likelihood of your application reading incorrect data?

Users can specify at the SQL statement level and override what was used at bind time. SELECT Col1, Col2 FROM TableAAA WHERE Col1=‘value’ WITH UR;

Add to DBA spufi/QMF queries against the catalog tables. This is especially helpful in DR testing when everyone is querying the catalog to build their recovery jobs.

Still need to issue commits for read-only packages that touch objects which have online reorg requirements (to get the drain)!

Page 63: I love packages and SQLJ

Page 63I love Packages & Collections So put another dime in the jukebox baby! Page 63IDUG North America 2008

Default is CURRENTDATA(YES). This is resource intensive. CURRENTDATA(YES) results in lock avoidance on rows that do not qualify the search criteria. CURRENTDATA(NO) may result in lock avoidance on rows that qualified.

ISOLATION(CS) CURRENTDATA(NO) will invoke lock avoidance. If batch jobs are committing properly, DB2 can verify qualifying rows have been committed and will get the page without acquiring page locks. Timestamp processes ensure data integrity!

Most applications tolerate lock avoidance, meaning they do not require the data on the page to remain unchanged while the cursor is on that page.

CURRENTDATA(YES) ensures data under read-only cursors is stable. DB2 ensures data under updateable cursors is stable regardless of currentdata parameter.

Use CURRENTDATA(NO) and avoid ambiguous cursors! Specify FOR READ ONLY or FOR UPDATE OF on your cursors.

Make every effort to use CURRENTDATA(NO). See currentdata query for details on DEFERPREP (sysibm.syspackage) and

EXPREDICATE (sysibm.sysplan).

CURRENTDATA

Page 64: I love packages and SQLJ

Page 64I love Packages & Collections So put another dime in the jukebox baby! Page 64IDUG North America 2008

Currentdata Query

SELECT COUNT(*), 'C-CURRENTDATA-YES-AMBIGUOUS-CURSOR' FROM SYSIBM.SYSPACKAGE WHERE DEFERPREP IN ('C')

UNION ALL

SELECT COUNT(*), 'PRE-CURRENTDATA' FROM SYSIBM.SYSPACKAGE WHERE DEFERPREP IN (' ')

UNION ALL

SELECT COUNT(*), 'B-CURRENTDATA-NO-AMBIGUOUS-CURSOR' FROM SYSIBM.SYSPACKAGE WHERE DEFERPREP IN ('B')

UNION ALL

SELECT COUNT(*), 'A-CURRENTDATA-YES-ALL-CURSOR' FROM SYSIBM.SYSPACKAGE WHERE DEFERPREP IN ('A')

WITH UR;

Page 65: I love packages and SQLJ

Page 65I love Packages & Collections So put another dime in the jukebox baby! Page 65IDUG North America 2008

Automate SQL Scripts

//*-- BUILD THE REBIND FOR THE DISABLE //BLD1RBND EXEC PGM=IKJEFT01,DYNAMNBR=100, // REGION=4M //SYSTSPRT DD SYSOUT=* //SYSTSIN DD * DSN SYSTEM(DSN) RUN PROGRAM(DSNTEP2) PLAN(DSNTEP2) PARMS('/ALIGN(LHS)') - LIB('SYS2.DB2.PROD.RUNLIB.LOAD') //SYSIN DD DSN=AFDB.OBSOLETE.PGMS(DISABLE1),DISP=SHR //SYSPRINT DD DSN=AFDB.OBSOLETE.PGMS.DISABLE1.SPUFIOUT, // DISP=(NEW,CATLG,CATLG),UNIT=SYSDA,SPACE=(CYL,(10,5),RLSE) //SYSUDUMP DD SYSOUT=* //*-- SORT OUT ALL BUT REBIND FROM DSNTEP2 OUTPUT //SRT1RBND EXEC PGM=SORT,REGION=8M //SYSOUT DD SYSOUT=* //SORTIN DD DSN=AFDB.OBSOLETE.PGMS.DISABLE1.SPUFIOUT,DISP=SHR //SORTOUT DD DSN=AFDB.OBSOLETE.PGMS.DISABLE1, // DISP=(NEW,CATLG,CATLG),UNIT=SYSDA,SPACE=(CYL,(10,50),RLSE) //SYSIN DD * SORT FIELDS=COPY OPTION VLSHRT OUTFIL OUTREC=(11,80,TRAN=ALTSEQ),VTOF,VLFILL=X'40' ALTSEQ CODE=(4F40) INCLUDE COND=(12,12,CH,EQ,C'REBIND PACKA',OR, 12,12,CH,EQ,C'REBIND PLAN(',OR, 12,12,CH,EQ,C'DISABLE(BATC',OR, 12,12,CH,EQ,C'EXPLAIN(YES)') /*

Page 66: I love packages and SQLJ

Page 66I love Packages & Collections So put another dime in the jukebox baby! Page 66IDUG North America 2008

db2sqljbind

C:\Crane\DB2\SQLJ>db2sqljbind -url jdbc:db2://afw3.hro.af.com:5040/AFDSNX -user

rac9296 -password 1234567 -staticpositioned YES -bindoptions "DBPROTOCOL(DRDA)

DEGREE(1) EXPLAIN(YES) ISOLATION(UR) OWNER(FXFQ) QUALIFIER(QA) RELEASE(COMMIT) R

EOPT(NEVER) SQLERROR(NOPACKAGE) VALIDATE(BIND) CURRENTDATA(NO) COLLECTION(FC) ACT

ION(REPLACE)" SQLJCustomerCenterDAO_SJProfile0.ser

[ibm][db2][jcc][sqlj] Begin Bind

[ibm][db2][jcc][sqlj] Loading profile: SQLJCustomerCenterDAO_SJProfile0

[ibm][db2][jcc][sqlj] User bind options: DBPROTOCOL(DRDA) DEGREE(1) EXPLAIN(YES)

ISOLATION(UR) OWNER(FXFQ) QUALIFIER(QA) RELEASE(COMMIT) REOPT(NEVER) SQLERROR(NO

PACKAGE) VALIDATE(BIND) CURRENTDATA(NO) COLLECTION(FC) ACTION(REPLACE)

[ibm][db2][jcc][sqlj] Driver defaults(user may override): BLOCKING ALL

[ibm][db2][jcc][sqlj] Fixed driver options: DATETIME ISO DYNAMICRULES BIND

[ibm][db2][jcc][sqlj] Binding package SQLJCustomerCenterDAO

[ibm][db2][jcc][sqlj] Bind complete for SQLJCustomerCenterDAO_SJProfile0

Page 67: I love packages and SQLJ

Page 67I love Packages & Collections So put another dime in the jukebox baby! Page 67IDUG North America 2008

db2sqljprint C:\Crane\DB2\SQLJ>db2sqljprint SQLJCustomerCenterDAO_SJProfile0.ser

Page 68: I love packages and SQLJ

Page 68I love Packages & Collections So put another dime in the jukebox baby! Page 68IDUG North America 2008

SQLJ REBIND Package Script

//SQLJRBND JOB X,CRANE,CLASS=P,MSGCLASS=X,NOTIFY=&SYSUID //BIND EXEC PGM=IKJEFT01,DYNAMNBR=20,REGION=8M //STEPLIB DD DSN=SYS2.DB2.PROD.SDSNLOAD,DISP=SHR //SYSTSPRT DD SYSOUT=* //SYSPRINT DD SYSOUT=* //SYSUDUMP DD SYSOUT=* //SYSTSIN DD * DSN SYSTEM(DSN) REBIND PACKAGE(HR_HRIS.BENDEP.(pAHrQGBs)) - EXPLAIN(YES) OWNER(AFW) QUALIFIER(PROD) RETAIN REBIND PACKAGE(HR_HRIS.BENDTL.(LBOrQGBs)) - EXPLAIN(YES) OWNER(AFW) QUALIFIER(PROD) RETAIN REBIND PACKAGE(HR_HRIS.BENENR.(SBArQGBs)) - EXPLAIN(YES) OWNER(AFW) QUALIFIER(PROD) RETAIN

Page 69: I love packages and SQLJ

Page 69I love Packages & Collections So put another dime in the jukebox baby! Page 69IDUG North America 2008

SQLJ COPY Package Script//SQLJCOPY JOB X,SQLJCPY,CLASS=8,MSGCLASS=X,NOTIFY=&SYSUID //BIND EXEC PGM=IKJEFT01,DYNAMNBR=20,REGION=8M //STEPLIB DD DSN=SYS2.DB2.TEST.SDSNLOAD,DISP=SHR //SYSTSPRT DD SYSOUT=* //SYSPRINT DD SYSOUT=* //SYSUDUMP DD SYSOUT=* //SYSTSIN DD * DSN SYSTEM(DSNB) BIND PACKAGE(AFDSNP.HR_HRIS) - COPY(HR_HRIS.BENDEP) COPYVER(pAHrQGBs) - ACTION(REPLACE) ISO(UR) OWNER(AFW) QUAL(PROD) BIND PACKAGE(AFDSNP.HR_HRIS) - COPY(HR_HRIS.BENDTL) COPYVER(LBOrQGBs) - ACTION(REPLACE) ISO(UR) OWNER(AFW) QUAL(PROD) BIND PACKAGE(AFDSNP.HR_HRIS) - COPY(HR_HRIS.BENENR) COPYVER(SBArQGBs) - ACTION(REPLACE) ISO(UR) OWNER(AFW) QUAL(PROD)

Page 70: I love packages and SQLJ

70

Rob CraneFedEx Freight System

[email protected]

[email protected]

Session: F05

I love Packages & Collections So put another dime in the jukebox baby!

Questions?Thanks f

or coming!!!