I want to set up streaming replication on the Slave.
On the Primary Server (Server A. Ubuntu 18.04; Postgres 12) :
sudo nano /etc/postgresql/12/main/postgresql.conf
- Set
listen_addresses = '*'
- The postgresql.conf settings are :
wal_level = "logical"
archive_mode = "ON"
archive_timeout = 3600
checkpoint_timeout = 600
hot_standby = "ON"
max_connections = 700
max_wal_sender = 5
max_wal_size = 16GB
min_wal_size = 2GB
max_worker_processes = 30
synchronous_commit = "OFF"
wal_log_hints = "OFF"
wal_recycle = "ON"
wal_keep_segments = 4000
wal_sync_method = "fdatasync"
This Primary Server has already hosted logical replication to another server (Server B. Ubuntu 18.04; Postgres 12)
On the Slave Server (Server C. Ubuntu 22.04; Postgres 12) :
- change the data directory
- set this up as Slave for streaming replication from Server A.
Here is the detail : After installing postgres (fresh install) I make sure it's running, then I change the data directory :
sudo -u postgres psql
SHOW data_directory;
. --Output /var/lib/postgresql/12/main- Quit psql :
\q
sudo systemctl stop postgresql
sudo systemctl status postgresql
sudo rsync -av /var/lib/postgresql /data/postgresql2
- rename the folder :
sudo mv /var/lib/postgresql/12/main /var/lib/postgresql/12/main.bak
- Edit the postgresql.conf :
sudo nano /etc/postgresql/12/main/postgresql.conf
- Set to new location :
data_directory = '/data/postgresql2/postgresql/12/main'
- Start the db again :
sudo systemctl start postgresql
The result is good. Postgres is running well on Server C. When I do SHOW data_directory;
it gives out : /data/postgresql2/postgresql/12/main
Then I setup streaming replication on Server C :
stop the service on the slave :
systemctl stop [email protected]
su - postgres
thencp -R /data/postgresql2/postgresql/12/main /data/postgresql2/postgresql/12/data_original
Remove the old directory :
rm -rf /data/postgresql2/postgresql/12/main/*
Then do base backup :
pg_basebackup -h 10.100.9.40 -p 5432 -U rep_user -D /data/postgresql2/postgresql/12/main -Fp -Xs -R -P -v
Restart :
systemctl start [email protected]
--gives out error :
*`Job for [email protected] failed because the service did not take the steps required by its unit configuration.
See "systemctl status [email protected]" and "journalctl -xeu [email protected]" for details`*
- Then I start using another way :
sudo -i -u postgres
/usr/lib/postgresql/12/bin/pg_ctl start -D /data/postgresql2/postgresql/12/main
It gives out error :
waiting for server to start....postgres: could not access the server configuration file "/data/postgresql2/postgresql/12/main/postgresql.conf": No such file or directory
Please help. What might cause this?