-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_replica_down.sh
More file actions
executable file
·71 lines (56 loc) · 2.87 KB
/
Copy pathtest_replica_down.sh
File metadata and controls
executable file
·71 lines (56 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
# Test Replica Down Scenario
# Stops pg-replica1 completely to test Pgpool failover behavior
REPLICA="pg-replica1"
DOWN_DURATION=20
echo "╔══════════════════════════════════════════════════════════════╗"
echo "║ REPLICA DOWN TEST - $REPLICA ║"
echo "╚══════════════════════════════════════════════════════════════╝"
echo ""
# Initial status
echo "[$(date +%H:%M:%S)] Initial Pgpool node status:"
PGPASSWORD=secret psql -h 127.0.0.1 -p 5433 -U postgres -d appdb -c "SHOW POOL_NODES" 2>/dev/null
echo ""
echo "[$(date +%H:%M:%S)] Initial replication status:"
docker exec pg-primary psql -U postgres -c "SELECT client_addr, state, replay_lag FROM pg_stat_replication;" 2>/dev/null
# Stop replica1
echo ""
echo "[$(date +%H:%M:%S)] ⛔ STOPPING $REPLICA..."
docker stop $REPLICA >/dev/null 2>&1
echo "[$(date +%H:%M:%S)] $REPLICA stopped."
# Wait for Pgpool to detect
echo ""
echo "[$(date +%H:%M:%S)] Waiting 5s for Pgpool to detect..."
sleep 5
# Show status after stop
echo ""
echo "[$(date +%H:%M:%S)] Pgpool node status (after $REPLICA stopped):"
PGPASSWORD=secret psql -h 127.0.0.1 -p 5433 -U postgres -d appdb -c "SHOW POOL_NODES" 2>/dev/null
echo ""
echo "[$(date +%H:%M:%S)] Replication status (after $REPLICA stopped):"
docker exec pg-primary psql -U postgres -c "SELECT client_addr, state, replay_lag FROM pg_stat_replication;" 2>/dev/null
# Wait remaining time
remaining=$((DOWN_DURATION - 5))
echo ""
echo "[$(date +%H:%M:%S)] Waiting ${remaining}s before restarting..."
sleep $remaining
# Start replica1 again
echo ""
echo "[$(date +%H:%M:%S)] ▶️ STARTING $REPLICA..."
docker start $REPLICA >/dev/null 2>&1
echo "[$(date +%H:%M:%S)] $REPLICA started."
# Wait for recovery
echo ""
echo "[$(date +%H:%M:%S)] Waiting 10s for $REPLICA to recover and sync..."
sleep 10
# Final status
echo ""
echo "[$(date +%H:%M:%S)] Final Pgpool node status:"
PGPASSWORD=secret psql -h 127.0.0.1 -p 5433 -U postgres -d appdb -c "SHOW POOL_NODES" 2>/dev/null
echo ""
echo "[$(date +%H:%M:%S)] Final replication status:"
docker exec pg-primary psql -U postgres -c "SELECT client_addr, state, replay_lag FROM pg_stat_replication;" 2>/dev/null
echo ""
echo "╔══════════════════════════════════════════════════════════════╗"
echo "║ TEST COMPLETE ║"
echo "╚══════════════════════════════════════════════════════════════╝"