Postgres Patterns
ThibautBaissac/rails_ai_agents
PostgreSQL database patterns for query optimization, schema design, indexing, and security.
A skill your agent uses when writing complex PostgreSQL queries, diagnosing slow queries with EXPLAIN ANALYZE, designing indexes (B-tree, GIN, partial, composite), handling concurrent writes and…
$ npx skills add kid-sid/claude-spellbook --skill postgresql -a claude-codeProject install by default; add -g for ~/.claude/skills/.
$ gh skill install kid-sid/claude-spellbook postgresql --agent claude-codeProject scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).
$ git clone --depth 1 https://github.com/kid-sid/claude-spellbook.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/postgresql .claude/skills/postgresql && rm -rf skills-srcUse ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.
Claude Code skills documentation · loads skills from .claude/skills/
Install the "postgresql" agent skill from https://github.com/kid-sid/claude-spellbook/tree/main/skills/postgresql into .claude/skills/postgresql/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "postgresql", then confirm the skill loads.Claude Code copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$skill-installer install https://github.com/kid-sid/claude-spellbook/tree/main/skills/postgresqlType this inside Codex. $skill-installer <name> installs a curated skill from openai/skills. The installer writes to $CODEX_HOME/skills (default ~/.codex/skills). Restart Codex if the skill does not show up.
$ npx skills add kid-sid/claude-spellbook --skill postgresql -a codexProject install goes to .agents/skills/; add -g for ~/.codex/skills/.
$ gh skill install kid-sid/claude-spellbook postgresql --agent codexProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/kid-sid/claude-spellbook.git skills-src && mkdir -p .agents/skills && cp -r skills-src/skills/postgresql .agents/skills/postgresql && rm -rf skills-srcUse ~/.agents/skills/ instead of .agents/skills for a personal install.
Codex skills documentation · loads skills from .agents/skills/
Install the "postgresql" agent skill from https://github.com/kid-sid/claude-spellbook/tree/main/skills/postgresql into .agents/skills/postgresql/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "postgresql", then confirm the skill loads.Codex copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add kid-sid/claude-spellbook --skill postgresql -a cursorProject install goes to .agents/skills/; add -g for ~/.cursor/skills/.
$ gh skill install kid-sid/claude-spellbook postgresql --agent cursorProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/kid-sid/claude-spellbook.git skills-src && mkdir -p .cursor/skills && cp -r skills-src/skills/postgresql .cursor/skills/postgresql && rm -rf skills-srcUse ~/.cursor/skills/ instead of .cursor/skills for a personal install.
Cursor skills documentation · loads skills from .cursor/skills/, .agents/skills/, .claude/skills/, .codex/skills/
Install the "postgresql" agent skill from https://github.com/kid-sid/claude-spellbook/tree/main/skills/postgresql into .cursor/skills/postgresql/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "postgresql", then confirm the skill loads.Cursor copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gemini skills install https://github.com/kid-sid/claude-spellbook.git --path skills/postgresql--scope user (default) or --scope workspace; --path is the subfolder of the repo that holds the skill; --consent skips the security confirmation prompt.
$ npx skills add kid-sid/claude-spellbook --skill postgresql -a gemini-cliProject install goes to .agents/skills/; add -g for ~/.gemini/skills/.
$ gh skill install kid-sid/claude-spellbook postgresql --agent gemini-cliProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/kid-sid/claude-spellbook.git skills-src && mkdir -p .gemini/skills && cp -r skills-src/skills/postgresql .gemini/skills/postgresql && rm -rf skills-srcUse ~/.gemini/skills/ instead of .gemini/skills for a personal install, then run /skills reload.
Gemini CLI skills documentation · loads skills from .gemini/skills/, .agents/skills/
Install the "postgresql" agent skill from https://github.com/kid-sid/claude-spellbook/tree/main/skills/postgresql into .gemini/skills/postgresql/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "postgresql", then confirm the skill loads.Gemini CLI copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gh skill install kid-sid/claude-spellbook postgresqlInstalls for Copilot at project scope by default; add --scope user for a personal install. Preview a skill first with gh skill preview. Needs GitHub CLI 2.90.0 or later (public preview).
$ npx skills add kid-sid/claude-spellbook --skill postgresql -a github-copilotProject install goes to .agents/skills/; add -g for ~/.copilot/skills/.
$ git clone --depth 1 https://github.com/kid-sid/claude-spellbook.git skills-src && mkdir -p .github/skills && cp -r skills-src/skills/postgresql .github/skills/postgresql && rm -rf skills-srcUse ~/.copilot/skills/ instead of .github/skills for a personal install. Commit .github/skills so cloud agent and code review can use it.
GitHub Copilot skills documentation · loads skills from .github/skills/, .claude/skills/, .agents/skills/
Install the "postgresql" agent skill from https://github.com/kid-sid/claude-spellbook/tree/main/skills/postgresql into .github/skills/postgresql/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "postgresql", then confirm the skill loads.GitHub Copilot copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add kid-sid/claude-spellbook --skill postgresql -a opencodeOpenCode documents no install command of its own. Project install goes to .agents/skills/; add -g for ~/.config/opencode/skills/.
$ gh skill install kid-sid/claude-spellbook postgresql --agent opencodeProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/kid-sid/claude-spellbook.git skills-src && mkdir -p .opencode/skills && cp -r skills-src/skills/postgresql .opencode/skills/postgresql && rm -rf skills-srcUse ~/.config/opencode/skills/ instead of .opencode/skills for a personal install.
OpenCode skills documentation · loads skills from .opencode/skills/, .claude/skills/, .agents/skills/
Install the "postgresql" agent skill from https://github.com/kid-sid/claude-spellbook/tree/main/skills/postgresql into .opencode/skills/postgresql/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "postgresql", then confirm the skill loads.OpenCode copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
postgresqlA skill your agent uses when writing complex PostgreSQL queries, diagnosing slow queries with EXPLAIN ANALYZE, designing indexes (B-tree, GIN, partial, composite), handling concurrent writes and…
Postgresql is an agent skill from kid-sid/claude-spellbook. Use when writing complex PostgreSQL queries, diagnosing slow queries with EXPLAIN ANALYZE, designing indexes (B-tree, GIN, partial, composite), handling concurrent writes and lock contention, or running safe live ALTER TABLE on large tables. For schema design, normalization, or relationship modelling, use database-design.
Its SKILL.md is about 3.7k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.
It sits in Databases, covering Database schema design and Query optimization. It works with PostgreSQL. The repository describes itself as: A curated collection of skills, prompts, and workflows that extend Claude's capabilities — your personal grimoire for AI-powered development. The licence is MIT.
Read from SKILL.md and the folder at commit a7c2ac9. It shows what the files ask for, not the result of running them.
Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.
From allowed-tools in the SKILL.md frontmatter.
No scripts in the folder and no shell commands in SKILL.md (its code samples are sql).
From the folder's file list and the shell code blocks in SKILL.md.
No URLs in SKILL.md.
From URLs in SKILL.md, links to its own repository left out.
Names no API keys, tokens, secrets or passwords.
From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.
Postgresql loads about 3.7k tokens when it runs. Until then it costs about 84 tokens; SKILL.md has 488 words of instructions outside code blocks.
Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.
The automated check found no risky patterns in SKILL.md.
Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.
The full file from kid-sid/claude-spellbook at commit a7c2ac9, republished under its MIT licence (© kid-sid). 488 words, ~3,666 tokens.
.claude/skills/postgresql/SKILL.md (or your agent's skills folder).Advanced querying, indexing, and schema design for PostgreSQL 14+.
EXPLAIN ANALYZE outputWindow functions compute values across rows related to the current row — without collapsing them like GROUP BY.
-- ROW_NUMBER: unique rank per partition
SELECT
user_id,
order_id,
total,
ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY created_at DESC) AS rn
FROM orders;
-- Get each user's latest order
SELECT * FROM (
SELECT *, ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY created_at DESC) AS rn
FROM orders
) ranked
WHERE rn = 1;
-- RANK vs DENSE_RANK vs ROW_NUMBER
-- RANK: 1,2,2,4 (gaps after tie)
-- DENSE_RANK: 1,2,2,3 (no gaps)
-- ROW_NUMBER: 1,2,3,4 (always unique)
-- Running total
SELECT
date,
amount,
SUM(amount) OVER (ORDER BY date ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS running_total
FROM transactions;
-- Moving average (last 7 days)
SELECT
date,
value,
AVG(value) OVER (ORDER BY date ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS ma7
FROM metrics;
-- LAG/LEAD: access previous/next row
SELECT
date,
revenue,
LAG(revenue) OVER (ORDER BY date) AS prev_revenue,
LEAD(revenue) OVER (ORDER BY date) AS next_revenue,
revenue - LAG(revenue) OVER (ORDER BY date) AS day_over_day
FROM daily_revenue;
-- NTILE: divide rows into buckets
SELECT user_id, spend,
NTILE(4) OVER (ORDER BY spend DESC) AS quartile -- 1=top 25%
FROM user_spend;-- Basic CTE — improves readability, reuse within query
WITH active_users AS (
SELECT id, name, email
FROM users
WHERE status = 'active' AND last_login > NOW() - INTERVAL '30 days'
),
user_orders AS (
SELECT user_id, COUNT(*) AS order_count, SUM(total) AS lifetime_value
FROM orders
WHERE status = 'completed'
GROUP BY user_id
)
SELECT
u.name,
u.email,
COALESCE(o.order_count, 0) AS orders,
COALESCE(o.lifetime_value, 0) AS ltv
FROM active_users u
LEFT JOIN user_orders o ON u.id = o.user_id
ORDER BY o.lifetime_value DESC NULLS LAST;
-- Recursive CTE — hierarchies, trees, paths
WITH RECURSIVE category_tree AS (
-- Anchor: start from roots
SELECT id, name, parent_id, 0 AS depth, ARRAY[id] AS path
FROM categories
WHERE parent_id IS NULL
UNION ALL
-- Recursive: join children
SELECT c.id, c.name, c.parent_id, ct.depth + 1, ct.path || c.id
FROM categories c
INNER JOIN category_tree ct ON c.parent_id = ct.id
)
SELECT * FROM category_tree ORDER BY path;
-- Writable CTEs (INSERT/UPDATE/DELETE in CTE)
WITH deleted_sessions AS (
DELETE FROM sessions
WHERE expires_at < NOW()
RETURNING user_id, session_id
)
INSERT INTO audit_log (user_id, action, metadata)
SELECT user_id, 'session_expired', jsonb_build_object('session_id', session_id)
FROM deleted_sessions;JSONB stores JSON as binary — indexable and queryable.
-- Schema
CREATE TABLE events (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
type TEXT NOT NULL,
payload JSONB NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- Query operators
SELECT payload->>'email' FROM users; -- text (->>' extracts as text)
SELECT payload->'address' FROM users; -- JSONB subtree
SELECT payload#>>'{address,city}' FROM users; -- nested path as text
SELECT payload#>'{address}' FROM users; -- nested path as JSONB
-- Filter on JSONB fields
SELECT * FROM events WHERE payload->>'type' = 'purchase';
SELECT * FROM events WHERE (payload->>'amount')::numeric > 100;
SELECT * FROM events WHERE payload @> '{"status": "active"}'; -- contains
SELECT * FROM events WHERE payload ? 'discount_code'; -- key exists
SELECT * FROM events WHERE payload ?| ARRAY['tag1', 'tag2']; -- any key exists
SELECT * FROM events WHERE payload ?& ARRAY['tag1', 'tag2']; -- all keys exist
-- Update JSONB
UPDATE users
SET metadata = jsonb_set(metadata, '{last_login}', to_jsonb(NOW()))
WHERE id = '123';
-- Remove key
UPDATE users SET metadata = metadata - 'temp_token' WHERE id = '123';
-- Aggregate into JSONB
SELECT jsonb_agg(row_to_json(u)) FROM users u WHERE active;
SELECT jsonb_object_agg(key, value) FROM settings;
-- Unnest JSONB array
SELECT elem->>'name' FROM products, jsonb_array_elements(tags) AS elem;CREATE INDEX idx_orders_user_id ON orders(user_id);
CREATE INDEX idx_orders_created_at ON orders(created_at DESC);
-- Composite: order matters — put equality columns first, range last
CREATE INDEX idx_orders_user_status_date ON orders(user_id, status, created_at);
-- This index helps: WHERE user_id = ? AND status = ? AND created_at > ?
-- This index helps: WHERE user_id = ? AND status = ?
-- This index doesn't help much: WHERE status = ? AND created_at > ? (skipped user_id)-- Index only active orders — much smaller than full index
CREATE INDEX idx_active_orders ON orders(user_id, created_at)
WHERE status = 'active';
-- Index only non-null values
CREATE INDEX idx_users_stripe_id ON users(stripe_customer_id)
WHERE stripe_customer_id IS NOT NULL;-- Query: SELECT status, total FROM orders WHERE user_id = ?
-- Without INCLUDE: index lookup + heap fetch for status, total
-- With INCLUDE: index lookup only (index-only scan)
CREATE INDEX idx_orders_user_covering ON orders(user_id) INCLUDE (status, total);-- JSONB containment queries (@>, ?)
CREATE INDEX idx_events_payload ON events USING GIN (payload);
-- Full-text search
CREATE INDEX idx_articles_tsv ON articles USING GIN (
to_tsvector('english', title || ' ' || body)
);-- Query: WHERE lower(email) = ?
CREATE INDEX idx_users_email_lower ON users (lower(email));
-- Query: WHERE DATE(created_at) = ?
CREATE INDEX idx_orders_date ON orders (DATE(created_at));EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT) SELECT ...;Key things to look for:
-- GOOD: index scan
Index Scan using idx_orders_user_id on orders (cost=0.43..8.45 rows=1)
Index Cond: (user_id = '123')
Actual Rows: 1, Loops: 1
-- BAD: sequential scan on large table
Seq Scan on orders (cost=0.00..45000.00 rows=1000000) ← missing index
Filter: (user_id = '123')
Rows Removed by Filter: 999999
-- BAD: nested loop with many iterations
Nested Loop (rows=10000)
-> Seq Scan on orders ← no index on join column
-> Index Scan using ...
-- Check Buffers output for cache hit ratio
Buffers: shared hit=95 read=5 ← 95% from cache (good)
Buffers: shared hit=10 read=990 ← mostly disk reads (bad — consider index or caching)Workflow: run EXPLAIN ANALYZE, look for Seq Scan on large tables and Rows Removed by Filter ratios. Add index on the filter/join column, re-check.
-- Explicit transaction
BEGIN;
UPDATE accounts SET balance = balance - 100 WHERE id = 'A';
UPDATE accounts SET balance = balance + 100 WHERE id = 'B';
COMMIT; -- or ROLLBACK;
-- SELECT FOR UPDATE — lock rows to prevent concurrent modification
BEGIN;
SELECT * FROM inventory WHERE product_id = '123' FOR UPDATE;
-- Other transactions block here until we COMMIT
UPDATE inventory SET quantity = quantity - 1 WHERE product_id = '123';
COMMIT;
-- SELECT FOR UPDATE SKIP LOCKED — skip locked rows (job queue pattern)
SELECT * FROM jobs
WHERE status = 'pending'
ORDER BY created_at
LIMIT 1
FOR UPDATE SKIP LOCKED;
-- Isolation levels
SET TRANSACTION ISOLATION LEVEL READ COMMITTED; -- default
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ; -- no phantom reads within tx
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; -- full serialization (slowest)
-- Advisory locks — application-level named locks
SELECT pg_advisory_lock(12345); -- session lock
SELECT pg_advisory_xact_lock(12345); -- transaction lock (auto-released on commit)-- Insert or ignore
INSERT INTO user_preferences (user_id, key, value)
VALUES ('123', 'theme', 'dark')
ON CONFLICT (user_id, key) DO NOTHING;
-- Insert or update
INSERT INTO user_preferences (user_id, key, value, updated_at)
VALUES ('123', 'theme', 'dark', NOW())
ON CONFLICT (user_id, key)
DO UPDATE SET
value = EXCLUDED.value,
updated_at = EXCLUDED.updated_at;
-- Conditional upsert — only update if new value is newer
ON CONFLICT (id) DO UPDATE SET
value = EXCLUDED.value
WHERE user_preferences.updated_at < EXCLUDED.updated_at;LATERAL lets a subquery reference columns from tables to its left — like a correlated subquery but returning multiple rows.
-- Latest 3 orders per user
SELECT u.name, o.order_id, o.total
FROM users u
CROSS JOIN LATERAL (
SELECT order_id, total
FROM orders
WHERE user_id = u.id -- references u from outer query
ORDER BY created_at DESC
LIMIT 3
) o;
-- Useful with functions that return sets
SELECT u.id, tags.tag
FROM users u
CROSS JOIN LATERAL jsonb_array_elements_text(u.tags) AS tags(tag);-- tsvector: preprocessed searchable document
-- tsquery: search query with operators
-- Create a generated column (auto-updated)
ALTER TABLE articles ADD COLUMN search_vector tsvector
GENERATED ALWAYS AS (
to_tsvector('english', coalesce(title,'') || ' ' || coalesce(body,''))
) STORED;
CREATE INDEX idx_articles_search ON articles USING GIN (search_vector);
-- Search
SELECT title, ts_rank(search_vector, query) AS rank
FROM articles, to_tsquery('english', 'postgres & indexing') query
WHERE search_vector @@ query
ORDER BY rank DESC
LIMIT 10;
-- Highlight matching terms
SELECT ts_headline('english', body, to_tsquery('postgres & indexing'),
'StartSel=<mark>, StopSel=</mark>, MaxFragments=2'
) FROM articles;
-- Phrase search (words in order)
SELECT * FROM articles
WHERE search_vector @@ phraseto_tsquery('english', 'full text search');-- Safe for large tables (doesn't lock):
-- 1. Add nullable column first (no default needed, no lock)
ALTER TABLE orders ADD COLUMN shipped_at TIMESTAMPTZ;
-- 2. Backfill in batches (avoid one giant UPDATE that locks)
UPDATE orders SET shipped_at = completed_at
WHERE id IN (SELECT id FROM orders WHERE shipped_at IS NULL LIMIT 10000);
-- Repeat until done, or use pg_cron / application loop
-- 3. Add constraint after backfill
ALTER TABLE orders ALTER COLUMN shipped_at SET NOT NULL;
-- Add index concurrently — no table lock
CREATE INDEX CONCURRENTLY idx_orders_shipped_at ON orders(shipped_at);
-- Drop index concurrently
DROP INDEX CONCURRENTLY idx_old_index;
-- Rename column (instant)
ALTER TABLE orders RENAME COLUMN old_name TO new_name;-- Date/time
NOW() -- current timestamp with timezone
CURRENT_DATE -- today as date
DATE_TRUNC('week', created_at) -- truncate to week start
created_at + INTERVAL '7 days' -- date arithmetic
EXTRACT(EPOCH FROM duration) -- seconds as number
-- String
COALESCE(field, 'default') -- first non-null
NULLIF(field, '') -- null if empty string
CONCAT_WS(', ', a, b, c) -- join with separator, skips nulls
REGEXP_REPLACE(text, pattern, replacement, 'g')
LEFT(text, 100) -- first 100 chars
-- Array
ARRAY_AGG(id ORDER BY created_at) -- aggregate into array
UNNEST(tags) -- expand array to rows
array_length(tags, 1) -- length of 1-dimensional array
-- UUID
gen_random_uuid() -- generate UUID v4 (pg 13+)child(parent_id) that appears in a JOIN or WHERE needs a manual CREATE INDEX, or every lookup is a sequential scanCREATE INDEX without CONCURRENTLY on a live table — plain CREATE INDEX acquires a full table lock and blocks all writes for the duration; always use CREATE INDEX CONCURRENTLY in production migrationsUPDATE to backfill a new column — UPDATE orders SET shipped_at = ... on millions of rows locks the table and blocks production traffic; backfill in batches of 10–50k rows via a loop or pg_cronEXPLAIN without ANALYZE and BUFFERS — EXPLAIN shows estimated costs only; EXPLAIN (ANALYZE, BUFFERS) shows actual row counts, actual time, and cache hit ratios — always use both flags when diagnosing performanceSELECT * on large tables in joins — selecting all columns brings unnecessary data from disk and prevents index-only scans; always project only the columns you needJOIN or a single IN query with application-side groupingNOT IN with a subquery that can return NULLs — if the subquery returns any NULL, NOT IN returns no rows at all due to three-valued logic; use NOT EXISTS or LEFT JOIN ... WHERE right.id IS NULL insteadCREATE INDEX ON child(parent_id))EXPLAIN ANALYZE run on any query returning > 10k rowsWHERE conditionsCREATE INDEX CONCURRENTLY, batched UPDATE) for large tablesON CONFLICT used for upsert instead of SELECT then INSERT/UPDATEFOR UPDATE SKIP LOCKED for queue patterns instead of application-level locking@> or ? operators© kid-sid, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file
Just SKILL.md in skills/postgresql of kid-sid/claude-spellbook.
Open the folder on GitHubat commit a7c2ac9
Postgresql next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.
| Skill | Stars | Used in | Tokens | Auto-check | Licence | Repo updated |
|---|---|---|---|---|---|---|
| Postgresql this skillkid-sid/claude-spellbook | 189 | — | ~3.7k | Automated safety check: Pass | MIT | |
| Postgres PatternsThibautBaissac/rails_ai_agents | 665 | 7 repos | ~922 | Automated safety check: Pass | MIT | |
| Supabase Postgres Best Practicessupabase/agent-skills | 2.7k | 24 repos | ~808 | Automated safety check: Pass | MIT | |
| DB SculptorEliasOulkadi/shokunin | 114 | — | ~3.1k | Automated safety check: Notes | MIT | |
| Database Domain Specialistmodu-ai/moai-adk | 1.2k | — | ~2.8k | Automated safety check: Pass | Apache-2.0 | |
| SQL ProJeffallan/claude-skills | 12k | — | ~1.3k | Automated safety check: Pass | MIT |
ThibautBaissac/rails_ai_agents
PostgreSQL database patterns for query optimization, schema design, indexing, and security.
supabase/agent-skills
Gives the agent Postgres rules to consult before writing or changing tables, queries, indexes, RLS policies or migrations, and when diagnosing slow queries.
EliasOulkadi/shokunin
Design database schemas with Prisma/Drizzle, PostgreSQL index strategy (B-tree, GIN, GiST, BRIN, Hash), query optimization (EXPLAIN ANALYZE), migration safety (expand/contract, zero-downtime), and…
modu-ai/moai-adk
Database guidance for PostgreSQL, MongoDB, Redis and Oracle plus Neon, Supabase and Firestore: schema design, indexing, query tuning and cloud database choice.
Jeffallan/claude-skills
Optimizes SQL queries and designs schemas using CTEs, window functions, covering indexes and EXPLAIN ANALYZE, with notes on dialect differences between major databases.
rand/cc-polymath
Automatically discover database skills when working with SQL, PostgreSQL, MongoDB, Redis, database schema design, query optimization, migrations, connection pooling, ORMs, or database selection.
kid-sid/claude-spellbook
A skill your agent uses when building or reviewing UI components for keyboard and screen reader compatibility, adding ARIA to custom widgets, auditing a page for WCAG AA conformance, or preparing…
kid-sid/claude-spellbook
A skill your agent uses when building, wiring, or debugging an Agentex agent — choosing agent type, configuring acp.py and manifest.yaml, using adk.messages or adk.state, or resolving…
kid-sid/claude-spellbook
A skill your agent uses when building production LLM applications — designing RAG pipelines, choosing vector databases, implementing agent orchestration, optimizing cost, or adding AI safety…
kid-sid/claude-spellbook
A skill your agent uses when building or refactoring Angular applications — choosing between signals, RxJS, and NgRx for state, configuring routing with guards and lazy loading, optimizing change…
kid-sid/claude-spellbook
A skill your agent uses when designing new REST endpoints, reviewing an existing API contract, adding pagination or filtering, planning a versioning strategy, or building a public or partner-facing…
kid-sid/claude-spellbook
A skill your agent uses when implementing login flows, issuing or validating JWTs, setting up OAuth2/OIDC with a provider, designing role-based or attribute-based access control, securing API…
Works with
Categories
A skill your agent uses when writing complex PostgreSQL queries, diagnosing slow queries with EXPLAIN ANALYZE, designing indexes (B-tree, GIN, partial, composite), handling concurrent writes and…. Postgresql is an agent skill from kid-sid/claude-spellbook. Use when writing complex PostgreSQL queries, diagnosing slow queries with EXPLAIN ANALYZE, designing indexes (B-tree, GIN, partial, composite), handling concurrent writes and lock contention, or running safe live ALTER TABLE on large tables.
Postgresql fits situations like: writing complex PostgreSQL queries; diagnosing slow queries with EXPLAIN ANALYZE; designing indexes (B-tree; handling concurrent writes and lock contention.
Run `npx skills add kid-sid/claude-spellbook --skill postgresql -a claude-code`. Or copy the skill folder (skills/postgresql in kid-sid/claude-spellbook) into .claude/skills/postgresql in your project. Claude Code loads it when a task matches its description.
Run `npx skills add kid-sid/claude-spellbook --skill postgresql -a codex`. Or copy the skill folder (skills/postgresql in kid-sid/claude-spellbook) into .agents/skills/postgresql in your project. Codex loads it when a task matches its description.
Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add kid-sid/claude-spellbook --skill postgresql -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/postgresql, .gemini/skills/postgresql, .github/skills/postgresql and .opencode/skills/postgresql in your project.
SKILL.md names no scripts, command-line tools or credentials: Postgresql is instructions for the agent only.
SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.
Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.
Postgresql is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.
About 3.7k tokens (SKILL.md is roughly 15k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.
Skills that share tags, products or a category with Postgresql: Postgres Patterns (ThibautBaissac/rails_ai_agents, 665 stars), Supabase Postgres Best Practices (supabase/agent-skills, 2.7k stars), DB Sculptor (EliasOulkadi/shokunin, 114 stars) and Database Domain Specialist (modu-ai/moai-adk, 1.2k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.
kid-sid (a GitHub user) maintains it in kid-sid/claude-spellbook, which has 189 GitHub stars. The repository holds 52 skills in this directory. The repository was last updated on August 5, 2026.
Source: kid-sid/claude-spellbook on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.