PostgreSQL 13.18 commit log

Stamp 13.18.

commit   : 4f8df7a3fb750007ff5018f8125e0d4793cab337    
  
author   : Tom Lane <[email protected]>    
date     : Mon, 18 Nov 2024 15:39:24 -0500    
  
committer: Tom Lane <[email protected]>    
date     : Mon, 18 Nov 2024 15:39:24 -0500    

Click here for diff

M configure
M configure.in

Fix recently-exposed portability issue in regex optimization.

commit   : adb6dbc7f5353afbd0f7ac07e6cc41a54ea2818a    
  
author   : Tom Lane <[email protected]>    
date     : Sun, 17 Nov 2024 14:14:06 -0500    
  
committer: Tom Lane <[email protected]>    
date     : Sun, 17 Nov 2024 14:14:06 -0500    

Click here for diff

fixempties() counts the number of in-arcs in the regex NFA and then  
allocates an array of that many arc pointers.  If the NFA contains no  
arcs, this amounts to malloc(0) for which some platforms return NULL.  
The code mistakenly treats that as indicating out-of-memory.  Thus,  
we can get a bogus "out of memory" failure for some unsatisfiable  
regexes.  
  
This happens only in v15 and earlier, since bea3d7e38 switched to  
using palloc() rather than bare malloc().  And at least of the  
platforms in the buildfarm, only AIX seems to return NULL.  So the  
impact is pretty narrow.  But I don't especially want to ship code  
that is failing its own regression tests, so let's fix this for  
this week's releases.  
  
A quick code survey says that there is only the one place in  
src/backend/regex/ that is at risk of doing malloc(0), so we'll just  
band-aid that place.  A more future-proof fix could be to install a  
malloc() wrapper similar to pg_malloc().  But this code seems unlikely  
to change much more in the affected branches, so that's probably  
overkill.  
  
The only known test case for this involves a complemented character  
class in a bracket expression, for example [^\s\S], and we didn't  
support that in v13.  So it may be that the problem is unreachable  
in v13.  But I'm not 100% sure of that, so patch v13 too.  
  
Discussion: https://postgr.es/m/[email protected]  

M src/backend/regex/regc_nfa.c

Release notes for 17.2, 16.6, 15.10, 14.15, 13.18, 12.22.

commit   : f4a0b188850a19802e11c0b9809f77d3b661f6e2    
  
author   : Tom Lane <[email protected]>    
date     : Sat, 16 Nov 2024 17:09:53 -0500    
  
committer: Tom Lane <[email protected]>    
date     : Sat, 16 Nov 2024 17:09:53 -0500    

Click here for diff

M doc/src/sgml/release-13.sgml

Fix per-session activation of ALTER {ROLE|DATABASE} SET role.

commit   : 07c6e0f613612ff060572a085c1c24aa44c8b2bb    
  
author   : Noah Misch <[email protected]>    
date     : Fri, 15 Nov 2024 20:39:56 -0800    
  
committer: Noah Misch <[email protected]>    
date     : Fri, 15 Nov 2024 20:39:56 -0800    

Click here for diff

After commit 5a2fed911a85ed6d8a015a6bafe3a0d9a69334ae, the catalog state  
resulting from these commands ceased to affect sessions.  Restore the  
longstanding behavior, which is like beginning the session with a SET  
ROLE command.  If cherry-picking the CVE-2024-10978 fixes, default to  
including this, too.  (This fixes an unintended side effect of fixing  
CVE-2024-10978.)  Back-patch to v12, like that commit.  The release team  
decided to include v12, despite the original intent to halt v12 commits  
earlier this week.  
  
Tom Lane and Noah Misch.  Reported by Etienne LAFARGE.  
  
Discussion: https://postgr.es/m/CADOZwSb0UsEr4_UTFXC5k7=fyyK8uKXekucd+-uuGjJsGBfxgw@mail.gmail.com  

M src/backend/utils/init/miscinit.c
M src/backend/utils/misc/guc.c
M src/test/modules/unsafe_tests/Makefile
A src/test/modules/unsafe_tests/expected/setconfig.out
A src/test/modules/unsafe_tests/sql/setconfig.sql

Fix a possibility of logical replication slot's restart_lsn going backwards.

commit   : 15dc1abb17ddb4bba3025302d0b71b9325258601    
  
author   : Masahiko Sawada <[email protected]>    
date     : Fri, 15 Nov 2024 17:05:57 -0800    
  
committer: Masahiko Sawada <[email protected]>    
date     : Fri, 15 Nov 2024 17:05:57 -0800    

Click here for diff

Previously LogicalIncreaseRestartDecodingForSlot() accidentally  
accepted any LSN as the candidate_lsn and candidate_valid after the  
restart_lsn of the replication slot was updated, so it potentially  
caused the restart_lsn to move backwards.  
  
A scenario where this could happen in logical replication is: after a  
logical replication restart, based on previous candidate_lsn and  
candidate_valid values in memory, the restart_lsn advances upon  
receiving a subscriber acknowledgment. Then, logical decoding restarts  
from an older point, setting candidate_lsn and candidate_valid based  
on an old RUNNING_XACTS record. Subsequent subscriber acknowledgments  
then update the restart_lsn to an LSN older than the current value.  
  
In the reported case, after WAL files were removed by a checkpoint,  
the retreated restart_lsn prevented logical replication from  
restarting due to missing WAL segments.  
  
This change essentially modifies the 'if' condition to 'else if'  
condition within the function. The previous code had an asymmetry in  
this regard compared to LogicalIncreaseXminForSlot(), which does  
almost the same thing for different fields.  
  
The WAL removal issue was reported by Hubert Depesz Lubaczewski.  
  
Backpatch to all supported versions, since the bug exists since 9.4  
where logical decoding was introduced.  
  
Reviewed-by: Tomas Vondra, Ashutosh Bapat, Amit Kapila  
Discussion: https://postgr.es/m/Yz2hivgyjS1RfMKs%40depesz.com  
Discussion: https://postgr.es/m/85fff40e-148b-4e86-b921-b4b846289132%40vondra.me  
Backpatch-through: 13  

M src/backend/replication/logical/logical.c

Count contrib/bloom index scans in pgstat view.

commit   : e493ea866ebb74093b0f5648143635b3f3df1adc    
  
author   : Peter Geoghegan <[email protected]>    
date     : Tue, 12 Nov 2024 20:57:35 -0500    
  
committer: Peter Geoghegan <[email protected]>    
date     : Tue, 12 Nov 2024 20:57:35 -0500    

Click here for diff

Maintain the pg_stat_user_indexes.idx_scan pgstat counter during  
contrib/Bloom index scans.  
  
Oversight in commit 9ee014fc, which added the Bloom index contrib  
module.  
  
Author: Masahiro Ikeda <[email protected]>  
Reviewed-By: Peter Geoghegan <[email protected]>  
Discussion: https://postgr.es/m/[email protected]  
Backpatch: 13- (all supported branches).  

M contrib/bloom/blscan.c

Fix arrays comparison in CompareOpclassOptions()

commit   : 5411e821386ce5c9ec794bbc9540c7c4a1acaa46    
  
author   : Alexander Korotkov <[email protected]>    
date     : Tue, 12 Nov 2024 01:44:20 +0200    
  
committer: Alexander Korotkov <[email protected]>    
date     : Tue, 12 Nov 2024 01:44:20 +0200    

Click here for diff

The current code calls array_eq() and does not provide FmgrInfo.  This commit  
provides initialization of FmgrInfo and uses C collation as the safe option  
for text comparison because we don't know anything about the semantics of  
opclass options.  
  
Backpatch to 13, where opclass options were introduced.  
  
Reported-by: Nicolas Maus  
Discussion: https://postgr.es/m/18692-72ea398df3ec6712%40postgresql.org  
Backpatch-through: 13  

M contrib/pg_trgm/expected/pg_trgm.out
M contrib/pg_trgm/sql/pg_trgm.sql
M src/backend/commands/indexcmds.c