Auto-commit from giteapush.sh at 2025-04-29 05:20:21
This commit is contained in:
parent
55202b29e1
commit
ab6080af65
66
miscellaneous/bash/database_lag.sh
Executable file
66
miscellaneous/bash/database_lag.sh
Executable file
@ -0,0 +1,66 @@
|
||||
#!/bin/bash
|
||||
|
||||
# === CONFIG ===
|
||||
REPLICA_SERVER="cluster.db1.genesishostingtechnologies.com" # <-- fill this in
|
||||
SSH_USER="doc" # <-- fill this in
|
||||
PG_USER="postgres" # usually postgres
|
||||
|
||||
# === Connect and check SSH first ===
|
||||
echo "[*] Connecting to replica server $REPLICA_SERVER..."
|
||||
|
||||
ssh -o BatchMode=yes -o ConnectTimeout=5 "$SSH_USER@$REPLICA_SERVER" "echo 2>&1" && SSH_OK=true || SSH_OK=false
|
||||
|
||||
if [[ "$SSH_OK" == false ]]; then
|
||||
echo "❌ SSH connection failed! Could not reach $REPLICA_SERVER."
|
||||
echo "👉 Suggested Action: Check server DNS, IP, SSH service, firewall."
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# === Run the Replication Check ===
|
||||
OUTPUT=$(ssh "doc@38.102.127.174" "sudo -u $PG_USER psql -Atc \"SELECT application_name, state, sync_state, write_lag, flush_lag, replay_lag FROM pg_stat_replication;\"")
|
||||
|
||||
if [[ -z "$OUTPUT" ]]; then
|
||||
echo "❌ No replication data found!"
|
||||
echo "👉 Suggested Action: Check PostgreSQL service on both primary and replica. Verify replication setup."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# === Parse and Advise ===
|
||||
echo ""
|
||||
echo "=== Replication Status ==="
|
||||
echo "$OUTPUT"
|
||||
echo "==========================="
|
||||
|
||||
while IFS='|' read -r application_name state sync_state write_lag flush_lag replay_lag; do
|
||||
echo ""
|
||||
echo "🛠 Replica: $application_name"
|
||||
echo "🔹 Connection State: $state"
|
||||
echo "🔹 Sync State: $sync_state"
|
||||
echo "🔹 Write Lag: $write_lag"
|
||||
echo "🔹 Flush Lag: $flush_lag"
|
||||
echo "🔹 Replay Lag: $replay_lag"
|
||||
|
||||
if [[ "$state" == "streaming" && "$sync_state" == "sync" ]]; then
|
||||
echo "✅ Status: Healthy synchronous replication. No action needed."
|
||||
elif [[ "$state" == "streaming" && "$sync_state" == "async" ]]; then
|
||||
echo "⚠️ Warning: Replica is asynchronous. Check if this is expected."
|
||||
elif [[ "$state" == "catchup" ]]; then
|
||||
echo "⚠️ Warning: Replica is catching up. Monitor closely."
|
||||
else
|
||||
echo "❌ Error: Unknown or broken state. Immediate action required."
|
||||
fi
|
||||
|
||||
if [[ "$write_lag" != "" && "$write_lag" != "0" ]]; then
|
||||
echo "⚠️ Write Lag Detected: $write_lag"
|
||||
fi
|
||||
if [[ "$flush_lag" != "" && "$flush_lag" != "0" ]]; then
|
||||
echo "⚠️ Flush Lag Detected: $flush_lag"
|
||||
fi
|
||||
if [[ "$replay_lag" != "" && "$replay_lag" != "0" ]]; then
|
||||
echo "⚠️ Replay Lag Detected: $replay_lag"
|
||||
fi
|
||||
|
||||
done <<< "$OUTPUT"
|
||||
|
||||
echo ""
|
||||
echo "[✓] Replica check complete."
|
File diff suppressed because it is too large
Load Diff
@ -477,3 +477,5 @@ NameError: name 'check_remote_disk' is not defined. Did you mean: 'check_remote_
|
||||
⚡ 1 warnings found:
|
||||
- 💥 [db2] WARNING: Replication lag is 95 seconds.
|
||||
✅ Genesis Radio Healthcheck 2025-04-29 04:45:14: All systems normal.
|
||||
✅ Genesis Radio Healthcheck 2025-04-29 05:00:12: All systems normal.
|
||||
✅ Genesis Radio Healthcheck 2025-04-29 05:15:10: All systems normal.
|
||||
|
Loading…
x
Reference in New Issue
Block a user