Cache lookup failed for type 34813 (CREATE TYPE AS ENUM + P/B/E insert, processor-specific) - Mailing list pgsql-bugs

From Eric Marsden
Subject Cache lookup failed for type 34813 (CREATE TYPE AS ENUM + P/B/E insert, processor-specific)
Date
Msg-id 2dcacb45-81c9-4c38-aa36-70e2dc8df487@risk-engineering.org
Whole thread Raw
Responses Re: Cache lookup failed for type 34813 (CREATE TYPE AS ENUM + P/B/E insert, processor-specific)
List pgsql-bugs
Hello,

I have a strange bug which is either processor-specific (occurs on AMD 
Ryzen 3 PRO 4350G processor, but not on Intel) or Linux kernel version 
specific. It occurs with PostgreSQL v16.3 as packaged by Debian: 16.3 
(Debian 16.3-1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 
13.2.0-24) 13.2.0, 64-bit, running on Linux 6.8.12-amd64 / Debian GLIBC 
2.38-13.

I see a PostgreSQL error "cache lookup failed for type 34813" after the 
following sequence of network requests over a single network connection 
to PostgreSQL (which is otherwise idle):

CREATE TYPE rating AS ENUM('ungood', 'good')
CREATE TABLE act(name TEXT, value RATING)
INSERT INTO act VALUES('thoughtcrime', 'ungood') -- OK
INSERT INTO act VALUES('blackwhite', $1) -- with $1 = "good" / type oid for "rating" / text format

The last line, which triggers the error, is using the 
prepare-bind-execute protocol, with a single parameter sent in text 
mode, with the oid corresponding to the "CREATE TYPE" (queried from the 
pg_type table). This is with an obscure Emacs Lisp implementation of the 
frontend/backend protocol. I have produced a standalone Emacs Lisp file 
which reproduces the problem, available as a gist here

    https://gist.github.com/emarsden/9bbaf02d62961cabaf5404f10da2c01c

To reproduce (requires Emacs to be installed), save as "cache-bug.el" 
and run

PGURI="postgresql://pgeltestuser:password@localhost/pgeltestdb" emacs 
--batch -Q -l cache-bug.el -f run

This produces a long backtrace of which the last line is (with FR locale)

    PostgreSQL error: "ERREUR : cache lookup failed for type 34841"

I have not made the effort to reproduce this with the psycopg Python 
library (the use of custom types is a little inconvenient).

This bug does not occur on the exact same version of PostgreSQL on 
Debian (same sha256sum on the postmaster binary) running on an Intel 
processor with an older kernel version. Nor does it occur on the problem 
machine when running the current Docker image for PostgreSQL (neither 
docker.io/library/postgres:16.3-bullseye nor the 16.3-alpine label).




pgsql-bugs by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: BUG #18377: Assert false in "partdesc->nparts >= pinfo->nparts", fileName="execPartition.c", lineNumber=1943
Next
From: Bruce Momjian
Date:
Subject: Re: BUG #18518: ::timestamp add minutes and seconds to the converted values