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.
| 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 deploymentOther measured skills in the registry, with their headline benchmark lift.