Skip to content

fix: call _heroku.pg_stat_statements_reset() on Essential and Advanced plans#3751

Merged
sbosio merged 3 commits into
mainfrom
fix/pg-outliers-reset-use-heroku-schema
Jun 8, 2026
Merged

fix: call _heroku.pg_stat_statements_reset() on Essential and Advanced plans#3751
sbosio merged 3 commits into
mainfrom
fix/pg-outliers-reset-use-heroku-schema

Conversation

@dasofiei

@dasofiei dasofiei commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • heroku pg:outliers --reset was calling pg_stat_statements_reset() directly for all plans
  • On Essential/Advanced, the real function is no longer granted to tenants — they have a SECURITY DEFINER wrapper _heroku.pg_stat_statements_reset() scoped to the current database only
  • Now uses getAttachment to detect the plan and calls the right function per fleet:
    • Essential & Advanced : SELECT _heroku.pg_stat_statements_reset()
    • Standard and below : SELECT pg_stat_statements_reset()

Change is not in shogun yet, it will be merged on Monday evening, right before the minor release.
There will be a brief period of time where the reset cli command won't work for essential & performance plans, in-between shogun release & cli release.

It can be tested using my shogun as below.

Type of Change

  • fix: Bug fix

Testing

Tests:

npx mocha --require ts-node/register test/unit/commands/pg/outliers.unit.test.ts

getting statement count:
SELECT count(*) FROM pg_stat_statements WHERE dbid = (SELECT   oid FROM pg_database WHERE datname = current_database())  AND userid = (SELECT usesysid FROM pg_user WHERE usename =  current_user);

calling reset:
HEROKU_DATA_HOST=shogun.dasofiei.herokudev.com HEROKU_DATA_SERVICE=heroku-postgresql-dasofiei ./bin/run pg:outliers --reset HEROKU_POSTGRESQL_DASOFIEI_RED_URL --app dasofiei-public

End-to-end:

  1. Build: `npm run build`
  2. On an Essential database: `heroku pg:outliers --reset --app ` — should succeed and return cleanly
  3. Verify the reset only cleared that database's stats — connect to a second Essential on the same cluster, confirm its `pg_stat_statements` count is unchanged
  4. On a Standard database: `heroku pg:outliers --reset --app ` — should succeed using the real function directly

Related

Shogun PR: https://github.com/heroku/shogun/pull/22200
Reset docs -> https://devcenter.heroku.com/articles/heroku-cli-commands#heroku-pg-outliers-database

dasofiei added 2 commits June 5, 2026 18:45
…plans

The real pg_stat_statements_reset is no longer granted to tenants on
Aurora (Essential/Advanced) — they now have a SECURITY DEFINER wrapper
in the _heroku schema scoped to the current database only. Standard and
below continue to call the real function directly.
getDatabase returns ConnectionDetails without plan info. Use getAttachment
to get the addon with plan and correctly detect Essential/Advanced plans.
@dasofiei dasofiei requested a review from a team as a code owner June 5, 2026 18:06
@dasofiei dasofiei temporarily deployed to AcceptanceTests June 5, 2026 18:06 — with GitHub Actions Inactive
@dasofiei dasofiei temporarily deployed to AcceptanceTests June 5, 2026 18:06 — with GitHub Actions Inactive
@dasofiei dasofiei temporarily deployed to AcceptanceTests June 5, 2026 18:06 — with GitHub Actions Inactive
@dasofiei dasofiei temporarily deployed to AcceptanceTests June 5, 2026 18:06 — with GitHub Actions Inactive
@sbosio sbosio temporarily deployed to AcceptanceTests June 8, 2026 14:49 — with GitHub Actions Inactive
@sbosio sbosio temporarily deployed to AcceptanceTests June 8, 2026 14:49 — with GitHub Actions Inactive
@sbosio sbosio temporarily deployed to AcceptanceTests June 8, 2026 14:49 — with GitHub Actions Inactive
@sbosio sbosio temporarily deployed to AcceptanceTests June 8, 2026 14:49 — with GitHub Actions Inactive
@sbosio

sbosio commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

@dasofiei I did a small change removing the extra resolution step, because the add-on info is already present on the attachment key for the database resolver and this avoids another slow request to Platform API. I had to improve a little bit the mocked data on tests so they resemble better the actual information returned by that database resolver and smoke tested all commands to ensure it continues working.

In my case that I was testing against prod, for Advanced and Essential DBs I've got an error related with the wrapper function not existing in the database engine, but I guess that has to do with the backend not being updated yet. Can you test against your development add-on and let me know if everything looks ok? That way I can approve and merge and we should be ready for the release.

@dasofiei

dasofiei commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

Tested successfully against an advanced, it reset the statements.
Screenshot 2026-06-08 at 17 49 28

@sbosio sbosio 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.

Looks good!

@sbosio sbosio merged commit 5414e36 into main Jun 8, 2026
17 checks passed
@sbosio sbosio deleted the fix/pg-outliers-reset-use-heroku-schema branch June 8, 2026 16:59
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