Set the all-visible flag on heap page before writing WAL record, not after.

If we set the all-visible flag after writing WAL record, and XLogInsert
takes a full-page image of the page, the image would not include the flag.
We will then proceed to set the VM bit, which would then be set without the
corresponding all-visible flag on the heap page.

Found by comparing page images on master and standby, after writing/replaying
each WAL record. (There is still a discrepancy: the all-visible flag won't
be set after replaying the HEAP_CLEAN record, even though it is set in the
master. However, it will be set when replaying the HEAP2_VISIBLE record and
setting the VM bit, so the all-visible flag and VM bit are always consistent
on the standby, even though they are momentarily out-of-sync with master)

Backpatch to 9.3 where this code was introduced.
docs: adjustments for streaming standbys that disconnect frequently

Document problems when disconnection causes loss of hot_standby_feedback
and suggest adjusting max_standby_archive_delay and
max_standby_streaming_delay.

Initial patch by Marko Tiikkaja, adjustments by me
pg_upgrade:  throw an error for non-existent tablespace directories

Non-existent tablespace directory references can occur if user
tablespaces are created inside data directories and the data directory
is renamed in preparation for running pg_upgrade, and the symbolic links
are not updated.

Backpatch to 9.3.
report stat() error in trigger file check

Permissions might prevent the existence of the trigger file from being
checked.

Per report from Andres Freund
pgcrypto:  fix memset() calls that might be optimized away

Specifically, on-stack memset() might be removed, so:

	* Replace memset() with px_memset()
	* Add px_memset to copy_crlf()
	* Add px_memset to pgp-s2k.c

Patch by Marko Kreen

Report by PVS-Studio

Backpatch through 8.4.
Fix unused-variable warning on Windows.

Introduced in 585bca39: msgid is not used in the Windows code path.

Also adjust comments a tad (mostly to keep pgindent from messing it up).

David Rowley
Create function prototype as part of PG_FUNCTION_INFO_V1 macro

Because of gcc -Wmissing-prototypes, all functions in dynamically
loadable modules must have a separate prototype declaration.  This is
meant to detect global functions that are not declared in header files,
but in cases where the function is called via dfmgr, this is redundant.
Besides filling up space with boilerplate, this is a frequent source of
compiler warnings in extension modules.

We can fix that by creating the function prototype as part of the
PG_FUNCTION_INFO_V1 macro, which such modules have to use anyway.  That
makes the code of modules cleaner, because there is one less place where
the entry points have to be listed, and creates an additional check that
functions have the right prototype.

Remove now redundant prototypes from contrib and other modules.
Fix typo

Amit Langote
libpq:  have PQconnectdbParams() and PQpingParams accept "" as default

Previously, these functions treated "" optin values as defaults in some
ways, but not in others, like when comparing to .pgpass.  Also, add
documentation to clarify that now "" and NULL use defaults, like
PQsetdbLogin() has always done.

BACKWARD INCOMPATIBILITY

Patch by Adrian Vondendriesch, docs by me

Report by Jeff Janes
docs:  tablespaces cannot be accessed independently

Mention impossibility of moving tablespaces, backing them up
independently, or the inadvisability of placing them on temporary
file systems.

Patch by Craig Ringer, adjustments by Ian Lawrence Warwick and me
doc: mention archive_command and recovery_command are exec'ed locally

Report by Craig Ringer
doc: CREATE DATABASE doesn't copy template database-level config params

Report by Alexey Bashtanov