Skip to content

Commit 9336d63

Browse files
committed
Flush any remaining statistics counts out to the collector at process
exit. Without this, operations triggered during backend exit (such as temp table deletions) won't be counted ... which given heavy usage of temp tables can lead to pg_autovacuum falling way behind on the need to vacuum pg_class and pg_attribute. Per reports from Steve Crawford and others.
1 parent 47888fe commit 9336d63

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/backend/postmaster/pgstat.c

+21-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* Copyright (c) 2001-2005, PostgreSQL Global Development Group
1515
*
16-
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.88 2005/03/25 00:34:21 tgl Exp $
16+
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.89 2005/03/31 23:20:49 tgl Exp $
1717
* ----------
1818
*/
1919
#include "postgres.h"
@@ -160,6 +160,7 @@ NON_EXEC_STATIC void PgstatCollectorMain(int argc, char *argv[]);
160160
static void pgstat_recvbuffer(void);
161161
static void pgstat_exit(SIGNAL_ARGS);
162162
static void pgstat_die(SIGNAL_ARGS);
163+
static void pgstat_beshutdown_hook(int code, Datum arg);
163164

164165
static int pgstat_add_backend(PgStat_MsgHdr *msg);
165166
static void pgstat_sub_backend(int procpid);
@@ -670,6 +671,25 @@ pgstat_bestart(void)
670671

671672
pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_BESTART);
672673
pgstat_send(&msg, sizeof(msg));
674+
675+
/*
676+
* Set up a process-exit hook to ensure we flush the last batch of
677+
* statistics to the collector.
678+
*/
679+
on_proc_exit(pgstat_beshutdown_hook, 0);
680+
}
681+
682+
/*
683+
* Flush any remaining statistics counts out to the collector at process
684+
* exit. Without this, operations triggered during backend exit (such as
685+
* temp table deletions) won't be counted. This is an on_proc_exit hook,
686+
* not on_shmem_exit, so that everything interesting must have happened
687+
* already.
688+
*/
689+
static void
690+
pgstat_beshutdown_hook(int code, Datum arg)
691+
{
692+
pgstat_report_tabstat();
673693
}
674694

675695

0 commit comments

Comments
 (0)