#!/bin/bash
# Database connection details
PGUSER="your_user"
PGPASSWORD="your_password"
PGDATABASE="your_database"
PGHOST="your_primary_host"
PGPORT="your_port"
# Run SQL query to get replication lag in GB
LAG=$(PGPASSWORD=$PGPASSWORD psql -U $PGUSER -d $PGDATABASE -h $PGHOST -p $PGPORT -Atc "
SELECT round((redo_lsn - restart_lsn) / 1024.0 / 1024 / 1024, 2)
FROM pg_control_checkpoint(), pg_replication_slots;" | tr -d ' ')
# Check if lag is 0.00
if [[ "$LAG" == "0.00" ]]; then
echo "Replication lag is 0.00 GB. Proceeding..."
# Add your proceeding steps here
else
echo "Replication lag is $LAG GB. Failing..."
exit 1
fi





0 comments:
Post a Comment