46 lines
No EOL
1.5 KiB
Bash
Executable file
46 lines
No EOL
1.5 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
echo "=== PostgreSQL Connection Health Check ==="
|
|
echo ""
|
|
|
|
# Check pod status
|
|
echo "Pod Status:"
|
|
kubectl get pods -n aprs | grep -E "(NAME|postgis|pgbouncer|aprs-)"
|
|
echo ""
|
|
|
|
# Check PostgreSQL connections
|
|
echo "PostgreSQL Connection Stats:"
|
|
kubectl exec deployment/postgis -n aprs -- psql -U aprs -d aprs_prod -c "
|
|
SELECT
|
|
state,
|
|
COUNT(*) as connections,
|
|
ROUND(AVG(EXTRACT(EPOCH FROM (NOW() - state_change))), 2) as avg_duration_seconds
|
|
FROM pg_stat_activity
|
|
WHERE datname = 'aprs_prod'
|
|
GROUP BY state
|
|
ORDER BY connections DESC;" 2>/dev/null || echo "Failed to query PostgreSQL"
|
|
echo ""
|
|
|
|
# Check connection percentage
|
|
echo "Connection Usage:"
|
|
kubectl exec deployment/postgis -n aprs -- psql -U aprs -d aprs_prod -c "
|
|
SELECT
|
|
(SELECT COUNT(*) FROM pg_stat_activity) as current,
|
|
(SELECT setting::int FROM pg_settings WHERE name = 'max_connections') as max,
|
|
ROUND(100.0 * COUNT(*) / (SELECT setting::int FROM pg_settings WHERE name = 'max_connections'), 2) || '%' as usage
|
|
FROM pg_stat_activity;" 2>/dev/null || echo "Failed to query PostgreSQL"
|
|
echo ""
|
|
|
|
# Check PgBouncer logs for errors
|
|
echo "Recent PgBouncer Errors (last 10):"
|
|
kubectl logs -n aprs -l app=pgbouncer --tail=50 | grep -i "error\|warning" | tail -10
|
|
echo ""
|
|
|
|
# Check APRS pod logs for connection errors
|
|
echo "Recent APRS Connection Errors (last 10):"
|
|
kubectl logs -n aprs -l app=aprs --tail=100 | grep -i "postgrex\|connection\|protocol_violation" | tail -10
|
|
echo ""
|
|
|
|
# Show last cleanup job run
|
|
echo "Last Cleanup Job Run:"
|
|
kubectl get jobs -n aprs | grep postgres-cleanup | tail -1 |