Dosu LogoDosu Logo
Ask
Join our Discord
Organization avatar
HelmorPublic
Caspian's Workspace
DocumentsHelmor
monitor-pg-stat-statements
monitor-pg-stat-statements
Type
External
Status
Published
Created
Jul 14, 2026
Updated
Jul 14, 2026
Source
.agents/skills/supabase-postgres-best-practices/rules/monitor-pg-stat-statements.md

Enable pg_stat_statements for Query Analysis#

pg_stat_statements tracks execution statistics for all queries, helping identify slow and frequent queries.

Incorrect (no visibility into query patterns):

-- Database is slow, but which queries are the problem?
-- No way to know without pg_stat_statements

Correct (enable and query pg_stat_statements):

-- Enable the extension
create extension if not exists pg_stat_statements;

-- Find slowest queries by total time
select
  calls,
  round(total_exec_time::numeric, 2) as total_time_ms,
  round(mean_exec_time::numeric, 2) as mean_time_ms,
  query
from pg_stat_statements
order by total_exec_time desc
limit 10;

-- Find most frequent queries
select calls, query
from pg_stat_statements
order by calls desc
limit 10;

-- Reset statistics after optimization
select pg_stat_statements_reset();

Key metrics to monitor:

-- Queries with high mean time (candidates for optimization)
select query, mean_exec_time, calls
from pg_stat_statements
where mean_exec_time > 100 -- > 100ms average
order by mean_exec_time desc;

Reference: pg_stat_statements

Documents
01 - Get Started
01 - Introduction
02 - Install Helmor
03 - Add a Repository
04 - Create a Workspace
05 - Send Your First Agent Task
02 - Core Concepts
01 - Repository
02 - Workspace
03 - Session
04 - Agent
05 - Changes and Review
06 - GitHub Integration
03 - User Workflows
01 - Start a New Task
02 - Review Agent Changes
03 - Continue an Existing Session
04 - Commit and Ship Work
05 - Use Multiple Agents Safely
04 - Developer Setup
01 - Local Development Setup
02 - Architecture Overview
03 - Frontend Overview
04 - Backend Overview
05 - Sidecar Overview
06 - Testing Guide
07 - Debugging Guide
05 - Troubleshooting
01 - Agent Not Responding
02 - GitHub Authentication Issues
03 - Workspace Errors
04 - Sidecar and CLI Issues
05 - Logs and Diagnostics
7-data-driven-checks-to-ensure-your-documentation-roi-is-high
AGENTS
AGENTS
AGENTS
CHANGELOG
CLAUDE
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
SKILL
SKILL
SKILL
STRIPE_README
[tag]
_template
advanced-full-text-search
advanced-jsonb-indexing
ai-contributions-open-source
ai-is-better-at-maintaing-docs-than-humans
april-2025-newsletter-dosu-does-docs
august-2025-dosu-drop
automating-github-issue-triage
better-agent-testing-with-distributed-dependency-injection
blog_template
building-the-future-of-knowledge-management-june-dosu-drop
celery-preserializers-a-low-friction-path-to-pydantic-support
channel-creation-github-repository
channel-creation-slack-channel
ci-jobs
cncf-dosu-case-study
combating-open-source-maintainer-burnout-with-automation
concepts-channel
concepts-data-sources
concepts-interactions
configuration
confluence_edited_markdown
confluence_original_markdown
conn-idle-timeout
conn-limits
conn-pooling
conn-prepared-statements
data-batch-inserts
data-n-plus-one
data-pagination
data-upsert
december-2025-dosu-drop
default
devin
docling-open-source-growth-with-dosu
dosus-new-fact-based-reasoning-agent-is-generally-available
features-auto-labeling
features-generate-docs
features-issue-triage-qa
features-maintain-docs
february-2025-newsletter-introducing-spaces
from-maintenance-to-innovation-freeing-developers-with-ai-automation
george-xu
github-configuration
github-features-dosu-in-first-awesome-continuous-ai-list
github-installation
how-dosu-used-langsmith-to-achieve-a-30-accuracy-improvement-with-no-prompt-engineering
how-lancedb-supercharged-our-knowledge-graph
how-preset-keeps-apache-superset-healthy
how-triliumnext-revitalized-an-abandoned-open-source-project-with-dosus-help
index
index
internal-vs-external-documentation-audience-first
iterating-towards-llm-reliability-with-evaluation-driven-development
january-2026-dosu-drop
july-dosu-drop-public-spaces-enter-the-chat
knowledge-management-in-the-ai-era-why-documentation-is-more-critical-than-ever
li-zheng
lock-advisory
lock-deadlock-prevention
lock-short-transactions
lock-skip-locked
march-2025-newsletter-dosu-knows
marcos
markdown
mastering-auto-labeling-taming-the-backlog-with-intelligent-labels
may-2025-dosu-drop-new-agent-self-serve-pricing-fresh-look
member-invitation
michael-ludden
michael-mangus
migrate-celery-to-dbos-dosu
monitor-explain-analyze
monitor-pg-stat-statements
monitor-vacuum-analyze
notion_edited_markdown
notion_original_markdown
november-2025-dosu-drop
october-2025-dosu-drop
onboarding-introduction
onboarding-key-concepts
onboarding-quickstart
open-source-labeling-best-practices
page
page
pages
photos
pull_request_template
query-composite-indexes
query-covering-indexes
query-index-types
query-missing-indexes
query-partial-indexes
reliable-data-orchestration-for-ai-applications
response-previews
scaling-support-and-documentation-at-Dify-one-of-the-fastest-growing-oss-projects
schema-data-types
schema-foreign-key-indexes
schema-lowercase-identifiers
schema-partitioning
schema-primary-keys
security-privileges
security-rls-basics
security-rls-performance
september-2025-dosu-drop
settings
slack-configuration
slack-installation
sparrowhawk
taylor-dolezal
the-code-understanding-paradox-when-ai-makes-writing-code-fast-but-understanding-it-slow
top-5-zombie-problems-resurrected-by-ai-tools
using-ai-to-generate-and-maintain-documentation
what-lodashs-issue-backlog-reveals-about-oss-burnout
what-the-mythical-man-month-got-right-about-documentation
word2vec-to-transformers-ai-evolution