Supabase Postgres Best Practices

作者 supabasec9be0e931b79MIT收錄於 2026年10月8日更新於 2026年10月8日

Postgres best practices maintained by Supabase, for Postgres running anywhere. Load this skill BEFORE writing or changing anything that lives in a Postgres database: creating or altering tables and columns (including choosing column types), schema design, migrations and declarative schema files, RLS policies and the tests that verify them, indexes, triggers, database functions, queues and scheduled jobs (pg_cron, pgmq), vector/semantic search (pgvector), and restoring dumps (pg_restore) or importing data. Also load it when diagnosing slow queries, high CPU, timeouts, EXPLAIN plans, connection exhaustion, locking, bloat, or rows visible to the wrong user or tenant. This is not just a performance guide — schema, migration, security, and SQL authoring tasks need these rules too, even for a one-column change or a single query.

AI 產生的概覽

用於撰寫、審查與最佳化 Postgres 結構、查詢、索引、RLS 與連線的參考規則。

功能
提供依優先順序排列的 Postgres 最佳實務規則,涵蓋八個類別:查詢效能、連線管理、安全性與 RLS、結構設計、並行與鎖定、資料存取模式、監控與診斷,以及進階功能。每個規則檔案會說明該主題為何重要,並列出錯誤與正確的 SQL 範例,可選附上 EXPLAIN 輸出與指標。它只是純說明性參考,不會產生任何檔案或指令碼。
適用情境
在撰寫或修改 Postgres 資料庫中的任何內容之前載入,包括資料表、欄位、移轉、RLS 原則、索引、觸發程序、函式、佇列、排程工作、向量搜尋或資料匯入。也適用於診斷慢查詢、高 CPU、逾時、EXPLAIN 計畫、連線耗盡、鎖定、膨脹,或資料列被錯誤的使用者或租用戶看見等問題。
執行需求
不需要任何工具、套件或認證;它只是文件,不附帶指令碼。不需要網路存取,但文件中包含指向外部 Postgres 與 Supabase 文件的連結。

Supabase Postgres Best Practices

Comprehensive performance optimization guide for Postgres, maintained by Supabase. Contains rules across 8 categories, prioritized by impact to guide automated query optimization and schema design.

When to Apply

Reference these guidelines when:

  • Writing SQL queries or designing schemas
  • Implementing indexes or query optimization
  • Reviewing database performance issues
  • Configuring connection pooling or scaling
  • Optimizing for Postgres-specific features
  • Working with Row-Level Security (RLS)

Rule Categories by Priority

PriorityCategoryImpactPrefix
1Query PerformanceCRITICALquery-
2Connection ManagementCRITICALconn-
3Security & RLSCRITICALsecurity-
4Schema DesignHIGHschema-
5Concurrency & LockingMEDIUM-HIGHlock-
6Data Access PatternsMEDIUMdata-
7Monitoring & DiagnosticsLOW-MEDIUMmonitor-
8Advanced FeaturesLOWadvanced-

How to Use

Read individual rule files for detailed explanations and SQL examples:

references/query-missing-indexes.mdreferences/query-partial-indexes.mdreferences/_sections.md

Each rule file contains:

  • Brief explanation of why it matters
  • Incorrect SQL example with explanation
  • Correct SQL example with explanation
  • Optional EXPLAIN output or metrics
  • Additional context and references
  • Supabase-specific notes (when applicable)

References

來源與署名

來源:supabase/agent-skills位於skills/supabase-postgres-best-practices提交c9be0e9

授權條款: MIT

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架