Make it easy to detach completely from shared memory.

The new function dsm_detach_all() can be used either by postmaster
children that don't wish to take any risk of accidentally corrupting
shared memory; or by forked children of regular backends with
the same need.  This patch also updates the postmaster children that
already do PGSharedMemoryDetach() to do dsm_detach_all() as well.

Per discussion with Tom Lane.
Fix help message and document in pg_receivexlog.

Add SLOTNAME placeholder to --slot option in help message and
document.
Fix pg_dumpall option parsing: -i doesn't take an argument.

This used to work properly, but got fat-fingered in commit
3dee636e0404885d07885d41c0d70e50c784f324.  Per bug #9620 from
Nicolas Payart.
Improve shm_mq portability around MAXIMUM_ALIGNOF and sizeof(Size).

Revise the original decision to expose a uint64-based interface and
use Size everywhere possible.  Avoid assuming that MAXIMUM_ALIGNOF is
8, or making any assumption about the relationship between that value
and sizeof(Size).  If MAXIMUM_ALIGNOF is bigger, we'll now insert
padding after the length word; if it's smaller, we are now prepared
to read and write the length word in chunks.

Per discussion with Tom Lane.
Fix relcache reference leak in refresh_by_match_merge().

One path through the loop over indexes forgot to do index_close().  Rather
than adding a fourth call, restructure slightly so that there's only one.

In passing, get rid of an unnecessary syscache lookup: the pg_index struct
for the index is already available from its relcache entry.

Per report from YAMAMOTO Takashi, though this is a bit different from his
suggested patch.  This is new code in HEAD, so no need for back-patch.
Rewrite comment for shm_mq_receive_bytes.

The comment and the code diverged at some point before the initial
commit of this feature, and I failed to notice.

Noted by Tom Lane.
Add pg_recvlogical, a tool to receive data logical decoding data.

This is fairly basic at the moment, but it's at least useful for
testing and debugging, and possibly more.

Andres Freund
Documentation for logical decoding.

Craig Ringer, Andres Freund, Christian Kruse, with edits by me.
test_shm_mq: Use Size rather than uint64.

Commit 3bd261ca18c67eafe18088e58fab511e3b965418 updated the API but
neglected to make the corresponding edits here.

Per Tom Lane and the buildfarm.
Fix some remaining int64 vestiges in contrib/test_shm_mq.

Andres Freund and Tom Lane
Make the handling of interrupted B-tree page splits more robust.

Splitting a page consists of two separate steps: splitting the child page,
and inserting the downlink for the new right page to the parent. Previously,
we handled the case that you crash in between those steps with a cleanup
routine after the WAL recovery had finished, which finished the incomplete
split. However, that doesn't help if the page split is interrupted but the
database doesn't crash, so that you don't perform WAL recovery. That could
happen for example if you run out of disk space.

Remove the end-of-recovery cleanup step. Instead, when a page is split, the
left page is marked with a new INCOMPLETE_SPLIT flag, and when the downlink
is inserted to the parent, the flag is cleared again. If an insertion sees
a page with the flag set, it knows that the split was interrupted for some
reason, and inserts the missing downlink before proceeding.

I used the same approach to fix GIN and GiST split algorithms earlier. This
was the last WAL cleanup routine, so we could get rid of that whole
machinery now, but I'll leave that for a separate patch.

Reviewed by Peter Geoghegan.
Fix uninitialized variable.

Report from Andres Freund, but not his fix.
Logical decoding documentation corrections.

Thom Brown
Fix misc typos in comments.
Remove rm_safe_restartpoint machinery.

It is no longer used, none of the resource managers have multi-record
actions that would make it unsafe to perform a restartpoint.

Also don't allow rm_cleanup to write WAL records, it's also no longer
required. Move the call to rm_cleanup routines to make it more symmetric
with rm_startup.
Fix compilation of pg_xlogdump, now that rm_safe_restartpoint is no more.

Oops. Pointed out by Andres Freund.