pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: jesusthefrog <jesusthefrog@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: gen_random_uuid key collision
Date: Thu, 02 Sep 2021 19:47:55 -0400
Message-ID: <2442920.1630626475@sss.pgh.pa.us> (raw)
In-Reply-To: <CAH_wARuGPc6xDLGLo4U1=gvuKvnKO3NVjwzkFef5sPETQ9-Hcg@mail.gmail.com>
References: <CAH_wARuGPc6xDLGLo4U1=gvuKvnKO3NVjwzkFef5sPETQ9-Hcg@mail.gmail.com>

jesusthefrog <jesusthefrog@gmail.com> writes:
> I work with a postgres instance which has dozens (probably hundreds) of
> tables which each have a column defined as "uuid primary key default
> gen_random_uuid()".

> Most of the time this is fine, but one specific table has recently started
> repeatedly having inserts fail because of a unique constraint violation
> involving the primary key. The table only has ~10,000 rows, but I'll
> sometimes see two or three collisions in a single day. No other table (even
> those with many, many more rows) exhibit this issue.

That is pretty weird, all right.  The only idea that comes to mind
immediately is that maybe that table's pkey index is corrupt and needs
to be reindexed.  This isn't a great theory, because I don't see why
a corrupt index would lead to bogus unique-constraint errors rather
than missed ones.  But at least it squares with the observation that
only that table is having issues.

BTW, are you *entirely* certain that your application never inserts
non-default values into that column?

			regards, tom lane





view thread (11+ messages)  latest in thread

Message-ID: <2442920.1630626475@sss.pgh.pa.us>
Permalink:  ../2442920.1630626475@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2442920.1630626475@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, jesusthefrog@gmail.com
  Subject: Re: gen_random_uuid key collision
  In-Reply-To: <2442920.1630626475@sss.pgh.pa.us>
  References: <CAH_wARuGPc6xDLGLo4U1=gvuKvnKO3NVjwzkFef5sPETQ9-Hcg@mail.gmail.com> <2442920.1630626475@sss.pgh.pa.us>

* 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