1

Context

I want to grant privileges to a specific user, on the public schema in database mydb.

Currently, I connect as user postgres on database mydb, and run :

GRANT insert, update, delete, truncate ON ALL TABLES IN SCHEMA public TO myuser

My Issue

I would feel more comfortable naming the target database in the query, rather than relying on the connection being on the correct database.

For example, I wouldn't want to accidentally give accesses on the postgres database, rather than on mydb.

Question

Is there a way to target tables in another database in a GRANT query ?

I couldn't find a way to do so in the doc (perhaps I overlooked a paragraph ?) and the following do not work :

# grant insert on all tables in schema mydb.public to myuser;
ERROR:  syntax error at or near "."
LINE 1: grant insert on all tables in schema mydb.public to...
                                                          ^
# grant insert on mydb.public.mytable1 to myuser;
ERROR:  cross-database references are not implemented: "mydb.public.mytable1"

1 Answer 1

2

No, as the error message says, cross-database references are not implemented.

This is a security feature: There is no way to affect another database than the one you are connected to with an SQL statement (unless you are using something like dblink or foreign data wrappers).

Not the answer you're looking for? Browse other questions tagged or ask your own question.