Skip to content

pmdadb2: fix Db2 v12 MON_* column and view compatibility#2625

Open
kurik wants to merge 2 commits into
performancecopilot:mainfrom
kurik:db2
Open

pmdadb2: fix Db2 v12 MON_* column and view compatibility#2625
kurik wants to merge 2 commits into
performancecopilot:mainfrom
kurik:db2

Conversation

@kurik

@kurik kurik commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Update SQL for Db2 12 (TBSP_NAME, ACT_COMPLETED_TOTAL, SYSIBMADM.ENV_INST_INFO, transaction log byte fields), report zero for unavailable per-table deadlocks, and only drop connections on communication failures.

Update SQL for Db2 12 (TBSP_NAME, ACT_COMPLETED_TOTAL,
SYSIBMADM.ENV_INST_INFO, transaction log byte fields), report zero for
unavailable per-table deadlocks, and only drop connections on
communication failures.
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Repository UI (inherited), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 8a49aab7-7600-439f-be87-d9ea8af83f35

📥 Commits

Reviewing files that changed from the base of the PR and between a8f3be0 and e71d0f6.

📒 Files selected for processing (1)
  • src/pmdas/db2/pmdadb2.python

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of lost/unusable Db2 connections to avoid unnecessary connection resets.
    • Updated Db2 metric SQL/metadata to match current catalog/monitor view columns for more accurate reporting.
  • Changes

    • Refined Db2 metric semantics, including “statements completed” mapping and revised tablespace source naming.
    • Updated deadlock reporting behavior/messages (per-table deadlocks now report as zero where unsupported; use database-wide deadlocks).
    • Adjusted transaction log “used” and “available” calculations and their “Source” descriptions accordingly.

Walkthrough

Updates the Db2 PMDA in pmdadb2.python to align SQL cluster queries with correct Db2 view column names (TBSP_NAME, ACT_COMPLETED_TOTAL, SYSIBMADM.ENV_INST_INFO, log KB derivation), introduces a table_row_val callback and _db2_connection_lost helper, adds a row_val parameter to db2_refresh_instanced, and updates metric help text throughout.

Changes

Db2 PMDA metric and runtime fixes

Layer / File(s) Summary
SQL cluster column name corrections
src/pmdas/db2/pmdadb2.python
Tablespace indom and cluster SQL switch to TBSP_NAME; database cluster item 18 uses ACT_COMPLETED_TOTAL; instance cluster switches to SYSIBMADM.ENV_INST_INFO with SERVICE_LEVEL and BLD_LEVEL columns; transaction log SQL derives KB values via TOTAL_LOG_USED / 1024 and TOTAL_LOG_AVAILABLE / 1024.
Table deadlock zeroing via row_val callback
src/pmdas/db2/pmdadb2.python
MON_GET_TABLE select-list is realigned; new table_row_val() forces per-table deadlock metrics to 0; db2_refresh_instanced() gains an optional row_val parameter that replaces row[item+1] indexing when provided; MON_GET_TABLE refresh dispatch passes self.table_row_val.
Selective connection-handle clearing on failure
src/pmdas/db2/pmdadb2.python
New _db2_connection_lost() classifies exceptions by SQLSTATE and handle liveness state; db2_exec clears self.conns[dbname] only when the helper confirms the connection is unusable, rather than on every exception.
Metric help text and Source: string updates
src/pmdas/db2/pmdadb2.python
All Source: strings updated for db2.database.stmts_completed, db2.log.used_kb, db2.log.available_kb, and db2.instance.* metrics to reference corrected column sources; cluster 9 comment updated; db2.table.deadlocks help text replaced to document that per-table deadlock counts are always zero on affected Db2 versions and redirects users to database-wide deadlocks.

Possibly related PRs

  • performancecopilot/pcp#2621: Introduced the DB2PMDA class and its core methods (db2_refresh_instanced, db2_exec, cluster SQL definitions) that this PR directly extends with _db2_connection_lost, table_row_val, and the row_val callback parameter.

Poem

🐇 A rabbit checks the columns with care,
TBSP_NAME found waiting there.
Deadlocks zeroed, connections assessed,
BLD_LEVEL fields freshly redressed.
Each Source: string now points true —
The metrics hop through views brand new! 🐾

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'pmdadb2: fix Db2 v12 MON_* column and view compatibility' accurately summarizes the main objective of updating Db2 PMDA for version 12 compatibility with column and view name changes.
Description check ✅ Passed The PR description provides a concise summary of key changes (TBSP_NAME, ACT_COMPLETED_TOTAL, SYSIBMADM.ENV_INST_INFO, transaction log fields, deadlock reporting, and connection handling) that align with the actual changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kurik

kurik commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

This is a followup of #2621
Tested with DB2-11.5.9.0 and DB2-12.1.4.0 Community editions as back-end.

@natoscott I can not make db2.table.* metrics working. My AI agent is complaining, that those metrics were per-table in older DB2 versions, while for DB2 v11 and v12 these metrics are per-database and suggesting to remove these from the PMDA. Perhaps we might need some expert here, as discussed elsewhere.

To make pylint happy, the number of parameters passed to
db2_refresh_instanced() has been reworked.
@natoscott

Copy link
Copy Markdown
Member

This is a followup of #2621 Tested with DB2-11.5.9.0 and DB2-12.1.4.0 Community editions as back-end.

@natoscott I can not make db2.table.* metrics working. My AI agent is complaining, that those metrics were per-table in older DB2 versions, while for DB2 v11 and v12 these metrics are per-database and suggesting to remove these from the PMDA. Perhaps we might need some expert here, as discussed elsewhere.

@kurik Awesome - thanks for the investigation and fixes — the TABLESPACE_NAME -> TBSP_NAME, ACT_COMPLETED_TOTAL, SYSIBMADM.ENV_INST_INFO, and log byte-field changes all look good to me.

One concern about the DEADLOCKS handling: keeping the metric returning a hardcoded zero is misleading — this way if monitoring db2.table.deadlocks we cannot distinguish "no deadlocks occurred" from "this data is not available at the table level". Better to remove it entirely.

The same applies to the other lock-related columns in the MON_GET_TABLE query: LOCK_WAITS, LOCK_WAIT_TIME, and LOCK_ESCALS. If DEADLOCKS is not available per-table in Db2 v11/v12, these may have the same limitation. Could you verify whether these three columns return meaningful per-table values on your 12.1 instance, or whether they too reflect only database-wide aggregates?

If they are also unavailable per-table, we should remove all four lock-related metrics (db2.table.deadlocks, db2.table.lock_waits, db2.table.lock_wait_time, db2.table.lock_escalations) from the cluster rather than stub them. The row DML counters, overflow accesses, and table scan counts would remain as the meaningful per-table metrics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants