From c58a0841020595fd94f9f7d4ff68fb3e9b03887d Mon Sep 17 00:00:00 2001 From: Rafa de la Torre Date: Fri, 12 Jul 2019 13:27:41 +0200 Subject: [PATCH] Tweak ownership of db objects --- scripts-available/CDB_ForeignTable.sql | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts-available/CDB_ForeignTable.sql b/scripts-available/CDB_ForeignTable.sql index 66c4e3c..29fb4bc 100644 --- a/scripts-available/CDB_ForeignTable.sql +++ b/scripts-available/CDB_ForeignTable.sql @@ -203,6 +203,9 @@ BEGIN EXECUTE format('CREATE ROLE %I NOLOGIN', fdw_name); END IF; + -- Transfer ownership of the server to the fdw role + EXECUTE format('ALTER SERVER %I OWNER TO %I', fdw_name, fdw_name); + -- Create user mapping IF NOT EXISTS ( SELECT * FROM pg_user_mappings WHERE srvname = fdw_name AND usename = fdw_name ) THEN EXECUTE FORMAT ('CREATE USER MAPPING FOR %I SERVER %I', fdw_name, fdw_name); @@ -226,8 +229,8 @@ BEGIN EXECUTE FORMAT ('CREATE SCHEMA %I', fdw_name); END IF; - -- Give the fdw role usage permisions over the schema - EXECUTE FORMAT ('GRANT USAGE ON SCHEMA %I TO %I', fdw_name, fdw_name); + -- Give the fdw role ownership over the schema + EXECUTE FORMAT ('ALTER SCHEMA %I OWNER TO %I', fdw_name, fdw_name); -- Grant the fdw role to the caller, and permissions to grant it to others EXECUTE FORMAT ('GRANT %I TO %I WITH ADMIN OPTION', fdw_name, session_user);