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

Commit115f414

Browse files
committed
Fix VACUUM's reporting of dead-tuple counts to the stats collector.
Historically, VACUUM has just reported its new_rel_tuples estimate(the same thing it puts into pg_class.reltuples) to the stats collector.That number counts both live and dead-but-not-yet-reclaimable tuples.This behavior may once have been right, but modern versions of thepgstats code track live and dead tuple counts separately, so puttingthe total into n_live_tuples and zero into n_dead_tuples is surelypretty bogus. Fix it to report live and dead tuple counts separately.This doesn't really do much for situations where updating transactionscommit concurrently with a VACUUM scan (possibly causing double-counting oromission of the tuples they add or delete); but it's clearly an improvementover what we were doing before.Hari Babu, reviewed by Amit Kapila
1 parent76e91b3 commit115f414

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

‎src/backend/commands/vacuumlazy.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ typedef struct LVRelStats
106106
doublescanned_tuples;/* counts only tuples on scanned pages */
107107
doubleold_rel_tuples;/* previous value of pg_class.reltuples */
108108
doublenew_rel_tuples;/* new estimated total # of tuples */
109+
doublenew_dead_tuples;/* new estimated total # of dead tuples */
109110
BlockNumberpages_removed;
110111
doubletuples_deleted;
111112
BlockNumbernonempty_pages;/* actually, last nonempty page + 1 */
@@ -185,6 +186,7 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
185186
BlockNumbernew_rel_pages;
186187
doublenew_rel_tuples;
187188
BlockNumbernew_rel_allvisible;
189+
doublenew_live_tuples;
188190
TransactionIdnew_frozen_xid;
189191
MultiXactIdnew_min_multi;
190192

@@ -307,9 +309,14 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
307309
new_min_multi);
308310

309311
/* report results to the stats collector, too */
312+
new_live_tuples=new_rel_tuples-vacrelstats->new_dead_tuples;
313+
if (new_live_tuples<0)
314+
new_live_tuples=0;/* just in case */
315+
310316
pgstat_report_vacuum(RelationGetRelid(onerel),
311317
onerel->rd_rel->relisshared,
312-
new_rel_tuples);
318+
new_live_tuples,
319+
vacrelstats->new_dead_tuples);
313320

314321
/* and log the action if appropriate */
315322
if (IsAutoVacuumWorkerProcess()&&Log_autovacuum_min_duration >=0)
@@ -334,7 +341,7 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
334341
ereport(LOG,
335342
(errmsg("automatic vacuum of table \"%s.%s.%s\": index scans: %d\n"
336343
"pages: %d removed, %d remain\n"
337-
"tuples: %.0f removed, %.0f remain\n"
344+
"tuples: %.0f removed, %.0f remain, %.0f are dead but not yet removable\n"
338345
"buffer usage: %d hits, %d misses, %d dirtied\n"
339346
"avg read rate: %.3f MB/s, avg write rate: %.3f MB/s\n"
340347
"system usage: %s",
@@ -346,6 +353,7 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
346353
vacrelstats->rel_pages,
347354
vacrelstats->tuples_deleted,
348355
vacrelstats->new_rel_tuples,
356+
vacrelstats->new_dead_tuples,
349357
VacuumPageHit,
350358
VacuumPageMiss,
351359
VacuumPageDirty,
@@ -1036,6 +1044,7 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
10361044
/* save stats for use later */
10371045
vacrelstats->scanned_tuples=num_tuples;
10381046
vacrelstats->tuples_deleted=tups_vacuumed;
1047+
vacrelstats->new_dead_tuples=nkeep;
10391048

10401049
/* now we can compute the new value for pg_class.reltuples */
10411050
vacrelstats->new_rel_tuples=vac_estimate_reltuples(onerel, false,

‎src/backend/postmaster/pgstat.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,8 @@ pgstat_report_autovac(Oid dboid)
13271327
* ---------
13281328
*/
13291329
void
1330-
pgstat_report_vacuum(Oidtableoid,boolshared,PgStat_Countertuples)
1330+
pgstat_report_vacuum(Oidtableoid,boolshared,
1331+
PgStat_Counterlivetuples,PgStat_Counterdeadtuples)
13311332
{
13321333
PgStat_MsgVacuummsg;
13331334

@@ -1339,7 +1340,8 @@ pgstat_report_vacuum(Oid tableoid, bool shared, PgStat_Counter tuples)
13391340
msg.m_tableoid=tableoid;
13401341
msg.m_autovacuum=IsAutoVacuumWorkerProcess();
13411342
msg.m_vacuumtime=GetCurrentTimestamp();
1342-
msg.m_tuples=tuples;
1343+
msg.m_live_tuples=livetuples;
1344+
msg.m_dead_tuples=deadtuples;
13431345
pgstat_send(&msg,sizeof(msg));
13441346
}
13451347

@@ -4809,9 +4811,8 @@ pgstat_recv_vacuum(PgStat_MsgVacuum *msg, int len)
48094811

48104812
tabentry=pgstat_get_tab_entry(dbentry,msg->m_tableoid, true);
48114813

4812-
tabentry->n_live_tuples=msg->m_tuples;
4813-
/* Resetting dead_tuples to 0 is an approximation ... */
4814-
tabentry->n_dead_tuples=0;
4814+
tabentry->n_live_tuples=msg->m_live_tuples;
4815+
tabentry->n_dead_tuples=msg->m_dead_tuples;
48154816

48164817
if (msg->m_autovacuum)
48174818
{

‎src/include/pgstat.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,8 @@ typedef struct PgStat_MsgVacuum
333333
Oidm_tableoid;
334334
boolm_autovacuum;
335335
TimestampTzm_vacuumtime;
336-
PgStat_Counterm_tuples;
336+
PgStat_Counterm_live_tuples;
337+
PgStat_Counterm_dead_tuples;
337338
}PgStat_MsgVacuum;
338339

339340

@@ -775,7 +776,7 @@ extern void pgstat_reset_single_counter(Oid objectid, PgStat_Single_Reset_Type t
775776

776777
externvoidpgstat_report_autovac(Oiddboid);
777778
externvoidpgstat_report_vacuum(Oidtableoid,boolshared,
778-
PgStat_Countertuples);
779+
PgStat_Counterlivetuples,PgStat_Counterdeadtuples);
779780
externvoidpgstat_report_analyze(Relationrel,
780781
PgStat_Counterlivetuples,PgStat_Counterdeadtuples);
781782

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp