Skip to content

Commit 514fde3

Browse files
committed
update pgmq after-create script for pg 17
1 parent 8cec32f commit 514fde3

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

ansible/files/postgresql_extension_custom_scripts/pgmq/after-create.sql

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,41 @@ do $$
22
declare
33
extoid oid := (select oid from pg_extension where extname = 'pgmq');
44
r record;
5+
cls pg_class%rowtype;
56
begin
7+
68
set local search_path = '';
79
update pg_extension set extowner = 'postgres'::regrole where extname = 'pgmq';
10+
811
for r in (select * from pg_depend where refobjid = extoid) loop
12+
13+
914
if r.classid = 'pg_type'::regclass then
10-
execute(format('alter type %s owner to postgres;', r.objid::regtype));
15+
16+
-- store the type's relkind
17+
select * into cls from pg_class c where c.reltype = r.objid;
18+
19+
if r.objid::regtype::text like '%[]' then
20+
-- do nothing (skipping array type)
21+
22+
elsif cls.relkind in ('r', 'p', 'f', 'm') then
23+
-- table-like objects (regular table, partitioned, foreign, materialized view)
24+
execute format('alter table pgmq.%I owner to postgres;', cls.relname);
25+
26+
else
27+
execute(format('alter type %s owner to postgres;', r.objid::regtype));
28+
29+
end if;
30+
1131
elsif r.classid = 'pg_proc'::regclass then
1232
execute(format('alter function %s(%s) owner to postgres;', r.objid::regproc, pg_get_function_identity_arguments(r.objid)));
33+
1334
elsif r.classid = 'pg_class'::regclass then
1435
execute(format('alter table %s owner to postgres;', r.objid::regclass));
36+
1537
else
1638
raise exception 'error on pgmq after-create script: unexpected object type %', r.classid;
39+
1740
end if;
1841
end loop;
1942
end $$;

0 commit comments

Comments
 (0)