Skip to content

Feature: add pg_query_state to gp_stats_collector - #1934

Open
roaldm153 wants to merge 5 commits into
apache:REL_2_STABLEfrom
roaldm153:pgqs-apache
Open

Feature: add pg_query_state to gp_stats_collector#1934
roaldm153 wants to merge 5 commits into
apache:REL_2_STABLEfrom
roaldm153:pgqs-apache

Conversation

@roaldm153

Copy link
Copy Markdown

What does this PR do?

Adds a signal-based runtime query-state facility to the gp_stats_collector extension. It lets a session inspect the live execution state of another running backend on demand - walking its active plan tree across the QD and all QEs - without waiting for the query to finish, pushing batches to the UDS(unix domain socket).

New SQL API (extension v1.2, schema gpsc):

  • gpsc.pg_query_state(pid, trace_id) - fan out a poll to the query running on pid; each participating backend walks its plan tree and logs a per-node snapshot.
  • gpsc.pg_query_state_backends(pid) - list the (segid, pid) QE backends taking part in that query.
  • cbdb_mpp_query_state(gpsc.gp_segment_pid[], trace_id) - QE-side dispatch target.

The extension embeds the pg_query_state signal layer, which depends on three PostgreSQL core changes folded directly into the tree (configure enables the extension by default, so the tree must build without a manual patch step):

  • custom ProcSignal handlers (procsignal.c/.h, postgres.c);
  • end-of-node instrumentation flag readable mid-run (instrument.c/.h);
  • runtime EXPLAIN entry points (explain.c/.h).

Type of Change

  • Bug fix (non-breaking change)
  • New feature (non-breaking change)
  • Breaking change (fix or feature with breaking changes)
  • Documentation update

Breaking Changes

None. Core changes are additive (new signal reasons, a new Instrumentation field, new runtime-EXPLAIN paths); existing behavior is unchanged.

Test Plan

  • Unit tests added/updated

  • Integration tests added/updated

  • Passed make installcheck

  • pg_regress (gpcontrib/gp_stats_collector/test): catalog contract (function/type registration, exec location) and input-validation errors.

  • isolation2 (gpcontrib/gp_stats_collector/test/isolation2), multi-session:

    • gpsc_pqs_backends - idle backend yields an empty list;
    • gpsc_pqs_running - happy path: poll a query suspended on the QEs via a fault injector;
    • gpsc_pqs_perms - permission gate (non-owner non-superuser denied);
    • gpsc_pqs_disabled - STAT_DISABLED reports no backends;
    • gpsc_pqs_seg_count - one backend per primary segment.
  • gpsc-crash-test - parallel tracing on make installcheck-parallel, core dumps checking

  • A dedicated CI workflow builds Cloudberry with the extension across ubuntu22.04/rocky8/rocky9 and runs the pg_regress, isolation2, and core regression suites.

Impact

Performance:
No steady-state cost. Work happens only when a poll is issued: one signal fan-out plus a bounded shared-memory round-trip; the shmem lock is held only around the request, not during dispatch.

User-facing changes:
New gpsc.pg_query_state* functions and the pg_query_state.enable GUC. Functions are granted to PUBLIC; access is gated in C so a caller may poll a backend only if it is a superuser or owns the target query.

Dependencies:
None.

Checklist

  • Followed contribution guide
  • Added/updated documentation
  • Reviewed code for security implications
  • Requested review from cloudberry committers

Additional Context

The signal layer under src/pg_query_state/ is derived from pg_query_state (PostgreSQL License). Derived files carry dual license headers (ASF + Portions Copyright Postgres Professional) and the root LICENSE records a PostgreSQL-License notice for it. Happy to provide provenance details for IP clearance.

@tuhaihe
tuhaihe self-requested a review August 28, 2026 02:15
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.

1 participant