From cbfac44b8671b9919ba54ea8008928483262b35a Mon Sep 17 00:00:00 2001 From: harinath Date: Tue, 8 Apr 2025 12:58:42 -0700 Subject: [PATCH] Make extension-owner as the owner of schema repack, and grant access to tables, functions in schema repack. This will ensure that the extension can be installed as trusted extension, and non-superusers can create and use the extension, without superuser/DBA help. --- lib/pg_repack.sql.in | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/pg_repack.sql.in b/lib/pg_repack.sql.in index b0596452..13d71dfd 100644 --- a/lib/pg_repack.sql.in +++ b/lib/pg_repack.sql.in @@ -380,3 +380,19 @@ LANGUAGE C STABLE STRICT; CREATE FUNCTION repack.get_table_and_inheritors(regclass) RETURNS regclass[] AS 'MODULE_PATHNAME', 'repack_get_table_and_inheritors' LANGUAGE C STABLE STRICT; + +DO $$ +DECLARE + pg_version_num TEXT; + major_version INT; +BEGIN + -- Get the pg version + SELECT current_setting('server_version_num') INTO pg_version_num; + major_version := pg_version_num::INT; + + IF major_version >= 130000 THEN + ALTER SCHEMA repack OWNER TO @extowner@; + GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA repack TO @extowner@; + GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA repack TO @extowner@; + END IF; +END $$;