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 1ixdO5-0006YQ-Ml for pgsql-hackers@arkaria.postgresql.org; Fri, 31 Jan 2020 20:59:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ixdO3-0001ce-3E for pgsql-hackers@arkaria.postgresql.org; Fri, 31 Jan 2020 20:59:35 +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 1ixdO2-0001cW-Li for pgsql-hackers@lists.postgresql.org; Fri, 31 Jan 2020 20:59:34 +0000 Received: from mail-qt1-x843.google.com ([2607:f8b0:4864:20::843]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ixdNz-0007bf-FS for pgsql-hackers@lists.postgresql.org; Fri, 31 Jan 2020 20:59:33 +0000 Received: by mail-qt1-x843.google.com with SMTP id n17so5360317qtv.2 for ; Fri, 31 Jan 2020 12:59:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:subject:message-id:mime-version:content-disposition :content-transfer-encoding:user-agent; bh=A3RdcyQJAt/dRFq/qd7wsXdwp43m1kS+42FocwxxY+8=; b=vDzFxTUihU8tGd5E0kIFLBvS9JL/mNXAydi1k+/BUBPEJmkcewlgxmN8m98qQpzHTI Y//cYgFXHvkhQ+JcEf4KtO3FRibPzaZZM0UCnVJOfCImsIz2yGmE8BAewXKXvOwA3Zqb XlCUByendIiF5G0k3PoUzYgeu+F1GPevxfBDpT6KpEU6hwWvvyjYUhcY8/RRjcZbX9Ix 9TYy3DgWfgn1I3QuJA29QkBBKawrpT+ajxtfxRu4tCgErY/FkUAO+zamOGhdtMvy085Q H3iqtFOhBibfJjV49i1X8lg0rEKRflmNto+raDwlWK96WwXV91BQv7xVrPWP+BmP4SHE vAwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:content-transfer-encoding:user-agent; bh=A3RdcyQJAt/dRFq/qd7wsXdwp43m1kS+42FocwxxY+8=; b=h1sSUDa9jJ/FMY2VmiMzjRibeTUS7G9+pSgIpHxz3Bfq91Ydn3kz8RpHq2xt7Wjnpb 9iK/7SVF7jB5bSlo2w4QcLXBEsvWC8exNnIy58kCyhnGnJZujsHQ3tiXax9MKVInSytK SmabHChiTZ5oL69c02FAWceI4x0Yl5uVwj8GJmkrANTz9Ju1y7F3w4swQ+7bGLvc1Z3x 5j0xULxZnhhe0uiuFf8G7BvxLd65t3Ns4XZGsq2DcZAgUCbZ7YndRPFZOY7CWGKbD+cE VgxOETT4u2Eda3TV4WC2zJ0z4v0nRWFtuRixu/gLnMYIyY/WyP3Z2DiwHjwu1B9HWnZR mS1g== X-Gm-Message-State: APjAAAWtPhlwdht3IMOjdSfgzcfiQXig2Sd6t5yWJn8NTQHo1NabHKfR L2qWeQajdIxw7bdEUuWVRnbUADwAy74THmDKZqAdTfRdv5256p+wgarEmGw/EvlnhLTE2gG+zx6 HtjCyr12vQ6TZlu8KRwA0esnlStzjx6d4gpNWvh5TaTMHwGxvf4tQfdF8T/pjxrgM1higPRFqJv jzFwhR+Q/uqQ53cA== X-Google-Smtp-Source: APXvYqwUVHbA3xBi0btSAYxVXJVrrYqPzn3nzajddIgGrZCkUnuJ2O2lxUBcrAzQCOJ+rtSSzc4WbQ== X-Received: by 2002:ac8:4e3c:: with SMTP id d28mr8605618qtw.190.1580504369357; Fri, 31 Jan 2020 12:59:29 -0800 (PST) Received: from nimloth.alvh.no-ip.org ([179.56.30.174]) by smtp.gmail.com with ESMTPSA id m27sm5781929qta.21.2020.01.31.12.59.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 12:59:28 -0800 (PST) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 2D03B300A44; Fri, 31 Jan 2020 17:59:26 -0300 (-03) Date: Fri, 31 Jan 2020 17:59:26 -0300 From: Alvaro Herrera To: Pg Hackers Subject: widen vacuum buffer counters Message-ID: <20200131205926.GA16367@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="UugvWAfsgieZRqgk" Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --UugvWAfsgieZRqgk Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit We recently noticed that vacuum buffer counters wraparound in extreme cases, with ridiculous results. Example: 2020-01-06 16:38:38.010 EST [45625-1] app= LOG: automatic vacuum of table "somtab.sf.foobar": index scans: 17 pages: 0 removed, 207650641 remain, 0 skipped due to pins, 13419403 skipped frozen tuples: 141265419 removed, 3186614627 remain, 87783760 are dead but not yet removable buffer usage: -2022059267 hits, -17141881 misses, 1252507767 dirtied avg read rate: -0.043 MB/s, avg write rate: 3.146 MB/s system usage: CPU 107819.92s/2932957.75u sec elapsed 3110498.10 sec That's to be expected, as tables exist that are large enough for 4 billion buffer accesses to be a possibility. Let's widen the counters, as in the attached patch. I propose to backpatch this. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --UugvWAfsgieZRqgk Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="widen-vacuum-counts.patch" diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c index 8ce501151e..049ec2703b 100644 --- a/src/backend/access/heap/vacuumlazy.c +++ b/src/backend/access/heap/vacuumlazy.c @@ -614,7 +614,7 @@ heap_vacuum_rel(Relation onerel, VacuumParams *params, vacrelstats->new_dead_tuples, OldestXmin); appendStringInfo(&buf, - _("buffer usage: %d hits, %d misses, %d dirtied\n"), + _("buffer usage: %zd hits, %zd misses, %zd dirtied\n"), VacuumPageHit, VacuumPageMiss, VacuumPageDirty); diff --git a/src/backend/utils/init/globals.c b/src/backend/utils/init/globals.c index b1f6291b99..eb19644419 100644 --- a/src/backend/utils/init/globals.c +++ b/src/backend/utils/init/globals.c @@ -140,9 +140,9 @@ int VacuumCostPageDirty = 20; int VacuumCostLimit = 200; double VacuumCostDelay = 0; -int VacuumPageHit = 0; -int VacuumPageMiss = 0; -int VacuumPageDirty = 0; +int64 VacuumPageHit = 0; +int64 VacuumPageMiss = 0; +int64 VacuumPageDirty = 0; int VacuumCostBalance = 0; /* working state for vacuum */ bool VacuumCostActive = false; diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h index 62d64aa0a1..f985453ec3 100644 --- a/src/include/miscadmin.h +++ b/src/include/miscadmin.h @@ -252,9 +252,9 @@ extern int VacuumCostPageDirty; extern int VacuumCostLimit; extern double VacuumCostDelay; -extern int VacuumPageHit; -extern int VacuumPageMiss; -extern int VacuumPageDirty; +extern int64 VacuumPageHit; +extern int64 VacuumPageMiss; +extern int64 VacuumPageDirty; extern int VacuumCostBalance; extern bool VacuumCostActive; --UugvWAfsgieZRqgk--