[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M74G9FHNSCJXNG19R2EQYVNJ":3,"skill-same:01M74G9FHNSCJXNG19R2EQYVNJ":44},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":14,"repositoryHtmlUrl":27,"repositoryHomepageUrl":6,"ownerHtmlUrl":28,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":29,"install":30,"resources":43},"01M74G9FHNSCJXNG19R2EQYVNJ","db-io-tuning",null,"Cut database IO — cache and working set, read\u002Fwrite amplification, WAL\u002Ffsync, checkpoints, bloat, volume IOPS limits. Not plans or indexes.","MohammadBafkar\u002Fpolymath","MohammadBafkar","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F34940462?v=4","01M74G540TQFZWK6KVAPKFVGNR","Mohammad Bafkar","01M74G541HG19QP9V5DQCJVKYE",0,"MIT","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-database\u002Fskills\u002Fdb-io-tuning\u002FSKILL.md",[],[],"2026-11-11 15:11:14",false,"---\nname: db-io-tuning\ndescription: Cut database IO — cache and working set, read\u002Fwrite amplification, WAL\u002Ffsync, checkpoints, bloat, volume IOPS limits. Not plans or indexes.\n---\n\n# db-io-tuning\n\n> The database is usually IO-bound before it is CPU-bound. Cut the bytes you read and write first; buy faster disks second.\n\n**Mode:** analytical — judgment inside a fixed frame. Keep the output shape; every verdict cites its evidence; unknowns are marked `[TBD]` or `[VERIFY]`, never filled in.\n\n## When to use\n\n- Triage points at IO: waits are `DataFileRead` \u002F `WALWrite` \u002F `log file sync`, volume IOPS or throughput is near its ceiling, or latency tracks storage metrics.\n- Write-heavy workload (ingest, queue tables, audit logs) with commit latency spikes or replica lag.\n- Sizing storage and instance class for a data set that has outgrown memory.\n\nNot this when: the cause hasn't been located yet — start with `polymath-database:db-performance-triage`. Plan reading is `polymath-data:sql-optimize`; index choice is `polymath-database:index-strategy`.\n\n## Inputs\n\n- IO evidence: read vs write IOPS, throughput, queue depth, and latency over the incident window; cache hit ratio and `blks_read`\u002F`temp` volume from the statements view.\n- The working set vs RAM: hot data size (tables + indexes actually touched), total size, buffer\u002Fcache size.\n- Storage: type and provisioned IOPS\u002Fthroughput (and the instance's own storage-bandwidth cap), the data and WAL\u002Fredo layout, filesystem, and whether it is managed.\n- Write profile: rows\u002Fs, row width, indexes per table, transaction size, commit rate, durability requirements (`synchronous_commit`, `innodb_flush_log_at_trx_commit`).\n\n**Read-only.** Measure; never change `fsync`, flush settings, or storage on a live system from this skill — recommend, owner applies.\n\n## Procedure\n\n1. **Convert the symptom to bytes.** IOPS × IO size = throughput, and either number can be the cap. Many small random reads (index\u002Fheap lookups) hit the IOPS limit; large scans hit the throughput limit. Compare each to the *provisioned* ceiling, not the device's marketing peak.\n2. **Reads — shrink what must come from disk:**\n   - **Working set vs memory.** If hot data fits in cache, reads are mostly hits; a low hit ratio with a growing `blks_read` means the working set outgrew RAM or a scan is evicting it. Fix order: stop the scan (index, predicate, partition pruning), then shrink the data (narrower rows, drop dead indexes, compress, archive cold rows — `polymath-database:data-retention-archiving`), then add memory.\n   - **Read amplification.** Rows examined ≫ rows returned; heap fetches per index hit; low index correlation turning an index range scan into random IO; `SELECT *` pulling wide\u002FTOASTed columns that are discarded. Narrow the projection, add covering columns for hot reads, cluster\u002Fpartition by the common filter.\n   - **Table\u002Findex bloat.** Dead space makes every scan read more pages. Measure (`pgstattuple`, `pg_stat_user_tables.n_dead_tup`); fix the cause (autovacuum lag, long transactions pinning the horizon, update-heavy rows) before `pg_repack` or rebuilds.\n3. **Writes — shrink what must be made durable:**\n   - **Write amplification.** One logical row write becomes heap + every index + WAL (+ full-page images after a checkpoint) + replica traffic. Fewer indexes, narrower rows, HOT-friendly updates (don't update indexed columns; leave `fillfactor` headroom), and not rewriting unchanged values all cut it.\n   - **Commit path.** Each commit waits for a log flush. Group commit helps concurrent writers; batching many rows per transaction (hundreds–thousands, not millions) cuts fsyncs by orders of magnitude. Relaxing durability (`synchronous_commit = off`, `innodb_flush_log_at_trx_commit = 2`) trades up to a few hundred ms of recent commits on crash for latency — a business decision, never a default; never `fsync = off`.\n   - **Checkpoints.** Too-frequent checkpoints (small `max_wal_size` \u002F redo log) cause write bursts and full-page-image storms; too-rare ones lengthen crash recovery. Check requested-vs-timed checkpoints, spread writes (`checkpoint_completion_target`), and size WAL\u002Fredo to the write rate.\n   - **Bulk loads.** Use `COPY` \u002F multi-row inserts \u002F `LOAD DATA`, drop or defer secondary indexes for the load when feasible, load in sort order, and avoid per-row round trips.\n4. **Storage layout and limits.** Separate WAL\u002Fredo from data when the volume class or latency profile warrants; know the volume's IOPS\u002Fthroughput\u002Fburst model (a burst balance that drains produces a cliff, not a slope); check the instance's EBS\u002Fnetwork bandwidth cap, filesystem (XFS\u002Fext4 options), and read-ahead for scan-heavy engines. Prefer provisioning to the measured peak plus headroom over \"bigger disk\".\n5. **Temp and spill IO.** Sorts\u002Fhashes spilling past `work_mem` (Postgres `temp_blks_written`, MySQL `Created_tmp_disk_tables`) are avoidable IO — fix the query or raise the per-session limit for that job, not the global default.\n6. **Rank the changes by bytes saved per unit of risk**, apply one at a time, and re-measure the same IO metrics. State the expected effect as a measured delta to confirm, not a promised percentage.\n\n## Output\n\n```text\nDB IO review: events-db (Postgres 15, 16 vCPU \u002F 128 GB, gp3 12k IOPS \u002F 500 MB\u002Fs)\n\nEvidence\n  reads   9.8k IOPS avg, 11.7k peak (98% of 12k) · cache hit 91% (was 99.4% last month) · working set ≈ 190 GB vs 96 GB shared_buffers + page cache\n  writes  2.1k IOPS · WAL 38 MB\u002Fs · 74% of checkpoints requested (max_wal_size 4 GB) · commit p99 18 ms\n  bloat   events_raw 41% dead\u002Ffree space (long-running report held xmin 6 h)\n\nFindings (ranked by bytes saved ÷ risk)\n  1. Seq scan from nightly export reads 140 GB and evicts the hot set → add created_at partition pruning (see partitioning-sharding); run on a replica.\n  2. events_raw bloat inflates every scan ~1.7× → fix the 6 h report transaction first, then pg_repack off-peak.\n  3. Checkpoints requested 74% → raise max_wal_size to 32 GB; expect fewer full-page images (verify pg_stat_wal.wal_fpi).\n  4. 7 indexes on a 2.1k writes\u002Fs table; 2 unused → each removed index cuts heap+WAL writes (see index-strategy).\nNot changed: synchronous_commit stays on (payments data — durability is a business requirement).\nVerify after each change: IOPS vs ceiling, cache hit, wal_fpi\u002Fs, checkpoint ratio, commit p99.\nUnknowns: [TBD: whether the volume has burst credits — IOPS held at 12k for 6 h suggests provisioned, confirm in the volume metrics].\n```\n\n## Quality bar\n\n- IO is expressed as IOPS, throughput, and latency against provisioned ceilings, not \"high disk usage\".\n- Each recommendation reduces bytes read or written (or fsyncs), and says which metric will show it.\n- Durability trade-offs are named as business decisions with the failure window stated; none are slipped in as a \"free\" tweak.\n- Bloat is traced to its cause before a rebuild is proposed.\n- Findings are ordered by impact per risk and applied one at a time.\n\n## Anti-patterns to avoid\n\n- Buying provisioned IOPS before finding the scan or missing index generating them.\n- Turning off `fsync` \u002F `full_page_writes`, or setting relaxed commit globally, to win a benchmark.\n- `VACUUM FULL` or an unthrottled rebuild on a hot table during peak.\n- Huge transactions (millions of rows) as \"batching\" — they bloat, block vacuum, and lag replicas; batch in bounded chunks.\n- Benchmarking on a data set that fits in RAM and extrapolating to one that doesn't.\n- Treating cache hit ratio as a goal: 99% can hide a hot scan, and 90% can be fine for a cold archive table.\n","# db-io-tuning\n\n> The database is usually IO-bound before it is CPU-bound. Cut the bytes you read and write first; buy faster disks second.\n\n**Mode:** analytical — judgment inside a fixed frame. Keep the output shape; every verdict cites its evidence; unknowns are marked `[TBD]` or `[VERIFY]`, never filled in.\n\n## When to use\n\n- Triage points at IO: waits are `DataFileRead` \u002F `WALWrite` \u002F `log file sync`, volume IOPS or throughput is near its ceiling, or latency tracks storage metrics.\n- Write-heavy workload (ingest, queue tables, audit logs) with commit latency spikes or replica lag.\n- Sizing storage and instance class for a data set that has outgrown memory.\n\nNot this when: the cause hasn't been located yet — start with `polymath-database:db-performance-triage`. Plan reading is `polymath-data:sql-optimize`; index choice is `polymath-database:index-strategy`.\n\n## Inputs\n\n- IO evidence: read vs write IOPS, throughput, queue depth, and latency over the incident window; cache hit ratio and `blks_read`\u002F`temp` volume from the statements view.\n- The working set vs RAM: hot data size (tables + indexes actually touched), total size, buffer\u002Fcache size.\n- Storage: type and provisioned IOPS\u002Fthroughput (and the instance's own storage-bandwidth cap), the data and WAL\u002Fredo layout, filesystem, and whether it is managed.\n- Write profile: rows\u002Fs, row width, indexes per table, transaction size, commit rate, durability requirements (`synchronous_commit`, `innodb_flush_log_at_trx_commit`).\n\n**Read-only.** Measure; never change `fsync`, flush settings, or storage on a live system from this skill — recommend, owner applies.\n\n## Procedure\n\n1. **Convert the symptom to bytes.** IOPS × IO size = throughput, and either number can be the cap. Many small random reads (index\u002Fheap lookups) hit the IOPS limit; large scans hit the throughput limit. Compare each to the *provisioned* ceiling, not the device's marketing peak.\n2. **Reads — shrink what must come from disk:**\n   - **Working set vs memory.** If hot data fits in cache, reads are mostly hits; a low hit ratio with a growing `blks_read` means the working set outgrew RAM or a scan is evicting it. Fix order: stop the scan (index, predicate, partition pruning), then shrink the data (narrower rows, drop dead indexes, compress, archive cold rows — `polymath-database:data-retention-archiving`), then add memory.\n   - **Read amplification.** Rows examined ≫ rows returned; heap fetches per index hit; low index correlation turning an index range scan into random IO; `SELECT *` pulling wide\u002FTOASTed columns that are discarded. Narrow the projection, add covering columns for hot reads, cluster\u002Fpartition by the common filter.\n   - **Table\u002Findex bloat.** Dead space makes every scan read more pages. Measure (`pgstattuple`, `pg_stat_user_tables.n_dead_tup`); fix the cause (autovacuum lag, long transactions pinning the horizon, update-heavy rows) before `pg_repack` or rebuilds.\n3. **Writes — shrink what must be made durable:**\n   - **Write amplification.** One logical row write becomes heap + every index + WAL (+ full-page images after a checkpoint) + replica traffic. Fewer indexes, narrower rows, HOT-friendly updates (don't update indexed columns; leave `fillfactor` headroom), and not rewriting unchanged values all cut it.\n   - **Commit path.** Each commit waits for a log flush. Group commit helps concurrent writers; batching many rows per transaction (hundreds–thousands, not millions) cuts fsyncs by orders of magnitude. Relaxing durability (`synchronous_commit = off`, `innodb_flush_log_at_trx_commit = 2`) trades up to a few hundred ms of recent commits on crash for latency — a business decision, never a default; never `fsync = off`.\n   - **Checkpoints.** Too-frequent checkpoints (small `max_wal_size` \u002F redo log) cause write bursts and full-page-image storms; too-rare ones lengthen crash recovery. Check requested-vs-timed checkpoints, spread writes (`checkpoint_completion_target`), and size WAL\u002Fredo to the write rate.\n   - **Bulk loads.** Use `COPY` \u002F multi-row inserts \u002F `LOAD DATA`, drop or defer secondary indexes for the load when feasible, load in sort order, and avoid per-row round trips.\n4. **Storage layout and limits.** Separate WAL\u002Fredo from data when the volume class or latency profile warrants; know the volume's IOPS\u002Fthroughput\u002Fburst model (a burst balance that drains produces a cliff, not a slope); check the instance's EBS\u002Fnetwork bandwidth cap, filesystem (XFS\u002Fext4 options), and read-ahead for scan-heavy engines. Prefer provisioning to the measured peak plus headroom over \"bigger disk\".\n5. **Temp and spill IO.** Sorts\u002Fhashes spilling past `work_mem` (Postgres `temp_blks_written`, MySQL `Created_tmp_disk_tables`) are avoidable IO — fix the query or raise the per-session limit for that job, not the global default.\n6. **Rank the changes by bytes saved per unit of risk**, apply one at a time, and re-measure the same IO metrics. State the expected effect as a measured delta to confirm, not a promised percentage.\n\n## Output\n\n```text\nDB IO review: events-db (Postgres 15, 16 vCPU \u002F 128 GB, gp3 12k IOPS \u002F 500 MB\u002Fs)\n\nEvidence\n  reads   9.8k IOPS avg, 11.7k peak (98% of 12k) · cache hit 91% (was 99.4% last month) · working set ≈ 190 GB vs 96 GB shared_buffers + page cache\n  writes  2.1k IOPS · WAL 38 MB\u002Fs · 74% of checkpoints requested (max_wal_size 4 GB) · commit p99 18 ms\n  bloat   events_raw 41% dead\u002Ffree space (long-running report held xmin 6 h)\n\nFindings (ranked by bytes saved ÷ risk)\n  1. Seq scan from nightly export reads 140 GB and evicts the hot set → add created_at partition pruning (see partitioning-sharding); run on a replica.\n  2. events_raw bloat inflates every scan ~1.7× → fix the 6 h report transaction first, then pg_repack off-peak.\n  3. Checkpoints requested 74% → raise max_wal_size to 32 GB; expect fewer full-page images (verify pg_stat_wal.wal_fpi).\n  4. 7 indexes on a 2.1k writes\u002Fs table; 2 unused → each removed index cuts heap+WAL writes (see index-strategy).\nNot changed: synchronous_commit stays on (payments data — durability is a business requirement).\nVerify after each change: IOPS vs ceiling, cache hit, wal_fpi\u002Fs, checkpoint ratio, commit p99.\nUnknowns: [TBD: whether the volume has burst credits — IOPS held at 12k for 6 h suggests provisioned, confirm in the volume metrics].\n```\n\n## Quality bar\n\n- IO is expressed as IOPS, throughput, and latency against provisioned ceilings, not \"high disk usage\".\n- Each recommendation reduces bytes read or written (or fsyncs), and says which metric will show it.\n- Durability trade-offs are named as business decisions with the failure window stated; none are slipped in as a \"free\" tweak.\n- Bloat is traced to its cause before a rebuild is proposed.\n- Findings are ordered by impact per risk and applied one at a time.\n\n## Anti-patterns to avoid\n\n- Buying provisioned IOPS before finding the scan or missing index generating them.\n- Turning off `fsync` \u002F `full_page_writes`, or setting relaxed commit globally, to win a benchmark.\n- `VACUUM FULL` or an unthrottled rebuild on a hot table during peak.\n- Huge transactions (millions of rows) as \"batching\" — they bloat, block vacuum, and lag replicas; batch in bounded chunks.\n- Benchmarking on a data set that fits in RAM and extrapolating to one that doesn't.\n- Treating cache hit ratio as a goal: 99% can hide a hot scan, and 90% can be fine for a cold archive table.\n",{"name":5,"description":7},"main","23f6e21841a39580c9da2b5ec941f39dda17cd86","plugins\u002Fpolymath-database\u002Fskills\u002Fdb-io-tuning","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath","https:\u002F\u002Fgithub.com\u002FMohammadBafkar","2026-10-29 18:34:59",{"source":8,"skillName":5,"commands":31,"prompt":41,"zipAvailable":42},[32,35,38],{"tool":33,"command":34},"npx","npx skills add MohammadBafkar\u002Fpolymath --skill db-io-tuning",{"tool":36,"command":37},"bunx","bunx skills add MohammadBafkar\u002Fpolymath --skill db-io-tuning",{"tool":39,"command":40},"pnpm","pnpm dlx skills add MohammadBafkar\u002Fpolymath --skill db-io-tuning","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-database\u002Fskills\u002Fdb-io-tuning\u002FSKILL.md",true,[],[45,52,59,66,73,80],{"skillNo":46,"name":47,"nameZh":6,"description":48,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":49,"categories":50,"keywords":51,"publishedAt":19},"01M74GN87EBRHM9N87M7AP1HDD","runbook","Write or refresh an operational runbook for an alert\u002Fsymptom; structured as TL;DR + Pre-checks + Steps + Verification + Rollback + Escalation.","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-writing\u002Fskills\u002Frunbook\u002FSKILL.md",[],[],{"skillNo":53,"name":54,"nameZh":6,"description":55,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":56,"categories":57,"keywords":58,"publishedAt":19},"01M74GN5GPKEC1JEKP2DFQNEQJ","rfc","Draft a lightweight design RFC to docs\u002Frfcs\u002F\u003Cslug>.md; Summary, Motivation, Detailed design, Drawbacks, Alternatives, Unresolved questions. A proposal to debate, not a recorded decision (adr).","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-writing\u002Fskills\u002Frfc\u002FSKILL.md",[],[],{"skillNo":60,"name":61,"nameZh":6,"description":62,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":63,"categories":64,"keywords":65,"publishedAt":19},"01M74GN2F4CWPMV4X09TG4E304","editorial-pass","Review and tighten prose in a Markdown artifact for a target tone (terse, formal, friendly) without dropping information; preserve quotations and load-bearing constraints.","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-writing\u002Fskills\u002Feditorial-pass\u002FSKILL.md",[],[],{"skillNo":67,"name":68,"nameZh":6,"description":69,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":70,"categories":71,"keywords":72,"publishedAt":19},"01M74GMZWGYMZ37C4DYGT6P23G","architecture-review-facilitation","Run an architecture review as a process — entry criteria, reviewer checklist, decision log, and follow-up actions — pairing the design artifact with a red-team pass.","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-writing\u002Fskills\u002Farchitecture-review-facilitation\u002FSKILL.md",[],[],{"skillNo":74,"name":75,"nameZh":6,"description":76,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":19},"01M74GMXVX0YX3ETDXS527XDGM","architecture-doc","Write a C4-style architecture document; System Context + Containers (+ Components when interesting) with mermaid diagrams. Describes structure, not a decision (adr) or proposal (rfc).","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-writing\u002Fskills\u002Farchitecture-doc\u002FSKILL.md",[],[],{"skillNo":81,"name":82,"nameZh":6,"description":83,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":84,"categories":85,"keywords":86,"publishedAt":19},"01M74GMVG1WSMCK066S3KE6V5K","adr","Write an Architecture Decision Record (Michael Nygard format) to docs\u002Fadrs\u002FNNNN-\u003Cslug>.md; frontmatter validated by the ADR artifact schema. Records a made decision, not a proposal to debate (rfc).","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-writing\u002Fskills\u002Fadr\u002FSKILL.md",[],[]]