Skip to content

Commit b57a412

Browse files
authored
pgmq don't manipulate sequences
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
1 parent 3642def commit b57a412

File tree

1 file changed

+0
-67
lines changed
  • ansible/files/admin_api_scripts/pg_upgrade_scripts

1 file changed

+0
-67
lines changed

ansible/files/admin_api_scripts/pg_upgrade_scripts/complete.sh

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -82,73 +82,6 @@ EOF
8282
# Patching pgmq ownership as it resets during upgrade
8383
HAS_PGMQ=$(run_sql -A -t -c "select count(*) > 0 from pg_extension where extname = 'pgmq';")
8484
if [ "$HAS_PGMQ" = "t" ]; then
85-
PATCH_PGMQ_QUERY=$(cat <<EOF
86-
do \$\$
87-
declare
88-
tbl record;
89-
seq_name text;
90-
new_seq_name text;
91-
archive_table_name text;
92-
begin
93-
-- Loop through each table in the pgmq schema starting with 'q_'
94-
-- Rebuild the pkey column's default to avoid pg_dumpall segfaults
95-
for tbl in
96-
select c.relname as table_name
97-
from pg_catalog.pg_attribute a
98-
join pg_catalog.pg_class c on c.oid = a.attrelid
99-
join pg_catalog.pg_namespace n on n.oid = c.relnamespace
100-
where n.nspname = 'pgmq'
101-
and c.relname like 'q_%'
102-
and a.attname = 'msg_id'
103-
and a.attidentity in ('a', 'd') -- 'a' for ALWAYS, 'd' for BY DEFAULT
104-
loop
105-
-- Check if msg_id is an IDENTITY column for idempotency
106-
-- Define sequence names
107-
seq_name := 'pgmq.' || format ('"%s_msg_id_seq"', tbl.table_name);
108-
new_seq_name := 'pgmq.' || format ('"%s_msg_id_seq2"', tbl.table_name);
109-
archive_table_name := regexp_replace(tbl.table_name, '^q_', 'a_');
110-
-- Execute dynamic SQL to perform the required operations
111-
execute format('
112-
create sequence %s;
113-
select setval(''%s'', nextval(''%s''));
114-
alter table %s."%s" alter column msg_id drop identity;
115-
alter table %s."%s" alter column msg_id set default nextval(''%s'');
116-
alter sequence %s rename to "%s";',
117-
-- Parameters for format placeholders
118-
new_seq_name,
119-
new_seq_name, seq_name,
120-
'pgmq', tbl.table_name,
121-
'pgmq', tbl.table_name,
122-
new_seq_name,
123-
-- alter seq
124-
new_seq_name,
125-
tbl.table_name || '_msg_id_seq'
126-
);
127-
end loop;
128-
-- No tables should be owned by the extension.
129-
-- We want them to be included in logical backups
130-
for tbl in
131-
select c.relname as table_name
132-
from pg_class c
133-
join pg_depend d
134-
on c.oid = d.objid
135-
join pg_extension e
136-
on d.refobjid = e.oid
137-
where
138-
c.relkind in ('r', 'p', 'u')
139-
and e.extname = 'pgmq'
140-
and (c.relname like 'q_%' or c.relname like 'a_%')
141-
loop
142-
execute format('
143-
alter extension pgmq drop table pgmq."%s";',
144-
tbl.table_name
145-
);
146-
end loop;
147-
end \$\$;
148-
EOF
149-
)
150-
151-
run_sql -c "$PATCH_PGMQ_QUERY"
15285
run_sql -c "update pg_extension set extowner = 'postgres'::regrole where extname = 'pgmq';"
15386
fi
15487

0 commit comments

Comments
 (0)