[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M74G9JNXHNWCHNBCKCT6EQMS":3,"skill-same:01M74G9JNXHNWCHNBCKCT6EQMS":50},{"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},"01M74G9JNXHNWCHNBCKCT6EQMS","db-performance-triage",null,"Triage a slow or saturated database top-down (workload, waits, plans, IO, locks, pools) to ONE bottleneck. Engine-agnostic; not one query plan.","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-performance-triage\u002FSKILL.md",[],[],"2026-11-11 15:11:14",false,"---\nname: db-performance-triage\ndescription: Triage a slow or saturated database top-down (workload, waits, plans, IO, locks, pools) to ONE bottleneck. Engine-agnostic; not one query plan.\n---\n\n# db-performance-triage\n\n> Don't tune what you haven't measured. Find which resource the database is actually starved of — CPU, IO, locks, memory, or connections — then fix that, not the query you happened to look at.\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- \"The database is slow\", latency or CPU spiked, or the app times out waiting on queries and nobody knows which one.\n- Before buying a bigger instance: prove the bottleneck is capacity and not a bad query, missing index, or lock.\n- A workflow or review needs a ranked, evidence-backed cause — not a pile of tuning tips.\n\nNot this when: you already have one slow query and its plan — that is `polymath-data:sql-optimize`. For Postgres-specific catalog queries and settings, continue with `polymath-database:postgres-performance` after this.\n\n## Inputs\n\n- Engine + version, instance size (vCPU, RAM, storage type and provisioned IOPS\u002Fthroughput), and whether it is managed.\n- The symptom with a time window: which endpoints, latency percentiles, error\u002Ftimeout rate, and what changed (deploy, traffic, data growth, config).\n- Access to workload statistics (see [references\u002Fdiagnostics.md](references\u002Fdiagnostics.md)): top-statements view, wait events, lock views, and host\u002Fvolume metrics. Missing one → say which step it blocks and continue with the rest.\n\n**Read-only.** Gather with `SELECT`\u002F`SHOW`\u002Fmetrics only. Never `KILL`, `VACUUM FULL`, `ALTER SYSTEM`, drop an index, or flush a cache on a live primary — recommend; the owner applies. `EXPLAIN ANALYZE` executes the query: use a replica or a rollback block.\n\n## Procedure\n\nWalk the layers in order (a USE-method pass — Utilization, Saturation, Errors — per resource). Stop at the first layer with decisive evidence, not the first plausible one.\n\n1. **Frame the symptom.** One sentence: which queries\u002Fendpoints, which percentile, since when, correlated with what change. A regression with a start time is a diff problem; a slow climb is a growth problem. Different hunts.\n2. **Host resources (USE).** CPU utilization + run-queue, memory + swap, disk IOPS \u002F throughput \u002F queue depth \u002F latency vs the provisioned ceiling, network. A resource at its ceiling with a queue is the lead. Cloud volumes throttle silently at their IOPS\u002Fthroughput caps — check the burst-credit or throttle metric, not just utilization.\n3. **Connections.** Active vs idle vs idle-in-transaction, vs `max_connections`\u002Fpool size. Many active sessions on few cores is saturation (latency grows with every extra concurrent query); a wall of idle-in-transaction holds locks and snapshots. Fix with a pooler and a lower concurrency cap before touching queries.\n4. **Where the time goes — waits.** Sample wait events (Postgres `pg_stat_activity.wait_event`, MySQL `performance_schema` waits, SQL Server `sys.dm_os_wait_stats`, Oracle ASH). Classify: CPU, IO read, IO write\u002FWAL\u002Ffsync, lock, latch\u002FLWLock, client (app is slow, not the DB). The dominant class decides the next step.\n5. **Workload — which statements.** Rank by *total* time (`calls × mean`), not worst single run: `pg_stat_statements`, MySQL `events_statements_summary_by_digest`, SQL Server Query Store. Top 3–5 usually carry most of the load. Note calls\u002Fsec — a 2 ms query called 20k\u002Fs (an N+1) beats a 3 s report.\n6. **Per-statement plan.** For the top statements only, read the plan (`polymath-data:sql-optimize`): rows scanned vs returned, estimate-vs-actual drift, sort\u002Fhash spills, nested-loop blowups, plan flips after stats change.\n7. **Indexes and schema.** Missing (seq scan on a selective predicate), redundant\u002Funused (write cost for no reads), wrong column order → `polymath-database:index-strategy`. Bloat and table width → `polymath-database:db-io-tuning`.\n8. **Locks and contention.** Blocking chains, deadlock log, long transactions, hot rows (counters, queue tables, a single \"latest\" row), DDL waiting behind a long transaction.\n9. **Maintenance and stats.** Stale statistics, vacuum\u002Fautovacuum lag, dead tuples, checkpoint storms, replica lag, long-running backups competing for IO.\n10. **Decide: tune, or scale.** If the top statements are fixed-cost and the resource is genuinely saturated, the answer is capacity or architecture — `polymath-database:db-scaling-strategy`. If one fix would drop a resource below ~60–70% sustained, do that fix first.\n\n## Output\n\n```text\nDB triage: orders-db (Postgres 16, db.r6g.2xlarge, 8 vCPU \u002F 64 GB, gp3 6k IOPS) — checkout p99 0.4 s → 2.8 s since Tue 14:10\n\nSymptom: POST \u002Fcheckout p99 regression; started with deploy 2025.41 (adds order-history lookup).\nEvidence by layer\n  host      CPU 38% · IOPS 5.9k\u002F6k (98% of provisioned, queue depth 14) · mem fine      ← IO saturated\n  conns     active 22 \u002F 120, idle-in-tx 0                                                 ← not it\n  waits     61% IO:DataFileRead, 22% CPU, 4% Lock                                         ← read IO\n  workload  #1 SELECT … FROM orders WHERE customer_id=$1 ORDER BY created_at DESC LIMIT 20\n            41% of total time · 18k calls\u002Fs · mean 3.1 ms · shared_blks_read 96\u002Fcall\n  plan      Seq Scan on orders (rows removed by filter 99.98%) — no index on customer_id\nDominant bottleneck: read IO from a missing index on orders(customer_id, created_at DESC) (introduced by the new query).\nNot the cause (checked): connections, locks, checkpoints, replica lag.\nFirst fix (one change): CREATE INDEX CONCURRENTLY orders_customer_created_idx ON orders (customer_id, created_at DESC) — plan it with polymath-backend:migration-plan.\nVerify: IOPS \u003C 60% of provisioned, query mean \u003C 0.3 ms, shared_blks_read\u002Fcall \u003C 5, checkout p99 back under 0.5 s.\nUnknowns: [VERIFY: whether read replicas can absorb the order-history reads — would remove the load from the primary entirely].\n```\n\n## Quality bar\n\n- ONE dominant bottleneck, with the layer's evidence — and the layers checked and ruled out are listed.\n- Statements ranked by total time and calls\u002Fsec, not by slowest single execution.\n- Every metric is read against the provisioned ceiling, not in isolation.\n- The first fix is a single change with a measurable success criterion; \"upgrade the instance\" is only offered after the cheaper layers are eliminated.\n- No live-system mutation was proposed as something the skill itself runs.\n\n## Anti-patterns to avoid\n\n- Starting from the config file or a favorite tuning parameter instead of the symptom.\n- Optimizing the slowest query when a 2 ms query at 20k calls\u002Fs owns the load.\n- Reading averages: a p99 problem hides in the tail, in waits, and in lock chains.\n- Scaling up to mask a missing index — the bill grows, the problem returns at 2× traffic.\n- Changing several things at once, so nobody knows what helped.\n- Judging on a cold cache or a different data volume than production.\n","# db-performance-triage\n\n> Don't tune what you haven't measured. Find which resource the database is actually starved of — CPU, IO, locks, memory, or connections — then fix that, not the query you happened to look at.\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- \"The database is slow\", latency or CPU spiked, or the app times out waiting on queries and nobody knows which one.\n- Before buying a bigger instance: prove the bottleneck is capacity and not a bad query, missing index, or lock.\n- A workflow or review needs a ranked, evidence-backed cause — not a pile of tuning tips.\n\nNot this when: you already have one slow query and its plan — that is `polymath-data:sql-optimize`. For Postgres-specific catalog queries and settings, continue with `polymath-database:postgres-performance` after this.\n\n## Inputs\n\n- Engine + version, instance size (vCPU, RAM, storage type and provisioned IOPS\u002Fthroughput), and whether it is managed.\n- The symptom with a time window: which endpoints, latency percentiles, error\u002Ftimeout rate, and what changed (deploy, traffic, data growth, config).\n- Access to workload statistics (see [references\u002Fdiagnostics.md](references\u002Fdiagnostics.md)): top-statements view, wait events, lock views, and host\u002Fvolume metrics. Missing one → say which step it blocks and continue with the rest.\n\n**Read-only.** Gather with `SELECT`\u002F`SHOW`\u002Fmetrics only. Never `KILL`, `VACUUM FULL`, `ALTER SYSTEM`, drop an index, or flush a cache on a live primary — recommend; the owner applies. `EXPLAIN ANALYZE` executes the query: use a replica or a rollback block.\n\n## Procedure\n\nWalk the layers in order (a USE-method pass — Utilization, Saturation, Errors — per resource). Stop at the first layer with decisive evidence, not the first plausible one.\n\n1. **Frame the symptom.** One sentence: which queries\u002Fendpoints, which percentile, since when, correlated with what change. A regression with a start time is a diff problem; a slow climb is a growth problem. Different hunts.\n2. **Host resources (USE).** CPU utilization + run-queue, memory + swap, disk IOPS \u002F throughput \u002F queue depth \u002F latency vs the provisioned ceiling, network. A resource at its ceiling with a queue is the lead. Cloud volumes throttle silently at their IOPS\u002Fthroughput caps — check the burst-credit or throttle metric, not just utilization.\n3. **Connections.** Active vs idle vs idle-in-transaction, vs `max_connections`\u002Fpool size. Many active sessions on few cores is saturation (latency grows with every extra concurrent query); a wall of idle-in-transaction holds locks and snapshots. Fix with a pooler and a lower concurrency cap before touching queries.\n4. **Where the time goes — waits.** Sample wait events (Postgres `pg_stat_activity.wait_event`, MySQL `performance_schema` waits, SQL Server `sys.dm_os_wait_stats`, Oracle ASH). Classify: CPU, IO read, IO write\u002FWAL\u002Ffsync, lock, latch\u002FLWLock, client (app is slow, not the DB). The dominant class decides the next step.\n5. **Workload — which statements.** Rank by *total* time (`calls × mean`), not worst single run: `pg_stat_statements`, MySQL `events_statements_summary_by_digest`, SQL Server Query Store. Top 3–5 usually carry most of the load. Note calls\u002Fsec — a 2 ms query called 20k\u002Fs (an N+1) beats a 3 s report.\n6. **Per-statement plan.** For the top statements only, read the plan (`polymath-data:sql-optimize`): rows scanned vs returned, estimate-vs-actual drift, sort\u002Fhash spills, nested-loop blowups, plan flips after stats change.\n7. **Indexes and schema.** Missing (seq scan on a selective predicate), redundant\u002Funused (write cost for no reads), wrong column order → `polymath-database:index-strategy`. Bloat and table width → `polymath-database:db-io-tuning`.\n8. **Locks and contention.** Blocking chains, deadlock log, long transactions, hot rows (counters, queue tables, a single \"latest\" row), DDL waiting behind a long transaction.\n9. **Maintenance and stats.** Stale statistics, vacuum\u002Fautovacuum lag, dead tuples, checkpoint storms, replica lag, long-running backups competing for IO.\n10. **Decide: tune, or scale.** If the top statements are fixed-cost and the resource is genuinely saturated, the answer is capacity or architecture — `polymath-database:db-scaling-strategy`. If one fix would drop a resource below ~60–70% sustained, do that fix first.\n\n## Output\n\n```text\nDB triage: orders-db (Postgres 16, db.r6g.2xlarge, 8 vCPU \u002F 64 GB, gp3 6k IOPS) — checkout p99 0.4 s → 2.8 s since Tue 14:10\n\nSymptom: POST \u002Fcheckout p99 regression; started with deploy 2025.41 (adds order-history lookup).\nEvidence by layer\n  host      CPU 38% · IOPS 5.9k\u002F6k (98% of provisioned, queue depth 14) · mem fine      ← IO saturated\n  conns     active 22 \u002F 120, idle-in-tx 0                                                 ← not it\n  waits     61% IO:DataFileRead, 22% CPU, 4% Lock                                         ← read IO\n  workload  #1 SELECT … FROM orders WHERE customer_id=$1 ORDER BY created_at DESC LIMIT 20\n            41% of total time · 18k calls\u002Fs · mean 3.1 ms · shared_blks_read 96\u002Fcall\n  plan      Seq Scan on orders (rows removed by filter 99.98%) — no index on customer_id\nDominant bottleneck: read IO from a missing index on orders(customer_id, created_at DESC) (introduced by the new query).\nNot the cause (checked): connections, locks, checkpoints, replica lag.\nFirst fix (one change): CREATE INDEX CONCURRENTLY orders_customer_created_idx ON orders (customer_id, created_at DESC) — plan it with polymath-backend:migration-plan.\nVerify: IOPS \u003C 60% of provisioned, query mean \u003C 0.3 ms, shared_blks_read\u002Fcall \u003C 5, checkout p99 back under 0.5 s.\nUnknowns: [VERIFY: whether read replicas can absorb the order-history reads — would remove the load from the primary entirely].\n```\n\n## Quality bar\n\n- ONE dominant bottleneck, with the layer's evidence — and the layers checked and ruled out are listed.\n- Statements ranked by total time and calls\u002Fsec, not by slowest single execution.\n- Every metric is read against the provisioned ceiling, not in isolation.\n- The first fix is a single change with a measurable success criterion; \"upgrade the instance\" is only offered after the cheaper layers are eliminated.\n- No live-system mutation was proposed as something the skill itself runs.\n\n## Anti-patterns to avoid\n\n- Starting from the config file or a favorite tuning parameter instead of the symptom.\n- Optimizing the slowest query when a 2 ms query at 20k calls\u002Fs owns the load.\n- Reading averages: a p99 problem hides in the tail, in waits, and in lock chains.\n- Scaling up to mask a missing index — the bill grows, the problem returns at 2× traffic.\n- Changing several things at once, so nobody knows what helped.\n- Judging on a cold cache or a different data volume than production.\n",{"name":5,"description":7},"main","23f6e21841a39580c9da2b5ec941f39dda17cd86","plugins\u002Fpolymath-database\u002Fskills\u002Fdb-performance-triage","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-performance-triage",{"tool":36,"command":37},"bunx","bunx skills add MohammadBafkar\u002Fpolymath --skill db-performance-triage",{"tool":39,"command":40},"pnpm","pnpm dlx skills add MohammadBafkar\u002Fpolymath --skill db-performance-triage","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-database\u002Fskills\u002Fdb-performance-triage\u002FSKILL.md",true,[44],{"path":45,"resourceType":46,"resourceTypeDesc":47,"sizeBytes":48,"sourceHtmlUrl":49},"references\u002Fdiagnostics.md","REFERENCE","参考文档",3144,"https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-database\u002Fskills\u002Fdb-performance-triage\u002Freferences\u002Fdiagnostics.md",[51,58,65,72,79,86],{"skillNo":52,"name":53,"nameZh":6,"description":54,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":55,"categories":56,"keywords":57,"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":59,"name":60,"nameZh":6,"description":61,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":62,"categories":63,"keywords":64,"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":66,"name":67,"nameZh":6,"description":68,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":69,"categories":70,"keywords":71,"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":73,"name":74,"nameZh":6,"description":75,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":76,"categories":77,"keywords":78,"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":80,"name":81,"nameZh":6,"description":82,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":85,"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":87,"name":88,"nameZh":6,"description":89,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":90,"categories":91,"keywords":92,"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",[],[]]