Loading...
Loading...
PostgreSQL 17/18+ performance tuning and optimization. Covers async I/O configuration, query plan forensics, index strategies, autovacuum tuning, and vector search optimization. Use when diagnosing slow queries, configuring async I/O, tuning autovacuum, optimizing vector indexes, or analyzing execution plans with EXPLAIN BUFFERS.
npx skill4agent add oakoss/agent-skills postgres-tuningpg_stat_statementspg_stat_iopg_stat_checkpointerpg_stat_bgwriterpg_stat_user_tablespg_statio_user_tablespg_aios| Pattern | Configuration / Query | Key Points |
|---|---|---|
| Async I/O | | PG18 default is |
| I/O concurrency | | |
| Forensic EXPLAIN | | PG18 auto-includes BUFFERS with ANALYZE; target Shared Hit > 95% |
| UUIDv7 primary keys | | PG18 built-in; time-ordered, monotonic within a session; RFC 9562 compliant |
| B-tree skip scan | Composite index on | PG18 skips leading column; works best with low-cardinality prefix and equality on trailing columns |
| Aggressive autovacuum | | Triggers at 1% row change instead of default 20% |
| Shared buffers | Start at 25% of RAM | Do not exceed 40% without benchmarking |
| work_mem tuning | | Prevents sort spills to disk; allocated per operator, not per query |
| BRIN index | | 100x smaller than B-tree for physically ordered time-series data |
| HNSW vector index | | Tune |
| GIN index | | JSONB containment, full-text search, array operators; slower writes |
| Checkpoint tuning | | Spread writes over 90% of timeout window to avoid I/O storms |
| WAL compression | | Available since PG15; reduces WAL I/O 50-70% for write-heavy workloads |
| Bloat detection | | Reindex concurrently if bloat > 30% |
| I/O monitoring | | Watch |
| Checkpoint monitoring | | PG17+ moved checkpoint stats out of |
io_methoduuidv7()uuidv4()gen_random_uuid()uuid_extract_timestamp()pg_stat_ioread_byteswrite_bytesextend_bytesop_byteseffective_io_concurrencypg_aiospg_stat_bgwriterpg_stat_checkpointercheckpoints_timednum_timedcheckpoints_reqnum_requestedbuffers_backendbuffers_backend_fsyncpg_stat_bgwriterpg_stat_iowal_compressionpglzlz4zstd| Mistake | Correct Pattern |
|---|---|
Using | PG18 provides built-in |
Using | The correct PG18 parameter is |
Querying | Checkpoint stats moved to |
| Using SELECT * in high-frequency queries | Select only needed columns to reduce I/O and improve cache hit ratios |
| Ignoring sequential scans on tables over 10k rows | Add targeted indexes on columns used in WHERE, ORDER BY, and JOIN clauses |
| Setting shared_buffers above 40% of RAM without testing | Start at 25% and benchmark; excessive allocation causes OS page cache contention |
| Leaving autovacuum at default settings for high-churn tables | Tune |
| Over-indexing columns rarely used in queries | Every extra index slows UPDATE/INSERT and prevents HOT (Heap Only Tuple) updates |
| Expecting B-tree skip scan to work with range predicates | PG18 skip scan only works with equality operators on trailing columns |
| Ignoring "External Merge Disk" in query plans | Increase work_mem for specific sessions; it indicates sort spills to disk |
Setting | PostgreSQL must be built with |
| Assuming PG18 AIO accelerates writes | AIO in PG18 only covers reads (seq scans, bitmap heap scans, VACUUM); writes remain synchronous |
pg_stat_statementstotal_exec_timeEXPLAIN (ANALYZE, BUFFERS, SETTINGS)pg_statio_user_tablespg_stat_ioExploreTaskPlan