*** a/src/backend/commands/vacuumlazy.c --- b/src/backend/commands/vacuumlazy.c *************** *** 288,294 **** lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt, /* 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) --- 288,295 ---- /* report results to the stats collector, too */ pgstat_report_vacuum(RelationGetRelid(onerel), onerel->rd_rel->relisshared, ! new_rel_tuples, ! vacrelstats->tuples_deleted); /* and log the action if appropriate */ if (IsAutoVacuumWorkerProcess() && Log_autovacuum_min_duration >= 0) *************** *** 989,994 **** lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats, --- 990,997 ---- RecordPageWithFreeSpace(onerel, blkno, freespace); } + num_tuples -= nkeep; + /* save stats for use later */ vacrelstats->scanned_tuples = num_tuples; vacrelstats->tuples_deleted = tups_vacuumed; *** 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 tuples_removed) { 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_tuples_removed = tuples_removed; 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,4814 ---- tabentry = pgstat_get_tab_entry(dbentry, msg->m_tableoid, true); tabentry->n_live_tuples = msg->m_tuples; ! ! /* ! * clearing out the number of tuples removed by the vacuum from total dead ! * tuples of the table. ! */ ! tabentry->n_dead_tuples -= msg->m_tuples_removed; ! tabentry->n_dead_tuples = Max(tabentry->n_dead_tuples, 0); 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_tuples_removed; } 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 tuples_removed); extern void pgstat_report_analyze(Relation rel, PgStat_Counter livetuples, PgStat_Counter deadtuples);