WIP Prepare postgres for migration by replication
This commit is contained in:
29
site-cookbooks/kosmos_postgresql/files/drop_subscriptions.sh
Normal file
29
site-cookbooks/kosmos_postgresql/files/drop_subscriptions.sh
Normal file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
echo "== Dropping subscriptions =="
|
||||
|
||||
for db in $(psql -Atqc "SELECT datname FROM pg_database WHERE datallowconn AND datname NOT IN ('template1')"); do
|
||||
echo "Processing DB: $db"
|
||||
|
||||
SUB="migrate_sub_${db}"
|
||||
|
||||
# Check if subscription exists
|
||||
EXISTS=$(psql -d "$db" -Atqc "SELECT 1 FROM pg_subscription WHERE subname = '$SUB'")
|
||||
|
||||
if [ "$EXISTS" = "1" ]; then
|
||||
echo " Found subscription: $SUB"
|
||||
|
||||
# Disable first (good practice)
|
||||
psql -d "$db" -c "ALTER SUBSCRIPTION $SUB DISABLE;"
|
||||
|
||||
# Drop it (must be top-level)
|
||||
psql -d "$db" -c "DROP SUBSCRIPTION $SUB;"
|
||||
|
||||
else
|
||||
echo " No subscription: $SUB"
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
echo "== Done =="
|
||||
Reference in New Issue
Block a user