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

Commit b6cb063

Browse files
zhjwpkuCommitfest Bot
authored and
Commitfest Bot
committed
skip vacuuming the table if last time vacuum percent less than 10
1 parent af51121 commit b6cb063

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/backend/postmaster/autovacuum.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3093,6 +3093,22 @@ relation_needs_vacanalyze(Oid relid,
30933093
float4 reltuples = classForm->reltuples;
30943094
int32 relpages = classForm->relpages;
30953095
int32 relallfrozen = classForm->relallfrozen;
3096+
float4 last_remove_tuples_percent = tabentry->last_autovacuum_removed_tuples_percent;
3097+
TimestampTz last_autovacuum_time = tabentry->last_autovacuum_time;
3098+
3099+
/*
3100+
* If the last autovacuum removed tuples is less than 10% of the
3101+
* current dead tuples, then skip vacuuming this table for some time.
3102+
*/
3103+
if (!TimestampDifferenceExceedsSeconds(last_autovacuum_time,
3104+
GetCurrentTimestamp(),
3105+
autovacuum_naptime) &&
3106+
last_remove_tuples_percent < 10.0)
3107+
{
3108+
*doanalyze = false;
3109+
*dovacuum = false;
3110+
return;
3111+
}
30963112

30973113
vactuples = tabentry->dead_tuples;
30983114
instuples = tabentry->ins_since_vacuum;

src/backend/utils/activity/pgstat_relation.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ pgstat_report_vacuum(Oid tableoid, bool shared,
217217
Oid dboid = (shared ? InvalidOid : MyDatabaseId);
218218
TimestampTz ts;
219219
PgStat_Counter elapsedtime;
220+
PgStat_Counter old_dead_tuples;
220221

221222
if (!pgstat_track_counts)
222223
return;
@@ -232,6 +233,7 @@ pgstat_report_vacuum(Oid tableoid, bool shared,
232233
shtabentry = (PgStatShared_Relation *) entry_ref->shared_stats;
233234
tabentry = &shtabentry->stats;
234235

236+
old_dead_tuples = tabentry->dead_tuples;
235237
tabentry->live_tuples = livetuples;
236238
tabentry->dead_tuples = deadtuples;
237239

@@ -250,6 +252,11 @@ pgstat_report_vacuum(Oid tableoid, bool shared,
250252
if (AmAutoVacuumWorkerProcess())
251253
{
252254
tabentry->last_autovacuum_time = ts;
255+
if (old_dead_tuples > deadtuples)
256+
tabentry->last_autovacuum_removed_tuples_percent =
257+
100 * (old_dead_tuples - deadtuples) / old_dead_tuples;
258+
else
259+
tabentry->last_autovacuum_removed_tuples_percent = 0;
253260
tabentry->autovacuum_count++;
254261
tabentry->total_autovacuum_time += elapsedtime;
255262
}

src/include/pgstat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ typedef struct PgStat_StatTabEntry
443443
TimestampTz last_vacuum_time; /* user initiated vacuum */
444444
PgStat_Counter vacuum_count;
445445
TimestampTz last_autovacuum_time; /* autovacuum initiated */
446+
PgStat_Counter last_autovacuum_removed_tuples_percent;
446447
PgStat_Counter autovacuum_count;
447448
TimestampTz last_analyze_time; /* user initiated */
448449
PgStat_Counter analyze_count;

0 commit comments

Comments
 (0)