Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sGq2J-0009bQ-Bt for pgsql-general@arkaria.postgresql.org; Tue, 11 Jun 2024 01:10:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sGq2H-000aBT-An for pgsql-general@arkaria.postgresql.org; Tue, 11 Jun 2024 01:10:54 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sGq2G-000aBK-Qc for pgsql-general@lists.postgresql.org; Tue, 11 Jun 2024 01:10:53 +0000 Received: from mail.appl-ecosys.com ([50.126.108.78]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sGq2F-000iQX-AZ for pgsql-general@lists.postgresql.org; Tue, 11 Jun 2024 01:10:52 +0000 Received: from salmo.appl-ecosys.com (salmo.appl-ecosys.com [192.168.55.1]) by mail.appl-ecosys.com (Postfix) with ESMTP id D13502A2B7C for ; Mon, 10 Jun 2024 18:10:49 -0700 (PDT) Date: Mon, 10 Jun 2024 18:10:49 -0700 (PDT) From: Rich Shepard To: pgsql-general@lists.postgresql.org Subject: Re: Gaps in PK sequence numbers [RESOLVED] In-Reply-To: Message-ID: References: <35fd10ab-5f7f-7a57-9cc5-c03d81476d13@appl-ecosys.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 10 Jun 2024, Christophe Pettus wrote: > Strictly speaking, the sequence underlying nextval() has no idea what > primary keys are or are not in use. It's just a transaction-ignoring > counter that increases with each nextval() call. The only reason that > you'd get duplicate key errors in this case are: > > 1. The sequence was reset to a different, lower value. > 2. Rows were inserted that didn't use the sequence to select a primary key. Thanks, Christophe. Is there a way to reset the sequence to the maximum number +1? I don't recall seeing this in the postgres docs but will look again. Regards, Rich