Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eBiHf-0003d2-Cs for pgsql-performance@arkaria.postgresql.org; Mon, 06 Nov 2017 14:21:51 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1eBiHe-0002fK-Ai for pgsql-performance@arkaria.postgresql.org; Mon, 06 Nov 2017 14:21:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eBiHd-0002cs-JP for pgsql-performance@postgresql.org; Mon, 06 Nov 2017 14:21:49 +0000 Received: from mail-it0-x236.google.com ([2607:f8b0:4001:c0b::236]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1eBiHZ-0006hI-OE for pgsql-performance@postgresql.org; Mon, 06 Nov 2017 14:21:48 +0000 Received: by mail-it0-x236.google.com with SMTP id p138so5456507itp.2 for ; Mon, 06 Nov 2017 06:21:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=hD+xHqwbhRkwKpq+uakD0VpANwz7fa4vEA4stdBolA0=; b=OJpzpeHTtGzJBebkA2gIx8oQpzWws14mH2Jtj+fQOaZfsZsrq0a9t1SEPQ2AwaTMbD a1fj2L94SI9eCgbmvr20GflCZqPyTS5qUIHvSyMigsehiqOJH9BNmyqVo3HusISK7hMN Yhzfxe1A2eCXX23J0zYAkPg5dR/caqk7VFYjL490p/wzAv+WzDiYqLkwinc/VjAAGxeL 45QS2QaBhE2fZiyKGd3SWJcQMXjb+ehntI+cAwGsyudEgC+ZFbBvaWpUfF1sEZ8gc4LK dP+E2x0f3WHg8MYFHNnyX/aeRkch61P+XnIUwtA90y7LGYMu+fFZ0tfMdyRL2c6cvBe+ CPlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=hD+xHqwbhRkwKpq+uakD0VpANwz7fa4vEA4stdBolA0=; b=ZIlOv6lKiwHqLWNAlG8WvNm64agMC2eKH/UPcCrS85HZAeYvTW4ZMu8DS91oUWViCw DTqG9Tq2Nhd/pM6PeVtCFFwgI8CuQRydtUl9YV8gn8QCRaMhKY511ER7Jw3EYgzsf9bb wdvPbrfuUJjomjIElPQBrIrN5gzCQ1wNmZxQ71T2buBvq6c5Bj+qYCAgFljOhcJL5Qup 4Qk6SWOatwkMhAKxn5gnWjfbbY4S6TBuP4BSMhkLENrh5NOBr/hVEao5cyM/Rtk7Vxfw kDXbq+awt3b1QMfIip8kBAv7DfbSpArAzaFJpKYS/bFdCbWAK3AVu4kZgcYwYyK3tLJy gO7Q== X-Gm-Message-State: AJaThX44SIHPhgjcV9YmEDIcwkyBfP3xuFFEpFCCL2ByNDsifHzxaB0s 7tXWkFCXa72a/DcjFio61+jotllDmPg= X-Google-Smtp-Source: ABhQp+SztbD2FEY38e6vLFHp7yh/z0Zmx1vKORwj6rHAI8M0mTqpfPGEUdM30I9KsSagbqy81H9PtQ== X-Received: by 10.36.178.85 with SMTP id h21mr10262984iti.118.1509978103654; Mon, 06 Nov 2017 06:21:43 -0800 (PST) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id y192sm4443036itb.30.2017.11.06.06.21.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Nov 2017 06:21:43 -0800 (PST) Received: by pryzbyj (Postfix, from userid 1000) id 3795C800FE7; Mon, 6 Nov 2017 08:21:42 -0600 (CST) Date: Mon, 6 Nov 2017 08:21:42 -0600 From: Justin Pryzby To: Adam Torres Cc: "pgsql-performance@postgresql.org" Subject: Re: Performance loss upgrading from 9.3 to 9.6 Message-ID: <20171106142142.GD14205@telsasoft.com> References: <68F12CAE-BFD8-4E21-8B39-AECB0C5E5A8F@contoso.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <68F12CAE-BFD8-4E21-8B39-AECB0C5E5A8F@contoso.com> User-Agent: Mutt/1.5.23 (2014-03-12) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On Mon, Nov 06, 2017 at 01:18:00PM +0000, Adam Torres wrote: > Good morning all, > > We have a problem with performance after upgrading from 9.3 to 9.6 where certain queries take 9 times longer to run. On our initial attempt to upgrade, we noticed the system as a whole was taking longer to run through normal daily processes. The query with the largest run time was picked to act as a measuring stick. > https://explain.depesz.com/s/z71u > Planning time: 8.218 ms > Execution time: 639319.525 ms > > Same query as run on 9.3 > https://explain.depesz.com/s/gjN3 > Total runtime: 272897.150 ms Actually it looks to me like both query plans are poor.. ..because of this: | Hash Join (cost=85,086.25..170,080.80 ROWS=40 width=115) (actual time=32.673..84.427 ROWS=13,390 loops=1) | Hash Cond: (av.customer_id = cc_1.id) If there are a large number of distinct customer_ids (maybe with nearly equal frequencies), it might help to ALTER TABLE av ALTER customer_id SET STATISTICS 400 ..same for cc_1.id. And re-analyze those tables (are they large??). see if statistics improve: SELECT (SELECT sum(x) FROM unnest(most_common_freqs) x) frac_MCV, tablename, attname, n_distinct, array_length(most_common_vals,1) n_mcv, FROM pg_stats WHERE attname~'customers_customer' AND tablename='id' GROUP BY 1,2,3,4,5 ORDER BY 1 Goal is to get at least an accurate value for n_distinct (but preferably also storing the most frequent IDs). I wouldn't bother re-running the query unless you find that increasing stats target causes the plan to change. Justin -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance