Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pbhj5-000578-RR for pgsql-admin@arkaria.postgresql.org; Mon, 13 Mar 2023 12:56:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pbhj3-0004YL-Nw for pgsql-admin@arkaria.postgresql.org; Mon, 13 Mar 2023 12:56:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pbhj3-0004YB-D0 for pgsql-admin@lists.postgresql.org; Mon, 13 Mar 2023 12:56:29 +0000 Received: from mail-qt1-x829.google.com ([2607:f8b0:4864:20::829]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pbhj0-0007FM-Cm for pgsql-admin@lists.postgresql.org; Mon, 13 Mar 2023 12:56:29 +0000 Received: by mail-qt1-x829.google.com with SMTP id cf14so12904831qtb.10 for ; Mon, 13 Mar 2023 05:56:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678712184; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=z1P33eD2gzPf8+ZdxGwu7VdiVmN6IZyKJf4Ts5i9V7s=; b=nnV7fzd5hyg++SzqsABbUJtq779hPJcVibV3qheI+GPyCsV3l0wUSOSaGXoDBUUxyG KlHCMeaK3o3zAWE7kgHAWwQMWiWtRn1v+JjH7s3yNQjPSYO09oDPDqVUE3Y+9K2bYzQ2 woX/vVxervBLEejrUlmnfJ3rCV12sCHBgFVpDo7DSK4OXtW8Rr79U5US7ddbqTdw2ycO dyVUMgDcQX0iCyFKz4cVGSZPtl20oBjsQYS3VCJQy8/H9du4ePlRgY4AJq23q3acl9/e s30tr0MBMeEHhMkUaslKlG92a5Q3MEYWvxBKfonNxD204ZUyRSOQKEk5n9JtMgtG0dH7 zP5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678712184; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=z1P33eD2gzPf8+ZdxGwu7VdiVmN6IZyKJf4Ts5i9V7s=; b=tURv3XPBpWnrML9uVopD/KGLSf8IEjj0od8sJe/Dnw5LdpoCwyWIR/K6BxE+2+DZ2C UbRce1PG5lkMpoPAgRGBs0f1NMoIn3YlOhLibIr7Y5dczcpInKJ4CoMowaRo4MxO6tTQ SwnN/l3RbVZxR6NYCJO0Fm8/h7708U2ulLiwYOITNsCiODLmSg0+HhzUpAXGJAMVXOhE SxIz7kMWSQdogCstMg2ATghpGQGlorG5r786v6r6KZRyJ1NMpVZ49klIXCQJXV3ubFQk PBNEbUf/edgZvli+I9wLW+WI6QuLM9H+nFuqu8zDEGJq7lXmPnSQIjdG/qqJKQaD+AiO JF9w== X-Gm-Message-State: AO0yUKVUhW/axr+P6P2wYh4/0E4nJ4KdYudjMg4JkmM+Q/f19Lt0pCJP QuLiJBVH5oT3dNGStBrSk599gS/qFTM= X-Google-Smtp-Source: AK7set8MQdg28mOAilw8COWx6z0Ou8qW3OhuC2OWUTHkFLM/fEOczqH7hImYW0mJwhA/9M4HBa+AqQ== X-Received: by 2002:ac8:58d1:0:b0:3c0:6c3:fe72 with SMTP id u17-20020ac858d1000000b003c006c3fe72mr18702397qta.10.1678712184349; Mon, 13 Mar 2023 05:56:24 -0700 (PDT) Received: from ?IPV6:2600:1700:bd2c:b810::43? ([2600:1700:bd2c:b810::43]) by smtp.googlemail.com with ESMTPSA id m17-20020ae9e011000000b00738e8e81dc9sm5244411qkk.75.2023.03.13.05.56.23 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 Mar 2023 05:56:23 -0700 (PDT) Message-ID: <96f99040-9501-c5dc-50ee-a0b95adf288d@gmail.com> Date: Mon, 13 Mar 2023 07:56:23 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: Tooling for per table autovacuum tuning Content-Language: en-US To: pgsql-admin@lists.postgresql.org References: <20230313100936.seqzbfms7hj25xyt@alvherre.pgsql> From: Ron In-Reply-To: <20230313100936.seqzbfms7hj25xyt@alvherre.pgsql> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk An excellent write up. And seems to be for the same reason why one should VACUUM after On 3/13/23 05:09, Alvaro Herrera wrote: > On 2023-Mar-12, Ron wrote: > >> A giant table which is never updated (or deleted from) doesn't need to be >> vacuumed. > Actually, this bit is wrong, because vacuuming is also used for things > such as setting up the visibility map, which feeds index-only scans. So > insert-only tables also benefit from vacuuming, and indeed Postgres 13 > introduced this as an autovacuum feature, in this commit: > > > commit b07642dbcd8d5de05f0ee1dbb72dd6760dd30436 > Author: David Rowley [] > AuthorDate: Sat Mar 28 19:20:12 2020 +1300 > CommitDate: Sat Mar 28 19:20:12 2020 +1300 > > Trigger autovacuum based on number of INSERTs > > Traditionally autovacuum has only ever invoked a worker based on the > estimated number of dead tuples in a table and for anti-wraparound > purposes. For the latter, with certain classes of tables such as > insert-only tables, anti-wraparound vacuums could be the first vacuum that > the table ever receives. This could often lead to autovacuum workers being > busy for extended periods of time due to having to potentially freeze > every page in the table. This could be particularly bad for very large > tables. New clusters, or recently pg_restored clusters could suffer even > more as many large tables may have the same relfrozenxid, which could > result in large numbers of tables requiring an anti-wraparound vacuum all > at once. > > Here we aim to reduce the work required by anti-wraparound and aggressive > vacuums in general, by triggering autovacuum when the table has received > enough INSERTs. This is controlled by adding two new GUCs and reloptions; > autovacuum_vacuum_insert_threshold and > autovacuum_vacuum_insert_scale_factor. These work exactly the same as the > existing scale factor and threshold controls, only base themselves off the > number of inserts since the last vacuum, rather than the number of dead > tuples. New controls were added rather than reusing the existing > controls, to allow these new vacuums to be tuned independently and perhaps > even completely disabled altogether, which can be done by setting > autovacuum_vacuum_insert_threshold to -1. > > We make no attempt to skip index cleanup operations on these vacuums as > they may trigger for an insert-mostly table which continually doesn't have > enough dead tuples to trigger an autovacuum for the purpose of removing > those dead tuples. If we were to skip cleaning the indexes in this case, > then it is possible for the index(es) to become bloated over time. > > There are additional benefits to triggering autovacuums based on inserts, > as tables which never contain enough dead tuples to trigger an autovacuum > are now more likely to receive a vacuum, which can mark more of the table > as "allvisible" and encourage the query planner to make use of Index Only > Scans. > > Currently, we still obey vacuum_freeze_min_age when triggering these new > autovacuums based on INSERTs. For large insert-only tables, it may be > beneficial to lower the table's autovacuum_freeze_min_age so that tuples > are eligible to be frozen sooner. Here we've opted not to zero that for > these types of vacuums, since the table may just be insert-mostly and we > may otherwise freeze tuples that are still destined to be updated or > removed in the near future. > > There was some debate to what exactly the new scale factor and threshold > should default to. For now, these are set to 0.2 and 1000, respectively. > There may be some motivation to adjust these before the release. > > Author: Laurenz Albe, Darafei Praliaskouski > Reviewed-by: Alvaro Herrera, Masahiko Sawada, Chris Travers, Andres Freund, Justin Pryzby > Discussion: https://postgr.es/m/CAC8Q8t%2Bj36G_bLF%3D%2B0iMo6jGNWnLnWb1tujXuJr-%2Bx8ZCCTqoQ%40mail.gmail.com > > -- Born in Arizona, moved to Babylonia.