Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc584781

Browse files
Use pgBufferUsage for buffer usage tracking in analyze.
Previously, (auto)analyze used global variables VacuumPageHit,VacuumPageMiss, and VacuumPageDirty to track buffer usage. However,pgBufferUsage provides a more generic way to track buffer usage withsupport functions.This change replaces those global variables with pgBufferUsage inanalyze. Since analyze was the sole user of those variables, itremoves their declarations. Vacuum previously used those variables butreplaced them with pgBufferUsage as part of a bug fix, commit5cd72cc.Additionally, it adjusts the buffer usage message in both vacuum andanalyze for better consistency.Author: Anthonin BonnefoyReviewed-by: Masahiko Sawada, Michael PaquierDiscussion:https://postgr.es/m/CAO6_Xqr__kTTCLkftqS0qSCm-J7_xbRG3Ge2rWhucxQJMJhcRA%40mail.gmail.com
1 parent2488058 commitc584781

File tree

7 files changed

+38
-43
lines changed

7 files changed

+38
-43
lines changed

‎src/backend/access/heap/vacuumlazy.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -608,13 +608,23 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
608608
int32diff;
609609
doubleread_rate=0,
610610
write_rate=0;
611+
int64total_blks_hit;
612+
int64total_blks_read;
613+
int64total_blks_dirtied;
611614

612615
TimestampDifference(starttime,endtime,&secs_dur,&usecs_dur);
613616
memset(&walusage,0,sizeof(WalUsage));
614617
WalUsageAccumDiff(&walusage,&pgWalUsage,&startwalusage);
615618
memset(&bufferusage,0,sizeof(BufferUsage));
616619
BufferUsageAccumDiff(&bufferusage,&pgBufferUsage,&startbufferusage);
617620

621+
total_blks_hit=bufferusage.shared_blks_hit+
622+
bufferusage.local_blks_hit;
623+
total_blks_read=bufferusage.shared_blks_read+
624+
bufferusage.local_blks_read;
625+
total_blks_dirtied=bufferusage.shared_blks_dirtied+
626+
bufferusage.local_blks_dirtied;
627+
618628
initStringInfo(&buf);
619629
if (verbose)
620630
{
@@ -740,18 +750,18 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
740750
}
741751
if (secs_dur>0||usecs_dur>0)
742752
{
743-
read_rate= (double)BLCKSZ*(bufferusage.shared_blks_read+bufferusage.local_blks_read) /
753+
read_rate= (double)BLCKSZ*total_blks_read /
744754
(1024*1024) / (secs_dur+usecs_dur /1000000.0);
745-
write_rate= (double)BLCKSZ*(bufferusage.shared_blks_dirtied+bufferusage.local_blks_dirtied) /
755+
write_rate= (double)BLCKSZ*total_blks_dirtied /
746756
(1024*1024) / (secs_dur+usecs_dur /1000000.0);
747757
}
748758
appendStringInfo(&buf,_("avg read rate: %.3f MB/s, avg write rate: %.3f MB/s\n"),
749759
read_rate,write_rate);
750760
appendStringInfo(&buf,
751-
_("buffer usage: %lld hits, %lldmisses, %lld dirtied\n"),
752-
(long long)(bufferusage.shared_blks_hit+bufferusage.local_blks_hit),
753-
(long long)(bufferusage.shared_blks_read+bufferusage.local_blks_read),
754-
(long long)(bufferusage.shared_blks_dirtied+bufferusage.local_blks_dirtied));
761+
_("buffer usage: %lld hits, %lldreads, %lld dirtied\n"),
762+
(long long)total_blks_hit,
763+
(long long)total_blks_read,
764+
(long long)total_blks_dirtied);
755765
appendStringInfo(&buf,
756766
_("WAL usage: %lld records, %lld full page images, %llu bytes\n"),
757767
(long long)walusage.wal_records,

‎src/backend/commands/analyze.c

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,8 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
303303
Oidsave_userid;
304304
intsave_sec_context;
305305
intsave_nestlevel;
306-
int64AnalyzePageHit=VacuumPageHit;
307-
int64AnalyzePageMiss=VacuumPageMiss;
308-
int64AnalyzePageDirty=VacuumPageDirty;
306+
BufferUsagestartbufferusage=pgBufferUsage;
307+
BufferUsagebufferusage;
309308
PgStat_Counterstartreadtime=0;
310309
PgStat_Counterstartwritetime=0;
311310

@@ -736,15 +735,19 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
736735
doubleread_rate=0;
737736
doublewrite_rate=0;
738737
StringInfoDatabuf;
738+
int64total_blks_hit;
739+
int64total_blks_read;
740+
int64total_blks_dirtied;
739741

740-
/*
741-
* Calculate the difference in the Page Hit/Miss/Dirty that
742-
* happened as part of the analyze by subtracting out the
743-
* pre-analyze values which we saved above.
744-
*/
745-
AnalyzePageHit=VacuumPageHit-AnalyzePageHit;
746-
AnalyzePageMiss=VacuumPageMiss-AnalyzePageMiss;
747-
AnalyzePageDirty=VacuumPageDirty-AnalyzePageDirty;
742+
memset(&bufferusage,0,sizeof(BufferUsage));
743+
BufferUsageAccumDiff(&bufferusage,&pgBufferUsage,&startbufferusage);
744+
745+
total_blks_hit=bufferusage.shared_blks_hit+
746+
bufferusage.local_blks_hit;
747+
total_blks_read=bufferusage.shared_blks_read+
748+
bufferusage.local_blks_read;
749+
total_blks_dirtied=bufferusage.shared_blks_dirtied+
750+
bufferusage.local_blks_dirtied;
748751

749752
/*
750753
* We do not expect an analyze to take > 25 days and it simplifies
@@ -770,10 +773,10 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
770773

771774
if (delay_in_ms>0)
772775
{
773-
read_rate= (double)BLCKSZ*AnalyzePageMiss / (1024*1024) /
774-
(delay_in_ms /1000.0);
775-
write_rate= (double)BLCKSZ*AnalyzePageDirty / (1024*1024) /
776-
(delay_in_ms /1000.0);
776+
read_rate= (double)BLCKSZ*total_blks_read /
777+
(1024*1024) / (delay_in_ms /1000.0);
778+
write_rate= (double)BLCKSZ*total_blks_dirtied /
779+
(1024*1024) / (delay_in_ms /1000.0);
777780
}
778781

779782
/*
@@ -796,10 +799,10 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
796799
}
797800
appendStringInfo(&buf,_("avg read rate: %.3f MB/s, avg write rate: %.3f MB/s\n"),
798801
read_rate,write_rate);
799-
appendStringInfo(&buf,_("buffer usage: %lld hits, %lldmisses, %lld dirtied\n"),
800-
(long long)AnalyzePageHit,
801-
(long long)AnalyzePageMiss,
802-
(long long)AnalyzePageDirty);
802+
appendStringInfo(&buf,_("buffer usage: %lld hits, %lldreads, %lld dirtied\n"),
803+
(long long)total_blks_hit,
804+
(long long)total_blks_read,
805+
(long long)total_blks_dirtied);
803806
appendStringInfo(&buf,_("system usage: %s"),pg_rusage_show(&ru0));
804807

805808
ereport(LOG,

‎src/backend/commands/vacuum.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,6 @@ vacuum(List *relations, VacuumParams *params, BufferAccessStrategy bstrategy,
603603
VacuumFailsafeActive= false;
604604
VacuumUpdateCosts();
605605
VacuumCostBalance=0;
606-
VacuumPageHit=0;
607-
VacuumPageMiss=0;
608-
VacuumPageDirty=0;
609606
VacuumCostBalanceLocal=0;
610607
VacuumSharedCostBalance=NULL;
611608
VacuumActiveNWorkers=NULL;

‎src/backend/commands/vacuumparallel.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,9 +1043,6 @@ parallel_vacuum_main(dsm_segment *seg, shm_toc *toc)
10431043
/* Set cost-based vacuum delay */
10441044
VacuumUpdateCosts();
10451045
VacuumCostBalance=0;
1046-
VacuumPageHit=0;
1047-
VacuumPageMiss=0;
1048-
VacuumPageDirty=0;
10491046
VacuumCostBalanceLocal=0;
10501047
VacuumSharedCostBalance=&(shared->cost_balance);
10511048
VacuumActiveNWorkers=&(shared->active_nworkers);

‎src/backend/storage/buffer/bufmgr.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,6 @@ PinBufferForBlock(Relation rel,
11921192
}
11931193
if (*foundPtr)
11941194
{
1195-
VacuumPageHit++;
11961195
pgstat_count_io_op(io_object,io_context,IOOP_HIT);
11971196
if (VacuumCostActive)
11981197
VacuumCostBalance+=VacuumCostPageHit;
@@ -1588,7 +1587,6 @@ WaitReadBuffers(ReadBuffersOperation *operation)
15881587
false);
15891588
}
15901589

1591-
VacuumPageMiss+=io_buffers_len;
15921590
if (VacuumCostActive)
15931591
VacuumCostBalance+=VacuumCostPageMiss*io_buffers_len;
15941592
}
@@ -2582,7 +2580,6 @@ MarkBufferDirty(Buffer buffer)
25822580
*/
25832581
if (!(old_buf_state&BM_DIRTY))
25842582
{
2585-
VacuumPageDirty++;
25862583
pgBufferUsage.shared_blks_dirtied++;
25872584
if (VacuumCostActive)
25882585
VacuumCostBalance+=VacuumCostPageDirty;
@@ -5122,7 +5119,6 @@ MarkBufferDirtyHint(Buffer buffer, bool buffer_std)
51225119

51235120
if (dirtied)
51245121
{
5125-
VacuumPageDirty++;
51265122
pgBufferUsage.shared_blks_dirtied++;
51275123
if (VacuumCostActive)
51285124
VacuumCostBalance+=VacuumCostPageDirty;

‎src/backend/utils/init/globals.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,6 @@ intVacuumCostPageDirty = 20;
153153
intVacuumCostLimit=200;
154154
doubleVacuumCostDelay=0;
155155

156-
int64VacuumPageHit=0;
157-
int64VacuumPageMiss=0;
158-
int64VacuumPageDirty=0;
159-
160156
intVacuumCostBalance=0;/* working state for vacuum */
161157
boolVacuumCostActive= false;
162158

‎src/include/miscadmin.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,6 @@ extern PGDLLIMPORT int VacuumCostPageDirty;
284284
externPGDLLIMPORTintVacuumCostLimit;
285285
externPGDLLIMPORTdoubleVacuumCostDelay;
286286

287-
externPGDLLIMPORTint64VacuumPageHit;
288-
externPGDLLIMPORTint64VacuumPageMiss;
289-
externPGDLLIMPORTint64VacuumPageDirty;
290-
291287
externPGDLLIMPORTintVacuumCostBalance;
292288
externPGDLLIMPORTboolVacuumCostActive;
293289

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp