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 1sGqDv-000BS2-Q2 for pgsql-general@arkaria.postgresql.org; Tue, 11 Jun 2024 01:22: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 1sGqDt-000hbM-LB for pgsql-general@arkaria.postgresql.org; Tue, 11 Jun 2024 01:22:54 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sGqDt-000hbA-9t for pgsql-general@lists.postgresql.org; Tue, 11 Jun 2024 01:22:54 +0000 Received: from smtp67.ord1d.emailsrvr.com ([184.106.54.67]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sGqDr-0011Wi-AY for pgsql-general@lists.postgresql.org; Tue, 11 Jun 2024 01:22:53 +0000 X-Auth-ID: xof@thebuild.com Received: by smtp17.relay.ord1d.emailsrvr.com (Authenticated sender: xof-AT-thebuild.com) with ESMTPSA id 32583202BB; Mon, 10 Jun 2024 21:22:41 -0400 (EDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.600.62\)) Subject: Re: Gaps in PK sequence numbers [RESOLVED] From: Christophe Pettus In-Reply-To: Date: Mon, 10 Jun 2024 18:21:59 -0700 Cc: pgsql-general@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <88E9C97A-E616-4162-9CAB-64C98C5620B6@thebuild.com> References: <35fd10ab-5f7f-7a57-9cc5-c03d81476d13@appl-ecosys.com> To: Rich Shepard X-Mailer: Apple Mail (2.3774.600.62) X-Classification-ID: d759c903-0ad2-4185-bca6-faa01c1a1d87-1-1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Jun 10, 2024, at 18:10, Rich Shepard = wrote: > 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. The sequence functions are documented here: https://www.postgresql.org/docs/current/functions-sequence.html setval is the function you want. You can use a SELECT so you don't have = to copy values around: select setval('t_pk_seq', (select max(pk) from t)); That form of setval() sets the sequence so that the next value will be = one more than the value you set it to, so you don't have to do max()+1 = there.=