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.92) (envelope-from ) id 1j7EaL-00060Q-M0 for pgsql-performance@arkaria.postgresql.org; Thu, 27 Feb 2020 08:31:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j7EaK-0005x2-E7 for pgsql-performance@arkaria.postgresql.org; Thu, 27 Feb 2020 08:31:56 +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 1j7EaK-0005qY-0u for pgsql-performance@lists.postgresql.org; Thu, 27 Feb 2020 08:31:56 +0000 Received: from mail.mnc.ch ([62.2.77.205]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j7EaG-0006xB-2Y for pgsql-performance@postgresql.org; Thu, 27 Feb 2020 08:31:53 +0000 X-Virus-Scanned: amavisd-new at mnc.ch Sender: gc@mnc.ch Received: by gc-P7xxDM3-G.localdomain (Postfix, from userid 1000) id 99ED682BA1; Thu, 27 Feb 2020 09:31:45 +0100 (CET) From: Guillaume Cottenceau To: Jeff Janes Cc: "pgsql-performa." Subject: Re: much slower query in production References: <878skpnx0u.fsf@mnc.ch> <20200226162809.GZ31889@telsasoft.com> <87tv3dmdlu.fsf@mnc.ch> Date: Thu, 27 Feb 2020 09:31:45 +0100 In-Reply-To: (Jeff Janes's message of "Wed, 26 Feb 2020 18:17:58 -0500") Message-ID: <87k148mnwu.fsf@mnc.ch> MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Jeff Janes writes: > On Wed, Feb 26, 2020 at 1:02 PM Guillaume Cottenceau wrote: > > It is actually consistent with using a restored backup on the dev > computer, as my understanding is this comes out without any > garbage and like a perfectly vacuumed database. > > I think I got that backwards in my previous email. It is the > dev that was restored, not the prod? But unless you went out of Yes (prod was also restored not so long ago, when updating to pg 11.5 tho). > your way to vacuum dev, it would not be perfectly vacuumed. If > it were a logical restore, it would be perfectly unvacuumed, > and if a physical restore would be in the same state of > vacuuming as the database it was cloned from. > > Btw do you have > any hint as to how to perform timings using production data which > are consistent with production? Backup/restore is maybe not the > way to go, but rather a block device level copy? > > block device copy seems like overkill, just using pg_basebackup should be good enough. > > Since postgresql 8, I have to say I rely entirely on autovacuum, > and did not notice it could really run too infrequently for the > work and create such difference. I see in documentation a default > autovacuum_vacuum_scale_factor = 0.2, is that something that is > typically lowered globally, e.g. maybe on a fairly active system? > I am worried that changing that configuration for that table to > 0.005 would fix this query and similar ones, but later I might > face the same situation on other tables. Or how would you elect > tables for a lowered value configuration? > > The autovacuum system has never been redesigned with the needs of index-only-scans in mind. If I have a table for which > index-only scans are important, I'd set autovacuum_vacuum_scale_factor = 0 and set autovacuum_vacuum_threshold to about 5% of > the number of blocks in the table. There is no syntax to say '5% of the number of blocks in the table' so you have to compute > it yourself and hardcode the result, which makes it unsuitable for a global setting. And this still only addresses UPDATE and It seems also difficult for us as this table grows over time (and is trimmed only infrequently). > DELETE operations, not INSERTs. If you have INSERT only or mostly table for which index-only-scans are important, you might > need to set up cron jobs to do vacuuming. Thanks! -- Guillaume Cottenceau