Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+21 more

    Postgres Performance Playbook

    1

    Turn slow Supabase queries around: measure real plans, fix indexes, tame RLS, and stop connection exhaustion with a tested order of operations.

    Free

    1 useSecurity scanned
    Postgres Performance Playbook

    Postgres Performance Playbook

    Example session with this skill installed

    Our Supabase dashboard is crawling. The posts feed endpoint takes over 4 seconds once users scroll deep, and we started seeing 'remaining connection slots are reserved' errors at around 300 concurrent users. The main table is posts (~2M rows), filtered by author_id, sorted by created_at, with soft deletes via deleted_at. RLS checks visibility = 'public' OR author_id = auth.uid(). Please profile the queries, propose the right composite and partial indexes as CONCURRENTLY migrations, rewrite our offset-based PostgREST paging into keyset pagination, and give me the pooler URL options and timeout settings to fix connection exhaustion.

    • Read your context and instructions
    • Compiled the postgres performance playbook

    Summary

    Profiled the two slowest PostgREST endpoints and cut p95 latency from 4.2s to 210ms by replacing a sequential scan and offset paging with a composite partial index and a keyset cursor.

    MetricBeforeAfter
    p95 feed latency4,200 ms210 ms
    Author query planSeq Scan + Sort (412k rows)Index Scan on idx_posts_author_created
    Page ~5,000 fetch1.9 s (OFFSET 100000)12 ms (keyset cursor)
    Pooler timeouts34/min0

    Next steps

    • Deploy CREATE INDEX CONCURRENTLY idx_posts_author_created ON posts (author_id, created_at DESC) WHERE deleted_at IS NULL; in a low-traffic window.
    • Set statement_timeout=2s and idle_in_transaction_session_timeout=30s on the pooler connection string.
    • Add post_members (post_id, user_id) index before shipping team-based RLS.
    • Re-run EXPLAIN (ANALYZE, BUFFERS) once the table passes 1M rows to confirm the plan holds.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Supabase applications often suffer from high latency and connection exhaustion as data volume scales. This skill provides a systematic order of operations to diagnose bottlenecks, optimize query execution, and stabilize database performance. It focuses on concrete fixes for indexing, RLS policy efficiency, and connection management.

    What it does

    • Query Profiling provides specific patterns for EXPLAIN (ANALYZE, BUFFERS) to identify sequential scans and costly sort nodes.
    • Index Optimization defines rules for composite, partial, and covering indexes based on query selectivity and predicates.
    • RLS Tuning simplifies row-level security policies to prevent recursive lookups and expensive subqueries from slowing down auth-scoped requests.
    • Connection Management configures transaction pooling settings and timeouts to prevent pool exhaustion in high-concurrency environments.
    • Pagination Strategy implements keyset pagination patterns to replace slow OFFSET and LIMIT queries.

    How it works

    1. Use the measurement commands to generate real query plans and identify high-impact bottlenecks.
    2. Apply specific index patterns or schema changes based on the identified scan types.
    3. Refactor RLS policies and application-side SELECT statements to reduce I/O and network overhead.

    Frameworks & tools

    PostgreSQL, Supabase, PostgREST, and PgBouncer.

    Why this beats prompting it yourself

    Generic AI advice often suggests adding indexes to every column, which destroys write performance. This skill enforces a "read-heavy vs. write-heavy" balance and provides Supabase-specific patterns for RLS and connection pooling that general models miss.

    Use cases

    • Reducing API latency in a Supabase-backed dashboard with millions of rows.
    • Fixing "too many connections" errors during traffic spikes.
    • Speeding up slow authenticated queries caused by complex RLS policies.
    • Optimizing search and filtering performance for large JSONB datasets.

    Known limitations

    Does not cover hardware-level scaling or vertical instance upgrades. Requires direct database access for some diagnostic commands.

    Assumes Supabase-style transaction poolers and auth.uid(); self-hosted Postgres with different proxies needs the pooling and RLS sections adapted. It cannot fix bottlenecks outside the database, such as app serialization or network transfer.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before any payment.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    1 use

    Times used to date

    Free to use

    No account required to browse

    Trust & safety

    Security scan

    Security scan passed 1 month ago

    • Free with an Agensi account

    Permissions

    Read Files

    File Scopes

    **/*.sql
    supabase/**
    src/**

    Terminal runs read-only EXPLAIN and pg_indexes diagnostics, file reads cover migrations and query code, and environment access is needed to locate pooler connection settings.

    Listed1 month ago

    What's inside

    Frequently Asked Questions

    This skill focuses on systematic diagnostic patterns for identifying high-latency queries, refactoring inefficient RLS policies, and optimizing connection pooling to prevent crashes during traffic spikes.

    While the core indexing and query profiling logic works with any PostgreSQL instance, the skill includes specialized patterns specifically for PostgREST-driven RLS policies and PgBouncer connection management.

    The purchase includes a set of optimized prompts, diagnostic command templates, and a structured order of operations that you can load into your preferred LLM to guide your database optimization process.

    No, this skill is designed to optimize your existing schema and queries within your current tier; it does not provide advice on hardware upgrades or changing your Supabase billing plan.

    By providing specific rules for composite and partial indexing, this skill helps you avoid 'over-indexing,' which ensures your read performance improves without severely degrading your database's write speed.

    No. Every rule uses built-in Postgres features such as EXPLAIN, pg_indexes, and CREATE INDEX CONCURRENTLY, plus plain SQL and HTTP examples for Supabase and PostgREST.

    Yes. The query, indexing, and locking rules apply to any modern Postgres; only the pooler configuration and RLS sections assume Supabase specifics like transaction pooling and auth.uid().

    Install the skill and describe your slow endpoint, table, or migration to the agent. It follows the measurement-first order of operations and returns concrete index SQL, rewritten queries, and config changes for your review.

    New in Data & Databases

    Free