Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lDQuI-0003wr-M3 for pgsql-general@arkaria.postgresql.org; Sat, 20 Feb 2021 11:58:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lDQuG-0003f0-I1 for pgsql-general@arkaria.postgresql.org; Sat, 20 Feb 2021 11:58:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lDQuG-0003es-9y for pgsql-general@lists.postgresql.org; Sat, 20 Feb 2021 11:58:40 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lDQuC-0003FR-D1 for pgsql-general@lists.postgresql.org; Sat, 20 Feb 2021 11:58:39 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id 1198E4507; Sat, 20 Feb 2021 12:58:35 +0100 (CET) Date: Sat, 20 Feb 2021 12:58:35 +0100 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: Please help to improve SELECT JOIN performance, EXPLAIN ANALYZE attached Message-ID: <20210220115835.GA21988@hjp.at> Mail-Followup-To: pgsql-general@lists.postgresql.org References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="h31gzZEtNLTqOjlF" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --h31gzZEtNLTqOjlF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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. >=20 > At the same time my CentOS 8 server with 64 GB RAM is never loaded, the l= oad > average show by top is 0.35-0.45. >=20 > What could be the reason, does PostgreSQL 13.2 has some scheduled task ma= ybe? 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).=20 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 --=20 _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" --h31gzZEtNLTqOjlF Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmAw+WUACgkQ8g5IURL+ KF2+Uw/7BizWbYohr1wGBfMfYyu9q4JIjEvHjrV2/9VmD9Z03jq3hqlYfOuDpn8T frssz2Uk8gElhG/aYCrPLiTykm8kOmWBWm2XX0bsWCCOeG1NNgK9BEWaJx+jIP0B OL4VBb4WjYSTHR7kANwBTaYzmTIAiboDdZK+08Qx5JDNlfAGxjnfwy/GhQ8dwtn3 tY3h5RYREZ2CxFAcP5uiJrsopx6IOrf55Nw5dPSSalTY3s81VbI/QGTdUSPdiBB4 zpdLb86BVpHKCVFH7D1HSf6o3ZtP3o+O5xR5M8T9GSX6pu1aEcAOv3MnJ9DtdPJa XDWNHGgcTe/pySVraZ4savmNdPqJnzMljW9Ttsg9tVSr/ByjWGU3LkwhjOt6UZiO FhPMxPulOM11EBB5Kp0PkZQ8QAoX469ugm8Sa59FijyWRRc9/90hIBXwxTta+7uN Q2oQg+5ZImwJSe/NhLKKEDfMo82+S8INLIIHZpg6ZHlJMbY0JG512SnM6Hzr1jCU gqpfm0SypAzmkgdBphu13DbqF/UNnT+IjhjTdBhsoT6jvyVpL9BMrWtGtSDtOOTO q6aS3FoaK060POoeEozHFI+KAF1yog4SeFxVjVEc9CJHehxcjgmlCYb4vh3EhLr1 nkfFVIThzN37mpKV2Z7f4zTQrP4GWvdpkl0M2ke7AsFg1VNQp2w= =V+2o -----END PGP SIGNATURE----- --h31gzZEtNLTqOjlF--