veza/ansible/roles/postgres/files/pg_replication_slots_discovery.sh

7 lines
346 B
Bash
Raw Normal View History

#!/bin/bash
if [[ "$(systemctl show --value --property UnitFileState patroni)" == "enabled" ]]; then
filter="WHERE slot_name like 'pitr%'"
fi
/usr/bin/sudo -u postgres /usr/bin/psql -p $1 -Atc "select slot_name from pg_replication_slots $filter" |awk 'BEGIN{printf "{\"data\":["}; {printf c"{\"{#SLOT}\":\""$1"\"}";c=","}; END{print "]}"}'