Created at: 2025-05-25
Source: https://www.highgo.ca/2023/04/03/setting-up-a-postgresql-replica-server-locally/
CREATE ROLE rep_user WITH REPLICATION LOGIN PASSWORD 'rep_pass';
CREATE TABLE t1(a INT, b INT);
INSERT INTO t1 VALUES (1,2);
build/data/postgresql.conf
by adding this line:listen_addresses = 'localhost'
build/data/pg_hba.conf
by adding this line:host replication rep_user localhost md5
pg_basebackup
to create a rep/
folder with the replica data.build/bin/pg_basebackup -h localhost \
-U rep_user \
-X stream \
-C \
-S replica_1 \
-v \
-R \
-W \
-D build/rep
build/rep/postgresql.conf
and set the port number to something
different than the main server.port = 5454
build/rep/postgresql.conf
set primary_conninfo to (change the
user accordingly):primary_conninfo = 'dbname=postgres user=postgres host=localhost port=5432 sslmode=disable'
sandby.signal
file:touch build/rep/standby.signal
build/bin/pg_ctl -D build/rep start
build/bin/psql --port=5454 --dbname=postgres
build/bin/pg_ctl -D build/rep stop