|
13 | 13 | *
|
14 | 14 | * Copyright (c) 2001-2005, PostgreSQL Global Development Group
|
15 | 15 | *
|
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 $ |
17 | 17 | * ----------
|
18 | 18 | */
|
19 | 19 | #include "postgres.h"
|
@@ -160,6 +160,7 @@ NON_EXEC_STATIC void PgstatCollectorMain(int argc, char *argv[]);
|
160 | 160 | static void pgstat_recvbuffer(void);
|
161 | 161 | static void pgstat_exit(SIGNAL_ARGS);
|
162 | 162 | static void pgstat_die(SIGNAL_ARGS);
|
| 163 | +static void pgstat_beshutdown_hook(int code, Datum arg); |
163 | 164 |
|
164 | 165 | static int pgstat_add_backend(PgStat_MsgHdr *msg);
|
165 | 166 | static void pgstat_sub_backend(int procpid);
|
@@ -670,6 +671,25 @@ pgstat_bestart(void)
|
670 | 671 |
|
671 | 672 | pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_BESTART);
|
672 | 673 | 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(); |
673 | 693 | }
|
674 | 694 |
|
675 | 695 |
|
|
0 commit comments