PostgreSQL 12.12 (upcoming) commit log

Update xml_1.out and xml_2.out

commit   : 0ebd20e20ff48a5df16ebfa49947c4044b948fa8    
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   : ade17703def9c8820d1a47cd21f37b1eb5656f89    
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   : 7e59b1219109be1b42d1f3937d09637327a56f5b    
author   : Michael Paquier <>    
date     : Mon, 16 May 2022 11:26:30 +0900    
committer: Michael Paquier <>    
date     : Mon, 16 May 2022 11:26:30 +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   : 301b91c56556e8edd6b59837731e5eb4aa5a9685    
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   : f832b5007c1c4b61bb1fd9a5000e0ca56b070373    
author   : Amit Kapila <>    
date     : Wed, 11 May 2022 10:25:56 +0530    
committer: Amit Kapila <>    
date     : Wed, 11 May 2022 10:25:56 +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   : de6eec10ee2b639a57c4b02b21b834c519f24e5b    
author   : Michael Paquier <>    
date     : Wed, 11 May 2022 10:22:37 +0900    
committer: Michael Paquier <>    
date     : Wed, 11 May 2022 10:22:37 +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   : 8ed13fb9346dfcf4423a40cc740b247463340342    
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