partition-planner
Skill0 starsChanged 39 days agoMITView on GitHub
Produces a partitioning or sharding plan for an oversized table - range/list/hash strategy, partition-key choice, composite-key and pruning constraints, and a verdict on whether to partition at all. Use when one table has grown past tens of millions of rows or hundreds of GB, vacuum/autovacuum on it runs for hours, retention deletes are giant DELETEs, or you are deciding between range/list/hash partitioning or sharding a hot table. Do NOT use when the goal is choosing indexes for specific slow queries - use index-advisor instead.
In this repository7 other files it gives its agents.
- connection-pool-tunerSkill
- explain-plan-readerSkill
- index-advisorSkill
- migration-safety-checkerSkill
- n-plus-one-hunterSkill
- query-rewriterSkill
- replication-lag-debuggerSkill
The file
We split this skill into the rules it gives an agent
11 rules. About 0 are common, 11 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈11
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 18
Hash: - no natural range but you must cap any single child's size.
- Distinctive: line 23
Keep partition count bounded (low hundreds, not thousands) to avoid planning bloat, and size individual partitions so maintenance stays …
- Distinctive: line 24
Verify foreign-key behavior against your engine version's partitioning limits.
- Distinctive: line 37
Every Postgres unique/primary key in the plan includes the partition key.
- Distinctive: line 41
Do not partition a table that is small or merely missing an index.
- Distinctive: line 42
Do not choose a partition key absent from hot queries' WHERE clauses - it kills pruning.
- Distinctive: line 43
Do not partition on a high-churn updated column - it forces cross-partition row movement.
- Distinctive: line 44
Do not create thousands of partitions.
- Distinctive: line 45
Do not leave partition creation manual - a missing future partition rejects writes.
- Distinctive: line 46
Do not jump to sharding before single-node partitioning is exhausted.
- Distinctive: line 47
Do not prescribe per-query index sets here - defer that to index-advisor.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Table Partition Planner
Plan how to split one too-large table into partitions (or shards) keyed to its real access and retention patterns - or prove it should stay a single indexed table.
Workflow
- Confirm partitioning is warranted. Get the row count and on-disk size. Below roughly 50-100M rows or a few hundred GB, a well-indexed single table usually beats a partitioned one; recommend staying single unless retention or vacuum pain forces the issue. Never partition to compensate for a missing index - that is index-advisor's job; add the index first and re-measure.
- Characterize the access pattern. Capture the hot queries' WHERE clauses, the retention/deletion policy, and write distribution. The partition key must come from this evidence, not a guess.
- Pick the strategy from that pattern.
- Range - time-series or any naturally ordered key (e.g.
created_atby month). Old data leaves viaDROP/DETACH PARTITIONinstead of a giantDELETE. Monthly granularity is the sane default for multi-year retention; drop to weekly or daily only when a single month would exceed roughly 50-100 GB. - List - a small fixed set of discrete values (region, tenant tier).
- Hash - no natural range but you must cap any single child's size; use a fixed modulus (a power of two, commonly 8-64) to spread writes evenly, because changing the modulus later means rewriting the table.
- Range - time-series or any naturally ordered key (e.g.
- Choose the partition key. It must appear in the WHERE clause of hot queries (or the planner cannot prune and scans every child), align with the retention policy (drop by time), and align with the largest indexes. Reject any column that is frequently updated - moving a row across partitions on UPDATE is expensive.
- Resolve the constraint and operational requirements.
- In Postgres declarative partitioning, every unique constraint and primary key must include the partition key - design composite keys accordingly.
- Automate partition creation (pg_partman or a scheduled job) so writes never hit a missing partition; pre-create at least 3 future partitions as a buffer.
- Keep partition count bounded (low hundreds, not thousands) to avoid planning bloat, and size individual partitions so maintenance stays fast - roughly 10-50 GB per child is a comfortable working range.
- Verify foreign-key behavior against your engine version's partitioning limits.
- Decide partition vs shard. Partitioning stays on one node. Reach for sharding (Citus, Vitess, or app-level routing) only when a single node's write throughput or storage is the hard ceiling - it adds distributed-transaction and rebalancing cost. If sharding, pick a shard key with even distribution and no cross-shard joins on the hot path.
- Write the plan. State chosen strategy, key, composite-key changes, creation/automation mechanism, retention operation, and the migration approach to convert the existing table.
Deliverable
Produce a partitioning plan document containing: the verdict (partition / stay single / shard) with the measured row count and on-disk size backing it, the chosen strategy and partition key with the hot WHERE clauses and retention policy that justify them, the composite-key and constraint changes required, the partition-creation automation mechanism, the retention operation (which partitions get dropped and when), the migration approach for the existing table, and the expected partition count over the table's lifetime.
Quality bar
- The recommendation is backed by an actual row count and size measurement, not an estimate.
- The partition key provably appears in the hot queries' WHERE clauses and matches the retention policy.
- "Do not partition" is a valid, expected outcome and must be stated plainly when the evidence supports it.
- Every Postgres unique/primary key in the plan includes the partition key.
Do NOT
- Do not partition a table that is small or merely missing an index.
- Do not choose a partition key absent from hot queries' WHERE clauses - it kills pruning.
- Do not partition on a high-churn updated column - it forces cross-partition row movement.
- Do not create thousands of partitions; planning time degrades.
- Do not leave partition creation manual - a missing future partition rejects writes.
- Do not jump to sharding before single-node partitioning is exhausted.
- Do not prescribe per-query index sets here - defer that to index-advisor.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

