From: Peter J. Holzer <hjp-pgsql@hjp.at>
To: pgsql-general@lists.postgresql.org
Subject: Re: Please help to improve SELECT JOIN performance, EXPLAIN ANALYZE attached
Date: Sat, 20 Feb 2021 12:58:35 +0100
Message-ID: <20210220115835.GA21988@hjp.at> (raw)
In-Reply-To: <CAADeyWijZ-P4Gcz30+5+E6tuB17Py6aLAtCPaPypWugaf8Tdyw@mail.gmail.com>
References: <CAADeyWihs2wwUmyUJmEav20sXUanp8P9BpJMQVUApoBQV-HMgg@mail.gmail.com>
<CAHOFxGrPSnwrw3yq9XM0k=g84r1bgNc2xyYVxW+NX9FCnSVTTA@mail.gmail.com>
<CAADeyWijZ-P4Gcz30+5+E6tuB17Py6aLAtCPaPypWugaf8Tdyw@mail.gmail.com>
On 2021-02-20 10:24:36 +0100, Alexander Farber wrote:
> The query when I try it does run in 15ms, but evening logs show the query (I
> think only small percentage of it) running 1-3s.
>
> At the same time my CentOS 8 server with 64 GB RAM is never loaded, the load
> average show by top is 0.35-0.45.
>
> What could be the reason, does PostgreSQL 13.2 has some scheduled task maybe?
One very common reason for wildly different execution times is where the
data is: Accessing data in RAM is a lot faster than accessing it on disk
(even for SSDs, but especially for rotating disks).
So it might be that when you executed the EXPLAIN the data just happened
to be in RAM (that's almost certainly the case if you executed the same
query without EXPLAIN before that) while in those cases where it was
slow, the data (or a large part of it) had to be loaded from disk first.
Data might not be in RAM because it wasn't needed for some time, because
some other query or process which needed lots of RAM displaced it, or
because the server was just rebootet.
> I have only changed few lines in the postgresql.conf:
I don't see shared_buffers here. That's quite small by default so you
might want to increase it. The usual recommendation is to start with 25%
of the memory (that would be 16 GB in your case) and then see if it gets
better if decrease or increase it.
hp
--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
Attachments:
signature.asc (application/pgp-signature, 832B) download
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: hjp-pgsql@hjp.at
Subject: Re: Please help to improve SELECT JOIN performance, EXPLAIN ANALYZE attached
In-Reply-To: <20210220115835.GA21988@hjp.at>
References: <CAADeyWihs2wwUmyUJmEav20sXUanp8P9BpJMQVUApoBQV-HMgg@mail.gmail.com> <CAHOFxGrPSnwrw3yq9XM0k=g84r1bgNc2xyYVxW+NX9FCnSVTTA@mail.gmail.com> <CAADeyWijZ-P4Gcz30+5+E6tuB17Py6aLAtCPaPypWugaf8Tdyw@mail.gmail.com> <20210220115835.GA21988@hjp.at>
* 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