Granting user access to a table

A user needs to have access to a table in order to perform any action on it.

Getting ready

Make sure that you have appropriate roles defined, and that privileges are revoked from the PUBLIC role.

How to do it…

Grant access to the schema containing the table, as follows:

GRANT USAGE ON someschema TO somerole;
GRANT SELECT, INSERT, UPDATE, DELETE ON someschema.sometable TO somerole;
GRANT somerole TO someuser, otheruser;

How it works…

This sequence of commands first grants full access to all objects in that schema to a role, gives viewing (SELECT) and modifying (INSERT, UPDATE, and DELETE) rights on that table to the role, and then grants membership in that role to two database users.

There's more…

There is no requirement ...

Get PostgreSQL 9 Administration Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.