Re: gen_random_uuid key collision

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: jesusthefrog <jesusthefrog(at)gmail(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: gen_random_uuid key collision
Date: 2021-09-02 23:47:55
Message-ID: 2442920.1630626475@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

jesusthefrog <jesusthefrog(at)gmail(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2021-09-03 00:05:26 Re: gen_random_uuid key collision
Previous Message jesusthefrog 2021-09-02 23:38:07 Re: gen_random_uuid key collision