In step one on this page it says to add select on sequence. Being relatively new to Postgres, what is a sequence and why does it need separate permissions and why is there what looks like an extra table for the sequence I didn't create?

-- run this in psql using the database created
-- in the previous tutorial

create role todo_user nologin;
grant todo_user to authenticator;

grant usage on schema api to todo_user;
grant all on api.todos to todo_user;
grant usage, select on sequence api.todos_id_seq to todo_user;

1 Answer 1


I should mark the question as "needs focus", since you ask three questions, but it is simple enough:

  • A sequence is an object that efficiently generates unique numbers, even when used by many sessions in parallel.

  • Sequences have permissions just like all other objects. By default, only the owner (the user that created the sequence) can use it. If you grant SELECT on a sequence to a user, that user can read the current value from the sequence, but it cannot use the nextval function to get the next value.

  • Sequences are “relations” in PostgreSQL (that is, something with columns, whose metadata are stored in pg_class). This is an implementation detail of PostgreSQL that changed somewhat in v10. The “table” now contains a single row that contains those metadata that are changed by nextval.

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.