Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h9UaG-000134-Dt for pgsql-admin@arkaria.postgresql.org; Thu, 28 Mar 2019 12:56:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h9UaF-0000Pc-1C for pgsql-admin@arkaria.postgresql.org; Thu, 28 Mar 2019 12:56:39 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h9UaE-0000Ok-LT for pgsql-admin@lists.postgresql.org; Thu, 28 Mar 2019 12:56:38 +0000 Received: from mx1.mailbox.org ([2001:67c:2050:104:0:1:25:1]) by makus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h9UaA-00086k-Os for pgsql-admin@postgresql.org; Thu, 28 Mar 2019 12:56:37 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:105:465:1:1:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx1.mailbox.org (Postfix) with ESMTPS id 4F18A4B418; Thu, 28 Mar 2019 13:56:28 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter02.heinlein-hosting.de (spamfilter02.heinlein-hosting.de [80.241.56.116]) (amavisd-new, port 10030) with ESMTP id xr5mKvey5Qkh; Thu, 28 Mar 2019 13:56:17 +0100 (CET) Message-ID: <55e1328ed76390092c1ea5f1af4b59ce593e732f.camel@cybertec.at> Subject: Re: Long running query in new production, not so long in old From: Laurenz Albe To: Mark Steben , pgsql-admin Date: Thu, 28 Mar 2019 13:56:16 +0100 In-Reply-To: References: Organization: Cybertec Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, 2019-03-27 at 19:27 -0400, Mark Steben wrote: > We are moving to a new VM environment (expedient) and have one query that typically runs in 22 - 25 > seconds in our old environment, but is running in about 1 hour, 20 minutes in our new. > I'd like some insight as to why the explain is showing shared buffer hits numbering over 113 milliion > in the new environment and only 445 thousand in the old. I have sent the explains along with the > table descriptions, row counts, the one function that I know causes the bottleneck, the query, > some relevant configuration settings in postgresql conf (identical in both environments) > and a listing from top in both environments, showing memory, shared memory, and cpu. > > Everything seems to be identical or close, except for the shared buffer count in the explain. > Any insight would be appreciated. Slow plan: -> Index Scan using emailrcpts_4columns on emailrcpts (cost=0.56..119078.48 rows=5 width=29) (actual time=4873080.765..4873080.765 rows=0 loops=1) Index Cond: ((cid = 1784539) AND (removed = false) AND (active = true) AND (bounce < 3)) Filter: ((NOT removed) AND active AND (email IS NOT NULL) AND (((fname IS NOT NULL) AND (length((fname)::text) <> 0)) OR ((lname IS NOT NULL) AND (length((lname)::text) <> 0))) AND (number_of_sends(id, 30, 1) < 3) AND (lower(get_make(cid, (vin)::text, (make_purchased)::text)) = 'ohgoshnonotthebees!!!'::text) AND (NOT (SubPlan 1))) Rows Removed by Filter: 19952 Buffers: shared hit=113768530 read=6244 SubPlan 1 -> Limit (cost=0.28..15.58 rows=1 width=0) (never executed) Fast plan: -> Index Scan using emailrcpts_4columns on emailrcpts (cost=0.56..113162.26 rows=5 width=29) (actual time=21086.555..21086.555 rows=0 loops=1) Index Cond: ((cid = 1784539) AND (removed = false) AND (active = true) AND (bounce < 3)) Filter: ((NOT removed) AND active AND (email IS NOT NULL) AND (((fname IS NOT NULL) AND (length((fname)::text) <> 0)) OR ((lname IS NOT NULL) AND (length((lname)::text) <> 0))) AND (number_of_sends(id, 30, 1) < 3) AND (lower(get_make(cid, (vin)::text, (make_purchased)::text)) = 'ohgoshnonotthebees!!!'::text) AND (NOT (SubPlan 1))) Rows Removed by Filter: 19952 Buffers: shared hit=445188 read=61756 SubPlan 1 -> Limit (cost=0.28..15.58 rows=1 width=0) (never executed) Hmm. These are the ideas I can come up with: 1. There are many index tuples belonging to dead heap tuples. Then re-running the query should produce way fewer buffer hits. VACUUM would fix that issue. 2. The index is terribly fragmented. REINDEX INDEX emailrcpts_4columns would improve that one. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com