pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
widen vacuum buffer counters
6+ messages / 4 participants
[nested] [flat]

Commits from this thread:
  2020-02-05 15d13e8291  Make vacuum buffer counters 64 bits wide
* widen vacuum buffer counters
@ 2020-01-31 20:59 Alvaro Herrera <alvherre@2ndquadrant.com>
  2020-01-31 21:10 ` Re: widen vacuum buffer counters Julien Rouhaud <rjuju123@gmail.com>
  2020-01-31 22:13 ` Re: widen vacuum buffer counters Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 2 replies; 6+ messages in thread

From: Alvaro Herrera @ 2020-01-31 20:59 UTC (permalink / raw)
  To: Pg Hackers <pgsql-hackers@lists.postgresql.org>

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

Attachments:

widen-vacuum-counts.patch (text/x-diff, 1.6K) download 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;
^ permalink raw reply [nested|flat] 6+ messages in thread

* Re: widen vacuum buffer counters
  2020-01-31 20:59 widen vacuum buffer counters Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2020-01-31 21:10 ` Julien Rouhaud <rjuju123@gmail.com>
  1 sibling, 0 replies; 6+ messages in thread

From: Julien Rouhaud @ 2020-01-31 21:10 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: Pg Hackers <pgsql-hackers@lists.postgresql.org>

On Fri, Jan 31, 2020 at 9:59 PM Alvaro Herrera <alvherre@2ndquadrant.com> wrote:
>
> 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.

+1, and patch LGTM.





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: widen vacuum buffer counters
  2020-01-31 20:59 widen vacuum buffer counters Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2020-01-31 22:13 ` Tom Lane <tgl@sss.pgh.pa.us>
  2020-02-01 09:52   ` Re: widen vacuum buffer counters Michael Paquier <michael@paquier.xyz>
  2020-02-05 20:18   ` Re: widen vacuum buffer counters Alvaro Herrera <alvherre@2ndquadrant.com>
  1 sibling, 2 replies; 6+ messages in thread

From: Tom Lane @ 2020-01-31 22:13 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: Pg Hackers <pgsql-hackers@lists.postgresql.org>

Alvaro Herrera <alvherre@2ndquadrant.com> writes:
> We recently noticed that vacuum buffer counters wraparound in extreme
> cases, with ridiculous results.

Ugh.

> I propose to backpatch this.

+1 for widening these counters, but since they're global variables, -0.2
or so for back-patching.  I don't know of any reason that an extension
would be touching these, but I feel like the problem isn't severe enough
to justify taking an ABI-break risk.

Also, %zd is the wrong format code for int64.  Recommended practice
these days is to use "%lld" with an explicit cast of the printf argument
to long long (just to be sure).  That doesn't work safely before v12,
and if you did insist on back-patching further, you'd need to jump
through hoops to avoid having platform-specific format codes in a
translatable string.  (The side-effects for translation seem like
an independent argument against back-patching.)

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: widen vacuum buffer counters
  2020-01-31 20:59 widen vacuum buffer counters Alvaro Herrera <alvherre@2ndquadrant.com>
  2020-01-31 22:13 ` Re: widen vacuum buffer counters Tom Lane <tgl@sss.pgh.pa.us>
@ 2020-02-01 09:52   ` Michael Paquier <michael@paquier.xyz>
  2020-02-01 15:26     ` Re: widen vacuum buffer counters Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 1 reply; 6+ messages in thread

From: Michael Paquier @ 2020-02-01 09:52 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Alvaro Herrera <alvherre@2ndquadrant.com>; Pg Hackers <pgsql-hackers@lists.postgresql.org>

On Fri, Jan 31, 2020 at 05:13:53PM -0500, Tom Lane wrote:
> +1 for widening these counters, but since they're global variables, -0.2
> or so for back-patching.  I don't know of any reason that an extension
> would be touching these, but I feel like the problem isn't severe enough
> to justify taking an ABI-break risk.

I would not recommend doing a back-patch because of that.  I don't
think that's worth taking any risk.  Extension authors can have a lot
of imagination.

> Also, %zd is the wrong format code for int64.  Recommended practice
> these days is to use "%lld" with an explicit cast of the printf argument
> to long long (just to be sure).  That doesn't work safely before v12,
> and if you did insist on back-patching further, you'd need to jump
> through hoops to avoid having platform-specific format codes in a
> translatable string.  (The side-effects for translation seem like
> an independent argument against back-patching.)

Surely you meant INT64_FORMAT here?  Anyway, looking at the patch,
couldn't we just use uint64?
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: widen vacuum buffer counters
  2020-01-31 20:59 widen vacuum buffer counters Alvaro Herrera <alvherre@2ndquadrant.com>
  2020-01-31 22:13 ` Re: widen vacuum buffer counters Tom Lane <tgl@sss.pgh.pa.us>
  2020-02-01 09:52   ` Re: widen vacuum buffer counters Michael Paquier <michael@paquier.xyz>
@ 2020-02-01 15:26     ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 2020-02-01 15:26 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: Alvaro Herrera <alvherre@2ndquadrant.com>; Pg Hackers <pgsql-hackers@lists.postgresql.org>

Michael Paquier <michael@paquier.xyz> writes:
> On Fri, Jan 31, 2020 at 05:13:53PM -0500, Tom Lane wrote:
>> Also, %zd is the wrong format code for int64.  Recommended practice
>> these days is to use "%lld" with an explicit cast of the printf argument
>> to long long (just to be sure).  That doesn't work safely before v12,
>> and if you did insist on back-patching further, you'd need to jump
>> through hoops to avoid having platform-specific format codes in a
>> translatable string.  (The side-effects for translation seem like
>> an independent argument against back-patching.)

> Surely you meant INT64_FORMAT here?

No, because that varies depending on platform, so using it in a
translatable string is a bad idea.  See e.g. 6a1cd8b92.

> Anyway, looking at the patch,
> couldn't we just use uint64?

Yeah, I was wondering if those counters shouldn't be unsigned, too.
Probably doesn't matter once we widen them to 64 bits though.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: widen vacuum buffer counters
  2020-01-31 20:59 widen vacuum buffer counters Alvaro Herrera <alvherre@2ndquadrant.com>
  2020-01-31 22:13 ` Re: widen vacuum buffer counters Tom Lane <tgl@sss.pgh.pa.us>
@ 2020-02-05 20:18   ` Alvaro Herrera <alvherre@2ndquadrant.com>
  1 sibling, 0 replies; 6+ messages in thread

From: Alvaro Herrera @ 2020-02-05 20:18 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Pg Hackers <pgsql-hackers@lists.postgresql.org>

On 2020-Jan-31, Tom Lane wrote:

> Also, %zd is the wrong format code for int64.  Recommended practice
> these days is to use "%lld" with an explicit cast of the printf argument
> to long long (just to be sure).  That doesn't work safely before v12,
> and if you did insist on back-patching further, you'd need to jump
> through hoops to avoid having platform-specific format codes in a
> translatable string.  (The side-effects for translation seem like
> an independent argument against back-patching.)

Pushed with that change; did not backpatch, because I don't think it's
really worth the possible breakage :-)

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services





^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2020-02-05 20:18 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-01-31 20:59 widen vacuum buffer counters Alvaro Herrera <alvherre@2ndquadrant.com>
2020-01-31 21:10 ` Julien Rouhaud <rjuju123@gmail.com>
2020-01-31 22:13 ` Tom Lane <tgl@sss.pgh.pa.us>
2020-02-01 09:52   ` Michael Paquier <michael@paquier.xyz>
2020-02-01 15:26     ` Tom Lane <tgl@sss.pgh.pa.us>
2020-02-05 20:18   ` Alvaro Herrera <alvherre@2ndquadrant.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox