supabase-postgres.git / summary / log / commit / refs

commit    48f22dd2eef5bee8f029e82bcf653a68a166a1ec
Author:   Oliver Rice <github@oliverrice.com>
Commit:   GitHub <noreply@github.com>
Date:     Mon Jul 07 19:22:30 2025 +0000

    pgmq don't manipulate sequences (#1471)
    
    The script being deleted was a hacky solution we put in place to resolve a pg_dump segfault due to its interaction with pgmq tables. It currently introduces errors where sequences become owned by supabase_admin and are inaccessible to users after upgrading.
    https://supabase.slack.com/archives/C05Q0CVC65B/p1741093731995359
    
    
    This update mirrors the same code's removal from our on-backup hook here: https://github.com/supabase/infrastructure/pull/21405/files
    
    Co-authored-by: Bobbie Soedirgo <bobbie@soedirgo.dev>


.../pg_upgrade_scripts/complete.sh | 67 ---------------------- 1 file changed, 67 deletions(-) diff --git a/ansible/files/admin_api_scripts/pg_upgrade_scripts/complete.sh b/ansible/files/admin_api_scripts/pg_upgrade_scripts/complete.sh index 31cc7d09..e170482e 100755 --- a/ansible/files/admin_api_scripts/pg_upgrade_scripts/complete.sh +++ b/ansible/files/admin_api_scripts/pg_upgrade_scripts/complete.sh @@ -148,73 +148,6 @@ EOF # Patching pgmq ownership as it resets during upgrade HAS_PGMQ=$(run_sql -A -t -c "select count(*) > 0 from pg_extension where extname = 'pgmq';") if [ "$HAS_PGMQ" = "t" ]; then - PATCH_PGMQ_QUERY=$(cat <<EOF - do \$\$ - declare - tbl record; - seq_name text; - new_seq_name text; - archive_table_name text; - begin - -- Loop through each table in the pgmq schema starting with 'q_' - -- Rebuild the pkey column's default to avoid pg_dumpall segfaults - for tbl in - select c.relname as table_name - from pg_catalog.pg_attribute a - join pg_catalog.pg_class c on c.oid = a.attrelid - join pg_catalog.pg_namespace n on n.oid = c.relnamespace - where n.nspname = 'pgmq' - and c.relname like 'q_%' - and a.attname = 'msg_id' - and a.attidentity in ('a', 'd') -- 'a' for ALWAYS, 'd' for BY DEFAULT - loop - -- Check if msg_id is an IDENTITY column for idempotency - -- Define sequence names - seq_name := 'pgmq.' || format ('"%s_msg_id_seq"', tbl.table_name); - new_seq_name := 'pgmq.' || format ('"%s_msg_id_seq2"', tbl.table_name); - archive_table_name := regexp_replace(tbl.table_name, '^q_', 'a_'); - -- Execute dynamic SQL to perform the required operations - execute format(' - create sequence %s; - select setval(''%s'', nextval(''%s'')); - alter table %s."%s" alter column msg_id drop identity; - alter table %s."%s" alter column msg_id set default nextval(''%s''); - alter sequence %s rename to "%s";', - -- Parameters for format placeholders - new_seq_name, - new_seq_name, seq_name, - 'pgmq', tbl.table_name, - 'pgmq', tbl.table_name, - new_seq_name, - -- alter seq - new_seq_name, - tbl.table_name || '_msg_id_seq' - ); - end loop; - -- No tables should be owned by the extension. - -- We want them to be included in logical backups - for tbl in - select c.relname as table_name - from pg_class c - join pg_depend d - on c.oid = d.objid - join pg_extension e - on d.refobjid = e.oid - where - c.relkind in ('r', 'p', 'u') - and e.extname = 'pgmq' - and (c.relname like 'q_%' or c.relname like 'a_%') - loop - execute format(' - alter extension pgmq drop table pgmq."%s";', - tbl.table_name - ); - end loop; - end \$\$; -EOF - ) - - run_sql -c "$PATCH_PGMQ_QUERY" run_sql -c "update pg_extension set extowner = 'postgres'::regrole where extname = 'pgmq';" fi [parent: 990483154743]