HS - Postgres 9.6
HS - Postgres 9.6
--- root
sudo yum install -y dnf
sudo dnf install -y epel-release vim
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-
x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo dnf -qy module disable postgresql
sudo dnf install -y postgresql96-server postgresql96-contrib rsync
sudo dnf install -y repmgr96
cat<<EOF>/etc/sudoers.d/postgres
Defaults:postgres !requiretty
postgres ALL = NOPASSWD: /usr/bin/systemctl stop postgresql-9.6, \\
/usr/bin/systemctl start postgresql-9.6, \\
/usr/bin/systemctl restart postgresql-9.6, \\
/usr/bin/systemctl reload postgresql-9.6, \\
/usr/bin/systemctl stop repmgr96, \\
/usr/bin/systemctl start repmgr96, \\
/usr/bin/systemctl restart repmgr96
EOF
--- postgres
cat<<EOF>~/.bash_profile
if [ -f /var/lib/pgsql/.pgsql_profile ]; then
source /var/lib/pgsql/.pgsql_profile
fi
EOF
cat<<EOF>>~/.pgsql_profile
PATH=$PATH:/usr/pgsql-9.6/bin
EOF
# PG-1
--- root
/usr/pgsql-9.6/bin/postgresql96-setup initdb
vim /var/lib/pgsql/9.6/data/postgresql.conf
--
listen_addresses = '*'
shared_preload_libraries = 'pg_stat_statements, repmgr'
wal_log_hints = on
wal_level = logical
wal_keep_segments = 20
max_replication_slots = 10
max_wal_senders = 12
archive_mode = on
archive_command = '/bin/true'
archive_timeout = 6h
hot_standby = on
hot_standby_feedback = on
pg_stat_statements.max = 1000
pg_stat_statements.track = all
pg_stat_statements.track_utility = on
pg_stat_statements.save = on
-----
sudo systemctl restart postgresql-9.6
--- postgres
# PG-1
createuser --superuser --replication --pwprompt repmgr
# TODOS
echo "*:5432:*:repmgr:CONTRASEÑA_USUARIO_REPMGR" >> ~/.pgpass
chmod 600 ~/.pgpass
# PG-1
cat<<EOF>>/var/lib/pgsql/9.6/data/pg_hba.conf
host replication all PGSERVER1-IP/32 md5
host replication all PGSERVER2-IP/32 md5
host all all 0.0.0.0/0 md5
EOF
# TODOS
--- root
sudo chown postgres:postgres /etc/repmgr/9.6/repmgr.conf
vim /etc/repmgr/9.6/repmgr.conf
---
node_id = 1
node_name ='PGSERVER'
conninfo ='host=PGSERVER-IP port=5432 dbname=repmgr user=repmgr
application_name=PGSERVER connect_timeout=2'
data_directory ='/var/lib/pgsql/9.6/data'
pg_bindir ='/usr/pgsql-9.6/bin'
use_replication_slots = 1
async_query_timeout = 60
reconnect_attempts = 6
reconnect_interval = 10
failover = automatic
ssh_options ='-q'
log_level = INFO
log_facility=STDERR
log_file='/var/log/repmgr/repmgr.log'
monitoring_history =true
promote_command ='/etc/repmgr/9.6/promote_command.sh'
follow_command ='/usr/pgsql-9.6/bin/repmgr standby follow -f
/etc/repmgr/9.6/repmgr.conf'
# PG-1
--- postgres
# TODOS - Local
scp promote_command.sh root@PGSERVER-IP:/etc/repmgr/9.6/
scp config.sh root@PGSERVER-IP:/etc/repmgr/9.6/
# PG-1
--- postgres
repmgr primary register
# PG-2
repmgr standby clone -c -U repmgr -d repmgr -h PRIMARY-IP --dry-run # Probar
replicación
repmgr standby clone -c -U repmgr -d repmgr -h PRIMARY-IP # Crear replicación
sudo systemctl start postgresql-9.6
repmgr standby register
# TODOS
--- root
cd /etc/repmgr/9.6/
chown postgres:postgres config.sh
chown postgres:postgres promote_command.sh
chmod 744 promote_command.sh
chmod 744 config.sh
cd /run
mkdir repmgr
chown postgres:postgres -R repmgr
sudo systemctl start repmgr96
sudo systemctl enable repmgr96
sudo systemctl enable postgresql-9.6
# FILEBACK
--- old-primary
sudo systemctl stop postgresql-9.6
repmgr --force --host=NEWPRIMARY-IP --dbname=repmgr --user=repmgr standby clone
sudo systemctl start postgresql-9.6
repmgr standby register --force