set -e echo "== Dropping subscriptions slots and publications on PRIMARY ==" for db in $(psql -Atqc "SELECT datname FROM pg_database WHERE datallowconn AND datname NOT IN ('template0','template1')"); do echo "Processing DB: $db" SLOT="migrate_slot_${db}" # Drop slot if exists if psql -d "$db" -Atqc "SELECT 1 FROM pg_replication_slots WHERE slot_name = '$SLOT'" | grep -q 1; then echo " Dropping slot: $SLOT" psql -d "$db" -c "SELECT pg_drop_replication_slot('$SLOT');" else echo " Slot not found: $SLOT" fi # Drop publication if exists psql -d "$db" -v ON_ERROR_STOP=1 <