| From: | Jakub Wartak <jakub(dot)wartak(at)enterprisedb(dot)com> |
|---|---|
| To: | Jim Jones <jim(dot)jones(at)uni-muenster(dot)de> |
| Cc: | 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 13:01:46 |
| Message-ID: | CAKZiRmzm5Kz5zOOi1gROuXq7T6FeYt=bcbzDBwGRbvKn6N=gfw@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Wed, Nov 25, 2026 at 12:50 PM Jim Jones <jim(dot)jones(at)uni-muenster(dot)de> wrote:
>
> Hi
>
> While answering a review in [1] I noticed that xmlelement() accumulates
> the intermediate data produced for every array element until the end of
> the statement. For large arrays this can quickly exhaust the server's
> memory, and the loop does not check for interrupts, so it cannot be
> cancelled while memory grows..
>
> == PG19 =
>
> psql (19.0 (Debian 19.0-2.pgdg13+1))
> Type "help" for help.
>
> postgres=# select length(xmlelement(name a, array_fill(''::text,
> ARRAY[56000000]))::text);
> server closed the connection unexpectedly
Oh my! Reproduced, this oneliner almost crashed my 32GB laptop:
Out of memory: Killed process 66563 (postgres) total-vm:29998880kB,
anon-rss:22659436kB[..]
(yeah, that's literally 22-29GB)
+1 to fixing this. Patch LGMT, maybe just two tiny things:
- perhaps move MemoryContext oldcxt to the loop
- "map_sql_value_to_xml_value temporary cxt" is a bit lengthy blob, maybe
"elements of XML array" would suffice there (or maybe check further wihtin
pg_backend_memory_contexts for better examples)
---
Not related to the thread: I wish we had a way to limit backend total RSS
somehow. I've lost count on how many occassions we hit such issues without
any safety net. Not that the patch fixes it, but it can still DoS the thing.
Andres told me that setrlimit(RLIMIT_DATA) SIGSEGVs in case of hitting the
limit when growing stack and not just overallocating memory (if I recall
correctly). I've tried to simulate such stuff, but it always worked properly
for me...
-J.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Chengpeng Yan | 2026-11-25 13:09:18 | Re: Preserve presorted ORDER BY keys when reordering DISTINCT ON keys |
| Previous Message | Zhijie Hou | 2026-11-25 13:00:33 | Fix assert failure in composite type dependency check for index expr |