Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 2E8AD632C20 for ; Wed, 7 Jul 2010 17:26:37 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 57747-04 for ; Wed, 7 Jul 2010 20:26:29 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.magwerks.com (mail.magwerks.com [209.248.233.131]) by mail.postgresql.org (Postfix) with ESMTP id AD9AC63258B for ; Wed, 7 Jul 2010 17:26:28 -0300 (ADT) Received: from [192.168.1.35] by mail.magwerks.com (GMS 15.01.3664/RS2750.00.1b502c7c) with ESMTP id zdyyeaaa for pgsql-sql@postgresql.org; Wed, 7 Jul 2010 16:26:27 -0400 Message-ID: <4C34F0B9.5020902@magwerks.com> Date: Wed, 07 Jul 2010 16:25:13 -0500 From: Justin Graf User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.10) Gecko/20100512 Thunderbird/3.0.5 MIME-Version: 1.0 To: John , postgres sql Subject: Re: strangest thing happened References: <201007071259.03294.johnf@jfcomputer.com> In-Reply-To: <201007071259.03294.johnf@jfcomputer.com> Content-Type: multipart/mixed; boundary="------------070108010506000805000002" X-AntiSpam: Checked for restricted content by Gordano's AntiSpam Software X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.79 tagged_above=-5 required=5 tests=BAYES_50=0.8, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201007/30 X-Sequence-Number: 34343 This is a multi-part message in MIME format. --------------070108010506000805000002 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 > > All legitimate Magwerks Corporation quotations are sent in a .PDF file attachment with a unique ID number generated by our proprietary quotation system. Quotations received via any other form of communication will not be honored. CONFIDENTIALITY NOTICE: This e-mail, including attachments, may contain legally privileged, confidential or other information proprietary to Magwerks Corporation and is intended solely for the use of the individual to whom it addresses. If the reader of this e-mail is not the intended recipient or authorized agent, the reader is hereby notified that any unauthorized viewing, dissemination, distribution or copying of this e-mail is strictly prohibited. If you have received this e-mail in error, please notify the sender by replying to this message and destroy all occurrences of this e-mail immediately. Thank you. --------------070108010506000805000002 Content-Type: text/x-vcard; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="justin.vcf" begin:vcard fn:Justin Graf n:Graf;Justin org:Magwerks Corp adr:;;501 Commerce Drive;Danville ;IN;46122;USA email;internet:justin@magwerks.com tel;work:317-241-8011 ext 703 tel;fax:317-241-8015 x-mozilla-html:FALSE url:www.magwerks.com version:2.1 end:vcard --------------070108010506000805000002--