postgresql/src/backend
Tom Lane 6fea65508a Tighten ComputeXidHorizons' handling of walsenders.
ComputeXidHorizons (nee GetOldestXmin) thought that it could identify
walsenders by checking for proc->databaseId == 0.  Perhaps that was
safe when the code was written, but it's been wrong at least since
autovacuum was invented.  Background processes that aren't connected
to any particular database, such as the autovacuum launcher and
logical replication launcher, look like that too.

This imprecision is harmful because when such a process advertises an
xmin, the result is to hold back dead-tuple cleanup in all databases,
though it'd be sufficient to hold it back in shared catalogs (which
are the only relations such a process can access).  Aside from being
generally inefficient, this has recently been seen to cause regression
test failures in the buildfarm, as a consequence of the logical
replication launcher's startup transaction preventing VACUUM from
marking pages of a user table as all-visible.

We only want that global hold-back effect for the case where a
walsender is advertising a hot standby feedback xmin.  Therefore,
invent a new PGPROC flag that says that a process' xmin should be
considered globally, and check that instead of using the incorrect
databaseId == 0 test.  Currently only a walsender sets that flag,
and only if it is not connected to any particular database.  (This is
for bug-compatibility with the undocumented behavior of the existing
code, namely that feedback sent by a client who has connected to a
particular database would not be applied globally.  I'm not sure this
is a great definition; however, such a client is capable of issuing
plain SQL commands, and I don't think we want xmins advertised for
such commands to be applied globally.  Perhaps this could do with
refinement later.)

While at it, I rewrote the comment in ComputeXidHorizons, and
re-ordered the commented-upon if-tests, to make them match up
for intelligibility's sake.

This is arguably a back-patchable bug fix, but given the lack of
complaints I think it prudent to let it age awhile in HEAD first.

Discussion: https://postgr.es/m/1346227.1649887693@sss.pgh.pa.us
2022-04-15 17:50:05 -04:00
..
access VACUUM VERBOSE: Show dead items for an empty table. 2022-04-15 14:20:56 -07:00
bootstrap pg_upgrade: Preserve relfilenodes and tablespace OIDs. 2022-01-17 13:40:27 -05:00
catalog Remove extraneous blank lines before block-closing braces 2022-04-13 19:16:02 +02:00
commands Have CLUSTER ignore partitions not owned by caller 2022-04-14 22:11:06 +02:00
executor Remove extraneous blank lines before block-closing braces 2022-04-13 19:16:02 +02:00
foreign Create routine able to set single-call SRFs for Materialize mode 2022-03-07 10:26:29 +09:00
jit Remove extraneous blank lines before block-closing braces 2022-04-13 19:16:02 +02:00
lib dshash: revise sequential scan support. 2022-04-04 14:32:52 -07:00
libpq Remove extraneous blank lines before block-closing braces 2022-04-13 19:16:02 +02:00
main Fix collection of typos in the code and the documentation 2022-03-15 11:29:35 +09:00
nodes Use WRITE_ENUM_FIELD for enum field 2022-04-12 16:19:00 +02:00
optimizer Remove extraneous blank lines before block-closing braces 2022-04-13 19:16:02 +02:00
parser Small cleanups in SQL/JSON code 2022-04-15 07:49:20 -04:00
partitioning Refactor and cleanup runtime partition prune code a little 2022-04-05 11:46:48 +02:00
po Translation updates 2021-06-21 12:33:50 +02:00
port Ensure that the argument of shmdt(2) is declared "void *". 2022-02-15 17:17:28 -05:00
postmaster Remove extraneous blank lines before block-closing braces 2022-04-13 19:16:02 +02:00
regex Call pg_newlocale_from_collation() also with default collation 2022-01-20 09:50:18 +01:00
replication Tighten ComputeXidHorizons' handling of walsenders. 2022-04-15 17:50:05 -04:00
rewrite Add support for MERGE SQL command 2022-03-28 16:47:48 +02:00
snowball Update copyright for 2022 2022-01-07 19:04:57 -05:00
statistics Remove extraneous blank lines before block-closing braces 2022-04-13 19:16:02 +02:00
storage Tighten ComputeXidHorizons' handling of walsenders. 2022-04-15 17:50:05 -04:00
tcop Remove extraneous blank lines before block-closing braces 2022-04-13 19:16:02 +02:00
tsearch Remove extraneous blank lines before block-closing braces 2022-04-13 19:16:02 +02:00
utils Small cleanups in SQL/JSON code 2022-04-15 07:49:20 -04:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
Makefile Server-side gzip compression. 2022-01-24 15:13:18 -05:00
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
nls.mk Report progress of startup operations that take a long time. 2021-10-25 11:51:57 -04:00