Shard rebalancing in the Citus 10.1 extension to Postgres

Published Sep 03 2021 09:51 AM 1,061 Views
Microsoft

With the 10.1 release to the Citus extension to Postgres, you can now monitor the progress of an ongoing shard rebalance—plus you get performance optimizations, as well as some user experience improvements to the rebalancer, too.

 

Whether you use Citus open source to scale out Postgres, or you use Citus in the cloud, this post is your guide to what’s new with the shard rebalancer in Citus 10.1.

 

And if you’re wondering when you might need to use the shard rebalancer: the rebalancer is used when you add a new Postgres node to your existing Citus database cluster and you want to move some of the old data to this new node, to “balance” the cluster. There are also times you might want to balance shards across nodes in a Citus cluster in order to optimize performance. A common example of this is when you have a SaaS application and one of your customers/tenants has significant more activity than the rest.

 

And if you haven’t yet heard the exciting news: in Citus 10, earlier in 2021, we open sourced the shard rebalancer. My previous blog post explains more about what that change means for you.

 

Elephant-balancing-on-a-ball-against-a-purple-and-teal-background-1920x1080.jpg

 

Monitoring progress of a shard move

When you distribute a Postgres table with Citus, the table is usually distributed across multiple nodes. Often people refer to this as “sharding” the Postgres table across multiple nodes in a cluster. And in Citus-speak, these smaller components of the distributed table are called “shards”.

 

Once you start rebalancing shards, the rebalancer will tell you which shard it’s going to move. One of the most frequent questions some of you ask is: “how long will a shard move take?” The answer depends both on the amount of data on the shard that’s being moved and the speed at which this data is being moved: a shard rebalance might take minutes, hours, or even days to complete.

 

With Citus 10.1, it’s now easy for you to monitor the progress of the rebalance. While monitoring the progress won’t directly tell you exactly how long the rebalance will take, the good news is that you’ll be able to see that the rebalance is still progressing and roughly how far along it is.

 

To see the progress, you can use the get_rebalance_progress function. This function already existed in previous Citus versions, but in the Citus 10.1 release it has been made much more useful: get_rebalance_progress will now tell you the size of the shard on both the source and target node! To view this information you can run the following query (in a different session than the one in which you are running the rebalance itself):

 

SELECT * FROM get_rebalance_progress();
┌───────────┬────────────┬─────────┬────────────┬────────────┬────────────┬────────────┬────────────┬──────────┬───────────────────┬───────────────────┐
│ sessionid │ table_name │ shardid │ shard_size │ sourcename │ sourceport │ targetname │ targetport │ progress │ source_shard_size │ target_shard_size │
├───────────┼────────────┼─────────┼────────────┼────────────┼────────────┼────────────┼────────────┼──────────┼───────────────────┼───────────────────┤
│     13524 │ customers  │  102008 │   46718976 │ localhost  │       9701 │ localhost  │       9702 │        2 │          46686208 │          46718976 │
│     13524 │ orders     │  102024 │   52355072 │ localhost  │       9701 │ localhost  │       9702 │        2 │          52322304 │          52355072 │
│     13524 │ customers  │  102012 │   46628864 │ localhost  │       9701 │ localhost  │       9703 │        2 │          46604288 │          46628864 │
│     13524 │ orders     │  102028 │   52264960 │ localhost  │       9701 │ localhost  │       9703 │        2 │          52232192 │          52264960 │
│     13524 │ customers  │  102016 │   46669824 │ localhost  │       9701 │ localhost  │       9704 │        1 │          46669824 │          46702592 │
│     13524 │ orders     │  102032 │   52297728 │ localhost  │       9701 │ localhost  │       9704 │        1 │          52297728 │                 0 │
│     13524 │ customers  │  102020 │   46702592 │ localhost  │       9701 │ localhost  │       9702 │        0 │          46702592 │                 0 │
│     13524 │ orders     │  102036 │   52338688 │ localhost  │       9701 │ localhost  │       9702 │        0 │          52338688 │                 0 │
└───────────┴────────────┴─────────┴────────────┴────────────┴────────────┴────────────┴────────────┴──────────┴───────────────────┴───────────────────┘

 

The values in the progress column have the following meaning:
0: Not yet started
1: In progress
2: Finished

 

Using this knowledge, you can use the following SQL query to zoom in on the progress of the shard moves that the Citus shard rebalancer is currently doing, using the following queries:

 

-- To show the progress for each shard that's currently being moved
SELECT
    table_name,
    shardid,
    pg_size_pretty(source_shard_size) AS  source_shard_size,
    pg_size_pretty(target_shard_size) AS target_shard_size,
    CASE WHEN shard_size = 0
        THEN 100
        ELSE LEAST(round(target_shard_size::numeric / shard_size * 100, 2), 100)
    END AS percent_completed_estimate
FROM get_rebalance_progress()
WHERE progress = 1;
┌────────────┬─────────┬───────────────────┬───────────────────┬────────────────────────────┐
│ table_name │ shardid │ source_shard_size │ target_shard_size │ percent_completed_estimate │
├────────────┼─────────┼───────────────────┼───────────────────┼────────────────────────────┤
│ customers  │  102013 │ 44 MB             │ 44 MB             │                        100 │
│ orders     │  102029 │ 50 MB             │ 23 MB             │                      45.85 │
└────────────┴─────────┴───────────────────┴───────────────────┴────────────────────────────┘

-- To show the progress for the colocation group that's being moved as a whole
SELECT
   pg_size_pretty(sum(source_shard_size)) AS source_shard_size,
   pg_size_pretty(sum(target_shard_size)) AS target_shard_size,
   CASE WHEN sum(shard_size) = 0
     THEN 100
     ELSE LEAST(round(sum(target_shard_size)::numeric / sum(shard_size) * 100, 2), 100)
   END AS percent_completed_estimate
FROM get_rebalance_progress()
WHERE progress = 1;
┌───────────────────┬───────────────────┬────────────────────────────┐
│ source_shard_size │ target_shard_size │ percent_completed_estimate │
├───────────────────┼───────────────────┼────────────────────────────┤
│ 95 MB             │ 45 MB             │                      47.15 │
└───────────────────┴───────────────────┴────────────────────────────┘

 

Using the percent_completed_estimate you can get a rough indication of how long the move of a shard will take by doing some basic math yourself. If the percent_completed_estimate went from 30% to 40% in 10 minutes then the rate at which the shard move is happening is 10% per 10 minutes. Since there’s still 60% left, it means that you will have to wait roughly 60 minutes for the shard move to complete. However, there are some important caveats that can make this time estimate imprecise in some cases:

 

  • The percent_completed_estimate column in this query is more of a rough indication than a precise progress bar. Why? It’s possible that after the move, the shard will be smaller than before—because by moving the data, a Postgres VACUUM was essentially run on the table. So, the percent_completed_estimate might not be able to reach 100% because the shard is now smaller in size than it was originally.
  • If one shard seems to be stuck, but another shard is still making progress, chances are that the shard that seems stuck is already finished with the data transfer. If you’re wondering why such a shard is still marked as “in progress”: it’s because a shard won’t be marked as “finished” until all of the shards it is colocated with have also been moved successfully.
  • There’s another important thing to keep in mind when you’re looking at the shard rebalancer progress: At the end of the rebalance, indexes are created. Index creation can also take a long time, although the data transfer usually takes longer. Sadly, there’s currently no indication of the progress during index creation in the progress monitor output.

 

What this means for you: Don’t stop the rebalancer right away if you think there’s no progress, even if all shards are almost finished with the transfer. If you have Postgres indexes on your Citus table, it’s very likely you’ll just have to wait a bit longer until the indexes are finished creating. If you want to be sure that this is what’s going on, the easiest way to confirm is to connect directly to the Citus worker node and look at pg_stat_activity. If there’s a CREATE INDEX query running, then there’s a very good chance that the rebalancer is currently very busy creating your Postgres indexes.

 

Optimizing how shard rebalancing works with Postgres partitioning

Similar to Postgres query planning, the first thing that the shard rebalancer does when rebalancing is to figure out a plan for where to move each shard. To build this plan, the rebalancer needs the sizes of your shards on disk. In previous versions of Citus, getting these sizes could become very slow when a cluster contained thousands of shards. This situation mostly happened when a cluster contained partitioned tables, because Postgres partitions often cause a lot of shards to be created (one for each partition). As of 10.1, the way the rebalancer gets the shard sizes is optimized, making this operation fast even when there are tons of shards in the cluster.

 

Checking that there’s space on the target node

Running out of disk is one of the worst things that can happen to a Postgres server. When that happens, Postgres will crash. The only way to start Postgres again is to either get a larger disk or remove unnecessary files, such as log files.

 

The shard rebalancer often moves big chunks of data across nodes in the distributed cluster. That’s why we added a new safety feature to the shard rebalancer: before actually moving a shard, the Citus rebalancer will first check if there’s enough space on the target node to actually store it (plus some margin for safety).

 

Deferred dropping of shards by default

Citus 10.1 also solves an annoying issue that some of you may have run into: Prior to Citus 10.1, a shard move would sometimes be cancelled and rolled back right when the move would normally finish. Why? After moving all the data, the rebalancer used to drop the shard on the source node. However, when other queries were still reading or writing to this shard, the deletion could result in a distributed deadlock. This deadlock would only happen with transactions that were highly concurrent, and when you had acquired locks in the reverse order within a very short time window.

 

We have now enabled deferred dropping of shards by default, which makes sure such deadlocks do not occur. Deferred dropping means that instead of dropping the shard on the old node right away, shards are only marked for deletion. Then after a while, only after all the read queries have finished, will the shard actually be dropped. We call such a shard that is waiting to be dropped an “orphaned shard”.

 

This feature is not strictly new in Citus 10.1. It was already possible to enable this in previous versions by setting citus.defer_drop_after_shard_move to true. However, when not used with care, the previous implementation could result in confusing errors. This release we spent on hardening this feature and improving all of the error messages so they make sense. That’s why deferred dropping is now turned on by default—because we’re now confident that it works as well as we want it to.

 

The Citus shard rebalancer in 10.1: happier, faster, and with a way to monitor

With Citus 10.1, you will be much happier when using the shard rebalancer to balance the data sizes across the nodes in your cluster. Your shards will be moved faster. You can see the progress being made. And finally, your shard moves will not be rolled back anymore because Citus avoids the distributed deadlocks I mentioned earlier.

 

If you want to learn more about the Citus rebalancer (recently made open source!) you might want to check out my previous post or check out the Hyperscale (Citus) docs on the shard rebalancer and the rebalancer strategies.

 

If you’re new to Citus, you can find a good collection of getting started resources online here. And as always if you have any questions, you can find me and the rest of the Citus engineers—and other users, too—on our Citus slack.


This post by Jelte Fennema about the shard rebalancer was originally published on the Citus Blog.

 

%3CLINGO-SUB%20id%3D%22lingo-sub-2712133%22%20slang%3D%22en-US%22%3EShard%20rebalancing%20in%20the%20Citus%2010.1%20extension%20to%20Postgres%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2712133%22%20slang%3D%22en-US%22%3E%3CP%20class%3D%22pg-section%22%3EWith%20the%20%3CA%20href%3D%22https%3A%2F%2Fwww.citusdata.com%2Fblog%2F2021%2F07%2F30%2Fcitus-10-1-extension-to-postgres-whats-new%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3E10.1%20release%3C%2FA%3E%20to%20the%20Citus%20extension%20to%20Postgres%2C%20you%20can%20now%20monitor%20the%20progress%20of%20an%20ongoing%20shard%20rebalance%E2%80%94plus%20you%20get%20performance%20optimizations%2C%20as%20well%20as%20some%20user%20experience%20improvements%20to%20the%20rebalancer%2C%20too.%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%22%3EWhether%20you%20use%20Citus%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fcitusdata%2Fcitus%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Eopen%20source%3C%2FA%3E%20to%20scale%20out%20Postgres%2C%20or%20you%20use%20%3CA%20href%3D%22https%3A%2F%2Fwww.citusdata.com%2Fproduct%2Fhyperscale-citus%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3ECitus%20in%20the%20cloud%3C%2FA%3E%2C%20%3CSTRONG%3Ethis%20post%20is%20your%20guide%20to%20what%E2%80%99s%20new%20with%20the%20shard%20rebalancer%20in%20Citus%2010.1%3C%2FSTRONG%3E.%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%22%3EAnd%20if%20you%E2%80%99re%20wondering%20when%20you%20might%20need%20to%20use%20the%20shard%20rebalancer%3A%20the%20rebalancer%20is%20used%20when%20you%20add%20a%20new%20Postgres%20node%20to%20your%20existing%20Citus%20database%20cluster%20and%20you%20want%20to%20move%20some%20of%20the%20old%20data%20to%20this%20new%20node%2C%20to%20%E2%80%9Cbalance%E2%80%9D%20the%20cluster.%20There%20are%20also%20times%20you%20might%20want%20to%20balance%20shards%20across%20nodes%20in%20a%20Citus%20cluster%20in%20order%20to%20optimize%20performance.%20A%20common%20example%20of%20this%20is%20when%20you%20have%20a%20SaaS%20application%20and%20one%20of%20your%20customers%2Ftenants%20has%20significant%20more%20activity%20than%20the%20rest.%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%22%3EAnd%20if%20you%20haven%E2%80%99t%20yet%20heard%20the%20exciting%20news%3A%20in%20Citus%2010%2C%20earlier%20in%202021%2C%20we%20%3CA%20href%3D%22https%3A%2F%2Fwww.citusdata.com%2Fblog%2F2021%2F03%2F13%2Fscaling-out-postgres-with-citus-open-source-shard-rebalancer%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Eopen%20sourced%20the%20shard%20rebalancer%3C%2FA%3E.%20My%20previous%20blog%20post%20explains%20more%20about%20what%20that%20change%20means%20for%20you.%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Elephant-balancing-on-a-ball-against-a-purple-and-teal-background-1920x1080.jpg%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F307826i59B3D2C4B9E0765E%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Elephant-balancing-on-a-ball-against-a-purple-and-teal-background-1920x1080.jpg%22%20alt%3D%22Elephant-balancing-on-a-ball-against-a-purple-and-teal-background-1920x1080.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--356203637%22%20id%3D%22toc-hId--356046803%22%3EMonitoring%20progress%20of%20a%20shard%20move%3C%2FH2%3E%0A%3CP%20class%3D%22pg-section%22%3EWhen%20you%20distribute%20a%20Postgres%20table%20with%20Citus%2C%20the%20table%20is%20usually%20distributed%20across%20multiple%20nodes.%20Often%20people%20refer%20to%20this%20as%20%E2%80%9Csharding%E2%80%9D%20the%20Postgres%20table%20across%20multiple%20nodes%20in%20a%20cluster.%20And%20in%20Citus-speak%2C%20these%20smaller%20components%20of%20the%20distributed%20table%20are%20called%20%E2%80%9Cshards%E2%80%9D.%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%22%3EOnce%20you%20start%20rebalancing%20shards%2C%20the%20rebalancer%20will%20tell%20you%20which%20shard%20it%E2%80%99s%20going%20to%20move.%20One%20of%20the%20most%20frequent%20questions%20some%20of%20you%20ask%20is%3A%20%3CSTRONG%3E%E2%80%9Chow%20long%20will%20a%20shard%20move%20take%3F%E2%80%9D%3C%2FSTRONG%3E%20The%20answer%20depends%20both%20on%20the%20amount%20of%20data%20on%20the%20shard%20that%E2%80%99s%20being%20moved%20and%20the%20speed%20at%20which%20this%20data%20is%20being%20moved%3A%20a%20shard%20rebalance%20might%20take%20minutes%2C%20hours%2C%20or%20even%20days%20to%20complete.%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%22%3EWith%20Citus%2010.1%2C%20it%E2%80%99s%20now%20easy%20for%20you%20to%20monitor%20the%20progress%20of%20the%20rebalance.%20While%20monitoring%20the%20progress%20won%E2%80%99t%20directly%20tell%20you%20exactly%20how%20long%20the%20rebalance%20will%20take%2C%20the%20good%20news%20is%20that%20you%E2%80%99ll%20be%20able%20to%20see%20that%20the%20rebalance%20is%20still%20progressing%20and%20roughly%20how%20far%20along%20it%20is.%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%22%3ETo%20see%20the%20progress%2C%20you%20can%20use%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Eget_rebalance_progress%3C%2FCODE%3Efunction.%20This%20function%20already%20existed%20in%20previous%20Citus%20versions%2C%20but%20in%20the%20Citus%2010.1%20release%20it%20has%20been%20made%20much%20more%20useful%3A%3CCODE%20style%3D%22color%3A%20black%3B%22%3Eget_rebalance_progress%3C%2FCODE%3Ewill%20now%20tell%20you%20the%20size%20of%20the%20shard%20on%20both%20the%20source%20and%20target%20node!%20To%20view%20this%20information%20you%20can%20run%20the%20following%20query%20(in%20a%20different%20session%20than%20the%20one%20in%20which%20you%20are%20running%20the%20rebalance%20itself)%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ESELECT%20*%20FROM%20get_rebalance_progress()%3B%0A%E2%94%8C%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%AC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%AC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%AC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%AC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%AC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%AC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%AC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%AC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%AC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%AC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%90%0A%E2%94%82%20sessionid%20%E2%94%82%20table_name%20%E2%94%82%20shardid%20%E2%94%82%20shard_size%20%E2%94%82%20sourcename%20%E2%94%82%20sourceport%20%E2%94%82%20targetname%20%E2%94%82%20targetport%20%E2%94%82%20progress%20%E2%94%82%20source_shard_size%20%E2%94%82%20target_shard_size%20%E2%94%82%0A%E2%94%9C%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%BC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%BC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%BC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%BC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%BC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%BC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%BC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%BC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%BC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%BC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%A4%0A%E2%94%82%20%20%20%20%2013524%20%E2%94%82%20customers%20%20%E2%94%82%20%20102008%20%E2%94%82%20%20%2046718976%20%E2%94%82%20localhost%20%20%E2%94%82%20%20%20%20%20%20%209701%20%E2%94%82%20localhost%20%20%E2%94%82%20%20%20%20%20%20%209702%20%E2%94%82%20%20%20%20%20%20%20%202%20%E2%94%82%20%20%20%20%20%20%20%20%20%2046686208%20%E2%94%82%20%20%20%20%20%20%20%20%20%2046718976%20%E2%94%82%0A%E2%94%82%20%20%20%20%2013524%20%E2%94%82%20orders%20%20%20%20%20%E2%94%82%20%20102024%20%E2%94%82%20%20%2052355072%20%E2%94%82%20localhost%20%20%E2%94%82%20%20%20%20%20%20%209701%20%E2%94%82%20localhost%20%20%E2%94%82%20%20%20%20%20%20%209702%20%E2%94%82%20%20%20%20%20%20%20%202%20%E2%94%82%20%20%20%20%20%20%20%20%20%2052322304%20%E2%94%82%20%20%20%20%20%20%20%20%20%2052355072%20%E2%94%82%0A%E2%94%82%20%20%20%20%2013524%20%E2%94%82%20customers%20%20%E2%94%82%20%20102012%20%E2%94%82%20%20%2046628864%20%E2%94%82%20localhost%20%20%E2%94%82%20%20%20%20%20%20%209701%20%E2%94%82%20localhost%20%20%E2%94%82%20%20%20%20%20%20%209703%20%E2%94%82%20%20%20%20%20%20%20%202%20%E2%94%82%20%20%20%20%20%20%20%20%20%2046604288%20%E2%94%82%20%20%20%20%20%20%20%20%20%2046628864%20%E2%94%82%0A%E2%94%82%20%20%20%20%2013524%20%E2%94%82%20orders%20%20%20%20%20%E2%94%82%20%20102028%20%E2%94%82%20%20%2052264960%20%E2%94%82%20localhost%20%20%E2%94%82%20%20%20%20%20%20%209701%20%E2%94%82%20localhost%20%20%E2%94%82%20%20%20%20%20%20%209703%20%E2%94%82%20%20%20%20%20%20%20%202%20%E2%94%82%20%20%20%20%20%20%20%20%20%2052232192%20%E2%94%82%20%20%20%20%20%20%20%20%20%2052264960%20%E2%94%82%0A%E2%94%82%20%20%20%20%2013524%20%E2%94%82%20customers%20%20%E2%94%82%20%20102016%20%E2%94%82%20%20%2046669824%20%E2%94%82%20localhost%20%20%E2%94%82%20%20%20%20%20%20%209701%20%E2%94%82%20localhost%20%20%E2%94%82%20%20%20%20%20%20%209704%20%E2%94%82%20%20%20%20%20%20%20%201%20%E2%94%82%20%20%20%20%20%20%20%20%20%2046669824%20%E2%94%82%20%20%20%20%20%20%20%20%20%2046702592%20%E2%94%82%0A%E2%94%82%20%20%20%20%2013524%20%E2%94%82%20orders%20%20%20%20%20%E2%94%82%20%20102032%20%E2%94%82%20%20%2052297728%20%E2%94%82%20localhost%20%20%E2%94%82%20%20%20%20%20%20%209701%20%E2%94%82%20localhost%20%20%E2%94%82%20%20%20%20%20%20%209704%20%E2%94%82%20%20%20%20%20%20%20%201%20%E2%94%82%20%20%20%20%20%20%20%20%20%2052297728%20%E2%94%82%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%200%20%E2%94%82%0A%E2%94%82%20%20%20%20%2013524%20%E2%94%82%20customers%20%20%E2%94%82%20%20102020%20%E2%94%82%20%20%2046702592%20%E2%94%82%20localhost%20%20%E2%94%82%20%20%20%20%20%20%209701%20%E2%94%82%20localhost%20%20%E2%94%82%20%20%20%20%20%20%209702%20%E2%94%82%20%20%20%20%20%20%20%200%20%E2%94%82%20%20%20%20%20%20%20%20%20%2046702592%20%E2%94%82%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%200%20%E2%94%82%0A%E2%94%82%20%20%20%20%2013524%20%E2%94%82%20orders%20%20%20%20%20%E2%94%82%20%20102036%20%E2%94%82%20%20%2052338688%20%E2%94%82%20localhost%20%20%E2%94%82%20%20%20%20%20%20%209701%20%E2%94%82%20localhost%20%20%E2%94%82%20%20%20%20%20%20%209702%20%E2%94%82%20%20%20%20%20%20%20%200%20%E2%94%82%20%20%20%20%20%20%20%20%20%2052338688%20%E2%94%82%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%200%20%E2%94%82%0A%E2%94%94%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%B4%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%B4%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%B4%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%B4%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%B4%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%B4%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%B4%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%B4%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%B4%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%B4%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%98%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%22%3EThe%20values%20in%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Eprogress%3C%2FCODE%3Ecolumn%20have%20the%20following%20meaning%3A%3CBR%20%2F%3E0%3A%20Not%20yet%20started%3CBR%20%2F%3E1%3A%20In%20progress%3CBR%20%2F%3E2%3A%20Finished%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%22%3EUsing%20this%20knowledge%2C%20you%20can%20use%20the%20following%20SQL%20query%20to%20zoom%20in%20on%20the%20progress%20of%20the%20shard%20moves%20that%20the%20Citus%20shard%20rebalancer%20is%20currently%20doing%2C%20using%20the%20following%20queries%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3E--%20To%20show%20the%20progress%20for%20each%20shard%20that's%20currently%20being%20moved%0ASELECT%0A%20%20%20%20table_name%2C%0A%20%20%20%20shardid%2C%0A%20%20%20%20pg_size_pretty(source_shard_size)%20AS%20%20source_shard_size%2C%0A%20%20%20%20pg_size_pretty(target_shard_size)%20AS%20target_shard_size%2C%0A%20%20%20%20CASE%20WHEN%20shard_size%20%3D%200%0A%20%20%20%20%20%20%20%20THEN%20100%0A%20%20%20%20%20%20%20%20ELSE%20LEAST(round(target_shard_size%3A%3Anumeric%20%2F%20shard_size%20*%20100%2C%202)%2C%20100)%0A%20%20%20%20END%20AS%20percent_completed_estimate%0AFROM%20get_rebalance_progress()%0AWHERE%20progress%20%3D%201%3B%0A%E2%94%8C%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%AC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%AC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%AC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%AC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%90%0A%E2%94%82%20table_name%20%E2%94%82%20shardid%20%E2%94%82%20source_shard_size%20%E2%94%82%20target_shard_size%20%E2%94%82%20percent_completed_estimate%20%E2%94%82%0A%E2%94%9C%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%BC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%BC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%BC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%BC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%A4%0A%E2%94%82%20customers%20%20%E2%94%82%20%20102013%20%E2%94%82%2044%20MB%20%20%20%20%20%20%20%20%20%20%20%20%20%E2%94%82%2044%20MB%20%20%20%20%20%20%20%20%20%20%20%20%20%E2%94%82%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20100%20%E2%94%82%0A%E2%94%82%20orders%20%20%20%20%20%E2%94%82%20%20102029%20%E2%94%82%2050%20MB%20%20%20%20%20%20%20%20%20%20%20%20%20%E2%94%82%2023%20MB%20%20%20%20%20%20%20%20%20%20%20%20%20%E2%94%82%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2045.85%20%E2%94%82%0A%E2%94%94%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%B4%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%B4%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%B4%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%B4%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%98%0A%0A--%20To%20show%20the%20progress%20for%20the%20colocation%20group%20that's%20being%20moved%20as%20a%20whole%0ASELECT%0A%20%20%20pg_size_pretty(sum(source_shard_size))%20AS%20source_shard_size%2C%0A%20%20%20pg_size_pretty(sum(target_shard_size))%20AS%20target_shard_size%2C%0A%20%20%20CASE%20WHEN%20sum(shard_size)%20%3D%200%0A%20%20%20%20%20THEN%20100%0A%20%20%20%20%20ELSE%20LEAST(round(sum(target_shard_size)%3A%3Anumeric%20%2F%20sum(shard_size)%20*%20100%2C%202)%2C%20100)%0A%20%20%20END%20AS%20percent_completed_estimate%0AFROM%20get_rebalance_progress()%0AWHERE%20progress%20%3D%201%3B%0A%E2%94%8C%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%AC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%AC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%90%0A%E2%94%82%20source_shard_size%20%E2%94%82%20target_shard_size%20%E2%94%82%20percent_completed_estimate%20%E2%94%82%0A%E2%94%9C%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%BC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%BC%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%A4%0A%E2%94%82%2095%20MB%20%20%20%20%20%20%20%20%20%20%20%20%20%E2%94%82%2045%20MB%20%20%20%20%20%20%20%20%20%20%20%20%20%E2%94%82%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2047.15%20%E2%94%82%0A%E2%94%94%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%B4%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%B4%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%98%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%22%3EUsing%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Epercent_completed_estimate%3C%2FCODE%3Eyou%20can%20get%20a%20rough%20indication%20of%20how%20long%20the%20move%20of%20a%20shard%20will%20take%20by%20doing%20some%20basic%20math%20yourself.%20If%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Epercent_completed_estimate%3C%2FCODE%3Ewent%20from%2030%25%20to%2040%25%20in%2010%20minutes%20then%20the%20rate%20at%20which%20the%20shard%20move%20is%20happening%20is%2010%25%20per%2010%20minutes.%20Since%20there%E2%80%99s%20still%2060%25%20left%2C%20it%20means%20that%20you%20will%20have%20to%20wait%20roughly%2060%20minutes%20for%20the%20shard%20move%20to%20complete.%20%3CSTRONG%3EHowever%2C%20there%20are%20some%20important%20caveats%20that%20can%20make%20this%20time%20estimate%20imprecise%20in%20some%20cases%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%20class%3D%22pg-section%22%3E%0A%3CLI%3EThe%3CCODE%20style%3D%22color%3A%20black%3B%22%3Epercent_completed_estimate%3C%2FCODE%3Ecolumn%20in%20this%20query%20is%20more%20of%20a%20rough%20indication%20than%20a%20precise%20progress%20bar.%20Why%3F%20It%E2%80%99s%20possible%20that%20after%20the%20move%2C%20the%20shard%20will%20be%20smaller%20than%20before%E2%80%94because%20by%20moving%20the%20data%2C%20a%20Postgres%20VACUUM%20was%20essentially%20run%20on%20the%20table.%20So%2C%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Epercent_completed_estimate%3C%2FCODE%3Emight%20not%20be%20able%20to%20reach%20100%25%20because%20the%20shard%20is%20now%20smaller%20in%20size%20than%20it%20was%20originally.%3C%2FLI%3E%0A%3CLI%3EIf%20one%20shard%20seems%20to%20be%20stuck%2C%20but%20another%20shard%20is%20still%20making%20progress%2C%20chances%20are%20that%20the%20shard%20that%20seems%20stuck%20is%20already%20finished%20with%20the%20data%20transfer.%20If%20you%E2%80%99re%20wondering%20why%20such%20a%20shard%20is%20still%20marked%20as%20%E2%80%9Cin%20progress%E2%80%9D%3A%20it%E2%80%99s%20because%20a%20shard%20won%E2%80%99t%20be%20marked%20as%20%E2%80%9Cfinished%E2%80%9D%20until%20all%20of%20the%20shards%20it%20is%20colocated%20with%20have%20also%20been%20moved%20successfully.%3C%2FLI%3E%0A%3CLI%3EThere%E2%80%99s%20another%20important%20thing%20to%20keep%20in%20mind%20when%20you%E2%80%99re%20looking%20at%20the%20shard%20rebalancer%20progress%3A%20At%20the%20end%20of%20the%20rebalance%2C%20indexes%20are%20created.%20Index%20creation%20can%20also%20take%20a%20long%20time%2C%20although%20the%20data%20transfer%20usually%20takes%20longer.%20Sadly%2C%20there%E2%80%99s%20currently%20no%20indication%20of%20the%20progress%20during%20index%20creation%20in%20the%20progress%20monitor%20output.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%22%3EWhat%20this%20means%20for%20you%3A%20Don%E2%80%99t%20stop%20the%20rebalancer%20right%20away%20if%20you%20think%20there%E2%80%99s%20no%20progress%2C%20even%20if%20all%20shards%20are%20almost%20finished%20with%20the%20transfer.%20If%20you%20have%20Postgres%20indexes%20on%20your%20Citus%20table%2C%20it%E2%80%99s%20very%20likely%20you%E2%80%99ll%20just%20have%20to%20wait%20a%20bit%20longer%20until%20the%20indexes%20are%20finished%20creating.%20If%20you%20want%20to%20be%20sure%20that%20this%20is%20what%E2%80%99s%20going%20on%2C%20the%20easiest%20way%20to%20confirm%20is%20to%20connect%20directly%20to%20the%20Citus%20worker%20node%20and%20look%20at%3CCODE%20style%3D%22color%3A%20black%3B%22%3Epg_stat_activity%3C%2FCODE%3E.%20If%20there%E2%80%99s%20a%3CCODE%20style%3D%22color%3A%20black%3B%22%3ECREATE%20INDEX%3C%2FCODE%3Equery%20running%2C%20then%20there%E2%80%99s%20a%20very%20good%20chance%20that%20the%20rebalancer%20is%20currently%20very%20busy%20creating%20your%20Postgres%20indexes.%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-2131309196%22%20id%3D%22toc-hId-2131466030%22%3EOptimizing%20how%20shard%20rebalancing%20works%20with%20Postgres%20partitioning%3C%2FH2%3E%0A%3CP%20class%3D%22pg-section%22%3ESimilar%20to%20Postgres%20query%20planning%2C%20the%20first%20thing%20that%20the%20shard%20rebalancer%20does%20when%20rebalancing%20is%20to%20figure%20out%20a%20plan%20for%20where%20to%20move%20each%20shard.%20To%20build%20this%20plan%2C%20the%20rebalancer%20needs%20the%20sizes%20of%20your%20shards%20on%20disk.%20In%20previous%20versions%20of%20Citus%2C%20getting%20these%20sizes%20could%20become%20very%20slow%20when%20a%20cluster%20contained%20thousands%20of%20shards.%20This%20situation%20mostly%20happened%20when%20a%20cluster%20contained%20partitioned%20tables%2C%20because%20Postgres%20partitions%20often%20cause%20a%20lot%20of%20shards%20to%20be%20created%20(one%20for%20each%20partition).%20As%20of%2010.1%2C%20the%20way%20the%20rebalancer%20gets%20the%20shard%20sizes%20is%20optimized%2C%20making%20this%20operation%20fast%20even%20when%20there%20are%20tons%20of%20shards%20in%20the%20cluster.%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-323854733%22%20id%3D%22toc-hId-324011567%22%3EChecking%20that%20there%E2%80%99s%20space%20on%20the%20target%20node%3C%2FH2%3E%0A%3CP%20class%3D%22pg-section%22%3ERunning%20out%20of%20disk%20is%20one%20of%20the%20worst%20things%20that%20can%20happen%20to%20a%20Postgres%20server.%20When%20that%20happens%2C%20Postgres%20will%20crash.%20The%20only%20way%20to%20start%20Postgres%20again%20is%20to%20either%20get%20a%20larger%20disk%20or%20remove%20unnecessary%20files%2C%20such%20as%20log%20files.%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%22%3EThe%20shard%20rebalancer%20often%20moves%20big%20chunks%20of%20data%20across%20nodes%20in%20the%20distributed%20cluster.%20That%E2%80%99s%20why%20we%20added%20a%20new%20safety%20feature%20to%20the%20shard%20rebalancer%3A%20before%20actually%20moving%20a%20shard%2C%20the%20Citus%20rebalancer%20will%20first%20check%20if%20there%E2%80%99s%20enough%20space%20on%20the%20target%20node%20to%20actually%20store%20it%20(plus%20some%20margin%20for%20safety).%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1483599730%22%20id%3D%22toc-hId--1483442896%22%3EDeferred%20dropping%20of%20shards%20by%20default%3C%2FH2%3E%0A%3CP%20class%3D%22pg-section%22%3ECitus%2010.1%20also%20solves%20an%20annoying%20issue%20that%20some%20of%20you%20may%20have%20run%20into%3A%20Prior%20to%20Citus%2010.1%2C%20a%20shard%20move%20would%20sometimes%20be%20cancelled%20and%20rolled%20back%20right%20when%20the%20move%20would%20normally%20finish.%20Why%3F%20After%20moving%20all%20the%20data%2C%20the%20rebalancer%20used%20to%20drop%20the%20shard%20on%20the%20source%20node.%20However%2C%20when%20other%20queries%20were%20still%20reading%20or%20writing%20to%20this%20shard%2C%20the%20deletion%20could%20result%20in%20a%20distributed%20deadlock.%20This%20deadlock%20would%20only%20happen%20with%20transactions%20that%20were%20highly%20concurrent%2C%20and%20when%20you%20had%20acquired%20locks%20in%20the%20reverse%20order%20within%20a%20very%20short%20time%20window.%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%20section-active%22%3EWe%20have%20now%20enabled%20deferred%20dropping%20of%20shards%20by%20default%2C%20which%20makes%20sure%20such%20deadlocks%20do%20not%20occur.%20Deferred%20dropping%20means%20that%20instead%20of%20dropping%20the%20shard%20on%20the%20old%20node%20right%20away%2C%20shards%20are%20only%20marked%20for%20deletion.%20Then%20after%20a%20while%2C%20only%20after%20all%20the%20read%20queries%20have%20finished%2C%20will%20the%20shard%20actually%20be%20dropped.%20We%20call%20such%20a%20shard%20that%20is%20waiting%20to%20be%20dropped%20an%20%E2%80%9Corphaned%20shard%E2%80%9D.%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%20section-active%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%20section-active%22%3EThis%20feature%20is%20not%20strictly%20new%20in%20Citus%2010.1.%20It%20was%20already%20possible%20to%20enable%20this%20in%20previous%20versions%20by%20setting%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ecitus.defer_drop_after_shard_move%3C%2FCODE%3Eto%3CCODE%20style%3D%22color%3A%20black%3B%22%3Etrue%3C%2FCODE%3E.%20However%2C%20when%20not%20used%20with%20care%2C%20the%20previous%20implementation%20could%20result%20in%20confusing%20errors.%20This%20release%20we%20spent%20on%20hardening%20this%20feature%20and%20improving%20all%20of%20the%20error%20messages%20so%20they%20make%20sense.%20That%E2%80%99s%20why%20deferred%20dropping%20is%20now%20turned%20on%20by%20default%E2%80%94because%20we%E2%80%99re%20now%20confident%20that%20it%20works%20as%20well%20as%20we%20want%20it%20to.%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%20section-active%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1003913103%22%20id%3D%22toc-hId-1004069937%22%3EThe%20Citus%20shard%20rebalancer%20in%2010.1%3A%20happier%2C%20faster%2C%20and%20with%20a%20way%20to%20monitor%3C%2FH2%3E%0A%3CP%20class%3D%22pg-section%20section-active%22%3EWith%20Citus%2010.1%2C%20you%20will%20be%20much%20happier%20when%20using%20the%20shard%20rebalancer%20to%20balance%20the%20data%20sizes%20across%20the%20nodes%20in%20your%20cluster.%20Your%20shards%20will%20be%20moved%20faster.%20You%20can%20see%20the%20progress%20being%20made.%20And%20finally%2C%20your%20shard%20moves%20will%20not%20be%20rolled%20back%20anymore%20because%20Citus%20avoids%20the%20distributed%20deadlocks%20I%20mentioned%20earlier.%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%20section-active%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%20section-active%22%3EIf%20you%20want%20to%20learn%20more%20about%20the%20Citus%20rebalancer%20(recently%20made%20open%20source!)%20you%20might%20want%20to%20check%20out%20%3CA%20href%3D%22https%3A%2F%2Fwww.citusdata.com%2Fblog%2F2021%2F03%2F13%2Fscaling-out-postgres-with-citus-open-source-shard-rebalancer%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Emy%20previous%20post%3C%2FA%3E%20or%20check%20out%20the%20Hyperscale%20(Citus)%20docs%20on%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fpostgresql%2Freference-hyperscale-functions%23rebalance_table_shards%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Eshard%20rebalancer%3C%2FA%3E%20and%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.citusdata.com%2Fen%2Fstable%2Fdevelop%2Fapi_metadata.html%23rebalancer-strategy-table%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Erebalancer%20strategies%3C%2FA%3E.%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%20section-active%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%20section-active%22%3EIf%20you%E2%80%99re%20new%20to%20Citus%2C%20you%20can%20find%20a%20good%20collection%20of%20%3CA%20href%3D%22https%3A%2F%2Fwww.citusdata.com%2Fgetting-started%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Egetting%20started%20resources%3C%2FA%3E%20online%20here.%20And%20as%20always%20if%20you%20have%20any%20questions%2C%20you%20can%20find%20me%20and%20the%20rest%20of%20the%20Citus%20engineers%E2%80%94and%20other%20users%2C%20too%E2%80%94on%20our%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fslack.citusdata.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3ECitus%20slack%3C%2FA%3E.%3C%2FP%3E%0A%3CHR%20%2F%3E%0A%3CP%20class%3D%22pg-section%20section-active%22%3E%3CEM%3EThis%20post%20by%20Jelte%20Fennema%20about%20the%20shard%20rebalancer%20was%20%3CA%20href%3D%22https%3A%2F%2Fwww.citusdata.com%2Fblog%2F2021%2F09%2F03%2Fshard-rebalancing-in-citus-10-1%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Eoriginally%20published%20on%20the%20Citus%20Blog%3C%2FA%3E.%3C%2FEM%3E%3C%2FP%3E%0A%3CP%20class%3D%22pg-section%20section-active%22%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2712133%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Elephant-balancing-on-a-ball-against-a-purple-and-teal-background-1200x630.jpg%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F307813i884B3B1277595183%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Elephant-balancing-on-a-ball-against-a-purple-and-teal-background-1200x630.jpg%22%20alt%3D%22Elephant-balancing-on-a-ball-against-a-purple-and-teal-background-1200x630.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EHow%20to%20monitor%20the%20progress%20of%20the%20Citus%20shard%20rebalancer%2C%20new%20as%20of%20Citus%2010.1.%20Plus%20performance%20optimizations.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2712133%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Database%20for%20PostgreSQL%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ECitus%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eopen%20source%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Epostgres%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPostgres%20extensions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPostgreSQL%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Co-Authors
Version history
Last update:
‎Sep 03 2021 11:37 AM
Updated by: