Session: F05
I Love Packages & Collections
So put another dime in the jukebox baby!
Rob Crane II FedEx Freight System
May 20, 2008 • 09:15 a.m. – 10:15 a.m. Platform: DB2 for z/OS
FedEx Freight Production DB2 Overview
z9 – 2094-715 z9 – 2094-702
AFW1 (15)
DB2 Subsystem DBP1 CICS PIPES
BATCH
AFW2 (2)
DB2 Subsystem DBP2
ESS Shark
8100
800
800
DS Group DRDA
DSN
SAN
BATCH
DRDA
CF01 (1)
Group Buffer Pools
CF02 (1)
Shared Com Area Lock Structure
Virtual Tape Server
JMS
128/12 Drives
AFWC (1)
CA SPOOL
Automated Tape Library
CDC
JHS
22 Drives | 3592, 3590
6,143 MIPS
6 TB data 4 billion SQL every 24 hrs
1,127 MIPS
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 2
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, review of the skeleton cursor and package tables
Package Execution Flow and System & Catalog Table Overview
Recommendations for Implementing and Maintaining Packages
Ensuring only package based SQL
Review DSNDB01 & DSNDB06 tables and purpose, with V8 updates
Advanced Package Topics & Problem Resolution
Java & SQLJ package deployment
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
Reference Material
Deprecating obsolete packages What makes a package invalid and inoperative? Consistency token investigation, solve your -805s
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)
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 3
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)
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 4
Understanding the Relationship
Plan, collection and package relationship plan(s) package path
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 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) (for
collection(s)
Execution ties, how DB2 finds your COLLID and package
BATCH EXECUTE PLAN(xxxxxxxx) PROGRAM(pppppppp) CICS RDO ties TRANid to PLAN
package(s)
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.
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 5
SOURCE
The Big Picture
PRECOMPILE
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)
PreCompile Mod-Source
CONTOKEN
DBRM
CONTOKEN
Compile Link
plan
BIND
BIND Translates SQL into executable instructions. Validates objects against the DB2 catalog tables. Optimizes SQL - Access Path Selection. Validates security / authorizations.
package
Load
executes in THREAD App Address Space
CICS/BATCH/TSO
SQL call
REBIND
executes in
DBRM name CONTOKEN Section # Statement #
DSNHLI
DB2 Address Space
REBIND Validates 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].
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 6
Execution Flow – One Layer Deeper
SQL Call DSNHLI Entry Point
Parm list (DBRM name, contoken, Section #, Statement #)
Rid Pool
DSNDB01
Sort Pool Buffer Pool
BP0
SKCT & SKPT pages are read into the database buffer pool Pages copied into EDM pool, which is in DBM1 below the 2 GB bar.
Castout Engine Work Area
Compression Dictionary Buffer ControlBlocks EDM DBD Pool LOB Global Dynamic Statement Cache
DBM1
2 GB bar EDM Pool Thread Storage
Application Copy SKPT SKCT CT
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 7
Plan and Package Bind
Bind plan with PKLIST
BIND PLAN(PLAN_NAME) PKLIST(list of collections or individual DBRMs)
Bind package
BIND PACKAGE(collection name) MEMBER(DBRM aka package / program name)
DSNDB06 catalog
DSNDB01 directory
DSNDB06 catalog SYSPACKAGE * SYSPACKSTMT SYSPACKAUTH
DSNDB01 directory
SYSPLAN
*REMARKS
SCT02
SPT01
SYSPACKLIST SYSPLANAUTH
SYSPLANSYSTEM
SYSPACKDEP
SYSPKSYSTEM
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 8
Joan Jett Loves Package Based SQL!
DBRM A
CONTOKEN
DBRM B
CONTOKEN
DBRM A
CONTOKEN BIND PLAN OSHDE19 MEMBER(A) LIBRARY(„FXes.DBRMLIB‟) PKLIST( *.s_SH.*, *.s_CM); BIND PLAN OSHDE19 PKLIST( *.s_SH.*, *.s_CM);
BIND PLAN OSHDE19 MEMBER(A,B) LIBRARY(„FXes.DBRMLIB‟);
DB2 plan
DB2 plan
DBRM A
CONTOKEN
DB2 plan
DBRM B
CONTOKEN
BIND PACKAGE(s_SH) MEMBER(B) LIBRARY(„FXes.DBRMLIB‟);
DBRM B
CONTOKEN
BIND PACKAGE(s_SH) MEMBER(A) LIBRARY(„FXes.DBRMLIB‟) ; BIND PACKAGE(s_SH) MEMBER(B) LIBRARY(„FXes.DBRMLIB‟);
DB2 Package
Plan based SQL No versioning allowed Plan & Package based SQL
Versioning only allowed for packaged based dbrm
DB2 Package
Packaged based SQL Versioning allowed
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 9
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‟
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 10
V8 in New Function Mode (NFM)
Precompile – NEWFUN YES Unicode Database Request Module
DBRM, all SQL statements in UNICODE - UTF 8 - CCSID(1208)
Bind with EXPLAIN(YES) Package / Plan executes in DB2 Address Space
OPTHINT Performance Tuning
PLAN_TABLE
DSN_FUNCTION_TABLE DSN_DETCOST_TABLE DSN_PGRANGE_TABLE DSN_PREDICAT_TABLE DSN_SORT_TABLE DSN_STRUCT_TABLE DSN_STATEMNT_TABLE DSN_FILTER_TABLE DSN_PGROUP_TABLE DSN_PTASK_TABLE DSN_SORTKEY_TABLE DSN_VIEWREF_TABLE
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 11
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
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 12
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)
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 13
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. Ability to EXPLAIN from statements in the dynamic statement cache once in V8 NFM.
V7.PLAN_TABLE, V8CM_PLAN_TABLE, V8NFM.PLAN_TABLE DSN_STATEMENT_CACHE_AUX DSN_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.
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 14
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 Available for static and dynamic SQL Carry over of REOPT(VARS) from V7 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. 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
REOPT(ALWAYS)
REOPT(ONCE)
Static SQL | package level 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.)
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 15
Executing a REOPT TRAN
DISABLE
Caveats with REOPT
CICS TranID Outage
13.16.08 STC13637 DSNI031I -DBP2 DSNILKES - LOCK ESCALATION HAS OCCURRED FOR RESOURCE NAME = DSNDB06.SYSPLAN SYSDBASE LOCK STATE = X ARPOSTQ Outage 15 minutes, 5 seconds BIND 177 DBRMs PLAN NAME : PACKAGE NAME = DSNBIND : N/A RQ06 Outage 13 minutes, 21 seconds SYSPLAN COLLECTION-ID = N/A Other Plan Outages 4 minutes, 40 seconds STATEMENT NUMBER = N/A CORRELATION-ID = CGARPOST SYSPLAN CONNECTION-ID = BATCH Contention BIND LUW-ID = USARFW01.LUDSNP2.C0079D34792B RC=0 THREAD-INFO = STCUSER : * Plan EDMPOOL 13.20.36 STC13736 DSNT501I -DBP1 DSNILMCL RESOURCE UNAVAILABLE Load Failure CORRELATION-ID=POOLEQ030135 ENABLE CONNECTION-ID=CICSCOM2 LUW-ID=USARFW01.LUDSNP.C0079DA6108D=0 13.05.43 STC13637 DSNT375I -DBP2 PLAN=DSNBIND WITH REASON 00C9008E CORRELATION-ID=CGARPOST TYPE 00000200 CONNECTION-ID=BATCH NAME DSNDB06 .SYSPLAN LUW-ID=USARFW01.LUDSNP2.C0079AC395F7=15307 13.20.36 STC13736 DSNT501I -DBP1 DSNILMCL RESOURCE UNAVAILABLE THREAD-INFO=STCUSER:*:*:* CORRELATION-ID=IV710DO IS DEADLOCKED WITH PLAN=RQ06SGL WITH CONNECTION-ID=BATCH CORRELATION-ID=ENTRRQ060037 LUW-ID=USARFW01.LUDSNP.C0079D47A4A2=0 CONNECTION-ID=CICSCOM2 REASON 00C9008E LUW-ID=USARFW01.LUDSNP.C0079A5B8C70=122665 TYPE 00000200 THREAD-INFO=CICSUSER:*:*:* NAME DSNDB06 .SYSPLAN ON MEMBER DBP1 13.20.36 STC13736 DSNT501I -DBP1 DSNILMCL RESOURCE UNAVAILABLE 13.05.43 STC13637 DSNT501I -DBP2 DSNILMCL RESOURCE UNAVAILABLE CORRELATION-ID=POOLIV780100 CORRELATION-ID=CGARPOST CONNECTION-ID=CICSWEBB CONNECTION-ID=BATCH LUW-ID=USARFW01.LUDSNP.C0079D9E0E81=0 LUW-ID=USARFW01.LUDSNP2.C0079AC395F7=0 REASON 00C9008E REASON 00C90088 TYPE 00000200 TYPE 00000302 NAME DSNDB06 .SYSPLAN NAME DSNDB06 .SYSDBASE.X'0007B3' 13.20.48 CGARPOST BIND Completed, RC=0 13.08.11 CICS Transaction RQ06 is disabled tied to PLAN RQ06SGL using REOPT 13.21.32 CICS Transaction RQ06 enabled 13.08.13 CGARPOST BIND Begins DSNDB06
SYSPLAN Outages
REOPT Contention
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 16
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 I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 17
1
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);
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.
3
No
Is this Index on your PLAN_TABLE?
Yes
PLAN_TABLE | before the OPTHINT is sourced QUERYNO 7448 7448 7448 APPLNAME PROGNAME LIKESRCH LIKESRCH LIKESRCH VERSION 2007-02-28-13.22.01.003007 2006-10-31-13.07.04.004008 2006-10-26-23.14.02.002004 COLLID CS_MATCH CS_MATCH CS_MATCH OPTHINT HINT_USED
RScan DBUSXPTB.USTSPLTB
Index Access PROD.DX1HINT QUERYNO, APPLNAME, PROGNAME, VERSION, COLLID, OPTHINT
PLAN_TABLE | After the OPTHINT is sourced
1
QUERYNO 7448 7448 7448
APPLNAME
PROGNAME LIKESRCH LIKESRCH LIKESRCH
VERSION 2007-02-28-13.22.01.003007 2006-10-31-13.07.04.004008 2006-10-26-23.14.02.002004
COLLID CS_MATCH CS_MATCH CS_MATCH
OPTHINT
HINT_USED
V8RSU0702_H1
PLAN_TABLE | After REBIND OPTHINT('V8RSU0702_H1')
2
REBIND PACKAGE(CS_MATCH) MEMBER(LIKESRCH) VERSION(„2007-02-28-13.22.01.003007‟) OPTHINT(„V8RSU0702_H1‟)
2
QUERYNO 7448 7448 7448
APPLNAME
PROGNAME LIKESRCH LIKESRCH LIKESRCH
VERSION 2007-02-28-13.22.01.003007 2006-10-31-13.07.04.004008 2006-10-26-23.14.02.002004
COLLID CS_MATCH CS_MATCH CS_MATCH
OPTHINT
HINT_USED V8RSU0702_H1
V8RSU0702_H1
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 18
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”.
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 19
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, BIND(BSHLH) PKLIST(*.P_SH_LINEHAUL.*, *.P_CM.*) *.P_CM.*)
COLLID (collection name) has increased from CHAR(18) to VARCHAR(128) with V8.
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 20
Plan Naming Options
• One per Environment (Batch, OLTP, STC)
-Less Administration • One per Data Focus Area (DFA) | Business Area • One per DFA | Business Area | Environment • One per Application -Greater Control • One per Application | Environment • One per Program -More Thread Reuse -Less Granularity in Ownership & Security
-Easier Identification of Packages Running
-More Granularity in Ownership & Security
More than one option may be needed to meet your organization‟s needs. Be consistent with your standard.
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 21
Naming Standards with Enforcement & Consistency
Object
Collection ID
Physical Limit & Usage
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)
Naming Convention
S_DF_xxxxxxxxxx_Z S = P A F M S Segment -- Prime segment -- Acceptance segment -- break Fix segment -- Maintenance segment -- Secondary segment
Description
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, nonbusiness 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.
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
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 22
Free Package Fallback
Bind plan with PKLIST Setup once, and be done
plan pklist *.AR.* *.CM.*
Plan bound to two collections
Bind or Rebind package to “_Z” collection
Seed performance work to “_Z” collection Rebind after DB2 version and maintenance upgrades to “_Z” collection
OARCASH
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
PKLIST setup for free package fallback
plan OARCASH
Plan bound to four collections
pklist *.AR_Z.* *.AR.* *.CM_Z.* *.CM.*
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
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 23
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!
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 24
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
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 25
Static vs. Dynamic SQL
Dynamic SQL
Check auth for plan/pkg execute
Static SQL
Check auth for plan/pkg execute
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();
Parse SQL statement
Check table/view authority
Determine access path
Execute Statement
Execute Statement
Static SQL minimizes CPU cost during runtime
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. 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. Static statements are retrievable from both the source code and DB2‟s catalog, providing accountability back to the individual SQL statement/query number.
Security
Audit
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 26
SQLJ
Conceptual Picture
Source Code - .sqlj SQLJ Translator
Modified Source - .java Java Interpreter Java Class File(s) - .class
Dynamic Execution
.ser .class .class
contoken match
Serialized Profile(s) - .ser db2sqljcustomize
Customized Serialized Profile - .ser
contoken generated & encapsulated in .ser customize options (-collection XX –pkgversion AUTO) online check, -storebindoptions YES -bindoptions Package Bind
Static Execution
.ser
type 4 driver
type 4 driver
prepare / execute
Package
IDUG North America 2008
I love Packages & Collections
So put another dime in the jukebox baby!
Page 27
db2sqljcustomize
Customize Options
Online Check
Syntax & semantic validity Check HV data types to target DB data types -qualifier PROD Don‟t hard code table/view owners! 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 Support multiple versions of .sqlj program Inverted timestamp (ascii collating sequence) Generate 1 package using isolation level specified in the –bindpotions.. DROP vs. FREE for mixed case package names Ensures binds to other environments are consistent based on bindoptions stored in the customized .ser 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.
-bindoptions
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.
-collection FC
-pkgversion AUTO -singlepkgname SQLJCustomerCenterDAO
-storebindoptions YES -longpkgname
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)
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 28
SQLJ
Issuance & Runtime Flow
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‟]
Runtime
Code Push
Test Server
.ser .class
Runtime
Code Push
QA Server
.ser .class
.java
Java Interpreter (compile)
.class .class
.class
.ser
jcc driver Connection url, applid $CSRTA
.ser
jcc driver Connection url, applid $CSRQA
Code Repository
.ser
.sqlj
.ser
.java
db2sqljcustomize
.ser
Developer laptop
.ser
.class
.ser
jcc driver
DBT2 BIND PACKAGE
db2sqljbind
DBX1 BIND PACKAGE OWNER(@BNDQA) QUAL(FFQA)
@CSRQAE only has Execute on packages in collection A_FC.
db2sqljbind
OWNER(@BNDTA) QUAL(FFTA) RACF FML1234 @APPTFA @BNDTFG @APPTFA $CSRTA @CSRTAE $CSRQA @CSRQAE
@CSRTAE only has Execute on packages in collection A_FC @APPTFA has bindagent to @BNDTA
TEST
IDUG North America 2008
QA
I love Packages & Collections
So put another dime in the jukebox baby!
Page 29
SQLJ
Package Promotion
Source Code Repository
.SQLJ, .ser, .java
.ser file
db2sqljprint
Grep for required db2sqljbind, bind avoidance, packreview and DB2Binder information.
BindAvoidance SP Call
Input: collid, name, version, “B” Output: Exists/Not Exists
Not Exists
EXISTS
Sqlj package implemented.
Ant script for SQLJ package promotion
db2sqljbind
PackReview SP Call
Input: collid, name, version, “R” Output: Clean/Not Clean
CLEAN
Not clean
Tuning Loop
Sqlj package implemented.
Java interpreter
Input: .java files Output: .class files Multiple builds; only 1 db2sqljbind per sqlj package (location.collid.name.version)
Build Push
Build pushed after db2sqljbind so no -805 possiblities.
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 30
SQLJ
Performance Tuning Flow
Rebind path
Source Code Repository
.SQLJ, .ser, .java
.ser file
Rebind Batch Script or User Interface Only the collid, name, version will be needed, access to the .ser not required.
db2sqljprint
Grep for required DB2Binder API and packreview information.
com.ibm.db2.
jcc.DB2Binder -action REBIND-generic
-package terminalIDLookUp
PackReview SP Call
Input: collid, name, version, “R” Output: Clean/Not Clean
CLEAN
Not clean
Tuning Loop
Sqlj package rebound.
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 31
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).
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 32
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) 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 REASON 00E3001B, TYPE 00000800, NAME FMR7448 DSNT418I SQLSTATE = 57015 SQLSTATE RETURN CODE ACCESS,
SYSPKSYSTEM, SYSPLSYSTEM
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).
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 33
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).
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 34
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‟
-805 | package -818 | plan
ORDER BY NAME, COLLID, VERSION WITH UR;
-------------------------------------------OUTPUT------------------------------------------------COLLECTION P_SH P_SH PACKAGE ML01A24 ML01A24 DBRM_TOKEN 15D1906116E27DD8 15D1906116EF8EC8 LOADLIB_TOKEN 16E27DD815D19061 16EF8EC815D19061
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 35
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 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 Stored procedures and triggers, packageset example (for use on V2.3 - V7) Bind options (acquire, release, isolation, currentdata)
Security issues (see slides that follow)
Other package topics
DB2 Listserv (info on lister at www.idug.org) SP Redbook (www.ibm.com/redbooks)
SQLJ Development and Deployment DB2 for z/OS Application Programming and SQL Guide DB2 for z/OS Java Application Programming and SQL Guide
DB2 Packages: Implementation and Use - GG24-4001-00 DB2 9 for z/OS Technical Overview - SG247330 DB2 9 for z/OS Performance Topics - SG247473
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 36
Session: F05
I love Packages & Collections So put another dime in the jukebox baby!
Rob Crane
FedEx Freight System
rob.crane@fedex.com racraneii@comcast.net
Questions?
37
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.
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 38
Which collection will a SP use to find the package?
1) Was coll_id denoted on the Create Procedure statement?
NO
Yes
Use SP’s catalog entry
2) Was the current package path special register set?
NO
Yes
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
4) Use PKLIST collections’ of calling program
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 39
Stored Procedures & PACKAGE PATH
PRGMHUNT
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
WLM SPAS
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
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…
OUTFITTER_NAME defined as NOT NULL WITH DEFAULT “SELF GUIDED HUNT”
REGULATIONS.REGSATV Validate :in2 SET :atv_resID = „not valid‟
WITH RETURN
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 40
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.
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 41
Stored Procedures
PRGMFISH
BEGIN FISHTRIP SCHEDULER :in1 = „brook trout‟ :in2 = „horse back‟ :in3 = „mountains‟ SET CURRENT PACKAGESET=„SCHEMA1‟
DB2 DBM1 locates stored procedure, verifies caller can execute, loads SP from the loadlib, executes SP in WLM SPAS.
WLM SPAS
EXEC
CALL PBESTFDT( in1, in2, in3, out4)
CHECK SQLCODE-ROUTINE WHEN(OUT4) >= 7 DAYS SET VACATION 2 WEEKS
SCHEMA1. PBESTFDT
WHEN(OUT4) < 7 DAYS AND >= 4
SET VACATION 1 WEEK WHEN(OUT4) <= 3 DAYS and > 0 SET VACATION 3 DAYS EXIT FISHTRIP SCHEDULER
DSNDB06.SYSOBJ DSNDB06.SYSPAKGE
WITH RETURN
RRSAF - attachment calls Type 2 driver
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 42
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)
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 43
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.
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 44
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.
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 45
Read-Only Plan and Package Bind
Bind plan with PKLIST
BIND PLAN(PLAN_NAME) PKLIST(list of collections or individual DBRMs)
Bind package
BIND PACKAGE(collection name) MEMBER(DBRM aka package / program name)
plan RODF#### ROAR
Plan bound to three collections
*.collection.* *.RO_DF_##########.* *.RO_AR.*, *.RO_PR_HR_TC.*, *.RO_CM.*
.* *.collection.* *.RO_DF_##########.* *.RO_AR.*
packages bound to a collection
program/package PC######
CV200805 CV000086 CV000067
ROSH
Plan bound to two collections
*.RO_SH.*, *.RO_CM.*
*.RO_PR_HR_TC.*
packages
TC000925
bound to a collection
TC000928
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 46
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.
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 47
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!
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 48
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)
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 49
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)
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 50
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)
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 51
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.
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 52
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.* .
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 53
Plan & Package Privileges
Who can bind a new plan or package? SYSADM, SYSCTRL authority BINDADD authority granted to your authid CREATE IN also needed with BINDADD for packages Who can REBIND or do a BIND(REPLACE)? SYSADM, SYSCTRL authority BINDAGENT granted by the plan/package owner PACKADM authority on the collection for packages or BIND privilege for plans Who can Drop or Free a plan / package?
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 54
Plan Specific Privileges
What is needed to execute a Plan? SYSADM Ownership of the plan Execute privilege granted to your authid for the plan Who can include packages in the PKLIST? SYSADM, PACKADM on the collection Ownership of the package Execute privilege granted to your authid for the package
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 55
Catalog and System Tables
Database Services Component DB2 Catalog (DSNDB06) Internal Table Information Backup Information DB2 Object Definitions Plan Information Package Information Authorization Permissions RI Relationships Stored Procedure Information
V7 See Appendix F – DB2 Catalog Tables of the SQL Reference for details on catalog table changes associated to V8. V8
TS 20 22
DB2 Directory (DSNDB01) Database Information (DBD01) Log Information Plan Information Utility Information (SYSLGNRX) (SCT02) (SYSUTILX)
Package Information (SPT01)
DSNDB06
TB 82 85 IX 119 138
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 56
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)
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 57
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.
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 58
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.
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 59
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.
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 60
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).
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 61
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)!
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 62
CURRENTDATA
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).
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 63
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; I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 64
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)') /*
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 65
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
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 66
db2sqljprint
C:\Crane\DB2\SQLJ>db2sqljprint SQLJCustomerCenterDAO_SJProfile0.ser
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 67
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
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 68
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)
I love Packages & Collections
So put another dime in the jukebox baby!
IDUG North America 2008
Page 69
Session: F05
I love Packages & Collections So put another dime in the jukebox baby!
Rob Crane
FedEx Freight System
rob.crane@fedex.com racraneii@comcast.net
Questions?
70