Professional Documents
Culture Documents
- Medium
Alparslan Ozturk
In this scenario, the settings that need to be made after installing Debian 11 on our db4 and db5 servers will be explained. In
addition, Postgresql 14 and repmgr have been installed with apt.
cat /etc/hosts
1.1.1.24 db4.ornek.com db4
1.1.1.25 db5.example.com db5 apt install -y postgresql-14-repmgr postgresql-14 on #db4
sudo pg_createcluster 14 main -d /pg_data/14/main -- --data-checksum
sudo systemctl daemon-reload
sudo systemctl status postgresql@14-main.service
sudo systemctl enable --now postgresql@14-main.service
on #db5
sudo pg_createcluster 14 main -d /pg_data/14/main -- --data-checksum ...start edilmeyecek...
4. pg_hba.conf settings: It is not the same as replication, even if it is specified with superuser all, it must be specified. Since the
rules in pg_hba.conf work from top to bottom, it is useful to put it at the top. (eg: 1.1.1.0/24 local network)
5. On standby server(db5);
6. Testing connections;
psql -U repmgr
8. Standby clone;
$ repmgr -h node1 -U repmgr -d repmgr -f /etc/repmgr.conf standby clone — dry-run
After this process, pg_hba.conf or posgresql.auto.conf etc. you may want to copy the files manually and start that way. I added
the copy and force commands to move the configuration files. so it can be controlled with systemd.
All files seem to have come with the clone command. This process should be done with basebackup and the
recovery.conf file should be created automatically. now "standby register" will be done.
It seems that all config files are also copied on Debian Server.
c) Primary servers will listen on port 5432. Standby servers will listen on port 5433.
listen primary
bind *:5432
option httpchk GET / HTTP/1.1
http-check expect status 200
server db4 1.1.1.24:5432 check port 18080
server db5 1.1.1.25:5432 check port 18080 listen standby
bind *:5433
option httpchk GET / HTTP/1.1
http-check expect status 201
server db4 1.1.1.24:5432 check port 18080
server db5 1.1.1.25:5432 check port 18080
curl -i -v http://db4:18080/
* Trying 1.1.1.24...
* TCP_NODELAY set
* Connected to db4 (1.1.1.24) port 18080 (#0)
> GET / HTTP/1.1
> Host: db4:18080
> User-Agent: curl/7.61.1
> Accept: */*
>
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Content-Type: text/plain
Content-Type: text/plain
< Connection: close
Connection: close
< Content-Length: 9
Content-Length: 9 <
* Recv failure: Connection reset by peer
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer
SWITCHOVER
We give the following command on standby (db5 ). and we are watching from Haproxy.
In debian/ubuntu to work properly as above; The serices*command in your /etc/repmgr.conf file should be as follows.
$ cat /etc/repmgr.conf
node_id=1
node_name='db4'
conninfo='host=db4 user=repmgr dbname=repmgr connect_timeout=2'
data_directory='/pg_data/14/main'
pg_bindir='/usr/lib/postgresql/14/bin'
repmgr_bindir='/usr/lib/postgresql/14/bin' service_start_command = 'sudo systemctl start postgresql@14-main.service'
service_stop_command = 'sudo systemctl stop postgresql@14-main.service'
service_restart_command = 'suod systemctl restart postgresql@14-main.service'
His