Tom Lane [Tue, 31 Mar 2020 16:57:55 +0000 (12:57 -0400)]     Teach pg_ls_dir_files() to ignore ENOENT failures from stat().
  Buildfarm experience shows that this function can fail with ENOENT
 if some other process unlinks a file between when we read the directory
 entry and when we try to stat() it.  The problem is old but we had
 not noticed it until 
085b6b667 added regression test coverage. 
 To fix, just ignore ENOENT failures.  There is one other case that
 this might hide: a symlink that points to nowhere.  That seems okay
 though, at least better than erroring. 
 Back-patch to v10 where this function was added, since the regression
 test cases were too. 
 Discussion: https://postgr.es/m/
20200308173103.GC1357@telsasoft.com  
  Tom Lane [Tue, 31 Mar 2020 15:14:30 +0000 (11:14 -0400)]     Fix lquery's NOT handling, and add ability to quantify non-'*' items.
 
 The existing implementation of the ltree ~ lquery match operator is
 sufficiently complex and undocumented that it's hard to tell exactly
 what it does.  But one thing it clearly gets wrong is the combination
 of NOT symbols (!) and '*' symbols.  A pattern such as '*.!foo.*'
 should, by any ordinary understanding of regular expression behavior,
 match any ltree that has at least one label that's not "foo".  As best
 we can tell by experimentation, what it's actually matching is any
 ltree in which *no* label is "foo".  That's surprising, and not at all
 what the documentation says.
 
 Now, that's arguably a useful behavior, so if we rewrite to fix the
 bug we should provide some other way to get it.  To do so, add the
 ability to attach lquery quantifiers to non-'*' items as well as '*'s.
 Then the pattern '!foo{,}' expresses "any ltree in which no label is
 foo".  For backwards compatibility, the default quantifier for non-'*'
 items has to be "{1}", although the default for '*' items is '{,}'.
 I wouldn't have done it like that in a green field, but it's not
 totally horrible.
 
 Armed with that, rewrite checkCond() from scratch.  Treating '*' and
 non-'*' items alike makes it simpler, not more complicated, so that
 the function actually gets a lot shorter than it was.
 
 Filip Rembiałkowski, Tom Lane, Nikita Glukhov, per a very
 ancient bug report from M. Palm
 
 Discussion: https://postgr.es/m/CAP_rww=waX2Oo6q+MbMSiZ9ktdj6eaJj0cQzNu=Ry2cCDij5fw@mail.gmail.com
 
 
    Tom Lane [Tue, 31 Mar 2020 14:30:59 +0000 (10:30 -0400)]     Improve error messages in ltree_in and lquery_in.
  Ensure that the type name is mentioned in all cases (bare "syntax error"
 isn't that helpful).  Avoid using the term "level", since that's not
 used in the documentation.  Phrase error position reports as "at
 character N" not "in position N"; the latter seems ambiguous, and it's
 certainly not how we say it elsewhere.  For the same reason, make the
 character position values be 1-based not 0-based.  Provide a position
 in more cases.  (I continued to leave that out of messages complaining
 about end-of-input, where it seemed pointless, as well as messages
 complaining about overall input complexity, where fingering any one part
 of the input would be arbitrary.) 
 Discussion: https://postgr.es/m/15582.
1585529626@sss.pgh.pa.us  
  Alexander Korotkov [Tue, 31 Mar 2020 14:51:57 +0000 (17:51 +0300)]     Improve error reporting in opclasscmds.c
  This commit improves error reporting introduced by 
911e702077.  It puts
 argument of errmsg() to the single line for easier grepping source for error
 text.  Also it improves wording of errhint().  
  Magnus Hagander [Tue, 31 Mar 2020 14:00:06 +0000 (16:00 +0200)]     Fix assorted typos
 
 Author: Daniel Gustafsson <daniel@yesql.se>
 
 
    Peter Eisentraut [Tue, 31 Mar 2020 06:40:32 +0000 (08:40 +0200)]     Fix INSERT OVERRIDING USER VALUE behavior
 
 The original implementation disallowed using OVERRIDING USER VALUE on
 identity columns defined as GENERATED ALWAYS, which is not per
 standard.  So allow that now.
 
 Expand documentation and tests around this.
 
 Author: Dean Rasheed <dean.a.rasheed@gmail.com>
 Reviewed-by: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
 Reviewed-by: Vik Fearing <vik@postgresfriends.org>
 Discussion: https://www.postgresql.org/message-id/flat/CAEZATCVrh2ufCwmzzM%3Dk_OfuLhTTPBJCdFkimst2kry4oHepuQ%40mail.gmail.com
 
 
    Michael Paquier [Tue, 31 Mar 2020 06:33:04 +0000 (15:33 +0900)]     Move routine definitions of xlogarchive.c to a new header file
  The definitions of the routines defined in xlogarchive.c have been part
 of xlog_internal.h which is included by several frontend tools, but all
 those routines are only called by the backend.  More cleanup could be
 done within xlog_internal.h, but that's already a nice cut. 
 This will help a follow-up patch for pg_rewind where handling of
 restore_command is added for frontends. 
 Author: Alexey Kondratov, Michael Paquier 
Reviewed-by: Álvaro Herrera, Alexander Korotkov Discussion: https://postgr.es/m/
a3acff50-5a0d-9a2c-b3b2-
ee36168955c1@postgrespro.ru  
  Peter Eisentraut [Tue, 31 Mar 2020 06:25:03 +0000 (08:25 +0200)]     Update SQL features
 
 Set T653 to supported.  This has always been possible.
 
 
    Amit Kapila [Tue, 31 Mar 2020 04:04:49 +0000 (09:34 +0530)]     Avoid calls to RelationGetRelationName() and RelationGetNamespace() in
 vacuum code. 
 After commit 
b61d161c14, during vacuum, we cache the information of
 relation name and relation namespace in local structure LVRelStats so that
 we can use it in an error callback function.  We can use the cached
 information to avoid the calls to RelationGetRelationName(),
 RelationGetNamespace() and get_namespace_name().  This is mainly for the
 consistent in vacuum code path but it will avoid the extra syscache lookup
 we do in get_namespace_name(). 
 Author: Justin Pryzby 
Reviewed-by: Amit Kapila Discussion: https://www.postgresql.org/message-id/
20191120210600.GC30362@telsasoft.com  
  Peter Geoghegan [Tue, 31 Mar 2020 00:34:12 +0000 (17:34 -0700)]     Further simplify nbtree high key truncation.
  Commit 
7c2dbc69 reorganized _bt_truncate() in a way that enables a
 further simplification that I (pgeoghegan) missed:  Since we mark the
 tuple that is returned to the caller as a pivot tuple before the point
 where its heap TID is set as of 
7c2dbc69, it is possible to use the high
 level BTreeTupleGetHeapTID() inline function to get an item pointer.  Do
 it that way now.  This approach is clearer and more maintainable.  
  Michael Paquier [Mon, 30 Mar 2020 23:27:47 +0000 (08:27 +0900)]     Revert "Skip redundant anti-wraparound vacuums"
  This reverts commit 
2aa6e33, that added a fast path to skip
 anti-wraparound and non-aggressive autovacuum jobs (these have no sense
 as anti-wraparound implies aggressive).  With a cluster using a high
 amount of relations with a portion of them being heavily updated, this
 could cause autovacuum to lock down, with autovacuum workers attempting
 repeatedly those jobs on the same relations for the same database, that
 just kept being skipped.  This lock down can be solved with a manual
 VACUUM FREEZE. 
 Justin King has reported one environment where the issue happened, and
 Julien Rouhaud and I have been able to reproduce it in a second
 environment.  With a very aggressive autovacuum_freeze_max_age,
 triggering those jobs with pgbench is a matter of minutes, and hitting
 the lock down is a lot harder (my local tests failed to do that). 
 Note that anti-wraparound and non-aggressive jobs can only be triggered
 on a subset of shared catalogs:
 - pg_auth_members
 - pg_authid
 - pg_database
 - pg_replication_origin
 - pg_shseclabel
 - pg_subscription
 - pg_tablespace
 While the lock down was possible down to v12, the root cause of those
 jobs is a much older issue, which needs more analysis. 
 Bonus thanks to Andres Freund for the discussion.  
Reported-by: Justin King Discussion: https://postgr.es/m/CAE39h22zPLrkH17GrkDgAYL3kbjvySYD1io+rtnAUFnaJJVS4g@mail.gmail.com
 Backpatch-through: 12  
  Peter Geoghegan [Mon, 30 Mar 2020 22:52:39 +0000 (15:52 -0700)]     Refactor nbtree high key truncation.
  Simplify _bt_truncate(), the routine that generates truncated leaf page
 high keys.  Remove a micro-optimization that avoided a second palloc0()
 call (this was used when a heap TID was needed in the final pivot tuple,
 though only when the index happened to not be an INCLUDE index). 
 Removing this dubious micro-optimization allows _bt_truncate() to use
 the index_truncate_tuple() indextuple.c utility routine in all cases.
 This was already the common case. 
 This commit is a HEAD-only follow up to bugfix commit 
4b42a899.  
  Andres Freund [Mon, 30 Mar 2020 20:51:12 +0000 (13:51 -0700)]     Deduplicate PageIsNew() check in lazy_scan_heap().
 
 The recheck isn't needed anymore, as RelationGetBufferForTuple() now
 extends the relation with RBM_ZERO_AND_LOCK. Previously we needed to
 handle the fact that relation extension extended the relation and then
 separately acquired a lock on the page - while expecting that the page
 is empty.
 
 Reported-By: Ranier Vilela
 Discussion: https://postgr.es/m/CAEudQArA_=J0D5T258xsCY6Xtf6wiH4b=QDPDgVS+WZUN10WDw@mail.gmail.com
 
 
    Alexander Korotkov [Mon, 30 Mar 2020 20:45:03 +0000 (23:45 +0300)]     Fix missing SP-GiST support in 
911e702077  911e702077 misses setting of amoptsprocnum for SP-GiST.  This commit fixes
 that.  
  Alexander Korotkov [Mon, 30 Mar 2020 20:40:22 +0000 (23:40 +0300)]     Remove rudiments of supporting procnum == 0 from 
911e702077  Early versions of opclass options patch uses zero support procedure as opclass
 options procedure.  This commit removes rudiments of it, which were committed
 in 
911e702077.  Also, it implements correct handling of amoptsprocnum == 0.  
  Peter Geoghegan [Mon, 30 Mar 2020 19:03:59 +0000 (12:03 -0700)]     Consistently truncate non-key suffix columns.
  INCLUDE indexes failed to have their non-key attributes physically
 truncated away in certain rare cases.  This led to physically larger
 pivot tuples that contained useless non-key attribute values.  The
 impact on users should be negligible, but this is still clearly a
 regression (Postgres 11 supports INCLUDE indexes, and yet was not
 affected). 
 The bug appeared in commit 
dd299df8, which introduced "true" suffix
 truncation of key attributes. 
 Discussion: https://postgr.es/m/CAH2-Wz=E8pkV9ivRSFHtv812H5ckf8s1-yhx61_WrJbKccGcrQ@mail.gmail.com
 Backpatch: 12-, where "true" suffix truncation was introduced.  
  Alexander Korotkov [Mon, 30 Mar 2020 16:17:11 +0000 (19:17 +0300)]     Implement operator class parameters
  PostgreSQL provides set of template index access methods, where opclasses have
 much freedom in the semantics of indexing.  These index AMs are GiST, GIN,
 SP-GiST and BRIN.  There opclasses define representation of keys, operations on
 them and supported search strategies.  So, it's natural that opclasses may be
 faced some tradeoffs, which require user-side decision.  This commit implements
 opclass parameters allowing users to set some values, which tell opclass how to
 index the particular dataset. 
 This commit doesn't introduce new storage in system catalog.  Instead it uses
 pg_attribute.attoptions, which is used for table column storage options but
 unused for index attributes. 
 In order to evade changing signature of each opclass support function, we
 implement unified way to pass options to opclass support functions.  Options
 are set to fn_expr as the constant bytea expression.  It's possible due to the
 fact that opclass support functions are executed outside of expressions, so
 fn_expr is unused for them. 
 This commit comes with some examples of opclass options usage.  We parametrize
 signature length in GiST.  That applies to multiple opclasses: tsvector_ops,
 gist__intbig_ops, gist_ltree_ops, gist__ltree_ops, gist_trgm_ops and
 gist_hstore_ops.  Also we parametrize maximum number of integer ranges for
 gist__int_ops.  However, the main future usage of this feature is expected
 to be json, where users would be able to specify which way to index particular
 json parts. 
 Catversion is bumped. 
 Discussion: https://postgr.es/m/
d22c3a18-31c7-1879-fc11-
4c1ce2f5e5af%40postgrespro.ru
 Author: Nikita Glukhov, revised by me 
Reviwed-by: Nikolay Shaplov, Robert Haas, Tom Lane, Tomas Vondra, Alvaro Herrera   Peter Eisentraut [Mon, 30 Mar 2020 15:30:44 +0000 (17:30 +0200)]     Allow using Unix-domain sockets on Windows in tests
  The test suites currently don't use Unix-domain sockets on Windows.
 This optionally allows enabling that by setting the environment
 variable PG_TEST_USE_UNIX_SOCKETS. 
 This should currently be considered experimental.  In particular,
 pg_regress.c contains some comments that the cleanup code for
 Unix-domain sockets doesn't work correctly under Windows, which hasn't
 been an problem until now.  But it's good enough for locally
 supervised testing of the functionality.  
Reviewed-by: Andrew Dunstan <andrew.dunstan@2ndquadrant.com> Discussion: https://www.postgresql.org/message-id/flat/
54bde68c-d134-4eb8-5bd3-
8af33b72a010@2ndquadrant.com  
  Tom Lane [Mon, 30 Mar 2020 15:14:58 +0000 (11:14 -0400)]     Be more careful about extracting encoding from locale strings on Windows.
  GetLocaleInfoEx() can fail on strings that setlocale() was perfectly
 happy with.  A common way for that to happen is if the locale string
 is actually a Unix-style string, say "et_EE.UTF-8".  In that case,
 what's after the dot is an encoding name, not a Windows codepage number;
 blindly treating it as a codepage number led to failure, with a fairly
 silly error message.  Hence, check to see if what's after the dot is
 all digits, and if not, treat it as a literal encoding name rather than
 a codepage number.  This will do the right thing with many Unix-style
 locale strings, and produce a more sensible error message otherwise. 
 Somewhat independently of that, treat a zero (CP_ACP) result from
 GetLocaleInfoEx() as meaning that we must use UTF-8 encoding. 
 Back-patch to all supported branches. 
 Juan José Santamaría Flecha 
 Discussion: https://postgr.es/m/24905.
1585445371@sss.pgh.pa.us  
  David Rowley [Mon, 30 Mar 2020 10:41:11 +0000 (23:41 +1300)]     Attempt to fix unstable regression tests, take 2
  Following up on 
2dc16efed, petalura has suffered some additional
 failures in stats_ext which again appear to be around the timing of an
 autovacuum during the test, causing instability in the row estimates. 
 Again, let's fix this by explicitly performing a VACUUM on the table
 and not leave it to happen by chance of an autovacuum pass. 
 Discussion: https://postgr.es/m/CAApHDvok5hmXr%2BbUbJe7%2B2sQzWo4B_QzSk7RKFR9fP6BjYXx5g%40mail.gmail.com  
  Fujii Masao [Mon, 30 Mar 2020 08:35:03 +0000 (17:35 +0900)]     Report waiting via PS while recovery is waiting for buffer pin in hot standby.
 
 Previously while the startup process was waiting for the recovery conflict
 with snapshot, tablespace or lock to be resolved, waiting was reported in
 PS display, but not in the case of recovery conflict with buffer pin.
 This commit makes the startup process in hot standby report waiting via PS
 while waiting for the conflicts with other backends holding buffer pins to
 be resolved.
 
 Author: Masahiko Sawada
 Reviewed-by: Fujii Masao
 Discussion: https://postgr.es/m/CA+fd4k4mXWTwfQLS3RPwGr4xnfAEs1ysFfgYHvmmoUgv6Zxvmg@mail.gmail.com
 
 
    Peter Eisentraut [Mon, 30 Mar 2020 07:19:40 +0000 (09:19 +0200)]     Improve handling of parameter differences in physical replication
  When certain parameters are changed on a physical replication primary,
 this is communicated to standbys using the XLOG_PARAMETER_CHANGE WAL
 record.  The standby then checks whether its own settings are at least
 as big as the ones on the primary.  If not, the standby shuts down
 with a fatal error. 
 The correspondence of settings between primary and standby is required
 because those settings influence certain shared memory sizings that
 are required for processing WAL records that the primary might send.
 For example, if the primary sends a prepared transaction, the standby
 must have had max_prepared_transaction set appropriately or it won't
 be able to process those WAL records. 
 However, fatally shutting down the standby immediately upon receipt of
 the parameter change record might be a bit of an overreaction.  The
 resources related to those settings are not required immediately at
 that point, and might never be required if the activity on the primary
 does not exhaust all those resources.  If we just let the standby roll
 on with recovery, it will eventually produce an appropriate error when
 those resources are used. 
 So this patch relaxes this a bit.  Upon receipt of
 XLOG_PARAMETER_CHANGE, we still check the settings but only issue a
 warning and set a global flag if there is a problem.  Then when we
 actually hit the resource issue and the flag was set, we issue another
 warning message with relevant information.  At that point we pause
 recovery, so a hot standby remains usable.  We also repeat the last
 warning message once a minute so it is harder to miss or ignore.  
Reviewed-by: Sergei Kornilov <sk@zsrv.org> Reviewed-by: Masahiko Sawada <masahiko.sawada@2ndquadrant.com> Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/
4ad69a4c-cc9b-0dfe-0352-
8b1b0cd36c7b@2ndquadrant.com  
  Peter Eisentraut [Mon, 30 Mar 2020 06:55:55 +0000 (08:55 +0200)]     Add new part SQL/MDA to information_schema.sql_parts
 
 
    Fujii Masao [Mon, 30 Mar 2020 04:51:05 +0000 (13:51 +0900)]     Allow the planner-related functions and hook to accept the query string.
  This commit adds query_string argument into the planner-related functions
 and hook and allows us to pass the query string to them. 
 Currently there is no user of the query string passed. But the upcoming patch
 for the planning counters will add the planning hook function into
 pg_stat_statements and the function will need the query string. So this change
 will be necessary for that patch. 
 Also this change is useful for some extensions that want to use the query
 string in their planner hook function. 
 Author: Pascal Legrand, Julien Rouhaud 
Reviewed-by: Yoshikazu Imai, Tom Lane, Fujii Masao Discussion: https://postgr.es/m/CAOBaU_bU1m3_XF5qKYtSj1ua4dxd=FWDyh2SH4rSJAUUfsGmAQ@mail.gmail.com
 Discussion: https://postgr.es/m/
1583789487074-0.post@n3.nabble.com  
  Fujii Masao [Mon, 30 Mar 2020 03:15:26 +0000 (12:15 +0900)]     Expose BufferUsageAccumDiff().
  Previously pg_stat_statements calculated the difference of buffer counters
 by its own code even while BufferUsageAccumDiff() had the same code.
 This commit expose BufferUsageAccumDiff() and makes pg_stat_statements
 use it for the calculation, in order to simply the code. 
 This change also would be useful for the upcoming patch for the planning
 counters in pg_stat_statements because the patch will add one more code
 for the calculation of difference of buffer counters and that can easily be
 done by using BufferUsageAccumDiff(). 
 Author: Julien Rouhaud 
Reviewed-by: Fujii Masao Discussion: https://postgr.es/m/
bdfee4e0-a304-2498-8da5-
3cb52c0a193e@oss.nttdata.com  
  Amit Kapila [Mon, 30 Mar 2020 02:03:38 +0000 (07:33 +0530)]     Introduce vacuum errcontext to display additional information.
  The additional information displayed will be block number for error
 occurring while processing heap and index name for error occurring
 while processing the index. 
 This will help us in diagnosing the problems that occur during a vacuum.
 For ex. due to corruption (either caused by bad hardware or by some bug)
 if we get some error while vacuuming, it can help us identify the block
 in heap and or additional index information. 
 It sets up an error context callback to display additional information
 with the error.  During different phases of vacuum (heap scan, heap
 vacuum, index vacuum, index clean up, heap truncate), we update the error
 context callback to display appropriate information.  We can extend it to
 a bit more granular level like adding the phases for FSM operations or for
 prefetching the blocks while truncating. However, I felt that it requires
 adding many more error callback function calls and can make the code a bit
 complex, so left those for now. 
 Author: Justin Pryzby, with few changes by Amit Kapila 
Reviewed-by: Alvaro Herrera, Amit Kapila, Andres Freund, Michael Paquier and Sawada Masahiko
 Discussion: https://www.postgresql.org/message-id/
20191120210600.GC30362@telsasoft.com  
  Tom Lane [Sun, 29 Mar 2020 23:14:15 +0000 (19:14 -0400)]     Cosmetic improvements in ltree code.
 
 Add more comments in ltree.h, and correct a misstatement or two.
 
 Use a symbol, rather than hardwired constants, for the maximum length
 of an ltree label.  The max length is still hardwired in the associated
 error messages, but I want to clean that up as part of a separate patch
 to improve the error messages.
 
 
    Tom Lane [Sun, 29 Mar 2020 22:54:19 +0000 (18:54 -0400)]     Doc: correct misstatement about ltree label maximum length.
 
 The documentation says that the max length is 255 bytes, but
 code inspection says it's actually 255 characters; and relevant
 lengths are stored as uint16 so that that works.
 
 
    Peter Eisentraut [Sun, 29 Mar 2020 09:13:27 +0000 (11:13 +0200)]     Document color support
  Add a documentation appendix that explains the PG_COLOR and PG_COLORS
 environment variables. 
 Discussion: https://www.postgresql.org/message-id/flat/
bbdcce43-bd2e-5599-641b-
9b44b9e0add4@2ndquadrant.com  
  Peter Eisentraut [Sun, 29 Mar 2020 07:25:40 +0000 (09:25 +0200)]     pg_regress: Observe TMPDIR
  Put the temporary socket directory under TMPDIR, if that environment
 variable is set, instead of the hardcoded /tmp. 
 This allows running the tests if there is no /tmp at all (for example
 on Windows, although running the tests with Unix-domain sockets is not
 enabled on Windows yet).  We also use TMPDIR everywhere else /tmp is
 hardcoded, so this makes the behavior consistent.  
Reviewed-by: Andrew Dunstan <andrew.dunstan@2ndquadrant.com> Discussion: https://www.postgresql.org/message-id/flat/
54bde68c-d134-4eb8-5bd3-
8af33b72a010@2ndquadrant.com  
  Peter Eisentraut [Sun, 29 Mar 2020 06:56:41 +0000 (08:56 +0200)]     Update SQL features
 
 Change F181 to supported.  It requires that an embedded C program can
 be split across multiple files, which ECPG easily supports.
 
 
    David Rowley [Sun, 29 Mar 2020 06:36:20 +0000 (19:36 +1300)]     Attempt to fix unstable regression tests
  b07642dbc added code to trigger autovacuums based on the number of
 inserts into a table. This seems to have caused some regression test
 results to destabilize. I suspect this is due to autovacuum triggering a
 vacuum sometime after the test's ANALYZE run and perhaps reltuples is
 ending up being set to a slightly different value as a result. 
 Attempt to resolve this by running a VACUUM ANALYZE on the affected table
 instead of just ANALYZE. pg_class.reltuples will still get set to whatever
 ANALYZE chooses but we should no longer get the proceeding autovacuum
 overriding that. 
 The overhead this adds to each test's runtime seems small enough not to
 worry about. I measure 3-4% on stats_ext and can't measure any change in
 partition_aggregate. 
 I'm unable to recreate the issue locally, so this is a bit of a blind
 fix. 
 Discussion: https://postgr.es/m/CAApHDvpWmpqYrKwwDQyeDq8dAyK7GMNaxDhrG69CkSuXoEg%2BVg%40mail.gmail.com  
  Peter Geoghegan [Sun, 29 Mar 2020 03:25:03 +0000 (20:25 -0700)]     Make deduplication use number of key attributes.
 
 Use IndexRelationGetNumberOfKeyAttributes() rather than
 IndexRelationGetNumberOfAttributes() when determining whether or not two
 index tuples are suitable for merging together into a single posting
 list tuple.  This is a little bit tidier.  It brings affected code in
 nbtdedup.c a little closer to similar, related code in nbtsplitloc.c.
 
 
    Tom Lane [Sat, 28 Mar 2020 22:31:05 +0000 (18:31 -0400)]     Fix lquery's behavior for consecutive '*' items.
 
 Something like "*{2}.*{3}" should presumably mean the same as
 "*{5}", but it didn't.  Improve that.
 
 Get rid of an undocumented and remarkably ugly (though not, as far as
 I can tell, actually unsafe) static variable in favor of passing more
 arguments to checkCond().
 
 Reverse-engineer some commentary.  This function, like all of ltree,
 is still far short of what I would consider the minimum acceptable
 level of internal documentation, but at least now it has more than
 zero comments.
 
 Although this certainly seems like a bug fix, people might not
 thank us for changing query behavior in stable branches, so
 no back-patch.
 
 Nikita Glukhov, with cosmetic improvements by me
 
 Discussion: https://postgr.es/m/CAP_rww=waX2Oo6q+MbMSiZ9ktdj6eaJj0cQzNu=Ry2cCDij5fw@mail.gmail.com
 
 
    Tom Lane [Sat, 28 Mar 2020 21:09:51 +0000 (17:09 -0400)]     Protect against overflow of ltree.numlevel and lquery.numlevel.
 
 These uint16 fields could be overflowed by excessively long input,
 producing strange results.  Complain for invalid input.
 
 Likewise check for out-of-range values of the repeat counts in lquery.
 (We don't try too hard on that one, notably not bothering to detect
 if atoi's result has overflowed.)
 
 Also detect length overflow in ltree_concat.
 
 In passing, be more consistent about whether "syntax error" messages
 include the type name.  Also, clarify the documentation about what
 the size limit is.
 
 This has been broken for a long time, so back-patch to all supported
 branches.
 
 Nikita Glukhov, reviewed by Benjie Gillam and Tomas Vondra
 
 Discussion: https://postgr.es/m/CAP_rww=waX2Oo6q+MbMSiZ9ktdj6eaJj0cQzNu=Ry2cCDij5fw@mail.gmail.com
 
 
    Andres Freund [Sat, 28 Mar 2020 18:52:11 +0000 (11:52 -0700)]     Ensure snapshot is registered within ScanPgRelation().
  In 9.4 I added support to use a historical snapshot in
 ScanPgRelation(), while adding logical decoding. Unfortunately a
 conflict with the concurrent removal of SnapshotNow was incorrectly
 resolved, leading to an unregistered snapshot being used. 
 It is not correct to use an unregistered (or non-active) snapshot for
 anything non-trivial, because catalog invalidations can cause the
 snapshot to be invalidated. 
 Luckily it seems unlikely to actively cause problems in practice, as
 ScanPgRelation() requires that we already have a lock on the relation,
 we only look for a single row, and we don't appear to rely on the
 result's tid to be correct. It however is clearly wrong and potential
 negative consequences would likely be hard to find. So it seems worth
 backpatching the fix, even without a concrete hazard. 
 Discussion: https://postgr.es/m/
20200229052459.wzhqnbhrriezg4v2@alap3.anarazel.de
 Backpatch: 9.5-  
  Jeff Davis [Sat, 28 Mar 2020 17:53:01 +0000 (10:53 -0700)]     Fix costing for disk-based hash aggregation.
 
 Report and suggestions from Richard Guo and Tomas Vondra.
 
 Discussion: https://postgr.es/m/CAMbWs4_W8fYbAn8KxgidAaZHON_Oo08OYn9ze=7remJymLqo5g@mail.gmail.com
 
 
    Dean Rasheed [Sat, 28 Mar 2020 14:37:53 +0000 (14:37 +0000)]     Improve the performance and accuracy of numeric sqrt() and ln().
 
 Instead of using Newton's method to compute numeric square roots, use
 the Karatsuba square root algorithm, which performs better for numbers
 of all sizes. In practice, this is 3-5 times faster for inputs with
 just a few digits and up to around 10 times faster for larger inputs.
 
 Also, the new algorithm guarantees that the final digit of the result
 is correctly rounded, since it computes an integer square root with
 truncation, containing at least 1 extra decimal digit before rounding.
 The former algorithm would occasionally round the wrong way because
 it rounded both the intermediate and final results.
 
 In addition, arrange for sqrt_var() to explicitly support negative
 rscale values (rounding before the decimal point). This allows the
 argument reduction phase of ln_var() to be optimised for large inputs,
 since it only needs to compute square roots with a few more digits
 than the final ln() result, rather than computing all the digits
 before the decimal point. For very large inputs, this can be many
 thousands of times faster.
 
 In passing, optimise div_var_fast() in a couple of places where it was
 doing unnecessary work.
 
 Patch be me, reviewed by Tom Lane and Tels.
 
 Discussion: https://postgr.es/m/CAEZATCV1A7+jD3P30Zu31KjaxeSEyOn3v9d6tYegpxcq3cQu-g@mail.gmail.com
 
 
    Peter Eisentraut [Sat, 28 Mar 2020 12:01:42 +0000 (13:01 +0100)]     Enable Unix-domain sockets support on Windows
  As of Windows 10 version 1803, Unix-domain sockets are supported on
 Windows.  But it's not automatically detected by configure because it
 looks for struct sockaddr_un and Windows doesn't define that.  So we
 just make our own definition on Windows and override the configure
 result. 
 Set DEFAULT_PGSOCKET_DIR to empty on Windows so by default no
 Unix-domain socket is used, because there is no good standard
 location. 
 In pg_upgrade, we have to do some extra tweaking to preserve the
 existing behavior of not using Unix-domain sockets on Windows.  Adding
 support would be desirable, but it needs further work, in particular a
 way to select whether to use Unix-domain sockets from the command-line
 or with a run-time test. 
 The pg_upgrade test script needs a fix.  The previous code passed
 "localhost" to postgres -k, which only happened to work because
 Windows used to ignore the -k argument value altogether.  We instead
 need to pass an empty string to get the desired effect. 
 The test suites will continue to not use Unix-domain sockets on
 Windows.  This requires a small tweak in pg_regress.c.  The TAP tests
 don't need to be changed because they decide by the operating system
 rather than HAVE_UNIX_SOCKETS.  
Reviewed-by: Andrew Dunstan <andrew.dunstan@2ndquadrant.com> Discussion: https://www.postgresql.org/message-id/flat/
54bde68c-d134-4eb8-5bd3-
8af33b72a010@2ndquadrant.com  
  Dean Rasheed [Sat, 28 Mar 2020 12:48:34 +0000 (12:48 +0000)]     Prevent functional dependency estimates from exceeding column estimates.
  Formerly we applied a functional dependency "a => b with dependency
 degree f" using the formula 
   P(a,b) = P(a) * [f + (1-f)*P(b)] 
 This leads to the possibility that the combined selectivity P(a,b)
 could exceed P(b), which is not ideal. The addition of support for IN
 and OR clauses (commits 
8f321bd16c and 
ccaa3569f5) would seem to make
 this more likely, since the user-supplied values in such clauses are
 not necessarily compatible with the functional dependency. 
 Mitigate this by using the formula 
   P(a,b) = f * Min(P(a), P(b)) + (1-f) * P(a) * P(b) 
 instead, which guarantees that the combined selectivity is less than
 each column's individual selectivity. Logically, this is modifies the
 part of the formula that accounts for dependent rows to handle cases
 where P(a) > P(b), whilst not changing the second term which accounts
 for independent rows. 
 Additionally, this refactors the way that functional dependencies are
 applied, so now dependencies_clauselist_selectivity() estimates both
 the implying clauses and the implied clauses for each functional
 dependency (formerly only the implied clauses were estimated), and now
 all clauses for each attribute are taken into account (formerly only
 one clause for each implied attribute was estimated). This removes the
 previously built-in assumption that only equality clauses will be
 seen, which is no longer true, and opens up the possibility of
 applying functional dependencies to more general clauses. 
 Patch by me, reviewed by Tomas Vondra. 
 Discussion: https://postgr.es/m/CAEZATCXaNFZyOhR4XXAfkvj1tibRBEjje6ZbXwqWUB_tqbH%3Drw%40mail.gmail.com
 Discussion: https://postgr.es/m/
20200318002946.6dvblukm3cfmgir2%40development  
  Peter Eisentraut [Sat, 28 Mar 2020 07:46:18 +0000 (08:46 +0100)]     Cleanup in SQL features files
 
 Feature C011 was still listed in sql_feature_packages.txt but had been
 removed from sql_features.txt, so also remove from the former.
 
 
    David Rowley [Sat, 28 Mar 2020 06:20:12 +0000 (19:20 +1300)]     Trigger autovacuum based on number of INSERTs
 
 Traditionally autovacuum has only ever invoked a worker based on the
 estimated number of dead tuples in a table and for anti-wraparound
 purposes. For the latter, with certain classes of tables such as
 insert-only tables, anti-wraparound vacuums could be the first vacuum that
 the table ever receives. This could often lead to autovacuum workers being
 busy for extended periods of time due to having to potentially freeze
 every page in the table. This could be particularly bad for very large
 tables. New clusters, or recently pg_restored clusters could suffer even
 more as many large tables may have the same relfrozenxid, which could
 result in large numbers of tables requiring an anti-wraparound vacuum all
 at once.
 
 Here we aim to reduce the work required by anti-wraparound and aggressive
 vacuums in general, by triggering autovacuum when the table has received
 enough INSERTs. This is controlled by adding two new GUCs and reloptions;
 autovacuum_vacuum_insert_threshold and
 autovacuum_vacuum_insert_scale_factor. These work exactly the same as the
 existing scale factor and threshold controls, only base themselves off the
 number of inserts since the last vacuum, rather than the number of dead
 tuples. New controls were added rather than reusing the existing
 controls, to allow these new vacuums to be tuned independently and perhaps
 even completely disabled altogether, which can be done by setting
 autovacuum_vacuum_insert_threshold to -1.
 
 We make no attempt to skip index cleanup operations on these vacuums as
 they may trigger for an insert-mostly table which continually doesn't have
 enough dead tuples to trigger an autovacuum for the purpose of removing
 those dead tuples. If we were to skip cleaning the indexes in this case,
 then it is possible for the index(es) to become bloated over time.
 
 There are additional benefits to triggering autovacuums based on inserts,
 as tables which never contain enough dead tuples to trigger an autovacuum
 are now more likely to receive a vacuum, which can mark more of the table
 as "allvisible" and encourage the query planner to make use of Index Only
 Scans.
 
 Currently, we still obey vacuum_freeze_min_age when triggering these new
 autovacuums based on INSERTs. For large insert-only tables, it may be
 beneficial to lower the table's autovacuum_freeze_min_age so that tuples
 are eligible to be frozen sooner. Here we've opted not to zero that for
 these types of vacuums, since the table may just be insert-mostly and we
 may otherwise freeze tuples that are still destined to be updated or
 removed in the near future.
 
 There was some debate to what exactly the new scale factor and threshold
 should default to. For now, these are set to 0.2 and 1000, respectively.
 There may be some motivation to adjust these before the release.
 
 Author: Laurenz Albe, Darafei Praliaskouski
 Reviewed-by: Alvaro Herrera, Masahiko Sawada, Chris Travers, Andres Freund, Justin Pryzby
 Discussion: https://postgr.es/m/CAC8Q8t%2Bj36G_bLF%3D%2B0iMo6jGNWnLnWb1tujXuJr-%2Bx8ZCCTqoQ%40mail.gmail.com
 
 
    Peter Geoghegan [Fri, 27 Mar 2020 23:44:52 +0000 (16:44 -0700)]     Justify nbtree page split locking in code comment.
  Delaying unlocking the right child page until after the point that the
 left child's parent page has been refound is no longer truly necessary.
 Commit 
40dae7ec made nbtree tolerant of interrupted page splits.  VACUUM
 was taught to avoid deleting a page that happens to be the right half of
 an incomplete split.  As long as page splits don't unlock the left child
 page until the end of the second/final phase, it should be safe to
 unlock the right child page earlier (at the end of the first phase). 
 It probably isn't actually useful to release the right child's lock
 earlier like this (it probably won't improve performance).  Even still,
 pointing out that it ought to be safe to do so should make it easier to
 understand the overall design.  
  Alvaro Herrera [Fri, 27 Mar 2020 22:43:41 +0000 (19:43 -0300)]     Allow walreceiver configuration to change on reload
  The parameters primary_conninfo, primary_slot_name and
 wal_receiver_create_temp_slot can now be changed with a simple "reload"
 signal, no longer requiring a server restart.  This is achieved by
 signalling the walreceiver process to terminate and having it start
 again with the new values. 
 Thanks to Andres Freund, Kyotaro Horiguchi, Fujii Masao for discussion. 
 Author: Sergei Kornilov <sk@zsrv.org> 
Reviewed-by: Michael Paquier <michael@paquier.xyz> Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org> Discussion: https://postgr.es/m/
19513901543181143@sas1-
19a94364928d.qloud-c.yandex.net  
  Alvaro Herrera [Fri, 27 Mar 2020 19:04:52 +0000 (16:04 -0300)]     Set wal_receiver_create_temp_slot PGC_POSTMASTER
  Commit 
329730827848 gave walreceiver the ability to create and use a
 temporary replication slot, and made it controllable by a GUC (enabled
 by default) that can be changed with SIGHUP.  That's useful but has two
 problems: one, it's possible to cause the origin server to fill its disk
 if the slot doesn't advance in time; and also there's a disconnect
 between state passed down via the startup process and GUCs that
 walreceiver reads directly. 
 We handle the first problem by setting the option to disabled by
 default.  If the user enables it, its on their head to make sure that
 disk doesn't fill up. 
 We handle the second problem by passing the flag via startup rather than
 having walreceiver acquire it directly, and making it PGC_POSTMASTER
 (which ensures a walreceiver always has the fresh value).  A future
 commit can relax this (to PGC_SIGHUP again) by having the startup
 process signal walreceiver to shutdown whenever the value changes. 
 Author: Sergei Kornilov <sk@zsrv.org> 
Reviewed-by: Michael Paquier <michael@paquier.xyz> Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org> Discussion: https://postgr.es/m/
20200122055510.GH174860@paquier.xyz  
  Tom Lane [Fri, 27 Mar 2020 18:47:34 +0000 (14:47 -0400)]     Rearrange validity checks for plpgsql "simple" expressions.
  Buildfarm experience shows what probably should've occurred to me before:
 if a cache flush occurs partway through building a generic plan, then
 the plansource may have is_valid = false even though the plan is valid.
 We need to accept this case, use the generated plan, and then try to
 replan the next time.  We can't try to replan immediately, because that
 would produce an infinite loop in CLOBBER_CACHE_ALWAYS builds; moreover
 it's really overkill.  (We can assume that the plan is valid, it's just
 possibly a bit stale.  Note that the pre-existing code behaved this way,
 and the non-simple-expression code paths do too.)  Conversely, not using
 the generated plan would drop us into the not-a-simple-expression code
 path, which is bad for performance and would also cause regression-test
 failures due to visibly different error-reporting behavior. 
 Hence, refactor the validity-check functions so that the initial check
 and recheck cases can react differently to plansource->is_valid.
 This makes their usage a bit simpler, too. 
 Discussion: https://postgr.es/m/7072.
1585332104@sss.pgh.pa.us  
  Peter Eisentraut [Fri, 27 Mar 2020 07:36:08 +0000 (08:36 +0100)]     Update SQL features
 
 Change F311 to supported.  This was already accomplished when
 subfeature F311-04 (WITH CHECK OPTION) was added, but the top-level
 feature wasn't updated at the time.
 
 
    Tom Lane [Thu, 26 Mar 2020 22:58:57 +0000 (18:58 -0400)]     Improve performance of "simple expressions" in PL/pgSQL.
 
 For relatively simple expressions (say, "x + 1" or "x > 0"), plpgsql's
 management overhead exceeds the cost of evaluating the expression.
 This patch substantially improves that situation, providing roughly
 2X speedup for such trivial expressions.
 
 First, add infrastructure in the plancache to allow fast re-validation
 of cached plans that contain no table access, and hence need no locks.
 Teach plpgsql to use this infrastructure for expressions that it's
 already deemed "simple" (which in particular will never contain table
 references).
 
 The fast path still requires checking that search_path hasn't changed,
 so provide a fast path for OverrideSearchPathMatchesCurrent by
 counting changes that have occurred to the active search path in the
 current session.  This is simplistic but seems enough for now, seeing
 that PushOverrideSearchPath is not used in any performance-critical
 cases.
 
 Second, manage the refcounts on simple expressions' cached plans using
 a transaction-lifespan resource owner, so that we only need to take
 and release an expression's refcount once per transaction not once per
 expression evaluation.  The management of this resource owner exactly
 parallels the existing management of plpgsql's simple-expression EState.
 
 Add some regression tests covering this area, in particular verifying
 that expression caching doesn't break semantics for search_path changes.
 
 Patch by me, but it owes something to previous work by Amit Langote,
 who recognized that getting rid of plancache-related overhead would
 be a useful thing to do here.  Also thanks to Andres Freund for review.
 
 Discussion: https://postgr.es/m/CAFj8pRDRVfLdAxsWeVLzCAbkLFZhW549K+67tpOc-faC8uH8zw@mail.gmail.com
 
 
    Tom Lane [Thu, 26 Mar 2020 22:06:55 +0000 (18:06 -0400)]     Ensure that plpgsql cleans up cleanly during parallel-worker exit.
  plpgsql_xact_cb ought to treat events XACT_EVENT_PARALLEL_COMMIT and
 XACT_EVENT_PARALLEL_ABORT like XACT_EVENT_COMMIT and XACT_EVENT_ABORT
 respectively, since its goal is to do process-local cleanup.  This
 oversight caused plpgsql's end-of-transaction cleanup to not get done
 in parallel workers.  Since a parallel worker will exit just after the
 transaction cleanup, the effects of this are limited.  I couldn't find
 any case in the core code with user-visible effects, but perhaps there
 are some in extensions.  In any case it's wrong, so let's fix it before
 it bites us not after. 
 In passing, add some comments around the handling of expression
 evaluation resources in DO blocks.  There's no live bug there, but it's
 quite unobvious what's happening; at least I thought so.  This isn't
 related to the other issue, except that I found both things while poking
 at expression-evaluation performance. 
 Back-patch the plpgsql_xact_cb fix to 9.5 where those event types
 were introduced, and the DO-block commentary to v11 where DO blocks
 gained the ability to issue COMMIT/ROLLBACK. 
 Discussion: https://postgr.es/m/10353.
1585247879@sss.pgh.pa.us  
  Magnus Hagander [Thu, 26 Mar 2020 14:05:54 +0000 (15:05 +0100)]     Document that pg_checksums exists in checksums README
 
 Author: Daniel Gustafsson <daniel@yesql.se>
 
 
    Peter Eisentraut [Thu, 26 Mar 2020 10:51:39 +0000 (11:51 +0100)]     Drop slot's LWLock before returning from SaveSlotToPath()
  When SaveSlotToPath() is called with elevel=LOG, the early exits didn't
 release the slot's io_in_progress_lock. 
 This could result in a walsender being stuck on the lock forever.  A
 possible way to get into this situation is if the offending code paths
 are triggered in a low disk space situation. 
 Author: Pavan Deolasee <pavan.deolasee@2ndquadrant.com> 
Reported-by: Craig Ringer <craig@2ndquadrant.com> Discussion: https://www.postgresql.org/message-id/flat/
56a138c5-de61-f553-7e8f-
6789296de785%402ndquadrant.com  
  Tom Lane [Thu, 26 Mar 2020 02:05:19 +0000 (22:05 -0400)]     Further fixes for ssl_passphrase_callback test module.
 
 The Makefile should set TAP_TESTS = 1, not implement the infrastructure
 for itself.  For one thing, it missed the appropriate "make clean"
 steps.  For another, the buildfarm isn't running this test because
 it wasn't hooked into "make installcheck" either.
 
 
    Andrew Dunstan [Thu, 26 Mar 2020 01:14:14 +0000 (21:14 -0400)]     Don't listen to localhost in ssl_passphrase_callback test
  Commit 
896fcdb230 contained an unnecessary setting that listened to
 localhost. Since the test doesn't actually try to make an SSL connection
 to the database this isn't required. Moreover, it's a security hole. 
 Per gripe from Tom Lane.  
  Tom Lane [Wed, 25 Mar 2020 23:37:30 +0000 (19:37 -0400)]     Fix assorted portability issues in commit 
896fcdb23. 
 Some platforms require libssl to be linked explicitly in the new
 SSL test module.  Borrow contrib/sslinfo's code for that. 
 Since src/test/modules/Makefile now has a variable SUBDIRS list,
 it needs to follow the ALWAYS_SUBDIRS protocol for that (cf.
 comments in Makefile.global.in). 
 Blindly try to fix MSVC build failures by adding PGDLLIMPORT.  
  Andrew Dunstan [Wed, 25 Mar 2020 21:13:17 +0000 (17:13 -0400)]     Provide a TLS init hook
  The default hook function sets the default password callback function.
 In order to allow preloaded libraries to have an opportunity to override
 the default, TLS initialization if now delayed slightly until after
 shared preloaded libraries have been loaded. 
 A test module is provided which contains a trivial example that decodes
 an obfuscated password for an SSL certificate. 
 Author: Andrew Dunstan
 Reviewed By: Andreas Karlsson, Asaba Takanori
 Discussion: https://postgr.es/m/
04116472-818b-5859-1d74-
3d995aab2252@2ndQuadrant.com  
  Alvaro Herrera [Wed, 25 Mar 2020 18:14:14 +0000 (15:14 -0300)]     pg_dump new test: Change order of arguments
 
 Some getopt_long implementations don't like to have a non-option
 argument before option arguments, so put the database name as the
 last switch.
 
 Per buildfarm member hoverfly.
 
 
    Alvaro Herrera [Wed, 25 Mar 2020 16:19:31 +0000 (13:19 -0300)]     pg_dump: Allow dumping data of specific foreign servers
 
 The new command-line switch --include-foreign-data=PATTERN lets the user
 specify foreign servers from which to dump foreign table data.  This can
 be refined by further inclusion/exclusion switches, so that the user has
 full control over which tables to dump.
 
 A limitation is that this doesn't work in combination with parallel
 dumps, for implementation reasons.  This might be lifted in the future,
 but requires shuffling some code around.
 
 Author: Luis Carril <luis.carril@swarm64.com>
 Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
 Reviewed-by: Surafel Temesgen <surafel3000@gmail.com>
 Reviewed-by: vignesh C <vignesh21@gmail.com>
 Reviewed-by: Álvaro Herrera <alvherre@2ndQuadrant.com>
 Discussion: https://postgr.es/m/LEJPR01MB0185483C0079D2F651B16231E7FC0@LEJPR01MB0185.DEUPRD01.PROD.OUTLOOK.DE
 
 
    Tom Lane [Wed, 25 Mar 2020 15:57:36 +0000 (11:57 -0400)]     Go back to returning int from ereport auxiliary functions.
  This reverts the parts of commit 
17a28b03645e27d73bf69a95d7569b61e58f06eb that changed ereport's auxiliary functions from returning dummy integer
 values to returning void.  It turns out that a minority of compilers
 complain (not entirely unreasonably) about constructs such as 
	(condition) ? errdetail(...) : 0 
 if errdetail() returns void rather than int.  We could update those
 call sites to say "(void) 0" perhaps, but the expectation for this
 patch set was that ereport callers would not have to change anything.
 And this aspect of the patch set was already the most invasive and
 least compelling part of it, so let's just drop it. 
 Per buildfarm. 
 Discussion: https://postgr.es/m/CA+fd4k6N8EjNvZpM8nme+y+05mz-SM8Z_BgkixzkA34R+ej0Kw@mail.gmail.com  
  Peter Eisentraut [Wed, 25 Mar 2020 13:23:25 +0000 (14:23 +0100)]     Define EXEC_BACKEND in pg_config_manual.h
  It was for unclear reasons defined in a separate location, which makes
 it more cumbersome to override for testing, and it also did not have
 any prominent documentation.  Move to pg_config_manual.h, where
 similar things are already collected. 
 The previous definition on the command-line had the effect of defining
 it to the value 1, but now that we don't need that anymore we just
 define it to empty, to simplify manual editing a bit.  
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://www.postgresql.org/message-id/flat/
b7053ba8-b008-5335-31de-
2fe4fe41ef0f%402ndquadrant.com  
  Peter Eisentraut [Wed, 25 Mar 2020 07:46:41 +0000 (08:46 +0100)]     Update SQL features
 
 The name of E182 was changed in SQL:2011.
 
 Also, we can change it to supported because all it requires is one
 embedded language to be supported, which we do.
 
 
    Thomas Munro [Wed, 25 Mar 2020 02:56:00 +0000 (15:56 +1300)]     Add collation versions for Windows.
 
 On Vista and later, use GetNLSVersionEx() to request collation version
 information.
 
 Reviewed-by: Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
 Discussion: https://postgr.es/m/CA%2BhUKGJvqup3s%2BJowVTcacZADO6dOhfdBmvOPHLS3KXUJu41Jw%40mail.gmail.com
 
 
    Thomas Munro [Wed, 25 Mar 2020 02:53:24 +0000 (15:53 +1300)]     Allow NULL version for individual collations.
 
 Remove the documented restriction that collation providers must either
 return NULL for all collations or non-NULL for all collations.
 
 Use NULL for glibc collations like "C.UTF-8", which might otherwise lead
 future proposed commits to force unnecessary index rebuilds.
 
 Reviewed-by: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
 Discussion: https://postgr.es/m/CA%2BhUKGJvqup3s%2BJowVTcacZADO6dOhfdBmvOPHLS3KXUJu41Jw%40mail.gmail.com
 
 
    Jeff Davis [Wed, 25 Mar 2020 01:19:51 +0000 (18:19 -0700)]     Consider disk-based hash aggregation to implement DISTINCT.
  Correct oversight in 
1f39bce0. If enable_hashagg_disk=true, we should
 consider hash aggregation for DISTINCT when applicable.  
  Jeff Davis [Wed, 25 Mar 2020 01:19:34 +0000 (18:19 -0700)]     Avoid allocating unnecessary zero-sized array.
 
 If there are no aggregates, there is no need to allocate an array of
 zero AggStatePerGroupData elements.
 
 
    Peter Geoghegan [Tue, 24 Mar 2020 21:58:27 +0000 (14:58 -0700)]     Fix nbtree deduplication README commentary.
 
 Descriptions of some aspects of how deduplication works were unclear in
 a couple of places.
 
 
    Andres Freund [Tue, 24 Mar 2020 19:14:18 +0000 (12:14 -0700)]     logical decoding: Remove TODO about unnecessary optimization.
 
 Measurements show, and intuition agrees, that there's currently no
 known cases where adding a fastpath to avoid allocating / ordering a
 heap for a single transaction is worthwhile.
 
 Author: Dilip Kumar
 Discussion: https://postgr.es/m/CAFiTN-sp701wvzvnLQJGk7JDqrFM8f--97-ihbwkU8qvn=p8nw@mail.gmail.com
 
 
    Peter Eisentraut [Tue, 24 Mar 2020 18:29:34 +0000 (19:29 +0100)]     Fix compiler warning on Cygwin
  bf68b79e50e3359accc85c94fa23cc03abb9350a introduced an unused variable
 compiler warning on Cygwin.  
  Tom Lane [Tue, 24 Mar 2020 16:08:48 +0000 (12:08 -0400)]     Improve the internal implementation of ereport().
 
 Change all the auxiliary error-reporting routines to return void,
 now that we no longer need to pretend they are passing something
 useful to errfinish().  While this probably doesn't save anything
 significant at the machine-code level, it allows detection of some
 additional types of mistakes.
 
 Pass the error location details (__FILE__, __LINE__, PG_FUNCNAME_MACRO)
 to errfinish not errstart.  This shaves a few cycles off the case where
 errstart decides we're not going to emit anything.
 
 Re-implement elog() as a trivial wrapper around ereport(), removing
 the separate support infrastructure it used to have.  Aside from
 getting rid of some now-surplus code, this means that elog() now
 really does have exactly the same semantics as ereport(), in particular
 that it can skip evaluation work if the message is not to be emitted.
 
 Andres Freund and Tom Lane
 
 Discussion: https://postgr.es/m/CA+fd4k6N8EjNvZpM8nme+y+05mz-SM8Z_BgkixzkA34R+ej0Kw@mail.gmail.com
 
 
    Tom Lane [Tue, 24 Mar 2020 15:48:33 +0000 (11:48 -0400)]     Re-implement the ereport() macro using __VA_ARGS__.
 
 Now that we require C99, we can depend on __VA_ARGS__ to work, and
 revising ereport() to use it has several significant benefits:
 
 * The extra parentheses around the auxiliary function calls are now
 optional.  Aside from being a bit less ugly, this removes a common
 gotcha for new contributors, because in some cases the compiler errors
 you got from forgetting them were unintelligible.
 
 * The auxiliary function calls are now evaluated as a comma expression
 list rather than as extra arguments to errfinish().  This means that
 compilers can be expected to warn about no-op expressions in the list,
 allowing detection of several other common mistakes such as forgetting
 to add errmsg(...) when converting an elog() call to ereport().
 
 * Unlike the situation with extra function arguments, comma expressions
 are guaranteed to be evaluated left-to-right, so this removes platform
 dependency in the order of the auxiliary function calls.  While that
 dependency hasn't caused us big problems in the past, this change does
 allow dropping some rather shaky assumptions around errcontext() domain
 handling.
 
 There's no intention to make wholesale changes of existing ereport
 calls, but as proof-of-concept this patch removes the extra parens
 from a couple of calls in postgres.c.
 
 While new code can be written either way, code intended to be
 back-patched will need to use extra parens for awhile yet.  It seems
 worth back-patching this change into v12, so as to reduce the window
 where we have to be careful about that by one year.  Hence, this patch
 is careful to preserve ABI compatibility; a followup HEAD-only patch
 will make some additional simplifications.
 
 Andres Freund and Tom Lane
 
 Discussion: https://postgr.es/m/CA+fd4k6N8EjNvZpM8nme+y+05mz-SM8Z_BgkixzkA34R+ej0Kw@mail.gmail.com
 
 
    Peter Eisentraut [Tue, 24 Mar 2020 15:01:06 +0000 (16:01 +0100)]     Fix compiler warning
 
 A variable was unused in non-assert builds.  Simplify the code to
 avoid the issue.
 
 Reported-by: Erik Rijkers <er@xs4all.nl>
 
    Tom Lane [Tue, 24 Mar 2020 14:27:02 +0000 (10:27 -0400)]     Doc: fix broken markup.
  Sloppiness in commit 
cedffbdb8, noted by Erikjan Rijkers.
 (It's fairly unfortunate that xmllint doesn't catch this.) 
 Discussion: https://postgr.es/m/
2e3dc9e4bfa4802d2c9f5fe15bde44de@xs4all.nl  
  Peter Eisentraut [Tue, 24 Mar 2020 13:00:58 +0000 (14:00 +0100)]     Some refactoring of logical/worker.c
 
 This moves the main operations of apply_handle_{insert|update|delete},
 that of inserting, updating, deleting a tuple into/from a given
 relation, into corresponding
 apply_handle_{insert|update|delete}_internal functions.  This allows
 performing those operations on relations that are not directly the
 targets of replication, which is something a later patch will use for
 targeting partitioned tables.
 
 Author: Amit Langote <amitlangote09@gmail.com>
 Reviewed-by: Rafia Sabih <rafia.pghackers@gmail.com>
 Reviewed-by: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
 Discussion: https://www.postgresql.org/message-id/flat/CA+HiwqH=Y85vRK3mOdjEkqFK+E=ST=eQiHdpj43L=_eJMOOznQ@mail.gmail.com
 
 
    Peter Eisentraut [Tue, 24 Mar 2020 07:49:52 +0000 (08:49 +0100)]     Add support for other normal forms to Unicode normalization API
  It previously only supported NFKC, for use by SASLprep.  This expands
 the API to offer the choice of all four normalization forms.  Right
 now, there are no internal users of the forms other than NFKC.  
Reviewed-by: Daniel Verite <daniel@manitou-mail.org> Reviewed-by: Andreas Karlsson <andreas@proxel.se> Discussion: https://www.postgresql.org/message-id/flat/
c1909f27-c269-2ed9-12f8-
3ab72c8caf7a@2ndquadrant.com  
  Andres Freund [Tue, 24 Mar 2020 05:19:56 +0000 (22:19 -0700)]     Report wait event for cost-based vacuum delay.
  Author: Justin Pryzby
 Discussion: https://postgr.es/m/
20200321040750.GD13662@telsasoft.com  
  Fujii Masao [Tue, 24 Mar 2020 03:46:48 +0000 (12:46 +0900)]     Prefer standby promotion over recovery pause.
  Previously if a promotion was triggered while recovery was paused,
 the paused state continued. Also recovery could be paused by executing
 pg_wal_replay_pause() even while a promotion was ongoing. That is,
 recovery pause had higher priority over a standby promotion.
 But this behavior was not desirable because most users basically wanted
 the recovery to complete as soon as possible and the server to become
 the master when they requested a promotion. 
 This commit changes recovery so that it prefers a promotion over
 recovery pause. That is, if a promotion is triggered while recovery
 is paused, the paused state ends and a promotion continues. Also
 this commit makes recovery pause functions like pg_wal_replay_pause()
 throw an error if they are executed while a promotion is ongoing. 
 Internally, this commit adds new internal function PromoteIsTriggered()
 that returns true if a promotion is triggered. Since the name of
 this function and the existing function IsPromoteTriggered() are
 confusingly similar, the commit changes the name of IsPromoteTriggered()
 to IsPromoteSignaled, as more appropriate name. 
 Author: Fujii Masao 
Reviewed-by: Atsushi Torikoshi, Sergei Kornilov Discussion: https://postgr.es/m/
00c194b2-dbbb-2e8a-5b39-
13f14048ef0a@oss.nttdata.com  
  Michael Paquier [Tue, 24 Mar 2020 03:13:36 +0000 (12:13 +0900)]     Move routine building restore_command to src/common/
  restore_command has only been used until now by the backend, but there
 is a pending patch for pg_rewind to make use of that in the frontend. 
 Author: Alexey Kondratov 
Reviewed-by: Andrey Borodin, Andres Freund, Alvaro Herrera, Alexander Korotkov, Michael Paquier
 Discussion: https://postgr.es/m/
a3acff50-5a0d-9a2c-b3b2-
ee36168955c1@postgrespro.ru  
  Fujii Masao [Tue, 24 Mar 2020 02:12:21 +0000 (11:12 +0900)]     Add wait events for WAL archive and recovery pause.
  This commit introduces new wait events BackupWaitWalArchive and
 RecoveryPause. The former is reported while waiting for the WAL files
 required for the backup to be successfully archived. The latter is
 reported while waiting for recovery in pause state to be resumed. 
 Author: Fujii Masao 
Reviewed-by: Michael Paquier, Atsushi Torikoshi, Robert Haas Discussion: https://postgr.es/m/
f0651f8c-9c96-9f29-0ff9-
80414a15308a@oss.nttdata.com  
  Jeff Davis [Tue, 24 Mar 2020 01:55:12 +0000 (18:55 -0700)]     Reduce test time for disk-based Hash Aggregation.
  Discussion: https://postgr.es/m/23196.
1584943506@sss.pgh.pa.us  
  Fujii Masao [Tue, 24 Mar 2020 01:43:41 +0000 (10:43 +0900)]     Report NULL as total backup size if it's not estimated.
 
 Previously 0 was reported in pg_stat_progress_basebackup.total_backup
 if the total backup size was not estimated. Per discussion, our consensus
 is that NULL is better choise as the value in total_backup in that case.
 So this commit makes pg_stat_progress_basebackup view report NULL
 in total_backup column if the estimation is disabled.
 
 Bump catversion.
 
 Author: Fujii Masao
 Reviewed-by: Amit Langote, Magnus Hagander, Alvaro Herrera
 Discussion: https://postgr.es/m/CABUevExnhOD89zBDuPvfAAh243RzNpwCPEWNLtMYpKHMB8gbAQ@mail.gmail.com
 
 
    Jeff Davis [Mon, 23 Mar 2020 20:56:28 +0000 (13:56 -0700)]     Fixes for Disk-based Hash Aggregation.
  Justin Pryzby raised a couple issues with commit 
1f39bce0. Fixed. 
 Also, tweak the way the size of a hash entry is estimated and the
 number of buckets is estimated when calling BuildTupleHashTableExt(). 
 Discussion: https://www.postgresql.org/message-id/
20200319064222.GR26184@telsasoft.com  
  Bruce Momjian [Mon, 23 Mar 2020 22:38:42 +0000 (18:38 -0400)]     docs:  add backend_type to file-fdw CSV log example
  backend_type was added to the CVS log output in commit 
70a7b4776b.  
Reported-by: Fabrízio de Royes Mello Discussion: https://postgr.es/m/CAFcNs+ruvRks3BV1j7yQ-MvxsswmKJa0cVh2yK5Dd-xXVM8wPw@mail.gmail.com 
 Backpatch-through: master  
  Andres Freund [Mon, 23 Mar 2020 21:48:19 +0000 (14:48 -0700)]     Add regression tests for constraint errors in partitioned tables.
  While #16293 only applied to 11 (and 10 to some degree), it seems best
 to add tests to all branches with partitioning support.  
Reported-By: Daniel WM Author: Andres Freund
 Bug: #16293
 Discussion: https://postgr.es/m/16293-
26f5777d10143a66@postgresql.org
 Backpatch: 10-  
  Alexander Korotkov [Mon, 23 Mar 2020 21:54:33 +0000 (00:54 +0300)]     Fix ordering in typedefs.list
 
 
    Tom Lane [Mon, 23 Mar 2020 16:42:15 +0000 (12:42 -0400)]     Doc: explain that LIKE et al can be used in ANY (sub-select) etc.
 
 This wasn't stated anywhere, and it's perhaps not that obvious,
 since we get questions about it from time to time.  Also undocumented
 was that the parser actually translates these into operators.
 
 Discussion: https://postgr.es/m/CAFj8pRBkvZ71BqGKZnBBG4=0cKG+s50Dy+DYmrizUKEpAtdc+w@mail.gmail.com
 
 
    Tom Lane [Mon, 23 Mar 2020 15:58:00 +0000 (11:58 -0400)]     Fix our getopt_long's behavior for a command line argument of just "-".
  src/port/getopt_long.c failed on such an argument, always seeing it
 as an unrecognized switch.  This is unhelpful; better is to treat such
 an item as a non-switch argument.  That behavior is what we find in
 GNU's getopt_long(); it's what src/port/getopt.c does; and it is
 required by POSIX for getopt(), which getopt_long() ought to be
 generally a superset of.  Moreover, it's expected by ecpg, which
 intends an argument of "-" to mean "read from stdin".  So fix it. 
 Also add some documentation about ecpg's behavior in this area, since
 that was miserably underdocumented.  I had to reverse-engineer it
 from the code. 
 Per bug #16304 from James Gray.  Back-patch to all supported branches,
 since this has been broken forever. 
 Discussion: https://postgr.es/m/16304-
c662b00a1322db7f@postgresql.org  
  Michael Paquier [Mon, 23 Mar 2020 04:38:03 +0000 (13:38 +0900)]     Doc: Fix type of some storage parameters in CREATE TABLE page
 
 autovacuum_vacuum_scale_factor and autovacuum_analyze_scale_factor have
 been documented as "float4", but "floating type" is used in this case
 for GUCs and relation options in the documentation.
 
 Author: Atsushi Torikoshi
 Discussion: https://postgr.es/m/CACZ0uYFf_p9BpbjLccx3CA=eM1Hk2Te=ULY4iptGLUhL-JxCPA@mail.gmail.com
 Backpatch-through: 9.5
 
 
    Michael Paquier [Mon, 23 Mar 2020 03:52:37 +0000 (12:52 +0900)]     Revert "Refactor compile-time assertion checks in c.h"
  This reverts commit 
b7f64c6, which broke the fallback implementation for
 C++.  We have discussed a couple of alternatives to reduce the number of
 implementations for those asserts, but nothing allowing to reduce the
 number of implementations down to three instead of four, so there is no
 benefit in keeping this patch. 
 Thanks to Tom Lane for the discussion. 
 Discussion: https://postgr.es/m/
20200313115033.GA183471@paquier.xyz  
  Amit Kapila [Mon, 23 Mar 2020 02:39:15 +0000 (08:09 +0530)]     Add object names to partition integrity violations.
  All errors of SQLSTATE class 23 should include the name of an object
 associated with the error in separate fields of the error report message.
 We do this so that applications need not try to extract them from the
 possibly-localized human-readable text of the message.  
Reported-by: Chris Bandy Author: Chris Bandy 
Reviewed-by: Amit Kapila and Amit Langote Discussion: https://postgr.es/m/
0aa113a3-3c7f-db48-bcd8-
f9290b2269ae@gmail.com  
  Michael Paquier [Mon, 23 Mar 2020 02:01:41 +0000 (11:01 +0900)]     Add bound checks for ssl_min_protocol_version and ssl_max_protocol_version
  Mixing incorrect bounds in the SSL context leads to confusing error
 messages generated by OpenSSL which are hard to act on.  New range
 checks are added when both min/max parameters are loaded in the context
 of a SSL reload to improve the error reporting.  Note that this does not
 make use of the GUC hook machinery contrary to 
41aadee, as there is no
 way to ensure a consistent range check (except if there is a way one day
 to define range types for GUC parameters?).  Hence, this patch applies
 only to OpenSSL, and uses a logic similar to other parameters to trigger
 an error when reloading the SSL context in a session. 
 Author: Michael Paquier 
Reviewed-by: Daniel Gustafsson Discussion: https://postgr.es/m/
20200114035420.GE1515@paquier.xyz  
  Noah Misch [Sun, 22 Mar 2020 16:24:09 +0000 (09:24 -0700)]     Revert "Skip WAL for new relfilenodes, under wal_level=minimal."
  This reverts commit 
cb2fd7eac285b1b0a24eeb2b8ed4456b66c5a09f.  Per
 numerous buildfarm members, it was incompatible with parallel query, and
 a test case assumed LP64.  Back-patch to 9.5 (all supported versions). 
 Discussion: https://postgr.es/m/
20200321224920.GB1763544@rfd.leadboat.com  
  Tom Lane [Sat, 21 Mar 2020 22:28:44 +0000 (18:28 -0400)]     Fix up recent breakage of headerscheck and cpluspluscheck.
  headerscheck and cpluspluscheck should skip the recently-added
 cmdtaglist.h header, since (like kwlist.h and some other similarly-
 designed headers) it's not meant to be included standalone. 
 evtcache.h was missing an #include to support its usage of Bitmapset. 
 typecmds.h was missing an #include to support its usage of ParseState. 
 The first two of these were evidently oversights in commit 
2f9661311.
 I didn't track down exactly which change broke typecmds.h, but it
 must have been some rearrangement in one of its existing inclusions,
 because it's referenced ParseState for quite a long time and there
 were not complaints from these checking programs before.  
  Noah Misch [Sat, 21 Mar 2020 16:38:26 +0000 (09:38 -0700)]     Skip WAL for new relfilenodes, under wal_level=minimal.
  Until now, only selected bulk operations (e.g. COPY) did this.  If a
 given relfilenode received both a WAL-skipping COPY and a WAL-logged
 operation (e.g. INSERT), recovery could lose tuples from the COPY.  See
 src/backend/access/transam/README section "Skipping WAL for New
 RelFileNode" for the new coding rules.  Maintainers of table access
 methods should examine that section. 
 To maintain data durability, just before commit, we choose between an
 fsync of the relfilenode and copying its contents to WAL.  A new GUC,
 wal_skip_threshold, guides that choice.  If this change slows a workload
 that creates small, permanent relfilenodes under wal_level=minimal, try
 adjusting wal_skip_threshold.  Users setting a timeout on COMMIT may
 need to adjust that timeout, and log_min_duration_statement analysis
 will reflect time consumption moving to COMMIT from commands like COPY. 
 Internally, this requires a reliable determination of whether
 RollbackAndReleaseCurrentSubTransaction() would unlink a relation's
 current relfilenode.  Introduce rd_firstRelfilenodeSubid.  Amend the
 specification of rd_createSubid such that the field is zero when a new
 rel has an old rd_node.  Make relcache.c retain entries for certain
 dropped relations until end of transaction. 
 Back-patch to 9.5 (all supported versions).  This introduces a new WAL
 record type, XLOG_GIST_ASSIGN_LSN, without bumping XLOG_PAGE_MAGIC.  As
 always, update standby systems before master systems.  This changes
 sizeof(RelationData) and sizeof(IndexStmt), breaking binary
 compatibility for affected extensions.  (The most recent commit to
 affect the same class of extensions was 
089e4d405d0f3b94c74a2c6a54357a84a681754b.) 
 Kyotaro Horiguchi, reviewed (in earlier, similar versions) by Robert
 Haas.  Heikki Linnakangas and Michael Paquier implemented earlier
 designs that materially clarified the problem.  Reviewed, in earlier
 designs, by Andrew Dunstan, Andres Freund, Alvaro Herrera, Tom Lane,
 Fujii Masao, and Simon Riggs.  Reported by Martijn van Oosterhout. 
 Discussion: https://postgr.es/m/
20150702220524.GA9392@svana.org  
  Noah Misch [Sat, 21 Mar 2020 16:38:26 +0000 (09:38 -0700)]     In log_newpage_range(), heed forkNum and page_std arguments.
  The function assumed forkNum=MAIN_FORKNUM and page_std=true, ignoring
 the actual arguments.  Existing callers passed exactly those values, so
 there's no live bug.  Back-patch to v12, where the function first
 appeared, because another fix needs this. 
 Discussion: https://postgr.es/m/
20191118045434.GA1173436@rfd.leadboat.com  
  Noah Misch [Sat, 21 Mar 2020 16:38:26 +0000 (09:38 -0700)]     During heap rebuild, lock any TOAST index until end of transaction.
  swap_relation_files() calls toast_get_valid_index() to find and lock
 this index, just before swapping with the rebuilt TOAST index.  The
 latter function releases the lock before returning.  Potential for
 mischief is low; a concurrent session can issue ALTER INDEX ... SET
 (fillfactor = ...), which is not alarming.  Nonetheless, changing
 pg_class.relfilenode without a lock is unconventional.  Back-patch to
 9.5 (all supported versions), because another fix needs this. 
 Discussion: https://postgr.es/m/
20191226001521.GA1772687@rfd.leadboat.com  
  Noah Misch [Sat, 21 Mar 2020 16:38:26 +0000 (09:38 -0700)]     Fix cosmetic blemishes involving rd_createSubid.
  Remove an obsolete comment from AtEOXact_cleanup().  Restore formatting
 of a comment in struct RelationData, mangled by the pgindent run in
 commit 
9af4159fce6654aa0e081b00d02bca40b978745c.  Back-patch to 9.5 (all
 supported versions), because another fix stacks on this.  
  Amit Kapila [Sat, 21 Mar 2020 03:18:06 +0000 (08:48 +0530)]     Allow page lock to conflict among parallel group members.
 
 This is required as it is no safer for two related processes to perform
 clean up in gin indexes at a time than for unrelated processes to do the
 same.  After acquiring page locks, we can acquire relation extension lock
 but reverse never happens which means these will also not participate in
 deadlock.  So, avoid checking wait edges from this lock.
 
 Currently, the parallel mode is strictly read-only, but after this patch
 we have the infrastructure to allow parallel inserts and parallel copy.
 
 Author: Dilip Kumar, Amit Kapila
 Reviewed-by: Amit Kapila, Kuntal Ghosh and Sawada Masahiko
 Discussion: https://postgr.es/m/CAD21AoCmT3cFQUN4aVvzy5chw7DuzXrJCbrjTU05B+Ss=Gn1LA@mail.gmail.com
 
 
    Bruce Momjian [Sat, 21 Mar 2020 00:19:32 +0000 (20:19 -0400)]     docs:  use alias in WHERE clause of full text search example
  The current doc query specified an alias in the FROM clause and used in
 it the target list, but not in the WHERE clause.  
Reported-by: axykon@gmail.com Discussion: https://postgr.es/m/
158316348159.30450.
16075357948244298217@wrigleys.postgresql.org 
 Backpatch-through: 9.5  
  Alvaro Herrera [Fri, 20 Mar 2020 21:11:28 +0000 (18:11 -0300)]     Fix bogus last-minute edit in 
4e62091341b4  Noticed by Erik Rijkers before I was able to push the fix.  
  Alvaro Herrera [Fri, 20 Mar 2020 20:21:00 +0000 (17:21 -0300)]     pg_dump: Add FOREIGN to ALTER statements, if appropriate
 
 Author: Luis Carril
 Reviewed-by: Tomas Vondra, Daniel Gustafsson, Álvaro Herrera
 Discussion: https://postgr.es/m/LEJPR01MB0185A19B2E7C98E5E2A031F5E7F20@LEJPR01MB0185.DEUPRD01.PROD.OUTLOOK.DE
 
 
    Andrew Dunstan [Fri, 20 Mar 2020 17:55:15 +0000 (13:55 -0400)]     Turn off deprecated bison warnings under MSVC
 
 These are disabled by the configure code, so this is just fixing an
 inconsistency in the MSVC code.
 
 Backpatch to all live branches.