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

From: Eric Marsden <eric(dot)marsden(at)risk-engineering(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Cache lookup failed for type 34813 (CREATE TYPE AS ENUM + P/B/E insert, processor-specific)
Date: 2024-06-21 14:02:48
Message-ID: 2dcacb45-81c9-4c38-aa36-70e2dc8df487@risk-engineering.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)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).

Responses

Browse pgsql-bugs by date

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