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 1hCLkL-000088-N8 for pgsql-general@arkaria.postgresql.org; Fri, 05 Apr 2019 10:06:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hCLkK-0002Nx-7D for pgsql-general@arkaria.postgresql.org; Fri, 05 Apr 2019 10:06:52 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1hCLkJ-0002Jr-NO for pgsql-general@lists.postgresql.org; Fri, 05 Apr 2019 10:06:51 +0000 Received: from mail-oi1-x241.google.com ([2607:f8b0:4864:20::241]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hCLkH-0007es-2x for pgsql-general@lists.postgresql.org; Fri, 05 Apr 2019 10:06:51 +0000 Received: by mail-oi1-x241.google.com with SMTP id t81so4380455oig.10 for ; Fri, 05 Apr 2019 03:06:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=RAsKhmedsqJ9NHcAFTO1yMOUNZbAZaqHg+uqHBi8bbU=; b=WyT7MYLpA4iyNWqbG/0tYEoLiiadATxFgAZ+wXzAmWwQZVU29R4SjWm1yjZ75yoEDu gctbRicTmtKCpHg+qSK24B0OXEH/+x234xRcn8WFs8K0pZ0ejQumezutZ0kfM5+4KbQh rYgdidutX7SeeBWweAaJXj/FYzpo2NamGdKn7kDiZwq2bJIytCvA3hFxjdBNNg8A1xdx 9nQyJA4tI4513nF405OV9U/+imoKZ5cW2/PyxYwIrZGRHkBK9vyKnHWFPuzHjhvnGT8I L0kOOAFxHfqD6bwy92OiQtlfHP+amkUcVUPfaXhoFe/Z4rrcGaEIKEUDWi/iG9TCwo4z a7qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=RAsKhmedsqJ9NHcAFTO1yMOUNZbAZaqHg+uqHBi8bbU=; b=fkvst+CEGnCoYdnZIdukc5fbEFHPg5Vr+3ik0SfRBn9vwI3wPwNgcB346KQjM30ziq sbeFVwHEul4sb4Z0jMEpXUX6P+2e8VqEj8LInsOWFNAnMrCxXyYrqnmlWkJ7cu0OM8xP hqm7nwdMBI56salWBNcIcYZyQZNVJkuVmkQRp0/Hk75rbf/ZaU8CHoFJbWQHzGew/Lio Wc7mzpndKxyiEdl7lmPtXzTgnevlygWM56Idbve4f6TF8IjWAfVKKQ2njvfWi1XW59Lq uRLGjivclyfQxvCcAdIlw/sNh3wWMc7ZSFh/n7ZqaBFu3OBZRDPhOe0Z+ckLEtGXtO2+ rDdg== X-Gm-Message-State: APjAAAX9z5N/sFnEGLdshpOduYViltgNULIjWaOE109WQA07NMA+noLd XVEE6Ai7gE3ob4B10AQ/qMOvEiWflno= X-Google-Smtp-Source: APXvYqxNmScVp7XCaKYbtGuBce7hFcPdzkKR9dQBcYVRyYRvg+LMjkV7j+K/acIXItDf3YhRO37wbQ== X-Received: by 2002:aca:d7d5:: with SMTP id o204mr6562353oig.23.1554458806556; Fri, 05 Apr 2019 03:06:46 -0700 (PDT) Received: from [192.168.1.10] (ip70-171-116-89.no.no.cox.net. [70.171.116.89]) by smtp.googlemail.com with ESMTPSA id o5sm5051642otl.44.2019.04.05.03.06.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Apr 2019 03:06:45 -0700 (PDT) Subject: Re: Query much slower on 9.6.5 than on 9.3.5 To: pgsql-general@lists.postgresql.org References: From: Ron Message-ID: <83564721-f491-66fa-9752-bfcd5d5b7176@gmail.com> Date: Fri, 5 Apr 2019 05:06:44 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------33A396A7A01C8A0D25A7E640" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------33A396A7A01C8A0D25A7E640 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Rob, pg_dump/restore gets rid of all the dead space, and you should *always* run an ANALYZE after pg_restore, since pg_restore doesn't populate the statistics tables. On 4/5/19 4:35 AM, Rob Northcott wrote: > > Hi Ron, > > Thanks for that.  I did just run analyse and vacuum on the live database > before I saw your message and it has sorted it out. > > Do you think the analyse on its own would have cured it, or would it have > been the vacuum? (vacuum took a long time). > > Perhaps I should schedule a vacuum to run periodically to stop this > happening again – I didn’t think it would be necessary because these > aren’t particularly big or heavily-used databases, but it seems I was wrong. > > Also, my assumption that downloading a backup and restoring it locally > would replicate the problem would seem to be wrong. Presumably the backup > removes any dead stuff, so backup/restore has the same effect as a vacuum? > > Anyway, looks like I was panicking prematurely, but thanks for the help > anyway 😊 > > Rob > > *From:*Ron > *Sent:* 05 April 2019 10:13 > *To:* pgsql-general@lists.postgresql.org > *Subject:* Re: Query much slower on 9.6.5 than on 9.3.5 > > On 4/5/19 3:43 AM, Rob Northcott wrote: > > I’ve had a couple of customers complaining of slow searches and doing > some testing last night it seems to be much slower on the live server > than on my test setup. > > It’s quite a messy query built up by the search code, with lots of > joins and subqueries. > > I’ve downloaded a backup of the customer’s live database to test, so > I’m running the same query on the same data, just two different servers. > > On the local test server (PSQL 9.3.5 running on an old Core2 Duo PC) > it takes around 200ms to run the query. > > On the live server (PSQL 9.6.5 on virtual server with 4 cores) it > takes 20 seconds to run the same query. > > Looking at the explain analyse, the two servers are using quite > different optimisation plans, but I can’t find any differences in the > settings. > > Is there anything obvious I should look at that may be different > between 9.3 and 9.6? > > If not, would it help if I post the analyse output on here? (can we > post attachments to the group or should it just be text in the email?) > > Many thanks for any hints > > > I'll get the obvious first question out of the way, so that no one else > has to ask: have you analyzed the 9.6 database? If not, do that first. > > -- > Angular momentum makes the world go 'round. > -- Angular momentum makes the world go 'round. --------------33A396A7A01C8A0D25A7E640 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit Rob,

pg_dump/restore gets rid of all the dead space, and you should always run an ANALYZE after pg_restore, since pg_restore doesn't populate the statistics tables.

On 4/5/19 4:35 AM, Rob Northcott wrote:

Hi Ron,

 

Thanks for that.  I did just run analyse and vacuum on the live database before I saw your message and it has sorted it out.

Do you think the analyse on its own would have cured it, or would it have been the vacuum? (vacuum took a long time).

Perhaps I should schedule a vacuum to run periodically to stop this happening again – I didn’t think it would be necessary because these aren’t particularly big or heavily-used databases, but it seems I was wrong.

 

Also, my assumption that downloading a backup and restoring it locally would replicate the problem would seem to be wrong.  Presumably the backup removes any dead stuff, so backup/restore has the same effect as a vacuum?

 

Anyway, looks like I was panicking prematurely, but thanks for the help anyway 😊

 

Rob

 

From: Ron <ronljohnsonjr@gmail.com>
Sent: 05 April 2019 10:13
To: pgsql-general@lists.postgresql.org
Subject: Re: Query much slower on 9.6.5 than on 9.3.5

 

On 4/5/19 3:43 AM, Rob Northcott wrote:

I’ve had a couple of customers complaining of slow searches and doing some testing last night it seems to be much slower on the live server than on my test setup.

It’s quite a messy query built up by the search code, with lots of joins and subqueries.

I’ve downloaded a backup of the customer’s live database to test, so I’m running the same query on the same data, just two different servers.

On the local test server (PSQL 9.3.5 running on an old Core2 Duo PC) it takes around 200ms to run the query.

On the live server (PSQL 9.6.5 on virtual server with 4 cores) it takes 20 seconds to run the same query.

 

Looking at the explain analyse, the two servers are using quite different optimisation plans, but I can’t find any differences in the settings.

 

Is there anything obvious I should look at that may be different between 9.3 and 9.6?

 

If not, would it help if I post the analyse output on here? (can we post attachments to the group or should it just be text in the email?)

 

Many thanks for any hints


I'll get the obvious first question out of the way, so that no one else has to ask: have you analyzed the 9.6 database?  If not, do that first.

--
Angular momentum makes the world go 'round.


--
Angular momentum makes the world go 'round.
--------------33A396A7A01C8A0D25A7E640--