pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Radoslav Nedyalkov <rnedyalkov@gmail.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: how to limit statement memory allocation
Date: Tue, 09 Mar 2021 13:13:49 -0500
Message-ID: <2036985.1615313629@sss.pgh.pa.us> (raw)
In-Reply-To: <CANhtRiZL8FBBQ+o=9OzAs0VaJg6Nh7w9ijHUB1=+UZ5sH8_4VQ@mail.gmail.com>
References: <CANhtRiabb+qeeRp--iBMrzWEJWJQoOOqS2-JaKA-3PY7CULXuw@mail.gmail.com>
	<2022857.1615305820@sss.pgh.pa.us>
	<CANhtRia8yRBMNOpPGoTaOYDQeyUJahd5+LVAsHY_TJyHTbUpxQ@mail.gmail.com>
	<2033832.1615308833@sss.pgh.pa.us>
	<CANhtRiZL8FBBQ+o=9OzAs0VaJg6Nh7w9ijHUB1=+UZ5sH8_4VQ@mail.gmail.com>

Radoslav Nedyalkov <rnedyalkov@gmail.com> writes:
> On Tue, Mar 9, 2021 at 6:53 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> The only thing I'm aware of that could consume unbounded memory
>> on the server side is hash aggregation.  (v13 has improved that
>> situation, but I'm guessing you are running some older version.)
>> The planner won't choose hash aggregation if it estimates that
>> the hash table would need to exceed work_mem, but its estimate
>> could be wrong.

> Query and plan attached.

Yeah, so, this looks suspicious:

     ->  HashAggregate  (cost=181320662.52..181323190.52 rows=252800 width=16)
           Group Key: gsm.merchant_id, cer.date
           ->  Merge Left Join  (cost=161250580.17..170174828.82 rows=891666696 width=71)

How accurate is that estimate for the number of merchant_id/date
groups?  Is the estimate for the size of the input join reasonable?

Assuming this is the problem, a brute-force fix could be to turn off
enable_hashagg.  But it'd be better to try to get the planner's
estimates more in line with reality.

			regards, tom lane





view thread (7+ messages)  latest in thread

Message-ID: <2036985.1615313629@sss.pgh.pa.us>
Permalink:  ../2036985.1615313629@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2036985.1615313629@sss.pgh.pa.us

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, rnedyalkov@gmail.com
  Subject: Re: how to limit statement memory allocation
  In-Reply-To: <2036985.1615313629@sss.pgh.pa.us>
  References: <CANhtRiabb+qeeRp--iBMrzWEJWJQoOOqS2-JaKA-3PY7CULXuw@mail.gmail.com> <2022857.1615305820@sss.pgh.pa.us> <CANhtRia8yRBMNOpPGoTaOYDQeyUJahd5+LVAsHY_TJyHTbUpxQ@mail.gmail.com> <2033832.1615308833@sss.pgh.pa.us> <CANhtRiZL8FBBQ+o=9OzAs0VaJg6Nh7w9ijHUB1=+UZ5sH8_4VQ@mail.gmail.com> <2036985.1615313629@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox