Attivazione Standby: differenze tra le versioni

Da GazziNet.
Vai alla navigazione Vai alla ricerca
Nessun oggetto della modifica
Nessun oggetto della modifica
 
(2 versioni intermedie di uno stesso utente non sono mostrate)
Riga 3: Riga 3:
Configurazione del server primario
Configurazione del server primario


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


Riga 15: Riga 15:
  EOL
  EOL


# 4. Modificare il file pg_hba.conf per consentire la replica
Modificare il file pg_hba.conf per consentire la replica


  cat <<EOL | sudo tee -a /var/lib/pgsql/15/data/pg_hba.conf
  cat <<EOL | sudo tee -a /var/lib/pgsql/15/data/pg_hba.conf
  host    replication    replica_user    standby_ip/32      md5
  host    replication    replica_user    standby_ip/32      scram-sha-256
  EOL
  EOL


# 5. Creare un utente per la replica
Creare un utente per la replica


  sudo -u postgres psql -c "CREATE USER replica_user REPLICATION LOGIN ENCRYPTED PASSWORD 'replica_password';"
  sudo -u postgres psql -c "CREATE USER replica_user REPLICATION LOGIN ENCRYPTED PASSWORD 'replica_password';"


# 6. Riavviare PostgreSQL per applicare le modifiche
Riavviare PostgreSQL per applicare le modifiche


  sudo systemctl restart postgresql-15
  sudo systemctl restart postgresql-15


## Configurazione del server standby
Configurazione del server standby


# 1. Installare PostgreSQL 15 sul server standby
Installare PostgreSQL 15 sul server standby
 
Install the repository RPM:
 
 
# 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
  sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm


# Disable the built-in PostgreSQL module:
Disable the built-in PostgreSQL module:


  sudo dnf -qy module disable postgresql <-- Importante!!
  sudo dnf -qy module disable postgresql


# Install PostgreSQL:
Install PostgreSQL:


  sudo dnf install -y postgresql15-server postgresql15
  sudo dnf install -y postgresql15-server postgresql15


# 2. Fermare il servizio PostgreSQL sul server standby
Fermare il servizio PostgreSQL sul server standby
 
Optionally initialize the database and enable automatic start:
# Optionally initialize the database and enable automatic start:


  sudo /usr/pgsql-15/bin/postgresql-15-setup initdb
  sudo /usr/pgsql-15/bin/postgresql-15-setup initdb
  sudo systemctl enable postgresql-15
  sudo systemctl enable postgresql-15
  sudo systemctl start postgresql-15
  sudo systemctl start postgresql-15
sudo systemctl stop postgresql-15


# 3. Eliminare il contenuto della directory dei dati
Eliminare il contenuto della directory dei dati


  sudo rm -rf /var/lib/pgsql/15/data/*
  sudo rm -rf /var/lib/pgsql/15/data/*


# 4. Eseguire il backup dei dati dal server primario
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
  sudo -u postgres pg_basebackup -h primary_ip -D /var/lib/pgsql/15/data -U replica_user -P -R


# 5. Configurare il file recovery.conf (creato automaticamente da pg_basebackup)
Avviare PostgreSQL sul server standby
   
   
  echo "primary_conninfo = 'host=primary_ip port=5432 user=replica_user password=replica_password'" | sudo tee -a /var/lib/pgsql/15/data/postgresql.auto.conf
  sudo systemctl start postgresql-15
 
# 6. Avviare PostgreSQL sul server standby
sudo systemctl start postgresql-15


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

Versione attuale delle 17:28, 27 feb 2025

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

Configurazione del server primario

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

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      scram-sha-256
EOL

Creare un utente per la replica

sudo -u postgres psql -c "CREATE USER replica_user REPLICATION LOGIN ENCRYPTED PASSWORD 'replica_password';"

Riavviare PostgreSQL per applicare le modifiche

sudo systemctl restart postgresql-15

Configurazione del server standby

Installare PostgreSQL 15 sul server standby 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

Disable the built-in PostgreSQL module:

sudo dnf -qy module disable postgresql  

Install PostgreSQL:

sudo dnf install -y postgresql15-server postgresql15

Fermare il servizio PostgreSQL sul server standby 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

Eliminare il contenuto della directory dei dati

sudo rm -rf /var/lib/pgsql/15/data/*

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

Avviare PostgreSQL sul server standby

sudo systemctl start postgresql-15

Verifica dello stato della replica

sudo -u postgres psql -c "SELECT client_addr, state FROM pg_stat_replication;"