]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Change data type of counters in BufferUsage and WalUsage from long to int64.
authorFujii Masao <fujii@postgresql.org>
Wed, 12 May 2021 00:56:34 +0000 (09:56 +0900)
committerFujii Masao <fujii@postgresql.org>
Wed, 12 May 2021 00:56:34 +0000 (09:56 +0900)
Previously long was used as the data type for some counters in BufferUsage
and WalUsage. But long is only four byte, e.g., on Windows, and it's entirely
possible to wrap a four byte counter. For example, emitting more than
four billion WAL records in one transaction isn't actually particularly rare.

To avoid the overflows of those counters, this commit changes the data type
of them from long to int64.

Suggested-by: Andres Freund
Author: Masahiro Ikeda
Reviewed-by: Fujii Masao
Discussion: https://postgr.es/m/20201221211650.k7b53tcnadrciqjo@alap3.anarazel.de
Discussion: https://postgr.es/m/af0964ac-7080-1984-dc23-513754987716@oss.nttdata.com

src/backend/access/heap/vacuumlazy.c
src/backend/commands/explain.c
src/include/executor/instrument.h

index 47ac6385d12120ff545655254712591ac2431e0a..4b4db4c81b5e6bce98f0dec1b2f8ea42e3f6f796 100644 (file)
@@ -830,9 +830,9 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
                        }
                        appendStringInfo(&buf, _("system usage: %s\n"), pg_rusage_show(&ru0));
                        appendStringInfo(&buf,
-                                                        _("WAL usage: %ld records, %ld full page images, %llu bytes"),
-                                                        walusage.wal_records,
-                                                        walusage.wal_fpi,
+                                                        _("WAL usage: %lld records, %lld full page images, %llu bytes"),
+                                                        (long long) walusage.wal_records,
+                                                        (long long) walusage.wal_fpi,
                                                         (unsigned long long) walusage.wal_bytes);
 
                        ereport(LOG,
index 8ab7bca866b04f9ba12291e3779e5f50c2cb8b45..9867da83bca0d6e6fffeaa2164e980941abfdcc1 100644 (file)
@@ -3526,17 +3526,17 @@ show_buffer_usage(ExplainState *es, const BufferUsage *usage, bool planning)
                        {
                                appendStringInfoString(es->str, " shared");
                                if (usage->shared_blks_hit > 0)
-                                       appendStringInfo(es->str, " hit=%ld",
-                                                                        usage->shared_blks_hit);
+                                       appendStringInfo(es->str, " hit=%lld",
+                                                                        (long long) usage->shared_blks_hit);
                                if (usage->shared_blks_read > 0)
-                                       appendStringInfo(es->str, " read=%ld",
-                                                                        usage->shared_blks_read);
+                                       appendStringInfo(es->str, " read=%lld",
+                                                                        (long long) usage->shared_blks_read);
                                if (usage->shared_blks_dirtied > 0)
-                                       appendStringInfo(es->str, " dirtied=%ld",
-                                                                        usage->shared_blks_dirtied);
+                                       appendStringInfo(es->str, " dirtied=%lld",
+                                                                        (long long) usage->shared_blks_dirtied);
                                if (usage->shared_blks_written > 0)
-                                       appendStringInfo(es->str, " written=%ld",
-                                                                        usage->shared_blks_written);
+                                       appendStringInfo(es->str, " written=%lld",
+                                                                        (long long) usage->shared_blks_written);
                                if (has_local || has_temp)
                                        appendStringInfoChar(es->str, ',');
                        }
@@ -3544,17 +3544,17 @@ show_buffer_usage(ExplainState *es, const BufferUsage *usage, bool planning)
                        {
                                appendStringInfoString(es->str, " local");
                                if (usage->local_blks_hit > 0)
-                                       appendStringInfo(es->str, " hit=%ld",
-                                                                        usage->local_blks_hit);
+                                       appendStringInfo(es->str, " hit=%lld",
+                                                                        (long long) usage->local_blks_hit);
                                if (usage->local_blks_read > 0)
-                                       appendStringInfo(es->str, " read=%ld",
-                                                                        usage->local_blks_read);
+                                       appendStringInfo(es->str, " read=%lld",
+                                                                        (long long) usage->local_blks_read);
                                if (usage->local_blks_dirtied > 0)
-                                       appendStringInfo(es->str, " dirtied=%ld",
-                                                                        usage->local_blks_dirtied);
+                                       appendStringInfo(es->str, " dirtied=%lld",
+                                                                        (long long) usage->local_blks_dirtied);
                                if (usage->local_blks_written > 0)
-                                       appendStringInfo(es->str, " written=%ld",
-                                                                        usage->local_blks_written);
+                                       appendStringInfo(es->str, " written=%lld",
+                                                                        (long long) usage->local_blks_written);
                                if (has_temp)
                                        appendStringInfoChar(es->str, ',');
                        }
@@ -3562,11 +3562,11 @@ show_buffer_usage(ExplainState *es, const BufferUsage *usage, bool planning)
                        {
                                appendStringInfoString(es->str, " temp");
                                if (usage->temp_blks_read > 0)
-                                       appendStringInfo(es->str, " read=%ld",
-                                                                        usage->temp_blks_read);
+                                       appendStringInfo(es->str, " read=%lld",
+                                                                        (long long) usage->temp_blks_read);
                                if (usage->temp_blks_written > 0)
-                                       appendStringInfo(es->str, " written=%ld",
-                                                                        usage->temp_blks_written);
+                                       appendStringInfo(es->str, " written=%lld",
+                                                                        (long long) usage->temp_blks_written);
                        }
                        appendStringInfoChar(es->str, '\n');
                }
@@ -3638,11 +3638,11 @@ show_wal_usage(ExplainState *es, const WalUsage *usage)
                        appendStringInfoString(es->str, "WAL:");
 
                        if (usage->wal_records > 0)
-                               appendStringInfo(es->str, " records=%ld",
-                                                                usage->wal_records);
+                               appendStringInfo(es->str, " records=%lld",
+                                                                (long long) usage->wal_records);
                        if (usage->wal_fpi > 0)
-                               appendStringInfo(es->str, " fpi=%ld",
-                                                                usage->wal_fpi);
+                               appendStringInfo(es->str, " fpi=%lld",
+                                                                (long long) usage->wal_fpi);
                        if (usage->wal_bytes > 0)
                                appendStringInfo(es->str, " bytes=" UINT64_FORMAT,
                                                                 usage->wal_bytes);
index aa8eceda5f411aac88cde1c559435e35021fa442..c25aa1b04c2c27da6fd7303fbedd36764ae061c8 100644 (file)
 
 typedef struct BufferUsage
 {
-       long            shared_blks_hit;        /* # of shared buffer hits */
-       long            shared_blks_read;       /* # of shared disk blocks read */
-       long            shared_blks_dirtied;    /* # of shared blocks dirtied */
-       long            shared_blks_written;    /* # of shared disk blocks written */
-       long            local_blks_hit; /* # of local buffer hits */
-       long            local_blks_read;        /* # of local disk blocks read */
-       long            local_blks_dirtied; /* # of local blocks dirtied */
-       long            local_blks_written; /* # of local disk blocks written */
-       long            temp_blks_read; /* # of temp blocks read */
-       long            temp_blks_written;      /* # of temp blocks written */
+       int64           shared_blks_hit;        /* # of shared buffer hits */
+       int64           shared_blks_read;       /* # of shared disk blocks read */
+       int64           shared_blks_dirtied;    /* # of shared blocks dirtied */
+       int64           shared_blks_written;    /* # of shared disk blocks written */
+       int64           local_blks_hit; /* # of local buffer hits */
+       int64           local_blks_read;        /* # of local disk blocks read */
+       int64           local_blks_dirtied; /* # of local blocks dirtied */
+       int64           local_blks_written; /* # of local disk blocks written */
+       int64           temp_blks_read; /* # of temp blocks read */
+       int64           temp_blks_written;      /* # of temp blocks written */
        instr_time      blk_read_time;  /* time spent reading */
        instr_time      blk_write_time; /* time spent writing */
 } BufferUsage;
 
 typedef struct WalUsage
 {
-       long            wal_records;    /* # of WAL records produced */
-       long            wal_fpi;                /* # of WAL full page images produced */
+       int64           wal_records;    /* # of WAL records produced */
+       int64           wal_fpi;                /* # of WAL full page images produced */
        uint64          wal_bytes;              /* size of WAL records produced */
 } WalUsage;