Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I forget what version PostgreSQL added the syntax, but one of the easiest ways to administer permissions in PostgreSQL is through the "GRANT foo, priv ON ALL something IN SCHEMA" syntax.</p> <pre><code>BEGIN; GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA my_schema TO my_role; GRANT USAGE ON ALL SEQUENCES IN SCHEMA my_schema TO my_role; GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA my_schema TO my_role; COMMIT; </code></pre> <p>Very handy for making sure that permissions are always set correctly.</p> <p>The EXECUTE for FUNCTIONS may seem spooky, but shouldn't be unless your functions were created with the SECURITY DEFINER attribute (and if you are using SECURITY DEFINER, you'd better be cautious since you're playing around with the PostgreSQL version of a "setuid" function). If you space out your TABLES across different SCHEMAS based on the expected permissions, then this becomes a pretty handy convention when used with the search_path variable.</p> <pre><code>ALTER ROLE my_role SET search_path = my_schema, auth_schema, public; -- Avoid using the public schema (pretty please) </code></pre> <p>Where auth_schema has a collection of tables that my_role shouldn't have direct read or write privileges on. Assigning privs to GROUPS is also useful.</p> <p>Here are some relevant docs:</p> <p><a href="http://developer.postgresql.org/pgdocs/postgres/sql-grant.html" rel="nofollow">http://developer.postgresql.org/pgdocs/postgres/sql-grant.html</a></p> <p>Don't forget you can use "\h GRANT" in psql to easily figure out the syntax or remember what can be done on all objects in a schema (search for "IN SCHEMA").</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload