简体   繁体   中英

How do I grant privilges on all tables in a schema in a particular database?

First, here is an overview of how my Postgres is set up

I have 3 Databases and within each database there is a schema which shares the same name across all 3 databases.

I have written a script to create a role and give it some privileges for the schemas in each database.

This is how I grant the privileges to the role:

\c Database1
GRANT SELECT, UPDATE, INSERT ON ALL TABLES IN SCHEMA "schemaName" TO roleName;
\c Database2
GRANT SELECT, UPDATE, INSERT ON ALL TABLES IN SCHEMA "schemaName" TO roleName;
\c Database3
GRANT SELECT, UPDATE, INSERT ON ALL TABLES IN SCHEMA "schemaName" TO roleName;

Is there a way to explicitly state which database I want to affect within the GRANT statement?

No it is not possible: each database in a instance/cluster is isolated and there is no possibility to reference a database different from the current one (unless you use some extension like dblink or postgres_fdw).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM