> > Per some earlier discussion, here is an attempt at implementing a
> > "delayed write" of the pgstats file, to decrease the write
> activity on
> > that file.
> > It changes so the file is only written once every 5 minutes
> > (changeable of course, I just picked something) instead of
> once every half second.
> > It's still written when the stats collector shuts down,
> just as before.
> > And it is now also written on backend request. A backend requests a
> > rewrite by simply sending a special stats message. It
> operates on the
> > assumption that the backends aren't actually going to read the
> > statistics file very often, compared to how frequent it's
> written today.
> If somebody tries to read something from the pgstat file, is
> the backend going to request a rewrite and wait until it is complete?
Not sure which part you mean, so I'll answer both ;)
Scenario: One backend reads the file. Second backend requests rewrite.
The write is initiated and later renamed()d into place. As the first
backend still has the file open it'll just continue to read off that
version of the file.
The requesting backend will wait for the file to change, and then read
the new version. So it'll wait for a complete rewrite of the file (with
a timeout of course, in which case we'll read the old file and report a
---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster