Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As per subject when a sequence hits its max val what happens?

What is the behavior? I have a big table with a sequence as a primary key and would like to know.


share|improve this question
So, some stuff to clear up: a sequence is not a PK, it just feeds autogenerated values for newly inserted rows which don't specify an explicit value for it. Also, you don't tell if the sequence is set to CYCLE or NOCYCLE (if you defined the PK with serial, the latter is the case). If it is cycling, it will just restart at the MINVALUE defined. – dezso Dec 12 '13 at 15:12
up vote 5 down vote accepted

If you try it, you'll get:

ERROR: nextval: reached maximum value of sequence "testseq" (9223372036854775807): select nextval('testseq')

This is the case when the sequence is created automatically for a serial or bigserial column. You can create a sequence with specifying CYCLE, in which case it will restart from the MINVALUE specified (or left at the default 1).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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