Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 9C7E364FCF3; Wed, 19 Nov 2008 12:52:32 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 08751-09; Wed, 19 Nov 2008 12:52:28 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.gransy.com (unknown [82.208.29.208]) by mail.postgresql.org (Postfix) with ESMTP id 38DF264FC5A; Wed, 19 Nov 2008 12:52:27 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by mail.gransy.com (Postfix) with ESMTP id B68B67AC0AD; Wed, 19 Nov 2008 17:52:24 +0100 (CET) Received: from mail.gransy.com ([127.0.0.1]) by localhost (nathalia.gransy.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QT1vbsVT4A9D; Wed, 19 Nov 2008 17:52:24 +0100 (CET) Received: from anastacia.gransy.com (anastacia.gransy.com [89.187.130.100]) by mail.gransy.com (Postfix) with ESMTP id 7D90F7AC06A; Wed, 19 Nov 2008 17:52:24 +0100 (CET) Received: from sq.gransy.com (localhost [127.0.0.1]) by anastacia.gransy.com (Postfix) with ESMTP id 16137282C06; Wed, 19 Nov 2008 17:53:09 +0100 (CET) Received: from 89.102.139.23 (SquirrelMail authenticated user tv@fuzzy.cz) by sq.gransy.com with HTTP; Wed, 19 Nov 2008 17:53:09 +0100 (CET) Message-ID: <61685.89.102.139.23.1227113589.squirrel@sq.gransy.com> In-Reply-To: References: <4478b4ac0811190754n42d9539v4bd42350fac24d1@mail.gmail.com> Date: Wed, 19 Nov 2008 17:53:09 +0100 (CET) Subject: Re: [PERFORM] Very Urgent : Sequences Problem From: tv@fuzzy.cz To: "Merlin Moncure" Cc: Kranti�@sq.gransy.com, "K K Parisa" , pgsql-admin@postgresql.org, pgsql-performance@postgresql.org User-Agent: SquirrelMail/1.4.10a MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-2 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.1 tagged_above=0 required=5 tests=RDNS_NONE=0.1 X-Spam-Level: X-Archive-Number: 200811/116 X-Sequence-Number: 30770 > On Wed, Nov 19, 2008 at 10:54 AM, Kranti� K K Parisa > wrote: >> Hi, >> >> I have defined sequence on a table something like this >> >> >> CREATE SEQUENCE items_unqid_seq >> INCREMENT 1 >> MINVALUE 0 >> MAXVALUE 9223372036854775807 >> START 7659 >> CACHE 1; >> >> this is on a table called items. where i have currently the max(unq_id) >> as >> 7659. >> >> and in the stored procedure when i am inserting values into the items >> table >> for the unq_id column i am using the sequence as follows: >> >> nextval('items_unqid_seq'::text) >> >> >> it seems to be working some times. and the sequences are not getting >> updated >> sometime. which is casuing primary key exceptions. >> >> please advise as soon as possible. >> >> is there any trivial problem with sequences in postgresql?? > > no (at least none that I know of). > > maybe if you posted the source of your procedure? I bet your error is > coming form some other source. Are you sure you're using the nextval() properly whenever you insert data into the table? This usually happens when a developer does not use it properly, i.e. he just uses a (select max(id) + 1 from ...) something like that. One of the more creative ways of breaking sequences was calling nextval() only for the first insert, and then adding 1 to the ID. BTW. do you have RULEs defined on the table? Some time ago I run into a problem with RULEs defined on the table, as all the rules are evaluated - I've used nextval() in all the rules so it was incremented for each rule and it was not clear which value was actually used. So it was not sure which value to use in a following insert (as a FK value). regards Tomas