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 1nEzNK-0003u9-LV for pgsql-hackers@arkaria.postgresql.org; Tue, 01 Feb 2022 20:03:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nEzNJ-0003UE-JE for pgsql-hackers@arkaria.postgresql.org; Tue, 01 Feb 2022 20:03:37 +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 1nEzMe-0007eN-UZ for pgsql-hackers@lists.postgresql.org; Tue, 01 Feb 2022 20:02:57 +0000 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nEzMc-00078e-5j for pgsql-hackers@lists.postgresql.org; Tue, 01 Feb 2022 20:02:56 +0000 Received: by mail-pl1-x62f.google.com with SMTP id u11so16278108plh.13 for ; Tue, 01 Feb 2022 12:02:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=cuaGbk/o19hUeb133xaeE6zivAM8MQgv4D68AmhLSJc=; b=oFJcHL4Ldj8/cFipnN+oGX7ymc0wTVocsI+GAqq5zH6mmhwzL8FRdIrjjEr1h6Oq+d Zde7ezf7kCaZwEVXX9f4SSqFo37wJAVA3OxlN0geMUjtrfyg06XCsWXLw0rGsMizlimE Zzq3owaxUaHgqizkSDqMTseSbXekg2kLfvCvnWpuAh++UwXtfdYcCeimhDd5LGyVesGO g18AvgGRsXOZ8Qb+pGT7pD3InRgj7pY+gBlx+EV2Lvm8pRWOUDJWec3XJGYa7EbH3c9W W1a4uaxzlOqagiUfahfMBn7Lhov4HJtHm/B3aNZrVwRE/ldQzuIZ4ETtxLfdktWkYbEi V1zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=cuaGbk/o19hUeb133xaeE6zivAM8MQgv4D68AmhLSJc=; b=mzY/LG/9fLbds5vtbISUZAzmbGofmHCOzUEfYskwnOUbdkG8zWAs+96Xp4b3N2dvt3 uDUX5FH3xC/S3G+aF9EaWiuuyO1YIruTuo7IkjS5DoejfYXW5Q31nFk58hi15RmVD9nB Nr9z2LB7m0u3TsQP2N6UD2Y5KU/ZiDYcHGAch3d6Ba8gJCeGPgnXN8IvCdbVyu2Ro+4d ati/sa/hVht7RVarJenQ1VluPZMnGtUqjL9qLb0WHeWYig0YRAjke9pP90XUMLPOwqmJ igjZWlp431fLV3j4WAg0tVkbiuDSdRE9sX1B+2CgFg8vdAhx/3/v9v5eAcS+za8hbxvH pMOg== X-Gm-Message-State: AOAM5339lXLWPdmY2mxW7fuAbxO/5nC4zY8l+CRaJK++J7hphVK6Wvdy OcmTbkU2WRSEe2JPBihtHkyZbdxcUU623mbQU8lxnRh7ANo= X-Google-Smtp-Source: ABdhPJy0oQ3tNIeCt3r05vis8+U+TdRMFAW8TTGSo0WHLYRNtbSXihrjsNcECwb5VHAxbVYu2GI5XnNPmGQDrSH6ep4= X-Received: by 2002:a17:90b:4b01:: with SMTP id lx1mr4156681pjb.52.1643745771654; Tue, 01 Feb 2022 12:02:51 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: David Rowley Date: Wed, 2 Feb 2022 09:02:38 +1300 Message-ID: Subject: Re: Why is INSERT-driven autovacuuming based on pg_class.reltuples? To: Peter Geoghegan Cc: PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 31 Jan 2022 at 17:28, David Rowley wrote: > If ANALYZE runs and sets pg_class.reltuples to 1 million, then we > insert 500k tuples, assuming a 0 vacuum_ins_threshold and a > vacuum_ins_scale_factor of 0.2, then we'll want to perform a vacuum as > "vac_ins_base_thresh + vac_ins_scale_factor * reltuples" will come out > at 200k. auto-vacuum will then trigger and update reltuples hopefully > to some value around 1.5 million, then next time it'll take 300k > tuples to trigger an insert vacuum. If we wanted a more current estimate for the number of tuples in a relation then we could use reltuples / relpages * RelationGetNumberOfBlocks(r). However, I still don't see why an INSERT driven auto-vacuums are a particularly special case. ANALYZE updating the reltuples estimate had an effect on when auto-vacuum would trigger for tables that generally grow in the number of live tuples but previously only (i.e before insert vacuums existed) received auto-vacuum attention due to UPDATEs/DELETEs. I suppose the question is, what is autovacuum_vacuum_scale_factor meant to represent? Our documents claim: > Specifies a fraction of the table size to add to autovacuum_vacuum_thresh= old when deciding whether to trigger a VACUUM. The default is 0.2 (20% of t= able size). This parameter can only be set in the postgresql.conf file or o= n the server command line; but the setting can be overridden for individual= tables by changing table storage parameters. Nothing there seems to indicate the scale is based on the historical table size when the table was last vacuumed/analyzed, so you could claim that the 3 usages of relpages when deciding if the table should be vacuumed and/or analyzed are all wrong and should take into account RelationGetNumberOfBlocks too. I'm not planning on doing anything to change any of this unless I see some compelling argument that what's there is wrong. David