replication is running

This commit is contained in:
asyncnomi 2025-08-02 03:40:45 +02:00
parent 83c9ee3283
commit 66c20020fc

View file

@ -1,3 +1,11 @@
## Note: This file wont setup the replication by itself
## Once deploy follow those instruction to run the streaming replication
## Execute on each slave (replace major version an ip addr accordingly):
# 1. sudo systemctl stop postgresql.service
# 2. sudo rm -r /var/lib/postgresql/17
# 3. pg_basebackup -h 172.19.1.2 -U replication -p 5432 -D /var/lib/postgresql/17 -P -Xs
# 4. sudo systemctl restart postgresql.service
{ config, pkgs, lib, ... }:
let
@ -45,7 +53,7 @@ in
++ lib.optionals (builtins.elem myName mapping.db.slaves) [
"host replication replication ${masterIP}/32 md5"
]));
ensureUsers = [{
ensureUsers = lib.mkIf (myName == mapping.db.master) [{
name = "replication";
ensureClauses.replication = true;
}];
@ -58,12 +66,13 @@ in
log_disconnections = true;
} // lib.optionalAttrs (myName == mapping.db.master) {
wal_level = "logical";
wal_sender_timeout = 10;
wal_sender_timeout = "60s";
max_wal_senders = 16;
wal_keep_size = 1000; # In MB
} // lib.optionalAttrs (builtins.elem myName mapping.db.slaves) {
wal_level = "logical";
wal_receiver_timeout = 10;
wal_receiver_timeout = "60s";
max_wal_senders = 16;
primary_conninfo = "host=${masterIP} port=5432 user=replication";
hot_standby = "on";
};