doc: Fix up ALTER TABLESPACE reference page

The documentation of ALTER TABLESPACE ... MOVE was added without any
markup, not even paragraph breaks.  Fix that, and clarify the text in a
few places.
Fix obsolete statement in smgr/README.

Since commit 2d00190495b22e0d0ba351b2cda9c95fb2e3d083, fork numbers are
defined in relpath.h not relfilenode.h.

Fabrízio de Royes Mello
Reword the sentence for pg_logical_slot_peek_changes function.

Previously the duplicated paragraphs were used next to each other
in the document to demonstrate that the changes in the stream
were not consumed by pg_logical_slot_peek_changes function.
But some users misunderstood that the duplication of the same
paragraph was just typo. So this commit rewords the sentence in
the latter paragraph for less confusing.

Christoph Moench-Tegeder
Treat 2PC commit/abort the same as regular xacts in recovery.

There were several oversights in recovery code where COMMIT/ABORT PREPARED
records were ignored:

* pg_last_xact_replay_timestamp() (wasn't updated for 2PC commits)
* recovery_min_apply_delay (2PC commits were applied immediately)
* recovery_target_xid (recovery would not stop if the XID used 2PC)

The first of those was reported by Sergiy Zuban in bug #11032, analyzed by
Tom Lane and Andres Freund. The bug was always there, but was masked before
commit d19bd29f07aef9e508ff047d128a4046cc8bc1e2, because COMMIT PREPARED
always created an extra regular transaction that was WAL-logged.

Backpatch to all supported versions (older versions didn't have all the
features and therefore didn't have all of the above bugs).
Oops, fix recoveryStopsBefore functions for regular commits.

Pointed out by Tom Lane. Backpatch to 9.4, the code was structured
differently in earlier branches and didn't have this mistake.
Simplify multixact freezing a bit

Testing for abortedness of a multixact member that's being frozen is
unnecessary: we only need to know whether the transaction is still in
progress or committed to determine whether it must be kept or not.  This
let us simplify the code a bit and avoid a useless TransactionIdDidAbort
test.

Suggested by Andres Freund awhile back.
Avoid uselessly looking up old LOCK_ONLY multixacts

Commit 0ac5ad5134f2 removed an optimization in multixact.c that skipped
fetching members of MultiXactId that were older than our
OldestVisibleMXactId value.  The reason this was removed is that it is
possible for multixacts that contain updates to be older than that
value.  However, if the caller is certain that the multi does not
contain an update (because the infomask bits say so), it can pass this
info down to GetMultiXactIdMembers, enabling it to use the old
optimization.

Pointed out by Andres Freund in 20131121200517.GM7240@alap2.anarazel.de
pg_upgrade:  improve C comment wording
doc: Clean up some recently added PL/pgSQL documentation

- Capitalize titles consistently.
- Fix some grammar.
- Group "Obtaining Information About an Error" under "Trapping Errors",
  but make "Obtaining the Call Stack Context Information" its own
  section, since it's not about errors.
Fix mishandling of background worker PGPROCs in EXEC_BACKEND builds.

InitProcess() relies on IsBackgroundWorker to decide whether the PGPROC
for a new backend should be taken from ProcGlobal's freeProcs or from
bgworkerFreeProcs.  In EXEC_BACKEND builds, InitProcess() is called
sooner than in non-EXEC_BACKEND builds, and IsBackgroundWorker wasn't
getting initialized soon enough.

Report by Noah Misch.  Diagnosis and fix by me.
pgbench: Allow \setrandom to generate Gaussian/exponential distributions.

Mitsumasa KONDO and Fabien COELHO, with further wordsmithing by me.
Avoid wholesale autovacuuming when autovacuum is nominally off.

When autovacuum is nominally off, we will still launch autovac workers
to vacuum tables that are at risk of XID wraparound.  But after we'd done
that, an autovac worker would proceed to autovacuum every table in the
targeted database, if they meet the usual thresholds for autovacuuming.
This is at best pretty unexpected; at worst it delays response to the
wraparound threat.  Fix it so that if autovacuum is nominally off, we
*only* do forced vacuums and not any other work.

Per gripe from Andrey Zhidenkov.  This has been like this all along,
so back-patch to all supported branches.
Move log_newpage and log_newpage_buffer to xlog.c.

log_newpage is used by many indexams, in addition to heap, but for
historical reasons it's always been part of the heapam rmgr. Starting with
9.3, we have another WAL record type for logging an image of a page,
XLOG_FPI. Simplify things by moving log_newpage and log_newpage_buffer to
xlog.c, and switch to using the XLOG_FPI record type.

Bump the WAL version number because the code to replay the old HEAP_NEWPAGE
records is removed.
Fix typo in user manual
Fix bug in pg_receivexlog --verbose.

In 9.2, pg_receivexlog with verbose option has emitted the messages
at the end of each WAL file. But the commit 0b63291 suppressed such
messages by mistake. This commit fixes the bug so that pg_receivexlog
--verbose outputs such messages again.

Back-patch to 9.3 where the bug was added.
Add missing PQclear() calls into pg_receivexlog.

Back-patch to 9.3.
Windows doesn't have M_PI; define it ourselves when needed.

This should fix the Windows build, broken by commit ed802e7d.
pg_upgrade:  remove reference to autovacuum_multixact_freeze_max_age

autovacuum_multixact_freeze_max_age was added as a pg_ctl start
parameter in 9.3.X to prevent autovacuum from running.  However, only
some 9.3.X releases have autovacuum_multixact_freeze_max_age as it was
added in a minor PG 9.3 release.  It also isn't needed because -b turns
off autovacuum in 9.1+.

Without this fix, trying to upgrade from an early 9.3 release to 9.4
would fail.

Report by EDB

Backpatch through 9.3
pg_upgrade:  assume user is install user

The user specified to the upgrade was effectively the install user, but
that was not clearly stated in the comments, documentation, or error
messages.
Improve some JSON error messages.

These messages are new in 9.4, which hasn't been released yet, so
back-patch to REL9_4_STABLE.

Daniele Varrazzo