Chapter 3 Exercises: DB2 Architecture

These exercises range from foundational recall to advanced analysis. Work through them in order — later exercises build on concepts from earlier ones.


Section A: Architecture Identification (Exercises 1-7)

Exercise 1: z/OS Address Space Identification

For each of the following DB2 activities, identify which z/OS address space (MSTR, DBM1, DIST, IRLM) is primarily responsible:

Activity Address Space
a. Writing a log record for an UPDATE statement
b. Compiling a dynamic SQL statement
c. Accepting a JDBC connection from a remote web server
d. Detecting a deadlock between two concurrent transactions
e. Reading a data page from the buffer pool
f. Processing the -DB2P STOP DATABASE command
g. Coordinating a two-phase commit with a remote DB2
h. Performing a checkpoint
Answers a. MSTR — logging is handled by system services. b. DBM1 — SQL compilation and optimization occur in database services. c. DIST — remote (DDF) connections are handled by the distributed data facility. d. IRLM — deadlock detection is a lock manager responsibility. e. DBM1 — buffer pools reside in the DBM1 address space. f. MSTR — command processing is a system services function. g. DIST — two-phase commit coordination for distributed transactions. h. MSTR — checkpoint processing is a system services function.

Exercise 2: LUW Process Identification

For each of the following DB2 LUW activities, identify which process is primarily responsible:

Activity Process
a. Executing a SELECT query for an application
b. Writing dirty buffer pool pages to disk
c. Reading ahead pages before they are requested
d. Running a user-written Java stored procedure safely
e. Writing log records to the active log
f. Accepting a TCP/IP connection from a client
g. Detecting a deadlock
Answers a. db2agent — agents execute SQL on behalf of clients. b. db2pclnr — page cleaners write dirty pages asynchronously. c. db2pfchr — prefetchers read ahead to anticipate data needs. d. db2fmp — fenced mode processes run user code outside the engine. e. db2loggr — the logger process writes log records. f. db2tcpcm — the TCP/IP communication manager accepts remote connections. g. db2dlock — the deadlock detector process.

Exercise 3: Architecture Diagram Labeling

Study the following incomplete diagram of a z/OS DB2 subsystem. Fill in the blanks with the correct component names.

z/OS LPAR
|
+-- DB2 Subsystem (SSID: DB2P)
    |
    +-- DB2P____  (Address Space A)
    |     - Command processing
    |     - Log management
    |     - Recovery coordination
    |
    +-- DB2P____  (Address Space B)
    |     - SQL compilation
    |     - Buffer pool management
    |     - _______ pool (caches compiled plans)
    |     - _______ pool (used for RID list processing)
    |
    +-- DB2P____  (Address Space C)
    |     - Remote client connections
    |     - _______ protocol
    |
    +-- ________  (Address Space D)
          - Lock management
          - _______ detection
Answers Address Space A: DB2PMSTR — System Services Address Space B: DB2PDBM1 — Database Services; EDM pool; RID pool Address Space C: DB2PDIST — Distributed Data Facility; DRDA protocol Address Space D: IRLM — Lock Manager; Deadlock detection

Exercise 4: Platform Comparison Matrix

Complete the following comparison table between z/OS and LUW:

Feature / Concept z/OS LUW
Compiled plan cache ____ pool ____ cache
Lock manager ____ (separate address space) Internal lock manager (____ parameter)
Remote connections ____ (DDF) ____ process
User code isolation ____ address spaces ____ mode processes
Automated memory tuning Not available (manual ZPARM tuning) ____
Data storage format VSAM ____ Data Sets File system ____
Modern tablespace type ____ (PBR/PBG) ____ storage
Answers | Feature / Concept | z/OS | LUW | |-------------------|------|-----| | Compiled plan cache | **EDM** pool | **Package** cache | | Lock manager | **IRLM** (separate address space) | Internal lock manager (**LOCKLIST** parameter) | | Remote connections | **DIST** (DDF) | **db2tcpcm** process | | User code isolation | **WLM-managed** address spaces | **Fenced** mode processes | | Automated memory tuning | Not available (manual ZPARM tuning) | **STMM** | | Data storage format | VSAM **Linear** Data Sets | File system **containers** | | Modern tablespace type | **UTS** (PBR/PBG) | **Automatic** storage |

Exercise 5: Memory Hierarchy Ordering

Arrange the following LUW memory areas from broadest scope to narrowest scope:

  • Application (private) memory
  • Instance shared memory
  • Sort heap (within a connection)
  • Database shared memory
  • Buffer pool (within a database)
Answer 1. Instance shared memory (broadest — spans all databases) 2. Database shared memory (one per database) 3. Buffer pool (within a database — part of database shared memory) 4. Application (private) memory (one per connection) 5. Sort heap (within a connection — part of application memory, narrowest)

Exercise 6: Tablespace Type Selection

For each of the following Meridian Bank scenarios, recommend the appropriate tablespace type on z/OS. Choose from: PBR UTS, PBG UTS. Justify your choice.

a. The TRANSACTION table, which currently has 50 million rows and grows by 200,000 rows per day. Most queries filter by transaction date.

b. The BRANCH table, which has 250 rows and changes infrequently.

c. A TRANSACTION_ARCHIVE table that holds 5 years of historical transactions (over 300 million rows), queried only for regulatory audits.

d. A SESSION_LOG table used by the web application to track active user sessions. Row count fluctuates between 100 and 50,000 throughout the day.

Answers a. **PBR UTS**, partitioned by TRANS_DATE (monthly). This enables partition elimination for date-range queries, efficient archival of old partitions, and parallel REORG of individual partitions. b. **PBG UTS**. The table is small and does not benefit from range partitioning. PBG will automatically manage a small number of partitions as needed. c. **PBR UTS**, partitioned by archive date (quarterly or yearly). Partition elimination is critical for audit queries that specify date ranges, and entire partitions can be detached when retention limits expire. d. **PBG UTS**. The row count is volatile and relatively small. Range partitioning adds unnecessary complexity. PBG handles growth and shrinkage gracefully.

Exercise 7: Buffer Pool Page Size Selection

For each table, recommend the appropriate page size (4K, 8K, 16K, 32K) and briefly explain why:

a. CUSTOMER table: CUSTOMER_ID (INTEGER), FIRST_NAME (VARCHAR(50)), LAST_NAME (VARCHAR(50)), EMAIL (VARCHAR(100)), PHONE (VARCHAR(20)), ADDRESS (VARCHAR(200)), CITY (VARCHAR(50)), STATE (CHAR(2)), ZIP (VARCHAR(10)), DATE_OF_BIRTH (DATE), SSN_ENCRYPTED (CHAR(64)). Average row size: ~400 bytes.

b. TRANSACTION table: TRANS_ID (BIGINT), ACCOUNT_ID (INTEGER), TRANS_TYPE (CHAR(2)), AMOUNT (DECIMAL(15,2)), TRANS_DATE (TIMESTAMP), DESCRIPTION (VARCHAR(100)), REFERENCE_NUM (VARCHAR(30)). Average row size: ~200 bytes.

c. DOCUMENT table: DOC_ID (INTEGER), CUSTOMER_ID (INTEGER), DOC_TYPE (VARCHAR(20)), DOC_CONTENT (CLOB(1M)), CREATED_DATE (TIMESTAMP). The CLOB column averages 50 KB.

d. BRANCH table: BRANCH_ID (INTEGER), BRANCH_NAME (VARCHAR(100)), ADDRESS (VARCHAR(200)), MANAGER_ID (INTEGER), PHONE (VARCHAR(20)). Average row size: ~250 bytes. Only 250 rows.

Answers a. **8K pages**. Average row size of ~400 bytes means you fit roughly 15-18 rows per 8K page (accounting for page overhead). 4K pages would fit only 7-8 rows, meaning more pages and more I/O. 8K is a good balance. b. **8K pages**. Average row size of ~200 bytes fits ~35 rows per 8K page. 4K would work too (~15 rows/page), but 8K reduces the total number of pages for this very large table, improving sequential scan performance and buffer pool efficiency. c. **32K pages** for the base table rows, but note that CLOB data over the inline length is stored in a separate LOB tablespace (auxiliary tablespace on z/OS). The LOB tablespace may benefit from 32K pages for larger chunk access. d. **4K pages**. The table is tiny (250 rows). Page size is largely irrelevant for such a small table. Using 4K avoids wasting buffer pool memory and keeps the table in the default 4K buffer pool alongside catalog tables.

Section B: Buffer Pool Analysis (Exercises 8-14)

Exercise 8: Buffer Pool Hit Ratio Calculation

A DB2 system reports the following buffer pool statistics for a 24-hour period:

Metric Value
Logical reads (getpages) 15,000,000
Physical reads (synchronous) 120,000
Physical reads (asynchronous/prefetch) 380,000

a. Calculate the overall buffer pool hit ratio. b. Calculate the synchronous hit ratio (excluding prefetch reads). c. Which metric is more relevant for OLTP response time, and why?

Answers a. Overall BPHR = (1 - (120,000 + 380,000) / 15,000,000) * 100 = (1 - 500,000/15,000,000) * 100 = (1 - 0.0333) * 100 = **96.67%** b. Synchronous BPHR = (1 - 120,000 / 15,000,000) * 100 = (1 - 0.008) * 100 = **99.2%** c. The **synchronous hit ratio** is more relevant for OLTP. Asynchronous (prefetch) reads happen in the background and do not directly block the SQL statement that triggered them. Synchronous reads are on the critical path — the application waits for them. A 99.2% synchronous hit ratio means only 0.8% of page requests force the application to wait for disk I/O.

Exercise 9: Buffer Pool Sizing

Meridian Bank's CUSTOMER table has the following characteristics:

  • 500,000 rows
  • Average row size: 400 bytes
  • Page size: 8 KB (8,192 bytes)
  • Usable space per page: approximately 7,800 bytes (after page header and overhead)
  • Rows per page: approximately 19

a. How many data pages does the CUSTOMER table occupy? b. If Meridian wants to cache the ENTIRE CUSTOMER table in the buffer pool, how much memory is needed? c. The CUSTOMER table also has three indexes totaling 8,000 index pages (4K pages). How much additional buffer pool memory is needed for indexes? d. Is caching the entire table realistic? What is the tradeoff?

Answers a. 500,000 rows / 19 rows per page = **approximately 26,316 data pages**. b. 26,316 pages * 8 KB = approximately 210,528 KB = **approximately 206 MB**. c. 8,000 pages * 4 KB = 32,000 KB = **approximately 31 MB** (in a separate 4K buffer pool). d. Yes, caching 206 MB of customer data is realistic on modern hardware. For a critical OLTP table accessed frequently, caching the entire table yields a near-100% buffer pool hit ratio for customer lookups. The tradeoff is that this memory is unavailable for other purposes. On a system with 64 GB or more of RAM, 206 MB is a modest allocation. However, if many tables all demand full caching, memory pressure increases and priorities must be set.

Exercise 10: Multiple Buffer Pool Design

You are the DBA for Meridian Bank. Currently, all tables and indexes share a single buffer pool (BP0, 4K, 500 MB). Performance monitoring shows:

  • Customer lookup queries (CUSTOMER, ACCOUNT tables): 99.5% hit ratio
  • End-of-day batch reporting (TRANSACTION table full scans): 45% hit ratio
  • After batch reporting starts, customer lookup hit ratio drops to 82%

a. Explain what is happening and why customer lookup performance degrades during batch. b. Propose a buffer pool redesign with specific pool names, page sizes, and approximate sizes. c. What is the expected improvement?

Answers a. **Buffer pool pollution.** The batch reporting job performs full table scans on the large TRANSACTION table, reading millions of pages through the single shared buffer pool. These pages push out the frequently-used CUSTOMER and ACCOUNT pages (LRU replacement). When customer lookups resume, they find their pages evicted and must re-read from disk, causing the hit ratio to drop from 99.5% to 82%. b. Proposed redesign: - **BP_CUST_ACCT** (8K, 600 MB): CUSTOMER and ACCOUNT tablespaces. Isolated from batch scan impact. - **BP_TRANS** (8K, 400 MB): TRANSACTION tablespace. Batch scans cycle through this pool without affecting other pools. - **BP_INDEX** (4K, 150 MB): All index spaces. Keeps hot index pages resident. - **BP_TEMP** (32K, 100 MB): Temporary tablespace for sorts during batch reporting. - **BP_DEFAULT** (4K, 50 MB): Catalog and small reference tables. - Total: 1,300 MB (up from 500 MB — additional investment justified by performance requirements). c. Customer lookup hit ratio should remain at 99%+ even during batch runs, because customer/account pages are now in an isolated buffer pool. Batch reporting hit ratio will still be low (the TRANSACTION table is too large to cache fully), but this no longer affects OLTP. Overall system response time during concurrent OLTP+batch should improve dramatically.

Exercise 11: Buffer Pool Hit Ratio Targets

Explain why a buffer pool hit ratio of 80% might be acceptable for a data warehouse workload but unacceptable for an OLTP workload. In your answer, address:

a. The difference in access patterns (random vs. sequential). b. The impact on individual query response time. c. The impact on throughput (number of transactions per second).

Answers a. **Access patterns**: OLTP workloads perform many small, random lookups (e.g., "find customer 10042"). Each query touches a few pages. Data warehouse workloads perform large sequential scans (e.g., "sum all transactions for the quarter"), touching millions of pages. It is impractical to cache an entire data warehouse in memory, so misses are expected. OLTP pages are frequently re-read (hot data), making them ideal for caching. b. **Individual query response time**: For OLTP, a miss on a single page adds 2-10ms of disk latency to a query that should complete in 1-2ms — doubling or tripling response time. For a data warehouse query that takes 30 seconds, a few extra seconds of I/O are proportionally less significant, and prefetch (asynchronous I/O) mitigates the latency. c. **Throughput**: OLTP systems may process thousands of transactions per second. If 20% of page requests go to disk, the I/O subsystem can become saturated, causing queuing delays that compound across all concurrent transactions. Data warehouse systems typically have fewer concurrent queries, and each query's I/O pattern is sequential and prefetchable, so the I/O subsystem handles misses more efficiently.

Exercise 12: Page Size Tradeoffs

A colleague suggests using 32K pages for all tablespaces in Meridian Bank to "maximize I/O efficiency." Write a response explaining why this is not a good idea. Address at least three specific drawbacks.

Answers Three (or more) drawbacks of using 32K pages universally: 1. **Buffer pool waste for small rows.** The TRANSACTION table has ~200-byte rows. On a 32K page (~31,000 usable bytes), you fit ~155 rows. But if you only need one row (a random lookup by TRANS_ID), you are reading 32K into the buffer pool to access 200 bytes. On an 8K page, the waste is much less. Each buffer pool page consumes memory regardless of how much useful data it contains. 2. **Buffer pool capacity reduction.** For a fixed amount of buffer pool memory, larger pages mean fewer pages cached. A 1 GB buffer pool holds ~256,000 4K pages but only ~32,000 32K pages. For OLTP workloads where many distinct pages are accessed, the reduced page count means more evictions and a lower hit ratio. 3. **Increased lock contention (with page-level locking).** If page-level locking is used, a 32K page holds many more rows than a 4K page. Two transactions updating different rows on the same page will conflict, causing lock waits. This is less of a concern with row-level locking, but page locks are still used in some scenarios. 4. **Index pages are small.** Index entries are typically 10-50 bytes. Using 32K index pages wastes significant space and buffer pool memory for index pools. 5. **Catalog objects require 4K.** DB2 catalog tablespaces use 4K pages. You need a 4K buffer pool regardless, so a "32K only" strategy is not even possible.

Exercise 13: Prefetch and Buffer Pool Interaction

Explain the difference between synchronous I/O and asynchronous prefetch I/O in the context of buffer pools. Then answer:

a. When does DB2 trigger sequential prefetch? b. When does DB2 trigger list prefetch? c. How does prefetch interact with the LRU (Least Recently Used) replacement algorithm? Why might prefetched pages be treated differently from demand-read pages?

Answers **Synchronous I/O**: The requesting thread waits for the I/O to complete. The application is blocked until the page is in the buffer pool. **Asynchronous prefetch I/O**: A separate prefetch thread reads pages into the buffer pool in advance, before the application requests them. The application does not wait for these reads directly. a. **Sequential prefetch** is triggered when DB2 detects a sequential access pattern — typically during a tablespace scan or a matching index scan that accesses many consecutive pages. DB2 reads ahead in large chunks (typically 32 pages at a time for 4K pages). b. **List prefetch** is triggered when DB2 has a list of RIDs (e.g., from a non-matching index scan) and sorts them by page number. It then reads the required pages in page-number order, converting random I/O into sequential I/O. c. Prefetched pages are often placed at the "cold" end of the LRU chain (or on the FIFO chain on z/OS) rather than the "hot" end. This is because prefetched pages — especially from sequential scans — may only be accessed once. If they were placed on the hot end, they would push out frequently re-accessed OLTP pages. By treating prefetched pages as "cooler," DB2 protects the working set of hot pages from scan pollution. (This behavior is configurable on some platforms.)

Exercise 14: STMM Analysis

Meridian Bank's LUW system has STMM enabled. The following memory allocations were observed at three different times:

Memory Area 8:00 AM (start of day) 12:00 PM (peak OLTP) 11:00 PM (batch reporting)
Buffer Pool (CUST/ACCT) 500 MB 900 MB 400 MB
Buffer Pool (TRANS) 300 MB 200 MB 800 MB
Sort Heap (shared) 200 MB 100 MB 400 MB
Package Cache 100 MB 150 MB 50 MB
Total Database Memory 1,100 MB 1,350 MB 1,650 MB

a. Explain the shift from 8 AM to 12 PM in terms of workload characteristics. b. Explain the shift from 12 PM to 11 PM. c. Why did the total database memory increase by 11 PM? d. Is STMM making good decisions here? How would you verify?

Answers a. **8 AM to 12 PM**: Peak OLTP workload. STMM grew the CUST/ACCT buffer pool from 500 MB to 900 MB because customer lookups are the primary workload. The TRANS buffer pool shrank (fewer large transaction scans during OLTP hours). Sort heap shrank (OLTP queries require less sorting). Package cache grew (more distinct SQL plans in use from diverse application paths). b. **12 PM to 11 PM**: Batch reporting started. STMM grew the TRANS buffer pool to 800 MB (batch scans on TRANSACTION table need more cache). Sort heap quadrupled to 400 MB (batch reports with ORDER BY, GROUP BY). CUST/ACCT buffer pool shrank (fewer customer lookups overnight). Package cache shrank (fewer distinct OLTP plans; batch uses fewer, larger queries). c. Total memory increased because the batch workload has higher overall memory demands (large sorts + large scans). STMM responded by requesting more memory from the DATABASE_MEMORY allocation, up to whatever limit is configured. d. To verify STMM is making good decisions, check buffer pool hit ratios, sort overflow rates, and package cache hit ratios at each time period. If hit ratios are acceptable and sort overflows are minimal, STMM is doing well. If not, you may need to set minimum sizes for critical pools or increase the DATABASE_MEMORY ceiling.

Section C: Logging and Recovery (Exercises 15-19)

Exercise 15: Write-Ahead Logging Walkthrough

Consider the following sequence of events:

  1. Application issues: UPDATE ACCOUNT SET BALANCE = BALANCE - 500 WHERE ACCOUNT_ID = 1001;
  2. DB2 modifies the data page in the buffer pool and writes a log record to the log buffer.
  3. Application issues: COMMIT;
  4. DB2 forces the log buffer to the active log on disk.
  5. DB2 returns "commit successful" to the application.
  6. (Some time later) The page cleaner writes the dirty data page to disk.

Questions: a. At step 5, has the modified data page been written to disk? Why or why not? b. If DB2 crashes between steps 5 and 6, is the update lost? Explain. c. If DB2 crashes between steps 2 and 3, what happens to the update? d. What would happen if DB2 wrote the data page to disk BEFORE writing the log record (violating WAL)?

Answers a. **No**, the modified data page has NOT been written to disk at step 5. Only the log record has been written (forced) to disk. The data page remains dirty in the buffer pool. This is the "no-force" policy — DB2 does not force data pages to disk at commit time. b. **No, the update is NOT lost.** During restart recovery, DB2 reads the log and finds the committed UPDATE. Since the data page was not written to disk, DB2 *redoes* the update by applying the log record to the data page. The result is identical to the original update. WAL guarantees this works. c. **The update is rolled back.** The COMMIT never occurred, so during restart recovery, DB2 finds the update log record but no corresponding COMMIT record. It *undoes* the update by reading the "before image" from the log record and restoring the original value. The account balance is restored to its pre-UPDATE value. d. **Data corruption risk.** If DB2 crashes after writing the data page but before writing the log record, there is no log record to undo the change. The data page on disk contains the modified value, but there is no record of what the original value was or whether the transaction committed. DB2 cannot recover correctly. This is why WAL is an absolute rule.

Exercise 16: Log Sizing Calculation

Meridian Bank processes approximately 200,000 transactions per day. Each transaction generates an average of 500 bytes of log data (including the update log record, commit record, and overhead). The bank requires the ability to recover from the last 7 days of archive logs.

a. Calculate the daily log volume. b. Calculate the weekly archive log storage requirement. c. If each active log data set (z/OS) or log file (LUW) is 40 MB, how many are needed to hold 2 hours of peak-period log data? (Assume peak volume is 3x average.) d. Why is it important to size active logs to hold several hours of data?

Answers a. Daily log volume = 200,000 transactions * 500 bytes = 100,000,000 bytes = **approximately 95 MB per day**. b. Weekly archive storage = 95 MB * 7 = **approximately 665 MB per week**. c. Peak hourly rate = (200,000 / 24) * 3 = 25,000 transactions/hour. Peak log volume per hour = 25,000 * 500 bytes = 12.5 MB/hour. For 2 hours of peak: 25 MB. With 40 MB log files, you need at least 1 file for 2 hours of peak data. However, best practice is to over-provision — **at least 6-10 active log files** to handle bursts, provide time for archiving, and avoid running out of active log space (which causes DB2 to stop processing). d. Active logs must be large enough that DB2 never runs out of log space during peak processing. If the active logs fill up before old logs can be archived and reused, DB2 will suspend all update activity until space is freed — a serious outage. Additionally, long-running transactions hold log space (their log records cannot be overwritten until they commit or roll back). You must account for these when sizing.

Exercise 17: BSDS and Recovery

Explain the role of the BSDS (Bootstrap Data Set) on z/OS. Then answer:

a. What information does the BSDS contain? b. Why is the BSDS duplexed (two copies)? c. What happens if BOTH copies of the BSDS are lost? d. Does DB2 LUW have an equivalent to the BSDS? If so, what is it?

Answers The BSDS is a critical data set that serves as DB2's "table of contents" for its logging system. a. The BSDS contains: an inventory of active log data sets (mapping RBA ranges to data set names), an inventory of archive log data sets, system timestamps, checkpoint records, the DDF communication record (location name, port, etc.), and conditional restart information. b. The BSDS is duplexed for availability. If one copy is damaged (media failure, accidental deletion), DB2 can continue operating with the surviving copy. The DBA can then restore the damaged copy from the surviving one. c. If BOTH copies are lost, DB2 cannot start. Recovery requires using the `DSNJU003` (Change Log Inventory) utility to rebuild the BSDS from knowledge of the log data set names and RBA ranges. This is a high-risk, manual process that requires detailed documentation of the log configuration. This scenario should be prevented at all costs through backup and separate storage placement. d. DB2 LUW uses the **recovery history file** and the **database configuration** to maintain similar information. The recovery history file tracks backup and restore operations, log file archiving, and reorg operations. The database configuration stores current log file information. However, the LUW model is simpler because log files have sequential names and do not require the complex RBA-to-data-set mapping needed on z/OS.

Exercise 18: Circular vs. Archive Logging

Meridian Bank's development team has set up a new LUW test database using the default configuration (circular logging). A developer accidentally runs a DELETE without a WHERE clause on the CUSTOMER table. They want to recover the data.

a. Can they recover using ROLLFORWARD DATABASE? Why or why not? b. What recovery options do they have with circular logging? c. What change would you recommend for the test database to prevent this situation? d. Even with archive logging, what additional step is required before ROLLFORWARD can be used?

Answers a. **No.** ROLLFORWARD DATABASE requires archive logging because it replays log records from a backup to a point in time. With circular logging, old log records are overwritten and cannot be replayed. b. With circular logging, the only recovery option is to restore from the last database BACKUP. Any changes made after that backup are lost. If no backup exists, the data may be unrecoverable (except from application-level exports or other external copies). c. **Enable archive logging** (`LOGARCHMETH1 DISK:/path/`) and ensure regular backups are taken. This enables point-in-time recovery. For a test database, also consider more frequent backups (daily or before major test runs). d. A full **database BACKUP** must have been taken after archive logging was enabled. ROLLFORWARD starts from a backup image and replays archive logs forward. Without a baseline backup, there is nothing to roll forward from.

Exercise 19: Checkpoint and Recovery Time

Explain the relationship between checkpoint frequency and recovery time. Specifically:

a. What happens during a DB2 restart after a crash? b. Why does the checkpoint position matter for recovery? c. If checkpoints occur every 500,000 log records on z/OS, and your system writes 10,000 log records per second at peak, approximately how far back might DB2 need to process the log during recovery? d. What is the tradeoff of more frequent checkpoints?

Answers a. During restart, DB2 reads the log forward from the last checkpoint, redoing committed changes that may not have been written to disk (redo phase) and undoing uncommitted changes (undo phase). It also processes any in-flight transactions. b. The checkpoint marks the starting point for recovery. DB2 only needs to process log records written AFTER the last checkpoint (plus any changes for transactions that started before the checkpoint but had not yet committed). c. 500,000 records / 10,000 records per second = **50 seconds** of log data. This means recovery would need to process approximately 50 seconds' worth of log records. Actual recovery time depends on the complexity of redo/undo operations, but this gives the approximate scope. d. More frequent checkpoints reduce recovery time (less log to process) but increase overhead during normal operation. Each checkpoint requires DB2 to record the current state, which involves writing checkpoint log records and may trigger page cleaning. Very frequent checkpoints can reduce throughput. The goal is to balance normal-operation overhead against acceptable recovery time.

Section D: SQL Lifecycle and Catalog (Exercises 20-25)

Exercise 20: SQL Lifecycle Ordering

Place the following steps in the correct order for processing a dynamic SQL statement:

  • [ ] Optimizer generates access plan
  • [ ] Agent/thread is assigned to the connection
  • [ ] Data pages are read from buffer pool
  • [ ] Authorization check against catalog
  • [ ] Result set returned to application
  • [ ] Syntax checking (parse)
  • [ ] Lock acquired on the data resource
  • [ ] Application connects to DB2
  • [ ] Semantic check (do objects exist?)
  • [ ] Check dynamic statement cache for existing plan
Correct Order 1. Application connects to DB2 2. Agent/thread is assigned to the connection 3. Syntax checking (parse) 4. Semantic check (do objects exist?) 5. Authorization check against catalog 6. Check dynamic statement cache for existing plan 7. Optimizer generates access plan (if not found in cache) 8. Lock acquired on the data resource 9. Data pages are read from buffer pool 10. Result set returned to application

Exercise 21: Catalog Queries

Write SQL queries against the DB2 catalog to answer the following questions for the Meridian Bank schema. Provide both z/OS and LUW versions.

a. List all tables in the MERIDIAN schema with their row counts (cardinality). b. Find all indexes on the ACCOUNT table, showing the index name and whether it is unique. c. Find the column names and data types for the TRANSACTION table.

Answers **a. List all tables with row counts:** z/OS:
SELECT NAME, TYPE, CARDF
  FROM SYSIBM.SYSTABLES
 WHERE CREATOR = 'MERIDIAN'
   AND TYPE = 'T'
 ORDER BY NAME;
LUW:
SELECT TABNAME, TYPE, CARD
  FROM SYSCAT.TABLES
 WHERE TABSCHEMA = 'MERIDIAN'
   AND TYPE = 'T'
 ORDER BY TABNAME;
**b. Indexes on ACCOUNT table:** z/OS:
SELECT NAME, UNIQUERULE, COLCOUNT
  FROM SYSIBM.SYSINDEXES
 WHERE TBCREATOR = 'MERIDIAN'
   AND TBNAME = 'ACCOUNT';
LUW:
SELECT INDNAME, UNIQUERULE, COLCOUNT
  FROM SYSCAT.INDEXES
 WHERE TABSCHEMA = 'MERIDIAN'
   AND TABNAME = 'ACCOUNT';
**c. Columns of TRANSACTION table:** z/OS:
SELECT NAME, COLTYPE, LENGTH, SCALE, NULLS
  FROM SYSIBM.SYSCOLUMNS
 WHERE TBCREATOR = 'MERIDIAN'
   AND TBNAME = 'TRANSACTION'
 ORDER BY COLNO;
LUW:
SELECT COLNAME, TYPENAME, LENGTH, SCALE, NULLS
  FROM SYSCAT.COLUMNS
 WHERE TABSCHEMA = 'MERIDIAN'
   AND TABNAME = 'TRANSACTION'
 ORDER BY COLNO;

Exercise 22: Static vs. Dynamic SQL

Explain the difference between static and dynamic SQL in the context of DB2's architecture. Address:

a. When is the access plan created for each type? b. Where is the plan stored? (Differentiate z/OS and LUW.) c. What are the performance implications of each? d. Which type is more common in modern Java applications using JDBC? Why?

Answers a. **Static SQL**: The access plan is created at BIND time (before execution). The SQL text is embedded in the application program and bound into a package. **Dynamic SQL**: The access plan is created at PREPARE time (during execution). The SQL text is constructed and submitted at runtime. b. **Static**: On z/OS, the plan is stored in the DB2 directory as a Cursor Table (CT) and loaded into the EDM pool at runtime. On LUW, it is stored as a package in the database and loaded into the package cache. **Dynamic**: On z/OS, the plan is cached in the dynamic statement cache (part of the EDM pool). On LUW, it is cached in the package cache. c. **Static SQL** avoids compilation overhead at runtime, giving predictable performance. However, the plan may become suboptimal as data changes (rebinding is needed). **Dynamic SQL** compiles at runtime, incurring overhead for the first execution, but benefits from the dynamic statement cache for subsequent identical SQL. It always uses current statistics, potentially choosing better plans. d. **Dynamic SQL** is far more common in modern Java/JDBC applications. JDBC's `PreparedStatement` uses dynamic SQL (PREPARE and EXECUTE). The dynamic statement cache mitigates the compilation overhead for repeated SQL. Static SQL requires a precompile step that does not fit well into modern development workflows.

Exercise 23: RUNSTATS Impact

Meridian Bank's DBA forgot to run RUNSTATS on the TRANSACTION table for three months. During that time, the table grew from 30 million to 50 million rows, and a new index was added. What are the likely consequences? Discuss:

a. Impact on the optimizer's access path choices. b. Specific scenarios where the optimizer would make poor decisions. c. How to fix the situation.

Answers a. The optimizer uses catalog statistics (cardinality, column distribution, index statistics) to estimate the cost of different access paths. With three-month-old statistics showing 30 million rows instead of 50 million, the optimizer's cost estimates are wrong. It may underestimate I/O costs, choose plans that were optimal at 30 million rows but are suboptimal at 50 million, or fail to consider the new index entirely (it has no statistics). b. Specific scenarios: - The optimizer might choose a **table scan** instead of an index access, because it underestimates the table size and thinks a scan is cheap. - The optimizer **ignores the new index** because it has no statistics, defaulting to an older index or no index. - For join queries, the optimizer might choose the **wrong join order** because it underestimates the TRANSACTION table's size relative to other tables. - The optimizer might underestimate **sort costs** for ORDER BY on transaction date, leading to insufficient sort memory allocation. c. Run RUNSTATS immediately on the TRANSACTION table with distribution statistics and detailed index statistics. On z/OS: `RUNSTATS TABLESPACE ... TABLE(MERIDIAN.TRANSACTION) INDEX(ALL) SHRLEVEL CHANGE`. On LUW: `RUNSTATS ON TABLE MERIDIAN.TRANSACTION WITH DISTRIBUTION AND DETAILED INDEXES ALL`. After RUNSTATS, consider rebinding affected packages (z/OS) or flushing the package cache (LUW) to force recompilation with updated statistics.

Exercise 24: Access Path Analysis

For the following query on the Meridian Bank TRANSACTION table:

SELECT TRANS_ID, AMOUNT, TRANS_DATE
  FROM TRANSACTION
 WHERE ACCOUNT_ID = 5001
   AND TRANS_DATE BETWEEN '2025-01-01' AND '2025-03-31'
 ORDER BY TRANS_DATE;

Assume the following indexes exist: - IX_TRANS_PK on TRANS_ID (unique) - IX_TRANS_ACCT on ACCOUNT_ID - IX_TRANS_DATE on TRANS_DATE - IX_TRANS_ACCT_DATE on (ACCOUNT_ID, TRANS_DATE)

a. Which index would the optimizer most likely choose? Why? b. Trace the data access steps using that index. c. Does DB2 need to perform a sort for the ORDER BY clause? Explain.

Answers a. The optimizer would most likely choose **IX_TRANS_ACCT_DATE** (the composite index on ACCOUNT_ID, TRANS_DATE). This index matches BOTH predicates — it can position directly on ACCOUNT_ID = 5001 and then scan the range of TRANS_DATE values. This is a *matching index scan* on both columns, which is the most efficient path. b. Access steps: 1. Navigate the B-tree of IX_TRANS_ACCT_DATE to find the first entry where ACCOUNT_ID = 5001 AND TRANS_DATE >= '2025-01-01'. 2. Scan forward through the index leaf pages, collecting RIDs for all entries where ACCOUNT_ID = 5001 AND TRANS_DATE <= '2025-03-31'. 3. For each RID, fetch the corresponding data page from the buffer pool (or disk) to retrieve TRANS_ID, AMOUNT, and TRANS_DATE. 4. Return the rows. c. **No sort is needed.** The composite index IX_TRANS_ACCT_DATE stores entries in order of (ACCOUNT_ID, TRANS_DATE). Since we are filtering on a single ACCOUNT_ID value (5001), the TRANS_DATE values within that account are already in ascending order in the index. The ORDER BY TRANS_DATE is satisfied by the index order — this is called *index-assisted ordering* or *order-preserving access*. Avoiding the sort saves significant CPU and memory.

Exercise 25: Catalog Exploration Challenge

Using only catalog queries (no application-level queries), determine the following for a DB2 database. Write the SQL for either z/OS or LUW (your choice):

a. The total number of tables in the database. b. The five largest tables by row count. c. All tables that have NO indexes defined. d. All indexes that are not unique. e. The total number of columns across all tables in the MERIDIAN schema.

Answers (LUW version) a.
SELECT COUNT(*) AS TOTAL_TABLES
  FROM SYSCAT.TABLES
 WHERE TYPE = 'T'
   AND TABSCHEMA NOT LIKE 'SYS%';
b.
SELECT TABSCHEMA, TABNAME, CARD
  FROM SYSCAT.TABLES
 WHERE TYPE = 'T'
   AND CARD > 0
 ORDER BY CARD DESC
 FETCH FIRST 5 ROWS ONLY;
c.
SELECT T.TABSCHEMA, T.TABNAME
  FROM SYSCAT.TABLES T
 WHERE T.TYPE = 'T'
   AND T.TABSCHEMA = 'MERIDIAN'
   AND NOT EXISTS (
     SELECT 1 FROM SYSCAT.INDEXES I
      WHERE I.TABSCHEMA = T.TABSCHEMA
        AND I.TABNAME = T.TABNAME
   );
d.
SELECT INDSCHEMA, INDNAME, TABNAME, UNIQUERULE
  FROM SYSCAT.INDEXES
 WHERE TABSCHEMA = 'MERIDIAN'
   AND UNIQUERULE = 'D';  -- D = Duplicates allowed (non-unique)
e.
SELECT COUNT(*) AS TOTAL_COLUMNS
  FROM SYSCAT.COLUMNS
 WHERE TABSCHEMA = 'MERIDIAN';

Section E: Architecture Design and Analysis (Exercises 26-30)

Exercise 26: Full Architecture Design

You are tasked with designing a DB2 LUW architecture for a new Meridian Bank branch-operations database. The requirements are:

  • 10 tables, largest will grow to 20 million rows
  • 50 concurrent users during business hours
  • OLTP workload with occasional reports
  • Server has 32 GB RAM, 8 cores
  • Must support point-in-time recovery

Provide: a. Instance and database names. b. Buffer pool configuration (names, page sizes, sizes). c. Tablespace layout. d. Logging configuration (type, sizing). e. Key database configuration parameters.

Sample Answer a. Instance: `db2mbnk`, Database: `MBNKBRCH` b. Buffer pools: - `BP_MAIN_8K` (8K, 200,000 pages = ~1.6 GB) — main operational tables - `BP_INDEX_4K` (4K, 50,000 pages = ~200 MB) — all indexes - `BP_TEMP_32K` (32K, 5,000 pages = ~160 MB) — temporary tablespace - `IBMDEFAULTBP` (4K, 10,000 pages = ~40 MB) — catalog and small tables - Total: ~2 GB, leaving ~30 GB for OS, application memory, sort heaps, etc. - All pools set to AUTOMATIC for STMM management. c. Tablespaces: - `TS_OPERATIONS` (8K, automatic storage, BP_MAIN_8K) — main tables - `TS_REFERENCE` (4K, automatic storage, IBMDEFAULTBP) — reference/lookup tables - `TS_INDEX` (4K, automatic storage, BP_INDEX_4K) — indexes - `TEMPSPACE1` (32K, automatic storage, BP_TEMP_32K) — temporary - Automatic storage paths: `/db2data/path1`, `/db2data/path2` d. Logging: - Archive logging: `LOGARCHMETH1 DISK:/db2archlog/` - `LOGPRIMARY 15`, `LOGSECOND 10`, `LOGFILSIZ 8000` (32 MB per file) - `LOGBUFSZ 512` (2 MB log buffer) - Separate filesystem for logs: `/db2logs/` e. Key parameters: - `SELF_TUNING_MEM ON` - `DATABASE_MEMORY 8G` (will be tuned by STMM within this ceiling) - `MAXAPPLS 100` (allow up to 100 concurrent applications) - `SORTHEAP AUTOMATIC` - `LOCKLIST AUTOMATIC` - `PCKCACHESZ AUTOMATIC` - `AUTO_RUNSTATS ON` (automatic statistics collection)

Exercise 27: Failure Analysis

For each of the following failure scenarios in a z/OS DB2 environment, describe what happens and how DB2 recovers:

a. The IRLM address space ABENDs. b. A single active log data set becomes unavailable (with dual logging enabled). c. DBM1 ABENDs but MSTR remains running. d. The entire z/OS LPAR crashes and is IPLed. e. A VSAM data set underlying a tablespace gets a media error.

Answers a. **IRLM ABEND**: DB2 cannot process any new lock requests. All SQL processing effectively stops. DB2 will attempt to reconnect to the IRLM or the IRLM will be restarted by z/OS automation. Depending on configuration, DB2 may need to be restarted as well. All in-flight transactions are rolled back during recovery. b. **Single active log data set failure (with dual logging)**: DB2 continues operating using the surviving copy. An alert is raised. The DBA must resolve the issue with the failed data set (replace it, reallocate it) and restore dual logging. No data is lost. c. **DBM1 ABEND**: The database engine is gone, but MSTR survives. MSTR will drive recovery — restarting DBM1, reading the log to redo committed transactions and undo uncommitted ones. Applications will experience an outage during recovery but no committed data is lost. d. **Full LPAR crash**: On IPL, DB2 is restarted (either manually or by automation). MSTR drives full restart recovery from the last checkpoint, reading the log forward to redo and undo as needed. Active log and BSDS on DASD survive the crash (they are on persistent storage). Recovery time depends on the volume of log to process since the last checkpoint. e. **Tablespace media error**: The affected tablespace is placed in a "stopped" or "recovery pending" state. Queries against that tablespace fail. Recovery requires restoring the tablespace from a backup (image copy) and applying log records forward to bring it to a current state. Other tablespaces are unaffected.

Exercise 28: Cross-Platform Migration Analysis

Meridian Bank is considering migrating its core banking application from DB2 for z/OS to DB2 for LUW (or running on both). For each architectural feature, describe what changes would be needed:

a. Buffer pool configuration b. Stored procedure execution environment c. Logging and recovery setup d. Connection management for application servers e. Catalog queries used by the monitoring team

Answers a. **Buffer pools**: The concept is identical, but the configuration syntax differs. z/OS buffer pools have fixed names (BP0, BP8K0, etc.) and are configured via ZPARMs. LUW buffer pools have user-defined names and are created with DDL. Page sizes and hit ratio targets remain the same. STMM on LUW can manage sizing automatically. b. **Stored procedures**: z/OS uses WLM-managed address spaces; LUW uses fenced mode processes. The SQL code may be largely portable, but external routines (C, Java) may need recompilation for the target platform. Language-specific dependencies (z/OS COBOL vs. LUW C) require rewrites. c. **Logging**: z/OS uses VSAM data sets for active/archive logs and the BSDS. LUW uses files and directory paths. The concepts (WAL, dual/archive logging, checkpoints) are the same. Configuration parameters are completely different (ZPARMs vs. `UPDATE DB CFG`). d. **Connection management**: z/OS uses DDF/DIST with DRDA. LUW uses db2tcpcm with DRDA (same protocol). JDBC applications may need only a connection string change (host, port, database name). Authentication mechanisms may differ (RACF vs. OS/LDAP). e. **Catalog queries**: This requires the most code changes. z/OS uses `SYSIBM.SYS*` tables; LUW uses `SYSCAT.*` views. Column names differ (e.g., `CREATOR` vs. `TABSCHEMA`, `CARDF` vs. `CARD`). All monitoring scripts and reports that query the catalog must be rewritten.

Exercise 29: Performance Troubleshooting Scenario

Meridian Bank's online banking application suddenly shows response time degradation. The average customer-lookup query went from 2ms to 45ms. You check the buffer pool statistics and find:

  • Buffer pool hit ratio for BP_CUST: dropped from 99.2% to 76%
  • Buffer pool hit ratio for BP_TRANS: 99.8% (unchanged)
  • No change in application code or query patterns
  • Physical I/O rate has tripled

Walk through your investigation: a. What is the most likely cause based on the symptoms? b. What specific metrics would you check next? c. Name three possible root causes. d. For each root cause, describe the fix.

Answers a. The customer buffer pool has experienced a sudden loss of cached pages. The hit ratio drop from 99.2% to 76% means nearly a quarter of page requests are going to disk, explaining the jump from 2ms to 45ms (disk I/O is orders of magnitude slower than memory access). b. Metrics to check: - Buffer pool size — has it been altered? - Number of pages in the pool vs. pages in use - Steal count / victim page count — are pages being evicted faster than normal? - Getpage count — has the workload increased dramatically? - Any new workloads hitting the CUSTOMER tablespace - System memory — is the OS paging DB2's memory? - Was REORG, RUNSTATS, or COPY running on the CUSTOMER tablespace? c. Three possible root causes: 1. **Buffer pool was resized smaller** — someone reduced the BP_CUST pool size (accidentally or intentionally). 2. **New workload or query pattern** — a new report or batch job is performing scans on the CUSTOMER table, cycling through pages faster than the LRU can protect the working set. 3. **Operating system memory pressure** — another application on the server consumed memory, causing the OS to page out DB2 buffer pool memory (LUW) or reducing real memory available for buffer pool pages. d. Fixes: 1. **Restore buffer pool size** to its previous value. Review change management to understand why it was reduced. 2. **Isolate the new workload** — if a new batch query is scanning CUSTOMER, move it to a different buffer pool or schedule it outside business hours. If it must run concurrently, increase the buffer pool to accommodate both workloads. 3. **Address OS memory pressure** — identify and resolve the competing memory consumer. Consider pinning buffer pool pages in real memory (z/OS PGFIX or LUW `DB2_PINNED_BP` registry variable) to prevent OS paging.

Exercise 30: Comprehensive Architecture Diagram

Draw (or describe in text) a complete architecture diagram for Meridian Bank on DB2 LUW that includes ALL of the following components. For each, indicate the approximate memory or storage size.

  • DB2 instance and database
  • All buffer pools (with tablespace assignments)
  • Package cache and catalog cache
  • Sort heap
  • Lock list
  • Active log files
  • Archive log destination
  • Storage paths for automatic storage
  • Application connections (50 OLTP users, 2 batch jobs)
  • Fenced mode processes for stored procedures
Sample Architecture Description
Server: mbnk-prod-db01 (64 GB RAM, 16 cores, Linux)
|
+-- DB2 Instance: db2mbnk
|   |
|   +-- Instance Shared Memory (~200 MB)
|   |     - FCM buffers, monitor heap
|   |
|   +-- db2sysc (system controller)
|   +-- db2tcpcm (TCP listener, port 50000)
|   +-- db2ipccm (local IPC)
|   |
|   +-- Database: MERIDIANDB
|   |   |
|   |   +-- Database Shared Memory (~12 GB total, STMM managed)
|   |   |   |
|   |   |   +-- Buffer Pools:
|   |   |   |     BP_CUSTACCT (8K, ~4 GB) --> TS_CUSTOMER, TS_ACCOUNT
|   |   |   |     BP_TRANS    (8K, ~3 GB) --> TS_TRANSACTION
|   |   |   |     BP_INDEX    (4K, ~2 GB) --> TS_INDEX_CUST, TS_INDEX_TRANS
|   |   |   |     BP_TEMP     (32K, ~500 MB) --> TEMPSPACE1
|   |   |   |     IBMDEFAULTBP (4K, ~200 MB) --> SYSCATSPACE, TS_REFERENCE
|   |   |   |
|   |   |   +-- Package Cache: ~500 MB (AUTOMATIC)
|   |   |   +-- Catalog Cache: ~200 MB (AUTOMATIC)
|   |   |   +-- Lock List: ~300 MB (AUTOMATIC)
|   |   |   +-- Shared Sort Heap: ~1 GB threshold
|   |   |
|   |   +-- Active Logs: /db2logs/
|   |   |     25 primary files x 40 MB = 1 GB
|   |   |     15 secondary files x 40 MB = 600 MB (if needed)
|   |   |
|   |   +-- Archive Logs: /db2archlog/
|   |   |     ~100 MB/day, retained 30 days = ~3 GB
|   |   |
|   |   +-- Automatic Storage Paths:
|   |         /db2data/path1 (SAN, 500 GB)
|   |         /db2data/path2 (SAN, 500 GB)
|   |
|   +-- Agents:
|   |     50 x db2agent (OLTP users, ~50 MB each private memory)
|   |     2 x db2agent (batch jobs, ~200 MB each for large sorts)
|   |
|   +-- Prefetchers: 6 x db2pfchr
|   +-- Page Cleaners: 4 x db2pclnr
|   +-- Logger: db2loggr
|   +-- Deadlock Detector: db2dlock
|   +-- Fenced Mode: 3 x db2fmp (for stored procedures)
|
+-- Operating System and Other:
      ~4 GB for OS
      ~4 GB for file system cache
      Remaining: headroom for spikes

Section F: Reflection and Synthesis (Exercises 31-35)

Exercise 31: Architecture Metaphor

The chapter compared DB2 to a hospital with separate departments. Create your own metaphor for DB2's architecture using a different real-world system (a factory, a restaurant, a city, etc.). Map at least five DB2 components to their equivalents in your metaphor. Explain why each mapping works.

(No single correct answer — evaluate based on accuracy of mappings and clarity of explanation.)


Exercise 32: Design Tradeoff Analysis

For each pair of design choices, explain the tradeoff and recommend a choice for Meridian Bank:

a. One large buffer pool vs. multiple specialized buffer pools. b. Fenced vs. unfenced stored procedures. c. Circular logging vs. archive logging. d. 4K page size vs. 8K page size for the TRANSACTION table. e. DPF (multi-partition) vs. single-partition for the core banking database.


Exercise 33: Historical Perspective

Research question: DB2 for z/OS was originally designed in the early 1980s. Explain how at least two architectural decisions were influenced by the hardware constraints of that era (e.g., limited memory, slow disk, expensive CPU). How have those decisions aged?


Exercise 34: Monitoring Plan

Create a monitoring plan for Meridian Bank that specifies which metrics to check for each architectural component. For each metric, define a threshold that should trigger investigation.

Component Metric Healthy Range Alert Threshold
Buffer pools Hit ratio
EDM pool / Package cache
Logging
Locks
Sort

Exercise 35: Architecture Presentation

Prepare a 5-minute presentation outline (bullet points) that explains DB2's architecture to a non-technical bank manager. Your goal is to convince them that proper architecture investment (memory, storage, monitoring) is essential for the bank's operations. Use analogies, avoid jargon, and focus on business impact (response time, reliability, recovery).

(This exercise develops communication skills essential for DBAs who must justify infrastructure investments.)