postgresql/src/backend
Tom Lane 22b27b4c9e Avoid useless closely-spaced writes of statistics files.
The original intent in the stats collector was that we should not write out
stats data oftener than every PGSTAT_STAT_INTERVAL msec.  Backends will not
make requests at all if they see the existing data is newer than that, and
the stats collector is supposed to disregard requests having a cutoff_time
older than its most recently written data, so that close-together requests
don't result in multiple writes.  But the latter part of that got broken
in commit 187492b6c2, so that if two backends concurrently decide
the existing stats are too old, the collector would write the data twice.
(In principle the collector's logic would still merge requests as long as
the second one arrives before we've actually written data ... but since
the message collection loop would write data immediately after processing
a single inquiry message, that never happened in practice, and in any case
the window in which it might work would be much shorter than
PGSTAT_STAT_INTERVAL.)

To fix, improve pgstat_recv_inquiry so that it checks whether the cutoff
time is too old, and doesn't add a request to the queue if so.  This means
that we do not need DBWriteRequest.request_time, because the decision is
taken before making a queue entry.  And that means that we don't really
need the DBWriteRequest data structure at all; an OID list of database
OIDs will serve and allow removal of some rather verbose and crufty code.

In passing, improve the comments in this area, which have been rather
neglected.  Also change backend_read_statsfile so that it's not silently
relying on MyDatabaseId to have some particular value in the autovacuum
launcher process.  It accidentally worked as desired because MyDatabaseId
is zero in that process; but that does not seem like a dependency we want,
especially with no documentation about it.

Although this patch is mine, it turns out I'd rediscovered a known bug,
for which Tomas Vondra had already submitted a patch that's functionally
equivalent to the non-cosmetic aspects of this patch.  Thanks to Tomas
for reviewing this version.

Back-patch to 9.3 where the bug was introduced.

Prior-Discussion: <1718942738eb65c8407fcd864883f4c8@fuzzy.cz>
Patch: <4625.1464202586@sss.pgh.pa.us>
2016-05-31 15:55:15 -04:00
..
access Fix PageAddItem BRIN bug 2016-05-30 14:47:22 -04:00
bootstrap Revert CREATE INDEX ... INCLUDING ... 2016-04-08 21:52:13 +03:00
catalog sql_features: Fix typos 2016-05-13 21:24:54 -04:00
commands Fix DROP ACCESS METHOD IF EXISTS. 2016-05-27 11:03:18 -04:00
executor Fix latent crash in do_text_output_multiline(). 2016-05-23 14:16:40 -04:00
foreign Fix whitespace 2016-04-11 14:44:51 -04:00
lib Remove mergeHyperLogLog. 2016-04-27 10:55:32 -04:00
libpq Add authentication parameters compat_realm and upn_usename for SSPI 2016-04-08 20:28:38 +02:00
main Avoid crash on old Windows with AVX2-capable CPU for VS2013 builds 2016-03-10 14:10:18 +01:00
nodes Mirror struct Aggref field order in _copyAggref(). 2016-05-31 00:01:03 -04:00
optimizer Disable physical tlist if any Var would need multiple sortgroupref labels. 2016-05-26 14:52:30 -04:00
parser Remove option to write USING before opclass name in CREATE INDEX. 2016-05-25 19:11:00 -04:00
po Translation updates 2016-05-09 10:04:41 -04:00
port Support building with Visual Studio 2015 2016-04-29 08:09:07 -04:00
postmaster Avoid useless closely-spaced writes of statistics files. 2016-05-31 15:55:15 -04:00
regex Suppress compiler warnings about useless comparison of unsigned to zero. 2016-02-15 17:12:16 -05:00
replication Revert timeline following in replication slots 2016-05-04 17:32:22 -03:00
rewrite Improve error message for rejecting RETURNING clauses with dropped columns. 2016-02-29 19:11:38 -05:00
snowball Update copyright for 2016 2016-01-02 13:33:40 -05:00
storage Fix PageAddItem BRIN bug 2016-05-30 14:47:22 -04:00
tcop Be more predictable about reporting "lock timeout" vs "statement timeout". 2016-05-27 10:40:20 -04:00
tsearch Tweak a few more things in preparation for upcoming pgindent run. 2016-05-03 10:52:25 -04:00
utils Be more predictable about reporting "lock timeout" vs "statement timeout". 2016-05-27 10:40:20 -04:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
common.mk Remove maintainer-check target, fold into normal build 2013-10-10 20:11:56 -04:00
Makefile Support multiple synchronous standby servers. 2016-04-06 17:18:25 +09:00
nls.mk Remove trailing slashes from directories in find command 2015-09-18 22:06:54 -04:00