postgres-tuning
PostgreSQL 17/18+ performance tuning and optimization. Covers async I/O configuration, query plan forensics, index strategies, autovacuum tuning, vector search optimization, connection pooling, declarative partitioning, and practical query patterns. Use when diagnosing slow queries, configuring async I/O, tuning autovacuum, optimizing vector indexes, analyzing execution plans with EXPLAIN BUFFERS, configuring PgBouncer or connection pooling, setting up table partitioning, implementing cursor pagination, or optimizing queue processing.
What this skill does
# PostgreSQL Tuning ## Overview Optimizes PostgreSQL 17/18+ performance across I/O, query execution, indexing, and maintenance. Covers the native AIO subsystem introduced in PostgreSQL 18 for throughput gains on modern storage, forensic query plan analysis with EXPLAIN BUFFERS (auto-included in PG18), B-tree skip scans for composite indexes, native UUIDv7 generation, and autovacuum tuning for high-churn tables. **When to use:** Diagnosing slow queries, configuring async I/O, tuning shared_buffers and work_mem, optimizing indexes for write-heavy workloads, managing table bloat, pgvector HNSW tuning. **When NOT to use:** Schema design (use a data modeling tool), application-level caching strategy, database selection decisions, ORM query generation. **Key monitoring views:** - `pg_stat_statements` — identifies slow query patterns by cumulative execution time - `pg_stat_io` — granular I/O analysis by backend type, object, and context (PG16+) - `pg_stat_checkpointer` — checkpoint frequency and timing (PG17+; previously in `pg_stat_bgwriter`) - `pg_stat_user_tables` — dead tuple counts for bloat detection and autovacuum monitoring - `pg_statio_user_tables` — buffer cache hit ratios per table - `pg_aios` — in-progress AIO operations (PG18+) ## Quick Reference | Pattern | Configuration / Query | Key Points | | --------------------- | --------------------------------------- | -------------------------------------------------------------------------------------------------- | | Async I/O | `io_method = worker` or `io_uring` | PG18 default is `worker`; `io_uring` Linux-only (kernel 5.1+, requires liburing build flag) | | I/O concurrency | `io_max_concurrency` and `io_workers` | `io_workers` defaults to 3; `io_max_concurrency` defaults to -1 (auto-calculated) | | Forensic EXPLAIN | `EXPLAIN (ANALYZE, BUFFERS, SETTINGS)` | PG18 auto-includes BUFFERS with ANALYZE; target Shared Hit > 95% | | UUIDv7 primary keys | `DEFAULT uuidv7()` | PG18 built-in; time-ordered, monotonic within a session; RFC 9562 compliant | | B-tree skip scan | Composite index on `(a, b)` | PG18 skips leading column; works best with low-cardinality prefix and equality on trailing columns | | Aggressive autovacuum | `autovacuum_vacuum_scale_factor = 0.01` | 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 | `SET work_mem = '64MB'` per session | Prevents sort spills to disk; allocated per operator, not per query | | BRIN index | `CREATE INDEX USING brin(...)` | 100x smaller than B-tree for physically ordered time-series data | | HNSW vector index | `USING hnsw (col vector_cosine_ops)` | Tune `m` (default 16) and `ef_construction` (default 64) for recall vs speed | | GIN index | `CREATE INDEX USING gin(...)` | JSONB containment, full-text search, array operators; slower writes | | Checkpoint tuning | `checkpoint_timeout = 30min` | Spread writes over 90% of timeout window to avoid I/O storms | | WAL compression | `wal_compression = zstd` | Available since PG15; reduces WAL I/O 50-70% for write-heavy workloads | | Bloat detection | `pg_stat_user_tables.n_dead_tup` | Reindex concurrently if bloat > 30% | | I/O monitoring | `SELECT * FROM pg_stat_io` | Watch `evictions` (cache too small) and `extends` (fast growth) | | Checkpoint monitoring | `pg_stat_checkpointer` | PG17+ moved checkpoint stats out of `pg_stat_bgwriter` | ## Key Version Changes **PostgreSQL 18:** - Native async I/O via `io_method` parameter (reads only; writes remain synchronous) - Built-in `uuidv7()` function with monotonic ordering within a session (RFC 9562) - `uuidv4()` alias for `gen_random_uuid()` and `uuid_extract_timestamp()` for UUIDv7 - B-tree skip scan for composite indexes (equality on trailing columns, low-cardinality prefix) - EXPLAIN ANALYZE auto-includes buffer statistics without specifying BUFFERS - `pg_stat_io` gains byte-level columns (`read_bytes`, `write_bytes`, `extend_bytes`); `op_bytes` removed - `effective_io_concurrency` default changed from 1 to 16 - AIO monitoring via `pg_aios` system view for in-progress I/O operations **PostgreSQL 17:** - Checkpoint statistics moved from `pg_stat_bgwriter` to `pg_stat_checkpointer` - Column renames: `checkpoints_timed` to `num_timed`, `checkpoints_req` to `num_requested` - `buffers_backend` and `buffers_backend_fsync` removed from `pg_stat_bgwriter` (now in `pg_stat_io`) **PostgreSQL 15:** - `wal_compression` expanded from boolean to support `pglz`, `lz4`, and `zstd` algorithms ## Common Mistakes | Mistake | Correct Pattern | | ------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------- | | Using `uuid_generate_v7()` or `gen_random_uuid()` for ordered keys | PG18 provides built-in `uuidv7()` for time-ordered UUIDs; pre-PG18 use `pg_uuidv7` extension | | Using `max_async_ios` as a configuration parameter | The correct PG18 parameter is `io_max_concurrency` (max concurrent I/O ops per process) | | Querying `pg_stat_bgwriter` for checkpoint statistics on PG17+ | Checkpoint stats moved to `pg_stat_checkpointer` in PG17; columns renamed (`num_timed`, `num_requested`) | | 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 `autovacuum_vacuum_scale_factor` to 0.01 for tables with frequent UPDATE/DELETE | | 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 `io_method = io_uring` without verifying build flags | PostgreSQL must be built with `--with-liburing` and requires Linux kernel 5.1+ | | Assuming PG18 AIO accelerates writes | AIO in PG18 only covers reads (seq scans, bitmap heap scans, VACUUM); writes remain synchronous | ## Tuning Workflow 1. **Identify** slow queries
Related in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.