-
Notifications
You must be signed in to change notification settings - Fork 126
Reshard with logical replication, part I #279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4b48abc to
d6439af
Compare
b26f3ee to
a18aa9f
Compare
This was referenced Jul 24, 2025
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Implement logical replication and
COPYfan-out between N origin shards and M destination shards. This reshards an existing cluster, one table at a time and streams table updates to the right shard(s) by parsing the replication stream.Implementation
Upserts allow us to rewind the stream back and replay without duplicates. All tables have to have a primary key, which will be used as the replica identity. DO NOT use the whole row as a replica identity, that doesn't work for upserts.
Missing pieces
pg_dump/pg_restore(see below)To solve the FK problem, we need to sync the schema ourselves without the constraints (or additional indexes). Once the replication is caught up, re-create the constraints & add back the indexes.
Updates and deletes just need us to hook into the query parser a bit to get shard on the where clause. This is still a PoC, this will be done in the next PR.
Misc
replication_modeenabled will be closed instead of re-used. This ensures that connections left in partial state after logical replication are not re-used by other clients.Cluster::executemethod to execute a query on all primaries in the cluster. Just a helper, useful for testing,Pool::standaloneto create a connection untracked by the pool. Can be used for whatever reason, incl. replication.