| From: | Alexander Lakhin <exclusion(at)gmail(dot)com> |
|---|---|
| To: | Michael Paquier <michael(at)paquier(dot)xyz>, Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com> |
| Cc: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: Unexpected behavior after OOM errors |
| Date: | 2026-07-17 09:00:01 |
| Message-ID: | 95c64dc2-3abe-4f4e-b285-4c681f565d9f@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hello Michael and Matthias,
Could you please look at other similar anomalies I have discovered?:
(Assuming the attached OOM injection patch applied.)
1) An issue in generate_partition_qual():
--- a/src/backend/utils/cache/partcache.c
+++ b/src/backend/utils/cache/partcache.c
@@ -419,3 +419,5 @@ generate_partition_qual(Relation rel)
oldcxt = MemoryContextSwitchTo(rel->rd_partcheckcxt);
+oom_prob = 0.1;
rel->rd_partcheck = copyObject(result);
+oom_prob = 0;
MemoryContextSwitchTo(oldcxt);
for i in {1..100}; do
echo "
CREATE TABLE t1(a INT PRIMARY KEY) PARTITION BY RANGE (a);
CREATE TABLE t1p1 PARTITION OF t1 FOR VALUES FROM (1) TO (2) PARTITION BY LIST (a);
CREATE TABLE t2 (a INT, CONSTRAINT fkey FOREIGN KEY(a) REFERENCES t1(a));
INSERT INTO t2 VALUES (1);
INSERT INTO t2 VALUES (1);
DROP TABLE t1, t2 CASCADE;
" | psql
grep 'TRAP' server.log && break;
done
triggers
TRAP: failed Assert("cache->cc_tupdesc != NULL"), File: "catcache.c", Line: 1112, PID: 43932
2) lookup_type_cache():
--- a/src/backend/utils/cache/typcache.c
+++ b/src/backend/utils/cache/typcache.c
@@ -463,8 +463,10 @@ lookup_type_cache(Oid type_id, int flags)
in_progress_list[in_progress_offset] = type_id;
+oom_prob = 0.1;
/* Try to look up an existing entry */
typentry = (TypeCacheEntry *) hash_search(TypeCacheHash,
&type_id,
HASH_FIND, NULL);
+oom_prob = 0;
if (typentry == NULL)
{
for i in {1..10}; do
echo "
CREATE TABLE t(a int);
\c
SELECT * FROM t ORDER BY a;
DROP TABLE t;
" | psql
grep 'TRAP' server.log && break;
done
triggers
TRAP: failed Assert("cache->cc_tupdesc != NULL"), File: "catcache.c", Line: 1112, PID: 43932
3) pgstat_prep_pending_entry() / pgstat_write_statsfiles():
--- a/src/backend/utils/activity/pgstat.c
+++ b/src/backend/utils/activity/pgstat.c
@@ -1333,3 +1333,5 @@ pgstat_prep_pending_entry(PgStat_Kind kind, Oid dboid, uint64 objid, bool *creat
+oom_prob = 0.005;
entry_ref->pending = MemoryContextAllocZero(pgStatPendingContext, entrysize);
+oom_prob = 0;
dlist_push_tail(&pgStatPending, &entry_ref->pending_node);
for i in {1..100}; do
pg_ctl -l server.log start
echo "
CREATE TABLE t (a int);
ALTER TABLE t SET (parallel_workers = 20);
SET parallel_setup_cost = 0;
SELECT SUM(a) FROM t;
DROP TABLE t;
" | psql
pg_ctl -l server.log stop
grep 'TRAP' server.log && break;
done
triggers
TRAP: failed Assert("!ps->dropped"), File: "pgstat.c", Line: 1730, PID: 844901
maybe this Assert can be removed, because there is no corresponding
assert in pgstat_build_snapshot(), but I saw also:
TRAP: failed Assert("rel->pgstat_info->relation == NULL"), File: "pgstat_relation.c", Line: 142, PID: 157820
TRAP: failed Assert("ent->entry_ref != NULL"), File: "pgstat_shmem.c", Line: 827, PID: 190431
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;
for i in {1..100}; do
echo "
CREATE TABLE t1(i int PRIMARY KEY);
CLUSTER t1 USING t1_pkey;
CREATE TABLE t2(i int PRIMARY KEY);
CLUSTER t2 USING t2_pkey;
DROP TABLE t2;
DROP TABLE t1;
" | psql
grep 'TRAP' server.log && break;
done
triggers:
TRAP: failed Assert("ItemIdIsNormal(lp)"), File: "heapam.c", Line: 2813, PID: 943626
also:
ERROR: attempted to delete invisible tuple
(similar to [1], which can also be triggered with OOM inside
CommandCounterIncrement(), but this one is even more interesting, IMO)
[1] https://www.postgresql.org/message-id/21363eb7-606c-468d-88f4-c14162ddafc8%40gmail.com
Best regards,
Alexander
| Attachment | Content-Type | Size |
|---|---|---|
| random-oom-errors.patch | text/x-patch | 2.1 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Ian Lawrence Barwick | 2026-07-17 09:00:49 | Re: doc: clarify wal_sender_shutdown_timeout behavior for small values |
| Previous Message | Nazir Bilal Yavuz | 2026-07-17 08:57:18 | Re: ci: namespace ccache by PostgreSQL major version |