Is there a one-liner that grants the SELECT permissions to a new user postgresql?
Something that would implement the following pseudo-code:
GRANT SELECT ON TABLE * TO my_new_user;
Is there a one-liner that grants the SELECT permissions to a new user postgresql?
Something that would implement the following pseudo-code:
GRANT SELECT ON TABLE * TO my_new_user;
I thought it might be helpful to mention that, as of 9.0, postgres does have the syntax to grant privileges on all tables (as well as other objects) in a schema:
Here's the link.
My (non-one-liner) solution:
Run from the privileged user, it worked like a charm.
This can be done with a two-step process.
Run this query:
Replacements:
$foo
= username you want to grant permissions for$bar
,$baz
= schemas you want to grant permissions in (can be just "public")That's going to give you a list of queries that will generate the required permissions. Copy the output, paste it into another query, and execute.
I ended up doing this, and it worked:
I ended up here because my DB user saw only a few tables and not the newer ones. If this is your case, this has helped me.
Grant privileges to all existing tables:
Grant privileges to all new tables to be created in future (via default privileges):
You can also double-check that all tables are granted correctly.
Count all existing tables:
Count all tables the user has access to:
The count of last two queries must be the same.
This is what I used:
I feel it's more natural to do formatting and where-clauses in sql..
I'm working with postgres 8.4 and to give all privileges to a user do the following:
one way to fix this is to write a stored procedure. unfortunately there is no "grant everything to all tables" command or so. you really need a procedure or some external shell script maybe to make this work.
The (one-liner solution) script by Adam Matan is great when there are many schema's, but it doesn't work where schema names or table names contain uppercase letters or special characters.
Modified version: