diff --git a/master_side/init-replication.sh b/master_side/init-replication.sh new file mode 100755 index 0000000..1c72b04 --- /dev/null +++ b/master_side/init-replication.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -e + +echo "Creating replication role..." + +psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL +DO \$\$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM pg_roles WHERE rolname = 'replicator' + ) THEN + CREATE ROLE replicator + WITH REPLICATION + LOGIN + PASSWORD 'replicator_password'; + END IF; +END +\$\$; +EOSQL + +echo "Replication role ready." + diff --git a/master_side/pg_hba.conf b/master_side/pg_hba.conf new file mode 100644 index 0000000..4d2edc1 --- /dev/null +++ b/master_side/pg_hba.conf @@ -0,0 +1,17 @@ +# TYPE DATABASE USER ADDRESS METHOD + +# Local connections +local all all trust + +# IPv4 local connections +host all all 127.0.0.1/32 trust + +# IPv6 local connections +host all all ::1/128 trust + +# Allow replication user from primary +host replication replicator 0.0.0.0/0 md5 + +host mytestdb postgres 0.0.0.0/0 md5 + + diff --git a/master_side/postgresql.conf b/master_side/postgresql.conf new file mode 100644 index 0000000..a71f0e7 --- /dev/null +++ b/master_side/postgresql.conf @@ -0,0 +1,35 @@ +# ----------------------------- +# BASIC +# ----------------------------- +listen_addresses = '*' +port = 5432 +max_connections = 100 + +# ----------------------------- +# REPLICATION +# ----------------------------- +wal_level = replica +hot_standby = on +max_wal_senders = 10 +max_replication_slots = 10 +wal_keep_size = 256MB + +# ----------------------------- +# REPLICA READ SAFETY +# ----------------------------- +hot_standby_feedback = on + +# ----------------------------- +# LOGGING (optional but useful) +# ----------------------------- +logging_collector = on +log_destination = 'stderr' +log_directory = 'log' +log_filename = 'postgresql-%Y-%m-%d.log' +log_statement = 'none' + +# ----------------------------- +# FILE LOCATIONS (IMPORTANT) +# ----------------------------- +hba_file = '/etc/postgresql/pg_hba.conf' +