buchananwill/ue-claude-scaffold/postgres-schema-indexing

Claude Code and agent skill by buchananwill/ue-claude-scaffold

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

PostgreSQL data types, index strategies, schema constraints, and diagnostic queries. Based on Supabase best practices.

Install

npx vskill@latest install buchananwill/ue-claude-scaffold/postgres-schema-indexing

SKILL.md

The same SKILL.md was published earlier as buchananwill/ue-claude-scaffold/postgres-schema-indexing.

PostgreSQL Schema and Indexing

Data types, index strategies, and schema design for PostgreSQL.

When to Activate

  • Designing database schemas
  • Choosing data types for columns
  • Adding or reviewing indexes
  • Troubleshooting slow queries

Data Type Reference

Use CaseCorrect TypeAvoid
IDsbigint (or UUIDv7)int, random UUID as PK
Stringstextvarchar(255) without reason
Timestampstimestamptztimestamp (no timezone)
Moneynumeric(12,2)float, real, double precision
Flagsbooleanvarchar, int

Index Cheat Sheet

Query PatternIndex TypeExample
WHERE col = valueB-tree (default)CREATE INDEX idx ON t (col)
WHERE col > valueB-treeCREATE INDEX idx ON t (col)
WHERE a = x AND b > yCompositeCREATE INDEX idx ON t (a, b)
WHERE jsonb @> '{}'GINCREATE INDEX idx ON t USING gin (col)
WHERE tsv @@ queryGIN (full-text)CREATE INDEX idx ON t USING gin (col)
Time-series rangesBRINCREATE INDEX idx ON t USING brin (col)

Index Patterns

Composite index order -- equality columns first, then range:

sql
CREATE INDEX idx ON orders (status, created_at);
-- Works for: WHERE status = 'pending' AND created_at > '2024-01-01'

Covering index -- avoids table lookup:

sql
CREATE INDEX idx ON users (email) INCLUDE (name, created_at);

Partial index -- smaller, faster:

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

Schema Constraints

  • Always define PK, FK with ON DELETE behavior, NOT NULL where appropriate, CHECK constraints
  • Use lowercase_snake_case identifiers (no quoted mixed-case)
  • Always index foreign keys -- no exceptions
  • Index columns referenced in RLS policies

Queue Processing Pattern

sql
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 *;

Diagnostic Queries

sql
-- Find unindexed foreign keys
SELECT conrelid::regclass, a.attname
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)
);
-- Find slow queries
SELECT query, mean_exec_time, calls
FROM pg_stat_statements
WHERE mean_exec_time > 100
ORDER BY mean_exec_time DESC;

Anti-Patterns

  • SELECT * in production code
  • Random UUIDs as primary keys (use UUIDv7 or IDENTITY)
  • OFFSET pagination on large tables (use cursor pagination)
  • Unparameterized queries (SQL injection risk)
  • GRANT ALL to application users

Based on Supabase best practices (MIT License)

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
5

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/buchananwill/ue-claude-scaffold/postgres-schema-indexing/badge)](https://verified-skill.com/skills/buchananwill/ue-claude-scaffold/postgres-schema-indexing)

Something wrong with this skill or its page? Tell us.