SlideShare a Scribd company logo
1 of 24
Download to read offline
#IDUG
Using RELEASE(DEALLOCATE)
and Painful Lessons to be Learned on DB2 Locking
John Campbell
DB2 for z/OS Development
Session Code: 6007
#IDUG
2
Agenda
• Thread reuse using RELEASE(DEALLOCATE)
• Primer on thread reuse with RELEASE bind option
• Considerations and limitations
• Painful Lessons to be Learned on DB2 Locking
• Primer on lock avoidance
• CURRENTDATA(YES) versus CURRENTDATA(NO)
• Ramifications of lock avoidance for SQL
• What should an application programmer do
• Finding packages to safely rebind with CURRENTDATA(NO)
#IDUG
3
“Resources”: Static SQL
• Static statements
• Packages and statements
• Parent locks
• Index look-aside buffer, dynamic prefetch tracking via sequential detection
#IDUG
4
RELEASE - BIND and REBIND Option
• Determines when to release the resources that a program uses
• RELEASE(COMMIT) - Releases resources at commit point
• RELEASE(DEALLOCATE) - Releases resources when thread terminates (child
page/row locks still released at commit)
• RELEASE(INHERITFROMPLAN) – Support added by APAR PM07087
• Default behavior
• BIND PLAN - COMMIT
• BIND PACKAGE - plan value
• REBIND PLAN/PACKAGE existing value
• DB2Binder Utility for JDBC and SQLJ
• DEALLOCATE is default in DB2 10
• COMMIT is default in DB2 9 and earlier releases
#IDUG
Package Allocation
Program A :
“Insert into table 1”
Thread allocation
Sign on, authorization checking
Locate SKCT and SKPT
Allocate CT/PT and STMT1
Start Insert STMT1
Lock table space 1
Lock data page
End STMT1
“insert into table 2”
Allocate STMT2
Start Insert STMT2
Lock table space 2
Lock data page
End STMT2
COMMIT ;
Program A
Stmt 1: Insert into table1
Stmt 2: Insert into table2
SPT01
EDM_SKELTON_POOL
SKCT/SKPT
V10 Thread storage above the bar
V9 EDM thread pool below the bar
CT
PT
SQL Stmt1
SQL Stmt2
I/O
#IDUG
6
Package Allocation and Commit
Program A
Stmt 1: Insert into table1
Stmt 2: Insert into table2
Commit ;
SPT01
EDM_SKELTON_POOL
SKCT/SKPT
V10 Thread storage above the bar
V9 EDM thread pool below the bar
CT
PT
SQL Stmt1
SQL Stmt2
I/O
Expensive Operation!
Lock TS 1
Lock table1 data page
Lock TS 2
Lock table2 data page
RELEASE PT, statements
Unlock data pages
Unlock TS1, TS2
COMMIT
#IDUG
7
Thread Reuse and RELEASE(DEALLOCATE)
• Thread reuse eliminates CPU cost of DB2 thread allocation and deallocation
• CICS
• Protected ENTRYs
• Organic reuse of ENTRYs (or POOL)
• IMS/TM
• Fast Path (IFP) regions
• Wait-For-Input (WFI) regions
• Pseudo Wait-For-Input (PWFI) regions
• DDF
• High Performance DBATs
• WebSphere Type 2 local connections
• Batch with intermediate commits
• Use of RELEASE(DEALLOCATE) coupled with effective thread reuse i.e., thread
persistence
• Further reduces the CPU cost with potential for significant savings (up to 10% plus)
• Resources are held until thread deallocation
• Without thread reuse RELEASE(COMMIT) vs. RELEASE(DEALLOCATE) is a moot point for
discussion
#IDUG
8
Limitations and Considerations
• Virtual and real storage
• DB2 9 and earlier - DBM1 virtual storage below the 2G bar and real storage
• Package information is stored in EDM pool below the bar
• DB2 10 after REBIND - real storage usage
• Package information is stored in thread storage above the bar in DB2 9 and earlier
releases
• Accumulated DB2 object control blocks
• Virtual, real, potentially CPU cost for scanning the objects built up under the thread
• Recommendations
• Design for thread reuse for
• High volume simple transactions
• Complex transactions at a reasonably high rate
• Selectively use RELEASE(DEALLOCATE) on high use packages – use % of Total Acctg Class
7 CPU
• DBM1 31-bit virtual storage constraint (DB2 9)
• Real storage constraint (DB2 10)
• Use CICS or WebSphere parameter to periodically clean up and rejuvenate threads
(thread deallocation)
#IDUG
9
Considerations for Clean Up
• REUSELIMIT (0-10,000) in CICS TS V4R2 - default 1000
• Number of times a thread can be reused before it is terminated
• Use default and monitor DB2 storage usage and adjust the number if needed
• WebSphere Type 2 connection Aged Timeout - default 0
• The interval in seconds before a physical connection is discarded
• Consider setting WAS “aged timeout” to less than 5 min, recommend using 120
secs to reduce exposure of long living threads
• DB2 10 High Performance DBATs (threads)
• Thread will go inactive every 200 commits
• No user control for this value
• DB2 11 optimizes RELEASE(DEALLOCATE) execution so that it is consistently
better performing than RELEASE(COMMIT)
#IDUG
10
Considerations - Concurrency
• More persistent threads with RELEASE(DEALLOCATE) is also trade off with
concurrency
• BIND/REBIND
• SQL DDL
• Online REORG which invalidates packages
• For RELEASE(DEALLOCATE) some locks are held beyond commit until thread
termination
• Mass delete locks (SQL DELETE without WHERE clause)
• Gross level lock acquired on behalf of a SQL LOCK TABLE
• Table space defined with LOCKSIZE TABLESPACE|TABLE
• Note: no longer a problem for gross level lock acquired by lock escalation
• DO YOUR HOMEWORK BEFORE USING PERSISTENT THREADS WITH
RELEASE(DEALLOCATE) BIND OPTION
#IDUG
11
Primer on lock avoidance
• Combination of techniques used by DB2 to try to avoid taking a S page/row
locks when processing for read only SQL whilst preventing the retrieval of
uncommitted data by the application
• (1) Page latching (and page p-lock in data sharing) controlled by DB2 to ensure
physical consistency of the page
• (2) Commit log sequence number (CLSN) – at the page level
• DB2 tracks "time" of last update to page (on page) (A)
• DB2 tracks "time" of oldest uncommitted activity on every pageset/partition (B)
• Non Data Sharing
• CLSN = lowest uncommitted RBA for all active transactions for a given pageset
• Data Sharing
• For non-GBP-dependent page sets, each member uses a local CLSN = lowest uncommitted LRSN for all active
transactions for a given pageset
• For GBP-dependent page sets, a Global CLSN value is maintained for the entire data sharing group = lowest CLSN value
across all members across all page sets (GBP-dependent or not)
• If (A) < (B) everything on the page is guaranteed to be committed
• Else, check Possibly UNCommitted bits (PUNC bits)
#IDUG
12
Primer on lock avoidance …
• Combination of techniques to prevent retrieval of uncommitted data …
• (3) Possibly UNCommitted bits (PUNC bits) – at the row level
• On each row, a PUNC bit is set when the row is updated
• PUNC bits are periodically reset
• If successful CLSN check and more than 25% of the rows have the PUNC bit ON
• RR scanner
• REORG TABLESPACE
• If the PUNC bit is not ON, the row/key is guaranteed to be committed
#IDUG
13
CURRENTDATA(YES) versus CURRENTDATA(NO) …
• Plans and packages have a better chance for lock avoidance if they are bound
with ISOLATION(CS) and CURRENTDATA(NO)
• What is CURRENTDATA?
• Helps to determine the currency and stability of data returned to an application
cursor
• Only applies to applications bound with ISOLATION(CS)
• What is isolation CURSOR STABILITY(CS)?
• Data fetched by a cursor is committed, but if the application process returns to the
same page, another application might have since updated, deleted, or inserted
qualifying rows
• If the cursor is defined as FOR UPDATE OF
• Data returned by the cursor is stable and it may not be updated by another
transaction while the updatable cursor is positioned on it
• If the cursor is defined as FOR READ|FETCH ONLY, or it is implicitly read only (or it is
ambiguous)
• ISOLATION(CS) ensures that the data returned is committed and the stability of
the cursor is determined by the CURRENTDATA option
#IDUG
14
Primer on lock avoidance …
• Benefits of lock avoidance
• Improved concurrency through less lock collisions
• Decrease in lock and unlock activity requests, with an associated decrease in CPU
resource consumption and data sharing overhead
• V8 improvements
• Lock avoidance for non-cursor ‘singleton’ SELECT
• In V7, ISOLATION(CS) CURRENTDATA(YES) acquires S page/row lock on the
qualified row
• In V8, DB2 no longer acquires and hold S page/row lock on the qualified row for
ISOLATION(CS) CURRENTDATA(YES or NO)
• Overflow lock avoidance when the update of a variable length row in a data page
results in a new row that cannot fit in that page i.e., indirect reference
• In V7, no lock avoidance on both pointer and overflow
• In V8, lock on pointer only
• Need to distinguish carefully between eligibility for lock avoidance and
actually achieving it
#IDUG
15
Primer on lock avoidance …
• BIND option ISOLATION(CS) with CURRENTDATA(NO) could
reduce # Lock/Unlock requests dramatically
• High Unlock requests/commit could also be possible from
• Large number of relocated rows after update of compressed or VL
row
• Lock/Unlock of pointer record (or page)
• Large number of pseudo-deleted entries in unique indexes
• Lock/Unlock of data (page or row) in insert to unique index when
pseudo-deleted entries exist
• Both can be eliminated by REORG
Field Name Description
QTXALOCK LOCK REQUESTS
QTXAUNLK UNLOCK REQUESTS
LOCKING ACTIVITY QUANTITY /SECOND /THREAD /COMMIT
------------------------ -------- ------- ------- -------
...
LOCK REQUESTS 521.0M 24.2K 3134.34 1050.75
UNLOCK REQUESTS 478.1M 22.2K 2876.06 964.16
Lock avoidance may not be working effectively if
Unlock requests/commit is high, e.g. >5
ROT
#IDUG
16
Primer on lock avoidance …
• Effective lock avoidance is very important in data sharing
• Global locks propagated beyond IRLM to Coupling Facility are relatively expensive
• Global management of lock contention/resolution is very expensive
• Effective Lock avoidance is critical to achieving good performance and lower data
sharing overhead
• Any long-running UR(s) can reduce the effectiveness of lock avoidance by stopping
the Global CLSN value from moving forward
• Recommendation: Aggressively monitor long-running URs
• 'First cut' ROTs:
• URs running for a long time without committing: zparm URCHKTH<=5
• Message DSNR035I
• URs performing massive update activity without committing: zparm
URLGWTH=10(K)
• Message DSNJ031I
• Need management ownership and process for getting rogue applications fixed up
so that they commit frequently based on
• Elapsed time and/or
• CPU time (no. of SQL update statements)
#IDUG
17
CURRENTDATA(YES) versus CURRENTDATA(NO) …
• Switching from CURRENTDATA(YES) to CURRENTDATA(NO)
• In general, can be done without any adverse effect to applications
• But consider the following scenario:
1. Program A bound with ISOLATION(CS) CURRENTDATA(YES) fetches a row from
a cursor with ORDER BY – and the row is read from the base table and not from
a work file
2. Program B tries to update the row just read by Program A
• The access is not allowed because the CURRENTDATA(YES) option for Program A caused a lock to
be acquired on the page/row in the base table
3. Program A then issues a searched UPDATE of the row just fetched from step 1.
• In the above example CURRENTDATA(YES) protects the integrity of the data read by
Program A in between the FETCH and the searched UPDATE
• If Program A was to be rebound with CURRENTDATA(NO) then
1. Program B may (should) be able to access the row just fetched by Program A
• This assumes correct timing and that lock avoidance is effective
2. When Program A issues the searched UPDATE, it could wipe out the changes
just made by Program B
#IDUG
18
CURRENTDATA(YES) versus CURRENTDATA(NO) …
• Switching from CURRENTDATA(YES) to CURRENTDATA(NO) …
• Now reconsider the same scenario:
1. Program A bound with ISOLATION(CS) CURRENTDATA(YES) fetches a row from
a cursor with ORDER BY, but the row is now read from a work file
2. Program B tries to update the row just read by Program A
1. Access is now allowed as there is no lock on the page/row in the base table
3. Program A then issues a searched UPDATE of the row just fetched from step 1
• In the above example CURRENTDATA(YES) does NOT protects the integrity of the
data read by Program A in between the FETCH and the searched UPDATE
#IDUG
19
Ramifications of lock avoidance for SQL
• Data may be returned without a lock
• All data returned will be committed at the time it is taken from page
• But may change by the time the application sees it
• DB2 only attempts lock avoidance for ISOLATION(CS) transactions when BOTH
of the following are true:
• The plan/package is bound CURRENTDATA(NO)
• The cursor (if cursor-based FETCH) is declared FOR READ|FETCH ONLY, or has some
other attribute (e.g., ORDER BY) that makes it a read-only cursor
• Applications that depend on the stability of what is under a read only cursor,
should use CURRENTDATA(YES)
• Default is CURRENTDATA(NO)
• Now lets look at another example
#IDUG
20
Ramifications of lock avoidance for SQL …
• Example
DECLARE CURSOR AS ...
SELECT THIRD_COL ... WHERE CLUST_COL = 'ABC'
AND ANOTHER_COL = 'DEF'
ORDER BY CLUST_COL; <--- makes cursor read only
FETCH ... <--- say this returns row ABC.DEF.GHI without taking a lock
UPDATE SET … WHERE CLUST_COL = 'ABC'
AND ANOTHER_COL = 'DEF'
AND THIRD_COL = 'GHI‘
• What is the issue?
• Row may no longer be ABC.DEF.GHI by the time update executes
• Another transaction may have gotten in and updated it to ABC.DEF.XYZ
• So update will receive "row not found"
#IDUG
21
What should an application programmer do
• Use programming techniques which avoid possible data currency exposures and access path
dependencies (these sometimes occur regardless of the CURRENTDATA option)
• Define cursors with their intended use
• Easier to read application code
• Number of ambiguous cursors can be reduced
• Some queries will not allow the use of a FOR UPDATE cursor due to possible work file usage e.g.,
with ORDER BY
• Use predicates on searched updates to enforce data currency
• When a FOR UPDATE cursor cannot be used with a query it is common for application
programmers to use a read only with a subsequent searched UPDATE or DELETE
• It is important to use WHERE predicates to ensure that data has not changed since your cursor
first selected the data
• Include all columns which logically determine if the update is necessary, instead of updating
based solely on the key
• This is an exposure regardless of the CURRENTDATA option, but the use of CURRENTDATA(NO)
can increase the exposure opportunity
• Consider the use of a timestamp or a version number
• Add a timestamp or version number column to a table to record the last update
• Select the timestamp or version number column with the cursor
• Use it as a predicate on the searched UPDATE or DELETE to ensure that an application is
updating the same row
#IDUG
22
Finding packages to safely rebind with CURRENTDATA(NO)
• Must recognise that access path dependencies will inevitably occur
• CURRENTDATA(YES) will not stop access path dependency and associated
exposures
• Access path independence and CURRENTDATA(NO) should be the goal for all
applications
• Can safely rebind packages that use only true read-only cursors with
CURRENTDATA(NO)
#IDUG
23
#IDUG
John Campbell
DB2 for z/OS Development
campbelj@uk.ibm.com
Session 6007
Using RELEASE(DEALLOCATE) and Painful Lessons to be Learned on DB2 Locking

More Related Content

What's hot

Parallel Sysplex Implement2
Parallel Sysplex Implement2Parallel Sysplex Implement2
Parallel Sysplex Implement2
ggddggddggdd
 

What's hot (20)

[AWS Builders] Effective AWS Glue
[AWS Builders] Effective AWS Glue[AWS Builders] Effective AWS Glue
[AWS Builders] Effective AWS Glue
 
Single Sign-On for APEX apps (Important: latest version on edocr!)
Single Sign-On for APEX apps (Important: latest version on edocr!)Single Sign-On for APEX apps (Important: latest version on edocr!)
Single Sign-On for APEX apps (Important: latest version on edocr!)
 
An Introduction to AWS
An Introduction to AWSAn Introduction to AWS
An Introduction to AWS
 
Best Practices for the Most Impactful Oracle Database 18c and 19c Features
Best Practices for the Most Impactful Oracle Database 18c and 19c FeaturesBest Practices for the Most Impactful Oracle Database 18c and 19c Features
Best Practices for the Most Impactful Oracle Database 18c and 19c Features
 
AWS Webcast - Amazon RDS for Oracle: Best Practices and Migration
AWS Webcast - Amazon RDS for Oracle: Best Practices and Migration  AWS Webcast - Amazon RDS for Oracle: Best Practices and Migration
AWS Webcast - Amazon RDS for Oracle: Best Practices and Migration
 
AWS Storage - S3 Fundamentals
AWS Storage - S3 FundamentalsAWS Storage - S3 Fundamentals
AWS Storage - S3 Fundamentals
 
Understanding oracle rac internals part 1 - slides
Understanding oracle rac internals   part 1 - slidesUnderstanding oracle rac internals   part 1 - slides
Understanding oracle rac internals part 1 - slides
 
Deep Dive on the Amazon Aurora MySQL-compatible Edition - DAT301 - re:Invent ...
Deep Dive on the Amazon Aurora MySQL-compatible Edition - DAT301 - re:Invent ...Deep Dive on the Amazon Aurora MySQL-compatible Edition - DAT301 - re:Invent ...
Deep Dive on the Amazon Aurora MySQL-compatible Edition - DAT301 - re:Invent ...
 
AWS IAM
AWS IAMAWS IAM
AWS IAM
 
z16 zOS Support - March 2023 - SHARE in Atlanta.pdf
z16 zOS Support - March 2023 - SHARE in Atlanta.pdfz16 zOS Support - March 2023 - SHARE in Atlanta.pdf
z16 zOS Support - March 2023 - SHARE in Atlanta.pdf
 
Introduction to oracle database (basic concepts)
Introduction to oracle database (basic concepts)Introduction to oracle database (basic concepts)
Introduction to oracle database (basic concepts)
 
Vsam
VsamVsam
Vsam
 
Weblogic application server
Weblogic application serverWeblogic application server
Weblogic application server
 
AWS EC2 Fundametals
AWS EC2 FundametalsAWS EC2 Fundametals
AWS EC2 Fundametals
 
Parallel Sysplex Implement2
Parallel Sysplex Implement2Parallel Sysplex Implement2
Parallel Sysplex Implement2
 
[AWS & 베스핀글로벌, 바이오∙헬스케어∙제약사를 위한 세미나] AWS 클라우드 보안
[AWS & 베스핀글로벌, 바이오∙헬스케어∙제약사를 위한 세미나] AWS 클라우드 보안[AWS & 베스핀글로벌, 바이오∙헬스케어∙제약사를 위한 세미나] AWS 클라우드 보안
[AWS & 베스핀글로벌, 바이오∙헬스케어∙제약사를 위한 세미나] AWS 클라우드 보안
 
사례로 알아보는 Database Migration Service : 데이터베이스 및 데이터 이관, 통합, 분리, 분석의 도구 - 발표자: ...
사례로 알아보는 Database Migration Service : 데이터베이스 및 데이터 이관, 통합, 분리, 분석의 도구 - 발표자: ...사례로 알아보는 Database Migration Service : 데이터베이스 및 데이터 이관, 통합, 분리, 분석의 도구 - 발표자: ...
사례로 알아보는 Database Migration Service : 데이터베이스 및 데이터 이관, 통합, 분리, 분석의 도구 - 발표자: ...
 
MongoDB World 2019: Finding the Right MongoDB Atlas Cluster Size: Does This I...
MongoDB World 2019: Finding the Right MongoDB Atlas Cluster Size: Does This I...MongoDB World 2019: Finding the Right MongoDB Atlas Cluster Size: Does This I...
MongoDB World 2019: Finding the Right MongoDB Atlas Cluster Size: Does This I...
 
ZERTO Introduction to End User Presentation
ZERTO Introduction to End User PresentationZERTO Introduction to End User Presentation
ZERTO Introduction to End User Presentation
 
Plan Advanced AWS Networking Architectures - SRV323 - Chicago AWS Summit
Plan Advanced AWS Networking Architectures - SRV323 - Chicago AWS SummitPlan Advanced AWS Networking Architectures - SRV323 - Chicago AWS Summit
Plan Advanced AWS Networking Architectures - SRV323 - Chicago AWS Summit
 

Viewers also liked

A First Look at the DB2 10 DSNZPARM Changes
A First Look at the DB2 10 DSNZPARM ChangesA First Look at the DB2 10 DSNZPARM Changes
A First Look at the DB2 10 DSNZPARM Changes
Willie Favero
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
Dvir Volk
 
Final project report on max life insurance 2
Final  project report on max life insurance 2Final  project report on max life insurance 2
Final project report on max life insurance 2
Student
 

Viewers also liked (18)

DB2 11 for z/OS Migration Planning and Early Customer Experiences
DB2 11 for z/OS Migration Planning and Early Customer ExperiencesDB2 11 for z/OS Migration Planning and Early Customer Experiences
DB2 11 for z/OS Migration Planning and Early Customer Experiences
 
ALL ABOUT DB2 DSNZPARM
ALL ABOUT DB2 DSNZPARMALL ABOUT DB2 DSNZPARM
ALL ABOUT DB2 DSNZPARM
 
IBM DB2 for z/OS Administration Basics
IBM DB2 for z/OS Administration BasicsIBM DB2 for z/OS Administration Basics
IBM DB2 for z/OS Administration Basics
 
Planning and executing a DB2 11 for z/OS Migration by Ian Cook
Planning and executing a DB2 11 for z/OS  Migration  by Ian Cook Planning and executing a DB2 11 for z/OS  Migration  by Ian Cook
Planning and executing a DB2 11 for z/OS Migration by Ian Cook
 
DB2 10 & 11 for z/OS System Performance Monitoring and Optimisation
DB2 10 & 11 for z/OS System Performance Monitoring and OptimisationDB2 10 & 11 for z/OS System Performance Monitoring and Optimisation
DB2 10 & 11 for z/OS System Performance Monitoring and Optimisation
 
IBM DB2 Analytics Accelerator Trends & Directions by Namik Hrle
IBM DB2 Analytics Accelerator  Trends & Directions by Namik Hrle IBM DB2 Analytics Accelerator  Trends & Directions by Namik Hrle
IBM DB2 Analytics Accelerator Trends & Directions by Namik Hrle
 
DB2 Accounting Reporting
DB2  Accounting ReportingDB2  Accounting Reporting
DB2 Accounting Reporting
 
A First Look at the DB2 10 DSNZPARM Changes
A First Look at the DB2 10 DSNZPARM ChangesA First Look at the DB2 10 DSNZPARM Changes
A First Look at the DB2 10 DSNZPARM Changes
 
Db2
Db2Db2
Db2
 
Key Note Session IDUG DB2 Seminar, 16th April London - Julian Stuhler .Trito...
Key Note Session  IDUG DB2 Seminar, 16th April London - Julian Stuhler .Trito...Key Note Session  IDUG DB2 Seminar, 16th April London - Julian Stuhler .Trito...
Key Note Session IDUG DB2 Seminar, 16th April London - Julian Stuhler .Trito...
 
DB2 for z/OS Architecture in Nutshell
DB2 for z/OS Architecture in NutshellDB2 for z/OS Architecture in Nutshell
DB2 for z/OS Architecture in Nutshell
 
Cassandra Introduction & Features
Cassandra Introduction & FeaturesCassandra Introduction & Features
Cassandra Introduction & Features
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Introduction to Apache ZooKeeper
Introduction to Apache ZooKeeperIntroduction to Apache ZooKeeper
Introduction to Apache ZooKeeper
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcached
 
Intro to HBase
Intro to HBaseIntro to HBase
Intro to HBase
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Final project report on max life insurance 2
Final  project report on max life insurance 2Final  project report on max life insurance 2
Final project report on max life insurance 2
 

Similar to Using Release(deallocate) and Painful Lessons to be learned on DB2 locking

IDUG NA 2014 / 11 tips for DB2 11 for z/OS
IDUG NA 2014 / 11 tips for DB2 11 for z/OSIDUG NA 2014 / 11 tips for DB2 11 for z/OS
IDUG NA 2014 / 11 tips for DB2 11 for z/OS
Cuneyt Goksu
 
Maaz Anjum - IOUG Collaborate 2013 - An Insight into Space Realization on ODA...
Maaz Anjum - IOUG Collaborate 2013 - An Insight into Space Realization on ODA...Maaz Anjum - IOUG Collaborate 2013 - An Insight into Space Realization on ODA...
Maaz Anjum - IOUG Collaborate 2013 - An Insight into Space Realization on ODA...
Maaz Anjum
 
NewSQL Database Overview
NewSQL Database OverviewNewSQL Database Overview
NewSQL Database Overview
Steve Min
 
COUG_AAbate_Oracle_Database_12c_New_Features
COUG_AAbate_Oracle_Database_12c_New_FeaturesCOUG_AAbate_Oracle_Database_12c_New_Features
COUG_AAbate_Oracle_Database_12c_New_Features
Alfredo Abate
 
Jdbc Best Practices - DB2/ IDUG - Orlando, May 10, 2004
Jdbc Best Practices - DB2/ IDUG - Orlando, May 10, 2004Jdbc Best Practices - DB2/ IDUG - Orlando, May 10, 2004
Jdbc Best Practices - DB2/ IDUG - Orlando, May 10, 2004
derek_clark_ashmore
 
Cisco at v mworld 2015 vmworld - cisco mds and emc xtrem_io-v2
Cisco at v mworld 2015 vmworld - cisco mds and emc xtrem_io-v2Cisco at v mworld 2015 vmworld - cisco mds and emc xtrem_io-v2
Cisco at v mworld 2015 vmworld - cisco mds and emc xtrem_io-v2
ldangelo0772
 
Lessons learned from Isbank - A Story of a DB2 for z/OS Initiative
Lessons learned from Isbank - A Story of a DB2 for z/OS InitiativeLessons learned from Isbank - A Story of a DB2 for z/OS Initiative
Lessons learned from Isbank - A Story of a DB2 for z/OS Initiative
Cuneyt Goksu
 

Similar to Using Release(deallocate) and Painful Lessons to be learned on DB2 locking (20)

Hp vertica certification guide
Hp vertica certification guideHp vertica certification guide
Hp vertica certification guide
 
Hpverticacertificationguide 150322232921-conversion-gate01
Hpverticacertificationguide 150322232921-conversion-gate01Hpverticacertificationguide 150322232921-conversion-gate01
Hpverticacertificationguide 150322232921-conversion-gate01
 
IDUG NA 2014 / 11 tips for DB2 11 for z/OS
IDUG NA 2014 / 11 tips for DB2 11 for z/OSIDUG NA 2014 / 11 tips for DB2 11 for z/OS
IDUG NA 2014 / 11 tips for DB2 11 for z/OS
 
Aioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_featuresAioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_features
 
Maaz Anjum - IOUG Collaborate 2013 - An Insight into Space Realization on ODA...
Maaz Anjum - IOUG Collaborate 2013 - An Insight into Space Realization on ODA...Maaz Anjum - IOUG Collaborate 2013 - An Insight into Space Realization on ODA...
Maaz Anjum - IOUG Collaborate 2013 - An Insight into Space Realization on ODA...
 
NewSQL Database Overview
NewSQL Database OverviewNewSQL Database Overview
NewSQL Database Overview
 
BigData Developers MeetUp
BigData Developers MeetUpBigData Developers MeetUp
BigData Developers MeetUp
 
VoltDB.ppt
VoltDB.pptVoltDB.ppt
VoltDB.ppt
 
DBCC - Dubi Lebel
DBCC - Dubi LebelDBCC - Dubi Lebel
DBCC - Dubi Lebel
 
OracleStore: A Highly Performant RawStore Implementation for Hive Metastore
OracleStore: A Highly Performant RawStore Implementation for Hive MetastoreOracleStore: A Highly Performant RawStore Implementation for Hive Metastore
OracleStore: A Highly Performant RawStore Implementation for Hive Metastore
 
Top 20 FAQs on the Autonomous Database
Top 20 FAQs on the Autonomous DatabaseTop 20 FAQs on the Autonomous Database
Top 20 FAQs on the Autonomous Database
 
COUG_AAbate_Oracle_Database_12c_New_Features
COUG_AAbate_Oracle_Database_12c_New_FeaturesCOUG_AAbate_Oracle_Database_12c_New_Features
COUG_AAbate_Oracle_Database_12c_New_Features
 
Jdbc Best Practices - DB2/ IDUG - Orlando, May 10, 2004
Jdbc Best Practices - DB2/ IDUG - Orlando, May 10, 2004Jdbc Best Practices - DB2/ IDUG - Orlando, May 10, 2004
Jdbc Best Practices - DB2/ IDUG - Orlando, May 10, 2004
 
Ibm db2 case study
Ibm db2 case studyIbm db2 case study
Ibm db2 case study
 
Cisco at v mworld 2015 vmworld - cisco mds and emc xtrem_io-v2
Cisco at v mworld 2015 vmworld - cisco mds and emc xtrem_io-v2Cisco at v mworld 2015 vmworld - cisco mds and emc xtrem_io-v2
Cisco at v mworld 2015 vmworld - cisco mds and emc xtrem_io-v2
 
Lessons learned from Isbank - A Story of a DB2 for z/OS Initiative
Lessons learned from Isbank - A Story of a DB2 for z/OS InitiativeLessons learned from Isbank - A Story of a DB2 for z/OS Initiative
Lessons learned from Isbank - A Story of a DB2 for z/OS Initiative
 
Best practices for Data warehousing with Amazon Redshift - AWS PS Summit Canb...
Best practices for Data warehousing with Amazon Redshift - AWS PS Summit Canb...Best practices for Data warehousing with Amazon Redshift - AWS PS Summit Canb...
Best practices for Data warehousing with Amazon Redshift - AWS PS Summit Canb...
 
Copy Data Management for the DBA
Copy Data Management for the DBACopy Data Management for the DBA
Copy Data Management for the DBA
 
iland Internet Solutions: Leveraging Cassandra for real-time multi-datacenter...
iland Internet Solutions: Leveraging Cassandra for real-time multi-datacenter...iland Internet Solutions: Leveraging Cassandra for real-time multi-datacenter...
iland Internet Solutions: Leveraging Cassandra for real-time multi-datacenter...
 
Leveraging Cassandra for real-time multi-datacenter public cloud analytics
Leveraging Cassandra for real-time multi-datacenter public cloud analyticsLeveraging Cassandra for real-time multi-datacenter public cloud analytics
Leveraging Cassandra for real-time multi-datacenter public cloud analytics
 

Recently uploaded

Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
nirzagarg
 
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Klinik kandungan
 
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
nirzagarg
 
Gartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptxGartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptx
chadhar227
 
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
gajnagarg
 
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
gajnagarg
 
Reconciling Conflicting Data Curation Actions: Transparency Through Argument...
Reconciling Conflicting Data Curation Actions:  Transparency Through Argument...Reconciling Conflicting Data Curation Actions:  Transparency Through Argument...
Reconciling Conflicting Data Curation Actions: Transparency Through Argument...
Bertram Ludäscher
 
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
nirzagarg
 
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
Health
 
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
gajnagarg
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
gajnagarg
 
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
HyderabadDolls
 

Recently uploaded (20)

Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
 
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
 
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
 
Aspirational Block Program Block Syaldey District - Almora
Aspirational Block Program Block Syaldey District - AlmoraAspirational Block Program Block Syaldey District - Almora
Aspirational Block Program Block Syaldey District - Almora
 
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
 
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
 
Gartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptxGartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptx
 
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
 
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
 
Reconciling Conflicting Data Curation Actions: Transparency Through Argument...
Reconciling Conflicting Data Curation Actions:  Transparency Through Argument...Reconciling Conflicting Data Curation Actions:  Transparency Through Argument...
Reconciling Conflicting Data Curation Actions: Transparency Through Argument...
 
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24  Building Real-Time Pipelines With FLaNKDATA SUMMIT 24  Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
 
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
 
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
 
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
 
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book nowVadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
 
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With OrangePredicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
 
Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...
Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...
Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...
 
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
 
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
 

Using Release(deallocate) and Painful Lessons to be learned on DB2 locking

  • 1. #IDUG Using RELEASE(DEALLOCATE) and Painful Lessons to be Learned on DB2 Locking John Campbell DB2 for z/OS Development Session Code: 6007
  • 2. #IDUG 2 Agenda • Thread reuse using RELEASE(DEALLOCATE) • Primer on thread reuse with RELEASE bind option • Considerations and limitations • Painful Lessons to be Learned on DB2 Locking • Primer on lock avoidance • CURRENTDATA(YES) versus CURRENTDATA(NO) • Ramifications of lock avoidance for SQL • What should an application programmer do • Finding packages to safely rebind with CURRENTDATA(NO)
  • 3. #IDUG 3 “Resources”: Static SQL • Static statements • Packages and statements • Parent locks • Index look-aside buffer, dynamic prefetch tracking via sequential detection
  • 4. #IDUG 4 RELEASE - BIND and REBIND Option • Determines when to release the resources that a program uses • RELEASE(COMMIT) - Releases resources at commit point • RELEASE(DEALLOCATE) - Releases resources when thread terminates (child page/row locks still released at commit) • RELEASE(INHERITFROMPLAN) – Support added by APAR PM07087 • Default behavior • BIND PLAN - COMMIT • BIND PACKAGE - plan value • REBIND PLAN/PACKAGE existing value • DB2Binder Utility for JDBC and SQLJ • DEALLOCATE is default in DB2 10 • COMMIT is default in DB2 9 and earlier releases
  • 5. #IDUG Package Allocation Program A : “Insert into table 1” Thread allocation Sign on, authorization checking Locate SKCT and SKPT Allocate CT/PT and STMT1 Start Insert STMT1 Lock table space 1 Lock data page End STMT1 “insert into table 2” Allocate STMT2 Start Insert STMT2 Lock table space 2 Lock data page End STMT2 COMMIT ; Program A Stmt 1: Insert into table1 Stmt 2: Insert into table2 SPT01 EDM_SKELTON_POOL SKCT/SKPT V10 Thread storage above the bar V9 EDM thread pool below the bar CT PT SQL Stmt1 SQL Stmt2 I/O
  • 6. #IDUG 6 Package Allocation and Commit Program A Stmt 1: Insert into table1 Stmt 2: Insert into table2 Commit ; SPT01 EDM_SKELTON_POOL SKCT/SKPT V10 Thread storage above the bar V9 EDM thread pool below the bar CT PT SQL Stmt1 SQL Stmt2 I/O Expensive Operation! Lock TS 1 Lock table1 data page Lock TS 2 Lock table2 data page RELEASE PT, statements Unlock data pages Unlock TS1, TS2 COMMIT
  • 7. #IDUG 7 Thread Reuse and RELEASE(DEALLOCATE) • Thread reuse eliminates CPU cost of DB2 thread allocation and deallocation • CICS • Protected ENTRYs • Organic reuse of ENTRYs (or POOL) • IMS/TM • Fast Path (IFP) regions • Wait-For-Input (WFI) regions • Pseudo Wait-For-Input (PWFI) regions • DDF • High Performance DBATs • WebSphere Type 2 local connections • Batch with intermediate commits • Use of RELEASE(DEALLOCATE) coupled with effective thread reuse i.e., thread persistence • Further reduces the CPU cost with potential for significant savings (up to 10% plus) • Resources are held until thread deallocation • Without thread reuse RELEASE(COMMIT) vs. RELEASE(DEALLOCATE) is a moot point for discussion
  • 8. #IDUG 8 Limitations and Considerations • Virtual and real storage • DB2 9 and earlier - DBM1 virtual storage below the 2G bar and real storage • Package information is stored in EDM pool below the bar • DB2 10 after REBIND - real storage usage • Package information is stored in thread storage above the bar in DB2 9 and earlier releases • Accumulated DB2 object control blocks • Virtual, real, potentially CPU cost for scanning the objects built up under the thread • Recommendations • Design for thread reuse for • High volume simple transactions • Complex transactions at a reasonably high rate • Selectively use RELEASE(DEALLOCATE) on high use packages – use % of Total Acctg Class 7 CPU • DBM1 31-bit virtual storage constraint (DB2 9) • Real storage constraint (DB2 10) • Use CICS or WebSphere parameter to periodically clean up and rejuvenate threads (thread deallocation)
  • 9. #IDUG 9 Considerations for Clean Up • REUSELIMIT (0-10,000) in CICS TS V4R2 - default 1000 • Number of times a thread can be reused before it is terminated • Use default and monitor DB2 storage usage and adjust the number if needed • WebSphere Type 2 connection Aged Timeout - default 0 • The interval in seconds before a physical connection is discarded • Consider setting WAS “aged timeout” to less than 5 min, recommend using 120 secs to reduce exposure of long living threads • DB2 10 High Performance DBATs (threads) • Thread will go inactive every 200 commits • No user control for this value • DB2 11 optimizes RELEASE(DEALLOCATE) execution so that it is consistently better performing than RELEASE(COMMIT)
  • 10. #IDUG 10 Considerations - Concurrency • More persistent threads with RELEASE(DEALLOCATE) is also trade off with concurrency • BIND/REBIND • SQL DDL • Online REORG which invalidates packages • For RELEASE(DEALLOCATE) some locks are held beyond commit until thread termination • Mass delete locks (SQL DELETE without WHERE clause) • Gross level lock acquired on behalf of a SQL LOCK TABLE • Table space defined with LOCKSIZE TABLESPACE|TABLE • Note: no longer a problem for gross level lock acquired by lock escalation • DO YOUR HOMEWORK BEFORE USING PERSISTENT THREADS WITH RELEASE(DEALLOCATE) BIND OPTION
  • 11. #IDUG 11 Primer on lock avoidance • Combination of techniques used by DB2 to try to avoid taking a S page/row locks when processing for read only SQL whilst preventing the retrieval of uncommitted data by the application • (1) Page latching (and page p-lock in data sharing) controlled by DB2 to ensure physical consistency of the page • (2) Commit log sequence number (CLSN) – at the page level • DB2 tracks "time" of last update to page (on page) (A) • DB2 tracks "time" of oldest uncommitted activity on every pageset/partition (B) • Non Data Sharing • CLSN = lowest uncommitted RBA for all active transactions for a given pageset • Data Sharing • For non-GBP-dependent page sets, each member uses a local CLSN = lowest uncommitted LRSN for all active transactions for a given pageset • For GBP-dependent page sets, a Global CLSN value is maintained for the entire data sharing group = lowest CLSN value across all members across all page sets (GBP-dependent or not) • If (A) < (B) everything on the page is guaranteed to be committed • Else, check Possibly UNCommitted bits (PUNC bits)
  • 12. #IDUG 12 Primer on lock avoidance … • Combination of techniques to prevent retrieval of uncommitted data … • (3) Possibly UNCommitted bits (PUNC bits) – at the row level • On each row, a PUNC bit is set when the row is updated • PUNC bits are periodically reset • If successful CLSN check and more than 25% of the rows have the PUNC bit ON • RR scanner • REORG TABLESPACE • If the PUNC bit is not ON, the row/key is guaranteed to be committed
  • 13. #IDUG 13 CURRENTDATA(YES) versus CURRENTDATA(NO) … • Plans and packages have a better chance for lock avoidance if they are bound with ISOLATION(CS) and CURRENTDATA(NO) • What is CURRENTDATA? • Helps to determine the currency and stability of data returned to an application cursor • Only applies to applications bound with ISOLATION(CS) • What is isolation CURSOR STABILITY(CS)? • Data fetched by a cursor is committed, but if the application process returns to the same page, another application might have since updated, deleted, or inserted qualifying rows • If the cursor is defined as FOR UPDATE OF • Data returned by the cursor is stable and it may not be updated by another transaction while the updatable cursor is positioned on it • If the cursor is defined as FOR READ|FETCH ONLY, or it is implicitly read only (or it is ambiguous) • ISOLATION(CS) ensures that the data returned is committed and the stability of the cursor is determined by the CURRENTDATA option
  • 14. #IDUG 14 Primer on lock avoidance … • Benefits of lock avoidance • Improved concurrency through less lock collisions • Decrease in lock and unlock activity requests, with an associated decrease in CPU resource consumption and data sharing overhead • V8 improvements • Lock avoidance for non-cursor ‘singleton’ SELECT • In V7, ISOLATION(CS) CURRENTDATA(YES) acquires S page/row lock on the qualified row • In V8, DB2 no longer acquires and hold S page/row lock on the qualified row for ISOLATION(CS) CURRENTDATA(YES or NO) • Overflow lock avoidance when the update of a variable length row in a data page results in a new row that cannot fit in that page i.e., indirect reference • In V7, no lock avoidance on both pointer and overflow • In V8, lock on pointer only • Need to distinguish carefully between eligibility for lock avoidance and actually achieving it
  • 15. #IDUG 15 Primer on lock avoidance … • BIND option ISOLATION(CS) with CURRENTDATA(NO) could reduce # Lock/Unlock requests dramatically • High Unlock requests/commit could also be possible from • Large number of relocated rows after update of compressed or VL row • Lock/Unlock of pointer record (or page) • Large number of pseudo-deleted entries in unique indexes • Lock/Unlock of data (page or row) in insert to unique index when pseudo-deleted entries exist • Both can be eliminated by REORG Field Name Description QTXALOCK LOCK REQUESTS QTXAUNLK UNLOCK REQUESTS LOCKING ACTIVITY QUANTITY /SECOND /THREAD /COMMIT ------------------------ -------- ------- ------- ------- ... LOCK REQUESTS 521.0M 24.2K 3134.34 1050.75 UNLOCK REQUESTS 478.1M 22.2K 2876.06 964.16 Lock avoidance may not be working effectively if Unlock requests/commit is high, e.g. >5 ROT
  • 16. #IDUG 16 Primer on lock avoidance … • Effective lock avoidance is very important in data sharing • Global locks propagated beyond IRLM to Coupling Facility are relatively expensive • Global management of lock contention/resolution is very expensive • Effective Lock avoidance is critical to achieving good performance and lower data sharing overhead • Any long-running UR(s) can reduce the effectiveness of lock avoidance by stopping the Global CLSN value from moving forward • Recommendation: Aggressively monitor long-running URs • 'First cut' ROTs: • URs running for a long time without committing: zparm URCHKTH<=5 • Message DSNR035I • URs performing massive update activity without committing: zparm URLGWTH=10(K) • Message DSNJ031I • Need management ownership and process for getting rogue applications fixed up so that they commit frequently based on • Elapsed time and/or • CPU time (no. of SQL update statements)
  • 17. #IDUG 17 CURRENTDATA(YES) versus CURRENTDATA(NO) … • Switching from CURRENTDATA(YES) to CURRENTDATA(NO) • In general, can be done without any adverse effect to applications • But consider the following scenario: 1. Program A bound with ISOLATION(CS) CURRENTDATA(YES) fetches a row from a cursor with ORDER BY – and the row is read from the base table and not from a work file 2. Program B tries to update the row just read by Program A • The access is not allowed because the CURRENTDATA(YES) option for Program A caused a lock to be acquired on the page/row in the base table 3. Program A then issues a searched UPDATE of the row just fetched from step 1. • In the above example CURRENTDATA(YES) protects the integrity of the data read by Program A in between the FETCH and the searched UPDATE • If Program A was to be rebound with CURRENTDATA(NO) then 1. Program B may (should) be able to access the row just fetched by Program A • This assumes correct timing and that lock avoidance is effective 2. When Program A issues the searched UPDATE, it could wipe out the changes just made by Program B
  • 18. #IDUG 18 CURRENTDATA(YES) versus CURRENTDATA(NO) … • Switching from CURRENTDATA(YES) to CURRENTDATA(NO) … • Now reconsider the same scenario: 1. Program A bound with ISOLATION(CS) CURRENTDATA(YES) fetches a row from a cursor with ORDER BY, but the row is now read from a work file 2. Program B tries to update the row just read by Program A 1. Access is now allowed as there is no lock on the page/row in the base table 3. Program A then issues a searched UPDATE of the row just fetched from step 1 • In the above example CURRENTDATA(YES) does NOT protects the integrity of the data read by Program A in between the FETCH and the searched UPDATE
  • 19. #IDUG 19 Ramifications of lock avoidance for SQL • Data may be returned without a lock • All data returned will be committed at the time it is taken from page • But may change by the time the application sees it • DB2 only attempts lock avoidance for ISOLATION(CS) transactions when BOTH of the following are true: • The plan/package is bound CURRENTDATA(NO) • The cursor (if cursor-based FETCH) is declared FOR READ|FETCH ONLY, or has some other attribute (e.g., ORDER BY) that makes it a read-only cursor • Applications that depend on the stability of what is under a read only cursor, should use CURRENTDATA(YES) • Default is CURRENTDATA(NO) • Now lets look at another example
  • 20. #IDUG 20 Ramifications of lock avoidance for SQL … • Example DECLARE CURSOR AS ... SELECT THIRD_COL ... WHERE CLUST_COL = 'ABC' AND ANOTHER_COL = 'DEF' ORDER BY CLUST_COL; <--- makes cursor read only FETCH ... <--- say this returns row ABC.DEF.GHI without taking a lock UPDATE SET … WHERE CLUST_COL = 'ABC' AND ANOTHER_COL = 'DEF' AND THIRD_COL = 'GHI‘ • What is the issue? • Row may no longer be ABC.DEF.GHI by the time update executes • Another transaction may have gotten in and updated it to ABC.DEF.XYZ • So update will receive "row not found"
  • 21. #IDUG 21 What should an application programmer do • Use programming techniques which avoid possible data currency exposures and access path dependencies (these sometimes occur regardless of the CURRENTDATA option) • Define cursors with their intended use • Easier to read application code • Number of ambiguous cursors can be reduced • Some queries will not allow the use of a FOR UPDATE cursor due to possible work file usage e.g., with ORDER BY • Use predicates on searched updates to enforce data currency • When a FOR UPDATE cursor cannot be used with a query it is common for application programmers to use a read only with a subsequent searched UPDATE or DELETE • It is important to use WHERE predicates to ensure that data has not changed since your cursor first selected the data • Include all columns which logically determine if the update is necessary, instead of updating based solely on the key • This is an exposure regardless of the CURRENTDATA option, but the use of CURRENTDATA(NO) can increase the exposure opportunity • Consider the use of a timestamp or a version number • Add a timestamp or version number column to a table to record the last update • Select the timestamp or version number column with the cursor • Use it as a predicate on the searched UPDATE or DELETE to ensure that an application is updating the same row
  • 22. #IDUG 22 Finding packages to safely rebind with CURRENTDATA(NO) • Must recognise that access path dependencies will inevitably occur • CURRENTDATA(YES) will not stop access path dependency and associated exposures • Access path independence and CURRENTDATA(NO) should be the goal for all applications • Can safely rebind packages that use only true read-only cursors with CURRENTDATA(NO)
  • 24. #IDUG John Campbell DB2 for z/OS Development campbelj@uk.ibm.com Session 6007 Using RELEASE(DEALLOCATE) and Painful Lessons to be Learned on DB2 Locking