Re: Problems with sequences

From: Scott Marlowe <smarlowe(at)g2switchworks(dot)com>
To: Arturo Perez <aperez(at)hayesinc(dot)com>
Cc: pgsql general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Problems with sequences
Date: 2006-09-06 22:23:18
Message-ID: 1157581398.20424.32.camel@state.g2switchworks.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 2006-09-06 at 16:56, Arturo Perez wrote:
> Hi all,
>
> My environment is Tomcat5.0, Cayenne 1.2 and PostgreSQL 8.1.4 on a
> RedHat ES3 machine.
>
> My webapplication is reusing sequence numbers and getting duplicate
> primary key
> failures because of it (error is "duplicate key violates unique
> constraint"). The
> columns are not defined as SERIAL for historical reasons so it fetches
> nextval and
> uses that.
>
> The webapp stays connected for days at a time. It's only using a
> handful (usually 2) connections.
>
> What happens is that if I do a select nextval('seq') I get a number
> that's lower than the
> max primary key id. This is inspite of my doing
> SELECT setval('seq', ((SELECT MAX(seq_ID) FROM table)+1))
> ALTER SEQUENCE seq RESTART WITH <max + 1>;
> select pg_catalog.setval(seq, <max+1>, true);

When are you doing these statements? You shouldn't really need to set a
sequence to a new number except right after a data load or something
like that. definitely not when anyone else is using the db.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Chris Browne 2006-09-06 22:50:10 Re: On DNS for postgresql.org
Previous Message Wayne Conrad 2006-09-06 22:21:04 Child program using parent program's transaction?