Skip to content

Commit

Permalink
Support for physical and logical replication
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
3 people authored and arpad-m committed Jan 30, 2025
1 parent 2eb3811 commit 4ad59e8
Show file tree
Hide file tree
Showing 16 changed files with 1,505 additions and 22 deletions.
2 changes: 2 additions & 0 deletions docker/sql_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ port = 5433
ssl = on
ssl_cert_file = 'server.crt'
ssl_key_file = 'server.key'
wal_level = logical
EOCONF

cat > "$PGDATA/pg_hba.conf" <<-EOCONF
Expand All @@ -82,6 +83,7 @@ host all ssl_user ::0/0 reject
# IPv4 local connections:
host all postgres 0.0.0.0/0 trust
host replication postgres 0.0.0.0/0 trust
# IPv6 local connections:
host all postgres ::0/0 trust
# Unix socket connections:
Expand Down
1 change: 1 addition & 0 deletions postgres-protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ byteorder = "1.0"
bytes = "1.0"
fallible-iterator = "0.2"
hmac = "0.12"
lazy_static = "1.4"
md-5 = "0.10"
memchr = "2.0"
rand = "0.8"
Expand Down
7 changes: 7 additions & 0 deletions postgres-protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

use byteorder::{BigEndian, ByteOrder};
use bytes::{BufMut, BytesMut};
use lazy_static::lazy_static;
use std::io;
use std::time::{Duration, SystemTime, UNIX_EPOCH};

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

lazy_static! {
/// Postgres epoch is 2000-01-01T00:00:00Z
pub static ref PG_EPOCH: SystemTime = UNIX_EPOCH + Duration::from_secs(946_684_800);
}

/// An enum indicating if a value is `NULL` or not.
pub enum IsNull {
/// The value is `NULL`.
Expand Down
Loading

0 comments on commit 4ad59e8

Please sign in to comment.