pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Philip Semanchuk <philip@americanefficient.com>
To: Abraham, Danny <danny_abraham@bmc.com>
Cc: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: PKEY getting corrupted
Date: Thu, 10 Sep 2020 09:05:04 -0400
Message-ID: <F0CCA124-89F4-4829-A1FD-79B4E737AAC8@americanefficient.com> (raw)
In-Reply-To: <e8fd5506c45f4508bc8fdbb5f630696f@phx-exmbprd-01.adprod.bmc.com>
References: <e8fd5506c45f4508bc8fdbb5f630696f@phx-exmbprd-01.adprod.bmc.com>



> On Sep 10, 2020, at 6:43 AM, Abraham, Danny <danny_abraham@bmc.com> wrote:
> 
> Hi,
> 
> We have seen several times a situation where a PKEY is compromised and duplicate values are created within a table.
> 
> This has happened so far on PG 928 on Linux and Windows, and also on PG955 on AIX.
> 
> We ran massive test on PG10.4 but it has not recreated the problem.
> 
> Has anyone faced the same issue? Any known bug?

In my experience, this is usually due to an application writing PK values rather than allowing a Postgres sequence to generate them, or due to the application misusing sequences. Postgres sequences are monotonically increasing, so even if you insert sequence values “out of order”, they won’t overlap. That’s not to say a bug in Postgres is impossible, but every time I’ve seen this problem, it’s been my application, not Postgres.

Postgres 10 added new syntax for PK columns "GENERATED ALWAYS AS IDENTITY” (https://www.postgresql.org/docs/10/sql-createtable.html). Postgres will raise an exception if an application tries to insert a specific value into a column defined this way. When we upgraded from 9.6 to 11 we converted all of our PK columns to use this syntax which added a nice safety net for us. 

You’re probably already aware that 9.5.23 is the oldest supported version in the 9.x series, so the sooner you can upgrade those unsupported 9.x versions the better. Maybe you’re in the middle of an upgrade already which is why this came up. :-) 

Cheers
Philip




view thread (4+ messages)  latest in thread

Message-ID: <F0CCA124-89F4-4829-A1FD-79B4E737AAC8@americanefficient.com>
Permalink:  ../F0CCA124-89F4-4829-A1FD-79B4E737AAC8@americanefficient.com/
Also on:    postgresql.org/message-id/F0CCA124-89F4-4829-A1FD-79B4E737AAC8@americanefficient.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: philip@americanefficient.com, danny_abraham@bmc.com
  Subject: Re: PKEY getting corrupted
  In-Reply-To: <F0CCA124-89F4-4829-A1FD-79B4E737AAC8@americanefficient.com>
  References: <e8fd5506c45f4508bc8fdbb5f630696f@phx-exmbprd-01.adprod.bmc.com> <F0CCA124-89F4-4829-A1FD-79B4E737AAC8@americanefficient.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox