WIP Prepare postgres for migration by replication
This commit is contained in:
28
site-cookbooks/kosmos_postgresql/files/drop_subscriptions.sh
Normal file
28
site-cookbooks/kosmos_postgresql/files/drop_subscriptions.sh
Normal file
@@ -0,0 +1,28 @@
|
||||
set -e
|
||||
|
||||
echo "== Dropping subscriptions on PG14 =="
|
||||
|
||||
for db in $(psql -Atqc "SELECT datname FROM pg_database WHERE datallowconn AND datname NOT IN ('template0,'template1'')"); do
|
||||
echo "Processing DB: $db"
|
||||
|
||||
SUB="migrate_sub_${db}"
|
||||
|
||||
# Disable first (important)
|
||||
psql -d "$db" -c "ALTER SUBSCRIPTION $SUB DISABLE;" 2>/dev/null || true
|
||||
|
||||
# Drop subscription if exists
|
||||
psql -d "$db" -v ON_ERROR_STOP=1 <<SQL
|
||||
DO \$\$
|
||||
BEGIN
|
||||
IF EXISTS (
|
||||
SELECT 1 FROM pg_subscription WHERE subname = '$SUB'
|
||||
) THEN
|
||||
DROP SUBSCRIPTION $SUB;
|
||||
END IF;
|
||||
END
|
||||
\$\$;
|
||||
SQL
|
||||
|
||||
done
|
||||
|
||||
echo "== Done =="
|
||||
Reference in New Issue
Block a user