RE: [EXT] Re: Sequence Cycle question

From: "Wong, Kam Fook (TR Technology)" <kamfook(dot)wong(at)thomsonreuters(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, "Campbell, Lance" <lance(at)illinois(dot)edu>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>
Subject: RE: [EXT] Re: Sequence Cycle question
Date: 2025-01-23 19:16:05
Message-ID: CH0SPR01MB0013AE6A6DE47B8E94701649FEE02@CH0SPR01MB0013.namprd03.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Lance,

Why can’t you change the max_value to 2,000,000 or higher? I can’t think of a reason if this will cause any other problems, including performance. Other please correct otherwise.

Thank you
Kam

From: David G. Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
Sent: Thursday, January 23, 2025 12:59 PM
To: Campbell, Lance <lance(at)illinois(dot)edu>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>; pgsql-admin(at)postgresql(dot)org
Subject: [EXT] Re: Sequence Cycle question

External Email: Use caution with links and attachments.

On Thu, Jan 23, 2025 at 11:47 AM Campbell, Lance <lance(at)illinois(dot)edu<mailto:lance(at)illinois(dot)edu>> wrote:
Lets say I was to set the cycle=true. Once the IDs start back at 1, lets say we get to an ID of 5 where there is a duplicate.

Is there a trigger or something else, that I could associate with the table that would "catch/detect" the insert error. If an error occurs it would then do a "fresh" insert with no specified ID so the sequence would naturally be incremented?

You are really fighting against the design of the system here. I suggest you avoid doing inserts to this table concurrently and put logic in the insertion code to simply find what would be the next identifier and use it. Sequences are meant to be used for performance and simplicity - your requirements are incompatible with both.

The better option if you can manage it is to increase your identifier space to bigint and forget about wrap-around. Re-using identifiers is simply not a good practice.

David J.

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Campbell, Lance 2025-01-23 19:24:16 RE: [EXT] Re: Sequence Cycle question
Previous Message Mauricio Fernandez 2025-01-23 19:01:14 Re: High Availability