Thursday, February 17, 2022

How To Set Up Streaming Replication in PostgreSQL

 in This Tutorial you Will Learn " How To Set Up Streaming Replication in PostgreSQL"

PostgreSQL is an extremely robust open-source database used by noted players like Skype, Reddit, Instagram, and OpenStreetMap. PostgreSQL allows replication to nodes that can run read-only queries.
Homepage - https://www.postgresql.org/
_________________________________________________________________________________________
Server - Os:  Rocky Linux 8.5  64Bit      | IP -192.168.1.60        |Hostname - server.yourdomain.com
                                 Replica Host IP - 192.168.1.80 | Os:  Rocky Linux 8.5
_________________________________________________________________________________________
cat /etc/system-release ; sestatus ; dnf groupinstall "Development Tools" -y
dnf module -y install postgresql:10
postgresql-setup --initdb
systemctl enable --now postgresql
gedit /var/lib/pgsql/data/postgresql.conf &>/dev/null
listen_addresses = '*'
wal_level = replica
synchronous_commit = on
max_wal_senders = 10
wal_keep_segments = 10
synchronous_standby_names = '*'

gedit /var/lib/pgsql/data/pg_hba.conf  &>/dev/null
# Allow replication connections from localhost, by a user with the
# replication privilege.
#host    replication     all             127.0.0.1/32            ident
#host    replication     all             ::1/128                 ident
host    replication     rep_user        192.168.1.60/32            md5
host    replication     rep_user        192.168.1.80/32            md5

su - postgres
createuser --replication -P rep_user   [ Password -toor ]
exit
systemctl restart postgresql ; systemctl status postgresql
firewall-cmd --add-service=postgresql ; firewall-cmd --runtime-to-permanent

su - postgres
psql -c "select usename, application_name, client_addr, state, sync_priority, sync_state from pg_stat_replication;"



+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Postgresql install and Configure Replica Host -
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
cat /etc/system-release ; sestatus ; dnf groupinstall "Development Tools" -y
dnf module -y install postgresql:10
postgresql-setup --initdb ; systemctl enable --now postgresql
systemctl stop postgresql
rm -rf /var/lib/pgsql/data/*
pg_basebackup -R -h 192.168.1.60 -U rep_user -D /var/lib/pgsql/data -P

cd /var/lib/pgsql/ ; chmod 700 data/ ; chown -R postgres:postgres data/
gedit /var/lib/pgsql/data/postgresql.conf &>/dev/null
listen_addresses = '*'
hot_standby = on
gedit /var/lib/pgsql/data/pg_hba.conf &>/dev/null
# Allow replication connections from localhost, by a user with the
# replication privilege.
#host    replication     all             127.0.0.1/32            ident
#host    replication     all             ::1/128                 ident
host    replication     rep_user        192.168.1.60/32            md5
host    replication     rep_user        192.168.1.80/32            md5
systemctl restart postgresql ; systemctl status postgresql
_________________________________________________________________________________________





















No comments:

Post a Comment