Attivazione Standby: differenze tra le versioni
Vai alla navigazione
Vai alla ricerca
Nessun oggetto della modifica |
Nessun oggetto della modifica |
||
Riga 41: | Riga 41: | ||
# Disable the built-in PostgreSQL module: | # Disable the built-in PostgreSQL module: | ||
sudo dnf -qy module disable postgresql | sudo dnf -qy module disable postgresql | ||
# Install PostgreSQL: | # Install PostgreSQL: | ||
Riga 54: | Riga 54: | ||
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 | # 3. Eliminare il contenuto della directory dei dati | ||
Riga 62: | Riga 63: | ||
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 | ||
# 6. Avviare PostgreSQL sul server standby | # 6. Avviare PostgreSQL sul server standby |
Versione delle 17:18, 27 feb 2025
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
- 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
- 5. Creare un utente per la replica
sudo -u postgres psql -c "CREATE USER replica_user REPLICATION LOGIN ENCRYPTED PASSWORD 'replica_password';"
- 6. Riavviare PostgreSQL per applicare le modifiche
sudo systemctl restart postgresql-15
- Configurazione del server standby
- 1. 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
- 2. 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
- 3. Eliminare il contenuto della directory dei dati
sudo rm -rf /var/lib/pgsql/15/data/*
- 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
- 6. 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;"