Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vsw1K-009VD9-1Z for pgsql-admin@arkaria.postgresql.org; Thu, 19 Feb 2026 04:52:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vsw1I-0022Aq-32 for pgsql-admin@arkaria.postgresql.org; Thu, 19 Feb 2026 04:52:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vsw1I-0022Ai-21 for pgsql-admin@lists.postgresql.org; Thu, 19 Feb 2026 04:52:08 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vsw1F-000000005RL-24SR for pgsql-admin@lists.postgresql.org; Thu, 19 Feb 2026 04:52:08 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 61J4pv5A2325375; Wed, 18 Feb 2026 23:51:57 -0500 From: Tom Lane To: Ed Sabol cc: Pgsql-admin Subject: Re: Duplicate key value violates unique constraint "pg_type_typname_nsp_index" error In-reply-to: <1D3D88D6-5E8C-4144-BF79-DB531FE4FE39@gmail.com> References: <1D3D88D6-5E8C-4144-BF79-DB531FE4FE39@gmail.com> Comments: In-reply-to Ed Sabol message dated "Wed, 18 Feb 2026 20:47:27 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2325373.1771476717.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 18 Feb 2026 23:51:57 -0500 Message-ID: <2325374.1771476717@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Ed Sabol 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 err= or: > ERROR: duplicate key value violates unique constraint "pg_type_typname_= nsp_index" > DETAIL: Key (typname, typnamespace)=3D(largetable, 20488) already exist= s. Huh. Does it always mention 20488? > I've tried the following queries to try to figure out what typnamespace = =3D 20488 refers to: > SELECT nspname FROM pg_namespace WHERE oid =3D 20488; > SELECT count(*) FROM pg_catalog.pg_type WHERE typname =3D 'targetable' A= ND typnamespace =3D 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 =3D 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