HiveBrain v1.2.0
Get Started
← Back to all entries
patternMajor

Grant SELECT on all tables in Redshift

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
tablesredshiftallgrantselect

Problem

I am trying to assign SELECT privilege to a group in Redshift. So I created a group and a user in that group:

CREATE GROUP data_viewers;
CREATE USER  PASSWORD '' IN GROUP data_viewers;


Now I would like to allow this group to be able to read data from any table:

GRANT SELECT ON ALL TABLES IN SCHEMA PUBLIC TO GROUP data_viewers;


The command returns GRANT. Now when I connect to Redshift as my newly created user and issue SELECT * FROM something.something; I get:


permission denied for schema something

I tried granting permissions to something: GRANT SELECT ON ALL TABLES IN SCHEMA something TO GROUP data_viewers; but this has not changed anything.

How can I allow users from my group to SELECT data from any table in the schema?

Solution

You need the USAGE privilege (at least) for the schema as well:

GRANT USAGE ON SCHEMA something TO GROUP data_viewers;


Related Postgres example:

  • Permission for sequence in another schema



Remember you only granted permissions to already existing tables. Does not apply to tables created later. To cover those, too:

ALTER DEFAULT PRIVILEGES FOR USER role_that_creates_tables
IN SCHEMA public
GRANT SELECT ON TABLES TO GROUP data_viewers;


Amazon Redshift implemented DEFAULT PRIVILEGES as well.

Here is a complete cookbook for Postgres:

  • How to manage DEFAULT PRIVILEGES for USERs on a DATABASE vs SCHEMA?



Be aware of some differences between mainline Postgres and Redshift! Redshift sticks to separate users and groups, while Postgres replaced that with the universal concept of roles:

  • Why did PostgreSQL merge users and groups into roles?



And I am not sure how Redshift handles sequences ...

Code Snippets

GRANT USAGE ON SCHEMA something TO GROUP data_viewers;
ALTER DEFAULT PRIVILEGES FOR USER role_that_creates_tables
IN SCHEMA public
GRANT SELECT ON TABLES TO GROUP data_viewers;

Context

StackExchange Database Administrators Q#135720, answer score: 22

Revisions (0)

No revisions yet.