veza/ansible/roles/postgres/files/pg_replication_slots_discovery.sh
2025-12-03 22:56:50 +01:00

6 lines
346 B
Bash

#!/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 "]}"}'