Attivazione Standby: differenze tra le versioni
Nessun oggetto della modifica |
Nessun oggetto della modifica |
||
(3 versioni intermedie di uno stesso utente non sono mostrate) | |||
Riga 3: | Riga 3: | ||
Configurazione del server primario | Configurazione del server primario | ||
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 | ||
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 | host replication replica_user standby_ip/32 scram-sha-256 | ||
EOL | EOL | ||
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';" | ||
Riavviare PostgreSQL per applicare le modifiche | |||
sudo systemctl restart postgresql-15 | 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 | 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 | sudo dnf -qy module disable postgresql | ||
Install PostgreSQL: | |||
sudo dnf install -y postgresql15-server postgresql15 | 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 | sudo systemctl stop postgresql-15 | ||
Eliminare il contenuto della directory dei dati | |||
sudo rm -rf /var/lib/pgsql/15/data/* | 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 | 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 | sudo systemctl start postgresql-15 | ||
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;"