Communitygithub.com

Supabase Postgres 最佳實踐

由 Supabase 維護的 Postgres 最佳實踐,適用於任何運行 Postgres 的環境。在編寫或修改任何與 Postgres 資料庫相關的內容前,請先載入此技能:建立或修改表格與欄位(包括選擇欄位類型)、綱要設計、遷移與宣告式綱要檔案、RLS 政策與其驗證測試、索引、觸發器、資料庫函數、佇列與排程任務(pg_cron、pgmq)、向量/語意搜尋(pgvector),以及還原備份(pg_restore)或匯入資料。在診斷慢查詢、高 CPU、逾時、EXPLAIN 計畫、連線耗盡、鎖定、資料膨脹,或發現錯誤使用者/租戶可見的資料列時,也應載入此技能。這不僅僅是一份效能指南——即使只是一個欄位變更或單一查詢,綱要、遷移、安全性和 SQL 撰寫任務也同樣需要這些規則。

Supabase Postgres 最佳實踐 是什麼?

這份由 Supabase 維護的綜合性效能最佳化指南,為 Postgres 資料庫提供了 8 大類別的規則,並按影響程度排列優先級。它涵蓋了從查詢效能、連線管理、安全性與 RLS,到綱要設計、並發與鎖定、資料存取模式、監控與診斷,以及進階功能。此技能旨在指導 AI Agent 自動化查詢最佳化和綱要設計,適用於任何執行 Postgres 的環境(不僅限於 Supabase)。使用方式很簡單:在執行任何資料庫變更(如建立表格、新增索引、編寫 RLS 政策)或診斷效能問題時,優先參考此指南中的具體規則文件(例如 `references/query-missing-indexes.md`),其中包含了錯誤與正確的 SQL 範例以及 EXPLAIN 輸出,幫助開發者避免常見陷阱。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Audomsub/Tiktok-Shop/tree/HEAD/.agents/skills/supabase-postgres-best-practices

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Supabase Postgres 最佳實踐 是做什麼的?

由 Supabase 維護的全面效能最佳化指南,適用於 Postgres。包含 8 大類別的規則,按影響程度排列優先級,以引導自動化查詢最佳化與綱要設計。

何時應用

在以下情況參考這些指南:

  • 撰寫 SQL 查詢或設計綱要時
  • 實作索引或查詢最佳化時
  • 檢視資料庫效能問題時
  • 設定連線池或擴展時
  • 針對 Postgres 特有功能進行最佳化時
  • 處理資料列級安全性(RLS)時

規則類別(依優先級排列)

優先級類別影響前綴
1查詢效能關鍵query-
2連線管理關鍵conn-
3安全性與 RLS關鍵security-
4綱要設計高schema-
5並發與鎖定中高lock-
6資料存取模式中data-
7監控與診斷低中monitor-
8進階功能低advanced-

如何使用

閱讀個別規則檔案以取得詳細說明與 SQL 範例:

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

每個規則檔案包含:

  • 為何重要的簡要說明
  • 錯誤的 SQL 範例與解釋
  • 正確的 SQL 範例與解釋
  • 選擇性的 EXPLAIN 輸出或指標
  • 額外的上下文與參考資料
  • Supabase 特定說明(若適用)

參考資料

Individual skills in this repo

This repo contains 6 individual skills — each has its own dedicated page.

Audomsub/Tiktok-Shop

Review the changes since a fixed point (commit, branch, tag, or merge-base) along two axes: Standards (does the code follow this repo's documented coding standards?) and Spec (does the code match what the originating issue/spec asked for?). Runs both reviews in parallel sub-agents and reports them side by side. Use when the user wants to review a branch, a PR, work-in-progress changes, or asks to \"review since X\".

Audomsub/Tiktok-Shop

A relentless interview to sharpen a plan or design, which also creates docs (ADR's and glossary) as we go.

Audomsub/Tiktok-Shop

Implement a piece of work based on a spec or set of tickets.

Audomsub/Tiktok-Shop

Use when doing ANY task involving Supabase. Triggers: Supabase products (Database, Auth, Edge Functions, Realtime, Storage, Vectors, Cron, Queues); client libraries and SSR integrations (supabase-js, @supabase/ssr) in Next.js, React, SvelteKit, Astro, Remix; auth issues (login, logout, sessions, JWT, cookies, getSession, getUser, getClaims, RLS); Supabase CLI or MCP server; schema changes, migrations, declarative schemas, security audits, Postgres extensions (pg_graphql, pg_cron, pg_vector); debugging and troubleshooting errors or unexpected behavior on Supabase projects (HTTP errors, Postgres errors, RLS surprises, permission denied, schema cache issues, timeouts, Edge Function crashes, Realtime drops, Storage failures) and reading or querying logs (Logs Explorer, ClickHouse).

Audomsub/Tiktok-Shop

Turn the current conversation into a spec and publish it to the project issue tracker: no interview, just synthesis of what you've already discussed.

Audomsub/Tiktok-Shop

Break a plan, spec, or the current conversation into a set of tracer-bullet tickets, each declaring its blocking edges, published to the configured tracker (edges as text in one file per ticket locally, or native blocking links on a real tracker).

相關技能