Re: OOM kill in xmlelement() with large arrays

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>
Cc: Daniel Gustafsson <daniel(at)yesql(dot)se>, Jakub Wartak <jakub(dot)wartak(at)enterprisedb(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Kirill Reshke <reshkekirill(at)gmail(dot)com>
Subject: Re: OOM kill in xmlelement() with large arrays
Date: 2026-11-25 15:30:29
Message-ID: 1280909.1795620629@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Jim Jones <jim(dot)jones(at)uni-muenster(dot)de> writes:
> Done in v2-0001.

I wonder whether this would be a net negative for many use-cases.
Creating and dropping a memory context is hardly free. Have you
done any performance measurements on cases that don't eat enough
memory to be OOM hazards?

One idea for limiting the damage if that does seem to be an issue
is to use a temporary context only when the VARSIZE of the input
array exceeds, say, 10kB. (I'm thinking that the VARSIZE would
be a good guide to the amount of memory we're going to use
because it tells something about the size of the array elements
as well as their number.)

A side point is that I think you don't need to switch in and out
of the temp context each time through the loop. Once the StringInfo
buffer is created it'll repalloc itself bigger in its original
context, and there's nothing saying you can't reset the current
context. This probably wouldn't be worth worrying about in itself,
but it might make it less messy to implement the first idea.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrey Rachitskiy 2026-11-25 15:38:04 Fix OOM when rendering large geometry arrays
Previous Message Nathan Bossart 2026-11-25 15:25:21 Re: Should we skip foreign key checks in binary upgrade mode?