Skip to content

DMA 2.0 Postgres collector review#569

Open
smpawar wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
smpawar:feat/postgres-collector-remediation
Open

DMA 2.0 Postgres collector review#569
smpawar wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
smpawar:feat/postgres-collector-remediation

Conversation

@smpawar

@smpawar smpawar commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

🚀 Overview
This Pull Request delivers a comprehensive E2E audit compliance sweep to remediate stability, performance, and security gaps in the PostgreSQL metadata collector.

To ensure an extremely clean and reviewable Git history, all changes have been applied surgically, line-by-line to the original source scripts. Pristine query formats, comment layouts, and lowercase casing have been kept 100% intact, yielding a clean and easily reviewable diff.

🛠️ Key Improvements

  1. Core Bash Wrapper & Enterprise Auth (Track A)
    Robust Connection Parsing: Added regex-based parsing (parse_connection_string) to support complex passwords containing enterprise characters (such as @ or /), eliminating cut-based string-splitting bugs.
    Error Trapping & Fail-Fast: Enabled ON_ERROR_STOP=1 directly in the psql invocation, coupled with non-zero exit status suffix checks (_ERROR) for collection archives. Added || true checks to error grep targets to prevent script crashes when logs are clean.
    OS Metrics Gating: Gated db-machine-specs.sh execution behind a strict check for COLLECT_OS_SPECS=true and non-empty vm_user_name to prevent automated pipelines from hanging.
    Platform Version Routing: Gated major version parsing so that versions below PG 11 fallback cleanly to the "base" queries directory instead of crashing on missing paths.
  2. Enterprise-Scale SQL Optimization & Safety (Track B)
    OOM & Storage Protection (schema_objects.sql): Swapped the verbose object-by-object record listing for aggregated counts (COUNT(*)) grouped by owner, category, type, and schema. This reduces the footprint by up to 99% on systems with massive catalog footprints (e.g., >50k tables).
    Lock & Catalog Protection (schema_details.sql): Stripped expensive disk relation sizing functions (pg_table_size/pg_total_relation_size) from schema detail joins to prevent production DDL lock contention.
    Fast Dependency Scans (aws_extension_dependency.sql): Replaced slow decompiling regex scans with direct, indexed catalog joins on pg_depend and pg_extension, yielding an almost 28x local execution speedup (from 170 ms down to 6 ms).
    Idle Relation Preservation (index_details.sql & data_types.sql): Coalesced metrics and resolved owners directly from pg_namespace so that newly created or idle indexes are no longer filtered out. Optimized type queries to scan strictly user relations.
    Cluster-Wide Footprints (database_details.sql): Removed the restrictive current database filter, enabling cluster-wide databases statistics collection withTablespace and Owner left-join mapping.
  3. Performance Diagnostics & Security Policy
    New Diagnostic Metrics: Appended division-safe Heap Cache Hit Ratio, Index Cache Hit Ratio, and Index Usage Ratio to calculated_metrics.sql.
    Least-Privilege Setup: Replaced the TBD placeholder in README.txt with a standard DDL role creation template for non-superuser read-only execution. Added a Performance Considerations section to guide users on high-scale footprints.
    📊 local Profiling Highlight:
    Local E2E execution and catalog profiling on AlloyDB Omni showed major CPU/IO savings:

aws_extension_dependency.sql (Original regex scan): 170.25 ms
aws_extension_dependency.sql (New optimized catalog-join): 6.11 ms (~28x speedup)
👥 Reviewers Requested:
Please review for E2E query accuracy and bash wrapper stability. All tests and staging validations are complete!

@smpawar smpawar marked this pull request as ready for review June 1, 2026 14:46
@smpawar smpawar requested a review from wpuziewicz June 2, 2026 16:29
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