Skip to content

feat: enable pg_stat_statements for Ecto Stats - #312

Merged
zorn merged 3 commits into
mainfrom
zorn/issue-308-enable-pg-stat-statements
Oct 20, 2026
Merged

zorn merged 3 commits into
mainfrom
zorn/issue-308-enable-pg-stat-statements

Conversation

@zorn

@zorn zorn commented Oct 20, 2026 •

Copy link
Copy Markdown
Owner

Closes #308

This enables pg_stat_statements on flick_prod, so LiveDashboard's Ecto Stats "outliers" and "calls" tabs can show which queries cost the most time. It follows the Ecto Stats rollout in #305.

The risk is a skipped extension, not a failed deploy

The migration runs at boot, so an error there would stop the deploy. To prevent that, the migration catches any error, rolls back, and logs pg_stat_statements skipped: <reason>. A revert followed by a rollback drops the extension. Nothing in Flick reads the extension, and the suite is unchanged at 193 passing.

Production preloads the library

A rolled-back dry run in a remote shell on flick_prod created the extension and read its view, returning {:error, :dry_run}. Render preloads the library, and the app role may create the extension.

The migration creates the extension, then reads its view once

The issue's plain CREATE EXTENSION broke Ecto Stats on any server that does not preload the library, which includes local and CI Postgres. A first version read shared_preload_libraries to decide, but only superusers can read that setting. The migration instead creates the extension and reads its view once. If either step raises, the block rolls back. I checked each path by hand on postgres:18:

Server Result
Preloaded, superuser Extension created, view readable
Not preloaded Skipped with notice
Preloaded, plain owner role Skipped with notice (permission denied)

Worth a reviewer's attention

  • A skip is logged, not fatal. A diagnostics extension should never block a deploy, but a skip shows up only in the migration log.
  • The check runs once. If a server starts preloading the library later, a new migration has to create the extension.
  • The down step always drops the extension. Production had no extension before this migration, so this migration is what creates it.
  • No automated test covers the preloaded path. CI's service container cannot pass -c shared_preload_libraries, so I verified it by hand.

Copilot AI balanced review requested due to automatic review settings October 20, 2026 16:58

Copilot AI 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.

🟢 Approval recommended

The scoped migration handles the documented failure paths and rollback, with no blocking issues identified.

No open issues 🎉

What changed in this PR

Enables pg_stat_statements where supported so LiveDashboard’s Ecto Stats can report query costs, following the dashboard rollout in #305.

Changes:

  • Adds a reversible migration that creates and probes the extension, skipping expected preload and permission failures with a notice.
  • Documents the requirements for the “outliers” and “calls” tabs.
File Description
priv/​repo/​migrations/​20261020164842_enable_pg_stat_statements.exs Creates and checks the extension; drops it on rollback.
AGENTS.md Documents preload requirements and local/CI skip behavior.

Review effort: Balanced

@zorn
zorn merged commit 6144916 into main Oct 20, 2026
8 checks passed
@zorn
zorn deleted the zorn/issue-308-enable-pg-stat-statements branch October 20, 2026 17:13
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.

Enable pg_stat_statements on flick_prod if Render supports it

2 participants