Book Image

PostgreSQL 9 Administration Cookbook - Second Edition

Book Image

PostgreSQL 9 Administration Cookbook - Second Edition

Overview of this book

Table of Contents (19 chapters)
PostgreSQL 9 Administration Cookbook Second Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

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 in PostgreSQL to have some privileges in order to have others. This means that you may well have "write-only" tables, where you are allowed to insert but you can't select. This can be used to implement a mail-queue-like functionality, where several...