A sequence in PostgreSQL is a user-defined schema-bound object that yields a sequence of integers based on a specified specification. The CREATE SEQUENCE statement is used to create sequences in PostgreSQL.
The following privileges are valid for sequences: SELECT: Execute functions CURRVAL and NEXTVAL on the specified sequences. ALTER: Modify a sequence's DDL with ALTER SEQUENCE.
Since PostgreSQL 8.2 you have to use:
GRANT USAGE, SELECT ON SEQUENCE cities_id_seq TO www;
GRANT USAGE - For sequences, this privilege allows the use of the currval and nextval functions.
Also as pointed out by @epic_fil in the comments you can grant permissions to all the sequences in the schema with:
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO www;
Note: Don't forget to choose the database (\c <database_name>
) before executing the privilege grant commands
Since @Phil has a comment getting a lot of upvotes which might not get noticed, I'm using his syntax to add an answer that will grant permissions to a user for all sequences in a schema (assuming your schema is the default 'public')
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public to www;
@Tom_Gerken, @epic_fil and @kupson are quite correct with their statements to give permissions to work with existing sequences. However, the user will NOT get access rights to sequences created in the future. To do that, you have to combine the GRANT statement with an ALTER DEFAULT PRIVILEGES statement, like so:
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO www;
ALTER DEFAULT PRIVILEGES IN SCHEMA public
GRANT USAGE, SELECT ON SEQUENCES TO www;
This only works on PostgreSQL 9+, of course.
This will append to existing default privileges, not overwrite them, so is quite safe in that regard.
It is due to permission issue on the SEQUENCES.
Try the following command to resolve the issue,
GRANT USAGE, SELECT ON SEQUENCE sequence_name TO user_name;
Eg:
GRANT USAGE, SELECT ON SEQUENCE cities_id_seq TO www;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With