Oom on temp (un-analyzed table caused by JIT) V16.1

From: Kirk Wolak <wolakk(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Daniel Gustafsson <daniel(at)yesql(dot)se>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Subject: Oom on temp (un-analyzed table caused by JIT) V16.1
Date: 2024-01-15 06:24:31
Message-ID: CACLU5mQynL+5s6kPpFTvmqtrLymSvMo=z7Tg7XBL0jD-DvcM8w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Daniel,
You have a commit [1] that MIGHT fix this.
I have a script that recreates the problem, using random data in pg_temp.
And a nested cursor.

It took me a few days to reduce this from actual code that was
experiencing this. If I turn off JIT, the problem goes away. (if I don't
FETCH the first row, the memory loss does not happen. Maybe because
opening a cursor is more decoration/prepare)

I don't have an easy way to test this script right now against the commit.
I am hopeful that your fix fixes this.

This was my first OOM issue in PG in 3yrs of working with it.

The problem goes away if the TABLE is analyzed, or JIT is disabled.

The current script, if run, will consume about 25% of my system memory
(10GB).
Just call the function below until it dies if that's what you need. The
only way to get the memory back down is to close the connection.

SELECT pg_temp.fx(497);

Surprisingly, to me, the report from pg_get_backend_memory_contexts()
doesn't really show "missing memory", which I thought it would. (FWIW, we
caught this with multiple rounds of testing our code, slowing down, then
crashing... Is there ANY way to interrogate that we are above X% of system
memory so we know to let this backend go?)

It takes about 18 minutes to run on my 4 CPU VM.

For now, we are going to add some ANALYZE statements to our code.
We will consider disabling JIT.

Thanks,
Kirk
[1] = 2cf50585e54a7b0c6bc62a087c69043ae57e4252
<https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=2cf50585e54a7b0c6bc62a087c69043ae57e4252>

Attachment Content-Type Size
Oom_recreation.sql text/plain 4.2 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Sutou Kouhei 2024-01-15 06:27:02 Re: Make COPY format extendable: Extract COPY TO format implementations
Previous Message Sutou Kouhei 2024-01-15 06:23:50 Re: Make COPY format extendable: Extract COPY TO format implementations