Monday, July 20, 2026

Db2 Locking Explained in 90 Seconds

Think your enterprise application is running slow because of "aging hardware" or "insufficient CPU"? Think again. In my experience, I’ve found that the vast majority of performance problems blamed on slow infrastructure are actually caused by a silent, internal killer: locking. Or more precisely, inefficient coding built without an understanding of locking!


Let’s talk about Db2 locking, which is one of the most misunderstood performance topics in enterprise systems.

When Db2 locks a resource, it isn't doing it to annoy you; it’s protecting data integrity. It ensures that concurrent transactions don't overwrite each other’s work or read uncommitted data (preventing dirty reads, non-repeatable reads, and phantoms). But when locks escalate or linger unnecessarily, your entire system can grind to a screeching halt.

If you only have 90 seconds, here is the fundamental loop of a locking problem:

  1. A transaction requests a lock: It could be a row lock, a page lock, or a table space lock depending on your bind parameters and data modifications.

  2. The lock is held too long: If the application does too much processing before committing, or if the access path is inefficient, the transaction hoards that lock.

  3. Other transactions must wait: Subsequent tasks trying to touch (read/update) that same resource enter a lock-wait state.

  4. The Bottleneck: Accumulate enough waiting tasks, and you get an enterprise-level bottleneck. To the end-user, it looks like the database has frozen.

Why More Hardware Won't Fix It

The classic knee-jerk reaction to this kind of slowdown is throwing money at the problem: adding more CPU, faster storage, or upgrading the mainframe/server capacity.

But if Transaction A is waiting for Transaction B to release a lock, giving Transaction A a faster processor just means it will arrive at the brick wall a microsecond quicker. It still has to wait. The fix isn't more CPU... it’s changing how your data and code interact.

The True Fixes for Lock Contention

If you want to eliminate locking bottlenecks, focus your tuning efforts on these three pillars:

  • Better Indexing: If Db2 has to perform a table space scan because an index is missing, it will lock vastly more data (potentially the entire table space) than if it could precisely target a single row via an index. Good indexes keep your locks small and surgical.

  • Shorter Units of Work: Keep your transactions tight. Don't fetch data, perform complex business logic, call external APIs, and then commit. Do your non-database work outside the transaction bounds so the lock is held for milliseconds, not seconds.

  • Proper Commit Frequency: If you are running batch processes or massive update loops without regular COMMIT statements, you are building an operational dam. Frequent, structured commits flush the log buffers and release held locks, keeping the data flowing smoothly for concurrent users.

The Bottom Line

If your team isn't actively monitoring lock contention, lock timeouts, and deadlocks using Db2 statistics and traces, you are likely tuning the wrong problem.

The next time someone complains that Db2 is "running slow," step away from the infrastructure metrics. Open your monitoring tools, look at the lock-wait times, and find out who is holding the key to the castle while everyone else is standing outside in the cold.

And if you are looking for more details on locking, I wrote a 17-part series on this blog awhile ago that is still pertinent. You can access it here (this is a link to part 17 that has links to the previous 16 parts, too).


What are your favorite techniques for tracking down elusive lock-waits in Db2? Drop a comment below and let’s discuss!

Thursday, July 02, 2026

The Most Overlooked Db2 Performance Metric

 If I had to identify a single most overlooked Db2 performance metric, it would be GETPAGEs.


Many organizations focus on CPU utilization, elapsed time, or buffer pool hit ratios because those metrics are easy to understand and frequently appear on dashboards. But getpages often reveal performance problems long before those other metrics become alarming.

In Db2 for z/OS, a GETPAGE represents a request by Db2 to access a page of data or an index page. If the page is already in the buffer pool, no physical I/O is required. If not, Db2 must read it from disk. Either way, every GETPAGE consumes CPU resources.

Why GETPAGEs Matter

Because every SQL statement generates GETPAGE requests, the number of GETPAGEs is a fundamental measure of how much work Db2 performs to execute a workload. The more pages Db2 must examine to satisfy a query, the more work it performs. Reducing unnecessary GETPAGEs often leads directly to lower CPU consumption and better application performance.

High GETPAGE counts usually indicate one or more of the following:

  • Inefficient index usage
  • Poor clustering
  • Table scans
  • Low filter factors
  • Redundant index probes
  • Accessing more columns or rows than necessary

Even when all pages are found in the buffer pool, millions of unnecessary GETPAGEs still consume CPU.

The Hidden CPU Consumer

I've worked with organizations that upgraded processors because CPU costs continued to rise. After analyzing the workload, we discovered that many critical SQL statements were generating ten or even one hundred times more GETPAGEs than necessary.

A simple index redesign or SQL rewrite reduced GETPAGE counts dramatically. And CPU usage dropped without any hardware changes.

That's why I often tell clients: "Every unnecessary GETPAGE results in costly unneeded work."

Don't Just Count GETPAGEs

The raw number of GETPAGEs by itself does not tell the whole story. Instead, monitor:

  • GETPAGEs per transaction
  • GETPAGEs per SQL statement
  • GETPAGEs per row returned
  • Trends over time
  • The highest GETPAGE-consuming applications

A workload processing twice as many transactions should naturally generate more GETPAGEs. The real warning sign is when GETPAGEs per transaction steadily increase. That usually means SQL or access paths have degraded.

GETPAGEs Point to Root Causes

Unlike CPU utilization, which tells you that work is occurring, GETPAGEs often explain why.

For example:

Symptom

What High GETPAGEs May Indicate

High CPU

Excessive index or table page accesses

Long elapsed time

Inefficient access path

Buffer pool pressure

Poor locality of reference

Lock contention

Long-running scans

Increased zIIP usage

More work being offloaded, but still excessive overall processing

My Rule of Thumb 👍

After more than four decades tuning Db2 systems, one principle has remained remarkably consistent:

Watch the work, not just the time.

Elapsed time can fluctuate because of concurrency. CPU depends on hardware generation. I/O depends on storage technology.

But GETPAGEs measure the amount of work Db2 is performing. If you reduce the work, you almost always improve performance.

Other Frequently Overlooked Metrics

Although GETPAGEs are my top choice, several other metrics deserve more attention:

  • Synchronous read percentage — Indicates how often Db2 must wait for I/O instead of benefiting from prefetch.
  • Pages read per GETPAGE — Helps evaluate buffer pool effectiveness.
  • Lock suspension time — Often more meaningful than simply counting lock waits.
  • Class 3 suspension time — Shows where Db2 is waiting (I/O, locks, logging, etc.).
  • RID pool failures — Can reveal access path problems that are otherwise difficult to diagnose.
  • Sort overflows — Indicate insufficient sort memory or inefficient SQL.
  • Index leaf page split rates — A useful indicator of index maintenance issues and clustering degradation.

If I were teaching a new Db2 performance analyst, I'd spend less time looking at CPU graphs and more time asking, "Why is Db2 doing so much work?" In many cases, the answer begins with GETPAGEs.