mirror of
https://github.com/status-im/infra-role-postgres-ha.git
synced 2025-02-21 10:58:15 +00:00
consul: add handling DB without replica to health.sh
Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
1ff92d5fc5
commit
6b296be196
@ -15,7 +15,7 @@
|
||||
tcp: 'localhost:{{ postgres_ha_cont_port }}'
|
||||
|
||||
- id: '{{ postgres_ha_service_name }}-mirror'
|
||||
name: 'PostgreSQL Replica Healthcheck'
|
||||
name: 'PostgreSQL {{ postgres_ha_replica_enabled | ternary("Replica", "Tables") }} Healthcheck'
|
||||
disabled: '{{ not postgres_ha_replica_enabled }}'
|
||||
type: 'script'
|
||||
script: '{{ postgres_ha_service_path }}/health.sh'
|
||||
|
@ -2,29 +2,27 @@
|
||||
# vim: set ft=sh:
|
||||
set -Eeo pipefail
|
||||
|
||||
{% if postgres_ha_is_master %}
|
||||
{% if not postgres_ha_replica_enabled %}
|
||||
STATUS_QUERY='SELECT oid,datname,dattablespace FROM pg_catalog.pg_database WHERE datistemplate = false;'
|
||||
HEALTH_REGEX='datname +| ({{ postgres_ha_databases | map(attribute="name") | join("|") }})'
|
||||
{% elif postgres_ha_is_master %}
|
||||
STATUS_QUERY='SELECT * FROM pg_stat_replication'
|
||||
HEALTH_REGEX='status +| streaming'
|
||||
{% else %}
|
||||
STATUS_QUERY='SELECT * FROM pg_stat_wal_receiver'
|
||||
HEALTH_REGEX='status +| streaming'
|
||||
{% endif %}
|
||||
REPLICA_STATUS=$(
|
||||
"{{ postgres_ha_service_path }}/admin.sh" -x -c "${STATUS_QUERY}"
|
||||
)
|
||||
|
||||
function fail() {
|
||||
echo "ERROR: Replication broken!"
|
||||
if [[ ! "${REPLICA_STATUS}" =~ ${HEALTH_REGEX} ]]; then
|
||||
echo "ERROR: {{ postgres_ha_replica_enabled | ternary("Replication", "Tables") }} broken!"
|
||||
echo
|
||||
echo "${REPLICA_STATUS}";
|
||||
exit 2;
|
||||
}
|
||||
fi
|
||||
|
||||
{% if postgres_ha_is_master %}
|
||||
REGEX='state +| streaming'
|
||||
{% else %}
|
||||
REGEX='status +| streaming'
|
||||
{% endif %}
|
||||
[[ ! "${REPLICA_STATUS}" =~ ${REGEX} ]] && fail
|
||||
|
||||
echo "Replication healthy."
|
||||
echo "{{ postgres_ha_replica_enabled | ternary("Replication", "Tables") }} healthy."
|
||||
echo
|
||||
echo "${REPLICA_STATUS}" | grep -v -e '_lsn' -e '_lag'
|
||||
|
Loading…
x
Reference in New Issue
Block a user