|
2 | 2 | declare
|
3 | 3 | extoid oid := (select oid from pg_extension where extname = 'pgmq');
|
4 | 4 | r record;
|
| 5 | + cls pg_class%rowtype; |
5 | 6 | begin
|
| 7 | + |
6 | 8 | set local search_path = '';
|
7 | 9 | update pg_extension set extowner = 'postgres'::regrole where extname = 'pgmq';
|
| 10 | + |
8 | 11 | for r in (select * from pg_depend where refobjid = extoid) loop
|
| 12 | + |
| 13 | + |
9 | 14 | 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 | + |
11 | 31 | elsif r.classid = 'pg_proc'::regclass then
|
12 | 32 | execute(format('alter function %s(%s) owner to postgres;', r.objid::regproc, pg_get_function_identity_arguments(r.objid)));
|
| 33 | + |
13 | 34 | elsif r.classid = 'pg_class'::regclass then
|
14 | 35 | execute(format('alter table %s owner to postgres;', r.objid::regclass));
|
| 36 | + |
15 | 37 | else
|
16 | 38 | raise exception 'error on pgmq after-create script: unexpected object type %', r.classid;
|
| 39 | + |
17 | 40 | end if;
|
18 | 41 | end loop;
|
19 | 42 | end $$;
|
0 commit comments