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 1vt3gU-000HNz-1R for pgsql-admin@arkaria.postgresql.org; Thu, 19 Feb 2026 13:03: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 1vt3gR-003bSl-0R for pgsql-admin@arkaria.postgresql.org; Thu, 19 Feb 2026 13:03:07 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vt3gQ-003bSc-2X for pgsql-admin@lists.postgresql.org; Thu, 19 Feb 2026 13:03:06 +0000 Received: from mail-qk1-x731.google.com ([2607:f8b0:4864:20::731]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vt3gN-000000008R0-3v5r for pgsql-admin@lists.postgresql.org; Thu, 19 Feb 2026 13:03:05 +0000 Received: by mail-qk1-x731.google.com with SMTP id af79cd13be357-8cb38e6d164so99553285a.3 for ; Thu, 19 Feb 2026 05:03:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771506184; x=1772110984; darn=lists.postgresql.org; h=to:references:message-id:cc:date:in-reply-to:from:subject :mime-version:content-transfer-encoding:from:to:cc:subject:date :message-id:reply-to; bh=T3C2K5Y/9JQIMji5y6tbocSKvBLyJIDHbffzyQMYUQg=; b=jqQ6jlgncV9lcVldf8azIyZU8YmLWpEBYWAoWacgZ68j/pzApOVOR9JQs3KM8r95c1 cDwbmk/XeJ/t1PTFQFdvxlzOME6fdVZ/jz6E/lntW27RX3nHke1h8E74ps9lT/hyR4VW l9V+fWbMuEzkEhP0zjpx8a6JZlGg8aKCr70Et/IkKdiYhf6vQ+gVN0OGPQ4B2yulM7fV DmZrSB+GI70EsOXl+CCu6cAKQ/qANcm3uCqOZ8w0mLDCZRsv30Yuk+28ken/NY/3N83F MpliZLmqrsacjdKsQ3Y6qaLCMy/lQNS3mkDmVi1wloS0vKR+gwA2g3KetmE3tdrpiOrt gnhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771506184; x=1772110984; h=to:references:message-id:cc:date:in-reply-to:from:subject :mime-version:content-transfer-encoding:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=T3C2K5Y/9JQIMji5y6tbocSKvBLyJIDHbffzyQMYUQg=; b=QtnbMbhC93XUGWeQUT/Cx471nLos7FKbUwRSIHFb3SlWWZ9HN3NYkCm3qOBkLVlUuL +CsdbsKuuwoWBdw9oP7GqS2N4g4V9ieDCmseclh+W3yO4f9+sRcdOMkk3QGVLEo9nox8 5yX6bfxMAekELVDN+39WV7eCXtAlBnfeYoOLbkAvrlTYyHkBmMT3ht2v1Vh/0qZKeG7g smlIPoEHbwRgLFspXJMJRJaN3S5V6L+EEZ6fDXMo4ZBFjk9ezTfaDzkge1AgAnsgtLVn 4qhR2csYJteBtwane84zJKvru07AAHmhbADy2qwJ+cNzaMhV2kjfJZjGWXiPBCemmqOV AxMA== X-Gm-Message-State: AOJu0YwShQRvPbO2p2A2r1Jw6CcTp5HF2Ig71KFTwMTOX2WoyFocbIbs kKR33mpo/qnfvxKLuHJ1FaneXKpWGmRRklic1m+Hz7bOni+WRuu5bWqW X-Gm-Gg: AZuq6aJfJfioAiXGc04fBsitxq/uNowkuN9EzwG1hVTx8Ltu4kC5jsVRD/27hiYc1wh t+ux5Q0KiPvn/HE2tYbRLgrtPD9Qi9cdJ6TJYJZUT6NSRetEbt1XrsWEl70RyRWCy3erOBTBytk u96F39mqC63MGJBpyiZVHZOghpLQe/3u6k1WhN2j/iMgEVS79ojVDniciZiZni/CYoJiUltnL3c JdXLA/YJHSKby9ZckrTUJW3S4C4eHLt6Dy0L+ZNSc7eU57Z+Y84RPest+/wi8nwJf6xGIMpph0T jaE7TONMydoDCXPmlfBPXWhzJHpxFRCt1Ptcs94QQdnk0IQCoy2QKcLcvSJ+hBBRJBB6bKDsF3+ VVIDF7tS9AYxdvwsTT0L2F0ZhIoSp0eoghZacATlxBX+SIzbcFTiRkc8r/5toraLsMRQRsk0c3N piuWxXVZ4EwxtTbcvSiwH+/HytSFMuhLk54UAHPriZwgTDdQsE1Z2MKD2WxA== X-Received: by 2002:a05:620a:698b:b0:8cb:4059:a90e with SMTP id af79cd13be357-8cb4c041a43mr2155774185a.80.1771506184141; Thu, 19 Feb 2026 05:03:04 -0800 (PST) Received: from smtpclient.apple ([2601:14b:4100:214f:7835:748d:8996:6192]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8cb2b1c7e71sm2251582485a.30.2026.02.19.05.03.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Feb 2026 05:03:03 -0800 (PST) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (1.0) Subject: Re: Duplicate key value violates unique constraint "pg_type_typname_nsp_index" error From: "Edward J. Sabol" In-Reply-To: <2325374.1771476717@sss.pgh.pa.us> Date: Thu, 19 Feb 2026 08:02:33 -0500 Cc: Pgsql-admin Message-Id: References: <2325374.1771476717@sss.pgh.pa.us> To: Tom Lane X-Mailer: iPad Mail (23D127) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Feb 18, 2026, at 11:51=E2=80=AFPM, Tom Lane wrote: > =EF=BB=BFEd Sabol writes: >> Using PostgreSQL 15.16, I have some SQL for creating a materialized view t= hat's inside a larger transaction which randomly emits the following error: >> ERROR: duplicate key value violates unique constraint "pg_type_typname_n= sp_index" >> DETAIL: Key (typname, typnamespace)=3D(largetable, 20488) already exists= . >=20 > Huh. Does it always mention 20488? Yes, it's always 20488. >> I've tried the following queries to try to figure out what typnamespace =3D= 20488 refers to: >=20 >> SELECT nspname FROM pg_namespace WHERE oid =3D 20488; >> SELECT count(*) FROM pg_catalog.pg_type WHERE typname =3D 'targetable' AN= D typnamespace =3D 20488; >=20 >> Neither query provides any useful information. >=20 > What do you mean by "any useful information", exactly? Do these show > that there is no pg_namespace row with oid =3D 20488? Well, the first query returns a schema that is completely unrelated to anyth= ing the SQL is doing. I wondered if the typnamespace =3D 20488 DETAIL was re= ferring to something else. > If that is the case, I'd bet on index corruption in the indexes of > pg_type and/or pg_namespace. REINDEX might help. I'll try that. But why would it only happen sometimes? All of the mentions of this error message I could find on the Internet sugge= st this happens when you have multiple processes trying to execute the same D= DL simultaneously, but I'm sure there's only one process executing this tran= saction. Thanks, Ed