Hundreds of partitions, one partition's memory: an OOM fix in WarehousePG 7.6.2
Some WarehousePG customers hit out-of-memory errors when querying multi-level partitioned tables. The EDB WarehousePG engineering team has fixed it in WarehousePG 7.6.2, which was released in November 2026.
The symptom
Picture a fact table partitioned by day and subpartitioned by region or sales channel, stored as an AO table with compression, with a year or more of history behind it: several hundred leaf partitions. A report scans a wide date range. As the query runs, memory on every segment climbs steadily, and on a busy system the query is cancelled with the familiar Canceling query because of high VMEM usage or an out-of-memory error.
The odd part: the query was not holding much data. Each partition was read once, front to back, and then never touched again. The memory was pure overhead.
Why it happened
Two facts about WarehousePG combine here.
- AO and AOCO tables bypass the shared buffer cache. Every scan of such a table allocates its own private read buffers, sized by the table's block size, and a column-oriented scan keeps one such buffer for every column it reads. A single partition scan therefore holds a few MB, more for wide column-oriented tables.
- The Postgres planner reads partitions one after another through an Append node. When the Postgres-based planner (rather than ORCA) plans a query over a partitioned table, it builds one Append node with one child scan per partition. The executor works through those children sequentially, one partition at a time, never in parallel. But a child that had been opened kept its buffers until the whole query ended. Memory grew with every partition visited and peaked at “all partitions at once”, even though only one was ever being read at a time.
This is why the problem shows up on multi-level partitioned tables. For a single-level partitioned table, ORCA plans a Dynamic Scan, which opens one partition at a time and never had this problem. But ORCA does not support multi-level partitioned tables: every query on one falls back to the Postgres-based planner and gets an Append. So the fix in 7.6.2 is in the Append itself.
The same query, four partitions in. Before: every finished partition still holds its read buffers, so per-segment memory grows until all 450 are open at once. After: finished partitions have released their buffers and memory stays at about one partition.
The fix: release as you go
The change lives in the Append node. When it finishes one child and moves on to the next, and that child is a plain scan of an AO or AOCO partition (sequential, index, index-only or bitmap heap scan), it tells the scan to close its read buffers right away. The finished child is also marked as done, so it can never hand out its rows a second time by accident.
What if the query legitimately needs to read a partition again? WarehousePG's scan nodes open their underlying scan on first use, so a rescan simply reopens the buffers. Correctness is untouched; only the idle memory goes away.
The release is deliberately conservative. It does nothing when:
- the plan announces that it will rewind, scan backward or mark positions, as a scrollable cursor does; every child then stays open;
- the Append is actually rescanned, as in a nested-loop join that re-reads the inner side for every outer row; early release then switches off for the rest of the query so hot loops never pay a reopen cost;
- the partition is a heap table, whose scans hold almost no private memory and rely on synchronized scanning;
- the scan is a parallel scan.
The general idea: early close
Nothing here is specific to WarehousePG. Since the Volcano iterator model (Graefe, 1994), query operators have followed an open() / next() / close() protocol, and close() is where an operator gives back its resources. The protocol never says close() must wait for the end of the query: an input that has returned its last row can be closed at once. Releasing an exhausted input's state as soon as it is no longer needed is known as early close, or more broadly eager resource release. What it buys is a lower peak memory: the peak is set by how much operator state is alive at the same moment, not by how much is allocated over the life of the query.
PostgreSQL's executor maps the protocol onto ExecInitNode(), ExecProcNode() and ExecEndNode(), and for an Append over partitions it splits each child's lifetime into three stages. The change moves only the last one:
| STAGE OF A PARTITION SCAN | BEFORE | AFTER |
|---|---|---|
| Build the plan-state node (cheap) | all partitions, at query start | unchanged |
| Open the scan and its read buffers (expensive) | lazily, on the first row read | unchanged |
| Close the scan and free the buffers | at the end of the query | as soon as Append moves past it |
Lazy open on one side and early close on the other means that, of all the expensive scan state, only the partition being read is ever alive. That is the textbook shape of a per-partition iterator: one operator that opens, drains and closes partitions in turn. ORCA's Dynamic Scan is built that way, which is why ORCA plans never had this problem; the Append now reaches the same memory profile while keeping its one-child-per-partition plan.
The conservative cases listed above are the other half of the textbook story: early close trades memory for a possible reopen cost. Whenever an input may be read again (a rewind, a backward scan, a rescan from a nested loop), reopening it each time can cost more than keeping it open, the same trade-off a planner weighs between rescanning the inner side of a nested loop and materializing it. The Append therefore closes early only while it can be sure each partition is read exactly once, and stops the moment that stops being true.
Seeing it in a plan
Here is the effect on a small three-segment test cluster, comparing WarehousePG 7.6.1 with 7.6.2. The table is a 20-column, column-oriented (AOCO) sales table compressed with zstd. It is partitioned by day for all of 2025 and subpartitioned by sales channel: 365 days times 2 channels gives 730 leaf partitions, with 1,000 rows each.
CREATE TABLE sales (
sale_id bigint,
sale_date date,
channel text,
store_id int,
product_id int,
... -- 20 columns in all
total numeric(12,2)
)
WITH (appendoptimized = true, orientation = column,
compresstype = zstd, compresslevel = 3)
DISTRIBUTED BY (sale_id)
PARTITION BY RANGE (sale_date)
SUBPARTITION BY LIST (channel)
SUBPARTITION TEMPLATE (
SUBPARTITION online VALUES ('online'),
SUBPARTITION store VALUES ('store'))
(START ('2025-01-01') END ('2026-01-01') EVERY (INTERVAL '1 day'));Because the table has two partition levels, ORCA cannot plan queries on it, even though ORCA is enabled on this cluster. With optimizer_trace_fallback switched on, the server says so:
SET optimizer_trace_fallback = on;
EXPLAIN (COSTS OFF) SELECT count(*) FROM sales WHERE sale_date = DATE '2025-01-01';
INFO: GPORCA failed to produce a plan, falling back to Postgres-based planner
DETAIL: Falling back to Postgres-based planner because GPORCA does not support
the following feature: Multi-level partitioned tablesA year-end report sums the whole year:
EXPLAIN (ANALYZE, COSTS OFF)
SELECT count(*), sum(total) FROM sales WHERE sale_date >= DATE '2025-01-01';The plan is the same on 7.6.1 and 7.6.2: one Append with 730 sequential scans beneath it, produced by the Postgres-based planner. Only the per-slice memory statistics at the bottom differ. This is the output on 7.6.1, shortened in the middle:
Finalize Aggregate (actual time=272.470..272.513 rows=1 loops=1)
-> Gather Motion 3:1 (slice1; segments: 3) (actual time=271.712..272.504 rows=3 loops=1)
-> Partial Aggregate (actual time=257.461..257.655 rows=1 loops=1)
-> Append (actual time=0.130..246.078 rows=243886 loops=1)
-> Seq Scan on sales_1_prt_1_2_prt_online (actual time=0.165..0.186 rows=348 loops=1)
Filter: (sale_date >= '2025-01-01'::date)
-> Seq Scan on sales_1_prt_1_2_prt_store (actual time=0.097..0.116 rows=351 loops=1)
Filter: (sale_date >= '2025-01-01'::date)
... 727 more partition scans ...
-> Seq Scan on sales_1_prt_365_2_prt_store (actual time=0.340..0.357 rows=346 loops=1)
Filter: (sale_date >= '2025-01-01'::date)
Optimizer: Postgres-based planner
Planning Time: 91.044 ms
(slice0) Executor memory: 4971K bytes.
(slice1) Executor memory: 172834K bytes avg x 3 workers, 172836K bytes max (seg1).
Memory used: 128000kB
Execution Time: 280.238 msOn 7.6.2 the same query ends with:
(slice1) Executor memory: 3682K bytes avg x 3 workers, 3682K bytes max (seg0).slice1 is the part of the plan that runs on the segments and holds the Append. On 7.6.1, each of the 730 partition scans left roughly 240 KB of read buffers behind (20 columns at the default 32 KB block size), 169 MB per segment in total. On 7.6.2 the whole query needs 3.6 MB, about 2% of that. Narrowing the date range shows the same pattern:
| DATE RANGE | LEAF PARTITIONS SCANNED | 7.6.1 | 7.6.2 |
|---|---|---|---|
| one day | 2 | 519 KB | 287 KB |
| one quarter | 180 | 41.7 MB | 1.1 MB |
| full year | 730 | 168.8 MB | 3.6 MB |
Executor memory per segment from EXPLAIN ANALYZE, three-segment development cluster, ORCA enabled, default block size. With a larger block size and wider tables each partition scan costs several MB, so the 7.6.1 figure scales into the hundreds of MB seen in the next section.
Results
Peak executor memory per segment in other scenarios, measured on planner-generated plans while the fix was being developed:
| SCENARIO | BEFORE | AFTER |
|---|---|---|
| 40-column AOCO (zstd), 150 partitions, sequential scan | 616 MB | 6.4 MB |
| AO, 450 partitions, sequential scan | 67.6 MB | 1.6 MB |
| AO, 450 partitions, join with dynamic partition elimination down to 225 | 36.5 MB | 3.5 MB |
| 20-column AO / AOCO, 30 partitions, index scan | 35.1 MB | 2.5 MB |
| 20-column AO / AOCO, 30 partitions, bitmap scan | 35.4 MB | 3.7 MB |
A new regression test checks that scanning 30 AO / AOCO partitions needs about as much executor memory as scanning one, and that rescans and cursors fetched in small chunks still return every row exactly once.
What this means for you
- Nothing to configure. The release applies automatically to planner-generated Append plans over AO and AOCO partitions.
- Who benefits most. Multi-level partitioned AO and AOCO tables, which always run on the planner because ORCA does not support them. The wider the table, the larger the block size and the more partitions, the bigger the saving. Other queries that fall back to the planner benefit too.
- How to see it. In
EXPLAIN ANALYZE, look for anAppendnode with many partition scans beneath it and compare the per-sliceExecutor memoryfigure before and after upgrading, as in the example above. - What's next. More improvements are coming in the next WarehousePG release.