Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit ad35fb6

Browse files
funbringerpetrosaggjeff-davis
authored and
Julius de Bruijn
committed
Support for physical and logical replication
This patch was implemented by Petros Angelatos and Jeff Davis to support physical and logical replication in rust-postgres (see sfackler#752). The original PR never made it to the upstream, but we (Neon) still use it in our own fork of rust-postgres. The following commits were squashed together: * Image configuration updates. * Make simple_query::encode() pub(crate). * decoding logic for replication protocol * Connection string config for replication. * add copy_both_simple method * helper ReplicationStream type for replication protocol This can be optionally used with a CopyBoth stream to decode the replication protocol * decoding logic for logical replication protocol * helper LogicalReplicationStream type to decode logical replication * add postgres replication integration test * add simple query versions of copy operations * replication: use SystemTime for timestamps at API boundary Co-authored-by: Petros Angelatos <[email protected]> Co-authored-by: Jeff Davis <[email protected]> Co-authored-by: Dmitry Ivanov <[email protected]>
1 parent 7bc27ca commit ad35fb6

File tree

16 files changed

+1502
-21
lines changed

16 files changed

+1502
-21
lines changed

docker/sql_setup.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ port = 5433
6464
ssl = on
6565
ssl_cert_file = 'server.crt'
6666
ssl_key_file = 'server.key'
67+
wal_level = logical
6768
EOCONF
6869

6970
cat > "$PGDATA/pg_hba.conf" <<-EOCONF
@@ -82,6 +83,7 @@ host all ssl_user ::0/0 reject
8283
8384
# IPv4 local connections:
8485
host all postgres 0.0.0.0/0 trust
86+
host replication postgres 0.0.0.0/0 trust
8587
# IPv6 local connections:
8688
host all postgres ::0/0 trust
8789
# Unix socket connections:

postgres-protocol/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ byteorder = "1.0"
1818
bytes = "1.0"
1919
fallible-iterator = "0.2"
2020
hmac = "0.12"
21+
lazy_static = "1.4"
2122
md-5 = "0.10"
2223
memchr = "2.0"
2324
rand = "0.8"

postgres-protocol/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
use byteorder::{BigEndian, ByteOrder};
1515
use bytes::{BufMut, BytesMut};
16+
use lazy_static::lazy_static;
1617
use std::io;
18+
use std::time::{Duration, SystemTime, UNIX_EPOCH};
1719

1820
pub mod authentication;
1921
pub mod escape;
@@ -27,6 +29,11 @@ pub type Oid = u32;
2729
/// A Postgres Log Sequence Number (LSN).
2830
pub type Lsn = u64;
2931

32+
lazy_static! {
33+
/// Postgres epoch is 2000-01-01T00:00:00Z
34+
pub static ref PG_EPOCH: SystemTime = UNIX_EPOCH + Duration::from_secs(946_684_800);
35+
}
36+
3037
/// An enum indicating if a value is `NULL` or not.
3138
pub enum IsNull {
3239
/// The value is `NULL`.

0 commit comments

Comments
 (0)