From d36738b343983202dd2c333cff60c0b9624c05aa Mon Sep 17 00:00:00 2001 From: Paul Cioanca Date: Sun, 15 Dec 2024 17:49:35 +0200 Subject: [PATCH] fix: pgmq perms+data --- .../pg_upgrade_scripts/complete.sh | 74 ++++++++++++++++++- .../20241215003910_backfill_pgmq_metadata.sql | 29 ++++++++ 2 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 migrations/db/migrations/20241215003910_backfill_pgmq_metadata.sql 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 c8542c685..515c490f6 100755 --- a/ansible/files/admin_api_scripts/pg_upgrade_scripts/complete.sh +++ b/ansible/files/admin_api_scripts/pg_upgrade_scripts/complete.sh @@ -79,7 +79,79 @@ EOF run_sql -c "$RECREATE_PG_CRON_QUERY" fi - # #incident-2024-09-12-project-upgrades-are-temporarily-disabled + # 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 <' + insert into pgmq.meta (queue_name, is_partitioned, is_unlogged, created_at) + select + substring(c.relname from 3) as queue_name, + false as is_partitioned, + case when c.relpersistence = 'u' then true else false end as is_unlogged, + now() as created_at + from + pg_catalog.pg_class c + join pg_catalog.pg_namespace n + on c.relnamespace = n.oid + where + n.nspname = 'pgmq' + and c.relname like 'q_%' + and c.relkind in ('r', 'p', 'u'); + end if; +end $$; + +-- migrate:down