Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d780d7c

Browse files
committed
Change data type of counters in BufferUsage and WalUsage from long to int64.
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
1 parent 0bf6293 commit d780d7c

File tree

3 files changed

+39
-39
lines changed

3 files changed

+39
-39
lines changed

src/backend/access/heap/vacuumlazy.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -830,9 +830,9 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
830830
}
831831
appendStringInfo(&buf, _("system usage: %s\n"), pg_rusage_show(&ru0));
832832
appendStringInfo(&buf,
833-
_("WAL usage: %ld records, %ld full page images, %llu bytes"),
834-
walusage.wal_records,
835-
walusage.wal_fpi,
833+
_("WAL usage: %lld records, %lld full page images, %llu bytes"),
834+
(long long) walusage.wal_records,
835+
(long long) walusage.wal_fpi,
836836
(unsigned long long) walusage.wal_bytes);
837837

838838
ereport(LOG,

src/backend/commands/explain.c

+24-24
Original file line numberDiff line numberDiff line change
@@ -3526,47 +3526,47 @@ show_buffer_usage(ExplainState *es, const BufferUsage *usage, bool planning)
35263526
{
35273527
appendStringInfoString(es->str, " shared");
35283528
if (usage->shared_blks_hit > 0)
3529-
appendStringInfo(es->str, " hit=%ld",
3530-
usage->shared_blks_hit);
3529+
appendStringInfo(es->str, " hit=%lld",
3530+
(long long) usage->shared_blks_hit);
35313531
if (usage->shared_blks_read > 0)
3532-
appendStringInfo(es->str, " read=%ld",
3533-
usage->shared_blks_read);
3532+
appendStringInfo(es->str, " read=%lld",
3533+
(long long) usage->shared_blks_read);
35343534
if (usage->shared_blks_dirtied > 0)
3535-
appendStringInfo(es->str, " dirtied=%ld",
3536-
usage->shared_blks_dirtied);
3535+
appendStringInfo(es->str, " dirtied=%lld",
3536+
(long long) usage->shared_blks_dirtied);
35373537
if (usage->shared_blks_written > 0)
3538-
appendStringInfo(es->str, " written=%ld",
3539-
usage->shared_blks_written);
3538+
appendStringInfo(es->str, " written=%lld",
3539+
(long long) usage->shared_blks_written);
35403540
if (has_local || has_temp)
35413541
appendStringInfoChar(es->str, ',');
35423542
}
35433543
if (has_local)
35443544
{
35453545
appendStringInfoString(es->str, " local");
35463546
if (usage->local_blks_hit > 0)
3547-
appendStringInfo(es->str, " hit=%ld",
3548-
usage->local_blks_hit);
3547+
appendStringInfo(es->str, " hit=%lld",
3548+
(long long) usage->local_blks_hit);
35493549
if (usage->local_blks_read > 0)
3550-
appendStringInfo(es->str, " read=%ld",
3551-
usage->local_blks_read);
3550+
appendStringInfo(es->str, " read=%lld",
3551+
(long long) usage->local_blks_read);
35523552
if (usage->local_blks_dirtied > 0)
3553-
appendStringInfo(es->str, " dirtied=%ld",
3554-
usage->local_blks_dirtied);
3553+
appendStringInfo(es->str, " dirtied=%lld",
3554+
(long long) usage->local_blks_dirtied);
35553555
if (usage->local_blks_written > 0)
3556-
appendStringInfo(es->str, " written=%ld",
3557-
usage->local_blks_written);
3556+
appendStringInfo(es->str, " written=%lld",
3557+
(long long) usage->local_blks_written);
35583558
if (has_temp)
35593559
appendStringInfoChar(es->str, ',');
35603560
}
35613561
if (has_temp)
35623562
{
35633563
appendStringInfoString(es->str, " temp");
35643564
if (usage->temp_blks_read > 0)
3565-
appendStringInfo(es->str, " read=%ld",
3566-
usage->temp_blks_read);
3565+
appendStringInfo(es->str, " read=%lld",
3566+
(long long) usage->temp_blks_read);
35673567
if (usage->temp_blks_written > 0)
3568-
appendStringInfo(es->str, " written=%ld",
3569-
usage->temp_blks_written);
3568+
appendStringInfo(es->str, " written=%lld",
3569+
(long long) usage->temp_blks_written);
35703570
}
35713571
appendStringInfoChar(es->str, '\n');
35723572
}
@@ -3638,11 +3638,11 @@ show_wal_usage(ExplainState *es, const WalUsage *usage)
36383638
appendStringInfoString(es->str, "WAL:");
36393639

36403640
if (usage->wal_records > 0)
3641-
appendStringInfo(es->str, " records=%ld",
3642-
usage->wal_records);
3641+
appendStringInfo(es->str, " records=%lld",
3642+
(long long) usage->wal_records);
36433643
if (usage->wal_fpi > 0)
3644-
appendStringInfo(es->str, " fpi=%ld",
3645-
usage->wal_fpi);
3644+
appendStringInfo(es->str, " fpi=%lld",
3645+
(long long) usage->wal_fpi);
36463646
if (usage->wal_bytes > 0)
36473647
appendStringInfo(es->str, " bytes=" UINT64_FORMAT,
36483648
usage->wal_bytes);

src/include/executor/instrument.h

+12-12
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@
1818

1919
typedef struct BufferUsage
2020
{
21-
long shared_blks_hit; /* # of shared buffer hits */
22-
long shared_blks_read; /* # of shared disk blocks read */
23-
long shared_blks_dirtied; /* # of shared blocks dirtied */
24-
long shared_blks_written; /* # of shared disk blocks written */
25-
long local_blks_hit; /* # of local buffer hits */
26-
long local_blks_read; /* # of local disk blocks read */
27-
long local_blks_dirtied; /* # of local blocks dirtied */
28-
long local_blks_written; /* # of local disk blocks written */
29-
long temp_blks_read; /* # of temp blocks read */
30-
long temp_blks_written; /* # of temp blocks written */
21+
int64 shared_blks_hit; /* # of shared buffer hits */
22+
int64 shared_blks_read; /* # of shared disk blocks read */
23+
int64 shared_blks_dirtied; /* # of shared blocks dirtied */
24+
int64 shared_blks_written; /* # of shared disk blocks written */
25+
int64 local_blks_hit; /* # of local buffer hits */
26+
int64 local_blks_read; /* # of local disk blocks read */
27+
int64 local_blks_dirtied; /* # of local blocks dirtied */
28+
int64 local_blks_written; /* # of local disk blocks written */
29+
int64 temp_blks_read; /* # of temp blocks read */
30+
int64 temp_blks_written; /* # of temp blocks written */
3131
instr_time blk_read_time; /* time spent reading */
3232
instr_time blk_write_time; /* time spent writing */
3333
} BufferUsage;
3434

3535
typedef struct WalUsage
3636
{
37-
long wal_records; /* # of WAL records produced */
38-
long wal_fpi; /* # of WAL full page images produced */
37+
int64 wal_records; /* # of WAL records produced */
38+
int64 wal_fpi; /* # of WAL full page images produced */
3939
uint64 wal_bytes; /* size of WAL records produced */
4040
} WalUsage;
4141

0 commit comments

Comments
 (0)