Skip to content

Commit c79c9ef

Browse files
funbringerpetrosaggjeff-davis
authored andcommitted
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 346d94a commit c79c9ef

File tree

16 files changed

+1503
-21
lines changed

16 files changed

+1503
-21
lines changed

docker/sql_setup.sh

+2
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

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ byteorder = "1.0"
1414
bytes = "1.0"
1515
fallible-iterator = "0.2"
1616
hmac = "0.12"
17+
lazy_static = "1.4"
1718
md-5 = "0.10"
1819
memchr = "2.0"
1920
rand = "0.8"

postgres-protocol/src/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
use byteorder::{BigEndian, ByteOrder};
1616
use bytes::{BufMut, BytesMut};
17+
use lazy_static::lazy_static;
1718
use std::io;
19+
use std::time::{Duration, SystemTime, UNIX_EPOCH};
1820

1921
pub mod authentication;
2022
pub mod escape;
@@ -28,6 +30,11 @@ pub type Oid = u32;
2830
/// A Postgres Log Sequence Number (LSN).
2931
pub type Lsn = u64;
3032

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

0 commit comments

Comments
 (0)