Re: How does Postgres estimate the memory needed for sorting/aggregating

From: Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>
To: John R Pierce <pierce(at)hogranch(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: How does Postgres estimate the memory needed for sorting/aggregating
Date: 2017-01-25 22:06:44
Message-ID: 2dfed0df-73bc-e3fd-3055-ea9ce6ca5005@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 01/25/2017 10:47 PM, John R Pierce wrote:
> On 1/25/2017 12:59 PM, Thomas Kellerer wrote:
>> So here is my question: how does Postgres estimate/know the memory
>> needed for the aggregation? Or does it dynamically resize the memory
>> if the initial assumption was wrong?
>
> my understanding is it fits as much as it can into a work_mem sized
> allocation, and if thats not enough uses temporary files and multiple
> passes.
>

That only works for hash joins, not for hash aggregates. Hash aggregate
is about the only operation in PostgreSQL that can cause OOM because of
under-estimation.

regards

--
Tomas Vondra http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michael Paquier 2017-01-26 00:24:04 Re: Tips on maintaining several pg_hba files
Previous Message Thomas Kellerer 2017-01-25 22:00:11 Re: How does Postgres estimate the memory needed for sorting/aggregating