public inbox for [email protected]  
help / color / mirror / Atom feed
From: Tom Lane <[email protected]>
To: Ed Sabol <[email protected]>
Cc: Pgsql-admin <[email protected]>
Subject: Re: Duplicate key value violates unique constraint "pg_type_typname_nsp_index" error
Date: Wed, 18 Feb 2026 23:51:57 -0500
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>

Ed Sabol <[email protected]> writes:
> Using PostgreSQL 15.16, I have some SQL for creating a materialized view that's inside a larger transaction which randomly emits the following error:
> ERROR:  duplicate key value violates unique constraint "pg_type_typname_nsp_index"
> DETAIL:  Key (typname, typnamespace)=(largetable, 20488) already exists.

Huh.  Does it always mention 20488?

> I've tried the following queries to try to figure out what typnamespace = 20488 refers to:

> SELECT nspname FROM pg_namespace WHERE oid = 20488;
> SELECT count(*) FROM pg_catalog.pg_type WHERE typname = 'targetable' AND typnamespace = 20488;

> Neither query provides any useful information.

What do you mean by "any useful information", exactly?  Do these show
that there is no pg_namespace row with oid = 20488?

If that is the case, I'd bet on index corruption in the indexes of
pg_type and/or pg_namespace.  REINDEX might help.

			regards, tom lane





view thread (10+ messages)  latest in thread

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 using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Duplicate key value violates unique constraint "pg_type_typname_nsp_index" error
  In-Reply-To: <[email protected]>

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

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