Re: Suggestion for memory parameters

From: Greg Sabino Mullane <htamfids(at)gmail(dot)com>
To: yudhi s <learnerdatabase99(at)gmail(dot)com>
Cc: Philip Semanchuk <philip(at)americanefficient(dot)com>, pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Suggestion for memory parameters
Date: 2024-10-01 12:00:07
Message-ID: CAKAnmmJSfw92MDa6TDxJ3e63AE=1gaZFJinFdHbkFQh=KrA7BQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Oct 1, 2024 at 2:52 AM yudhi s <learnerdatabase99(at)gmail(dot)com> wrote:

> When I execute the query with explain (analyze, buffers),I see the section
> below in the plan having "sort method" information in three places
> each showing ~75MB size, which if combined is coming <250MB. So , does that
> mean it's enough to set the work_mem as ~250MB for these queries before
> they start?
>

work_mem is set per action, so you don't need to usually combine them.
However, these are parallel workers, so you probably need to account for
the case in which no workers are available, in which case you DO want to
combine the values - but only for parallel workers all doing the same
action.

> But yes somehow this query is finished in a few seconds when i execute
> using explain(analyze,buffers) while if i run it without using explain it
> runs for ~10minutes+. My expectation was that doing (explain analyze)
> should actually execute the query fully. Is my understanding correct here
> and if the disk spilling stats which I am seeing is accurate enough to go
> with?
>

Running explain analyze does indeed run the actual query, but it also
throws away the output. It looks like your limit is set to 300,000 rows
(why!??), which could account for some or all of the time taken - to pass
back those rows and for your client to process them. But it's hard to say
if that's the total reason for the difference without more data. It might
help to see the query, but as a rule of thumb, don't use SELECT * and keep
your LIMIT sane - only pull back the columns and rows your application
absolutely needs.

Cheers,
Greg

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Greg Sabino Mullane 2024-10-01 12:14:36 Re: Question on session timeout
Previous Message Laurenz Albe 2024-10-01 10:39:02 Re: Help with query optimizer