Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Design high-performance PostgreSQL databases with schema optimization, indexing strategies, partitioning, replication, and PostgreSQL 17 tuning.
.claude/skills/williamzujkowski-postgresql-database-architect/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-21 | ✗→✓ | ▲ Improved | 179% | 0% |
| case-22 | ✗→✓ | ▲ Improved | 218% | 0% |
| case-20 | ✓→✓ | = Same ✓ | 541% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 576% | 0% |
| case-04 | ✓→✓ | = Same ✓ | 231% | 0% |
Primary trigger conditions:
When NOT to use this skill:
Value proposition: Optimizes PostgreSQL schema, indexes, and configuration for 2-10x performance improvement. PostgreSQL 17 delivers 2x write throughput in high-concurrency workloads and 20x vacuum memory reduction compared to PostgreSQL 16 (PostgreSQL.org 2025).
Required inputs validation:
pythonNOW_ET = "2025-10-26T18:30:00-04:00" assert workload_type in ["oltp", "olap", "htap", "time-series"], "Valid workload type required" assert data_volume_estimate is not None, "Data volume estimate required (GB or row count)" assert queries_per_second_target > 0, "QPS target required" # Version check if postgresql_version < 17: warn("PostgreSQL 17+ recommended for vectored I/O and improved parallelism") # Cloud vs self-hosted if deployment_environment in ["aws-rds", "gcp-cloudsql", "azure-postgres"]: note("Managed service constraints apply (limited postgresql.conf access)")
Authority checks:
Source citations (accessed 2025-10-26T18:30:00-04:00):
Goal: Identify top 3 performance bottlenecks and provide immediate tuning recommendations in <10 minutes.
Steps:
Token budget checkpoint: ~1.8k tokens for workload analysis, schema scan, config review, quick wins output.
Goal: Generate production-ready PostgreSQL architecture with optimized schema, indexes, partitioning, and configuration.
Extends T1 with:
Normalization strategy:
Data type optimization:
Constraints and validation:
Index types and use cases:
| Index Type | Use Case | Example | |------------|----------|---------| | B-tree (default) | Equality, range queries | CREATE INDEX idx_users_email ON users(email); | | Hash | Equality only (faster than B-tree for exact match) | CREATE INDEX idx_sessions_hash ON sessions USING HASH(session_id); | | GIN (Generalized Inverted) | Full-text search, JSONB, arrays | CREATE INDEX idx_posts_fts ON posts USING GIN(to_tsvector('english', content)); | | GiST (Generalized Search Tree) | Geometric data, full-text, range types | CREATE INDEX idx_locations_gist ON locations USING GIST(coordinates); | | BRIN (Block Range Index) | Large tables with natural ordering (time-series) | CREATE INDEX idx_logs_brin ON logs USING BRIN(created_at); | | Partial | Index subset of rows | CREATE INDEX idx_active_users ON users(last_login) WHERE active = true; | | Covering (INCLUDE) | Include non-key columns | CREATE INDEX idx_orders_cover ON orders(user_id) INCLUDE (total_amount, status); |
Index maintenance:
CREATE INDEX CONCURRENTLY idx_name ON table(column);pg_stat_user_indexes.idx_scan (drop unused indexes)Partitioning strategies (PostgreSQL 10+ declarative partitioning):
Range partitioning (most common, time-based): sql CREATE TABLE orders ( id BIGSERIAL, user_id BIGINT, created_at TIMESTAMPTZ NOT NULL, total_amount NUMERIC(10,2) ) PARTITION BY RANGE (created_at);
CREATE TABLE orders_2025_01 PARTITION OF orders FOR VALUES FROM ('2025-01-01') TO ('2025-02-01'); CREATE TABLE orders_2025_02 PARTITION OF orders FOR VALUES FROM ('2025-02-01') TO ('2025-03-01');
List partitioning (categorical data): sql CREATE TABLE users PARTITION BY LIST (country_code); CREATE TABLE users_us PARTITION OF users FOR VALUES IN ('US'); CREATE TABLE users_eu PARTITION OF users FOR VALUES IN ('DE', 'FR', 'UK');
Hash partitioning (distribute evenly when no natural partition key): sql CREATE TABLE sessions PARTITION BY HASH (session_id); CREATE TABLE sessions_0 PARTITION OF sessions FOR VALUES WITH (MODULUS 4, REMAINDER 0); CREATE TABLE sessions_1 PARTITION OF sessions FOR VALUES WITH (MODULUS 4, REMAINDER 1);
Partition pruning (PostgreSQL 17 improvement):
SELECT * FROM orders WHERE created_at >= '2025-10-01' only scans Oct 2025 partitionEXPLAIN ANALYZE to verify pruning: look for "Partitions pruned: N"Reading EXPLAIN ANALYZE output: sql EXPLAIN (ANALYZE, BUFFERS) SELECT * FROM users WHERE email = 'user@example.com';
Key metrics:
Common optimization patterns:
SELECT * with specific columns (especially with large TEXT/JSONB)LIMIT to reduce result set sizeLATERAL JOIN for row-dependent subqueriesVectored I/O (accessed 2025-10-26T18:30:00-04:00):
io_combine_limit (default: 128kB)Vacuum performance:
autovacuum_work_mem (default: -1, inherits maintenance_work_mem)pg_stat_progress_vacuumParallelism improvements:
FULL OUTER JOIN and aggregatesmax_parallel_workers_per_gather (default: 2, recommend 4-8 for OLAP)max_parallel_workers (total parallel workers across queries)Incremental sort optimization:
Memory parameters (postgresql.conf): ini # For 32GB RAM server (OLTP workload) shared_buffers = 8GB # 25% of RAM effective_cache_size = 20GB # 60% of RAM work_mem = 16MB # per operation (scale down if many connections) maintenance_work_mem = 1GB # for VACUUM, CREATE INDEX autovacuum_work_mem = 1GB # vacuum memory
Connection pooling:
max_connections = 100 (or lower), pool at application layerCheckpointing: ini checkpoint_timeout = 15min # reduce for faster crash recovery checkpoint_completion_target = 0.9 # spread writes over 90% of checkpoint interval
Write-Ahead Log (WAL): ini wal_level = replica # for streaming replication max_wal_size = 4GB # allow larger WAL before checkpoint min_wal_size = 1GB
Streaming replication (synchronous vs asynchronous):
synchronous_commit = on and synchronous_standby_namesLogical replication (PostgreSQL 10+):
Failover strategies:
pg_ctl promote on standbyAuthority sources (accessed 2025-10-26T18:30:00-04:00):
Output: Complete PostgreSQL architecture including schema DDL, index definitions, partitioning strategy, postgresql.conf tuning parameters, and HA architecture diagram.
Token budget checkpoint: ~5.5k tokens (includes T1 + comprehensive schema design + indexing + partitioning + tuning).
Goal: Advanced multi-region, disaster recovery, and large-scale PostgreSQL deployment for >1TB data or >100k QPS.
Extends T2 with:
ssl = on in postgresql.conf)Authority sources (accessed 2025-10-26T18:30:00-04:00):
Output: Full enterprise-grade PostgreSQL architecture including multi-region replication, sharding design, backup/DR plan, monitoring dashboard, and security configuration.
Token budget checkpoint: ~11k tokens (includes T1 + T2 + enterprise architecture).
When to abort:
Ambiguity thresholds:
Prioritization logic:
PostgreSQL principle application:
Schema (JSON):
json{ "schema_design": { "tables": [ { "name": "users", "columns": [ {"name": "id", "type": "BIGSERIAL", "constraints": ["PRIMARY KEY"]}, {"name": "email", "type": "VARCHAR(255)", "constraints": ["NOT NULL", "UNIQUE"]}, {"name": "created_at", "type": "TIMESTAMPTZ", "default": "NOW()"} ], "indexes": [ {"name": "idx_users_email", "type": "B-tree", "columns": ["email"], "unique": true} ], "partitioning": null } ], "normalization_level": "3NF", "estimated_size_gb": 50 }, "index_recommendations": [ { "table": "orders", "index_name": "idx_orders_user_created", "type": "B-tree", "columns": ["user_id", "created_at"], "rationale": "Covers 80% of queries filtering by user and time range", "estimated_speedup": "25x (seq scan 450ms → index scan 18ms)", "create_statement": "CREATE INDEX CONCURRENTLY idx_orders_user_created ON orders(user_id, created_at);" } ], "partitioning_strategy": { "table": "orders", "partition_by": "RANGE", "partition_key": "created_at", "partition_interval": "monthly", "retention_policy": "drop partitions older than 2 years", "estimated_query_speedup": "20x (table scan 45s → partition scan 2s)" }, "performance_tuning": { "postgresql_conf": { "shared_buffers": "8GB", "effective_cache_size": "20GB", "work_mem": "16MB", "maintenance_work_mem": "1GB", "max_connections": 100 }, "expected_improvement": "60% reduction in disk I/O, 2x query throughput" }, "high_availability": { "architecture": "primary + 2 read replicas (async)", "failover_strategy": "automatic (Patroni + etcd)", "rto": "< 60 seconds", "rpo": "< 5 seconds (async replication lag)" } }
Required fields: schema_design (tables with columns and indexes), performance_tuning (postgresql_conf parameters).
Optional fields: partitioning_strategy (only if tables >1M rows), high_availability (only if HA requirement specified).
yaml# Example: E-commerce platform (OLTP workload) input: workload_type: oltp data_volume: "500GB (5M users, 50M orders)" queries_per_second: 5000 availability_sla: 99.95% deployment: aws-rds-postgres-17 output: schema_design: users: 3NF normalized, BIGSERIAL id, VARCHAR email (indexed) orders: partitioned by created_at (monthly), indexed on user_id + status indexes: - users(email) B-tree UNIQUE → login queries 50x faster - orders(user_id, created_at) B-tree → user history 25x faster - orders(status) partial WHERE status != 'completed' → active orders partitioning: orders: RANGE by created_at, monthly, 24 partitions (2 years) performance_tuning: shared_buffers: 16GB (25% of 64GB), work_mem: 8MB, max_connections: 200 high_availability: primary + 2 read replicas (async), Patroni failover, RTO <60s
Token budgets (enforced):
Accuracy requirements:
Safety constraints:
Auditability:
Determinism:
Official PostgreSQL documentation:
PostgreSQL 17 features and tuning:
Schema design and indexing:
Tools and extensions:
Related skills:
database-schema-designer: Database-agnostic schema designdatabase-optimization-analyzer: Query-level performance tuningdatabase-migration-generator: Data migration and ETLcloud-aws-architect: AWS RDS/Aurora PostgreSQL deploymentcloud-gcp-architect: GCP Cloud SQL PostgreSQL deploymentcloud-azure-architect: Azure Database for PostgreSQL deployment| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-20 | pass→pass | 5,992 | 5,669 | -5% | 1 | 1 | 0% | 1,123 | 7,196 | +541% | 0 | 0 | — |
case-01 | fail→fail | 13,092 | 10,465 | -20% | 1 | 1 | 0% | 3,234 | 8,600 | +166% | 0 | 0 | — |
case-02 | pass→pass | 4,629 | 3,633 | -22% | 1 | 1 | 0% | 1,012 | 6,841 | +576% | 0 | 0 | — |
case-03 | fail→fail | 15,467 | 14,231 | -8% | 1 | 1 | 0% | 3,767 | 9,656 | +156% | 0 | 0 | — |
case-04 | pass→pass | 11,645 | 10,076 | -13% | 1 | 1 | 0% | 2,487 | 8,225 | +231% | 0 | 0 | — |
case-05 | pass→pass | 5,975 | 3,948 | -34% | 1 | 1 | 0% | 1,182 | 6,955 | +488% | 0 | 0 | — |
case-06 | pass→pass | 6,797 | 7,813 | +15% | 1 | 1 | 0% | 1,329 | 7,552 | +468% | 0 | 0 | — |
case-07 | pass→pass | 9,170 | 7,889 | -14% | 1 | 1 | 0% | 1,812 | 7,629 | +321% | 0 | 0 | — |
case-08 | pass→pass | 5,469 | 6,295 | +15% | 1 | 1 | 0% | 1,042 | 7,362 | +607% | 0 | 0 | — |
case-09 | pass→pass | 12,362 | 12,155 | -2% | 1 | 1 | 0% | 2,637 | 8,925 | +238% | 0 | 0 | — |
case-10 | pass→pass | 3,938 | 6,600 | +68% | 1 | 1 | 0% | 814 | 7,723 | +849% | 0 | 0 | — |
case-11 | pass→pass | 5,385 | 4,273 | -21% | 1 | 1 | 0% | 1,090 | 7,009 | +543% | 0 | 0 | — |
case-12 | pass→pass | 5,090 | 6,316 | +24% | 1 | 1 | 0% | 935 | 7,414 | +693% | 0 | 0 | — |
case-13 | pass→pass | 6,997 | 7,075 | +1% | 1 | 1 | 0% | 1,450 | 7,548 | +421% | 0 | 0 | — |
case-14 | pass→pass | 11,861 | 10,048 | -15% | 1 | 1 | 0% | 2,225 | 8,184 | +268% | 0 | 0 | — |
case-15 | pass→pass | 18,269 | 18,128 | -1% | 1 | 1 | 0% | 3,282 | 9,631 | +193% | 0 | 0 | — |
case-16 | pass→pass | 10,796 | 7,841 | -27% | 1 | 1 | 0% | 1,951 | 7,644 | +292% | 0 | 0 | — |
case-17 | pass→pass | 8,527 | 6,994 | -18% | 1 | 1 | 0% | 1,567 | 7,389 | +372% | 0 | 0 | — |
case-18 | pass→pass | 4,738 | 5,717 | +21% | 1 | 1 | 0% | 923 | 7,280 | +689% | 0 | 0 | — |
case-19 | pass→pass | 4,415 | 4,749 | +8% | 1 | 1 | 0% | 797 | 7,024 | +781% | 0 | 0 | — |
case-21 | fail→pass | 13,888 | 9,502 | -32% | 1 | 1 | 0% | 2,979 | 8,313 | +179% | 0 | 0 | — |
case-22 | fail→pass | 12,585 | 10,673 | -15% | 1 | 1 | 0% | 2,607 | 8,283 | +218% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +9 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.