Skip to content

fix: consolidate pg_stat_statements handling#3799

Merged
jdodson merged 3 commits into
mainfrom
jbd_migrate_functions_to_use_existing_functions
Jul 1, 2026
Merged

fix: consolidate pg_stat_statements handling#3799
jdodson merged 3 commits into
mainfrom
jbd_migrate_functions_to_use_existing_functions

Conversation

@jdodson

@jdodson jdodson commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

pg:calls and pg:outliers had duplicate setup code and assumed the extension lived in a specific schema. This unifies them and makes both commands work no matter where the extension is installed.

These changes were driven from the data team / Jason Wadsworth: https://salesforce-internal.slack.com/archives/C1N6YD1PG/p1782855687428859

  • Both commands now share one helper in lib/pg/extras.ts (removed the duplicate in pg:outliers).
  • The helper detects the extension's actual schema and the queries use it, instead of guessing public/heroku_ext.
  • pg:outliers --reset now uses that schema too (the aurora/essential path is unchanged).
  • Simplified the "extension not installed" error message.
  • Updated unit tests.

Type of Change

Breaking Changes (major semver update)

  • Add a ! after your change type to denote a change that breaks current behavior

Feature Additions (minor semver update)

  • feat: Introduces a new feature to the codebase

Patch Updates (patch semver update)

  • fix: Bug fix
  • deps: Dependency upgrade
  • revert: Revert a previous commit
  • chore: Change that does not affect production code
  • refactor: Refactoring existing code without changing behavior
  • test: Add/update/remove tests

Testing

Notes: npm install && npm run build. Provision a fresh, throwaway Standard-tier classic Postgres DB (standard-0) — it's billed hourly, starts clean, and hits the branch we changed (Essential/Aurora hit the untouched _heroku. branch and won't let you manage extensions). Destroy it when done.

Steps:

  1. Create a clean DB and wait for it:
    heroku addons:create heroku-postgresql:standard-0 -a $APP
    heroku pg:wait -a $APP
    
  2. Check where pg_stat_statements got installed:
    heroku pg:psql -a $APP -c "SELECT n.nspname FROM pg_extension e JOIN pg_namespace n ON n.oid=e.extnamespace WHERE e.extname='pg_stat_statements';"
    
    • If it's already non-public (e.g. heroku_ext), that's your non-default-schema case for free — skip to step 4.
    • If it's public (or missing), do step 3 to force a custom schema.
  3. (Only if step 2 showed public.) Reinstall into a non-default schema:
    heroku pg:psql -a $APP
    DROP EXTENSION IF EXISTS pg_stat_statements;
    CREATE SCHEMA IF NOT EXISTS stats;
    CREATE EXTENSION pg_stat_statements SCHEMA stats;
    \q
    
  4. Confirm both commands work against that schema, and --reset too:
    ./bin/run pg:calls -a $APP           # returns rows, no error
    ./bin/run pg:outliers -a $APP        # returns rows, no error
    ./bin/run pg:outliers --reset -a $APP   # succeeds
    
    (Before this PR these failed when the extension wasn't in public.)
  5. Confirm the not-installed error:
    heroku pg:psql -a $APP -c 'DROP EXTENSION pg_stat_statements;'
    ./bin/run pg:outliers -a $APP
    
    Expect exactly:
    The pg_stat_statements extension needs to be installed first.
    You can install it by running:
    
        CREATE EXTENSION pg_stat_statements;
    
  6. Tear down the test DB:
    heroku addons:destroy heroku-postgresql:standard-0 -a $APP --confirm $APP
    

Screenshots (if applicable)

Related Issues

GitHub issue: https://gus.lightning.force.com/lightning/r/ADM_Work__c/a07EE00002cTDz5YAG/view

@jdodson jdodson requested a review from a team as a code owner July 1, 2026 19:52
@jdodson jdodson temporarily deployed to AcceptanceTests July 1, 2026 19:52 — with GitHub Actions Inactive
@jdodson jdodson temporarily deployed to AcceptanceTests July 1, 2026 19:52 — with GitHub Actions Inactive
@jdodson jdodson temporarily deployed to AcceptanceTests July 1, 2026 19:52 — with GitHub Actions Inactive
@jdodson jdodson temporarily deployed to AcceptanceTests July 1, 2026 19:52 — with GitHub Actions Inactive
@jdodson jdodson temporarily deployed to AcceptanceTests July 1, 2026 21:14 — with GitHub Actions Inactive
@jdodson jdodson temporarily deployed to AcceptanceTests July 1, 2026 21:14 — with GitHub Actions Inactive
@jdodson jdodson temporarily deployed to AcceptanceTests July 1, 2026 21:14 — with GitHub Actions Inactive
@jdodson jdodson temporarily deployed to AcceptanceTests July 1, 2026 21:14 — with GitHub Actions Inactive
@jdodson jdodson changed the title fix: consolidate pg_stat_statements handling refactor: consolidate pg_stat_statements handling Jul 1, 2026
@jdodson jdodson changed the title refactor: consolidate pg_stat_statements handling fix: consolidate pg_stat_statements handling Jul 1, 2026

@tlowrimore-heroku tlowrimore-heroku left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

@jdodson jdodson temporarily deployed to AcceptanceTests July 1, 2026 22:52 — with GitHub Actions Inactive
@jdodson jdodson temporarily deployed to AcceptanceTests July 1, 2026 22:52 — with GitHub Actions Inactive
@jdodson jdodson temporarily deployed to AcceptanceTests July 1, 2026 22:52 — with GitHub Actions Inactive
@jdodson jdodson temporarily deployed to AcceptanceTests July 1, 2026 22:52 — with GitHub Actions Inactive
@jdodson jdodson merged commit e36b494 into main Jul 1, 2026
17 checks passed
@jdodson jdodson deleted the jbd_migrate_functions_to_use_existing_functions branch July 1, 2026 23:02
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