Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id DAB11632A69 for ; Wed, 7 Jul 2010 17:38:57 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 44777-02 for ; Wed, 7 Jul 2010 20:38:49 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.jfcomputer.com (unknown [76.14.161.106]) by mail.postgresql.org (Postfix) with ESMTP id 3B31B63258B for ; Wed, 7 Jul 2010 17:38:50 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by mail.jfcomputer.com (Postfix) with ESMTP id 0A73B79676 for ; Wed, 7 Jul 2010 13:38:49 -0700 (PDT) X-Virus-Scanned: amavisd-new at jfcomputer.com Received: from mail.jfcomputer.com ([127.0.0.1]) by localhost (server1.jfcomputer.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uU+1ZsrhezlR for ; Wed, 7 Jul 2010 13:38:46 -0700 (PDT) Received: from [192.168.1.219] (unknown [192.168.1.219]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: johnf@mail.jfcomputer.com) by mail.jfcomputer.com (Postfix) with ESMTPSA id BF84779638 for ; Wed, 7 Jul 2010 13:38:46 -0700 (PDT) From: John To: pgsql-sql@postgresql.org Subject: Re: strangest thing happened Date: Wed, 7 Jul 2010 13:38:46 -0700 User-Agent: KMail/1.9.9 References: <201007071259.03294.johnf@jfcomputer.com> <4C34F0B9.5020902@magwerks.com> In-Reply-To: <4C34F0B9.5020902@magwerks.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <201007071338.46469.johnf@jfcomputer.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.792 tagged_above=-5 required=5 tests=BAYES_40=-0.001, RDNS_NONE=0.793 X-Spam-Level: X-Archive-Number: 201007/31 X-Sequence-Number: 34344 Yes I'm using auto_increment (serial data type). No function, method inserts PK's anywhere in my code. I'm thinking/guessing it had something to do with vacumn or the backup. I have been using Postgres for a number of years now and I never seen this in the past. So I'm really at a loss as how this could have occurred. The backup is a windows product "exec" and I'm using a special plug-in from exec for the Linux backup. But I still can't see this actually happening. Well I have it running for the moment and I'll have to account black magic as the cause. Johnf On Wednesday 07 July 2010 02:25:13 pm Justin Graf wrote: > Are you using PG's sequence/auto increment??? > > If so. > Once PG fires off the nextval() for the sequence that number is > considered used and gone even if the transaction that called nextval() > is rolled back > > Depending on how the app is written nextval() might be called, but allow > the User to cancel the invoice creation before the insert into table is > completed eating up Invoice numbers > > To reset Sequences number call > Select setval('Sequence_Name', VAlue_To_Set_To); > > Most people ignore this kind of annoyance when sequence numbers jump. > Now if it happens all the time where every X hours eating up Z number of > sequence numbers then one needs to dig into the logs and figure out what > is calling nextval() > > Search the logs to see what is calling nextval('My_Sequence') > > You may need to turn up logging to find it. > > On 7/7/2010 2:59 PM, John wrote: > > I am the only developer, DBA etc.. for a small project. Today (yesterday > > was everything was perfect) many of the sequence numbers fell behind what > > is the actual PK value. For example the invoice PK sequence current > > value = 1056 but the table PK was 1071. Nobody (other than myself) knows > > how to edit/access the postgres server. So > > > > 1. Does anyone know how this could have happened?????? Other than human > > interaction. > > > > 2. Does anyone have a script to reset the sequences to match the tables? > > > > Thanks in advance, > > > > Johnf