Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eaPIX-0002nT-Kk for pgsql-general@arkaria.postgresql.org; Sat, 13 Jan 2018 17:08:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eaPIW-0003cA-G5 for pgsql-general@arkaria.postgresql.org; Sat, 13 Jan 2018 17:08:48 +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 1eaPIW-0003bz-8S for pgsql-general@lists.postgresql.org; Sat, 13 Jan 2018 17:08:48 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eaPIT-00035z-51 for pgsql-general@postgresql.org; Sat, 13 Jan 2018 17:08:47 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w0DH8dik012541; Sat, 13 Jan 2018 12:08:39 -0500 From: Tom Lane To: Rahul Sharma cc: pgsql-general@postgresql.org, Jagbir Singh , Sonender Singh , Rishikesh kumar , Ishank Singh Subject: Re: Postgres 9.4 using primary key index in almost all queries leading to degraded performance In-reply-to: References: Comments: In-reply-to Rahul Sharma message dated "Sat, 13 Jan 2018 12:07:17 +0530" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <12539.1515863319.1@sss.pgh.pa.us> Date: Sat, 13 Jan 2018 12:08:39 -0500 Message-ID: <12540.1515863319@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Rahul Sharma writes: > We're currently testing out upgrade of our Postgres database from 9.3.14 to > 9.4.9. We are using Amazon RDS. We've encountered an issue in testing > phase where after the upgrade, CPU utilization hovers around 100%. We dug > deep to find that the queries which executed in a few milliseconds on > Postgres 9.3.14 are taking a lot of time to complete on 9.4.9. We've > noticed a pattern under which the query planner (in almost all queries) is > using primary key index for scanning the table while ignoring other > alternatives like explicit sorting or using another efficient index present > on the table. In all the examples you show, the rowcount estimates are substantially different in 9.3 and 9.4 --- and at least in the non-LIMITed queries, where it's possible to verify the estimates, 9.3 is reasonably on-target but 9.4 is awful. So your problem is not with the costs but with the selectivity estimates. Has the 9.4 database been ANALYZEd at all? Maybe you disabled auto-analyze? Maybe the old DB has some special statistics target settings that you neglected to port forward? regards, tom lane