Teodor Sigaev [Mon, 7 Sep 2015 14:16:29 +0000 (17:16 +0300)]     Make GIN's cleanup pending list process interruptable
 
 Cleanup process could be called by ordinary insert/update and could take a lot
 of time. Add vacuum_delay_point() to make this process interruptable. Under
 vacuum this call will also throttle a vacuum process to decrease system load,
 called from insert/update it will not throttle, and that reduces a latency.
 
 Backpatch for all supported branches.
 
 Jeff Janes <jeff.janes@gmail.com>
 
 
    Teodor Sigaev [Mon, 7 Sep 2015 13:24:01 +0000 (16:24 +0300)]     Add pages deleted from pending list to FSM
 
 Add pages deleted from GIN's pending list during cleanup to free space map
 immediately. Clean up process could be initiated by ordinary insert but adding
 page to FSM might occur only at vacuum. On some workload like never-vacuumed
 insert-only tables it could cause a huge bloat.
 
 Jeff Janes <jeff.janes@gmail.com>
 
 
    Teodor Sigaev [Mon, 7 Sep 2015 12:20:45 +0000 (15:20 +0300)]     Update site address of Snowball project
 
 
    Joe Conway [Sun, 6 Sep 2015 18:25:36 +0000 (11:25 -0700)]     Adjust sepgsql regression output for recent error context change
  Recent commit 
0426f349e changed handling of error context reports
 in such a way to have a minor effect on the sepgsql regression
 output. Adapt the expected output file to suit. Since that commit
 was HEAD only, so is this one.  
  Magnus Hagander [Sun, 6 Sep 2015 12:26:33 +0000 (14:26 +0200)]     Support RADIUS passwords up to 128 characters
 
 Previous limit was 16 characters, due to lack of support for multiple passes
 of encryption.
 
 Marko Tiikkaja
 
 
    Andres Freund [Sun, 6 Sep 2015 11:17:23 +0000 (13:17 +0200)]     Add ability to reserve WAL upon slot creation via replication protocol.
  Since 
6fcd885 it is possible to immediately reserve WAL when creating a
 slot via pg_create_physical_replication_slot(). Extend the replication
 protocol to allow that as well. 
 Although, in contrast to the SQL interface, it is possible to update the
 reserved location via the replication interface, it is still useful
 being able to reserve upon creation there. Otherwise the logic in
 ReplicationSlotReserveWal() has to be repeated in slot employing
 clients. 
 Author: Michael Paquier
 Discussion: CAB7nPqT0Wc1W5mdYGeJ_wbutbwNN+3qgrFR64avXaQCiJMGaYA@mail.gmail.com  
  Greg Stark [Sun, 6 Sep 2015 01:04:37 +0000 (02:04 +0100)]     Move DTK_ISODOW DTK_DOW and DTK_DOY to be type UNITS rather than
 RESERV. RESERV is meant for tokens like "now" and having them in that
 category throws errors like these when used as an input date:
 
 stark=# SELECT 'doy'::timestamptz;
 ERROR:  unexpected dtype 33 while parsing timestamptz "doy"
 LINE 1: SELECT 'doy'::timestamptz;
                ^
 stark=# SELECT 'dow'::timestamptz;
 ERROR:  unexpected dtype 32 while parsing timestamptz "dow"
 LINE 1: SELECT 'dow'::timestamptz;
                ^
 
 Found by LLVM's Libfuzzer
 
 
    Tom Lane [Sat, 5 Sep 2015 20:15:38 +0000 (16:15 -0400)]     Fix CreateTableSpace() so it will compile without HAVE_SYMLINK.
  This has been broken since 9.3 (commit 
82b1b213cad3a69c to be exact),
 which suggests that nobody is any longer using a Windows build system that
 doesn't provide a symlink emulation.  Still, it's wrong on its own terms,
 so repair. 
 YUriy Zhuravlev  
  Tom Lane [Sat, 5 Sep 2015 15:58:20 +0000 (11:58 -0400)]     Rearrange the handling of error context reports.
 
 Remove the code in plpgsql that suppressed the innermost line of CONTEXT
 for messages emitted by RAISE commands.  That was never more than a quick
 backwards-compatibility hack, and it's pretty silly in cases where the
 RAISE is nested in several levels of function.  What's more, it violated
 our design theory that verbosity of error reports should be controlled
 on the client side not the server side.
 
 To alleviate the resulting noise increase, introduce a feature in libpq
 and psql whereby the CONTEXT field of messages can be suppressed, either
 always or only for non-error messages.  Printing CONTEXT for errors only
 is now their default behavior.
 
 The actual code changes here are pretty small, but the effects on the
 regression test outputs are widespread.  I had to edit some of the
 alternative expected outputs by hand; hopefully the buildfarm will soon
 find anything I fat-fingered.
 
 In passing, fix up (again) the output line counts in psql's various
 help displays.  Add some commentary about how to verify them.
 
 Pavel Stehule, reviewed by Petr Jelínek, Jeevan Chalke, and others
 
 
    Heikki Linnakangas [Sat, 5 Sep 2015 08:35:49 +0000 (11:35 +0300)]     Fix misc typos.
 
 Oskari Saarenmaa. Backpatch to stable branches where applicable.
 
 
    Tatsuo Ishii [Sat, 5 Sep 2015 00:19:25 +0000 (09:19 +0900)]     Fix brin index summarizing while vacuuming.
  If the number of heap blocks is not multiples of pages per range, the
 summarizing produces wrong summary information for the last brin index
 tuple while vacuuming. 
 Problem reported by Tatsuo Ishii and fixed by Amit Langote. 
 Discussion at "[HACKERS] BRIN INDEX value (message id :
20150903.174935.
1946402199422994347.t-ishii@sraoss.co.jp)
 Backpatched to 9.5 in which brin index was added.  
  Tom Lane [Fri, 4 Sep 2015 17:36:49 +0000 (13:36 -0400)]     Fix subtransaction cleanup after an outer-subtransaction portal fails.
 
 Formerly, we treated only portals created in the current subtransaction as
 having failed during subtransaction abort.  However, if the error occurred
 while running a portal created in an outer subtransaction (ie, a cursor
 declared before the last savepoint), that has to be considered broken too.
 
 To allow reliable detection of which ones those are, add a bookkeeping
 field to struct Portal that tracks the innermost subtransaction in which
 each portal has actually been executed.  (Without this, we'd end up
 failing portals containing functions that had called the subtransaction,
 thereby breaking plpgsql exception blocks completely.)
 
 In addition, when we fail an outer-subtransaction Portal, transfer its
 resources into the subtransaction's resource owner, so that they're
 released early in cleanup of the subxact.  This fixes a problem reported by
 Jim Nasby in which a function executed in an outer-subtransaction cursor
 could cause an Assert failure or crash by referencing a relation created
 within the inner subtransaction.
 
 The proximate cause of the Assert failure is that AtEOSubXact_RelationCache
 assumed it could blow away a relcache entry without first checking that the
 entry had zero refcount.  That was a bad idea on its own terms, so add such
 a check there, and to the similar coding in AtEOXact_RelationCache.  This
 provides an independent safety measure in case there are still ways to
 provoke the situation despite the Portal-level changes.
 
 This has been broken since subtransactions were invented, so back-patch
 to all supported branches.
 
 Tom Lane and Michael Paquier
 
 
    Teodor Sigaev [Fri, 4 Sep 2015 09:51:53 +0000 (12:51 +0300)]     Make unaccent handle all diacritics known to Unicode, and expand ligatures correctly
 
 Add Python script for buiding unaccent.rules from Unicode data. Don't
 backpatch because unaccent changes may require tsvector/index
 rebuild.
 
 Thomas Munro <thomas.munro@enterprisedb.com>
 
 
    Robert Haas [Thu, 3 Sep 2015 17:10:53 +0000 (13:10 -0400)]     Assorted code review for recent ProcArrayLock patch.
 
 Post-commit review by Andres Freund discovered a couple of concurrency
 bugs in the original patch: specifically, if the leader cleared a
 follower's XID before it reached PGSemaphoreLock, the semaphore would be
 left in the wrong state; and if another process did PGSemaphoreUnlock
 for some unrelated reason, we might resume execution before the fact
 that our XID was cleared was globally visible.
 
 Also, improve the wording of some comments, rename nextClearXidElem
 to firstClearXidElem in PROC_HDR for clarity, and drop some volatile
 qualifiers that aren't necessary.
 
 Amit Kapila, reviewed and slightly revised by me.
 
 
    Fujii Masao [Thu, 3 Sep 2015 13:30:16 +0000 (22:30 +0900)]     Document that max_worker_processes must be high enough in standby.
 
 The setting values of some parameters including max_worker_processes
 must be equal to or higher than the values on the master. However,
 previously max_worker_processes was not listed as such parameter
 in the document. So this commit adds it to that list.
 
 Back-patch to 9.4 where max_worker_processes was added.
 
 
    Noah Misch [Thu, 3 Sep 2015 04:29:11 +0000 (00:29 -0400)]     Disable fsync throughout TAP test suites.
 
 Most suites already did so via start_test_server(), but the pg_rewind,
 pg_ctl and pg_controldata suites ran a postmaster or initdb with fsync
 enabled.  This halves the pg_rewind suite's runtime on buildfarm member
 tern.  It makes tern and that machine's other buildfarm members less
 vulnerable to noise failures from postmaster startup overrunning the 60s
 pg_ctl timeout.  Back-patch to 9.5, where pg_rewind was introduced.
 
 
    Robert Haas [Wed, 2 Sep 2015 20:21:38 +0000 (16:21 -0400)]     Update the SSL test suite for recent changes to TAP testing framework.
 
 listen_addresses needs to be handled differently now, and so does
 logging.
 
 Michael Paquier
 
 
    Teodor Sigaev [Wed, 2 Sep 2015 17:08:58 +0000 (20:08 +0300)]     Allow usage of huge maintenance_work_mem for GIN build.
 
 Currently, in-memory posting list during GIN build process is limited 1GB
 because of using repalloc. The patch replaces call of repalloc to repalloc_huge.
 It increases limit of posting list from 180 millions
 (1GB / sizeof(ItemPointerData)) to 4 billions limited by maxcount/count fields
 in GinEntryAccumulator and subsequent calls. Check added.
 
 Also, fix accounting of allocatedMemory during build to prevent integer
 overflow with maintenance_work_mem > 4GB.
 
 Robert Abraham <robert.abraham86@googlemail.com> with additions by me
 
 
    Tom Lane [Tue, 1 Sep 2015 23:25:58 +0000 (19:25 -0400)]     Document that PL/Python now returns floats using repr() not str().
  Commit 
1ce7a57ca neglected to update the user-facing documentation,
 which described the old behavior precisely.  
  Kevin Grittner [Tue, 1 Sep 2015 21:12:22 +0000 (16:12 -0500)]     Flush to show results of TestLib.pm (TAP) test as we go.
 
 It appears that some attempt was made to do this using autocommit,
 but it wasn't effective (at least on Ubuntu 14.04).
 
 
    Bruce Momjian [Tue, 1 Sep 2015 20:42:43 +0000 (16:42 -0400)]     pg_upgrade docs:  clarify rsync and move verification step
 
 These are adjustments based on someone using the new standby upgrade
 steps.
 
 Report by Andy Colson
 
 Backpatch through 9.5
 
 
    Robert Haas [Tue, 1 Sep 2015 19:30:19 +0000 (15:30 -0400)]     Allow notifications to bgworkers without database connections.
 
 Previously, if one background worker registered another background
 worker and set bgw_notify_pid while for the second background worker,
 it would not receive notifications from the postmaster unless, at the
 time the "parent" was registered, BGWORKER_BACKEND_DATABASE_CONNECTION
 was set.
 
 To fix, instead instead of including only those background workers that
 requested database connections in the postmater's BackendList, include
 them all.  There doesn't seem to be any reason not do this, and indeed
 it removes a significant amount of duplicated code.  The other option
 is to make PostmasterMarkPIDForWorkerNotify look at BackgroundWorkerList
 in addition to BackendList, but that adds more code duplication instead
 of getting rid of it.
 
 Patch by me.  Review and testing by Ashutosh Bapat.
 
 
    Alvaro Herrera [Tue, 1 Sep 2015 17:58:28 +0000 (14:58 -0300)]     Use <substeps> in pg_upgrade's procedure
  For clarity, so that the substeps are not numbered identically to the
 outer procedure's steps. 
 Per report from Andy Colson in
 http://www.postgresql.org/message-id/
55D789B5.
7040308@squeakycode.net  
  Tom Lane [Mon, 31 Aug 2015 22:10:04 +0000 (18:10 -0400)]     Clean up icc + ia64 situation.
  Some googling turned up multiple sources saying that older versions of icc
 do not accept gcc-compatible asm blocks on IA64, though asm does work on
 x86[_64].  This is apparently fixed as of icc version 12.0 or so, but that
 doesn't help us much; if we have to carry the extra implementation anyway,
 we may as well just use it for icc rather than add a compiler version test. 
 Hence, revert commit 
2c713d6ea29c91cd2cbd92fa801a61e55ea2a3c4 (though I
 separated the icc code from the gcc code completely, producing what seems
 cleaner code).  Document the state of affairs more explicitly, both in
 s_lock.h and postgres.c, and make some cosmetic adjustments around the
 IA64 code in s_lock.h.  
  Bruce Momjian [Mon, 31 Aug 2015 21:05:23 +0000 (17:05 -0400)]     docs:  remove outdated note about unique indexes
 
 Patch by Josh Kupershmidt
 
 Backpatch through 9.5
 
 
    Tom Lane [Mon, 31 Aug 2015 20:30:12 +0000 (16:30 -0400)]     Allow icc to use the same atomics infrastructure as gcc.
 
 The atomics headers were written under the impression that icc doesn't
 handle gcc-style asm blocks, but this is demonstrably false on x86_[64],
 because s_lock.h has done it that way for more than a decade.  (The jury is
 still out on whether this also works on ia64, so I'm leaving ia64-related
 code alone for the moment.)  Treat gcc and icc the same in these headers.
 This is less code and it should improve the results for icc, because we
 hadn't gotten around to providing icc-specific implementations for most
 of the atomics.
 
 
    Tom Lane [Mon, 31 Aug 2015 19:52:56 +0000 (15:52 -0400)]     Actually, it's not that hard to merge the Windows pqsignal code ...
 
 ... just need to typedef sigset_t and provide sigemptyset/sigfillset,
 which are easy enough.
 
 
    Tom Lane [Mon, 31 Aug 2015 18:43:10 +0000 (14:43 -0400)]     Remove theoretically-unnecessary special case for icc.
 
 Intel's icc is generally able to swallow asm blocks written for gcc.
 We have a few places that don't seem to know that, though.  Experiment
 with removing the special case for icc in ia64_get_bsp(); if the buildfarm
 likes this, I'll try more cleanup.  This is a good test case because it
 involves a "stop" notation that seems like it might not be very portable.
 
 
    Tom Lane [Mon, 31 Aug 2015 16:55:59 +0000 (12:55 -0400)]     Remove support for Unix systems without the POSIX signal APIs.
 
 Remove configure's checks for HAVE_POSIX_SIGNALS, HAVE_SIGPROCMASK, and
 HAVE_SIGSETJMP.  These APIs are required by the Single Unix Spec v2
 (POSIX 1997), which we generally consider to define our minimum required
 set of Unix APIs.  Moreover, no buildfarm member has reported not having
 them since 2012 or before, which means that even if the code is still live
 somewhere, it's untested --- and we've made plenty of signal-handling
 changes of late.  So just take these APIs as given and save the cycles for
 configure probes for them.
 
 However, we can't remove as much C code as I'd hoped, because the Windows
 port evidently still uses the non-POSIX code paths for signal masking.
 Since we're largely emulating these BSD-style APIs for Windows anyway, it
 might be a good thing to switch over to POSIX-like notation and thereby
 remove a few more #ifdefs.  But I'm not in a position to code or test that.
 In the meantime, we can at least make things a bit more transparent by
 testing for WIN32 explicitly in these places.
 
 
    Bruce Momjian [Mon, 31 Aug 2015 16:24:16 +0000 (12:24 -0400)]     psql:  print longtable as a possible \pset option
 
 For some reason this message was not updated when the longtable option
 was added.
 
 Backpatch through 9.3
 
 
    Magnus Hagander [Mon, 31 Aug 2015 12:07:17 +0000 (14:07 +0200)]     Small grammar fix
 
 Josh Kupershmidt
 
 
    Tom Lane [Mon, 31 Aug 2015 05:36:46 +0000 (01:36 -0400)]     Remove long-dead support for platforms without sig_atomic_t.
 
 C89 requires <signal.h> to define sig_atomic_t, and there is no evidence
 in the buildfarm that any supported platforms don't comply.  Remove the
 configure test to stop wasting build cycles on a purely historical issue.
 (Once upon a time, we cared about supporting C89-compliant compilers on
 machines with pre-C89 system headers, but that use-case has been dead for
 quite a few years.)
 
 I have some other fixes planned in this area, but let's start with this
 to see if the buildfarm produces any surprising results.
 
 
    Joe Conway [Sun, 30 Aug 2015 18:09:05 +0000 (11:09 -0700)]     Fix sepgsql regression tests.
 
 The regression tests for sepgsql were broken by changes in the
 base distro as-shipped policies. Specifically, definition of
 unconfined_t in the system default policy was changed to bypass
 multi-category rules, which the regression test depended on.
 Fix that by defining a custom privileged domain
 (sepgsql_regtest_superuser_t) and using it instead of system's
 unconfined_t domain. The new sepgsql_regtest_superuser_t domain
 performs almost like the current unconfined_t, but restricted by
 multi-category policy as the traditional unconfined_t was.
 
 The custom policy module is a self defined domain, and so should not
 be affected by related future system policy changes. However, it still
 uses the unconfined_u:unconfined_r pair for selinux-user and role.
 Those definitions have not been changed for several years and seem
 less risky to rely on than the unconfined_t domain. Additionally, if
 we define custom user/role, they would need to be manually defined
 at the operating system level, adding more complexity to an already
 non-standard and complex regression test.
 
 Back-patch to 9.3. The regression tests will need more work before
 working correctly on 9.2. Starting with 9.2, sepgsql has had dependencies
 on libselinux versions that are only available on newer distros with
 the changed set of policies (e.g. RHEL 7.x). On 9.1 sepgsql works
 fine with the older distros with original policy set (e.g. RHEL 6.x),
 and on which the existing regression tests work fine. We might want
 eventually change 9.1 sepgsql regression tests to be more independent
 from the underlying OS policies, however more work will be needed to
 make that happen and it is not clear that it is worth the effort.
 
 Kohei KaiGai with review by Adam Brightwell and me, commentary by
 Stephen, Alvaro, Tom, Robert, and others.
 
 
    Tom Lane [Sat, 29 Aug 2015 20:09:25 +0000 (16:09 -0400)]     Fix s_lock.h PPC assembly code to be compatible with native AIX assembler.
 
 On recent AIX it's necessary to configure gcc to use the native assembler
 (because the GNU assembler hasn't been updated to handle AIX 6+).  This
 caused PG builds to fail with assembler syntax errors, because we'd try
 to compile s_lock.h's gcc asm fragment for PPC, and that assembly code
 relied on GNU-style local labels.  We can't substitute normal labels
 because it would fail in any file containing more than one inlined use of
 tas().  Fortunately, that code is stable enough, and the PPC ISA is simple
 enough, that it doesn't seem like too much of a maintenance burden to just
 hand-code the branch offsets, removing the need for any labels.
 
 Note that the AIX assembler only accepts "$" for the location counter
 pseudo-symbol.  The usual GNU convention is "."; but it appears that all
 versions of gas for PPC also accept "$", so in theory this patch will not
 break any other PPC platforms.
 
 This has been reported by a few people, but Steve Underwood gets the credit
 for being the first to pursue the problem far enough to understand why it
 was failing.  Thanks also to Noah Misch for additional testing.
 
 
    Stephen Frost [Fri, 28 Aug 2015 15:39:37 +0000 (11:39 -0400)]     Ensure locks are acquired on RLS-added relations
 
 During fireRIRrules(), get_row_security_policies can add to
 securityQuals and withCheckOptions.  Make sure to lock any relations
 added at that point and before firing RIR rules on those expressions.
 
 Back-patch to 9.5 where RLS was added.
 
 
    Andres Freund [Fri, 28 Aug 2015 14:24:32 +0000 (16:24 +0200)]     Clarify what some historic terms in rewriteHandler.c mean.
  Discussion: 
20150827131352.GF2435@awork2.anarazel.de  
  Peter Eisentraut [Tue, 25 Aug 2015 13:58:49 +0000 (09:58 -0400)]     Simplify Perl chmod calls
 
 The Perl chmod function already takes multiple file arguments, so we
 don't need a separate looping function.
 
 
    Bruce Momjian [Thu, 27 Aug 2015 17:43:10 +0000 (13:43 -0400)]     dblink docs:  fix typo to use "connname" (3 n's), not "conname"
 
 This makes the parameter names match the documented prototype names.
 
 Report by Erwin Brandstetter
 
 Backpatch through 9.0
 
 
    Tom Lane [Wed, 26 Aug 2015 22:18:57 +0000 (18:18 -0400)]     Speed up HeapTupleSatisfiesMVCC() by replacing the XID-in-progress test.
 
 Rather than consulting TransactionIdIsInProgress to see if an in-doubt
 transaction is still running, consult XidInMVCCSnapshot.  That requires
 the same or fewer cycles as TransactionIdIsInProgress, and what's far
 more important, it does not access shared data structures (at least in the
 no-subxip-overflow case) so it incurs no contention.  Furthermore, we would
 have had to check XidInMVCCSnapshot anyway before deciding that we were
 allowed to see the tuple.
 
 There should never be a case where XidInMVCCSnapshot says a transaction is
 done while TransactionIdIsInProgress says it's still running.  The other
 way around is quite possible though.  The result of that difference is that
 HeapTupleSatisfiesMVCC will no longer set hint bits on tuples whose source
 transactions recently finished but are still running according to our
 snapshot.  The main cost of delaying the hint-bit setting is that repeated
 visits to a just-committed tuple, by transactions none of which have
 snapshots new enough to see the source transaction as done, will each
 execute TransactionIdIsCurrentTransactionId, which they need not have done
 before.  However, that's normally just a small overhead, and no contention
 costs are involved; so it seems well worth the benefit of removing
 TransactionIdIsInProgress calls during the life of the source transaction.
 
 The core idea for this patch is due to Jeff Janes, who also did the legwork
 proving its performance benefits.  His original proposal was to swap the
 order of TransactionIdIsInProgress and XidInMVCCSnapshot calls in some
 cases within HeapTupleSatisfiesMVCC.  That was a bit messy though.
 The idea that we could dispense with calling TransactionIdIsInProgress
 altogether was mine, as is the final patch.
 
 
    Bruce Momjian [Wed, 26 Aug 2015 18:46:48 +0000 (14:46 -0400)]     release notes:  abbreviated key speedup only for varchar/text
 
 Report by Peter Geoghegan
 
 Backpatch through 9.5
 
 
    Bruce Momjian [Wed, 26 Aug 2015 14:33:02 +0000 (10:33 -0400)]     9.5 release notes:  mention lack of char() sort improvements
 
 Report by Peter Geoghegan
 
 Backpatch through 9.5
 
 
    Joe Conway [Wed, 26 Aug 2015 01:45:44 +0000 (18:45 -0700)]     Reestablish alignment of pg_controldata output.
 
 Until 9.4, pg_controldata output was all aligned. At some point
 during 9.5 development, a new item was added, namely
 "Current track_commit_timestamp setting:" which is two characters
 too long to be aligned with the rest of the output. Fix this by
 removing the noise word "Current" and adding the requisite number
 of padding spaces. Since the six preceding items are also similar
 in nature, remove "Current" and pad those as well in order to
 maintain overall consistency. Backpatch to 9.5 where new offending
 item was added.
 
 
    Tom Lane [Tue, 25 Aug 2015 23:11:17 +0000 (19:11 -0400)]     Docs: be explicit about datatype matching for lead/lag functions.
 
 The default argument, if given, has to be of exactly the same datatype
 as the first argument; but this was not stated in so many words, and
 the error message you get about it might not lead your thought in the
 right direction.  Per bug #13587 from Robert McGehee.
 
 A quick scan says that these are the only two built-in functions with two
 anyelement arguments and no other polymorphic arguments.  There are plenty
 of cases of, eg, anyarray and anyelement, but those seem less likely to
 confuse.  For instance this doesn't seem terribly hard to figure out:
 "function array_remove(integer[], numeric) does not exist".  So I've
 contented myself with fixing these two cases.
 
 
    Tom Lane [Tue, 25 Aug 2015 18:06:13 +0000 (14:06 -0400)]     Further tweak wording of error messages about bad CONTINUE/EXIT statements.
 
 Per discussion, a little more verbosity seems called for.
 
 
    Tom Lane [Tue, 25 Aug 2015 17:09:48 +0000 (13:09 -0400)]     Limit the verbosity of memory context statistics dumps.
 
 We had a report from Stefan Kaltenbrunner of a case in which postmaster
 log files overran available disk space because multiple backends spewed
 enormous context stats dumps upon hitting an out-of-memory condition.
 Given the lack of similar reports, this isn't a common problem, but it
 still seems worth doing something about.  However, we don't want to just
 blindly truncate the output, because that might prevent diagnosis of OOM
 problems.  What seems like a workable compromise is to limit the dump to
 100 child contexts per parent, and summarize the space used within any
 additional child contexts.  That should help because practical cases where
 the dump gets long will typically be huge numbers of siblings under the
 same parent context; while the additional debugging value from seeing
 details about individual siblings beyond 100 will not be large, we hope.
 Anyway it doesn't take much code or memory space to do this, so let's try
 it like this and see how things go.
 
 Since the summarization mechanism requires passing totals back up anyway,
 I took the opportunity to add a "grand total" line to the end of the
 printout.
 
 
    Tom Lane [Tue, 25 Aug 2015 15:43:37 +0000 (11:43 -0400)]     Fix potential platform dependence in gist regression test.
 
 The results of the KNN-search test cases were indeterminate, as they asked
 the system to sort pairs of points that are exactly equidistant from the
 query reference point.  It's a bit surprising that we've seen no
 platform-specific failures from this in the buildfarm.  Perhaps IEEE-float
 math is well enough standardized that no such failures will ever occur on
 supported platforms ... but since this entire regression test has yet to be
 shipped in any non-alpha release, that seems like an unduly optimistic
 assumption.  Tweak the queries so that the correct output is uniquely
 defined.
 
 (The other queries in this test are also underdetermined; but it looks like
 they are regurgitating index rows in insertion order, so for the moment
 assume that that behavior is stable enough.)
 
 Per Greg Stark's experiments with VAX.  Back-patch to 9.5 where this test
 script was introduced.
 
 
    Tom Lane [Sun, 23 Aug 2015 21:34:47 +0000 (17:34 -0400)]     Tweak wording of syntax error messages about bad CONTINUE/EXIT statements.
 
 Try to avoid any possible confusion about what these messages mean.
 
 
    Tom Lane [Sun, 23 Aug 2015 19:15:47 +0000 (15:15 -0400)]     Reduce number of bytes examined by convert_one_string_to_scalar().
 
 Previously, convert_one_string_to_scalar() would examine up to 20 bytes of
 the input string, producing a scalar conversion with theoretical precision
 far greater than is of any possible use considering the other limitations
 on the accuracy of the resulting selectivity estimate.  (I think this
 choice might pre-date the caller-level logic that strips any common prefix
 of the strings; before that, there could have been value in scanning the
 strings far enough to use all the precision available in a double.)
 
 Aside from wasting cycles to little purpose, this choice meant that the
 "denom" variable could grow to as much as 256^21 = 3.74e50, which could
 overflow in some non-IEEE float arithmetics.  While we don't really support
 any machines with non-IEEE arithmetic anymore, this still seems like quite
 an unnecessary platform dependency.  Limit the scan to 12 bytes instead,
 thus limiting "denom" to 256^13 = 2.03e31, a value more likely to be
 computable everywhere.
 
 Per testing by Greg Stark, which showed overflow failures in our standard
 regression tests on VAX.
 
 
    Tom Lane [Sun, 23 Aug 2015 17:02:13 +0000 (13:02 -0400)]     Avoid use of float arithmetic in bipartite_match.c.
 
 Since the distances used in this algorithm are small integers (not more
 than the size of the U set, in fact), there is no good reason to use float
 arithmetic for them.  Use short ints instead: they're smaller, faster, and
 require no special portability assumptions.
 
 Per testing by Greg Stark, which disclosed that the code got into an
 infinite loop on VAX for lack of IEEE-style float infinities.  We don't
 really care all that much whether Postgres can run on a VAX anymore,
 but there seems sufficient reason to change this code anyway.
 
 In passing, make a few other small adjustments to make the code match
 usual Postgres coding style a bit better.
 
 
    Kevin Grittner [Sun, 23 Aug 2015 15:38:57 +0000 (10:38 -0500)]     Fix typo in C comment.
 
 Merlin Moncure
 Backpatch to 9.5, where the misspelling was introduced
 
 
    Peter Eisentraut [Sun, 23 Aug 2015 01:41:29 +0000 (21:41 -0400)]     Improve whitespace
 
 
    Peter Eisentraut [Sun, 23 Aug 2015 01:41:13 +0000 (21:41 -0400)]     Improve spelling
 
 
    Heikki Linnakangas [Sat, 22 Aug 2015 13:19:10 +0000 (14:19 +0100)]     Add hint to run "pgbench -i", if test tables don't exist.
 
 Fabien Coelho, reviewed by Julien Rouhaud
 
 
    Tom Lane [Sat, 22 Aug 2015 00:32:11 +0000 (20:32 -0400)]     Avoid O(N^2) behavior when enlarging SPI tuple table in spi_printtup().
 
 For no obvious reason, spi_printtup() was coded to enlarge the tuple
 pointer table by just 256 slots at a time, rather than doubling the size at
 each reallocation, as is our usual habit.  For very large SPI results, this
 makes for O(N^2) time spent in repalloc(), which of course soon comes to
 dominate the runtime.  Use the standard doubling approach instead.
 
 This is a longstanding performance bug, so back-patch to all active
 branches.
 
 Neil Conway
 
 
    Tom Lane [Sat, 22 Aug 2015 00:17:19 +0000 (20:17 -0400)]     Detect mismatched CONTINUE and EXIT statements at plpgsql compile time.
 
 With a bit of tweaking of the compile namestack data structure, we can
 verify at compile time whether a CONTINUE or EXIT is legal.  This is
 surely better than leaving it to runtime, both because earlier is better
 and because we can issue a proper error pointer.  Also, we can get rid
 of the ad-hoc old way of detecting the problem, which only took care of
 CONTINUE not EXIT.
 
 Jim Nasby, adjusted a bit by me
 
 
    Stephen Frost [Fri, 21 Aug 2015 19:51:24 +0000 (15:51 -0400)]     Clean up roles from roleattributes test
 
 Having the roles remain after the test ends up causing repeated 'make
 installcheck' runs to fail and may be risky from a security perspective
 also, so remove them at the end of the test.
 
 
    Alvaro Herrera [Fri, 21 Aug 2015 17:36:54 +0000 (14:36 -0300)]     Do not allow *timestamp to be passed as NULL
 
 The code had bugs that would cause crashes if NULL was passed as that
 argument (originally intended to mean not to bother returning its
 value), and after inspection it turns out that nothing seems interested
 in the case that *ts is NULL anyway.  Therefore, remove the partial
 checks intended to support that case.
 
 Author: Michael Paquier
 though I didn't include a proposed Assert.
 
 Backpatch to 9.5.
 
 
    Alvaro Herrera [Fri, 21 Aug 2015 17:11:58 +0000 (14:11 -0300)]     Remove ExecGetScanType function
  This became unused in 
a191a169d6d0b9558da4519e66510c4540204a51.  
  Tom Lane [Fri, 21 Aug 2015 16:21:37 +0000 (12:21 -0400)]     Fix plpython crash when returning string representation of a RECORD result.
 
 PLyString_ToComposite() blithely overwrote proc->result.out.d, even though
 for a composite result type the other union variant proc->result.out.r is
 the one that should be valid.  This could result in a crash if out.r had
 in fact been filled in (proc->result.is_rowtype == 1) and then somebody
 later attempted to use that data; as per bug #13579 from Paweł Michalak.
 
 Just to add insult to injury, it didn't work for RECORD results anyway,
 because record_in() would refuse the case.
 
 Fix by doing the I/O function lookup in a local PLyTypeInfo variable,
 as we were doing already in PLyObject_ToComposite().  This is not a great
 technique because any fn_extra data allocated by the input function will
 be leaked permanently (thanks to using TopMemoryContext as fn_mcxt).
 But that's a pre-existing issue that is much less serious than a crash,
 so leave it to be fixed separately.
 
 This bug would be a potential security issue, except that plpython is
 only available to superusers and the crash requires coding the function
 in a way that didn't work before today's patches.
 
 Add regression test cases covering all the supported methods of converting
 composite results.
 
 Back-patch to 9.1 where the faulty coding was introduced.
 
 
    Tom Lane [Fri, 21 Aug 2015 15:19:33 +0000 (11:19 -0400)]     Allow record_in() and record_recv() to work for transient record types.
  If we have the typmod that identifies a registered record type, there's no
 reason that record_in() should refuse to perform input conversion for it.
 Now, in direct SQL usage, record_in() will always be passed typmod = -1
 with type OID RECORDOID, because no typmodin exists for type RECORD, so the
 case can't arise.  However, some InputFunctionCall users such as PLs may be
 able to supply the right typmod, so we should allow this to support them. 
 Note: the previous coding and comment here predate commit 
59c016aa9f490b53.
 There has been no case since 8.1 in which the passed type OID wouldn't be
 valid; and if it weren't, this error message wouldn't be apropos anyway.
 Better to let lookup_rowtype_tupdesc complain about it. 
 Back-patch to 9.1, as this is necessary for my upcoming plpython fix.
 I'm committing it separately just to make it a bit more visible in the
 commit history.  
  Stephen Frost [Fri, 21 Aug 2015 12:22:22 +0000 (08:22 -0400)]     Rename 'cmd' to 'cmd_name' in CreatePolicyStmt
 
 To avoid confusion, rename CreatePolicyStmt's 'cmd' to 'cmd_name',
 parse_policy_command's 'cmd' to 'polcmd', and AlterPolicy's 'cmd_datum'
 to 'polcmd_datum', per discussion with Noah and as a follow-up to his
 correction of copynodes/equalnodes handling of the CreatePolicyStmt
 'cmd' field.
 
 Back-patch to 9.5 where the CreatePolicyStmt was introduced, as we
 are still only in alpha.
 
 
    Stephen Frost [Fri, 21 Aug 2015 12:22:22 +0000 (08:22 -0400)]     In AlterRole, make bypassrls an int
 
 When reworking bypassrls in AlterRole to operate the same way the other
 attribute handling is done, I missed that the variable was incorrectly a
 bool rather than an int.  This meant that on platforms with an unsigned
 char, we could end up with incorrect behavior during ALTER ROLE.
 
 Pointed out by Andres thanks to tests he did changing our bool to be the
 one from stdbool.h which showed this and a number of other issues.
 
 Add regression tests to test CREATE/ALTER role for the various role
 attributes.  Arrange to leave roles behind for testing pg_dumpall, but
 none which have the LOGIN attribute.
 
 Back-patch to 9.5 where the AlterRole bug exists.
 
 
    Peter Eisentraut [Fri, 21 Aug 2015 02:34:35 +0000 (22:34 -0400)]     doc: Whitespace and formatting fixes
 
 
    Tom Lane [Thu, 20 Aug 2015 16:28:15 +0000 (12:28 -0400)]     Remove xpath namespace-handling change from 9.5 release notes.
  Although commit 
79af9a1d2 was initially applied to HEAD only, we later
 back-patched the change into all branches (commits 
6bbf75192 et al).
 So it's not a new behavior in 9.5 and should not be release-noted here.  
  Peter Eisentraut [Wed, 19 Aug 2015 15:45:52 +0000 (11:45 -0400)]     Update config.guess and config.sub
 
 
    Kevin Grittner [Wed, 19 Aug 2015 13:20:55 +0000 (08:20 -0500)]     Fix bug in calculations of hash join buckets.
  Commit 
8cce08f168481c5fc5be4e7e29b968e314f1b41e used a left-shift
 on a literal of 1 that could (in large allocations) be shifted by
 31 or more bits.  This was assigned to a local variable that was
 already declared to be a long to protect against overruns of int,
 but the literal in this shift needs to be declared long to allow it
 to work correctly in some compilers. 
 Backpatch to 9.5, where the bug was introduced. 
 Report and patch by KaiGai Kohei, slighly modified based on
 discussion.  
  Tom Lane [Tue, 18 Aug 2015 23:22:37 +0000 (19:22 -0400)]     Fix a few bogus statement type names in plpgsql error messages.
 
 plpgsql's error location context messages ("PL/pgSQL function fn-name line
 line-no at stmt-type") would misreport a CONTINUE statement as being an
 EXIT, and misreport a MOVE statement as being a FETCH.  These are clear
 bugs that have been there a long time, so back-patch to all supported
 branches.
 
 In addition, in 9.5 and HEAD, change the description of EXECUTE from
 "EXECUTE statement" to just plain EXECUTE; there seems no good reason why
 this statement type should be described differently from others that have
 a well-defined head keyword.  And distinguish GET STACKED DIAGNOSTICS from
 plain GET DIAGNOSTICS.  These are a bit more of a judgment call, and also
 affect existing regression-test outputs, so I did not back-patch into
 stable branches.
 
 Pavel Stehule and Tom Lane
 
 
    Robert Haas [Tue, 18 Aug 2015 16:49:04 +0000 (12:49 -0400)]     psql: Make EXECUTE PROCEDURE tab completion a bit narrower.
 
 If the user has typed GRANT EXECUTE, the correct completion is "ON",
 not "PROCEDURE".
 
 Daniel Verite
 
 
    Tom Lane [Mon, 17 Aug 2015 23:39:35 +0000 (19:39 -0400)]     Fix performance bug from conflict between two previous improvements.
  My expanded-objects patch (commit 
1dc5ebc9077ab742) included code to make
 plpgsql pass expanded-object variables as R/W pointers to certain functions
 that are trusted for modifying such variables in-place.  However, that
 optimization got broken by commit 
6c82d8d1fdb1f126, which arranged to share
 a single ParamListInfo across most expressions evaluated by a plpgsql
 function.  We don't want a R/W pointer to be passed to other functions
 just because we decided one function was safe!  Fortunately, the breakage
 was in the other direction, of never passing a R/W pointer at all, because
 we'd always have pre-initialized the shared array slot with a R/O pointer.
 So it was still functionally correct, but we were back to O(N^2)
 performance for repeated use of "a := a || x".  To fix, force an unshared
 param array to be used when the R/W param optimization is active. 
 Commit 
6c82d8d1fdb1f126 is in HEAD only, so no need for a back-patch.  
  Andres Freund [Mon, 17 Aug 2015 09:51:52 +0000 (11:51 +0200)]     docs: Fix "typo" introduced in 
3f811c2d.  
Reported-By: Michael Paquier Discussion: CAB7nPqSco+RFw9C-VgbCpyurQB3OocS-fuTOa_gFnUy1EE-pyQ@mail.gmail.com  
  Andres Freund [Mon, 17 Aug 2015 09:15:46 +0000 (11:15 +0200)]     Improve configure test for the sse4.2 crc instruction.
  With optimizations enabled at least one compiler, clang 3.7, optimized
 away the crc intrinsics knowing that the result went on unused and has
 no side effects. That can trigger errors in code generation when the
 intrinsic is used, as we chose to use the intrinsics without any
 additional compiler flag. Return the computed value to prevent that. 
 With some more pedantic warning flags (-Wold-style-definition) the
 configure test failed to recognize the existence of _mm_crc32_u*
 intrinsics due to an independent warning in the test because the test
 turned on -Werror, but that's not actually needed here. 
 Discussion: 
20150814092039.GH4955@awork2.anarazel.de
 Backpatch: 9.5, where the use of crc intrinsics was integrated.  
  Heikki Linnakangas [Mon, 17 Aug 2015 07:11:47 +0000 (10:11 +0300)]     Fix reporting of skipped transactions in pgbench.
  Broken by commit 
1bc90f7a. 
 Fabien Coelho.  
  Tom Lane [Sat, 15 Aug 2015 18:31:04 +0000 (14:31 -0400)]     Add docs about postgres_fdw's setting of search_path and other GUCs.
 
 This behavior wasn't documented, but it should be because it's user-visible
 in triggers and other functions executed on the remote server.
 Per question from Adam Fuchs.
 
 Back-patch to 9.3 where postgres_fdw was added.
 
 
    Tom Lane [Sat, 15 Aug 2015 17:30:16 +0000 (13:30 -0400)]     Improve documentation about MVCC-unsafe utility commands.
 
 The table-rewriting forms of ALTER TABLE are MVCC-unsafe, in much the same
 way as TRUNCATE, because they replace all rows of the table with newly-made
 rows with a new xmin.  (Ideally, concurrent transactions with old snapshots
 would continue to see the old table contents, but the data is not there
 anymore --- and if it were there, it would be inconsistent with the table's
 updated rowtype, so there would be serious implementation problems to fix.)
 This was nowhere documented though, and the problem was only documented for
 TRUNCATE in a note in the TRUNCATE reference page.  Create a new "Caveats"
 section in the MVCC chapter that can be home to this and other limitations
 on serializable consistency.
 
 In passing, fix a mistaken statement that VACUUM and CLUSTER would reclaim
 space occupied by a dropped column.  They don't reconstruct existing tuples
 so they couldn't do that.
 
 Back-patch to all supported branches.
 
 
    Tom Lane [Sat, 15 Aug 2015 16:00:36 +0000 (12:00 -0400)]     Repair unsafe use of shared typecast-lookup table in plpgsql DO blocks.
  DO blocks use private simple_eval_estates to avoid intra-transaction memory
 leakage, cf commit 
c7b849a89.  I had forgotten about that while writing
 commit 
0fc94a5ba, but it means that expression execution trees created
 within a DO block disappear immediately on exiting the DO block, and hence
 can't safely be linked into plpgsql's session-wide cast hash table.
 To fix, give a DO block a private cast hash table to go with its private
 simple_eval_estate.  This is less efficient than one could wish, since
 DO blocks can no longer share any cast lookup work with other plpgsql
 execution, but it shouldn't be too bad; in any case it's no worse than
 what happened in DO blocks before commit 
0fc94a5ba. 
 Per bug #13571 from Feike Steenbergen.  Preliminary analysis by
 Oleksandr Shulgin.  
  Andres Freund [Sat, 15 Aug 2015 15:25:00 +0000 (17:25 +0200)]     Don't use function definitions looking like old-style ones.
 
 This fixes a bunch of somewhat pedantic warnings with new
 compilers. Since by far the majority of other functions definitions use
 the (void) style it just seems to be consistent to do so as well in the
 remaining few places.
 
 
    Andres Freund [Sat, 15 Aug 2015 15:02:47 +0000 (17:02 +0200)]     Correct type of waitMode variable in ExecInsertIndexTuples().
  It was a bool, even though it should be CEOUC_WAIT_MODE. That's unlikely
 to have a negative effect with the current definition of bool (char),
 but it's definitely wrong. 
 Discussion: 
20150812084351.GD8470@awork2.anarazel.de
 Backpatch: 9.5, where ON CONFLICT was merged  
  Andres Freund [Wed, 12 Aug 2015 14:49:36 +0000 (16:49 +0200)]     vacuumdb: Don't assign negative values to a boolean.
  Since 
a17923204736 (vacuumdb: enable parallel mode) -1 has been assigned
 to a boolean. That can, justifiedly, trigger compiler warnings. There's
 also no need for ternary logic, result was only ever set to 0 or -1. So
 don't. 
 Discussion: 
20150812084351.GD8470@awork2.anarazel.de
 Backpatch: 9.5  
  Andres Freund [Wed, 12 Aug 2015 14:02:20 +0000 (16:02 +0200)]     Don't use 'bool' as a struct member name in help_config.c.
  Doing so doesn't work if bool is a macro rather than a typedef. 
 Although c.h spends some effort to support configurations where bool is
 a preexisting macro, help_config.c has existed this way since
 2003 (b700a6), and there have not been any reports of
 problems. Backpatch anyway since this is as riskless as it gets. 
 Discussion: 
20150812084351.GD8470@awork2.anarazel.de
 Backpatch: 9.0-master  
  Andres Freund [Wed, 12 Aug 2015 13:52:10 +0000 (15:52 +0200)]     Use the correct type for TableInfo->relreplident.
  Mistakenly relreplident was stored as a bool. That works today as c.h
 typedefs bool to a char, but isn't very future proof. 
 Discussion: 
20150812084351.GD8470@awork2.anarazel.de
 Backpatch: 9.4 where replica identity was introduced.  
  Robert Haas [Sat, 15 Aug 2015 03:13:13 +0000 (23:13 -0400)]     Remove unused expected-output file.
 
 
    Robert Haas [Sat, 15 Aug 2015 02:39:09 +0000 (22:39 -0400)]     Remove bogus step from test_decoding isolation tests.
  Commit 
43b4a16817c8b5568cec72f3b0e1c8209f5ac7f7 made the isolation
 tester reject duplicate step names, and it turns out that the
 test_decoding module's concurrent_ddl_dml isolation test has a
 duplicate name.  I think the second definition isn't actually getting
 used, so just remove it. 
 Per buildfarm.  
  Robert Haas [Sat, 15 Aug 2015 02:09:27 +0000 (22:09 -0400)]     Reject isolation test specifications with duplicate step names.
 
 alter-table-1.spec has such a case, so change one instance of step
 rx1 to rx3 instead.
 
 
    Noah Misch [Sat, 15 Aug 2015 00:23:13 +0000 (20:23 -0400)]     Encoding PG_UHC is code page 949.
 
 This fixes presentation of non-ASCII messages to the Windows event log
 and console in rare cases involving Korean locale.  Processes like the
 postmaster and checkpointer, but not processes attached to databases,
 were affected.  Back-patch to 9.4, where MessageEncoding was introduced.
 The problem exists in all supported versions, but this change has no
 effect in the absence of the code recognizing PG_UHC MessageEncoding.
 
 Noticed while investigating bug #13427 from Dmitri Bourlatchkov.
 
 
    Noah Misch [Sat, 15 Aug 2015 00:23:09 +0000 (20:23 -0400)]     Restore old pgwin32_message_to_UTF16() behavior outside transactions.
  Commit 
49c817eab78c6f0ce8c3bf46766b73d6cf3190b7 replaced with a hard
 error the dubious pg_do_encoding_conversion() behavior when outside a
 transaction.  Reintroduce the historic soft failure locally within
 pgwin32_message_to_UTF16().  This fixes errors when writing messages in
 less-common encodings to the Windows event log or console.  Back-patch
 to 9.4, where the aforementioned commit first appeared. 
 Per bug #13427 from Dmitri Bourlatchkov.  
  Peter Eisentraut [Fri, 14 Aug 2015 16:10:35 +0000 (12:10 -0400)]     Update key words table for 9.5
 
 
    Simon Riggs [Fri, 14 Aug 2015 13:19:28 +0000 (14:19 +0100)]     Reduce lock levels for ALTER TABLE SET autovacuum storage options
 
 Reduce lock levels down to ShareUpdateExclusiveLock for all autovacuum-related
 relation options when setting them using ALTER TABLE.
 
 Add infrastructure to allow varying lock levels for relation options in later
 patches. Setting multiple options together uses the highest lock level required
 for any option. Works for both main and toast tables.
 
 Fabrízio Mello, reviewed by Michael Paquier, mild edit and additional regression
 tests from myself
 
 
    Peter Eisentraut [Wed, 3 Jun 2015 23:52:08 +0000 (19:52 -0400)]     PL/Python: Make tests pass with Python 3.5
 
 The error message wording for AttributeError has changed in Python 3.5.
 For the plpython_error test, add a new expected file.  In the
 plpython_subtransaction test, we didn't really care what the exception
 is, only that it is something coming from Python.  So use a generic
 exception instead, which has a message that doesn't vary across
 versions.
 
 
    Alvaro Herrera [Thu, 13 Aug 2015 22:28:54 +0000 (19:28 -0300)]     MSVC: Exclude 'brin' contrib module
 
 The build script is not able to parse the Makefile, so remove it.
 
 
    Alvaro Herrera [Thu, 13 Aug 2015 17:41:52 +0000 (14:41 -0300)]     Re-add BRIN isolation test
 
 This time, instead of using a core isolation test, put it on its own
 test module; this way it can require the pageinspect module to be
 present before running.
 
 The module's Makefile is loosely modeled after test_decoding's, so that
 it's easy to add further tests for either pg_regress or isolationtester
 later.
 
 Backpatch to 9.5.
 
 
    Tom Lane [Thu, 13 Aug 2015 17:25:01 +0000 (13:25 -0400)]     Improve regression test case to avoid depending on system catalog stats.
  In commit 
95f4e59c32866716 I added a regression test case that examined
 the plan of a query on system catalogs.  That isn't a terribly great idea
 because the catalogs tend to change from version to version, or even
 within a version if someone makes an unrelated regression-test change that
 populates the catalogs a bit differently.  Usually I try to make planner
 test cases rely on test tables that have not changed since Berkeley days,
 but I got sloppy in this case because the submitted crasher example queried
 the catalogs and I didn't spend enough time on rewriting it.  But it was a
 problem waiting to happen, as I was rudely reminded when I tried to port
 that patch into Salesforce's Postgres variant :-(.  So spend a little more
 effort and rewrite the query to not use any system catalogs.  I verified
 that this version still provokes the Assert if 
95f4e59c32866716's code fix
 is reverted. 
 I also removed the EXPLAIN output from the test, as it turns out that the
 assertion occurs while considering a plan that isn't the one ultimately
 selected anyway; so there's no value in risking any cross-platform
 variation in that printout. 
 Back-patch to 9.2, like the previous patch.  
  Alvaro Herrera [Thu, 13 Aug 2015 16:02:10 +0000 (13:02 -0300)]     Use materialize SRF mode in brin_page_items
 
 This function was using the single-value-per-call mechanism, but the
 code relied on a relcache entry that wasn't kept open across calls.
 This manifested as weird errors in buildfarm during the short time that
 the "brin-1" isolation test lived.
 
 Backpatch to 9.5, where it was introduced.
 
 
    Heikki Linnakangas [Thu, 13 Aug 2015 11:35:02 +0000 (14:35 +0300)]     Run autoheader to add a few missing #defines to pg_config.h.in.
 
 These are emitted by the new ax_pthread.m4 script version. They are not
 used for anything in PostgreSQL, but let's keep the generated header file
 up-to-date.
 
 Andres Freund
 
 
    Michael Meskes [Thu, 13 Aug 2015 11:22:29 +0000 (13:22 +0200)]     Fix declaration of isarray variable.
 
 Found and fixed by Andres Freund.
 
 
    Alvaro Herrera [Thu, 13 Aug 2015 03:12:07 +0000 (00:12 -0300)]     Fix unitialized variables
  As complained by clang, reported by Andres Freund.  Brown paper bag bug
 in 
ccc4c074994d. 
 Add some comments, too. 
 Backpatch to 9.5, like that one.  
  Tom Lane [Thu, 13 Aug 2015 01:18:45 +0000 (21:18 -0400)]     Undo mistaken tightening in join_is_legal().
  One of the changes I made in commit 
8703059c6b55c427 turns out not to have
 been such a good idea: we still need the exception in join_is_legal() that
 allows a join if both inputs already overlap the RHS of the special join
 we're checking.  Otherwise we can miss valid plans, and might indeed fail
 to find a plan at all, as in recent report from Andreas Seltenreich. 
 That code was added way back in commit 
c17117649b9ae23d, but I failed to
 include a regression test case then; my bad.  Put it back with a better
 explanation, and a test this time.  The logic does end up a bit different
 than before though: I now believe it's appropriate to make this check
 first, thereby allowing such a case whether or not we'd consider the
 previous SJ(s) to commute with this one.  (Presumably, we already decided
 they did; but it was confusing to have this consideration in the middle
 of the code that was handling the other case.) 
 Back-patch to all active branches, like the previous patch.  
  Alvaro Herrera [Wed, 12 Aug 2015 17:20:38 +0000 (14:20 -0300)]     Close some holes in BRIN page assignment
  In some corner cases, it is possible for the BRIN index relation to be
 extended by brin_getinsertbuffer but the new page not be used
 immediately for anything by its callers; when this happens, the page is
 initialized and the FSM is updated (by brin_getinsertbuffer) with the
 info about that page, but these actions are not WAL-logged.  A later
 index insert/update can use the page, but since the page is already
 initialized, the initialization itself is not WAL-logged then either.
 Replay of this sequence of events causes recovery to fail altogether. 
 There is a related corner case within brin_getinsertbuffer itself, in
 which we extend the relation to put a new index tuple there, but later
 find out that we cannot do so, and do not return the buffer; the page
 obtained from extension is not even initialized.  The resulting page is
 lost forever. 
 To fix, shuffle the code so that initialization is not the
 responsibility of brin_getinsertbuffer anymore, in normal cases;
 instead, the initialization is done by its callers (brin_doinsert and
 brin_doupdate) once they're certain that the page is going to be used.
 When either those functions determine that the new page cannot be used,
 before bailing out they initialize the page as an empty regular page,
 enter it in FSM and WAL-log all this.  This way, the page is usable for
 future index insertions, and WAL replay doesn't find trying to insert
 tuples in pages whose initialization didn't make it to the WAL.  The
 same strategy is used in brin_getinsertbuffer when it cannot return the
 new page. 
 Additionally, add a new step to vacuuming so that all pages of the index
 are scanned; whenever an uninitialized page is found, it is initialized
 as empty and WAL-logged.  This closes the hole that the relation is
 extended but the system crashes before anything is WAL-logged about it.
 We also take this opportunity to update the FSM, in case it has gotten
 out of date. 
 Thanks to Heikki Linnakangas for finding the problem that kicked some
 additional analysis of BRIN page assignment code. 
 Backpatch to 9.5, where BRIN was introduced. 
 Discussion: https://www.postgresql.org/message-id/
20150723204810.GY5596@postgresql.org  
  Andres Freund [Wed, 12 Aug 2015 15:35:50 +0000 (17:35 +0200)]     Remove duplicated assignment in pg_create_physical_replication_slot.
 
 Reported-By: Gurjeet Singh
 
    Andres Freund [Wed, 12 Aug 2015 15:35:50 +0000 (17:35 +0200)]     Handle PQresultErrorField(PG_DIAG_SQLSTATE) returning NULL in streamutil.c.
  In 
ff27db5d I missed that PQresultErrorField() may return NULL if
 there's no sqlstate associated with an error.  
Spotted-By: Coverity Reported-By: Michael Paquier Discussion: CAB7nPqQ3o10SY6NVdU4pjq85GQTN5tbbkq2gnNUh2fBNU3rKyQ@mail.gmail.com
 Backpatch: 9.5, like 
ff27db5d    Andres Freund [Wed, 12 Aug 2015 15:35:50 +0000 (17:35 +0200)]     Fix two off-by-one errors in bufmgr.c.
  In 
4b4b680c I passed a buffer index number (starting from 0) instead of
 a proper Buffer id (which start from 1 for shared buffers) in two
 places. 
 This wasn't noticed so far as one of those locations isn't compiled at
 all (PrintPinnedBufs) and the other one (InvalidBuffer) requires a
 unlikely, but possible, set of circumstances to trigger a symptom. 
 To reduce the likelihood of such incidents a bit also convert existing
 open coded mappings from buffer descriptors to buffer ids with
 BufferDescriptorGetBuffer(). 
 Author: Qingqing Zhou 
Reported-By: Qingqing Zhou Discussion: CAJjS0u2ai9ooUisKtkV8cuVUtEkMTsbK8c7juNAjv8K11zeCQg@mail.gmail.com
 Backpatch: 9.5 where the private ref count infrastructure was introduced