mirror of
https://github.com/status-im/infra-role-postgres-ha.git
synced 2025-02-22 03:18:13 +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 }}'
|
tcp: 'localhost:{{ postgres_ha_cont_port }}'
|
||||||
|
|
||||||
- id: '{{ postgres_ha_service_name }}-mirror'
|
- 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 }}'
|
disabled: '{{ not postgres_ha_replica_enabled }}'
|
||||||
type: 'script'
|
type: 'script'
|
||||||
script: '{{ postgres_ha_service_path }}/health.sh'
|
script: '{{ postgres_ha_service_path }}/health.sh'
|
||||||
|
@ -2,29 +2,27 @@
|
|||||||
# vim: set ft=sh:
|
# vim: set ft=sh:
|
||||||
set -Eeo pipefail
|
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'
|
STATUS_QUERY='SELECT * FROM pg_stat_replication'
|
||||||
|
HEALTH_REGEX='status +| streaming'
|
||||||
{% else %}
|
{% else %}
|
||||||
STATUS_QUERY='SELECT * FROM pg_stat_wal_receiver'
|
STATUS_QUERY='SELECT * FROM pg_stat_wal_receiver'
|
||||||
|
HEALTH_REGEX='status +| streaming'
|
||||||
{% endif %}
|
{% endif %}
|
||||||
REPLICA_STATUS=$(
|
REPLICA_STATUS=$(
|
||||||
"{{ postgres_ha_service_path }}/admin.sh" -x -c "${STATUS_QUERY}"
|
"{{ postgres_ha_service_path }}/admin.sh" -x -c "${STATUS_QUERY}"
|
||||||
)
|
)
|
||||||
|
|
||||||
function fail() {
|
if [[ ! "${REPLICA_STATUS}" =~ ${HEALTH_REGEX} ]]; then
|
||||||
echo "ERROR: Replication broken!"
|
echo "ERROR: {{ postgres_ha_replica_enabled | ternary("Replication", "Tables") }} broken!"
|
||||||
echo
|
echo
|
||||||
echo "${REPLICA_STATUS}";
|
echo "${REPLICA_STATUS}";
|
||||||
exit 2;
|
exit 2;
|
||||||
}
|
fi
|
||||||
|
|
||||||
{% if postgres_ha_is_master %}
|
echo "{{ postgres_ha_replica_enabled | ternary("Replication", "Tables") }} healthy."
|
||||||
REGEX='state +| streaming'
|
|
||||||
{% else %}
|
|
||||||
REGEX='status +| streaming'
|
|
||||||
{% endif %}
|
|
||||||
[[ ! "${REPLICA_STATUS}" =~ ${REGEX} ]] && fail
|
|
||||||
|
|
||||||
echo "Replication healthy."
|
|
||||||
echo
|
echo
|
||||||
echo "${REPLICA_STATUS}" | grep -v -e '_lsn' -e '_lag'
|
echo "${REPLICA_STATUS}" | grep -v -e '_lsn' -e '_lag'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user