postgresql/src/include
Andres Freund 4f627f8973 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
..
access Rework the way multixact truncations work. 2015-09-26 19:04:25 +02:00
bootstrap pgindent run for 9.5 2015-05-23 21:35:49 -04:00
catalog Determine whether it's safe to attempt a parallel plan for a query. 2015-09-16 15:38:47 -04:00
commands Allow per-tablespace effective_io_concurrency 2015-09-08 12:51:42 -03:00
common pgindent run for 9.5 2015-05-23 21:35:49 -04:00
datatype Define integer limits independently from the system definitions. 2015-04-02 17:43:35 +02:00
executor Glue layer to connect the executor to the shm_mq mechanism. 2015-09-18 21:56:58 -04:00
foreign Add support for doing late row locking in FDWs. 2015-05-12 14:10:17 -04:00
lib Avoid use of float arithmetic in bipartite_match.c. 2015-08-23 13:02:18 -04:00
libpq Actually, it's not that hard to merge the Windows pqsignal code ... 2015-08-31 15:52:56 -04:00
mb Teach UtfToLocal/LocalToUtf to support algorithmic encoding conversions. 2015-05-14 22:27:12 -04:00
nodes Add new function planstate_tree_walker. 2015-09-17 11:27:06 -04:00
optimizer Determine whether it's safe to attempt a parallel plan for a query. 2015-09-16 15:38:47 -04:00
parser Determine whether it's safe to attempt a parallel plan for a query. 2015-09-16 15:38:47 -04:00
port Allow icc to use the same atomics infrastructure as gcc. 2015-08-31 16:30:12 -04:00
portability Use mmap MAP_NOSYNC option to limit shared memory writes 2015-03-21 22:06:19 -04:00
postmaster pgindent run for 9.5 2015-05-23 21:35:49 -04:00
regex Fix low-probability memory leak in regex execution. 2015-09-18 13:55:17 -04:00
replication Don't include rel.h when relcache.h is sufficient 2015-08-11 13:03:14 -03:00
rewrite RLS refactoring 2015-09-15 15:49:31 -04:00
snowball Update copyright for 2015 2015-01-06 11:43:47 -05:00
storage Glue layer to connect the executor to the shm_mq mechanism. 2015-09-18 21:56:58 -04:00
tcop Glue layer to connect the executor to the shm_mq mechanism. 2015-09-18 21:56:58 -04:00
tsearch Fix statically allocated struct with FLEXIBLE_ARRAY_MEMBER member. 2015-02-20 17:50:18 -05:00
utils Allow planner to use expression-index stats for function calls in WHERE. 2015-09-24 18:35:46 -04:00
.gitignore Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
c.h Remove support for Unix systems without the POSIX signal APIs. 2015-08-31 12:56:10 -04:00
fmgr.h Fix comment in fmgr.h to refer to actual function used. 2015-06-15 23:21:03 -04:00
funcapi.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
getaddrinfo.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
getopt_long.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
Makefile Install lwlocknames.h even in vpath builds. 2015-09-11 16:45:41 -04:00
miscadmin.h Remove the SECURITY_ROW_LEVEL_DISABLED security context bit. 2015-09-20 20:47:17 -04:00
pg_config.h.in Remove support for Unix systems without the POSIX signal APIs. 2015-08-31 12:56:10 -04:00
pg_config.h.win32 Remove support for Unix systems without the POSIX signal APIs. 2015-08-31 12:56:10 -04:00
pg_config_ext.h.in Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_ext.h.win32 Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_manual.h Define integer limits independently from the system definitions. 2015-04-02 17:43:35 +02:00
pg_getopt.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
pg_trace.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
pgstat.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
pgtar.h Error when creating names too long for tar format 2015-02-24 13:41:07 -05:00
pgtime.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
port.h Redesign tablesample method API, and do extensive code review. 2015-07-25 14:39:00 -04:00
postgres.h Support "expanded" objects, particularly arrays, for better performance. 2015-05-14 12:08:49 -04:00
postgres_ext.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
postgres_fe.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
rusagestub.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
windowapi.h Update copyright for 2015 2015-01-06 11:43:47 -05:00