Attivazione Standby

Da GazziNet.
Vai alla navigazione Vai alla ricerca

Istruzioni per creare uno standby di PostgreSQL 15 su Oracle Linux 9

Configurazione del server primario

1. Configurare PostgreSQL Modificare il file postgresql.conf (di solito in /var/lib/pgsql/15/data/postgresql.conf)

cat <<EOL | sudo tee -a /var/lib/pgsql/15/data/postgresql.conf
wal_level = replica
archive_mode = on
archive_command = 'cp %p /var/lib/pgsql/15/archive/%f'
max_wal_senders = 3
wal_keep_size = 512MB
hot_standby = on
EOL
  1. 4. Modificare il file pg_hba.conf per consentire la replica
cat <<EOL | sudo tee -a /var/lib/pgsql/15/data/pg_hba.conf
host    replication     replica_user     standby_ip/32      md5
EOL
  1. 5. Creare un utente per la replica
sudo -u postgres psql -c "CREATE USER replica_user REPLICATION LOGIN ENCRYPTED PASSWORD 'replica_password';"
  1. 6. Riavviare PostgreSQL per applicare le modifiche
sudo systemctl restart postgresql-15
    1. Configurazione del server standby
  1. 1. Installare PostgreSQL 15 sul server standby


  1. Install the repository RPM:
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
  1. Disable the built-in PostgreSQL module:
sudo dnf -qy module disable postgresql  
  1. Install PostgreSQL:
sudo dnf install -y postgresql15-server postgresql15
  1. 2. Fermare il servizio PostgreSQL sul server standby
  1. Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-15/bin/postgresql-15-setup initdb
sudo systemctl enable postgresql-15
sudo systemctl start postgresql-15
sudo systemctl stop postgresql-15
  1. 3. Eliminare il contenuto della directory dei dati
sudo rm -rf /var/lib/pgsql/15/data/*
  1. 4. Eseguire il backup dei dati dal server primario
sudo -u postgres pg_basebackup -h primary_ip -D /var/lib/pgsql/15/data -U replica_user -P -R
  1. 6. Avviare PostgreSQL sul server standby

sudo systemctl start postgresql-15

    1. Verifica dello stato della replica
sudo -u postgres psql -c "SELECT client_addr, state FROM pg_stat_replication;"