skills/database/postgresql/SKILL.md
PostgreSQL specialist focused on schema design, performance tuning, and advanced features. Use for PostgreSQL-specific patterns including JSONB, partitioning, CTEs, window functions, and index types (GIN, GiST, BRIN).
npx skillsauth add simplerick0/com.ackhax.configs postgresqlInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
You are a PostgreSQL specialist focused on schema design, performance tuning, and advanced features.
# Connect
psql -h localhost -U user -d database
# Schema inspection
\dt # List tables
\d table_name # Describe table
\di # List indexes
\df # List functions
# Query analysis
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT) SELECT ...;
# Database size
SELECT pg_size_pretty(pg_database_size('dbname'));
-- Native types
UUID, JSONB, ARRAY, INET, CIDR, MACADDR
TSTZRANGE, DATERANGE, INT4RANGE -- Range types
TSVECTOR, TSQUERY -- Full-text search
-- Example usage
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
email TEXT UNIQUE NOT NULL,
tags TEXT[] DEFAULT '{}',
metadata JSONB DEFAULT '{}',
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- Query JSONB
SELECT * FROM users WHERE metadata->>'role' = 'admin';
SELECT * FROM users WHERE metadata @> '{"active": true}';
-- Index JSONB
CREATE INDEX idx_metadata_gin ON users USING GIN (metadata);
CREATE INDEX idx_metadata_role ON users ((metadata->>'role'));
-- Update JSONB
UPDATE users SET metadata = metadata || '{"verified": true}';
UPDATE users SET metadata = metadata - 'temp_field';
-- B-tree (default, equality and range)
CREATE INDEX idx_email ON users(email);
-- GIN (arrays, JSONB, full-text)
CREATE INDEX idx_tags ON users USING GIN (tags);
-- GiST (geometric, range types, full-text)
CREATE INDEX idx_location ON places USING GIST (coordinates);
-- BRIN (large sequential data)
CREATE INDEX idx_created ON logs USING BRIN (created_at);
-- Partial index
CREATE INDEX idx_active ON users(email) WHERE active = true;
-- Concurrent index (no table lock)
CREATE INDEX CONCURRENTLY idx_name ON users(name);
-- Range partitioning
CREATE TABLE logs (
id BIGSERIAL,
message TEXT,
created_at TIMESTAMPTZ NOT NULL
) PARTITION BY RANGE (created_at);
CREATE TABLE logs_2024_01 PARTITION OF logs
FOR VALUES FROM ('2024-01-01') TO ('2024-02-01');
-- Automatic partition management
-- Use pg_partman extension
-- Recursive CTE
WITH RECURSIVE subordinates AS (
SELECT id, name, manager_id FROM employees WHERE id = 1
UNION ALL
SELECT e.id, e.name, e.manager_id
FROM employees e
JOIN subordinates s ON e.manager_id = s.id
)
SELECT * FROM subordinates;
-- Window functions
SELECT
name,
salary,
AVG(salary) OVER (PARTITION BY department) as dept_avg,
RANK() OVER (ORDER BY salary DESC) as salary_rank
FROM employees;
-- Memory settings (postgresql.conf)
shared_buffers = '256MB' -- 25% of RAM
effective_cache_size = '768MB' -- 75% of RAM
work_mem = '64MB' -- Per-operation memory
maintenance_work_mem = '128MB' -- For VACUUM, CREATE INDEX
-- Connection pooling (use PgBouncer)
max_connections = 100
-- Analyze query plan
EXPLAIN (ANALYZE, BUFFERS) SELECT ...;
-- Update statistics
ANALYZE table_name;
-- Identify slow queries
SELECT * FROM pg_stat_statements ORDER BY total_time DESC LIMIT 10;
-- Vacuum and analyze
VACUUM ANALYZE table_name;
-- Reindex
REINDEX INDEX CONCURRENTLY index_name;
-- Check bloat
SELECT schemaname, tablename,
pg_size_pretty(pg_total_relation_size(schemaname||'.'||tablename))
FROM pg_tables WHERE schemaname = 'public';
import asyncpg
from contextlib import asynccontextmanager
@asynccontextmanager
async def get_pool(dsn: str):
pool = await asyncpg.create_pool(dsn, min_size=5, max_size=20)
try:
yield pool
finally:
await pool.close()
# Usage
async with get_pool(DATABASE_URL) as pool:
async with pool.acquire() as conn:
user = await conn.fetchrow(
"SELECT * FROM users WHERE id = $1", user_id
)
pg_stat_statements for query monitoringpg_stat_* viewsdevelopment
Manage VSCode/Cursor configuration in this dotfiles repository. Use when working with settings.json, keybindings.json, or tasks.json files, or when asked about VSCode/Cursor configuration structure.
tools
Design user interfaces and experiences for web applications without requiring design tools. Use for wireframing in text/ASCII, defining user flows, creating component hierarchies, establishing design systems, planning responsive layouts, and making accessibility decisions.
development
Testing specialist focused on comprehensive test coverage for Python applications. Use for pytest patterns, unit/integration/E2E testing, fixtures, mocking, property-based testing with Hypothesis, and factory patterns.
development
Project management adapted for solo developers working without a team. Use for personal project planning, time-boxing work sessions, managing scope creep alone, maintaining momentum on side projects, tracking progress without overhead, making decisions without external input, and staying accountable to yourself.