S

supabase-postgres-best-practices

by supabase

supabase-postgres-best-practices is a Supabase Postgres optimization skill for query tuning, indexing, schema design, RLS performance, locking, and connection management.

Stars1.7k
Favorites0
Comments0
AddedMar 29, 2026
CategoryDatabase Engineering
Install Command
npx skills add https://github.com/supabase/agent-skills --skill supabase-postgres-best-practices
Curation Score

This skill scores 84/100, which means it is a solid directory listing candidate: agents get a clear trigger, a substantial body of reusable Postgres optimization guidance, and enough structure to apply it with less guesswork than a generic prompt. For directory users, the repository provides credible install-decision value through prioritized categories, on-demand references, and concrete SQL rewrite examples, though it reads more like a reference library than a step-by-step execution workflow.

84/100
Strengths
  • Clear trigger conditions in SKILL.md for query writing, schema design, performance review, scaling, and RLS work.
  • Strong agent leverage from 30+ topic references with incorrect vs. correct SQL examples and quantified impact claims.
  • Good progressive disclosure: SKILL.md gives category priorities while AGENTS.md routes agents to detailed files only as needed.
Cautions
  • No explicit install or invocation instructions in SKILL.md, so adopters must infer usage from the standard repository structure.
  • Some repository scaffolding files still include template/demo language, which slightly weakens trust even though the main references appear substantive.
Overview

Overview of supabase-postgres-best-practices skill

The supabase-postgres-best-practices skill is a structured Postgres optimization reference from Supabase for people who need better SQL, schema, indexing, RLS, and connection-management decisions than a generic coding prompt usually gives. It is best for database engineers, backend developers, and AI-assisted reviewers working on Supabase or plain Postgres systems where performance and correctness both matter.

What this skill actually helps you do

Use supabase-postgres-best-practices when your real job is not “explain Postgres,” but things like:

  • rewrite a slow query
  • choose the right index shape
  • avoid N+1 and bad pagination patterns
  • improve RLS safety without killing performance
  • reduce lock contention
  • diagnose whether a query, schema, or connection pattern is the bottleneck

The value is that the skill is organized into practical rule files with bad-vs-good SQL examples, not just broad advice.

Best-fit users and projects

This skill fits teams that:

  • run Supabase-backed apps and want Postgres-specific guidance
  • review migrations, SQL functions, policies, or schema changes with AI
  • want repeatable optimization patterns for Database Engineering work
  • need concrete examples for indexing, connection pooling, monitoring, and query plans

It is especially useful if you already have schema or query context and want the model to produce grounded improvements instead of generic “add indexes” advice.

Why this skill is better than a normal prompt

The main differentiator is coverage plus prioritization. The repository groups guidance into eight categories, with critical areas first: query performance, connection management, and security/RLS. The supporting references/ files also show exact transformations, quantified impact, and tradeoffs, which gives the model stronger material to apply than a one-line instruction like “optimize my Postgres.”

What it covers well

The supabase-postgres-best-practices skill is strongest on:

  • query indexing strategy, including composite, covering, partial, and missing indexes
  • schema choices like data types, primary keys, constraints, partitioning, and foreign-key indexing
  • operational topics like connection limits, pooling, prepared statements, and idle timeouts
  • concurrency patterns such as advisory locks, short transactions, deadlock prevention, and SKIP LOCKED
  • monitoring with EXPLAIN ANALYZE, pg_stat_statements, and vacuum/analyze
  • advanced Postgres features like JSONB indexing and full-text search

Where it is not the right tool

This is not a full Postgres administration manual, migration framework, or benchmark suite. If you need environment-specific tuning at the level of hardware sizing, WAL configuration, or deep replication architecture, this skill is more of a practical query-and-schema guide than a full DBA playbook.

How to Use supabase-postgres-best-practices skill

How to install supabase-postgres-best-practices

If your skill runner supports remote GitHub installs, use:

npx skills add https://github.com/supabase/agent-skills --skill supabase-postgres-best-practices

If your environment loads skills from a cloned repository, the skill lives at:

skills/supabase-postgres-best-practices

Because SKILL.md does not include an install command itself, directory users should rely on the repository-level install flow above or their local skill loader conventions.

Read these files first

For the fastest path to productive use, read in this order:

  1. skills/supabase-postgres-best-practices/SKILL.md
  2. skills/supabase-postgres-best-practices/AGENTS.md
  3. skills/supabase-postgres-best-practices/references/_sections.md
  4. the specific references/*.md files that match your problem

README.md is mainly contributor-oriented. It is useful if you want to extend or validate the skill, but less important for first-time usage.

Start from the category, not the whole repository

The skill is easiest to use if you map your problem to one of the repository prefixes first:

  • query- for slow SQL and indexes
  • conn- for serverless or high-concurrency connection issues
  • security- for privileges and RLS
  • schema- for table and column design
  • lock- for contention and queue workers
  • data- for batching, pagination, upsert, and N+1
  • monitor- for diagnostics
  • advanced- for JSONB and full-text search

This cuts down prompt drift and gets the model into the right solution family faster.

What inputs produce good results

The supabase-postgres-best-practices usage quality depends heavily on the specificity of your input. Give the model:

  • the current SQL query or migration
  • relevant table definitions
  • row counts or estimated scale
  • current indexes
  • slow symptoms such as latency, CPU, locks, or connection exhaustion
  • whether you are using Supabase features like RLS or pooled connections
  • any correctness constraints, such as “must preserve cursor order” or “policy must remain tenant-safe”

Without that, you will usually get broadly correct but shallow suggestions.

Turn a rough goal into a strong prompt

Weak prompt:

Optimize this Postgres query.

Better prompt:

Use the supabase-postgres-best-practices skill to review this query for index use, data access pattern issues, and RLS impact. Explain likely bottlenecks, propose rewritten SQL, recommend exact indexes, and note tradeoffs. Context: table sizes, existing indexes, and EXPLAIN ANALYZE are below.

Best prompt structure:

  • objective
  • current SQL/schema/policy
  • workload shape
  • constraints
  • desired output format

That structure aligns well with how the reference files teach transformations.

Example prompt for query optimization

Use a prompt like this:

Apply supabase-postgres-best-practices to this endpoint query. Check for missing composite or partial indexes, N+1 patterns, unnecessary scans, and pagination problems. If you suggest an index, explain why the predicate and sort order fit it. If EXPLAIN ANALYZE would change your confidence, say exactly what to verify.

This works better than asking for “best practices” because it asks for decisions, not summaries.

Example prompt for schema and RLS review

For schema or policy work, try:

Use the supabase-postgres-best-practices skill to review this migration and RLS policy set. Focus on foreign-key indexing, data types, constraints, lowercase identifiers, privilege boundaries, and whether the RLS predicates will scale on large tables. Return changes in priority order with SQL examples.

That prompt points the model to the strongest reference areas in the repo.

Best repository-reading paths by task

Use these file paths as shortcuts:

  • slow query: references/query-missing-indexes.md, references/query-composite-indexes.md, references/query-covering-indexes.md
  • soft-delete or filtered workload: references/query-partial-indexes.md
  • API overfetching or repeated calls: references/data-n-plus-one.md, references/data-batch-inserts.md
  • pagination issues: references/data-pagination.md
  • worker queues or contention: references/lock-skip-locked.md, references/lock-short-transactions.md
  • Supabase auth and policy performance: references/security-rls-basics.md, references/security-rls-performance.md
  • diagnosing slowness: references/monitor-explain-analyze.md, references/monitor-pg-stat-statements.md

This is the fastest way to get practical value from supabase-postgres-best-practices for Database Engineering.

Suggested workflow in real projects

A reliable workflow is:

  1. identify the problem class
  2. load only the matching reference files
  3. ask for a ranked list of fixes
  4. request SQL rewrites and index DDL
  5. validate with EXPLAIN ANALYZE or workload data
  6. iterate on the top one or two changes, not every possible improvement

The skill is strongest when used as a focused reviewer, not as a broad brainstorming assistant.

Practical tips that change output quality

A few usage choices make a noticeable difference:

  • include existing indexes so the model does not suggest duplicates
  • include sample predicates and ORDER BY clauses so index advice is shaped correctly
  • tell it whether writes are heavy, because that changes index tradeoffs
  • for RLS, provide actual policy text; otherwise performance advice will stay generic
  • ask for “priority order” so critical fixes come before nice-to-have cleanup

supabase-postgres-best-practices skill FAQ

Is supabase-postgres-best-practices only for Supabase users?

No. The skill is maintained by Supabase, but most of the guidance is standard Postgres engineering advice. It is still useful if you run vanilla Postgres, especially for query planning, indexing, locking, JSONB, and full-text search.

Is this skill good for beginners?

It can help motivated beginners, but it is not beginner-first. The examples are concrete and clear, yet many recommendations assume you can read SQL, understand indexes, and verify plans. If you are new to Postgres, use it with real schema context and ask for plain-language explanations alongside the fixes.

What does this skill do better than a general SQL prompt?

The supabase-postgres-best-practices guide gives the model a curated set of anti-patterns, corrected SQL, impact framing, and topic-specific references. That usually produces more actionable answers than generic prompting, especially on partial indexes, RLS performance, connection limits, and lock patterns.

When should I not use supabase-postgres-best-practices?

Do not expect it to replace production benchmarking, DBA-level infrastructure tuning, or vendor-specific managed-service operations guidance. It also will not infer your workload correctly if you provide no schema, query, or plan details.

Does it help with performance debugging, not just code generation?

Yes. The monitoring references cover EXPLAIN ANALYZE, pg_stat_statements, and vacuum/analyze topics, so the skill can support diagnosis as well as rewrites. It is useful both before writing SQL and after you observe slowness.

Can it review migrations and pull requests?

Yes. That is one of the best uses. It can inspect migration SQL, schema diffs, policy changes, and query code for likely performance or safety issues, then propose more Postgres-friendly alternatives.

How to Improve supabase-postgres-best-practices skill

Give the skill the evidence it needs

The fastest way to improve supabase-postgres-best-practices output is to supply concrete evidence:

  • EXPLAIN ANALYZE
  • table schemas
  • index definitions
  • row counts
  • query frequency
  • read/write ratio
  • policy definitions

This skill has strong reference material, but it still cannot choose well between, for example, a composite index and a partial index if your predicates are unclear.

Ask for ranked fixes, not a dump of advice

A strong prompt is:

Apply supabase-postgres-best-practices and return the top 3 changes by expected impact, with exact SQL and verification steps.

That produces better output than “review everything,” because the repository itself is organized by impact and category priority.

Force tradeoff-aware recommendations

Ask the model to include:

  • expected read benefit
  • write overhead
  • storage cost
  • migration risk
  • operational caveats

This matters especially for extra indexes, partitioning, covering indexes, JSONB indexing, and prepared statements.

Common failure modes to watch for

Typical low-quality outputs include:

  • suggesting indexes without checking filter and sort patterns
  • recommending partitioning too early
  • discussing RLS correctness but not RLS performance
  • proposing connection pooling advice without considering your deployment model
  • rewriting SQL without noting how to verify the plan changed

When you see these, narrow the task and point to the matching reference files.

Use the reference filenames inside your prompt

You can improve precision by steering to exact docs, for example:

Use references/query-partial-indexes.md and references/query-composite-indexes.md to decide which index strategy fits this workload.

or

Apply the guidance from references/security-rls-performance.md to these policies and explain any index support they need.

Because the repo is modular, file-targeted prompting often yields better results than invoking the whole skill abstractly.

Iterate after the first answer with verification prompts

After you get an initial answer, follow up with prompts like:

  • “Which recommendation has the best impact-to-risk ratio?”
  • “Show the exact EXPLAIN differences I should expect.”
  • “Revise the index recommendation for a write-heavy workload.”
  • “Rewrite this for cursor pagination instead of offset pagination.”
  • “Check whether the RLS predicate can use an index.”

That second pass is often where the supabase-postgres-best-practices install and usage effort pays off.

Improve output for Database Engineering teams

For team workflows, standardize the prompt template around the fields your reviewers actually need:

  • affected tables
  • current and proposed SQL
  • workload volume
  • latency target
  • existing indexes
  • RLS yes/no
  • deployment model
  • acceptable migration risk

That turns the supabase-postgres-best-practices for Database Engineering workflow into a repeatable review tool instead of an ad hoc assistant.

If you extend the skill yourself

If you contribute internally or upstream, follow the repo’s own pattern from references/_template.md and references/_contributing.md: show the incorrect pattern first, then the corrected SQL, and include quantified impact. That structure is one reason the skill is useful to agents in the first place.

Ratings & Reviews

No ratings yet
Share your review
Sign in to leave a rating and comment for this skill.
G
0/10000
Latest reviews
Saving...