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

Commit 8e2d19f

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 <petrosagg@gmail.com> Co-authored-by: Jeff Davis <jeff@j-davis.com> Co-authored-by: Dmitry Ivanov <ivadmi5@gmail.com>
1 parent d0cbcc8 commit 8e2d19f

File tree

18 files changed

+1587
-21
lines changed

18 files changed

+1587
-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:

flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
description = "A prisma test project";
3+
inputs.nixpkgs.url = "github:NixOS/nixpkgs/master";
4+
inputs.flake-utils.url = "github:numtide/flake-utils";
5+
6+
outputs = {
7+
self,
8+
nixpkgs,
9+
flake-utils,
10+
}:
11+
flake-utils.lib.eachDefaultSystem (system: let
12+
pkgs = nixpkgs.legacyPackages.${system};
13+
in {
14+
devShell = pkgs.mkShell {
15+
nativeBuildInputs = [pkgs.bashInteractive];
16+
buildInputs = with pkgs; [
17+
openssl
18+
rustup
19+
pkg-config
20+
];
21+
};
22+
});
23+
}

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)