burik=# create table test (id serial not null primary key, value integer);
CREATE TABLE
burik=# alter sequence test_id_seq maxvalue 2;
ALTER SEQUENCE
burik=# insert into test (value) VALUES(1);
INSERT 0 1
burik=# insert into test (value) VALUES(2);
INSERT 0 1
burik=# insert into test (value) VALUES(3);
ERROR: nextval: reached maximum value of sequence "test_id_seq" (2)