summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2005-03-31 23:20:49 +0000
committerTom Lane2005-03-31 23:20:49 +0000
commit9336d636e29a75be5c9a80b5a3bd455ff59468e5 (patch)
tree56063b9bdddf6063aff91af162290de2211e648f
parent47888fe84227aaf3decffc7204554bdec54d2b29 (diff)
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.
-rw-r--r--src/backend/postmaster/pgstat.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c
index 2d06cbf146d..bd97a07cde7 100644
--- a/src/backend/postmaster/pgstat.c
+++ b/src/backend/postmaster/pgstat.c
@@ -13,7 +13,7 @@
*
* Copyright (c) 2001-2005, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.88 2005/03/25 00:34:21 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.89 2005/03/31 23:20:49 tgl Exp $
* ----------
*/
#include "postgres.h"
@@ -160,6 +160,7 @@ NON_EXEC_STATIC void PgstatCollectorMain(int argc, char *argv[]);
static void pgstat_recvbuffer(void);
static void pgstat_exit(SIGNAL_ARGS);
static void pgstat_die(SIGNAL_ARGS);
+static void pgstat_beshutdown_hook(int code, Datum arg);
static int pgstat_add_backend(PgStat_MsgHdr *msg);
static void pgstat_sub_backend(int procpid);
@@ -670,6 +671,25 @@ pgstat_bestart(void)
pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_BESTART);
pgstat_send(&msg, sizeof(msg));
+
+ /*
+ * Set up a process-exit hook to ensure we flush the last batch of
+ * statistics to the collector.
+ */
+ on_proc_exit(pgstat_beshutdown_hook, 0);
+}
+
+/*
+ * 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. This is an on_proc_exit hook,
+ * not on_shmem_exit, so that everything interesting must have happened
+ * already.
+ */
+static void
+pgstat_beshutdown_hook(int code, Datum arg)
+{
+ pgstat_report_tabstat();
}