supabase-postgres-best-practices

supabase-postgres-best-practices is a skill for Claude Code, Codex from Morningstar202604/awesome-skillkit. It costs 71 tokens per session (1,238 once invoked), scanned A, original, Apache-2.0.

A set of engineering guidelines for Supabase’s managed PostgreSQL database service. It covers table design, indexes, migrations, access rules, connection pooling, and query performance.

In plain words
What is it for?
Use it when designing tables, writing migrations, adding indexes, setting row-level security, investigating slow queries, or planning partitions and cleanup.
Why use it?
It helps avoid slow queries, unsafe data access, overloaded database connections, and database changes made without a repeatable record.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it when designing tables, writing migrations, adding indexes, setting row-level security, investigating slow queries, or planning partitions and cleanup.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/morningstar202604/awesome-skillkit/supabase-postgres-best-practices
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add Morningstar202604/awesome-skillkit --skill supabase-postgres-best-practices
Clone the repo
git clone --depth 1 https://github.com/Morningstar202604/awesome-skillkit

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for supabase-postgres-best-practices

README.md
[![agentmods](https://agentmods.dev/badge/skills/morningstar202604/awesome-skillkit/supabase-postgres-best-practices/github.svg)](https://agentmods.dev/skills/morningstar202604/awesome-skillkit/supabase-postgres-best-practices)
Your own site
<a href="https://agentmods.dev/skills/morningstar202604/awesome-skillkit/supabase-postgres-best-practices"><img src="https://agentmods.dev/badge/skills/morningstar202604/awesome-skillkit/supabase-postgres-best-practices/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for supabase-postgres-best-practices

Your own site · 80×15
<a href="https://agentmods.dev/skills/morningstar202604/awesome-skillkit/supabase-postgres-best-practices"><img src="https://agentmods.dev/badge/skills/morningstar202604/awesome-skillkit/supabase-postgres-best-practices.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 71 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,238 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00071 $0.01238
Opus 5.5 $0.00028 $0.00495
Sonnet 5.5 $0.00014 $0.00248
Haiku 4.5 $0.00007 $0.00124

Measured 2mo ago against content hash c9dc0420408d, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

supabase-postgres-best-practices scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

expert-teams/teams/fullstack-web-team/skills/supabase-postgres-best-practices/SKILL.md · 76 lines

How it starts

The opening of the file, as written. The whole thing — 76 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Supabase / Postgres 最佳实践

本 skill 面向 fullstack-database-engineer,聚焦 Supabase 托管 Postgres 的日常建模、性能与安全。

何时使用

  • 新建表/迁移、加索引、写 RLS 策略;
  • 慢查询、连接打满、RLS 拖慢查询;
  • 评估分区、约束、vacuum、pg_stat_statements 调优。

核心原则

  1. 迁移即代码:所有 DDL 走 migration 工具(Supabase CLI / Flyway),禁止在控制台手改结构。
  2. 先看计划再建索引:用 EXPLAIN (ANALYZE, BUFFERS) 确认全表扫描,再决定索引。
  3. RLS 默认开:public 表必须开 Row Level Security,不依赖"前端不发请求"。
  4. 连接池:Supabase 用 pgbouncer 事务池,应用连 pooler 端口,不直连 5432。
  5. 约束兜底:外键、check、unique、not null 在数据库层,不只靠应用。

索引实践

  • 覆盖高频 WHERE/JOIN/ORDER BY:单列 btree 起步,多列按等值在前、排序在后排列。
  • 部分索引:CREATE INDEX ON orders(user_id) WHERE status = 'pending'; 减小索引体积。
  • 表达式索引:对 lower(email)、(json->>'field') 建表达式索引,不要对整列建。
  • 不要过度索引:每个索引都拖慢写入,先量测再加。
  • 查看未用索引:SELECT * FROM pg_stat_user_indexes WHERE idx_scan = 0;

RLS 模板

alter table public.profiles enable row level security;

create policy "用户只能看自己的资料"
  on public.profiles for select
  using (auth.uid() = id);

create policy "用户只能更新自己的资料"
  on public.profiles for update
  using (auth.uid() = id)
  with check (auth.uid() = id);
  • Service key 绕过 RLS,绝不能下发到浏览器/客户端。
  • RLS 策略里避免逐行子查询,必要时把关联表也索引好。

慢查询排查流程

  1. 开 pg_stat_statements(Supabase 已默认启用)。
  2. 按 mean_exec_time * calls 找总成本最高的查询。
  3. 对目标 SQL 跑 EXPLAIN (ANALYZE, BUFFERS),看 Seq Scan / 行数估算偏差。
  4. 加索引或改写 SQL(避免 select *、避免在索引列上包函数)。
  5. 复核是否命中索引,观察 pg_stat_statements 改善。

连接与迁移

  • 应用用 Supabase 连接池(port 6543,transaction mode),长连接/事务批量才用直接连接。
  • 迁移大表加列/加默认值用在线方式(ADD COLUMN ... DEFAULT ... 在 PG11+ 是元数据操作;重写表要锁表,避开高峰)。
  • 大表分区:按时间 range(按月/周),老分区 detach 归档。

清单(交付前逐项过)

  • 新表默认 enable row level security,并写好 select/insert/update 策略。
  • 外键、not null、unique、check 约束齐全。
  • 高频查询有 EXPLAIN ANALYZE 证据,索引不是拍脑袋加的。
  • Service key 只在服务端使用,前端只用 anon key + RLS。
  • 所有 DDL 进 migration 文件,可回滚、可审查。
  • 连接走 pooler,未在应用里维持大量长连接。
  • 大表/归档策略已评估分区或 detach。
  • 敏感列(密码 hash、PII)有注释与脱敏约定。

易错点

  • 在浏览器用 service_role key:等于把数据库管理员钥匙交给用户,RLS 直接失效。
  • 索引列上包函数:WHERE lower(email) = ... 普通索引失效,要建表达式索引。
  • RLS 策略里 N+1 子查询:每行都查一次,列表接口直接慢百倍;把条件改成 join 或把权限冗余进本表。
  • 过度索引:写入密集表堆了七八个索引,insert/update 变慢;定期清未用索引。
  • 迁移在生产手工执行:环境漂移,必须 CLI migration 可重复。
  • 忘记 vacuum 统计信息:分析信息过旧导致计划走错,autovacuum 正常运行即可,别手动关。

Read the full file on GitHub · 76 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2mo ago First seen · 76 lines · 71 tokens per session scan A c9dc0420408d

Subscribe to this mod's changes

supabase-postgres-best-practices is a skill published in the GitHub repository Morningstar202604/awesome-skillkit (0 stars, last pushed 2mo ago), licensed Apache-2.0. It adds 71 tokens to every session and 1,238 once invoked, about $0.0003 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-27.

Related

supabase-postgres-best-practices compared with skills from other repositories

supabase-postgres-best-practices next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
supabase-postgres-best-practicesMorningstar202604/awesome-skillkitSkill02mo agoApache-2.0A71Claude Code, Codex
postgres-patternsaffaan-m/ECCSkill313k7d agoMITA45Claude Code, Kiro
postgres-migrationlangwatch/langwatchSkill5.1ktodayApache-2.0A294Claude Code
haven-dblangwatch/langwatchSkill5.1ktodayApache-2.0A116Claude Code
alembic-migrationvstorm-co/full-stack-ai-agent-templateSkill2.0k3d agoMITA56Claude Code
postgresql-table-designBidingCC/BuildingAISkill1.9k13d agoApache-2.0A31Claude Code, Codex
database-patternsyonatangross/orchestkitSkill312todayMITA32Claude Code