postgres-patterns

postgres-patterns is a skill for Claude Code from shennawardana23/skillme. It costs 95 tokens per session (2,256 once invoked), scanned A, original, Apache-2.0.

A guide to designing PostgreSQL queries, indexes, data types, and row-level security, which controls which database rows each user can access. It focuses on shaping database structures and queries rather than running migrations.

In plain words
What is it for?
Use it when choosing indexes, improving SQL queries, selecting PostgreSQL types, or designing row-level security.
Why use it?
It helps avoid slow query patterns, unsuitable indexes, and unsafe access rules when designing a PostgreSQL database.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin. Also seen: positional $N argument.

Part of the skillme plugin — 137 skills, 2 commands shipped together

Good fit Use it when choosing indexes, improving SQL queries, selecting PostgreSQL types, or designing row-level security.

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

Made for: Claude Code.

Or install skillme, the plugin that ships this one along with the rest of its 137 skills, 2 commands.

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/shennawardana23/skillme/postgres-patterns/github.svg)](https://agentmods.dev/skills/shennawardana23/skillme/postgres-patterns)
Your own site
<a href="https://agentmods.dev/skills/shennawardana23/skillme/postgres-patterns"><img src="https://agentmods.dev/badge/skills/shennawardana23/skillme/postgres-patterns/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 postgres-patterns

Your own site · 80×15
<a href="https://agentmods.dev/skills/shennawardana23/skillme/postgres-patterns"><img src="https://agentmods.dev/badge/skills/shennawardana23/skillme/postgres-patterns.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 95 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,256 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.00095 $0.02256
Opus 5 $0.00048 $0.01128
Sonnet 5 $0.00019 $0.00451
Haiku 4.5 $0.00010 $0.00226

Measured 6d ago against content hash d1d2d9d480bc, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-09, 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 6d 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.

skills/postgres-patterns/SKILL.md · 214 lines

How it starts

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

PostgreSQL Patterns

This skill is the query- and schema-design layer: how to index a table and shape a query well. For how to ship a schema change safely, see database-migrations. For any table partitioned by hotel_id (most core tables in this organization), the partition-pruning predicate rules in postgres-hotel-partitioning apply on top of everything here — every example below assumes that predicate is already present.

Index selection

Query pattern Index type Example
WHERE col = value B-tree (default) CREATE INDEX idx ON t (col)
WHERE col > value / range B-tree CREATE INDEX idx ON t (col)
WHERE a = x AND b > y Composite, equality columns first CREATE INDEX idx ON t (a, b)
WHERE jsonb_col @> '{}' GIN CREATE INDEX idx ON t USING gin (jsonb_col)
Full-text tsv @@ query GIN CREATE INDEX idx ON t USING gin (tsv)
Append-only time-series ranges BRIN CREATE INDEX idx ON t USING brin (created_at)

Composite index column order matters: put equality-tested columns first, range-tested columns last, so the index can seek on the equality prefix and then scan the range within it:

-- Serves: WHERE status = 'pending' AND created_at > '2025-01-01'
CREATE INDEX idx_jobs_status_created ON jobs (status, created_at);

Covering index avoids a heap lookup entirely when the query only needs indexed + included columns:

CREATE INDEX idx_users_email ON users (email) INCLUDE (name, created_at);
-- SELECT email, name, created_at FROM users WHERE email = $1 -- index-only scan

Partial index shrinks the index to the subset that's actually queried frequently:

CREATE INDEX idx_users_active ON users (email) WHERE deleted_at IS NULL;

An unindexed foreign key is a common, silent bottleneck (every delete on the parent table triggers a sequential scan of the child to check for references). Find them:

SELECT conrelid::regclass AS table_name, a.attname AS column_name
FROM pg_constraint c
JOIN pg_attribute a ON a.attrelid = c.conrelid AND a.attnum = ANY(c.conkey)
WHERE c.contype = 'f'
  AND NOT EXISTS (
    SELECT 1 FROM pg_index i
    WHERE i.indrelid = c.conrelid AND a.attnum = ANY(i.indkey)
  );

Read the full file on GitHub · 214 lines

Files

What ships with it

1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

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. 6d ago First seen · 214 lines · 95 tokens per session scan A d1d2d9d480bc

Subscribe to this mod's changes

postgres-patterns is a skill published in the GitHub repository shennawardana23/skillme (2 stars, last pushed 12d ago), licensed Apache-2.0. It adds 95 tokens to every session and 2,256 once invoked, about $0.0005 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

postgresql-development-cloudbase

Use when building, debugging, or evaluating CloudBase PostgreSQL / CloudBase PG / PG mode apps, including Postgres schema setup, queryPgDatabase/managePgDatabase, JS SDK v3 app.rdb() CRUD/RPC, PG HTTP API fallback, RLS-style permissions, username-password auth, and Web CMS/admin CRUD flows backed by CloudBase PG.

sutchan/Agent-Skills-Hub · 77 tokens

timescaledb

MANDATORY when working with time-series data, hypertables, continuous aggregates, or compression - enforces TimescaleDB 2.24.0 best practices including lightning-fast recompression, UUIDv7 continuous aggregates, and Direct Compress.

troykelly/claude-skills · 50 tokens

database-architecture

MANDATORY when designing schemas, writing migrations, creating indexes, or making architectural database decisions - enforces PostgreSQL 18 best practices including AIO, UUIDv7, temporal constraints, and modern indexing strategies.

troykelly/claude-skills · 45 tokens

postgis

MANDATORY when working with geographic data, spatial queries, geometry operations, or location-based features - enforces PostGIS 3.6.1 best practices including STCoverageClean, SFCGAL 3D functions, and bigint topology.

troykelly/claude-skills · 52 tokens

postgres-rls

MANDATORY when touching auth tables, tenant isolation, RLS policies, or multi-tenant database code - enforces Row Level Security best practices and catches common bypass vulnerabilities.

troykelly/claude-skills · 38 tokens

alloydb-basics

Manages clusters, instances, and backups for AlloyDB for PostgreSQL, and integrates with AlloyDB Model Context Protocol (MCP) tools for automated database operations. Use when creating, configuring, or administering AlloyDB databases. Do NOT use for general PostgreSQL instances (e.g. Cloud SQL) or other GCP databases.

google/skills · 72 tokens