PostgreSQL 11.17 (upcoming) commit log

Update xml_1.out and xml_2.out

commit   : 50bf3157a1a5cd7196ba5b5feaca4b71e035afb4    
author   : Alvaro Herrera <>    
date     : Wed, 18 May 2022 23:19:53 +0200    
committer: Alvaro Herrera <>    
date     : Wed, 18 May 2022 23:19:53 +0200    

Click here for diff

Commit 0fbf01120023 should have updated them but didn't.  

M src/test/regress/expected/xml_1.out
M src/test/regress/expected/xml_2.out

Check column list length in XMLTABLE/JSON_TABLE alias

commit   : ba83de8ada5b4a179b93874f39241ed5e00226b2    
author   : Alvaro Herrera <>    
date     : Wed, 18 May 2022 20:28:31 +0200    
committer: Alvaro Herrera <>    
date     : Wed, 18 May 2022 20:28:31 +0200    

Click here for diff

We weren't checking the length of the column list in the alias clause of  
an XMLTABLE or JSON_TABLE function (a "tablefunc" RTE), and it was  
possible to make the server crash by passing an overly long one.  Fix it  
by throwing an error in that case, like the other places that deal with  
alias lists.  
In passing, modify the equivalent test used for join RTEs to look like  
the other ones, which was different for no apparent reason.  
This bug came in when XMLTABLE was born in version 10; backpatch to all  
stable versions.  
Reported-by: Wang Ke <>  

M src/backend/parser/parse_clause.c
M src/backend/parser/parse_relation.c
M src/test/regress/expected/int2.out
M src/test/regress/expected/join.out
M src/test/regress/expected/with.out
M src/test/regress/expected/xml.out
M src/test/regress/sql/int2.sql
M src/test/regress/sql/join.sql
M src/test/regress/sql/with.sql
M src/test/regress/sql/xml.sql

Fix control file update done in restartpoints still running after promotion

commit   : 4525151d4c2f32dfeeef817968172e4c3328fa52    
author   : Michael Paquier <>    
date     : Mon, 16 May 2022 11:26:36 +0900    
committer: Michael Paquier <>    
date     : Mon, 16 May 2022 11:26:36 +0900    

Click here for diff

If a cluster is promoted (aka the control file shows a state different  
than DB_IN_ARCHIVE_RECOVERY) while CreateRestartPoint() is still  
processing, this function could miss an update of the control file for  
"checkPoint" and "checkPointCopy" but still do the recycling and/or  
removal of the past WAL segments, assuming that the to-be-updated LSN  
values should be used as reference points for the cleanup.  This causes  
a follow-up restart attempting crash recovery to fail with a PANIC on a  
missing checkpoint record if the end-of-recovery checkpoint triggered by  
the promotion did not complete while the cluster abruptly stopped or  
crashed before the completion of this checkpoint.  The PANIC would be  
caused by the redo LSN referred in the control file as located in a  
segment already gone, recycled by the previous restartpoint with  
"checkPoint" out-of-sync in the control file.  
This commit fixes the update of the control file during restartpoints so  
as "checkPoint" and "checkPointCopy" are updated even if the cluster has  
been promoted while a restartpoint is running, to be on par with the set  
of WAL segments actually recycled in the end of CreateRestartPoint().  
7863ee4 has fixed this problem already on master, but the release timing  
of the latest point versions did not let me enough time to study and fix  
that on all the stable branches.  
Reported-by: Fujii Masao, Rui Zhao  
Author: Kyotaro Horiguchi  
Reviewed-by: Nathan Bossart, Michael Paquier  
Backpatch-through: 10  

M src/backend/access/transam/xlog.c

Make pull_var_clause() handle GroupingFuncs exactly like Aggrefs.

commit   : 7f7f1750d4ca7b03ca0bfc2b89dd466816514fe6    
author   : Tom Lane <>    
date     : Thu, 12 May 2022 11:31:46 -0400    
committer: Tom Lane <>    
date     : Thu, 12 May 2022 11:31:46 -0400    

Click here for diff

This follows in the footsteps of commit 2591ee8ec by removing one more  
ill-advised shortcut from planning of GroupingFuncs.  It's true that  
we don't intend to execute the argument expression(s) at runtime, but  
we still have to process any Vars appearing within them, or we risk  
failure at setrefs.c time (or more fundamentally, in EXPLAIN trying  
to print such an expression).  Vars in upper plan nodes have to have  
referents in the next plan level, whether we ever execute 'em or not.  
Per bug #17479 from Michael J. Sullivan.  Back-patch to all supported  
Richard Guo  

M src/backend/optimizer/util/var.c
M src/test/regress/expected/groupingsets.out
M src/test/regress/sql/groupingsets.sql

Fix the logical replication timeout during large transactions.

commit   : 87c1dd246af8ace926645900f02886905b889718    
author   : Amit Kapila <>    
date     : Wed, 11 May 2022 10:12:23 +0530    
committer: Amit Kapila <>    
date     : Wed, 11 May 2022 10:12:23 +0530    

Click here for diff

The problem is that we don't send keep-alive messages for a long time  
while processing large transactions during logical replication where we  
don't send any data of such transactions. This can happen when the table  
modified in the transaction is not published or because all the changes  
got filtered. We do try to send the keep_alive if necessary at the end of  
the transaction (via WalSndWriteData()) but by that time the  
subscriber-side can timeout and exit.  
To fix this we try to send the keepalive message if required after  
processing certain threshold of changes.  
Reported-by: Fabrice Chapuis  
Author: Wang wei and Amit Kapila  
Reviewed By: Masahiko Sawada, Euler Taveira, Hou Zhijie, Hayato Kuroda  
Backpatch-through: 10  

M src/backend/replication/logical/logical.c
M src/backend/replication/pgoutput/pgoutput.c
M src/backend/replication/walsender.c
M src/include/replication/logical.h

Improve setup of environment values for commands in MSVC's

commit   : f0fb2e9509e90322dfc73f9a817f1488afa03bf6    
author   : Michael Paquier <>    
date     : Wed, 11 May 2022 10:22:40 +0900    
committer: Michael Paquier <>    
date     : Wed, 11 May 2022 10:22:40 +0900    

Click here for diff

The current setup assumes that commands for lz4, zstd and gzip always  
exist by default if not enforced by a user's environment.  However,  
vcpkg, as one example, installs libraries but no binaries, so this  
default setup to assume that a command should always be present would  
cause failures.  This commit improves the detection of such external  
commands as follows:  
* If a ENV value is available, trust the environment/user and use it.  
* If a ENV value is not available, check its execution by looking in the  
current PATH, by launching a simple "$command --version" (that should be  
portable enough).  
** On execution failure, ignore ENV{command}.  
** On execution success, set ENV{command} = "$command".  
Note that this new rule applies to gzip, lz4 and zstd but not tar that  
we assume will always exist.  Those commands are set up in the  
environment only when using bincheck and taptest.  The CI includes all  
those commands and I have checked that their setup is correct there.  I  
have also tested this change in a MSVC environment where we have none of  
those commands.  
While on it, remove the references to lz4 from the documentation and in ~v13.  --with-lz4 has been added in v14~ so there is no  
point to have this information in these older branches.  
Reported-by: Andrew Dunstan  
Reviewed-by: Andrew Dunstan  
Backpatch-through: 10  

M doc/src/sgml/install-windows.sgml
M src/tools/msvc/

configure: don't probe for libldap_r if libldap is 2.5 or newer.

commit   : 36d76da8156a01073e805f90b5e861415dfb13b5    
author   : Tom Lane <>    
date     : Tue, 10 May 2022 18:42:02 -0400    
committer: Tom Lane <>    
date     : Tue, 10 May 2022 18:42:02 -0400    

Click here for diff

In OpenLDAP 2.5 and later, libldap itself is always thread-safe and  
there's never a libldap_r.  Our existing coding dealt with that  
by assuming it wouldn't find libldap_r if libldap is thread-safe.  
But that rule fails to cope if there are multiple OpenLDAP versions  
visible, as is likely to be the case on macOS in particular.  We'd  
end up using shiny new libldap in the backend and a hoary libldap_r  
in libpq.  
Instead, once we've found libldap, check if it's >= 2.5 (by  
probing for a function introduced then) and don't bother looking  
for libldap_r if so.  While one can imagine library setups that  
this'd still give the wrong answer for, they seem unlikely to  
occur in practice.  
Per report from Peter Eisentraut.  Back-patch to all supported branches.  

M configure