-
-
Notifications
You must be signed in to change notification settings - Fork 486
Streaming replication protocol #116
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
Comments
cc @posix4e |
We actually have a project called elephant pump that attempts to provide a bridge to writing logical decoder in rust. We intend on working with sfackler to port our code to his library once we get a bit further |
Any updates on a logical decoding/streaming replication client for Rust? |
@jmealo besides your work at http://github.com/posix4e/jsoncdc :) |
Any updates on this? extern crate postgres;
use postgres::{Connection, TlsMode};
fn main() {
let url = "postgresql://postgres:postgres@localhost:5432/postgres?replication=database";
let rep_conn = Connection::connect(url, TlsMode::None).unwrap();
rep_conn.execute("CREATE_REPLICATION_SLOT test_slot LOGICAL wal2json EXPORT_SNAPSHOT", &[]).unwrap();
} This produces an error:
|
@eadanfahey https://www.postgresql.org/docs/current/static/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY I hope this helps. We need to support the simple query protocol to send the logical replication commands. You could sniff the protocol from pg_recvlogical or checkout Lapidus to see what's required. |
@sfackler is there still interest in this? When this works, PG can enter into "replication" mode after the connection. Once the I could make a PR with the thank you |
Definitely interested! Other than adding the replication parameter, I think what we'd need to do is just add a |
@sfackler sorry, i am not that familiar with the with the layout of your lib/or pg protocol (i just cloned your repo, did a bunch of trace! to try to get the replication started) Just point me in the right direction and if i can i'll try and make this happen. |
|
I have made a lot of progress on my PR #696. Right now it's failing tests, but the biggest reason is because the image doesn't support logical replication. Can I get some high-level feedback on the PR? I'd like to know whether (a) it's something you want, and there is just more work to do and you don't have the bandwidth to give it a review right now; or (b) you don't really think #696 is the right approach. |
Re (a), just as a user, I would love this. Right now I use |
Would love to contribute as the use-case is coming up quite frequently; might be worth integrating with https://www.datadoghq.com/blog/engineering/introducing-glommio/ for each wal-sender which is a rebuild of Seastar C++. Could be super speedy |
even perhaps https://github.com/tokio-rs/io-uring |
what's the latest status? |
I hate to be bothering the maintainers (in case they just lack the time), but the last comment was over six months ago, and it might be helpful to know what additional steps need to be taken to get the pull-request over the finish line. Also @jakajancar, you mention:
To do this, are you using the copy-both branch of petrosagg's fork? Or are you accomplishing it on the And would it be straight-forward to show the key parts of the code you're using to accomplish it? Are you basically just using the commands seen in the EDIT: Not sure how relevant it is, but here is the polling mechanism used by postgraphile's logical-decoding plugin to receive database changes: https://github.com/graphile/graphile-engine/blob/a9fcbafc52244495420faac5da0e05cbceaf5e69/packages/lds/src/pg-logical-decoding.ts#L168 |
Good news! After a few hours of having my first "battle with the borrow-checker" (annoying and exhilarating at the same time 😅), I managed to get the copy-both branch of petrosagg's fork to stream the replication-log changes to my Rust server. (and using streams, rather than the For others wanting to see how it can be done, here is the working code: https://github.com/debate-map/app/blob/afc6467b6c6c961f7bcc7b7f901f0ff5cd79d440/Packages/app-server-rs/src/pgclient.rs (And here is the Cargo.toml file that tells cargo where to find the copy-both branch/fork mentioned earlier.) The Update: If you leave those bytes (mentioned just above) blank/zeroed, the server will keep holding all of the wal segments on disk while pgclient.rs is running; this can cause the pg_wal folder to grow to a huge size (if your client stays alive for a long time), which can cause postgres to crash due to all disk-space becoming used (as just happened for me); the solution is to track the wal-position each time you receive a wal update, and send that in your heartbeat response, so postgres knows those wal segments have been processed by all replication slots, thus enabling it to delete those old wal-segments' files. As for parsing the JSON text present in the XLogData/data-change events, I haven't added that yet -- though I've confirmed from the logs that the data is there. I'll be adding that parsing soon, using the serde library or something similar. EDIT: See also this comment here for a code change that is recommended, for large databases. EDIT: See also this file that is part of a smaller demo repo of logical decoding in Rust. |
This idea isn't fully formed yet, but it would be nice if rust-postgres could support the streaming replication protocol: http://www.postgresql.org/docs/devel/static/protocol-replication.html
It doesn't make a lot of sense with the physical replication (though that could be supported, too). But for logical replication it could be quite interesting.
The text was updated successfully, but these errors were encountered: