When there's a network interface card (NIC) failure,
I want to create a script that detects it in repmgrd and performs subsequent actions.
If the Primary DB loses its NIC connection for 10 seconds, I want the Primary DB to be forcibly terminated,
and the Standby DB to be promoted to take over.
However, although the Standby promotion occurs, the Primary DB does not stop.
Is repmgrd daemon unable to detect NIC disconnection?
repmgr version : 5.3.3
postgresql version : 15.3
#!/bin/bash
PRIMARY_IP="10.12.30.191"
STANDBY_IP="10.12.30.192"
REPMGR_CONFIG="/postgres15/app/postgres/etc/repmgr.conf"
PGLOG="/pglog/repmgrd.log"
function echodate() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')]"
}
# Function to stop PostgreSQL on primary server
function stop_primary_db() {
echo "$(echodate) [FAILOVER] Stopping primary PostgreSQL database" >> "$PGLOG"
repmgr -f "$REPMGR_CONFIG" node service --action=stop
}
# Check if primary server needs to be shut down
ping -c 1 -W 10 "$PRIMARY_IP" > /dev/null 2>&1
ping_exit_code=$?
if [ $ping_exit_code -ne 0 ]; then
# Ping to primary server timed out or failed, stop PostgreSQL and exit
stop_primary_db
exit 0
fi
# No failover condition met, exit
echo "$(echodate) [FAILOVER] No failover condition met, continuing normal operation" >> "$PGLOG"
exit 0
Hello.
When there's a network interface card (NIC) failure,
I want to create a script that detects it in repmgrd and performs subsequent actions.
If the Primary DB loses its NIC connection for 10 seconds, I want the Primary DB to be forcibly terminated,
and the Standby DB to be promoted to take over.
However, although the Standby promotion occurs, the Primary DB does not stop.
Is repmgrd daemon unable to detect NIC disconnection?