postgresql/src/include/storage
Andres Freund bd7c348d83 Rework the way multixact truncations work.
The fact that multixact truncations are not WAL logged has caused a fair
share of problems. Amongst others it requires to do computations during
recovery while the database is not in a consistent state, delaying
truncations till checkpoints, and handling members being truncated, but
offset not.

We tried to put bandaids on lots of these issues over the last years,
but it seems time to change course. Thus this patch introduces WAL
logging for multixact truncations.

This allows:
1) to perform the truncation directly during VACUUM, instead of delaying it
   to the checkpoint.
2) to avoid looking at the offsets SLRU for truncation during recovery,
   we can just use the master's values.
3) simplify a fair amount of logic to keep in memory limits straight,
   this has gotten much easier

During the course of fixing this a bunch of additional bugs had to be
fixed:
1) Data was not purged from memory the member's SLRU before deleting
   segments. This happened to be hard or impossible to hit due to the
   interlock between checkpoints and truncation.
2) find_multixact_start() relied on SimpleLruDoesPhysicalPageExist - but
   that doesn't work for offsets that haven't yet been flushed to
   disk. Add code to flush the SLRUs to fix. Not pretty, but it feels
   slightly safer to only make decisions based on actual on-disk state.
3) find_multixact_start() could be called concurrently with a truncation
   and thus fail. Via SetOffsetVacuumLimit() that could lead to a round
   of emergency vacuuming. The problem remains in
   pg_get_multixact_members(), but that's quite harmless.

For now this is going to only get applied to 9.5+, leaving the issues in
the older branches in place. It is quite possible that we need to
backpatch at a later point though.

For the case this gets backpatched we need to handle that an updated
standby may be replaying WAL from a not-yet upgraded primary. We have to
recognize that situation and use "old style" truncation (i.e. looking at
the SLRUs) during WAL replay. In contrast to before, this now happens in
the startup process, when replaying a checkpoint record, instead of the
checkpointer. Doing truncation in the restartpoint is incorrect, they
can happen much later than the original checkpoint, thereby leading to
wraparound.  To avoid "multixact_redo: unknown op code 48" errors
standbys would have to be upgraded before primaries.

A later patch will bump the WAL page magic, and remove the legacy
truncation codepaths. Legacy truncation support is just included to make
a possible future backpatch easier.

Discussion: 20150621192409.GA4797@alap3.anarazel.de
Reviewed-By: Robert Haas, Alvaro Herrera, Thomas Munro
Backpatch: 9.5 for now
2015-09-26 19:04:25 +02:00
..
backendid.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
barrier.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
block.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
buf.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
buf_internals.h Align buffer descriptors to cache line boundaries. 2015-01-29 22:48:45 +01:00
buffile.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
bufmgr.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
bufpage.h Add assertion to check the special size is sane before dereferencing it. 2015-06-30 13:44:04 +03:00
checksum.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
checksum_impl.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
copydir.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
dsm.h Add flags argument to dsm_create. 2015-03-19 13:03:03 -04:00
dsm_impl.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
fd.h Fix fsync-at-startup code to not treat errors as fatal. 2015-05-28 17:33:03 -04:00
freespace.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
fsm_internals.h Use FLEXIBLE_ARRAY_MEMBER in a bunch more places. 2015-02-20 00:11:42 -05:00
indexfsm.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
ipc.h Tweak __attribute__-wrapping macros for better pgindent results. 2015-03-26 14:03:25 -04:00
item.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
itemid.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
itemptr.h Improve packing/alignment annotation for ItemPointerData. 2015-05-21 17:21:46 -04:00
large_object.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
latch.h Add a default local latch for use in signal handlers. 2015-01-14 18:45:22 +01:00
lmgr.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
lock.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
lwlock.h Rework the way multixact truncations work. 2015-09-26 19:04:25 +02:00
off.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
pg_sema.h Remove the option to service interrupts during PGSemaphoreLock(). 2015-02-03 23:25:00 +01:00
pg_shmem.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
pmsignal.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
pos.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
predicate.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
predicate_internals.h Define integer limits independently from the system definitions. 2015-04-02 17:43:35 +02:00
proc.h Move deadlock and other interrupt handling in proc.c out of signal handlers. 2015-02-03 23:24:38 +01:00
procarray.h Create an infrastructure for parallel computation in PostgreSQL. 2015-04-30 15:02:14 -04:00
procsignal.h Create an infrastructure for parallel computation in PostgreSQL. 2015-04-30 15:02:14 -04:00
reinit.h reinit.h: Fix typo in identification comment 2015-01-22 12:26:51 -03:00
relfilenode.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
s_lock.h Fix s_lock.h PPC assembly code to be compatible with native AIX assembler. 2015-08-29 16:09:25 -04:00
shm_mq.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
shm_toc.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
shmem.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
sinval.h Introduce and use infrastructure for interrupt processing during client reads. 2015-02-03 22:25:20 +01:00
sinvaladt.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
smgr.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
spin.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
standby.h Use FLEXIBLE_ARRAY_MEMBER in a bunch more places. 2015-02-20 00:11:42 -05:00