mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-16 01:42:55 +00:00
ALTER SUBSCRIPTION requires AccessExclusive lock which conflicts with iteration over pg_subscription when multiple databases are present and operations are applied concurrently. Fix by explicitly locking pg_subscription in the beginning of the transaction in each database. ## Problem https://github.com/neondatabase/cloud/issues/24292
13 lines
477 B
SQL
13 lines
477 B
SQL
DO $$
|
|
DECLARE
|
|
subname TEXT;
|
|
BEGIN
|
|
LOCK TABLE pg_subscription IN ACCESS EXCLUSIVE MODE;
|
|
FOR subname IN SELECT pg_subscription.subname FROM pg_subscription WHERE subdbid = (SELECT oid FROM pg_database WHERE datname = {datname_str}) LOOP
|
|
EXECUTE format('ALTER SUBSCRIPTION %I DISABLE;', subname);
|
|
EXECUTE format('ALTER SUBSCRIPTION %I SET (slot_name = NONE);', subname);
|
|
EXECUTE format('DROP SUBSCRIPTION %I;', subname);
|
|
END LOOP;
|
|
END;
|
|
$$;
|