Move data between shards online using the coordinator console
This guide covers manual rebalancing. It may be useful when you need full control
over which key ranges move and when.For automated redistribution of UUID-based distributions, you may take a look at redmon. Built-in auto-rebalancing is tracked in #1960.
The cluster is deployed with a coordinator (or via
spqrinfra). Data rebalancing is not available in
bare-router deployments that run without a
coordinator.
The destination shard is registered in the cluster and visible via SHOW shards.
See Deployment overview and
Coordinator for how shards are added.
Both spqrguard and postgres_fdw
extensions are installed on the source and destination shards.
spqrguard is added to shared_preload_libraries in postgresql.conf.
For an existing cluster, follow the complete
spqrguard rollout guide.
The coordinator has use_spqrguard: true. The
forbid_direct_shard_queries setting is not required for data transfers;
enable it only when direct writes to shards must also be blocked.
spqrguard is optional but strongly recommended. It prevents direct inserts
into shards that bypass SPQR, protecting against data corruption.
Rebalancing commands are executed against the coordinator’s administrative
console, not the router. Use psql over the PostgreSQL protocol as described in
How to connect.In high-availability setups, SPQR runs multiple coordinator instances, but only
one of them is active at a time (see
Coordinator configuration).
You can redistribute an entire key range in one go — there is no technical
limitation preventing it. In practice, however, it is common to split the
source key range into several smaller pieces first and move them one by one.
This gives you more control: you can monitor each piece independently, stop
at any point, and limit the impact on the running application.When in doubt, prefer smaller pieces — you can always
UNITE them later.
SPLIT KEY RANGE turns one
key range into two, splitting it at the given bound. Both resulting ranges
continue to point to the same shard until you explicitly redistribute one of
them.Example — splitting krid1 (covering 0..335000 on sh1) into four pieces:
SPLIT KEY RANGE krid1_b FROM krid1 BY 100000;-- krid1 = 0..100000, krid1_b = 100000..335000SPLIT KEY RANGE krid1_c FROM krid1_b BY 200000;-- krid1_b = 100000..200000, krid1_c = 200000..335000SPLIT KEY RANGE krid1_d FROM krid1_c BY 300000;-- krid1_c = 200000..300000, krid1_d = 300000..335000
5. Redistribute key ranges to the destination shard
Move the new key ranges with
REDISTRIBUTE KEY RANGE.
It migrates both the metadata and the actual data.
Internally the coordinator splits the source key range into batches of
BATCH SIZE rows and moves them one by one as separate move tasks, all
tracked under a single task group. While a batch is in flight, the rows it
covers are briefly unavailable for writes.
REDISTRIBUTE KEY RANGE krid1_b TO sh2 BATCH SIZE 1000 NOWAIT;REDISTRIBUTE KEY RANGE krid1_c TO sh2 BATCH SIZE 1000 NOWAIT;REDISTRIBUTE KEY RANGE krid1_d TO sh2 BATCH SIZE 1000 NOWAIT;
NOWAIT returns control immediately and lets you observe the task group
asynchronously; without it, the session blocks until the task group finishes.
Use the CHECK modifier if you want to validate the operation without
performing the move.
Run the redistribute on a single key range first and wait for it to complete
before launching the rest. This validates the path end-to-end at production
load before you commit to moving everything.
BATCH SIZE controls how many rows each move task transfers at a time. It is
a tradeoff:
Smaller batches — shorter per-batch unavailability, smoother impact on
the application, more total batches and therefore longer total wall-clock
time.
Larger batches — fewer round trips and faster overall, but each batch
locks a larger slice of the key range for longer.
There is no universal formula — the right batch size can only be found
empirically. Start with 500–1000 and adjust from there; depending on your
workload and data, you may end up anywhere up to 1000000. Monitor the
impact on the application (see the next section) and increase the batch size
as long as it remains acceptable.
SHOW task_group on the coordinator — current state of every task group
and its move tasks. Possible values for state are PLANNED, RUNNING and
ERROR; a task group disappears from the listing once it has finished
successfully.
Application error rate and latency — in particular client-visible 5xx
errors and write latency on the affected key range.
Shard load — CPU, disk and replication lag on both source and destination
shards.
If one redistribute starts misbehaving (for example, replication lag on the
destination shard is growing), stop just that task group and leave the others
running:
A failed task group can leave affected key ranges in a locked state.
While a key range is locked, any application query that touches it will
receive a key range is locked error. Do not manually unlock key ranges —
this is unsafe and can lead to data loss.
If a task group fails mid-flight:
Run SHOW task_group to identify the failed task group and its error.
Run SHOW key_ranges to see which key ranges are locked and where the
data currently lives.
Investigate why the task failed (check coordinator and shard logs).
Fix the underlying issue and RETRY TASK GROUP to let it finish — this
is the safest way to unlock the affected key ranges.
Every partial failure is different. There is no universal recovery recipe —
you need to understand the specific error and determine where the most
recent data resides before taking action.
Once all redistributes have finished, verify with SHOW key_ranges that the
layout matches what you expect and spot-check that data actually lives on the
right shards. If two adjacent key ranges now point to the same shard, you can
merge them with
UNITE KEY RANGE.
{"docsConfig":{"$schema":"https://mintlify.com/docs.json","theme":"mint","name":"SPQR","colors":{"primary":"#5382ff","light":"#e2ebff","dark":"#5382ff"},"favicon":"https://mintcdn.com/pg-shardingspqr/55SknXFsB6PObVk2/logo/spqr_icon-main.svg?fit=max\u0026auto=format\u0026n=55SknXFsB6PObVk2\u0026q=85\u0026s=d6c32807f9b0a07418733c3d548908d3","logo":{"light":"https://mintcdn.com/pg-shardingspqr/55SknXFsB6PObVk2/logo/spqr_icon-main.svg?fit=max\u0026auto=format\u0026n=55SknXFsB6PObVk2\u0026q=85\u0026s=d6c32807f9b0a07418733c3d548908d3","dark":"https://mintcdn.com/pg-shardingspqr/55SknXFsB6PObVk2/logo/spqr_icon-main.svg?fit=max\u0026auto=format\u0026n=55SknXFsB6PObVk2\u0026q=85\u0026s=d6c32807f9b0a07418733c3d548908d3","href":"https://pg-sharding.tech/"},"appearance":{"default":"light","strict":null},"navbar":{"primary":{"type":"github","href":"https://github.com/pg-sharding/spqr"}},"styling":{"latex":false},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"pg-shardingspqr","hasAudioNarration":false,"actualSubdomain":"pg-shardingspqr","customDomains":["docs.pg-sharding.tech"],"gitSource":{"type":"github","owner":"pg-sharding","repo":"spqr","deployBranch":"master","contentDirectory":"docs","isPrivate":false,"mountPath":"","label":""},"chroma":{"liveDeploymentHistoryId":"6ae34cd6af12d5279fa8389f","collectionId":"1d1ce3cd-bfbd-4327-881b-81bd5976a9ed","schemaVersion":"v3","latestBuiltDeploymentHistoryId":"6ae34cd6af12d5279fa8389f"},"feedback":{"thumbs":true,"edits":true},"entitlements":{},"buildId":"6ae34cd6af12d5279fa8389f","clientVersion":"0.0.4021","searchFilterCounts":[{"language":"default","tag":"Documentation","count":102},{"language":"default","tag":"Sharding","count":19},{"language":"default","tag":"Features","count":16},{"language":"default","tag":"Configuration Guide","count":6},{"language":"default","tag":"Deployment Guide","count":5},{"language":"default","tag":"Cluster Components","count":4},{"language":"default","tag":"Balancing","count":3},{"language":"default","tag":"Admin Console","count":3},{"language":"default","tag":"Query routing","count":1}]},"assistantConfig":{},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"pause-universal-search-reconcile","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"per-site-search-delta","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-private-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"byok-sep-25","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"vite-origin","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-updated-9-15","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[],"page":{"pagePath":"sharding/manual_rebalancing","slug":"/sharding/manual_rebalancing","pageMetadata":{"title":"Manual shard rebalancing","description":"Move data between shards online using the coordinator console","href":"/sharding/manual_rebalancing"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Move data between shards online using the coordinator console\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,em:`em`,li:`li`,ol:`ol`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Note,Tip,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Note)_missingMdxReference(`Note`,true);if(!Tip)_missingMdxReference(`Tip`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsxs(Warning,{children:[_jsx(_components.p,{children:`This guide covers manual rebalancing. It may be useful when you need full control\nover which key ranges move and when.`}),_jsxs(_components.p,{children:[`For automated redistribution of UUID-based distributions, you may take a look at `,_jsx(_components.a,{href:`https://github.com/pg-sharding/redmon`,children:`redmon`}),`. Built-in auto-rebalancing is tracked in `,_jsx(_components.a,{href:`https://github.com/pg-sharding/spqr/issues/1960`,children:`#1960`}),`.`]})]}),`\n`,_jsx(Heading,{level:`2`,id:`when-to-use-it`,children:`When to use it`}),`\n`,_jsx(_components.p,{children:`Use this flow when you need explicit control over what moves and when:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`Add a new empty shard and fill it with data from existing shards.`}),`\n`,_jsx(_components.li,{children:`Remove a shard — first move all its data elsewhere, then delete it.`}),`\n`,_jsx(_components.li,{children:`Quickly fix a hotspot (overloaded data range) without waiting for the balancer.`}),`\n`,_jsx(_components.li,{children:`Move a specific tenant’s data to a separate shard.`}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`prerequisites`,children:`Prerequisites`}),`\n`,_jsx(_components.p,{children:`Before starting, make sure that:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`The cluster is deployed with a `,_jsx(_components.strong,{children:`coordinator`}),` (or via\n`,_jsx(_components.a,{href:`/deployment/spqrinfra`,children:`spqrinfra`}),`). Data rebalancing is not available in\n`,_jsx(_components.a,{href:`/deployment/bare_router`,children:`bare-router`}),` deployments that run without a\ncoordinator.`]}),`\n`,_jsxs(_components.li,{children:[`The destination shard is registered in the cluster and visible via `,_jsx(_components.code,{children:`SHOW shards`}),`.\nSee `,_jsx(_components.a,{href:`/deployment/overview`,children:`Deployment overview`}),` and\n`,_jsx(_components.a,{href:`/sharding/cluster_components/coordinator`,children:`Coordinator`}),` for how shards are added.`]}),`\n`,_jsxs(_components.li,{children:[`Both `,_jsx(_components.a,{href:`https://github.com/pg-sharding/spqrguard`,children:_jsx(_components.code,{children:`spqrguard`})}),` and `,_jsx(_components.code,{children:`postgres_fdw`}),`\nextensions are installed on the source and destination shards.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`spqrguard`}),` is added to `,_jsx(_components.code,{children:`shared_preload_libraries`}),` in `,_jsx(_components.code,{children:`postgresql.conf`}),`.\nFor an existing cluster, follow the complete\n`,_jsx(_components.a,{href:`/deployment/spqrguard`,children:`spqrguard rollout guide`}),`.`]}),`\n`,_jsxs(_components.li,{children:[`The coordinator has `,_jsx(_components.code,{children:`use_spqrguard: true`}),`. The\n`,_jsx(_components.code,{children:`forbid_direct_shard_queries`}),` setting is not required for data transfers;\nenable it only when direct writes to shards must also be blocked.`]}),`\n`]}),`\n`,_jsx(Note,{children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`spqrguard`}),` is optional but strongly recommended. It prevents direct inserts\ninto shards that bypass SPQR, protecting against data corruption.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`1-connect-to-the-coordinator`,children:`1. Connect to the coordinator`}),`\n`,_jsxs(_components.p,{children:[`Rebalancing commands are executed against the coordinator’s administrative\nconsole, not the router. Use `,_jsx(_components.code,{children:`psql`}),` over the PostgreSQL protocol as described in\n`,_jsx(_components.a,{href:`/sharding/console/how_to_connect`,children:`How to connect`}),`.`]}),`\n`,_jsxs(_components.p,{children:[`In high-availability setups, SPQR runs multiple coordinator instances, but only\none of them is active at a time (see\n`,_jsx(_components.a,{href:`/configuration/coordinator`,children:`Coordinator configuration`}),`).`]}),`\n`,_jsx(Heading,{level:`2`,id:`2-inspect-the-current-topology`,children:`2. Inspect the current topology`}),`\n`,_jsx(_components.p,{children:`Check the shards and the current key range layout:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`14`,language:`sql`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`sql`,children:_jsxs(_components.code,{language:`sql`,numberOfLines:`14`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`SHOW shards;`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` shard | options `})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`-------+---------------------------------------------------------`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` sh1 | {host`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`spqr_shard_1:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`6432`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,host`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`spqr_shard_1_replica:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`6432`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` sh2 | {host`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`spqr_shard_2:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`6432`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,host`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`spqr_shard_2_replica:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`6432`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` sh3 | {host`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`spqr_shard_3:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`6432`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,host`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`spqr_shard_3_replica:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`6432`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`3`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` rows`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`SHOW key_ranges;`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` key_range_id | shard_id | distribution_id | lower_bound | locked`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`--------------+----------+-----------------+-------------+--------`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` krid1 | sh1 | ds1 | `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` | false`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` krid2 | sh2 | ds1 | `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`335000`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` | false`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` krid3 | sh3 | ds1 | `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`670000`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` | false`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`3-plan-the-splits`,children:`3. Plan the splits`}),`\n`,_jsx(_components.p,{children:`You can redistribute an entire key range in one go — there is no technical\nlimitation preventing it. In practice, however, it is common to split the\nsource key range into several smaller pieces first and move them one by one.\nThis gives you more control: you can monitor each piece independently, stop\nat any point, and limit the impact on the running application.`}),`\n`,_jsxs(_components.p,{children:[`When in doubt, prefer smaller pieces — you can always\n`,_jsx(_components.a,{href:`/sharding/console/sql_commands#unite-key-range`,children:`UNITE`}),` them later.`]}),`\n`,_jsx(Heading,{level:`2`,id:`4-split-the-source-key-range`,children:`4. Split the source key range`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.a,{href:`/sharding/console/sql_commands#split-key-range`,children:_jsx(_components.code,{children:`SPLIT KEY RANGE`})}),` turns one\nkey range into two, splitting it at the given bound. Both resulting ranges\ncontinue to point to the same shard until you explicitly redistribute one of\nthem.`]}),`\n`,_jsxs(_components.p,{children:[`Example — splitting `,_jsx(_components.code,{children:`krid1`}),` (covering `,_jsx(_components.code,{children:`0..335000`}),` on `,_jsx(_components.code,{children:`sh1`}),`) into four pieces:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`8`,language:`sql`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`sql`,children:_jsxs(_components.code,{language:`sql`,numberOfLines:`8`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`SPLIT `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`KEY`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` RANGE`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` krid1_b `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`FROM`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` krid1 `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`BY`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 100000`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`-- krid1 = 0..100000, krid1_b = 100000..335000`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`SPLIT `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`KEY`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` RANGE`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` krid1_c `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`FROM`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` krid1_b `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`BY`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 200000`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`-- krid1_b = 100000..200000, krid1_c = 200000..335000`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`SPLIT `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`KEY`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` RANGE`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` krid1_d `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`FROM`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` krid1_c `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`BY`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 300000`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`-- krid1_c = 200000..300000, krid1_d = 300000..335000`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`Verify with `,_jsx(_components.code,{children:`SHOW key_ranges`}),`.`]}),`\n`,_jsx(Heading,{level:`2`,id:`5-redistribute-key-ranges-to-the-destination-shard`,children:`5. Redistribute key ranges to the destination shard`}),`\n`,_jsxs(_components.p,{children:[`Move the new key ranges with\n`,_jsx(_components.a,{href:`/sharding/console/sql_commands#redistribute-key-range`,children:_jsx(_components.code,{children:`REDISTRIBUTE KEY RANGE`})}),`.\nIt migrates both the metadata and the actual data.\nInternally the coordinator splits the source key range into batches of\n`,_jsx(_components.code,{children:`BATCH SIZE`}),` rows and moves them one by one as separate `,_jsx(_components.em,{children:`move tasks`}),`, all\ntracked under a single `,_jsx(_components.em,{children:`task group`}),`. While a batch is in flight, the rows it\ncovers are briefly unavailable for writes.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`3`,language:`sql`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`sql`,children:_jsxs(_components.code,{language:`sql`,numberOfLines:`3`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`REDISTRIBUTE `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`KEY`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` RANGE`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` krid1_b `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`TO`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` sh2 BATCH `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`SIZE`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 1000`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` NOWAIT`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`REDISTRIBUTE `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`KEY`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` RANGE`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` krid1_c `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`TO`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` sh2 BATCH `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`SIZE`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 1000`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` NOWAIT`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`REDISTRIBUTE `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`KEY`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` RANGE`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` krid1_d `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`TO`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` sh2 BATCH `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`SIZE`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 1000`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` NOWAIT`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`NOWAIT`}),` returns control immediately and lets you observe the task group\nasynchronously; without it, the session blocks until the task group finishes.\nUse the `,_jsx(_components.code,{children:`CHECK`}),` modifier if you want to validate the operation without\nperforming the move.`]}),`\n`,_jsx(Tip,{children:_jsx(_components.p,{children:`Run the redistribute on a single key range first and wait for it to complete\nbefore launching the rest. This validates the path end-to-end at production\nload before you commit to moving everything.`})}),`\n`,_jsx(Heading,{level:`3`,id:`choosing-a-batch-size`,children:`Choosing a batch size`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`BATCH SIZE`}),` controls how many rows each move task transfers at a time. It is\na tradeoff:`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Smaller batches`}),` — shorter per-batch unavailability, smoother impact on\nthe application, more total batches and therefore longer total wall-clock\ntime.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Larger batches`}),` — fewer round trips and faster overall, but each batch\nlocks a larger slice of the key range for longer.`]}),`\n`]}),`\n`,_jsx(Tip,{children:_jsxs(_components.p,{children:[`There is no universal formula — the right batch size can only be found\nempirically. Start with `,_jsx(_components.code,{children:`500`}),`–`,_jsx(_components.code,{children:`1000`}),` and adjust from there; depending on your\nworkload and data, you may end up anywhere up to `,_jsx(_components.code,{children:`1000000`}),`. Monitor the\nimpact on the application (see the next section) and increase the batch size\nas long as it remains acceptable.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`6-monitor-the-move`,children:`6. Monitor the move`}),`\n`,_jsx(_components.p,{children:`While a redistribute is running, watch:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:_jsx(_components.code,{children:`SHOW task_group`})}),` on the coordinator — current state of every task group\nand its move tasks. Possible values for `,_jsx(_components.code,{children:`state`}),` are `,_jsx(_components.code,{children:`PLANNED`}),`, `,_jsx(_components.code,{children:`RUNNING`}),` and\n`,_jsx(_components.code,{children:`ERROR`}),`; a task group disappears from the listing once it has finished\nsuccessfully.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Application error rate and latency`}),` — in particular client-visible 5xx\nerrors and write latency on the affected key range.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Shard load`}),` — CPU, disk and replication lag on both source and destination\nshards.`]}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`7-react-to-problems`,children:`7. React to problems`}),`\n`,_jsx(_components.p,{children:`If something goes wrong during the rebalancing, follow this escalation order.`}),`\n`,_jsx(Heading,{level:`3`,id:`stop-the-problematic-task-group`,children:`Stop the problematic task group`}),`\n`,_jsx(_components.p,{children:`If one redistribute starts misbehaving (for example, replication lag on the\ndestination shard is growing), stop just that task group and leave the others\nrunning:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`sql`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`sql`,children:_jsxs(_components.code,{language:`sql`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`STOP`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` TASK GROUP `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`\u003c`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`task_group_id`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`>`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`To stop all task groups at once:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`sql`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`sql`,children:_jsxs(_components.code,{language:`sql`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`STOP`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` TASK GROUP ALL;`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`retry-if-the-issue-was-transient`,children:`Retry if the issue was transient`}),`\n`,_jsx(_components.p,{children:`If a task group ended up in an error state due to a transient issue (network\nblip, restarted shard, etc.), retry it:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`3`,language:`sql`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`sql`,children:_jsxs(_components.code,{language:`sql`,numberOfLines:`3`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`RETRY TASK GROUP `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`\u003c`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`task_group_id`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`>`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`-- or, asynchronously`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`RETRY TASK GROUP `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`\u003c`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`task_group_id`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`>`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` NOWAIT`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`recovering-from-partial-failure`,children:`Recovering from partial failure`}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`A failed task group can leave affected key ranges in a `,_jsx(_components.strong,{children:`locked`}),` state.\nWhile a key range is locked, any application query that touches it will\nreceive a `,_jsx(_components.code,{children:`key range is locked`}),` error. `,_jsx(_components.strong,{children:`Do not manually unlock key ranges`}),` —\nthis is unsafe and can lead to data loss.`]})}),`\n`,_jsx(_components.p,{children:`If a task group fails mid-flight:`}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsxs(_components.li,{children:[`Run `,_jsx(_components.code,{children:`SHOW task_group`}),` to identify the failed task group and its error.`]}),`\n`,_jsxs(_components.li,{children:[`Run `,_jsx(_components.code,{children:`SHOW key_ranges`}),` to see which key ranges are locked and where the\ndata currently lives.`]}),`\n`,_jsxs(_components.li,{children:[`Investigate `,_jsx(_components.strong,{children:`why`}),` the task failed (check coordinator and shard logs).`]}),`\n`,_jsxs(_components.li,{children:[`Fix the underlying issue and `,_jsx(_components.code,{children:`RETRY TASK GROUP`}),` to let it finish — this\nis the safest way to unlock the affected key ranges.`]}),`\n`]}),`\n`,_jsx(_components.p,{children:`Every partial failure is different. There is no universal recovery recipe —\nyou need to understand the specific error and determine where the most\nrecent data resides before taking action.`}),`\n`,_jsx(Heading,{level:`2`,id:`8-post-rebalancing-cleanup`,children:`8. Post-rebalancing cleanup`}),`\n`,_jsxs(_components.p,{children:[`Once all redistributes have finished, verify with `,_jsx(_components.code,{children:`SHOW key_ranges`}),` that the\nlayout matches what you expect and spot-check that data actually lives on the\nright shards. If two adjacent key ranges now point to the same shard, you can\nmerge them with\n`,_jsx(_components.a,{href:`/sharding/console/sql_commands#unite-key-range`,children:_jsx(_components.code,{children:`UNITE KEY RANGE`})}),`.`]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"Manual shard rebalancing","description":"Move data between shards online using the coordinator console","href":"/sharding/manual_rebalancing"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"When to use it","slug":"when-to-use-it","depth":2,"children":[]},{"title":"Prerequisites","slug":"prerequisites","depth":2,"children":[]},{"title":"1. Connect to the coordinator","slug":"1-connect-to-the-coordinator","depth":2,"children":[]},{"title":"2. Inspect the current topology","slug":"2-inspect-the-current-topology","depth":2,"children":[]},{"title":"3. Plan the splits","slug":"3-plan-the-splits","depth":2,"children":[]},{"title":"4. Split the source key range","slug":"4-split-the-source-key-range","depth":2,"children":[]},{"title":"5. Redistribute key ranges to the destination shard","slug":"5-redistribute-key-ranges-to-the-destination-shard","depth":2,"children":[{"title":"Choosing a batch size","slug":"choosing-a-batch-size","depth":3,"children":[]}]},{"title":"6. Monitor the move","slug":"6-monitor-the-move","depth":2,"children":[]},{"title":"7. React to problems","slug":"7-react-to-problems","depth":2,"children":[{"title":"Stop the problematic task group","slug":"stop-the-problematic-task-group","depth":3,"children":[]},{"title":"Retry if the issue was transient","slug":"retry-if-the-issue-was-transient","depth":3,"children":[]},{"title":"Recovering from partial failure","slug":"recovering-from-partial-failure","depth":3,"children":[]}]},{"title":"8. Post-rebalancing cleanup","slug":"8-post-rebalancing-cleanup","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"pg-shardingspqr","siteName":"SPQR","title":"Manual shard rebalancing - SPQR","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-08-17T12:34:16.192Z","originalFileLocation":"sharding/manual_rebalancing.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"light\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Move data between shards online using the coordinator console\">\u003cmeta data-mint-head name=\"application-name\" content=\"SPQR\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/pg-shardingspqr/nzsKKGyE6s8yEmTB/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/pg-shardingspqr/nzsKKGyE6s8yEmTB/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/pg-shardingspqr/nzsKKGyE6s8yEmTB/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/pg-shardingspqr/nzsKKGyE6s8yEmTB/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/pg-shardingspqr/nzsKKGyE6s8yEmTB/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/pg-shardingspqr/nzsKKGyE6s8yEmTB/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/pg-shardingspqr/nzsKKGyE6s8yEmTB/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/pg-shardingspqr/nzsKKGyE6s8yEmTB/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/pg-shardingspqr/nzsKKGyE6s8yEmTB/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Manual shard rebalancing - SPQR\">\u003cmeta data-mint-head property=\"og:description\" content=\"Move data between shards online using the coordinator console\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"SPQR\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.pg-sharding.tech/sharding/manual_rebalancing\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://pg-shardingspqr.mintlify.app/_mintlify/api/og/v2?division=Balancing\u0026amp;title=Manual+shard+rebalancing\u0026amp;description=Move+data+between+shards+online+using+the+coordinator+console\u0026amp;theme=e465a5f6c0c6956ccd8133e1\u0026amp;signature=ec27a9b42e1c93193530957f6182c4be5d863db19e46e8c649e08c2a11c28ea5\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Manual shard rebalancing - SPQR\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Move data between shards online using the coordinator console\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://pg-shardingspqr.mintlify.app/_mintlify/api/og/v2?division=Balancing\u0026amp;title=Manual+shard+rebalancing\u0026amp;description=Move+data+between+shards+online+using+the+coordinator+console\u0026amp;theme=e465a5f6c0c6956ccd8133e1\u0026amp;signature=ec27a9b42e1c93193530957f6182c4be5d863db19e46e8c649e08c2a11c28ea5\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/pg-shardingspqr/nzsKKGyE6s8yEmTB/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"SPQR\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#5382ff\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.pg-sharding.tech/sharding/manual_rebalancing\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/sharding/manual_rebalancing.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.pg-sharding.tech/#organization\",\"name\":\"SPQR\",\"url\":\"https://docs.pg-sharding.tech\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/pg-shardingspqr/55SknXFsB6PObVk2/logo/spqr_icon-main.svg?fit=max\u0026auto=format\u0026n=55SknXFsB6PObVk2\u0026q=85\u0026s=d6c32807f9b0a07418733c3d548908d3\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.pg-sharding.tech#website\",\"name\":\"SPQR\",\"url\":\"https://docs.pg-sharding.tech\",\"publisher\":{\"@id\":\"https://docs.pg-sharding.tech/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.pg-sharding.tech/sharding/manual_rebalancing#webpage\",\"url\":\"https://docs.pg-sharding.tech/sharding/manual_rebalancing\",\"name\":\"Manual shard rebalancing\",\"description\":\"Move data between shards online using the coordinator console\",\"dateModified\":\"2026-08-17T12:34:16.192Z\",\"isPartOf\":{\"@id\":\"https://docs.pg-sharding.tech#website\"},\"breadcrumb\":{\"@id\":\"https://docs.pg-sharding.tech/sharding/manual_rebalancing#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.pg-sharding.tech/sharding/manual_rebalancing#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Documentation\",\"item\":\"https://docs.pg-sharding.tech/welcome/index\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Sharding\",\"item\":\"https://docs.pg-sharding.tech/welcome/get_started\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Balancing\",\"item\":\"https://docs.pg-sharding.tech/sharding/balancing/overview\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Manual shard rebalancing\",\"item\":\"https://docs.pg-sharding.tech/sharding/manual_rebalancing\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.pg-sharding.tech/sharding/manual_rebalancing#article\",\"headline\":\"Manual shard rebalancing\",\"name\":\"Manual shard rebalancing\",\"description\":\"Move data between shards online using the coordinator console\",\"url\":\"https://docs.pg-sharding.tech/sharding/manual_rebalancing\",\"mainEntityOfPage\":{\"@id\":\"https://docs.pg-sharding.tech/sharding/manual_rebalancing#webpage\"},\"dateModified\":\"2026-08-17T12:34:16.192Z\",\"publisher\":{\"@id\":\"https://docs.pg-sharding.tech/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.pg-sharding.tech#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"SPQR\",\"creator\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","siteName":"SPQR","nav":{"global":null,"anchors":[{"anchor":"Documentation","icon":"book-open-cover","groups":[{"group":"Documentation","pages":[{"title":"Welcome to SPQR","href":"/welcome"},{"title":"Get Started","href":"/welcome/get_started"},{"group":"Features","pages":[{"title":"Sharding","href":"/features/sharding"},{"title":"Default shard","href":"/features/default_shard"},{"title":"Reference tables","href":"/features/reference_tables"},{"title":"Distributed Transactions","href":"/features/distributed_transactions"},{"title":"Transaction and session pooling","href":"/features/pooling"},{"title":"Fault Tolerance","href":"/features/fault_tolerance"},{"title":"Data Balancing","href":"/features/data_balancing"},{"title":"Cross-shard queries","href":"/features/cross_shard_queries"},{"title":"Multiple servers and failover","href":"/features/multiple_servers_and_failover"},{"title":"Works over PostgreSQL protocol","href":"/features/protocol"},{"title":"Dedicated read-only mode","href":"/features/read_only"},{"title":"Performance","href":"/features/performance"},{"title":"Various authentication types","href":"/features/authentication"},{"title":"Live configuration reloading","href":"/features/config_reloading"},{"title":"Statistics","href":"/features/statistics"},{"title":"Metrics","href":"/features/metrics"}]},{"group":"Deployment Guide","pages":[{"title":"Overview","href":"/deployment/overview"},{"title":"Router with Init SQL","href":"/deployment/bare_router"},{"title":"Router + Coordinator","href":"/deployment/router_coordinator"},{"title":"SPQR Infra Mode","href":"/deployment/spqrinfra"},{"title":"Prevent direct writes to shards","href":"/deployment/spqrguard"}]},{"group":"Configuration Guide","pages":[{"title":"Router","href":"/configuration/router"},{"title":"Virtual functions","href":"/configuration/virtual_function"},{"title":"Coordinator","href":"/configuration/coordinator"},{"title":"Balancer","href":"/configuration/balancer"},{"title":"Auth settings","href":"/configuration/auth"},{"title":"Roles settings","href":"/configuration/roles"}]},{"group":"Sharding","pages":[{"title":"Get Started","href":"/welcome/get_started"},{"title":"Direct key sharding","href":"/sharding/ranged"},{"title":"Hash-based sharding","href":"/sharding/hashed"},{"title":"Sharded Tables","href":"/sharding/sharded_tables"},{"title":"Reference Tables","href":"/sharding/reference_tables"},{"title":"Composite Sharding Keys","href":"/sharding/composite_keys"},{"title":"Distributed Transactions","href":"/sharding/distributed_transactions"},{"group":"Cluster Components","pages":[{"title":"Overview","href":"/sharding/cluster_components/overview"},{"title":"Shard","href":"/sharding/cluster_components/shard"},{"title":"Router","href":"/sharding/cluster_components/router"},{"title":"Coordinator","href":"/sharding/cluster_components/coordinator"}]},{"group":"Balancing","pages":[{"title":"Overview","href":"/sharding/balancing/overview"},{"title":"Details","description":null,"href":"/sharding/balancing/details"},{"title":"Manual shard rebalancing","href":"/sharding/manual_rebalancing"}]},{"group":"Admin Console","pages":[{"title":"How to connect","description":"SPQR router and coordinator admin console","href":"/sharding/console/how_to_connect"},{"title":"Concepts","href":"/sharding/console/concepts"},{"title":"SQL commands","href":"/sharding/console/sql_commands"}]},{"title":"Bulk Operations","href":"/sharding/bulk"},{"title":"Default shard","href":"/sharding/default_shard"}]},{"group":"Query routing","pages":[{"title":"Routing hints","href":"/routing/hints"}]},{"title":"Design Goals","href":"/welcome/design"},{"title":"Talks","href":"/welcome/talks"},{"title":"FAQ","href":"/welcome/faq"}]}]},{"anchor":"Community","href":"https://t.me/+jMGhyjwicpI3ZWQy","icon":"telegram"},{"anchor":"Releases","href":"https://github.com/pg-sharding/spqr/releases","icon":"clock"}]},"title":"Manual shard rebalancing - SPQR","buildId":"dpl_EnxDqhjaNc9a8MVa833TGULPd9uJ","deploymentId":"dpl_EnxDqhjaNc9a8MVa833TGULPd9uJ","dynamics":[],"chunks":[]}