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 1wmAWK-000d3j-13 for pgsql-hackers@arkaria.postgresql.org; Tue, 21 Jul 2026 13:28:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wmAWJ-007ee5-2t for pgsql-hackers@arkaria.postgresql.org; Tue, 21 Jul 2026 13:28:27 +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 1wmAWJ-007edx-1j for pgsql-hackers@lists.postgresql.org; Tue, 21 Jul 2026 13:28:27 +0000 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wmAWG-00000000RaN-2yNw for pgsql-hackers@postgresql.org; Tue, 21 Jul 2026 13:28:26 +0000 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-47f7854678cso1021831f8f.1 for ; Tue, 21 Jul 2026 06:28:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1784640503; x=1785245303; darn=postgresql.org; h=message-id:date:content-type:mime-version:comments:references :in-reply-to:subject:cc:to:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=xMNlnRMnayDVygLrQBUNDDmo6jYKPd++uE9cPJh28ug=; b=Mwto/iqQ8PH33tEY6uZqjE9xeozOrW+ojPJhX1XclJZgvWfcY3Jyi9JYeKtyRtlQEJ h77znWEWdAXXCp0yOGTEtfavhmUcflPkmnB0TzYhlsW95JQ4m6pALDL8JcChYlt0OblZ +8cM/7dG8wVn07y6/NhXlFucNStgzG4umQck9vCftW9RtWVh1cdQP/TEN4Ml6hX61liO wGHQPgNCGCXAq0nc1rdK+pZiZCL10xOulQN5XxmAHSkRXhMMTWDpnyc1EJ2QgyR5T/wP tsYu0ADLn4hfvTPJ84uxYEeAT1hV5/Yi7IhhiiSM+S7/Dcr/0YHnDY38JarshKWVYfVY EhlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784640503; x=1785245303; h=message-id:date:content-type:mime-version:comments:references :in-reply-to:subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=xMNlnRMnayDVygLrQBUNDDmo6jYKPd++uE9cPJh28ug=; b=XpFBARAZe6AF2ivlhHPiu0EfcLbc5dEHioNAdl2RL5f/ikYhsSsfHfYHkmlTCuq70y Cfwc/RrFQ/VP4tcJA0dmI78MzW/Hcn+PCW20UO7IAVMnTIhojhH/yuRi4OuBtntxdivx upMhlcej0TxQJZiKvwUG3LQMsvAJy1YJPumZJx8Jh0UxDhW80d/NlHttn8VHeyYB9K64 Wj8I9VpaooTRfbzCWw6bkusZloMEyqAVXgiwHQwpzclmXGkAYagZxvhcp7uN8ztlXTz4 YR4etcMS3fH3vJdSXNI8OpCwbXqCzGQDVih+yKEboGZD0jKq7DTbc5JrS1p6tCq6MOtq UTLA== X-Forwarded-Encrypted: i=1; AHgh+RrI4BRjV8sa62SQ7Q/O4CRBqPQOU21dhdkx2WemIdecrKCNi3LgthT0M+tG5vELoDCLlMdkedorOBsYLmP+@postgresql.org X-Gm-Message-State: AOJu0YzammsmiCoPYJWAEWI1T8/C0aHGa0/3euGJAnGPsIwXm/JO+y// ICFIZM8efu0g6ZxLeEZ8C07Y4qWhpiRY85wrfFHHzrJ5hnESLyVwdBY+IpumE+D359U= X-Gm-Gg: AR+sD11IxKBbxH14815IxiQoBpnuW+pQ9c/TX9zOVnGuj/l6c2AduHkekLOAPCgi7RV WBmV1MLHVxIqw/QupEMOCk1mbhfXQjtP8R+HAJAGxolbKLENutcd5qXc9fUMPHdUryJ5PNuoPNQ NpG20WwQeMiZVyNZjTZxS7I95i/gVwXi8D+PlUKLMp3gZbK4Mggc4GI8Cwl7RLRN38+dsi0dTUI Z994yGhfQYtGzrYSqk9ACISPkBVr7UaxcsTLj8ocAhby1IEq/aJMIRvv8JcFm4kMWW7KhK2QuMH zYCn08CrMr7JOp+EO1imoEA78nv7jswK9jpf5C9pxlTGE26Q7l/eK9Xl7w8a7+2Nfu+9RpJ0Zj1 7a9gFM8QnNbxtA1hurfdui4C4zjEJo2juAfSfsFnRxxwCwFmLwhpn/neJKJio/SWGigUeuvUwwo aYPiBK4tstUI4OnR8= X-Received: by 2002:a05:6000:4383:b0:47f:80f7:e4a1 with SMTP id ffacd0b85a97d-47f80f7e4c1mr3234031f8f.28.1784640502976; Tue, 21 Jul 2026 06:28:22 -0700 (PDT) Received: from localhost (109-81-170-190.rct.o2.cz. [109.81.170.190]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47f63ed1911sm41855335f8f.22.2026.07.21.06.28.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jul 2026 06:28:22 -0700 (PDT) From: Antonin Houska To: Matthias van de Meent cc: Michael Paquier , Alexander Lakhin , pgsql-hackers Subject: Re: Unexpected behavior after OOM errors In-reply-to: References: <95c64dc2-3abe-4f4e-b285-4c681f565d9f@gmail.com> <91199.1784569717@localhost> Comments: In-reply-to Matthias van de Meent message dated "Mon, 20 Jul 2026 21:02:23 +0200." X-Mailer: MH-E 8.6+git; nmh 1.8; GNU Emacs 28.3 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Date: Tue, 21 Jul 2026 15:28:22 +0200 Message-ID: <62382.1784640502@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --=-=-= Content-Type: text/plain Matthias van de Meent wrote: > On Mon, 20 Jul 2026 at 19:48, Antonin Houska wrote: > > > > Michael Paquier wrote: > > > > > On Fri, Jul 17, 2026 at 12:00:01PM +0300, Alexander Lakhin wrote: > > > > 4) make_new_heap(): > > > > --- a/src/backend/commands/repack.c > > > > +++ b/src/backend/commands/repack.c > > > > @@ -1255,3 +1255,5 @@ make_new_heap(Oid OIDOldHeap, Oid NewTableSpace, Oid NewAccessMethod, > > > > */ > > > > +oom_prob = 0.01; > > > > CommandCounterIncrement(); > > > > +oom_prob = 0; > > > > > > > > triggers: > > > > TRAP: failed Assert("ItemIdIsNormal(lp)"), File: "heapam.c", Line: 2813, PID: 943626 > > > > also: > > > > ERROR: attempted to delete invisible tuple > > > > > > I'll let Alvaro comment on this one. It deserves an open item. > > > > I was also curious because I worked on repack.c recently. After applying (a > > bit rebased) random-oom-errors.patch from [1] and after turning some "out of > > memory" errors to PANIC, I could reproduce the error even on PG 18. The stack > > trace is below. So it does not seem to be PG 19 specific. > > A PANIC with AllocSetAlloc on the stacktrace isn't an indication of a > bug when you add both an OOM probability on palloc, and set the > OOM-error-thrower to PANIC instead of ERROR. > > This thread contains various examples of backend-local state remaining > in various levels of incomplete modifications/corruptions even after > the ERROR handling of an OOM has been completed. PANICs cause the > backend to be terminated, and so are much less likely to cause > problems down the line. > > Note, too, that the problem that Alexander reported is a failing > Assert(), and an ERROR reporting "attempted to delete invisible > tuple", rather than actual "out of memory" ERRORs. I supposed that these problems happen because relcache remains in wrong state due to the "out of memory" ERROR. So the point of using PANIC was to find out when exactly the cache gets broken. However, I missed the fact that Alexander's patch triggers the ERROR at several different places, so the stack trace I posted might be unrelated. Nevertheless, on a closer look I concluded that the problem is not related to OOM. Rather, *any* ERROR that happens during cache invalidation can cause this. Attached here is cache_inval_failure.diff that reproduces the problem reliably: postgres=# CREATE TABLE t1(i int PRIMARY KEY); CLUSTER t1 USING t1_pkey; DROP TABLE t1; CREATE TABLE ERROR: failure during cache invalidation ERROR: attempted to delete invisible tuple (The Assert(ItemIdIsNormal(lp)) IMO fires only if VACUUM manages to reset the item pointer before heap_delete() gets called. With autovacuum=off, I get only the "failure during cache invalidation" error.) So I think we need to make sure that ERROR during cache invalidation becomes FATAL. -- Antonin Houska Web: https://www.cybertec-postgresql.com --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=cache_inval_failure.diff diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 94a5aee90b5..7d9812804ce 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -784,7 +784,9 @@ make_new_heap(Oid OIDOldHeap, Oid NewTableSpace, Oid NewAccessMethod, * Advance command counter so that the newly-created relation's catalog * tuples will be visible to table_open. */ + invalidation_failure = true; CommandCounterIncrement(); + invalidation_failure = false; /* * If necessary, create a TOAST table for the new relation. diff --git a/src/backend/utils/cache/inval.c b/src/backend/utils/cache/inval.c index 30048e153e5..ca8a16c50f6 100644 --- a/src/backend/utils/cache/inval.c +++ b/src/backend/utils/cache/inval.c @@ -180,6 +180,8 @@ typedef struct InvalMessageArray static InvalMessageArray InvalMessageArrays[2]; +bool invalidation_failure = false; + /* Control information for one logical group of messages */ typedef struct InvalidationMsgsGroup { @@ -1419,6 +1421,9 @@ CommandEndInvalidationMessages(void) ProcessInvalidationMessages(&transInvalInfo->ii.CurrentCmdInvalidMsgs, LocalExecuteInvalidationMessage); + if (invalidation_failure) + elog(ERROR, "failure during cache invalidation"); + /* WAL Log per-command invalidation messages for wal_level=logical */ if (XLogLogicalInfoActive()) LogLogicalInvalidations(); diff --git a/src/include/utils/inval.h b/src/include/utils/inval.h index b5fbd754c2c..1512e47d38d 100644 --- a/src/include/utils/inval.h +++ b/src/include/utils/inval.h @@ -20,6 +20,8 @@ extern PGDLLIMPORT int debug_discard_caches; +extern bool invalidation_failure; + typedef void (*SyscacheCallbackFunction) (Datum arg, int cacheid, uint32 hashvalue); typedef void (*RelcacheCallbackFunction) (Datum arg, Oid relid); typedef void (*RelSyncCallbackFunction) (Datum arg, Oid relid); --=-=-=--