32

How can I grant the SELECT privilege on all sequences to a user using one statement? Somthing like:

GRANT SELECT ON <ALL SEQUENCES???> TO myUser
1

5 Answers 5

64

In PostgreSQL 9.x, you can grant permissions on all sequences in one schema to a role. The syntax is

GRANT SELECT
ON ALL SEQUENCES IN SCHEMA schema_name
    TO role_name

The role can be either a group role or a login role (user name).

2
41

This will be very useful in the future:

GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA schema_name TO your_user;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA schema_name TO your_user;
GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA schema_name TO your_user;
2
  • what are all privileges means for sequences..? Jul 4, 2018 at 12:00
  • Allow to perform this actions: currval(), lastval(), nextval(), setval() and DROP. Aug 9, 2018 at 15:50
13

The accepted answer dont worked for me on 9.1. The below sentence did work:

GRANT ALL ON ALL SEQUENCES IN SCHEMA public TO user;
1
  • 5
    you need SELECT, USAGE if you want to actually modify the sequence Apr 18, 2014 at 1:00
3

It works in Postgres 13

GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO admin;
2

For Postgres versions lower than 9.0

psql -d DBNAME -qAt -c "SELECT 'GRANT SELECT ON ' || relname || ' TO USER;' FROM pg_statio_all_sequences WHERE schemaname = 'public'" | psql -d DBNAME

Ref: http://gotochriswest.com/blog/2012/06/11/postgresql-granting-access-to-all-sequences/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.