Pages

Friday, January 14, 2011

Grant & Revoke access on PostgreSQL

Grant manual:
http://www.postgresql.org/docs/8.3/static/sql-grant.html

Revoke manual:
http://www.postgresql.org/docs/8.2/static/sql-revoke.html

By default, postgresql doesn't provide syntax for grant/revoking privileges from all tables, to do it just follow simple tricks:

=== quoted from http://postgresql.1045698.n5.nabble.com/REVOKE-from-all-tables-td2077327.html ===
I like doing things like with just psql as shown below. And, I get to
look at the commands before running them.  For example: something
like this to revoke all for all tables in the public schema:

  -- Turn off headers:
  \t
  -- Use SQL to build SQL:
  SELECT 'REVOKE ALL ON public.' || table_name || ' FROM PUBLIC;'
  FROM information_schema.tables
    WHERE table_type = 'BASE TABLE' AND table_schema='public';
  -- If the output looks good, write it to a file and run it:
  \g out.tmp
  \i out.tmp

It works pretty well on similar tasks, at least until you run into string
quote/escape problems.

=== end quote ===

No comments:

Post a Comment