*** a/src/backend/commands/vacuumlazy.c --- b/src/backend/commands/vacuumlazy.c *************** *** 185,190 **** lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt, --- 185,195 ---- BlockNumber new_rel_allvisible; TransactionId new_frozen_xid; MultiXactId new_min_multi; + PgStat_StatTabEntry *tabentry = NULL; + int64 dead_tuples = 0; + int64 new_dead_tuples = 0; + + /* measure elapsed time iff autovacuum logging requires it */ if (IsAutoVacuumWorkerProcess() && Log_autovacuum_min_duration >= 0) *************** *** 215,220 **** lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt, --- 220,235 ---- vacrelstats->pages_removed = 0; vacrelstats->lock_waiter_detected = false; + /* + * Get the data in the table's hashtable entry. + */ + if (IsAutoVacuumWorkerProcess()) + { + tabentry = pgstat_fetch_stat_tabentry(RelationGetRelid(onerel)); + if (tabentry != NULL) + dead_tuples = tabentry->n_dead_tuples; + } + /* Open all indexes of the relation */ vac_open_indexes(onerel, RowExclusiveLock, &nindexes, &Irel); vacrelstats->hasindex = (nindexes > 0); *************** *** 285,294 **** lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt, new_frozen_xid, new_min_multi); /* report results to the stats collector, too */ pgstat_report_vacuum(RelationGetRelid(onerel), onerel->rd_rel->relisshared, ! new_rel_tuples); /* and log the action if appropriate */ if (IsAutoVacuumWorkerProcess() && Log_autovacuum_min_duration >= 0) --- 300,314 ---- new_frozen_xid, new_min_multi); + /* calculate the number of new dead tuples */ + if (tabentry != NULL) + new_dead_tuples = tabentry->n_dead_tuples - dead_tuples; + /* report results to the stats collector, too */ pgstat_report_vacuum(RelationGetRelid(onerel), onerel->rd_rel->relisshared, ! new_rel_tuples, ! new_dead_tuples); /* and log the action if appropriate */ if (IsAutoVacuumWorkerProcess() && Log_autovacuum_min_duration >= 0) *** a/src/backend/postmaster/pgstat.c --- b/src/backend/postmaster/pgstat.c *************** *** 1317,1323 **** pgstat_report_autovac(Oid dboid) * --------- */ void ! pgstat_report_vacuum(Oid tableoid, bool shared, PgStat_Counter tuples) { PgStat_MsgVacuum msg; --- 1317,1324 ---- * --------- */ void ! pgstat_report_vacuum(Oid tableoid, bool shared, PgStat_Counter tuples, ! PgStat_Counter dead_tuples) { PgStat_MsgVacuum msg; *************** *** 1330,1335 **** pgstat_report_vacuum(Oid tableoid, bool shared, PgStat_Counter tuples) --- 1331,1337 ---- msg.m_autovacuum = IsAutoVacuumWorkerProcess(); msg.m_vacuumtime = GetCurrentTimestamp(); msg.m_tuples = tuples; + msg.m_dead_tuples = dead_tuples; pgstat_send(&msg, sizeof(msg)); } *************** *** 4800,4807 **** pgstat_recv_vacuum(PgStat_MsgVacuum *msg, int len) tabentry = pgstat_get_tab_entry(dbentry, msg->m_tableoid, true); tabentry->n_live_tuples = msg->m_tuples; ! /* Resetting dead_tuples to 0 is an approximation ... */ ! tabentry->n_dead_tuples = 0; if (msg->m_autovacuum) { --- 4802,4808 ---- tabentry = pgstat_get_tab_entry(dbentry, msg->m_tableoid, true); tabentry->n_live_tuples = msg->m_tuples; ! tabentry->n_dead_tuples = msg->m_dead_tuples; if (msg->m_autovacuum) { *** a/src/include/pgstat.h --- b/src/include/pgstat.h *************** *** 332,337 **** typedef struct PgStat_MsgVacuum --- 332,338 ---- bool m_autovacuum; TimestampTz m_vacuumtime; PgStat_Counter m_tuples; + PgStat_Counter m_dead_tuples; } PgStat_MsgVacuum; *************** *** 773,779 **** extern void pgstat_reset_single_counter(Oid objectid, PgStat_Single_Reset_Type t extern void pgstat_report_autovac(Oid dboid); extern void pgstat_report_vacuum(Oid tableoid, bool shared, ! PgStat_Counter tuples); extern void pgstat_report_analyze(Relation rel, PgStat_Counter livetuples, PgStat_Counter deadtuples); --- 774,780 ---- extern void pgstat_report_autovac(Oid dboid); extern void pgstat_report_vacuum(Oid tableoid, bool shared, ! PgStat_Counter tuples, PgStat_Counter dead_tuples); extern void pgstat_report_analyze(Relation rel, PgStat_Counter livetuples, PgStat_Counter deadtuples);