postgres-patterns

postgres-patterns is a skill for Claude Code from loulanyue/awesome-claude-notes. It costs 28 tokens per session (1,319 once invoked), scanned A, original, MIT.

A PostgreSQL reference for designing database schemas, writing queries, adding indexes, and applying database security rules.

In plain words
What is it for?
Use it when creating SQL or migrations, designing tables, improving query speed, setting up connection pooling, or implementing row-level security.
Why use it?
It helps avoid common database design mistakes and gives guidance when queries are slow or access needs to be restricted.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the awesome-claude-notes plugin — 106 skills, 61 commands, 28 agents shipped together

Good fit Use it when creating SQL or migrations, designing tables, improving query speed…

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/loulanyue/awesome-claude-notes/postgres-patterns
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 loulanyue/awesome-claude-notes --skill postgres-patterns
Clone the repo
git clone --depth 1 https://github.com/loulanyue/awesome-claude-notes

Made for: Claude Code.

Or install awesome-claude-notes, the plugin that ships this one along with the rest of its 106 skills, 61 commands, 28 agents.

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 postgres-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/loulanyue/awesome-claude-notes/postgres-patterns.svg)](https://agentmods.dev/skills/loulanyue/awesome-claude-notes/postgres-patterns)
Your own site
<a href="https://agentmods.dev/skills/loulanyue/awesome-claude-notes/postgres-patterns"><img src="https://agentmods.dev/badge/skills/loulanyue/awesome-claude-notes/postgres-patterns.svg" alt="Measured on agentmods" height="20"></a>
Per session 28 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,319 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.00028 $0.01319
Opus 5 $0.00014 $0.00660
Sonnet 5 $0.00006 $0.00264
Haiku 4.5 $0.00003 $0.00132

Measured 2d ago against content hash df2d82453421, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

postgres-patterns 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 2d 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.

Origin

Copies of this mod

1 near-identical copy found in the catalogue:

docs/ja-JP/skills/postgres-patterns/SKILL.md · 156 lines

How it starts

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

PostgreSQL パターン

PostgreSQLベストプラクティスのクイックリファレンス。詳細なガイダンスについては、database-reviewer エージェントを使用してください。

起動タイミング

  • SQLクエリまたはマイグレーションの作成時
  • データベーススキーマの設計時
  • 低速クエリのトラブルシューティング時
  • Row Level Securityの実装時
  • コネクションプーリングの設定時

クイックリファレンス

インデックスチートシート

クエリパターン インデックスタイプ
WHERE col = value B-tree(デフォルト) CREATE INDEX idx ON t (col)
WHERE col > value B-tree CREATE INDEX idx ON t (col)
WHERE a = x AND b > y 複合 CREATE INDEX idx ON t (a, b)
WHERE jsonb @> '{}' GIN CREATE INDEX idx ON t USING gin (col)
WHERE tsv @@ query GIN CREATE INDEX idx ON t USING gin (col)
時系列範囲 BRIN CREATE INDEX idx ON t USING brin (col)

データタイプクイックリファレンス

用途 正しいタイプ 避けるべき
ID bigint int、ランダムUUID
文字列 text varchar(255)
タイムスタンプ timestamptz timestamp
金額 numeric(10,2) float
フラグ boolean varcharint

一般的なパターン

複合インデックスの順序:

-- 等価列を最初に、次に範囲列
CREATE INDEX idx ON orders (status, created_at);
-- 次の場合に機能: WHERE status = 'pending' AND created_at > '2024-01-01'

カバリングインデックス:

CREATE INDEX idx ON users (email) INCLUDE (name, created_at);
-- SELECT email, name, created_at のテーブル検索を回避

部分インデックス:

CREATE INDEX idx ON users (email) WHERE deleted_at IS NULL;
-- より小さなインデックス、アクティブユーザーのみを含む

RLSポリシー(最適化):

CREATE POLICY policy ON orders
  USING ((SELECT auth.uid()) = user_id);  -- SELECTでラップ!

UPSERT:

INSERT INTO settings (user_id, key, value)
VALUES (123, 'theme', 'dark')
ON CONFLICT (user_id, key)
DO UPDATE SET value = EXCLUDED.value;

カーソルページネーション:

SELECT * FROM products WHERE id > $last_id ORDER BY id LIMIT 20;
-- O(1) vs OFFSET は O(n)

キュー処理:

UPDATE jobs SET status = 'processing'
WHERE id = (
  SELECT id FROM jobs WHERE status = 'pending'
  ORDER BY created_at LIMIT 1
  FOR UPDATE SKIP LOCKED
) RETURNING *;

Read the full file on GitHub · 156 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. 2d ago First seen · 156 lines · 28 tokens per session scan A df2d82453421

Subscribe to this mod's changes

postgres-patterns is a skill published in the GitHub repository loulanyue/awesome-claude-notes (270 stars, last pushed 3d ago), licensed MIT. It adds 28 tokens to every session and 1,319 once invoked, about $0.0001 per session on Opus 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-03.

Related

Other skills, from other repositories

database-expert

Advanced database design and administration for PostgreSQL, MongoDB, and Redis. Use when designing schemas, optimizing queries, managing database performance, or implementing data patterns.

travisjneuman/.claude · 36 tokens

google-analytics

Skill "google-analytics" from VKirill/claude-lane-stack, covering version requirements (may 2026), usage, use this skill when, do not use this skill when and purpose.

VKirill/claude-lane-stack · 188 tokens

agent-database-reviewer

PostgreSQL database specialist for query optimization, schema design, security, and performance. Use PROACTIVELY when writing SQL, creating migrations, designing schemas, or troubleshooting database performance. Incorporates Supabase best practices.

KunanonJ/ai-skills-hub · 50 tokens

postgresql

Design a PostgreSQL-specific schema. Covers best-practices, data types, indexing, constraints, performance patterns, and advanced features.

KunanonJ/ai-skills-hub · 29 tokens

postgres-patterns

PostgreSQL database patterns for query optimization, schema design, indexing, and security. Based on Supabase best practices.

shahidshabbir-se/my-pi-setup · 28 tokens

postgres-database-migration

Use this skill for planning, testing, and safely executing PostgreSQL schema migrations — especially when working with production data or shared databases. Trigger when user asks to: Test a schema migration before applying it to production Add, remove, or rename columns safely on a live table Change a column's data…

timescale/pg-aiguide · 220 tokens