Daniel Barlow wrote:
> Questions:
> 1) this is on a system with I believe to be quiescent - there is only
> one client open which is not doing anything. Before I get more involved
> with this, can someone just confirm that pgstat will continue to update
> this file even when nothing is happening? If not, then I guess
> something /is/ happening and I need to investigate what it is (advice on
> how to track it down is welcome - I already have statement logging on,
> and there's nothing showing in there)
Hmm, I don't think we have an optimization to avoid writing it when the
data hasn't changed. This seems easy to do ... see attached patch
(untested)
> 2) does the pgstat.stat file need to be preserved when postgres is not
> running? i.e. could I move it to a tmpfs or something? I can see
> nothing which suggests it has particularly important long-lived data
Yes, the data in the pgstat file is supposed to be kept around when the
system is restarted -- more so if you want autovacuum to work correctly!
--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Index: src/backend/postmaster/pgstat.c
===================================================================
RCS file: /home/alvherre/Code/cvs/pgsql/src/backend/postmaster/pgstat.c,v
retrieving revision 1.155
diff -c -p -r1.155 pgstat.c
*** src/backend/postmaster/pgstat.c 30 Apr 2007 16:37:08 -0000 1.155
--- src/backend/postmaster/pgstat.c 15 May 2007 20:46:01 -0000
*************** static time_t last_pgstat_start_time;
*** 110,115 ****
--- 110,117 ----
static bool pgStatRunningInCollector = false;
+ static bool msg_recvd = true;
+
/*
* Place where backends store per-table info to be sent to the collector.
* We store shared relations separately from non-shared ones, to be able to
*************** PgstatCollectorMain(int argc, char *argv
*** 1964,1969 ****
--- 1966,1972 ----
/*
* O.K. - we accept this message. Process it.
*/
+ msg_recvd = true;
switch (msg.msg_hdr.m_type)
{
case PGSTAT_MTYPE_DUMMY:
*************** pgstat_write_statsfile(void)
*** 2121,2126 ****
--- 2124,2133 ----
FILE *fpout;
int32 format_id;
+ /* no need to do anything if there hasn't been any activity */
+ if (!msg_recvd)
+ return;
+
/*
* Open the statistics temp file to write out the current values.
*/
*************** pgstat_write_statsfile(void)
*** 2207,2212 ****
--- 2214,2225 ----
PGSTAT_STAT_TMPFILE, PGSTAT_STAT_FILENAME)));
unlink(PGSTAT_STAT_TMPFILE);
}
+
+ /*
+ * reset the "message received" bit to avoid writing the file again until
+ * we see some activity
+ */
+ msg_recvd = false;
}
---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings