PostgreSQL 15.9 commit log

Stamp 15.9.

commit   : 0c53d54c812cea0d840490fd107910ed949e18c2    
  
author   : Tom Lane <[email protected]>    
date     : Mon, 11 Nov 2024 17:45:41 -0500    
  
committer: Tom Lane <[email protected]>    
date     : Mon, 11 Nov 2024 17:45:41 -0500    

Click here for diff

M configure
M configure.ac

Last-minute updates for release notes.

commit   : b83b358b1bac61ca46af995a3da83cc515a434c6    
  
author   : Tom Lane <[email protected]>    
date     : Mon, 11 Nov 2024 17:40:13 -0500    
  
committer: Tom Lane <[email protected]>    
date     : Mon, 11 Nov 2024 17:40:13 -0500    

Click here for diff

Security: CVE-2024-10976, CVE-2024-10977, CVE-2024-10978, CVE-2024-10979  

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

Parallel workers use AuthenticatedUserId for connection privilege checks.

commit   : 109a323807d752f66699a9ce0762244f536e784f    
  
author   : Tom Lane <[email protected]>    
date     : Mon, 11 Nov 2024 17:05:53 -0500    
  
committer: Tom Lane <[email protected]>    
date     : Mon, 11 Nov 2024 17:05:53 -0500    

Click here for diff

Commit 5a2fed911 had an unexpected side-effect: the parallel worker  
launched for the new test case would fail if it couldn't use a  
superuser-reserved connection slot.  The reason that test failed  
while all our pre-existing ones worked is that the connection  
privilege tests in InitPostgres had been based on the superuserness  
of the leader's AuthenticatedUserId, but after the rearrangements  
of 5a2fed911 we were testing the superuserness of CurrentUserId,  
which the new test case deliberately made to be a non-superuser.  
  
This all seems very accidental and probably not the behavior we really  
want, but a security patch is no time to be redesigning things.  
Pending some discussion about desirable semantics, hack it so that  
InitPostgres continues to pay attention to the superuserness of  
AuthenticatedUserId when starting a parallel worker.  
  
Nathan Bossart and Tom Lane, per buildfarm member sawshark.  
  
Security: CVE-2024-10978  

M src/backend/utils/init/postinit.c

Fix cross-version upgrade tests.

commit   : c834b375a6dc36ff92f9f738ef1d7af09d91165f    
  
author   : Tom Lane <[email protected]>    
date     : Mon, 11 Nov 2024 13:57:21 -0500    
  
committer: Tom Lane <[email protected]>    
date     : Mon, 11 Nov 2024 13:57:21 -0500    

Click here for diff

TestUpgradeXversion knows how to make the main regression database's  
references to pg_regress.so be version-independent.  But it doesn't  
do that for plperl's database, so that the C function added by  
commit b7e3a52a8 is causing cross-version upgrade test failures.  
Path of least resistance is to just drop the function at the end  
of the new test.  
  
In <= v14, also take the opportunity to clean up the generated  
test files.  
  
Security: CVE-2024-10979  

M src/pl/plperl/expected/plperl_env.out
M src/pl/plperl/sql/plperl_env.sql

src/tools/msvc: Respect REGRESS_OPTS in plcheck.

commit   : 16ed4f4d08d69f2aced8ece69ba1076b48c9ce06    
  
author   : Noah Misch <[email protected]>    
date     : Mon, 11 Nov 2024 10:55:18 -0800    
  
committer: Noah Misch <[email protected]>    
date     : Mon, 11 Nov 2024 10:55:18 -0800    

Click here for diff

v16 commit 8fe3e697a1a83a722b107c7cb9c31084e1f4d077 used REGRESS_OPTS in  
a way needing this.  That broke "vcregress plcheck".  Back-patch  
v16..v12; newer versions don't have this build system.  

M src/tools/msvc/vcregress.pl

Fix improper interactions between session_authorization and role.

commit   : a5d2e6205f716c79ecfb15eb1aae75bae3f8daa9    
  
author   : Tom Lane <[email protected]>    
date     : Mon, 11 Nov 2024 10:29:54 -0500    
  
committer: Tom Lane <[email protected]>    
date     : Mon, 11 Nov 2024 10:29:54 -0500    

Click here for diff

The SQL spec mandates that SET SESSION AUTHORIZATION implies  
SET ROLE NONE.  We tried to implement that within the lowest-level  
functions that manipulate these settings, but that was a bad idea.  
In particular, guc.c assumes that it doesn't matter in what order  
it applies GUC variable updates, but that was not the case for these  
two variables.  This problem, compounded by some hackish attempts to  
work around it, led to some security-grade issues:  
  
* Rolling back a transaction that had done SET SESSION AUTHORIZATION  
would revert to SET ROLE NONE, even if that had not been the previous  
state, so that the effective user ID might now be different from what  
it had been.  
  
* The same for SET SESSION AUTHORIZATION in a function SET clause.  
  
* If a parallel worker inspected current_setting('role'), it saw  
"none" even when it should see something else.  
  
Also, although the parallel worker startup code intended to cope  
with the current role's pg_authid row having disappeared, its  
implementation of that was incomplete so it would still fail.  
  
Fix by fully separating the miscinit.c functions that assign  
session_authorization from those that assign role.  To implement the  
spec's requirement, teach set_config_option itself to perform "SET  
ROLE NONE" when it sets session_authorization.  (This is undoubtedly  
ugly, but the alternatives seem worse.  In particular, there's no way  
to do it within assign_session_authorization without incompatible  
changes in the API for GUC assign hooks.)  Also, improve  
ParallelWorkerMain to directly set all the relevant user-ID variables  
instead of relying on some of them to get set indirectly.  That  
allows us to survive not finding the pg_authid row during worker  
startup.  
  
In v16 and earlier, this includes back-patching 9987a7bf3 which  
fixed a violation of GUC coding rules: SetSessionAuthorization  
is not an appropriate place to be throwing errors from.  
  
Security: CVE-2024-10978  

M src/backend/access/transam/parallel.c
M src/backend/commands/variable.c
M src/backend/utils/init/miscinit.c
M src/backend/utils/misc/guc.c
M src/include/miscadmin.h
M src/test/regress/expected/privileges.out
M src/test/regress/sql/privileges.sql

Ensure cached plans are correctly marked as dependent on role.

commit   : 6db5ea8de8ce15897b706009aaf701d23bd65b23    
  
author   : Nathan Bossart <[email protected]>    
date     : Mon, 11 Nov 2024 09:00:00 -0600    
  
committer: Nathan Bossart <[email protected]>    
date     : Mon, 11 Nov 2024 09:00:00 -0600    

Click here for diff

If a CTE, subquery, sublink, security invoker view, or coercion  
projection references a table with row-level security policies, we  
neglected to mark the plan as potentially dependent on which role  
is executing it.  This could lead to later executions in the same  
session returning or hiding rows that should have been hidden or  
returned instead.  
  
Reported-by: Wolfgang Walther  
Reviewed-by: Noah Misch  
Security: CVE-2024-10976  
Backpatch-through: 12  

M src/backend/executor/functions.c
M src/backend/rewrite/rewriteHandler.c
M src/test/regress/expected/rowsecurity.out
M src/test/regress/sql/rowsecurity.sql
M src/tools/pgindent/typedefs.list

Block environment variable mutations from trusted PL/Perl.

commit   : e530835c6cc5b2dbf330ebe6b0a7fb9f19f5a54c    
  
author   : Noah Misch <[email protected]>    
date     : Mon, 11 Nov 2024 06:23:43 -0800    
  
committer: Noah Misch <[email protected]>    
date     : Mon, 11 Nov 2024 06:23:43 -0800    

Click here for diff

Many process environment variables (e.g. PATH), bypass the containment  
expected of a trusted PL.  Hence, trusted PLs must not offer features  
that achieve setenv().  Otherwise, an attacker having USAGE privilege on  
the language often can achieve arbitrary code execution, even if the  
attacker lacks a database server operating system user.  
  
To fix PL/Perl, replace trusted PL/Perl %ENV with a tied hash that just  
replaces each modification attempt with a warning.  Sites that reach  
these warnings should evaluate the application-specific implications of  
proceeding without the environment modification:  
  
  Can the application reasonably proceed without the modification?  
  
    If no, switch to plperlu or another approach.  
  
    If yes, the application should change the code to stop attempting  
    environment modifications.  If that's too difficult, add "untie  
    %main::ENV" in any code executed before the warning.  For example,  
    one might add it to the start of the affected function or even to  
    the plperl.on_plperl_init setting.  
  
In passing, link to Perl's guidance about the Perl features behind the  
security posture of PL/Perl.  
  
Back-patch to v12 (all supported versions).  
  
Andrew Dunstan and Noah Misch  
  
Security: CVE-2024-10979  

M doc/src/sgml/plperl.sgml
M src/pl/plperl/GNUmakefile
A src/pl/plperl/expected/plperl_env.out
M src/pl/plperl/plc_trusted.pl
A src/pl/plperl/sql/plperl_env.sql
M src/test/regress/regress.c

Translation updates

commit   : 3f2c24e55b7ecfd06a4b65b9a52f74f27b580046    
  
author   : Peter Eisentraut <[email protected]>    
date     : Mon, 11 Nov 2024 13:55:53 +0100    
  
committer: Peter Eisentraut <[email protected]>    
date     : Mon, 11 Nov 2024 13:55:53 +0100    

Click here for diff

Source-Git-URL: https://git.postgresql.org/git/pgtranslation/messages.git  
Source-Git-Hash: ecbca81dbf801f683e24897668cec8d1fb0f55a5  

M src/backend/po/de.po
M src/backend/po/es.po
M src/backend/po/fr.po
M src/backend/po/ja.po
M src/backend/po/ru.po
M src/backend/po/sv.po
M src/bin/initdb/po/es.po
M src/bin/initdb/po/fr.po
M src/bin/initdb/po/ru.po
M src/bin/pg_amcheck/po/es.po
M src/bin/pg_amcheck/po/fr.po
M src/bin/pg_amcheck/po/ru.po
M src/bin/pg_archivecleanup/po/es.po
M src/bin/pg_archivecleanup/po/fr.po
M src/bin/pg_archivecleanup/po/ru.po
M src/bin/pg_basebackup/po/es.po
M src/bin/pg_basebackup/po/fr.po
M src/bin/pg_basebackup/po/ru.po
M src/bin/pg_checksums/po/es.po
M src/bin/pg_checksums/po/fr.po
M src/bin/pg_checksums/po/ru.po
M src/bin/pg_config/po/es.po
M src/bin/pg_config/po/fr.po
M src/bin/pg_config/po/ru.po
M src/bin/pg_controldata/po/es.po
M src/bin/pg_controldata/po/fr.po
M src/bin/pg_controldata/po/ru.po
M src/bin/pg_ctl/po/es.po
M src/bin/pg_ctl/po/fr.po
M src/bin/pg_ctl/po/ru.po
M src/bin/pg_dump/po/es.po
M src/bin/pg_dump/po/fr.po
M src/bin/pg_dump/po/ru.po
M src/bin/pg_resetwal/po/es.po
M src/bin/pg_resetwal/po/fr.po
M src/bin/pg_resetwal/po/ru.po
M src/bin/pg_rewind/po/es.po
M src/bin/pg_rewind/po/fr.po
M src/bin/pg_rewind/po/ru.po
M src/bin/pg_test_fsync/po/es.po
M src/bin/pg_test_fsync/po/fr.po
M src/bin/pg_test_fsync/po/ru.po
M src/bin/pg_test_timing/po/es.po
M src/bin/pg_test_timing/po/fr.po
M src/bin/pg_test_timing/po/ru.po
M src/bin/pg_upgrade/po/es.po
M src/bin/pg_upgrade/po/fr.po
M src/bin/pg_upgrade/po/ru.po
M src/bin/pg_verifybackup/po/es.po
M src/bin/pg_verifybackup/po/fr.po
M src/bin/pg_verifybackup/po/ru.po
M src/bin/pg_waldump/po/es.po
M src/bin/pg_waldump/po/fr.po
M src/bin/pg_waldump/po/ru.po
M src/bin/psql/po/de.po
M src/bin/psql/po/es.po
M src/bin/psql/po/fr.po
M src/bin/psql/po/ja.po
M src/bin/psql/po/ru.po
M src/bin/scripts/po/es.po
M src/bin/scripts/po/fr.po
M src/bin/scripts/po/ru.po
M src/interfaces/ecpg/ecpglib/po/es.po
M src/interfaces/ecpg/ecpglib/po/fr.po
M src/interfaces/ecpg/preproc/po/es.po
M src/interfaces/ecpg/preproc/po/fr.po
M src/interfaces/ecpg/preproc/po/ru.po
M src/interfaces/libpq/po/es.po
M src/interfaces/libpq/po/fr.po
M src/interfaces/libpq/po/ja.po
M src/interfaces/libpq/po/ru.po
M src/pl/plperl/po/es.po
M src/pl/plperl/po/fr.po
M src/pl/plperl/po/ru.po
M src/pl/plpgsql/src/po/es.po
M src/pl/plpgsql/src/po/fr.po
M src/pl/plpgsql/src/po/ru.po
M src/pl/plpython/po/es.po
M src/pl/plpython/po/fr.po
M src/pl/tcl/po/es.po
M src/pl/tcl/po/fr.po

libpq: Bail out during SSL/GSS negotiation errors

commit   : d2c3e31c13a6820980c2c6019f0b8f9f0b63ae6e    
  
author   : Michael Paquier <[email protected]>    
date     : Mon, 11 Nov 2024 10:19:59 +0900    
  
committer: Michael Paquier <[email protected]>    
date     : Mon, 11 Nov 2024 10:19:59 +0900    

Click here for diff

This commit changes libpq so that errors reported by the backend during  
the protocol negotiation for SSL and GSS are discarded by the client, as  
these may include bytes that could be consumed by the client and write  
arbitrary bytes to a client's terminal.  
  
A failure with the SSL negotiation now leads to an error immediately  
reported, without a retry on any other methods allowed, like a fallback  
to a plaintext connection.  
  
A failure with GSS discards the error message received, and we allow a  
fallback as it may be possible that the error is caused by a connection  
attempt with a pre-11 server, GSS encryption having been introduced in  
v12.  This was a problem only with v17 and newer versions; older  
versions discard the error message already in this case, assuming a  
failure caused by a lack of support for GSS encryption.  
  
Author: Jacob Champion  
Reviewed-by: Peter Eisentraut, Heikki Linnakangas, Michael Paquier  
Security: CVE-2024-10977  
Backpatch-through: 12  

M doc/src/sgml/protocol.sgml
M src/interfaces/libpq/fe-connect.c

Release notes for 17.1, 16.5, 15.9, 14.14, 13.17, 12.21.

commit   : f7b1678d0c75a63899d7240dff07989aec546ace    
  
author   : Tom Lane <[email protected]>    
date     : Sun, 10 Nov 2024 13:40:41 -0500    
  
committer: Tom Lane <[email protected]>    
date     : Sun, 10 Nov 2024 13:40:41 -0500    

Click here for diff

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

Improve fix for not entering parallel mode when holding interrupts.

commit   : bcbdb176e1e2d62d8e39bebdfc8130bded67ef36    
  
author   : Tom Lane <[email protected]>    
date     : Fri, 8 Nov 2024 13:42:01 -0500    
  
committer: Tom Lane <[email protected]>    
date     : Fri, 8 Nov 2024 13:42:01 -0500    

Click here for diff

Commit ac04aa84a put the shutoff for this into the planner, which is  
not ideal because it doesn't prevent us from re-using a previously  
made parallel plan.  Revert the planner change and instead put the  
shutoff into InitializeParallelDSM, modeling it on the existing code  
there for recovering from failure to allocate a DSM segment.  
  
However, that code path is mostly untested, and testing a bit harder  
showed there's at least one bug: ExecHashJoinReInitializeDSM is not  
prepared for us to have skipped doing parallel DSM setup.  I also  
thought the Assert in ReinitializeParallelWorkers is pretty  
ill-advised, and replaced it with a silent Min() operation.  
  
The existing test case added by ac04aa84a serves fine to test this  
version of the fix, so no change needed there.  
  
Patch by me, but thanks to Noah Misch for the core idea that we  
could shut off worker creation when !INTERRUPTS_CAN_BE_PROCESSED.  
Back-patch to v12, as ac04aa84a was.  
  
Discussion: https://postgr.es/m/CAC-SaSzHUKT=vZJ8MPxYdC_URPfax+yoA1hKTcF4ROz_Q6z0_Q@mail.gmail.com  

M src/backend/access/transam/parallel.c
M src/backend/executor/nodeHashjoin.c
M src/backend/optimizer/plan/planner.c

Disallow partitionwise join when collations don't match

commit   : 33040b1715c7a3450a6b3dc61bd7779a5f9ae709    
  
author   : Amit Langote <[email protected]>    
date     : Fri, 8 Nov 2024 16:30:22 +0900    
  
committer: Amit Langote <[email protected]>    
date     : Fri, 8 Nov 2024 16:30:22 +0900    

Click here for diff

If the collation of any join key column doesn’t match the collation of  
the corresponding partition key, partitionwise joins can yield incorrect  
results. For example, rows that would match under the join key collation  
might be located in different partitions due to the partitioning  
collation. In such cases, a partitionwise join would yield different  
results from a non-partitionwise join, so disallow it in such cases.  
  
Reported-by: Tender Wang <[email protected]>  
Author: Jian He <[email protected]>  
Reviewed-by: Tender Wang <[email protected]>  
Reviewed-by: Junwang Zhao <[email protected]>  
Discussion: https://postgr.es/m/CAHewXNno_HKiQ6PqyLYfuqDtwp7KKHZiH1J7Pqyz0nr+PS2Dwg@mail.gmail.com  
Backpatch-through: 12  

M src/backend/optimizer/util/relnode.c
M src/test/regress/expected/collate.icu.utf8.out
M src/test/regress/sql/collate.icu.utf8.sql

Disallow partitionwise grouping when collations don't match

commit   : 0a620659c549f05881800fddd1859f3e373dd9cf    
  
author   : Amit Langote <[email protected]>    
date     : Fri, 8 Nov 2024 16:06:58 +0900    
  
committer: Amit Langote <[email protected]>    
date     : Fri, 8 Nov 2024 16:06:58 +0900    

Click here for diff

If the collation of any grouping column doesn’t match the collation of  
the corresponding partition key, partitionwise grouping can yield  
incorrect results. For example, rows that would be grouped under the  
grouping collation may end up in different partitions under the  
partitioning collation. In such cases, full partitionwise grouping  
would produce results that differ from those without partitionwise  
grouping, so disallowed that.  
  
Partial partitionwise aggregation is still allowed, as the Finalize  
step reconciles partition-level aggregates with grouping requirements  
across all partitions, ensuring that the final output remains  
consistent.  
  
This commit also fixes group_by_has_partkey() by ensuring the  
RelabelType node is stripped from grouping expressions when matching  
them to partition key expressions to avoid false mismatches.  
  
Bug: #18568  
Reported-by: Webbo Han <[email protected]>  
Author: Webbo Han <[email protected]>  
Reviewed-by: Tender Wang <[email protected]>  
Reviewed-by: Aleksander Alekseev <[email protected]>  
Reviewed-by: Jian He <[email protected]>  
Discussion: https://postgr.es/m/[email protected]  
Discussion: https://postgr.es/m/[email protected]  
Discussion: https://postgr.es/m/CAHewXNno_HKiQ6PqyLYfuqDtwp7KKHZiH1J7Pqyz0nr+PS2Dwg@mail.gmail.com  
Backpatch-through: 12  

M src/backend/optimizer/plan/planner.c
M src/test/regress/expected/collate.icu.utf8.out
M src/test/regress/sql/collate.icu.utf8.sql

Message style improvement

commit   : 38f506470f3faebb00bbb352ec2ea25d1f6c33a2    
  
author   : Peter Eisentraut <[email protected]>    
date     : Fri, 8 Nov 2024 07:17:55 +0100    
  
committer: Peter Eisentraut <[email protected]>    
date     : Fri, 8 Nov 2024 07:17:55 +0100    

Click here for diff

Backpatch the part of edee0c621de that applies to a90bdd7a44d, which  
was also backpatched.  That way, the message is consistent in all  
branches.  

M src/backend/commands/tablecmds.c
M src/test/regress/expected/foreign_key.out

commit   : b9d4a927d627bf5802e7e8e797ffc60d21bbac8b    
  
author   : Thomas Munro <[email protected]>    
date     : Sat, 6 Aug 2022 12:01:42 +1200    
  
committer: Andrew Dunstan <[email protected]>    
date     : Sat, 6 Aug 2022 12:01:42 +1200    

Click here for diff

To support harmonization of Windows and Unix code, teach our unlink()  
wrapper that junction points need to be unlinked with rmdir() on  
Windows.  
  
Tested-by: Andrew Dunstan <[email protected]>  
Discussion: https://postgr.es/m/CA%2BhUKGLfOOeyZpm5ByVcAt7x5Pn-%3DxGRNCvgiUPVVzjFLtnY0w%40mail.gmail.com  
(cherry picked from commit f357233c9db8be2a015163da8e1ab0630f444340)  
  
Author: Thomas Munro <[email protected]>  
Author: Alexandra Wang <[email protected]>  

M src/port/dirmod.c

Replace pgwin32_is_junction() with lstat().

commit   : f95ad555de5623588bcc6e48fe8a3fd50d721216    
  
author   : Thomas Munro <[email protected]>    
date     : Sat, 6 Aug 2022 12:02:43 +1200    
  
committer: Andrew Dunstan <[email protected]>    
date     : Sat, 6 Aug 2022 12:02:43 +1200    

Click here for diff

Now that lstat() reports junction points with S_IFLNK/S_ISLINK(), and  
unlink() can unlink them, there is no need for conditional code for  
Windows in a few places.  That was expressed by testing for WIN32 or  
S_ISLNK, which we can now constant-fold.  
  
The coding around pgwin32_is_junction() was a bit suspect anyway, as we  
never checked for errors, and we also know that errors can be spuriously  
reported because of transient sharing violations on this OS.  The  
lstat()-based code has handling for that.  
  
This also reverts 4fc6b6ee on master only.  That was done because  
lstat() didn't previously work for symlinks (junction points), but now  
it does.  
  
Tested-by: Andrew Dunstan <[email protected]>  
Discussion: https://postgr.es/m/CA%2BhUKGLfOOeyZpm5ByVcAt7x5Pn-%3DxGRNCvgiUPVVzjFLtnY0w%40mail.gmail.com  
(cherry picked from commit 5fc88c5d53e43fa7dcea93499d230a0bf70f4f77)  
  
Author: Thomas Munro <[email protected]>  
Author: Alexandra Wang <[email protected]>  

M src/backend/backup/basebackup.c
M src/backend/commands/tablespace.c
M src/backend/storage/file/fd.c
M src/backend/utils/adt/misc.c
M src/bin/pg_checksums/pg_checksums.c
M src/bin/pg_rewind/file_ops.c
M src/common/file_utils.c
M src/include/port.h
M src/include/port/win32_port.h
M src/port/dirmod.c

Fix lstat() for broken junction points on Windows.

commit   : f2a4a137bb93922a925255665f5a47094ed8c9df    
  
author   : Thomas Munro <[email protected]>    
date     : Tue, 25 Oct 2022 15:20:00 +1300    
  
committer: Andrew Dunstan <[email protected]>    
date     : Tue, 25 Oct 2022 15:20:00 +1300    

Click here for diff

When using junction points to emulate symlinks on Windows, one edge case  
was not handled correctly by commit c5cb8f3b: if a junction point is  
broken (pointing to a non-existent path), we'd report ENOENT.  This  
doesn't break any known use case, but was noticed while developing a  
test suite for these functions and is fixed here for completeness.  
  
Also add translation ERROR_CANT_RESOLVE_FILENAME -> ENOENT, as that is  
one of the errors Windows can report for some kinds of broken paths.  
  
Discussion: https://postgr.es/m/CA%2BhUKG%2BajSQ_8eu2AogTncOnZ5me2D-Cn66iN_-wZnRjLN%2Bicg%40mail.gmail.com  
(cherry picked from commit 387803d81d6256fcb60b9192bb5b00042442b4e3)  
  
Author: Thomas Munro <[email protected]>  
Author: Alexandra Wang <[email protected]>  

M src/port/win32error.c
M src/port/win32stat.c

Provide lstat() for Windows.

commit   : b73c1496dc7aba7748eb3d55b29c4eb0dc788296    
  
author   : Thomas Munro <[email protected]>    
date     : Sat, 6 Aug 2022 12:00:57 +1200    
  
committer: Andrew Dunstan <[email protected]>    
date     : Sat, 6 Aug 2022 12:00:57 +1200    

Click here for diff

Junction points will be reported with S_ISLNK(x.st_mode), simulating  
POSIX lstat().  stat() will follow pseudo-symlinks, like in POSIX (but  
only one level before giving up, unlike in POSIX).  
  
This completes a TODO left by commit bed90759fcb.  
  
Tested-by: Andrew Dunstan <[email protected]> (earlier version)  
Discussion: https://postgr.es/m/CA%2BhUKGLfOOeyZpm5ByVcAt7x5Pn-%3DxGRNCvgiUPVVzjFLtnY0w%40mail.gmail.com  
(cherry picked from commit c5cb8f3b770c043509b61528664bcd805e1777e6)  
  
Author: Thomas Munro <[email protected]>  
Author:	Alexandra Wang <[email protected]>  

M src/include/port/win32_port.h
M src/port/win32stat.c

doc: Reword ALTER TABLE ATTACH restriction on NO INHERIT constraints

commit   : d291e819be0c21691e5acfe000738b47deaaf0c9    
  
author   : Álvaro Herrera <[email protected]>    
date     : Thu, 7 Nov 2024 14:06:24 +0100    
  
committer: Álvaro Herrera <[email protected]>    
date     : Thu, 7 Nov 2024 14:06:24 +0100    

Click here for diff

The previous wording is easy to read incorrectly; this change makes it  
simpler, less ambiguous, and less prominent.  
  
Backpatch to all live branches.  
  
Reviewed-by: Amit Langote <[email protected]>  
Discussion: https://postgr.es/m/[email protected]  

M doc/src/sgml/ref/alter_table.sgml

Monkey-patch LLVM code to fix ARM relocation bug.

commit   : 19bf81c06a372a138215d25e9844e68ddde35313    
  
author   : Thomas Munro <[email protected]>    
date     : Wed, 6 Nov 2024 22:04:44 +1300    
  
committer: Thomas Munro <[email protected]>    
date     : Wed, 6 Nov 2024 22:04:44 +1300    

Click here for diff

Supply a new memory manager for RuntimeDyld, to avoid crashes in  
generated code caused by memory placement that can overflow a 32 bit  
data type.  This is a drop-in replacement for the  
llvm::SectionMemoryManager class in the LLVM library, with Michael  
Smith's proposed fix from  
https://www.github.com/llvm/llvm-project/pull/71968.  
  
We hereby slurp it into our own source tree, after moving into a new  
namespace llvm::backport and making some minor adjustments so that it  
can be compiled with older LLVM versions as far back as 12.  It's harder  
to make it work on even older LLVM versions, but it doesn't seem likely  
that people are really using them so that is not investigated for now.  
  
The problem could also be addressed by switching to JITLink instead of  
RuntimeDyld, and that is the LLVM project's recommended solution as  
the latter is about to be deprecated.  We'll have to do that soon enough  
anyway, and then when the LLVM version support window advances far  
enough in a few years we'll be able to delete this code.  Unfortunately  
that wouldn't be enough for PostgreSQL today: in most relevant versions  
of LLVM, JITLink is missing or incomplete.  
  
Several other projects have already back-ported this fix into their fork  
of LLVM, which is a vote of confidence despite the lack of commit into  
LLVM as of today.  We don't have our own copy of LLVM so we can't do  
exactly what they've done; instead we have a copy of the whole patched  
class so we can pass an instance of it to RuntimeDyld.  
  
The LLVM project hasn't chosen to commit the fix yet, and even if it  
did, it wouldn't be back-ported into the releases of LLVM that most of  
our users care about, so there is not much point in waiting any longer  
for that.  If they make further changes and commit it to LLVM 19 or 20,  
we'll still need this for older versions, but we may want to  
resynchronize our copy and update some comments.  
  
The changes that we've had to make to our copy can be seen by diffing  
our SectionMemoryManager.{h,cpp} files against the ones in the tree of  
the pull request.  Per the LLVM project's license requirements, a copy  
is in SectionMemoryManager.LICENSE.  
  
This should fix the spate of crash reports we've been receiving lately  
from users on large memory ARM systems.  
  
Back-patch to all supported releases.  
  
Co-authored-by: Thomas Munro <[email protected]>  
Co-authored-by: Anthonin Bonnefoy <[email protected]>  
Reviewed-by: Anthonin Bonnefoy <[email protected]>  
Reviewed-by: Daniel Gustafsson <[email protected]> (license aspects)  
Reported-by: Anthonin Bonnefoy <[email protected]>  
Discussion: https://postgr.es/m/CAO6_Xqr63qj%3DSx7HY6ZiiQ6R_JbX%2B-p6sTPwDYwTWZjUmjsYBg%40mail.gmail.com  

M src/backend/jit/llvm/Makefile
A src/backend/jit/llvm/SectionMemoryManager.LICENSE
A src/backend/jit/llvm/SectionMemoryManager.cpp
M src/backend/jit/llvm/llvmjit.c
M src/backend/jit/llvm/llvmjit_wrap.cpp
A src/include/jit/SectionMemoryManager.h
M src/include/jit/llvmjit.h
A src/include/jit/llvmjit_backport.h
M src/tools/pginclude/headerscheck
M src/tools/pgindent/exclude_file_patterns

Clear padding of PgStat_HashKey when handling pgstats entries

commit   : 6d5e6693ee6bd08ed47713c808dbd281cf9cf9cd    
  
author   : Michael Paquier <[email protected]>    
date     : Tue, 5 Nov 2024 09:41:01 +0900    
  
committer: Michael Paquier <[email protected]>    
date     : Tue, 5 Nov 2024 09:41:01 +0900    

Click here for diff

PgStat_HashKey is currently initialized in a way that could result in  
random data if the structure has any padding bytes.  The structure  
has no padding bytes currently, fortunately, but it could become a  
problem should the structure change at some point in the future.  
  
The code is changed to use some memset(0) so as any padding would be  
handled properly, as it would be surprising to see random failures in  
the pgstats entry lookups.  PgStat_HashKey is a structure internal to  
pgstats, and an ABI change could be possible in the scope of a bug fix,  
so backpatch down to 15 where this has been introduced.  
  
Author: Bertrand Drouvot  
Reviewed-by: Jelte Fennema-Nio, Michael Paquier  
Discussion: https://postgr.es/m/[email protected]  
Backpatch-through: 15  

M src/backend/utils/activity/pgstat.c
M src/backend/utils/activity/pgstat_shmem.c

Suppress new "may be used uninitialized" warning.

commit   : d14e94ac45795f5bf55ba80b2a6f5acd02702e0f    
  
author   : Noah Misch <[email protected]>    
date     : Sat, 2 Nov 2024 19:42:52 -0700    
  
committer: Noah Misch <[email protected]>    
date     : Sat, 2 Nov 2024 19:42:52 -0700    

Click here for diff

Buildfarm member mamba fails to deduce that the function never uses this  
variable without initializing it.  Back-patch to v12, like commit  
b412f402d1e020c5dac94f3bf4a005db69519b99.  

M src/backend/catalog/index.c

Move I/O before the index_update_stats() buffer lock region.

commit   : 6d5b4031b927328e548088ebcc24781223b3b803    
  
author   : Noah Misch <[email protected]>    
date     : Sat, 2 Nov 2024 09:04:55 -0700    
  
committer: Noah Misch <[email protected]>    
date     : Sat, 2 Nov 2024 09:04:55 -0700    

Click here for diff

Commit a07e03fd8fa7daf4d1356f7cb501ffe784ea6257 enlarged the work done  
here under the pg_class heap buffer lock.  Two preexisting actions are  
best done before holding that lock.  Both RelationGetNumberOfBlocks()  
and visibilitymap_count() do I/O, and the latter might exclusive-lock a  
visibility map buffer.  Moving these reduces contention and risk of  
undetected LWLock deadlock.  Back-patch to v12, like that commit.  
  
Discussion: https://postgr.es/m/[email protected]  

M src/backend/catalog/index.c

Revert "For inplace update, send nontransactional invalidations."

commit   : 27642d89081ec5ec2949b1a52cb707adce5798e8    
  
author   : Noah Misch <[email protected]>    
date     : Sat, 2 Nov 2024 09:05:00 -0700    
  
committer: Noah Misch <[email protected]>    
date     : Sat, 2 Nov 2024 09:05:00 -0700    

Click here for diff

This reverts commit 95c5acb3fc261067ab65ddc0b2dca8e162f09442 (v17) and  
counterparts in each other non-master branch.  If released, that commit  
would have caused a worst-in-years minor release regression, via  
undetected LWLock self-deadlock.  This commit and its self-deadlock fix  
warrant more bake time in the master branch.  
  
Reported by Alexander Lakhin.  
  
Discussion: https://postgr.es/m/[email protected]  

M src/backend/access/heap/heapam.c
M src/backend/access/transam/xact.c
M src/backend/catalog/index.c
M src/backend/replication/logical/decode.c
M src/backend/utils/cache/catcache.c
M src/backend/utils/cache/inval.c
M src/backend/utils/cache/syscache.c
M src/include/utils/catcache.h
M src/include/utils/inval.h
M src/test/isolation/expected/inplace-inval.out
M src/test/isolation/specs/inplace-inval.spec
M src/tools/pgindent/typedefs.list

Revert "WAL-log inplace update before revealing it to other sessions."

commit   : e50f9de98d63fe81c34368df1ed452de33807ad9    
  
author   : Noah Misch <[email protected]>    
date     : Sat, 2 Nov 2024 09:04:59 -0700    
  
committer: Noah Misch <[email protected]>    
date     : Sat, 2 Nov 2024 09:04:59 -0700    

Click here for diff

This reverts commit bfd5c6e279c8e1702eea882439dc7ebdf4d4b3a5 (v17) and  
counterparts in each other non-master branch.  This unblocks reverting a  
commit on which it depends.  
  
Discussion: https://postgr.es/m/[email protected]  

M src/backend/access/heap/README.tuplock
M src/backend/access/heap/heapam.c

doc: fix ALTER DOMAIN domain_constraint to spell out options

commit   : ce0ddbbf3e6fd9160309632ab94d3df3df5087b3    
  
author   : Bruce Momjian <[email protected]>    
date     : Fri, 1 Nov 2024 13:54:28 -0400    
  
committer: Bruce Momjian <[email protected]>    
date     : Fri, 1 Nov 2024 13:54:28 -0400    

Click here for diff

It used to refer to CREATE DOMAIN, but CREATE DOMAIN allows NULL, while  
ALTER DOMAIN does not.  
  
Reported-by: [email protected]  
  
Discussion: https://postgr.es/m/[email protected]  
  
Backpatch-through: 12  

M doc/src/sgml/ref/alter_domain.sgml

doc: remove mention of ActiveState for Perl and Tcl on Windows

commit   : 4bedca41f5f605e2c95ccea5aa89a7c4d4f63103    
  
author   : Bruce Momjian <[email protected]>    
date     : Fri, 1 Nov 2024 11:30:53 -0400    
  
committer: Bruce Momjian <[email protected]>    
date     : Fri, 1 Nov 2024 11:30:53 -0400    

Click here for diff

Replace with Strawberry Perl and Magicsplat Tcl.  
  
Reported-by: Yasir Hussain  
  
Discussion: https://postgr.es/m/CAA9OW9fAAM_WDYYpAquqF6j1hmfRMzHPsFkRfP5E6oSfkF=dMA@mail.gmail.com  
  
Backpatch-through: 12  

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

Fix some more bugs in foreign keys connecting partitioned tables

commit   : 1b216fceffe3e4858b4e1e58427534e115f27547    
  
author   : Álvaro Herrera <[email protected]>    
date     : Wed, 30 Oct 2024 10:54:03 +0100    
  
committer: Álvaro Herrera <[email protected]>    
date     : Wed, 30 Oct 2024 10:54:03 +0100    

Click here for diff

* In DetachPartitionFinalize() we were applying a tuple conversion map  
  to tuples that didn't need one, which can lead to erratic behavior if  
  a partitioned table has a partition with a different column order, as  
  reported by Alexander Lakhin. This was introduced by 53af9491a043.  
  Don't do that.  Also, modify a recently added test case to exercise  
  this.  
  
* The same function as well as CloneFkReferenced() were acquiring  
  AccessShareLock on a partition, only to have CreateTrigger() later  
  acquire ShareRowExclusiveLock on it.  This can lead to deadlock by  
  lock escalation, unnecessarily.  Avoid that by acquiring the stronger  
  lock to begin with.  This probably dates back to branch 12, but I have  
  never seen a report of this being a problem in the field.  
  
* Innocuous but wasteful: also introduced by 53af9491a043, we were  
  reading a pg_constraint tuple from syscache that we don't need, as  
  reported by Tender Wang.  Don't.  
  
Backpatch to 15.  
  
Discussion: https://postgr.es/m/[email protected]  

M src/backend/commands/tablecmds.c
M src/test/regress/expected/foreign_key.out
M src/test/regress/sql/foreign_key.sql

Unpin buffer before inplace update waits for an XID to end.

commit   : 0fe002d0c9a5b04bb676e9cb8f80325f7129b5f3    
  
author   : Noah Misch <[email protected]>    
date     : Tue, 29 Oct 2024 09:39:55 -0700    
  
committer: Noah Misch <[email protected]>    
date     : Tue, 29 Oct 2024 09:39:55 -0700    

Click here for diff

Commit a07e03fd8fa7daf4d1356f7cb501ffe784ea6257 changed inplace updates  
to wait for heap_update() commands like GRANT TABLE and GRANT DATABASE.  
By keeping the pin during that wait, a sequence of autovacuum workers  
and an uncommitted GRANT starved one foreground LockBufferForCleanup()  
for six minutes, on buildfarm member sarus.  Prevent, at the cost of a  
bit of complexity.  Back-patch to v12, like the earlier commit.  That  
commit and heap_inplace_lock() have not yet appeared in any release.  
  
Discussion: https://postgr.es/m/[email protected]  

M src/backend/access/heap/heapam.c
M src/backend/access/index/genam.c
M src/include/access/heapam.h

Update time zone data files to tzdata release 2024b.

commit   : 74f70cb8633d186928fad24ff60d922613f89c6d    
  
author   : Tom Lane <[email protected]>    
date     : Tue, 29 Oct 2024 11:49:38 -0400    
  
committer: Tom Lane <[email protected]>    
date     : Tue, 29 Oct 2024 11:49:38 -0400    

Click here for diff

Historical corrections for Mexico, Mongolia, and Portugal.  
Notably, Asia/Choibalsan is now an alias for Asia/Ulaanbaatar  
rather than being a separate zone, mainly because the differences  
between those zones were found to be based on untrustworthy data.  

M src/timezone/data/tzdata.zi
M src/timezone/known_abbrevs.txt
M src/timezone/tznames/Default
M src/timezone/tznames/Europe.txt

doc: Add better description for rewrite functions in event triggers

commit   : 14440d3b07af2241460eb268811cf54f8eee365f    
  
author   : Michael Paquier <[email protected]>    
date     : Tue, 29 Oct 2024 15:35:19 +0900    
  
committer: Michael Paquier <[email protected]>    
date     : Tue, 29 Oct 2024 15:35:19 +0900    

Click here for diff

There are two functions that can be used in event triggers to get more  
details about a rewrite happening on a relation.  Both had a limited  
documentation:  
- pg_event_trigger_table_rewrite_reason() and  
pg_event_trigger_table_rewrite_oid() were not mentioned in the main  
event trigger section in the paragraph dedicated to the event  
table_rewrite.  
- pg_event_trigger_table_rewrite_reason() returns an integer which is a  
bitmap of the reasons why a rewrite happens.  There was no explanation  
about the meaning of these values, forcing the reader to look at the  
code to find out that these are defined in event_trigger.h.  
  
While on it, let's add a comment in event_trigger.h where the  
AT_REWRITE_* are defined, telling to update the documentation when  
these values are changed.  
  
Backpatch down to 13 as a consequence of 1ad23335f36b, where this area  
of the documentation has been heavily reworked.  
  
Author: Greg Sabino Mullane  
Discussion: https://postgr.es/m/CAKAnmmL+Z6j-C8dAx1tVrnBmZJu+BSoc68WSg3sR+CVNjBCqbw@mail.gmail.com  
Backpatch-through: 13  

M doc/src/sgml/event-trigger.sgml
M doc/src/sgml/func.sgml
M src/include/commands/event_trigger.h

Doc: clarify enable_indexscan=off also disabled Index Only Scans

commit   : 75f09cc460a3a1780df1dcd102f46e59779f9903    
  
author   : David Rowley <[email protected]>    
date     : Tue, 29 Oct 2024 16:25:29 +1300    
  
committer: David Rowley <[email protected]>    
date     : Tue, 29 Oct 2024 16:25:29 +1300    

Click here for diff

Disabling enable_indexscan has always also disabled Index Only Scans.  
Here we make that more clear in the documentation in an attempt to  
prevent future complaints complaining about this expected behavior.  
  
Reported-by: Melanie Plageman  
Author: David G. Johnston, David Rowley  
Backpatch-through: 12, oldest supported version  
Discussion: https://postgr.es/m/CAAKRu_atV=kovgpaLREyG68PB5+ncKvJ2UNoeRetEgyC3Yb5Sw@mail.gmail.com  

M doc/src/sgml/config.sgml

Guard against enormously long input in pg_saslprep().

commit   : dfff687f3c25fd114a7ab7d22df645716a98139f    
  
author   : Tom Lane <[email protected]>    
date     : Mon, 28 Oct 2024 14:33:55 -0400    
  
committer: Tom Lane <[email protected]>    
date     : Mon, 28 Oct 2024 14:33:55 -0400    

Click here for diff

Coverity complained that pg_saslprep() could suffer integer overflow,  
leading to under-allocation of the output buffer, if the input string  
exceeds SIZE_MAX/4.  This hazard seems largely hypothetical, but it's  
easy enough to defend against, so let's do so.  
  
This patch creates a third place in src/common/ where we are locally  
defining MaxAllocSize so that we can test against that in the same way  
in backend and frontend compiles.  That seems like about two places  
too many, so the next patch will move that into common/fe_memutils.h.  
I'm hesitant to do that in back branches however.  
  
Back-patch to v14.  The code looks similar in older branches, but  
before commit 67a472d71 there was a separate test on the input string  
length that prevented this hazard.  
  
Per Coverity report.  

M src/common/saslprep.c

Fix overflow in bsearch_arg() with more than INT_MAX elements

commit   : 07ca2d4110d474669fa03203782b5dae24f1c5c6    
  
author   : Heikki Linnakangas <[email protected]>    
date     : Mon, 28 Oct 2024 14:07:38 +0200    
  
committer: Heikki Linnakangas <[email protected]>    
date     : Mon, 28 Oct 2024 14:07:38 +0200    

Click here for diff

This was introduced in commit bfa2cee784, which replaced the old  
bsearch_cmp() function we had in extended_stats.c with the current  
implementation. The original discussion or commit message of  
bfa2cee784 didn't mention where the new implementation came from, but  
based on some googling, I'm guessing *BSD or libiberty, all of which  
share this same code, with or without this fix.  
  
Author: Ranier Vilela  
Reviewed-by: Nathan Bossart  
Backpatch-through: 14  
Discussion: https://www.postgresql.org/message-id/CAEudQAp34o_8u6sGSVraLwuMv9F7T9hyHpePXHmRaxR2Aboi%2Bw%40mail.gmail.com  

M src/port/bsearch_arg.c

WAL-log inplace update before revealing it to other sessions.

commit   : 431e05181e4172415decf618ada8e91d6df995b1    
  
author   : Noah Misch <[email protected]>    
date     : Fri, 25 Oct 2024 06:51:03 -0700    
  
committer: Noah Misch <[email protected]>    
date     : Fri, 25 Oct 2024 06:51:03 -0700    

Click here for diff

A buffer lock won't stop a reader having already checked tuple  
visibility.  If a vac_update_datfrozenid() and then a crash happened  
during inplace update of a relfrozenxid value, datfrozenxid could  
overtake relfrozenxid.  That could lead to "could not access status of  
transaction" errors.  Back-patch to v12 (all supported versions).  In  
v14 and earlier, this also back-patches the assertion removal from  
commit 7fcf2faf9c7dd473208fd6d5565f88d7f733782b.  
  
Discussion: https://postgr.es/m/[email protected]  

M src/backend/access/heap/README.tuplock
M src/backend/access/heap/heapam.c

For inplace update, send nontransactional invalidations.

commit   : 4eac5a1fa78edde0de53a89bd2b06e1fe5588913    
  
author   : Noah Misch <[email protected]>    
date     : Fri, 25 Oct 2024 06:51:02 -0700    
  
committer: Noah Misch <[email protected]>    
date     : Fri, 25 Oct 2024 06:51:02 -0700    

Click here for diff

The inplace update survives ROLLBACK.  The inval didn't, so another  
backend's DDL could then update the row without incorporating the  
inplace update.  In the test this fixes, a mix of CREATE INDEX and ALTER  
TABLE resulted in a table with an index, yet relhasindex=f.  That is a  
source of index corruption.  Back-patch to v12 (all supported versions).  
The back branch versions don't change WAL, because those branches just  
added end-of-recovery SIResetAll().  All branches change the ABI of  
extern function PrepareToInvalidateCacheTuple().  No PGXN extension  
calls that, and there's no apparent use case in extensions.  
  
Reviewed by Nitin Motiani and (in earlier versions) Andres Freund.  
  
Discussion: https://postgr.es/m/[email protected]  

M src/backend/access/heap/heapam.c
M src/backend/access/transam/xact.c
M src/backend/catalog/index.c
M src/backend/replication/logical/decode.c
M src/backend/utils/cache/catcache.c
M src/backend/utils/cache/inval.c
M src/backend/utils/cache/syscache.c
M src/include/utils/catcache.h
M src/include/utils/inval.h
M src/test/isolation/expected/inplace-inval.out
M src/test/isolation/specs/inplace-inval.spec
M src/tools/pgindent/typedefs.list

At end of recovery, reset all sinval-managed caches.

commit   : 3baf804b7295fff7551f93ed94550d8268804cc1    
  
author   : Noah Misch <[email protected]>    
date     : Fri, 25 Oct 2024 06:51:06 -0700    
  
committer: Noah Misch <[email protected]>    
date     : Fri, 25 Oct 2024 06:51:06 -0700    

Click here for diff

An inplace update's invalidation messages are part of its transaction's  
commit record.  However, the update survives even if its transaction  
aborts or we stop recovery before replaying its transaction commit.  
After recovery, a backend that started in recovery could update the row  
without incorporating the inplace update.  That could result in a table  
with an index, yet relhasindex=f.  That is a source of index corruption.  
  
This bulk invalidation avoids the functional consequences.  A future  
change can fix the !RecoveryInProgress() scenario without changing the  
WAL format.  Back-patch to v17 - v12 (all supported versions).  v18 will  
instead add invalidations to WAL.  
  
Discussion: https://postgr.es/m/[email protected]  

M src/backend/access/transam/xlog.c
M src/backend/storage/ipc/sinvaladt.c
M src/include/storage/sinvaladt.h

Stop reading uninitialized memory in heap_inplace_lock().

commit   : d34ffbaa102910490f427752fa4b28e786225e80    
  
author   : Noah Misch <[email protected]>    
date     : Thu, 24 Oct 2024 09:16:14 -0700    
  
committer: Noah Misch <[email protected]>    
date     : Thu, 24 Oct 2024 09:16:14 -0700    

Click here for diff

Stop computing a never-used value.  This removes the read; the read had  
no functional implications.  Back-patch to v12, like commit  
a07e03fd8fa7daf4d1356f7cb501ffe784ea6257.  
  
Reported by Alexander Lakhin.  
  
Discussion: https://postgr.es/m/[email protected]  

M src/backend/access/heap/heapam.c
M src/test/isolation/expected/intra-grant-inplace.out
M src/test/isolation/specs/intra-grant-inplace.spec

Remove unnecessary word in a comment

commit   : af4e342034d6dd17cf843612e37facabc70d3c34    
  
author   : Amit Langote <[email protected]>    
date     : Wed, 23 Oct 2024 17:54:48 +0900    
  
committer: Amit Langote <[email protected]>    
date     : Wed, 23 Oct 2024 17:54:48 +0900    

Click here for diff

Relations opened by the executor are only closed once in  
ExecCloseRangeTableRelations(), so the word "again" in the comment  
for ExecGetRangeTableRelation() is misleading and unnecessary.  
  
Discussion: https://postgr.es/m/CA+HiwqHnw-zR+u060i3jp4ky5UR0CjByRFQz50oZ05de7wUg=Q@mail.gmail.com  
Backpatch-through: 12  

M src/backend/executor/execUtils.c

ecpg: Fix out-of-bound read in DecodeDateTime()

commit   : 335501fb2b8007000d8c154628065355b5cd4366    
  
author   : Michael Paquier <[email protected]>    
date     : Wed, 23 Oct 2024 08:35:04 +0900    
  
committer: Michael Paquier <[email protected]>    
date     : Wed, 23 Oct 2024 08:35:04 +0900    

Click here for diff

It was possible for the code to read out-of-bound data from the  
"day_tab" table with some crafted input data.  Let's treat these as  
invalid input as the month number is incorrect.  
  
A test is added to test this case with a check on the errno returned by  
the decoding routine.  A test close to the new one added in this commit  
was testing for a failure, but did not look at the errno generated, so  
let's use this commit to also change it, adding a check on the errno  
returned by DecodeDateTime().  
  
Like the other test scripts, dt_test should likely be expanded to  
include more checks based on the errnos generated in these code paths.  
This is left as future work.  
  
This issue exists since 2e6f97560a83, so backpatch all the way down.  
  
Reported-by: Pavel Nekrasov  
Author: Bruce Momjian, Pavel Nekrasov  
Discussion: https://postgr.es/m/[email protected]  
Backpatch-through: 12  

M src/interfaces/ecpg/pgtypeslib/dt_common.c
M src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c
M src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stderr
M src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stdout
M src/interfaces/ecpg/test/pgtypeslib/dt_test.pgc

Restructure foreign key handling code for ATTACH/DETACH

commit   : 5d83bad6b87d0d65818ba631a254f9a74fa20601    
  
author   : Álvaro Herrera <[email protected]>    
date     : Tue, 22 Oct 2024 16:01:18 +0200    
  
committer: Álvaro Herrera <[email protected]>    
date     : Tue, 22 Oct 2024 16:01:18 +0200    

Click here for diff

... to fix bugs when the referenced table is partitioned.  
  
The catalog representation we chose for foreign keys connecting  
partitioned tables (in commit f56f8f8da6af) is inconvenient, in the  
sense that a standalone table has a different way to represent the  
constraint when referencing a partitioned table, than when the same  
table becomes a partition (and vice versa).  Because of this, we need to  
create additional catalog rows on detach (pg_constraint and pg_trigger),  
and remove them on attach.  We were doing some of those things, but not  
all of them, leading to missing catalog rows in certain cases.  
  
The worst problem seems to be that we are missing action triggers after  
detaching a partition, which means that you could update/delete rows  
from the referenced partitioned table that still had referencing rows on  
that table, the server failing to throw the required errors.  
  
!!!  
Note that this means existing databases with FKs that reference  
partitioned tables might have rows that break relational integrity, on  
tables that were once partitions on the referencing side of the FK.  
  
Another possible problem is that trying to reattach a table  
that had been detached would fail indicating that internal triggers  
cannot be found, which from the user's point of view is nonsensical.  
  
In branches 15 and above, we fix this by creating a new helper function  
addFkConstraint() which is in charge of creating a standalone  
pg_constraint row, and repurposing addFkRecurseReferencing() and  
addFkRecurseReferenced() so that they're only the recursive routine for  
each side of the FK, and they call addFkConstraint() to create  
pg_constraint at each partitioning level and add the necessary triggers.  
These new routines can be used during partition creation, partition  
attach and detach, and foreign key creation.  This reduces redundant  
code and simplifies the flow.  
  
In branches 14 and 13, we have a much simpler fix that consists on  
simply removing the constraint on detach.  The reason is that those  
branches are missing commit f4566345cf40, which reworked the way this  
works in a way that we didn't consider back-patchable at the time.  
  
We opted to leave branch 12 alone, because it's different from branch 13  
enough that the fix doesn't apply; and because it is going in EOL mode  
very soon, patching it now might be worse since there's no way to undo  
the damage if it goes wrong.  
  
Existing databases might need to be repaired.  
  
In the future we might want to rethink the catalog representation to  
avoid this problem, but for now the code seems to do what's required to  
make the constraints operate correctly.  
  
Co-authored-by: Jehan-Guillaume de Rorthais <[email protected]>  
Co-authored-by: Tender Wang <[email protected]>  
Co-authored-by: Alvaro Herrera <[email protected]>  
Reported-by: Guillaume Lelarge <[email protected]>  
Reported-by: Jehan-Guillaume de Rorthais <[email protected]>  
Reported-by: Thomas Baehler (SBB CFF FFS) <[email protected]>  
Discussion: https://postgr.es/m/20230420144344.40744130@karst  
Discussion: https://postgr.es/m/20230705233028.2f554f73@karst  
Discussion: https://postgr.es/m/GVAP278MB02787E7134FD691861635A8BC9032@GVAP278MB0278.CHEP278.PROD.OUTLOOK.COM  
Discussion: https://postgr.es/m/[email protected]  

M src/backend/commands/tablecmds.c
M src/test/regress/expected/foreign_key.out
M src/test/regress/sql/foreign_key.sql
M src/tools/pgindent/typedefs.list

Fix wrong assertion and poor error messages in "COPY (query) TO".

commit   : c80a1e0483970f88710469c5bfe55d5e48cf3bd7    
  
author   : Tom Lane <[email protected]>    
date     : Mon, 21 Oct 2024 15:08:22 -0400    
  
committer: Tom Lane <[email protected]>    
date     : Mon, 21 Oct 2024 15:08:22 -0400    

Click here for diff

If the query is rewritten into a NOTIFY command by a DO INSTEAD  
rule, we'd get an assertion failure, or in non-assert builds  
issue a rather confusing error message.  Improve that.  
  
Also fix a longstanding grammar mistake in a nearby error message.  
  
Per bug #18664 from Alexander Lakhin.  Back-patch to all supported  
branches.  
  
Tender Wang and Tom Lane  
  
Discussion: https://postgr.es/m/[email protected]  

M src/backend/commands/copyto.c
M src/test/regress/expected/copydml.out
M src/test/regress/sql/copydml.sql

Fix race condition in committing a serializable transaction

commit   : d97419b851f87c318c2e188afa9c669b5538010e    
  
author   : Heikki Linnakangas <[email protected]>    
date     : Mon, 21 Oct 2024 09:49:21 +0300    
  
committer: Heikki Linnakangas <[email protected]>    
date     : Mon, 21 Oct 2024 09:49:21 +0300    

Click here for diff

The finished transaction list can contain XIDs that are older than the  
serializable global xmin. It's a short-lived state;  
ClearOldPredicateLocks() removes any such transactions from the list,  
and it's called whenever the global xmin advances. But if another  
backend calls SummarizeOldestCommittedSxact() in that window, it will  
call SerialAdd() on an XID that's older than the global xmin, or if  
there are no more transactions running, when global xmin is  
invalid. That trips the assertion in SerialAdd().  
  
Fixes bug #18658 reported by Andrew Bille. Thanks to Alexander Lakhin  
for analysis. Backpatch to all versions.  
  
Discussion: https://www.postgresql.org/message-id/18658-7dab125ec688c70b%40postgresql.org  

M src/backend/storage/lmgr/predicate.c

Note that index_name in ALTER INDEX ATTACH PARTITION can be schema-qualified

commit   : d76a97a84a61ef3fd929fc8f2f2f561fccddaa83    
  
author   : Álvaro Herrera <[email protected]>    
date     : Sun, 20 Oct 2024 15:36:20 +0200    
  
committer: Álvaro Herrera <[email protected]>    
date     : Sun, 20 Oct 2024 15:36:20 +0200    

Click here for diff

Missed in 8b08f7d4820f; backpatch to all supported branches.  
  
Reported-by: [email protected]  
Reviewed-by: Tom Lane <[email protected]>  
Discussion: https://postgr.es/m/[email protected]  

M doc/src/sgml/ref/alter_index.sgml

Adjust documentation for configuring Linux huge pages.

commit   : ff0713d181d09cc0daf897a5f046ce7b953b84be    
  
author   : Nathan Bossart <[email protected]>    
date     : Fri, 18 Oct 2024 10:20:15 -0500    
  
committer: Nathan Bossart <[email protected]>    
date     : Fri, 18 Oct 2024 10:20:15 -0500    

Click here for diff

The present wording about viewing shared_memory_size_in_huge_pages  
seems to suggest that the parameter cannot be viewed after startup  
at all, whereas the intent is to make it clear that you can't use  
"postgres -C" to view this parameter while the server is running.  
This commit rephrases this section to remove the ambiguity.  
  
Author: Seino Yuki  
Reviewed-by: Michael Paquier, David G. Johnston, Fujii Masao  
Discussion: https://postgr.es/m/420584fd274f9ec4f337da55ffb3b790%40oss.nttdata.com  
Backpatch-through: 15  

M doc/src/sgml/runtime.sgml

Fix extreme skew detection in Parallel Hash Join.

commit   : 1831545ca1860bc8d6faf9c55bbae92a9177e57e    
  
author   : Thomas Munro <[email protected]>    
date     : Thu, 17 Oct 2024 15:52:24 +1300    
  
committer: Thomas Munro <[email protected]>    
date     : Thu, 17 Oct 2024 15:52:24 +1300    

Click here for diff

After repartitioning the inner side of a hash join that would have  
exceeded the allowed size, we check if all the tuples from a parent  
partition moved to one child partition.  That is evidence that it  
contains duplicate keys and later attempts to repartition will also  
fail, so we should give up trying to limit memory (for lack of a better  
fallback strategy).  
  
A thinko prevented the check from working correctly in partition 0 (the  
one that is partially loaded into memory already).  After  
repartitioning, we should check for extreme skew if the *parent*  
partition's space_exhausted flag was set, not the child partition's.  
The consequence was repeated futile repartitioning until per-partition  
data exceeded various limits including "ERROR: invalid DSA memory alloc  
request size 1811939328", OS allocation failure, or temporary disk space  
errors.  (We could also do something about some of those symptoms, but  
that's material for separate patches.)  
  
This problem only became likely when PostgreSQL 16 introduced support  
for Parallel Hash Right/Full Join, allowing NULL keys into the hash  
table.  Repartitioning always leaves NULL in partition 0, no matter how  
many times you do it, because the hash value is all zero bits.  That's  
unlikely for other hashed values, but they might still have caused  
wasted extra effort before giving up.  
  
Back-patch to all supported releases.  
  
Reported-by: Craig Milhiser <[email protected]>  
Reviewed-by: Andrei Lepikhov <[email protected]>  
Discussion: https://postgr.es/m/CA%2BwnhO1OfgXbmXgC4fv_uu%3DOxcDQuHvfoQ4k0DFeB0Qqd-X-rQ%40mail.gmail.com  

M src/backend/executor/nodeHash.c

Further refine _SPI_execute_plan's rule for atomic execution.

commit   : b35231989524be8bf7257e695ac61346dda35b7f    
  
author   : Tom Lane <[email protected]>    
date     : Wed, 16 Oct 2024 17:36:29 -0400    
  
committer: Tom Lane <[email protected]>    
date     : Wed, 16 Oct 2024 17:36:29 -0400    

Click here for diff

Commit 2dc1deaea turns out to have been still a brick shy of a load,  
because CALL statements executing within a plpgsql exception block  
could still pass the wrong snapshot to stable functions within the  
CALL's argument list.  That happened because standard_ProcessUtility  
forces isAtomicContext to true if IsTransactionBlock is true, which  
it always will be inside a subtransaction.  Then ExecuteCallStmt  
would think it does not need to push a new snapshot --- but  
_SPI_execute_plan didn't do so either, since it thought it was in  
nonatomic mode.  
  
The best fix for this seems to be for _SPI_execute_plan to operate  
in atomic execution mode if IsSubTransaction() is true, even when the  
SPI context as a whole is non-atomic.  This makes _SPI_execute_plan  
have the same rules about when non-atomic execution is allowed as  
_SPI_commit/_SPI_rollback have about when COMMIT/ROLLBACK are allowed,  
which seems appropriately symmetric.  (If anyone ever tries to allow  
COMMIT/ROLLBACK inside a subtransaction, this would all need to be  
rethought ... but I'm unconvinced that such a thing could be logically  
consistent at all.)  
  
For further consistency, also check IsSubTransaction() in  
SPI_inside_nonatomic_context.  That does not matter for its  
one present-day caller StartTransaction, which can't be reached  
inside a subtransaction.  But if any other callers ever arise,  
they'd presumably want this definition.  
  
Per bug #18656 from Alexander Alehin.  Back-patch to all  
supported branches, like previous fixes in this area.  
  
Discussion: https://postgr.es/m/[email protected]  

M src/backend/executor/spi.c
M src/pl/plpgsql/src/expected/plpgsql_call.out
M src/pl/plpgsql/src/sql/plpgsql_call.sql

Reduce memory block size for decoded tuple storage to 8kB.

commit   : 4a675f31868a6a7f0ef436ebfbaedddc74d1c2a1    
  
author   : Masahiko Sawada <[email protected]>    
date     : Wed, 16 Oct 2024 12:07:58 -0700    
  
committer: Masahiko Sawada <[email protected]>    
date     : Wed, 16 Oct 2024 12:07:58 -0700    

Click here for diff

Commit a4ccc1cef introduced the Generation Context and modified the  
logical decoding process to use a Generation Context with a fixed  
block size of 8MB for storing tuple data decoded during logical  
decoding (i.e., rb->tup_context). Several reports have indicated that  
the logical decoding process can be terminated due to  
out-of-memory (OOM) situations caused by excessive memory usage in  
rb->tup_context.  
  
This issue can occur when decoding a workload involving several  
concurrent transactions, including a long-running transaction that  
modifies tuples. By design, the Generation Context does not free a  
memory block until all chunks within that block are  
released. Consequently, if tuples modified by the long-running  
transaction are stored across multiple memory blocks, these blocks  
remain allocated until the long-running transaction completes, leading  
to substantial memory fragmentation. The memory usage during logical  
decoding, tracked by rb->size, does not account for memory  
fragmentation, resulting in potentially much higher memory consumption  
than the value of the logical_decoding_work_mem parameter.  
  
Various improvement strategies were discussed in the relevant  
thread. This change reduces the block size of the Generation Context  
used in rb->tup_context from 8MB to 8kB. This modification  
significantly decreases the likelihood of substantial memory  
fragmentation occurring and is relatively straightforward to  
backport. Performance testing across multiple platforms has confirmed  
that this change will not introduce any performance degradation that  
would impact actual operation.  
  
Backport to all supported branches.  
  
Reported-by: Alex Richman, Michael Guissine, Avi Weinberg  
Reviewed-by: Amit Kapila, Fujii Masao, David Rowley  
Tested-by: Hayato Kuroda, Shlok Kyal  
Discussion: https://postgr.es/m/CAD21AoBTY1LATZUmvSXEssvq07qDZufV4AF-OHh9VD2pC0VY2A%40mail.gmail.com  
Backpatch-through: 12  

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

Correctly identify which EC members are computable at a plan node.

commit   : 4f3bccbaaeb44d2568a387ce02e4c3d95237628c    
  
author   : Tom Lane <[email protected]>    
date     : Sat, 12 Oct 2024 14:56:08 -0400    
  
committer: Tom Lane <[email protected]>    
date     : Sat, 12 Oct 2024 14:56:08 -0400    

Click here for diff

find_computable_ec_member() had the wrong mental model of what  
its primary caller prepare_sort_from_pathkeys() would do with  
the selected EquivalenceClass member expression.  We will not  
compute the EC expression in a plan node atop the one returning  
the passed-in targetlist; rather, the EC expression will be  
computed as an additional column of that targetlist.  So any  
Var or quasi-Var used in the given tlist is also available to the  
EC expression.  In simple cases this makes no difference because  
the given tlist is just a list of Vars or quasi-Vars --- but if  
we are considering an appendrel member produced by flattening  
a UNION ALL, the tlist may contain expressions, resulting in  
failure to match and a "could not find pathkey item to sort"  
error.  
  
To fix, we can flatten both the tlist and the EC members with  
pull_var_clause(), and then just check for subset-ness, so  
that the code is actually shorter than before.  
  
While this bug is quite old, the present patch only works back to  
v13.  We could possibly make it work in v12 by back-patching parts  
of 375398244.  On the whole though I don't like the risk/reward  
ratio of that idea.  v12's final release is next month, meaning  
there would be no chance to correct matters if the patch causes a  
regression.  Since this failure has escaped notice for 14 years,  
it's likely nobody will hit it in the field with v12.  
  
Per bug #18652 from Alexander Lakhin.  
  
Andrei Lepikhov and Tom Lane  
  
Discussion: https://postgr.es/m/[email protected]  

M src/backend/optimizer/path/equivclass.c
M src/test/regress/expected/inherit.out
M src/test/regress/sql/inherit.sql

Remove incorrect function import from pgindent

commit   : 866e4a7d598b9edaddddd235df1414b746e37825    
  
author   : Daniel Gustafsson <[email protected]>    
date     : Wed, 9 Oct 2024 09:34:34 +0200    
  
committer: Daniel Gustafsson <[email protected]>    
date     : Wed, 9 Oct 2024 09:34:34 +0200    

Click here for diff

Commit 149ac7d4559 which re-implemented pgindent in Perl explicitly  
imported the devnull function from File::Spec, but the module does  
not export anything.  In recent versions of Perl calling a missing  
import function cause a warning, which combined with warnings being  
fatal cause pgindent to error out.  
  
Backpatch to all supported versions.  
  
Author: Erik Wienhold <[email protected]>  
Reviewed-by: Andrew Dunstan <[email protected]>  
Reviewed-by: Daniel Gustafsson <[email protected]>  
Discusson: https://postgr.es/m/[email protected]  
Backpatch-through: v12  

M src/tools/pgindent/pgindent

Stabilize the test added by commit 022564f60c.

commit   : 5ce0dcc99ad20bcb0de768d72d7126b6c033f5d9    
  
author   : Amit Kapila <[email protected]>    
date     : Tue, 8 Oct 2024 11:45:58 +0530    
  
committer: Amit Kapila <[email protected]>    
date     : Tue, 8 Oct 2024 11:45:58 +0530    

Click here for diff

The test was unstable in branches 14 and 15 as we were relying on the  
number of changes in the table having a toast column to start streaming.  
On branches >= 16, we have a GUC debug_logical_replication_streaming which  
can stream each change, so the test was stable in those branches.  
  
Change the test to use PREPARE TRANSACTION as that should make the result  
consistent and test the code changed in 022564f60c.  
  
Reported-by: Daniel Gustafsson as per buildfarm  
Author: Hou Zhijie, Amit Kapila  
Backpatch-through: 14  
Discussion: https://postgr.es/m/[email protected]  

M contrib/test_decoding/expected/stream.out
M contrib/test_decoding/expected/twophase.out
M contrib/test_decoding/sql/stream.sql
M contrib/test_decoding/sql/twophase.sql

vacuumdb: Schema-qualify operator in catalog query's WHERE clause.

commit   : 6d047c6a9192df34670a503c4d289a93e4909033    
  
author   : Nathan Bossart <[email protected]>    
date     : Mon, 7 Oct 2024 16:49:20 -0500    
  
committer: Nathan Bossart <[email protected]>    
date     : Mon, 7 Oct 2024 16:49:20 -0500    

Click here for diff

Commit 1ab67c9dfa, which modified this catalog query so that it  
doesn't return temporary relations, forgot to schema-qualify the  
operator.  A comment earlier in the function implores us to fully  
qualify everything in the query:  
  
	 * Since we execute the constructed query with the default search_path  
	 * (which could be unsafe), everything in this query MUST be fully  
	 * qualified.  
  
This commit fixes that.  While at it, add a newline for consistency  
with surrounding code.  
  
Reviewed-by: Noah Misch  
Discussion: https://postgr.es/m/ZwQJYcuPPUsF0reU%40nathan  
Backpatch-through: 12  

M src/bin/scripts/vacuumdb.c

Fix Y2038 issues with MyStartTime.

commit   : 01731eeeaa9665b47a45b7d2c967ef4c06a56d1b    
  
author   : Nathan Bossart <[email protected]>    
date     : Mon, 7 Oct 2024 13:51:03 -0500    
  
committer: Nathan Bossart <[email protected]>    
date     : Mon, 7 Oct 2024 13:51:03 -0500    

Click here for diff

Several places treat MyStartTime as a "long", which is only 32 bits  
wide on some platforms.  In reality, MyStartTime is a pg_time_t,  
i.e., a signed 64-bit integer.  This will lead to interesting bugs  
on the aforementioned systems in 2038 when signed 32-bit integers  
are no longer sufficient to store Unix time (e.g., "pg_ctl start"  
hanging).  To fix, ensure that MyStartTime is handled as a 64-bit  
value everywhere.  (Of course, users will need to ensure that  
time_t is 64 bits wide on their system, too.)  
  
Co-authored-by: Max Johnson  
Discussion: https://postgr.es/m/CO1PR07MB905262E8AC270FAAACED66008D682%40CO1PR07MB9052.namprd07.prod.outlook.com  
Backpatch-through: 12  

M contrib/postgres_fdw/option.c
M src/backend/utils/error/csvlog.c
M src/backend/utils/error/elog.c
M src/backend/utils/error/jsonlog.c
M src/backend/utils/init/miscinit.c
M src/bin/pg_ctl/pg_ctl.c

Fix fetching default toast value during decoding of in-progress transactions.

commit   : 8175a7d11f70589f6b44e28a8dd804f7542d0bbf    
  
author   : Amit Kapila <[email protected]>    
date     : Mon, 7 Oct 2024 14:53:18 +0530    
  
committer: Amit Kapila <[email protected]>    
date     : Mon, 7 Oct 2024 14:53:18 +0530    

Click here for diff

During logical decoding of in-progress transactions, we perform the toast  
table scan while fetching the default toast value for an attribute. We  
forgot to initialize the flag during this scan to indicate that the system  
table scan is in progress. We need this flag to ensure that during logical  
decoding we never directly access the tableam or heap APIs because we check  
for concurrent aborts only in systable_* APIs.  
  
Reported-by: Alexander Lakhin  
Author: Takeshi Ideriha, Hou Zhijie  
Reviewed-by: Amit Kapila, Hou Zhijie  
Backpatch-through: 14  
Discussion: https://postgr.es/m/[email protected]  

M contrib/test_decoding/expected/stream.out
M contrib/test_decoding/sql/stream.sql
M src/backend/access/index/genam.c

Ignore not-yet-defined Portals in pg_cursors view.

commit   : aef75219cc221cd4990eaec7d4213d85ed945069    
  
author   : Tom Lane <[email protected]>    
date     : Sun, 6 Oct 2024 16:03:48 -0400    
  
committer: Tom Lane <[email protected]>    
date     : Sun, 6 Oct 2024 16:03:48 -0400    

Click here for diff

pg_cursor() supposed that any Portal it finds in the hash table must  
have sourceText set up, but there's an edge case where that is not so.  
A newly-created Portal has sourceText = NULL, and that doesn't change  
until PortalDefineQuery is called.  In SPI_cursor_open_internal,  
we perform GetCachedPlan between CreatePortal and PortalDefineQuery,  
and it's possible for user-defined code to execute during that  
planning and cause a fetch from the pg_cursors view, resulting in a  
null-pointer-dereference crash.  (It looks like the same could happen  
in exec_bind_message, but I've not tried to provoke a failure there.)  
  
I considered trying to fix this by setting sourceText sooner, but  
there may be instances of this same calling pattern in extensions,  
and we couldn't be sure they'd get the memo promptly.  It seems  
better to redefine pg_cursor as not showing Portals that have  
not yet had PortalDefineQuery called on them, which we can do by  
just skipping them if sourceText is still NULL.  
  
(Before a1c692358, pg_cursor would instead return a row with NULL  
in the statement column.  We could revert to that behavior but it  
doesn't really seem like a better definition, especially since our  
documentation doesn't suggest that the column could be NULL.)  
  
Per report from PetSerAl.  Back-patch to all supported branches.  
  
Discussion: https://postgr.es/m/CAKygsHTBXLXjwV43kpZa+Cs+XTiaeeJiZdL4cPBm9f4MTdw7wg@mail.gmail.com  

M src/backend/utils/mmgr/portalmem.c

Parse libpq's "keepalives" option more like other integer options.

commit   : bb8c89dbcde713b56b644cb42519db884d59ed91    
  
author   : Tom Lane <[email protected]>    
date     : Wed, 2 Oct 2024 17:30:36 -0400    
  
committer: Tom Lane <[email protected]>    
date     : Wed, 2 Oct 2024 17:30:36 -0400    

Click here for diff

Use pqParseIntParam (nee parse_int_param) instead of using strtol  
directly.  This allows trailing whitespace, which the previous coding  
didn't, and makes the spelling of the error message consistent with  
other similar cases.  
  
This seems to be an oversight in commit e7a221797, which introduced  
parse_int_param.  That fixed places that were using atoi(), but missed  
this place which was randomly using strtol() instead.  
  
Ordinarily I'd consider this minor cleanup not worth back-patching.  
However, it seems that ecpg assumes it can add trailing whitespace  
to URL parameters, so that use of the keepalives option fails in  
that context.  Perhaps that's worth improving as a separate matter.  
In the meantime, back-patch this to all supported branches.  
  
Yuto Sasaki (some further cleanup by me)  
  
Discussion: https://postgr.es/m/TY2PR01MB36286A7B97B9A15793335D18C1772@TY2PR01MB3628.jpnprd01.prod.outlook.com  

M src/interfaces/libpq/fe-connect.c

Fix race condition in COMMIT PREPARED causing orphaned 2PC files

commit   : 41ab4568043bfaf0756bf43f89862ce0fc0006ee    
  
author   : Michael Paquier <[email protected]>    
date     : Tue, 1 Oct 2024 15:44:11 +0900    
  
committer: Michael Paquier <[email protected]>    
date     : Tue, 1 Oct 2024 15:44:11 +0900    

Click here for diff

COMMIT PREPARED removes on-disk 2PC files near its end, but the state  
checked if a file is on-disk or not gets read from shared memory while  
not holding the two-phase state lock.  
  
Because of that, there was a small window where a second backend doing a  
PREPARE TRANSACTION could reuse the GlobalTransaction put back into the  
2PC free list by the COMMIT PREPARED, overwriting the "ondisk" flag read  
afterwards by the COMMIT PREPARED to decide if its on-disk two-phase  
state file should be removed, preventing the file deletion.  
  
This commit fixes this issue so as the "ondisk" flag in the  
GlobalTransaction is read while holding the two-phase state lock, not  
from shared memory after its entry has been added to the free list.  
  
Orphaned two-phase state files flushed to disk after a checkpoint are  
discarded at the beginning of recovery.  However, a truncation of  
pg_xact/ would make the startup process issue a FATAL when it cannot  
read the SLRU page holding the state of the transaction whose 2PC file  
was orphaned, which is a necessary step to decide if the 2PC file should  
be removed or not.  Removing manually the file would be necessary in  
this case.  
  
Issue introduced by effe7d9552dd, so backpatch all the way down.  
  
Mea culpa.  
  
Author: wuchengwen  
Discussion: https://postgr.es/m/[email protected]  
Backpatch-through: 12  

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

Doc: replace unnecessary non-breaking space with ordinal space.

commit   : de357039c0300bc61bbfc23977a4b33d4e2f00a0    
  
author   : Tatsuo Ishii <[email protected]>    
date     : Tue, 1 Oct 2024 11:37:37 +0900    
  
committer: Tatsuo Ishii <[email protected]>    
date     : Tue, 1 Oct 2024 11:37:37 +0900    

Click here for diff

There were unnecessary non-breaking spaces (nbsp, U+00A0, 0xc2a0 in  
UTF-8) in the docs.  This commit replaces them with ASCII spaces  
(0x20).  
  
config.sgml is backpatched through 17.  
ref/drop_extension.sgml is backpatched through 13.  
  
Discussion: https://postgr.es/m/20240930.153404.202479334310259810.ishii%40postgresql.org  
Reviewed-by: Yugo Nagata, Daniel Gustafsson  
Backpatch-through: 17, 13  

M doc/src/sgml/ref/drop_extension.sgml

Bump MIN_WINNT for MINGW to clear a build error

commit   : d700e8d75bc3844d866bf15c8cadbd72d759422d    
  
author   : Andrew Dunstan <[email protected]>    
date     : Mon, 30 Sep 2024 11:32:32 -0400    
  
committer: Andrew Dunstan <[email protected]>    
date     : Mon, 30 Sep 2024 11:32:32 -0400    

Click here for diff

Because we have been setting this too low, there has been a  
long-standing warning about a missing declaration for inet_pton().  
Modern gcc now considers this an error, so we have been getting failures  
on the buildfarm animal fairywren.  
  
Fix suggested by Thomas Munro.  
  
This isn't needed in later branches, as they already set MIN_WINNT  
higher, nor on earlier branches because they don't use inet_pton().  
  
Discussion: https://postgr.es/m/[email protected]  

M src/include/port/win32.h

reindexdb: Skip reindexing temporary tables and indexes.

commit   : 92cc21d158f30d46642b5123697f71b7a740fbd7    
  
author   : Fujii Masao <[email protected]>    
date     : Mon, 30 Sep 2024 11:13:55 +0900    
  
committer: Fujii Masao <[email protected]>    
date     : Mon, 30 Sep 2024 11:13:55 +0900    

Click here for diff

Reindexing temp tables or indexes of other sessions is not allowed.  
However, reindexdb in parallel mode previously listed them as  
the objects to process, leading to failures.  
  
This commit ensures reindexdb in parallel mode skips temporary tables  
and indexes by adding a condition based on the relpersistence column  
in pg_class to the object listing queries, preventing these issues.  
  
Note that this commit does not affect reindexdb when temporary tables  
or indexes are explicitly specified using the -t or -j options;  
reindexdb in that case still does not skip them and can cause an error.  
  
Back-patch to v13 where parallel mode was introduced in reindexdb.  
  
Author: Fujii Masao  
Reviewed-by: Michael Paquier  
Discussion: https://postgr.es/m/[email protected]  

M src/bin/scripts/reindexdb.c

Remove NULL dereference from RenameRelationInternal().

commit   : 159bf0f31b59f7ef7f4bc6c3f57a5187f6a96947    
  
author   : Noah Misch <[email protected]>    
date     : Sun, 29 Sep 2024 15:54:25 -0700    
  
committer: Noah Misch <[email protected]>    
date     : Sun, 29 Sep 2024 15:54:25 -0700    

Click here for diff

Defect in last week's commit aac2c9b4fde889d13f859c233c2523345e72d32b,  
per Coverity.  Reaching this would need catalog corruption.  Back-patch  
to v12, like that commit.  

M src/backend/commands/tablecmds.c

Avoid 037_invalid_database.pl hang under debug_discard_caches.

commit   : 7f90b727422bde6308fd22b7fb0aef48255fd6db    
  
author   : Noah Misch <[email protected]>    
date     : Fri, 27 Sep 2024 15:28:56 -0700    
  
committer: Noah Misch <[email protected]>    
date     : Fri, 27 Sep 2024 15:28:56 -0700    

Click here for diff

Back-patch to v12 (all supported versions).  

M src/test/recovery/t/037_invalid_database.pl

Fix incorrect memory access in VACUUM FULL with invalid toast indexes

commit   : a613edc5c21c105a86e073278d890db0311ea9be    
  
author   : Michael Paquier <[email protected]>    
date     : Fri, 27 Sep 2024 09:40:18 +0900    
  
committer: Michael Paquier <[email protected]>    
date     : Fri, 27 Sep 2024 09:40:18 +0900    

Click here for diff

An invalid toast index is skipped in reindex_relation().  These would be  
remnants of a failed REINDEX CONCURRENTLY and they should never been  
rebuilt as there can only be one valid toast index at a time.  
  
REINDEX_REL_SUPPRESS_INDEX_USE, used by CLUSTER and VACUUM FULL, needs  
to maintain a list of the indexes being processed.  The list of indexes  
is retrieved from the relation cache, and includes invalid indexes.  The  
code has missed that invalid toast indexes are ignored in  
reindex_relation() as this leads to a hard failure in reindex_index(),  
and they were left in the reindex pending list, making the list  
inconsistent when rechecked.  The incorrect memory access was happening  
when scanning pg_class for the refresh of pg_database.datfrozenxid, when  
doing a scan of pg_class.  
  
This issue exists since REINDEX CONCURRENTLY exists, where invalid toast  
indexes can exist, so backpatch all the way down.  
  
Reported-by: Alexander Lakhin  
Author: Tender Wang  
Discussion: https://postgr.es/m/[email protected]  
Backpatch-through: 12  

M src/backend/catalog/index.c

tests: Restrict pg_locks queries in advisory_locks.sql to current database

commit   : 3981fd5869fc78296133bba5fd28586684835e5c    
  
author   : Andres Freund <[email protected]>    
date     : Wed, 5 Oct 2022 10:44:38 -0700    
  
committer: Michael Paquier <[email protected]>    
date     : Wed, 5 Oct 2022 10:44:38 -0700    

Click here for diff

Otherwise testing an existing installation can fail, if there are other locks,  
e.g. from one of the isolation tests.  
  
This was originally applied as c3315a7da57b in 16~, but it is possible  
to see this test fail depending on the concurrent activity for older  
active branches.  
  
Reviewed-by: Michael Paquier <[email protected]>  
Discussion: https://postgr.es/m/[email protected]  
Backpatch-through: 12  

M src/test/regress/expected/advisory_lock.out
M src/test/regress/sql/advisory_lock.sql

vacuumdb: Skip temporary tables in query to build list of relations

commit   : 74eaa0544abf84d82bceb80e6f66321ec4c92c82    
  
author   : Michael Paquier <[email protected]>    
date     : Wed, 25 Sep 2024 14:44:56 +0900    
  
committer: Michael Paquier <[email protected]>    
date     : Wed, 25 Sep 2024 14:44:56 +0900    

Click here for diff

Running vacuumdb with a non-superuser while another user has created a  
temporary table would lead to a mid-flight permission failure,  
interrupting the operation.  vacuum_rel() skips temporary relations of  
other backends, and it makes no sense for vacuumdb to know about these  
relations, so let's switch it to ignore temporary relations entirely.  
  
Adding a qual in the query based on relpersistence simplifies the  
generation of its WHERE clause in vacuum_one_database(), per se the  
removal of "has_where".  
  
Author: VaibhaveS, Michael Paquier  
Reviewed-by: Fujii Masao  
Discussion: https://postgr.es/m/CAM_eQjwfAR=y3G1fGyS1U9FTmc+FyJm9amNfY2QCZBnDDbNPZg@mail.gmail.com  
Backpatch-through: 12  

M src/bin/scripts/vacuumdb.c

Fix use of uninitialized value in previous commit.

commit   : 0cf3d41cbb425c142ca7b3f1e2efd875565b6142    
  
author   : Noah Misch <[email protected]>    
date     : Tue, 24 Sep 2024 17:16:36 -0700    
  
committer: Noah Misch <[email protected]>    
date     : Tue, 24 Sep 2024 17:16:36 -0700    

Click here for diff

Per buildfarm member akepa and others.  Back-patch to v16 and v15.  
  
Discussion: https://postgr.es/m/[email protected]  

M src/backend/executor/nodeModifyTable.c

For inplace update durability, make heap_update() callers wait.

commit   : 5c837f8fa022ff9d9ebced71fdcae273fe433570    
  
author   : Noah Misch <[email protected]>    
date     : Tue, 24 Sep 2024 15:25:18 -0700    
  
committer: Noah Misch <[email protected]>    
date     : Tue, 24 Sep 2024 15:25:18 -0700    

Click here for diff

The previous commit fixed some ways of losing an inplace update.  It  
remained possible to lose one when a backend working toward a  
heap_update() copied a tuple into memory just before inplace update of  
that tuple.  In catalogs eligible for inplace update, use LOCKTAG_TUPLE  
to govern admission to the steps of copying an old tuple, modifying it,  
and issuing heap_update().  This includes MERGE commands.  To avoid  
changing most of the pg_class DDL, don't require LOCKTAG_TUPLE when  
holding a relation lock sufficient to exclude inplace updaters.  
Back-patch to v12 (all supported versions).  In v13 and v12, "UPDATE  
pg_class" or "UPDATE pg_database" can still lose an inplace update.  The  
v14+ UPDATE fix needs commit 86dc90056dfdbd9d1b891718d2e5614e3e432f35,  
and it wasn't worth reimplementing that fix without such infrastructure.  
  
Reviewed by Nitin Motiani and (in earlier versions) Heikki Linnakangas.  
  
Discussion: https://postgr.es/m/[email protected]  

M src/backend/access/heap/README.tuplock
M src/backend/access/heap/heapam.c
M src/backend/access/index/genam.c
M src/backend/catalog/aclchk.c
M src/backend/catalog/catalog.c
M src/backend/commands/dbcommands.c
M src/backend/commands/indexcmds.c
M src/backend/commands/tablecmds.c
M src/backend/executor/execMain.c
M src/backend/executor/execReplication.c
M src/backend/executor/nodeModifyTable.c
M src/backend/utils/cache/relcache.c
M src/backend/utils/cache/syscache.c
M src/include/nodes/execnodes.h
M src/include/storage/lockdefs.h
M src/include/utils/syscache.h
M src/test/isolation/expected/intra-grant-inplace.out
M src/test/isolation/specs/eval-plan-qual.spec
M src/test/isolation/specs/intra-grant-inplace.spec

Fix data loss at inplace update after heap_update().

commit   : 8590c942c1a6b861d0cf4fa5aa694ab3a65fa306    
  
author   : Noah Misch <[email protected]>    
date     : Tue, 24 Sep 2024 15:25:18 -0700    
  
committer: Noah Misch <[email protected]>    
date     : Tue, 24 Sep 2024 15:25:18 -0700    

Click here for diff

As previously-added tests demonstrated, heap_inplace_update() could  
instead update an unrelated tuple of the same catalog.  It could lose  
the update.  Losing relhasindex=t was a source of index corruption.  
Inplace-updating commands like VACUUM will now wait for heap_update()  
commands like GRANT TABLE and GRANT DATABASE.  That isn't ideal, but a  
long-running GRANT already hurts VACUUM progress more just by keeping an  
XID running.  The VACUUM will behave like a DELETE or UPDATE waiting for  
the uncommitted change.  
  
For implementation details, start at the systable_inplace_update_begin()  
header comment and README.tuplock.  Back-patch to v12 (all supported  
versions).  In back branches, retain a deprecated heap_inplace_update(),  
for extensions.  
  
Reported by Smolkin Grigory.  Reviewed by Nitin Motiani, (in earlier  
versions) Heikki Linnakangas, and (in earlier versions) Alexander  
Lakhin.  
  
Discussion: https://postgr.es/m/CAMp+ueZQz3yDk7qg42hk6-9gxniYbp-=bG2mgqecErqR5gGGOA@mail.gmail.com  

M src/backend/access/heap/README.tuplock
M src/backend/access/heap/heapam.c
M src/backend/access/index/genam.c
M src/backend/catalog/index.c
M src/backend/catalog/toasting.c
M src/backend/commands/dbcommands.c
M src/backend/commands/vacuum.c
M src/include/access/genam.h
M src/include/access/heapam.h
M src/test/isolation/expected/intra-grant-inplace-db.out
M src/test/isolation/expected/intra-grant-inplace.out
M src/test/isolation/specs/intra-grant-inplace-db.spec
M src/test/isolation/specs/intra-grant-inplace.spec

Warn if LOCKTAG_TUPLE is held at commit, under debug_assertions.

commit   : 41e0ba33d5ab2b2301aa5d932836927bf69a76a8    
  
author   : Noah Misch <[email protected]>    
date     : Tue, 24 Sep 2024 15:25:18 -0700    
  
committer: Noah Misch <[email protected]>    
date     : Tue, 24 Sep 2024 15:25:18 -0700    

Click here for diff

The current use always releases this locktag.  A planned use will  
continue that intent.  It will involve more areas of code, making unlock  
omissions easier.  Warn under debug_assertions, like we do for various  
resource leaks.  Back-patch to v12 (all supported versions), the plan  
for the commit of the new use.  
  
Reviewed by Heikki Linnakangas.  
  
Discussion: https://postgr.es/m/[email protected]  

M src/backend/storage/lmgr/lock.c

Drop global objects after completed test

commit   : 2eecaf4b8cfb495a77512b7123f2867319973d29    
  
author   : Daniel Gustafsson <[email protected]>    
date     : Wed, 3 Apr 2024 13:33:25 +0200    
  
committer: Michael Paquier <[email protected]>    
date     : Wed, 3 Apr 2024 13:33:25 +0200    

Click here for diff

Project policy is to not leave global objects behind after a regress  
test run.  This was found as a result of the development of a patch  
to make pg_regress detect such leftovers automatically, which in the  
end was withdrawn due to issues with parallel runs.  
  
This was originally committed as 936e3fa3787a, but the issue also exists  
in the 12~16 range.  
  
Discussion: https://postgr.es/m/[email protected]  
Backpatch-through: 12  

M src/test/modules/test_pg_dump/expected/test_pg_dump.out
M src/test/modules/test_pg_dump/sql/test_pg_dump.sql

Doc: explain how to test ADMIN privilege with pg_has_role().

commit   : 23d44397321f96d8a94e4791172ecd1f494d3349    
  
author   : Tom Lane <[email protected]>    
date     : Fri, 20 Sep 2024 15:56:34 -0400    
  
committer: Tom Lane <[email protected]>    
date     : Fri, 20 Sep 2024 15:56:34 -0400    

Click here for diff

This has always been possible, but the syntax is a bit obscure,  
and our user-facing docs were not very helpful.  Spell it out  
more clearly.  
  
Per complaint from Dominique Devienne.  Back-patch to  
all supported branches.  
  
Discussion: https://postgr.es/m/CAFCRh-8JNEy+dV4SXFOrWca50u+d=--TO4cq=+ac1oBtfJy4AA@mail.gmail.com  

M doc/src/sgml/func.sgml

commit   : 785c53d91d8597062b9e6512c060e6aa4d8db540    
  
author   : Bruce Momjian <[email protected]>    
date     : Thu, 19 Sep 2024 18:05:22 -0400    
  
committer: Bruce Momjian <[email protected]>    
date     : Thu, 19 Sep 2024 18:05:22 -0400    

Click here for diff

Make paragraph empty instead of removing it.  
  
Discussion: https://postgr.es/m/[email protected]  
  
Backpatch-through: 12  

M doc/src/sgml/stylesheet-fo.xsl

doc PG relnotes: document "Unresolved ID reference found" cause

commit   : a7d2ec87a0e4a534df6dd3a2913a1a43847de1c7    
  
author   : Bruce Momjian <[email protected]>    
date     : Thu, 19 Sep 2024 12:01:59 -0400    
  
committer: Bruce Momjian <[email protected]>    
date     : Thu, 19 Sep 2024 12:01:59 -0400    

Click here for diff

Backpatch-through: 12  

M doc/src/sgml/stylesheet-fo.xsl

commit   : bbfce76fd3b30a84afa1332c2cd1c53186b4e024    
  
author   : Bruce Momjian <[email protected]>    
date     : Thu, 19 Sep 2024 09:47:22 -0400    
  
committer: Bruce Momjian <[email protected]>    
date     : Thu, 19 Sep 2024 09:47:22 -0400    

Click here for diff

FYI, during PDF builds, this link type generates a "Unresolved ID  
reference found" warning because it is suppressed from the PDF output.  
  
Backpatch-through: 12  

M doc/src/sgml/release.sgml
M doc/src/sgml/stylesheet-fo.xsl

commit   : 967316eebbd86bd3dce2607136ec24df7a9dce70    
  
author   : Bruce Momjian <[email protected]>    
date     : Thu, 19 Sep 2024 08:45:32 -0400    
  
committer: Bruce Momjian <[email protected]>    
date     : Thu, 19 Sep 2024 08:45:32 -0400    

Click here for diff

Reported-by: Andrew Dunstan  
  
Discussion: https://postgr.es/m/[email protected]  
  
Author: Andrew Dunstan  
  
Backpatch-through: 12  

M src/tools/add_commit_links.pl

doc PG relnotes: add paragraph explaining the section symbol

commit   : 772164777cd71bf62f2c67bd4bba75fcf83f5940    
  
author   : Bruce Momjian <[email protected]>    
date     : Wed, 18 Sep 2024 17:13:19 -0400    
  
committer: Bruce Momjian <[email protected]>    
date     : Wed, 18 Sep 2024 17:13:19 -0400    

Click here for diff

And suppress the symbol in print mode, where the section symbol does not  
appear.  
  
Discussion: https://postgr.es/m/[email protected]  
  
Backpatch-through: 12  

M doc/src/sgml/release.sgml
M doc/src/sgml/stylesheet-fo.xsl

commit   : 49f2650e8c208640f91716c5ac31d588410e70ab    
  
author   : Bruce Momjian <[email protected]>    
date     : Wed, 18 Sep 2024 16:34:51 -0400    
  
committer: Bruce Momjian <[email protected]>    
date     : Wed, 18 Sep 2024 16:34:51 -0400    

Click here for diff

In print output, there are too many commit links for footnotes in the  
release notes to be useful.  
  
Reported-by: Tom Lane  
  
Discussion: https://postgr.es/m/[email protected]  
  
Backpatch-through: 12  

M doc/src/sgml/stylesheet-fo.xsl

Don't enter parallel mode when holding interrupts.

commit   : 884860bfc0286ca35f7c097c2511bad90f4ede07    
  
author   : Noah Misch <[email protected]>    
date     : Tue, 17 Sep 2024 19:53:11 -0700    
  
committer: Noah Misch <[email protected]>    
date     : Tue, 17 Sep 2024 19:53:11 -0700    

Click here for diff

Doing so caused the leader to hang in wait_event=ParallelFinish, which  
required an immediate shutdown to resolve.  Back-patch to v12 (all  
supported versions).  
  
Francesco Degrassi  
  
Discussion: https://postgr.es/m/CAC-SaSzHUKT=vZJ8MPxYdC_URPfax+yoA1hKTcF4ROz_Q6z0_Q@mail.gmail.com  

M src/backend/optimizer/plan/planner.c
M src/test/regress/expected/select_parallel.out
M src/test/regress/sql/select_parallel.sql

Add missing query ID reporting in extended query protocol

commit   : cbcd4bb415cff8d7224dd84084f93b82829c81a7    
  
author   : Michael Paquier <[email protected]>    
date     : Wed, 18 Sep 2024 09:59:23 +0900    
  
committer: Michael Paquier <[email protected]>    
date     : Wed, 18 Sep 2024 09:59:23 +0900    

Click here for diff

This commit adds query ID reports for two code paths when processing  
extended query protocol messages:  
- When receiving a bind message, setting it to the first Query retrieved  
from a cached cache.  
- When receiving an execute message, setting it to the first PlannedStmt  
stored in a portal.  
  
An advantage of this method is that this is able to cover all the types  
of portals handled in the extended query protocol, particularly these  
two when the report done in ExecutorStart() is not enough (neither is an  
addition in ExecutorRun(), actually, for the second point):  
- Multiple execute messages, with multiple ExecutorRun().  
- Portal with execute/fetch messages, like a query with a RETURNING  
clause and a fetch size that stores the tuples in a first execute  
message going though ExecutorStart() and ExecuteRun(), followed by one  
or more execute messages doing only fetches from the tuplestore created  
in the first message.  This corresponds to the case where  
execute_is_fetch is set, for example.  
  
Note that the query ID reporting done in ExecutorStart() is still  
necessary, as an EXECUTE requires it.  Query ID reporting is optimistic  
and more calls to pgstat_report_query_id() don't matter as the first  
report takes priority except if the report is forced.  The comment in  
ExecutorStart() is adjusted to reflect better the reality with the  
extended query protocol.  
  
The test added in pg_stat_statements is a courtesy of Robert Haas.  This  
uses psql's \bind metacommand, hence this part is backpatched down to  
v16.  
  
Reported-by:  Kaido Vaikla, Erik Wienhold  
Author: Sami Imseih  
Reviewed-by: Jian He, Andrei Lepikhov, Michael Paquier  
Discussion: https://postgr.es/m/CA+427g8DiW3aZ6pOpVgkPbqK97ouBdf18VLiHFesea2jUk3XoQ@mail.gmail.com  
Discussion: https://postgr.es/m/CA+TgmoZxtnf_jZ=VqBSyaU8hfUkkwoJCJ6ufy4LGpXaunKrjrg@mail.gmail.com  
Discussion: https://postgr.es/m/[email protected]  
Backpatch-through: 14  

M src/backend/executor/execMain.c
M src/backend/tcop/postgres.c

Repair pg_upgrade for identity sequences with non-default persistence.

commit   : fc2d1ac1ad44b5c03e0e8edf0f9eb0e3f42cada4    
  
author   : Tom Lane <[email protected]>    
date     : Tue, 17 Sep 2024 15:53:26 -0400    
  
committer: Tom Lane <[email protected]>    
date     : Tue, 17 Sep 2024 15:53:26 -0400    

Click here for diff

Since we introduced unlogged sequences in v15, identity sequences  
have defaulted to having the same persistence as their owning table.  
However, it is possible to change that with ALTER SEQUENCE, and  
pg_dump tries to preserve the logged-ness of sequences when it doesn't  
match (as indeed it wouldn't for an unlogged table from before v15).  
  
The fly in the ointment is that ALTER SEQUENCE SET [UN]LOGGED fails  
in binary-upgrade mode, because it needs to assign a new relfilenode  
which we cannot permit in that mode.  Thus, trying to pg_upgrade a  
database containing a mismatching identity sequence failed.  
  
To fix, add syntax to ADD/ALTER COLUMN GENERATED AS IDENTITY to allow  
the sequence's persistence to be set correctly at creation, and use  
that instead of ALTER SEQUENCE SET [UN]LOGGED in pg_dump.  (I tried to  
make SET [UN]LOGGED work without any pg_dump modifications, but that  
seems too fragile to be a desirable answer.  This way should be  
markedly faster anyhow.)  
  
In passing, document the previously-undocumented SEQUENCE NAME option  
that pg_dump also relies on for identity sequences; I see no value  
in trying to pretend it doesn't exist.  
  
Per bug #18618 from Anthony Hsu.  
Back-patch to v15 where we invented this stuff.  
  
Discussion: https://postgr.es/m/[email protected]  

M doc/src/sgml/ref/create_table.sgml
M src/backend/commands/sequence.c
M src/backend/parser/gram.y
M src/backend/parser/parse_utilcmd.c
M src/bin/pg_dump/pg_dump.c
M src/test/regress/expected/identity.out
M src/test/regress/sql/identity.sql

doc PG relnotes: fix SGML markup for new commit links

commit   : 6f4e1fc5f34efa801475696d38449e21f38943ba    
  
author   : Bruce Momjian <[email protected]>    
date     : Mon, 16 Sep 2024 14:23:39 -0400    
  
committer: Bruce Momjian <[email protected]>    
date     : Mon, 16 Sep 2024 14:23:39 -0400    

Click here for diff

Backpatch-through: 12  

M doc/src/sgml/postgres.sgml

commit   : 5fd150379bbecce2a5e3798f2fce7c796eb00f73    
  
author   : Bruce Momjian <[email protected]>    
date     : Mon, 16 Sep 2024 14:14:38 -0400    
  
committer: Bruce Momjian <[email protected]>    
date     : Mon, 16 Sep 2024 14:14:38 -0400    

Click here for diff

Discussion: https://postgr.es/m/[email protected]  
  
Backpatch-through: 12  

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

commit   : ccd1ddc50750129a7900948ac28eef907bdbed51    
  
author   : Bruce Momjian <[email protected]>    
date     : Mon, 16 Sep 2024 13:26:37 -0400    
  
committer: Bruce Momjian <[email protected]>    
date     : Mon, 16 Sep 2024 13:26:37 -0400    

Click here for diff

Reported-by: jian he  
  
Discussion: https://postgr.es/m/[email protected]  
  
Backpatch-through: 12  

M src/tools/RELEASE_CHANGES
A src/tools/add_commit_links.pl

Replace usages of xmlXPathCompile() with xmlXPathCtxtCompile().

commit   : 634804885f334c4125134147a05a074e600598aa    
  
author   : Tom Lane <[email protected]>    
date     : Sun, 15 Sep 2024 13:33:09 -0400    
  
committer: Tom Lane <[email protected]>    
date     : Sun, 15 Sep 2024 13:33:09 -0400    

Click here for diff

In existing releases of libxml2, xmlXPathCompile can be driven  
to stack overflow because it fails to protect itself against  
too-deeply-nested input.  While there is an upstream fix as of  
yesterday, it will take years for that to propagate into all  
shipping versions.  In the meantime, we can protect our own  
usages basically for free by calling xmlXPathCtxtCompile instead.  
  
(The actual bug is that libxml2 keeps its nesting counter in the  
xmlXPathContext, and its parsing code was willing to just skip  
counting nesting levels if it didn't have a context.  So if we supply  
a context, all is well.  It seems odd actually that it works at all  
to not supply a context, because this means that XPath parsing does  
not have access to XML namespace info.  Apparently libxml2 never  
checks namespaces until runtime?  Anyway, this seems like good  
future-proofing even if its only immediate effect is to dodge a bug.)  
  
Sadly, this hack only offers protection with libxml2 2.9.11 and newer.  
Before that there are multiple similar problems, so if you are  
processing untrusted XML it behooves you to get a newer version.  
But we have some pretty old libxml2 in the buildfarm, so it seems  
impractical to add a regression test to verify this fix.  
  
Per bug #18617 from Jingzhou Fu.  Back-patch to all supported  
versions.  
  
Discussion: https://postgr.es/m/[email protected]  
Discussion: https://gitlab.gnome.org/GNOME/libxml2/-/issues/799  

M contrib/xml2/xpath.c
M src/backend/utils/adt/xml.c

doc PG relnotes: add attribution for time zone data files items

commit   : 9eafc0cc80d226268103ea2fd4de467a05ffd569    
  
author   : Bruce Momjian <[email protected]>    
date     : Sat, 14 Sep 2024 19:51:55 -0400    
  
committer: Bruce Momjian <[email protected]>    
date     : Sat, 14 Sep 2024 19:51:55 -0400    

Click here for diff

This is needed for a future script to add commit links;  specifically we  
need the closing parentheses of the attribution.  
  
Backpatch-through: 12  

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

Run regression tests with timezone America/Los_Angeles.

commit   : 2b94ee58bf256e1b4682f21f13d0f2c73e1b0cc2    
  
author   : Tom Lane <[email protected]>    
date     : Sat, 14 Sep 2024 17:55:03 -0400    
  
committer: Tom Lane <[email protected]>    
date     : Sat, 14 Sep 2024 17:55:03 -0400    

Click here for diff

Historically we've used timezone "PST8PDT", but the recent release  
2024b of tzdb changes the definition of that zone in a way that  
breaks many test cases concerned with dates before 1970.  Although  
we've not yet adopted 2024b into our own tree, this is already  
problematic for people using --with-system-tzdata if their platform  
has already adopted 2024b.  To work with both older and newer  
versions of tzdb, switch to using "America/Los_Angeles", accepting  
the ensuing changes in regression test results.  
  
Back-patch to all supported branches.  
  
Per report and patch from Wolfgang Walther.  
  
Discussion: https://postgr.es/m/[email protected]  

M doc/src/sgml/ref/set.sgml
M doc/src/sgml/regress.sgml
M src/test/regress/expected/date.out
M src/test/regress/expected/horology.out
M src/test/regress/expected/timestamptz.out
M src/test/regress/pg_regress.c
M src/test/regress/sql/horology.sql
M src/test/regress/sql/timestamptz.sql

Only define NO_THREAD_SAFE_LOCALE for MSVC plperl when required

commit   : 17c35ab236980fce2989f7fac7cee42ca4d5ca04    
  
author   : Andrew Dunstan <[email protected]>    
date     : Sat, 14 Sep 2024 08:37:08 -0400    
  
committer: Andrew Dunstan <[email protected]>    
date     : Sat, 14 Sep 2024 08:37:08 -0400    

Click here for diff

Latest versions of Strawberry Perl define USE_THREAD_SAFE_LOCALE, and we  
therefore get a handshake error when building against such instances.  
The solution is to perform a test to see if USE_THREAD_SAFE_LOCALE is  
defined and only define NO_THREAD_SAFE_LOCALE if it isn't.  
  
Backpatch the meson.build fix back to release 16 and apply the same  
logic to Mkvcbuild.pm in releases 12 through 16.  
  
Original report of the issue from Muralikrishna Bandaru.  

M src/tools/msvc/Mkvcbuild.pm

Allow _h_indexbuild() to be interrupted.

commit   : e0857898b87b745235e65c28feed6e23e121876d    
  
author   : Tom Lane <[email protected]>    
date     : Fri, 13 Sep 2024 16:16:47 -0400    
  
committer: Tom Lane <[email protected]>    
date     : Fri, 13 Sep 2024 16:16:47 -0400    

Click here for diff

When we are building a hash index that is large enough to need  
pre-sorting (larger than either maintenance_work_mem or NBuffers),  
the initial sorting phase is interruptible, but the insertion  
phase wasn't.  Add the missing CHECK_FOR_INTERRUPTS().  
  
Per bug #18616 from Alexander Lakhin.  Back-patch to all  
supported branches.  
  
Pavel Borisov  
  
Discussion: https://postgr.es/m/[email protected]  

M src/backend/access/hash/hashsort.c

Fix contrib/pageinspect's test for sequences.

commit   : a63aef5e496c1db0325845892d946e8569e7f9d6    
  
author   : Nathan Bossart <[email protected]>    
date     : Fri, 13 Sep 2024 10:16:40 -0500    
  
committer: Nathan Bossart <[email protected]>    
date     : Fri, 13 Sep 2024 10:16:40 -0500    

Click here for diff

I managed to break this test in two different ways in commit  
05036a3155.  
  
First, the output of the new call to tuple_data_split() on the test  
sequence is dependent on endianness.  This is fixed by setting a  
special start value for the test sequence that produces the same  
output regardless of the endianness of the machine.  
  
Second, on versions older than v15, the new test case fails under  
"force_parallel_mode = regress" with the following error:  
  
	ERROR:  cannot access temporary tables during a parallel operation  
  
This is because pageinspect's disk-accessing functions are  
incorrectly marked PARALLEL SAFE on versions older than v15 (see  
commit aeaaf520f4 for details).  This one is fixed by changing the  
test sequence to be permanent.  The only reason it was previously  
marked temporary was to avoid needing a DROP SEQUENCE command at  
the end of the test.  Unlike some other tests in this file, the use  
of a permanent sequence here shouldn't result in any test  
instability like what was fixed by commit e2933a6e11.  
  
Reviewed-by: Tom Lane  
Discussion: https://postgr.es/m/ZuOKOut5hhDlf_bP%40nathan  
Backpatch-through: 12  

M contrib/pageinspect/expected/page.out
M contrib/pageinspect/sql/page.sql

Reintroduce support for sequences in pgstattuple and pageinspect.

commit   : e03042a7003dcf0e966f0c6ea3ecf128455bf2b3    
  
author   : Nathan Bossart <[email protected]>    
date     : Thu, 12 Sep 2024 16:31:29 -0500    
  
committer: Nathan Bossart <[email protected]>    
date     : Thu, 12 Sep 2024 16:31:29 -0500    

Click here for diff

Commit 4b82664156 restricted a number of functions provided by  
contrib modules to only relations that use the "heap" table access  
method.  Sequences always use this table access method, but they do  
not advertise as such in the pg_class system catalog, so the  
aforementioned commit also (presumably unintentionally) removed  
support for sequences from some of these functions.  This commit  
reintroduces said support for sequences to these functions and adds  
a couple of relevant tests.  
  
Co-authored-by: Ayush Vatsa  
Reviewed-by: Robert Haas, Michael Paquier, Matthias van de Meent  
Discussion: https://postgr.es/m/CACX%2BKaP3i%2Bi9tdPLjF5JCHVv93xobEdcd_eB%2B638VDvZ3i%3DcQA%40mail.gmail.com  
Backpatch-through: 12  

M contrib/pageinspect/expected/page.out
M contrib/pageinspect/heapfuncs.c
M contrib/pageinspect/sql/page.sql
M contrib/pgstattuple/expected/pgstattuple.out
M contrib/pgstattuple/pgstattuple.c
M contrib/pgstattuple/sql/pgstattuple.sql

Remove incorrect Assert.

commit   : 78d0bd452c78b17a788d2f15dc4e28bd3d3159c0    
  
author   : Tom Lane <[email protected]>    
date     : Wed, 11 Sep 2024 11:41:47 -0400    
  
committer: Tom Lane <[email protected]>    
date     : Wed, 11 Sep 2024 11:41:47 -0400    

Click here for diff

check_agglevels_and_constraints() asserted that if we find an  
aggregate function in an EXPR_KIND_FROM_SUBSELECT expression, the  
expression must be in a LATERAL subquery.  Alexander Lakhin found a  
case where that's not so: because of the odd scoping rules for NEW/OLD  
within a rule, a reference to NEW/OLD could cause an aggregate to be  
considered top-level even though it's in an unmarked sub-select.  
The error message that would be thrown seems sufficiently on-point,  
so just remove the Assert.  (Hence, this is not a bug for production  
builds.)  
  
This Assert was added by me in commit eaccfded9 (9.3 era).  It looks  
like I put it in to cross-check that the new logic for detecting  
misplaced aggregates (using agglevelsup) caught the same cases that a  
previous check on p_lateral_active did.  So there might have been some  
related misbehavior before eaccfded9 ... but that's very ancient  
history by now, so I didn't dig any deeper.  
  
Per bug #18608 from Alexander Lakhin.  Back-patch to all supported  
branches.  
  
Discussion: https://postgr.es/m/[email protected]  

M src/backend/parser/parse_agg.c

Fix waits of REINDEX CONCURRENTLY for indexes with predicates or expressions

commit   : 239837a708cc2c6f27d96ddb3faf89691f2a22cd    
  
author   : Michael Paquier <[email protected]>    
date     : Mon, 9 Sep 2024 13:50:12 +0900    
  
committer: Michael Paquier <[email protected]>    
date     : Mon, 9 Sep 2024 13:50:12 +0900    

Click here for diff

As introduced by f9900df5f94, a REINDEX CONCURRENTLY job done for an  
index with predicates or expressions would set PROC_IN_SAFE_IC in its  
MyProc->statusFlags, causing it to be ignored by other concurrent  
operations.  
  
Such concurrent index rebuilds should never be ignored, as a predicate  
or an expression could call a user-defined function that accesses a  
different table than the table where the index is rebuilt.  
  
A test that uses injection points is added, backpatched down to 17.  
Michail has proposed a different test, but I have added something  
simpler with more coverage.  
  
Oversight in f9900df5f949.  
  
Author: Michail Nikolaev  
Discussion: https://postgr.es/m/CANtu0oj9A3kZVduFTG0vrmGnKB+DCHgEpzOp0qAyOgmks84j0w@mail.gmail.com  
Backpatch-through: 14  

M src/backend/commands/indexcmds.c

Prevent mis-encoding of "trailing junk after numeric literal" errors.

commit   : f37ac613a835c8ff28a2f23abe14c88fbac8b039    
  
author   : Tom Lane <[email protected]>    
date     : Thu, 5 Sep 2024 12:42:33 -0400    
  
committer: Tom Lane <[email protected]>    
date     : Thu, 5 Sep 2024 12:42:33 -0400    

Click here for diff

Since commit 2549f0661, we reject an identifier immediately following  
a numeric literal (without separating whitespace), because that risks  
ambiguity with hex/octal/binary integers.  However, that patch used  
token patterns like "{integer}{ident_start}", which is problematic  
because {ident_start} matches only a single byte.  If the first  
character after the integer is a multibyte character, this ends up  
with flex reporting an error message that includes a partial multibyte  
character.  That can cause assorted bad-encoding problems downstream,  
both in the report to the client and in the postmaster log file.  
  
To fix, use {identifier} not {ident_start} in the "junk" token  
patterns, so that they will match complete multibyte characters.  
This seems generally better user experience quite aside from the  
encoding problem: for "123abc" the error message will now say that  
the error appeared at or near "123abc" instead of "123a".  
  
While at it, add some commentary about why these patterns exist  
and how they work.  
  
Report and patch by Karina Litskevich; review by Pavel Borisov.  
Back-patch to v15 where the problem came in.  
  
Discussion: https://postgr.es/m/CACiT8iZ_diop=0zJ7zuY3BXegJpkKK1Av-PU7xh0EDYHsa5+=g@mail.gmail.com  

M src/backend/parser/scan.l
M src/fe_utils/psqlscan.l
M src/interfaces/ecpg/preproc/pgc.l
M src/test/regress/expected/numerology.out

Stabilize 039_end_of_wal test.

commit   : 777f50b9b5822d1058c59fc2ee1d1a7e9c766bf8    
  
author   : Thomas Munro <[email protected]>    
date     : Sat, 31 Aug 2024 14:32:08 +1200    
  
committer: Thomas Munro <[email protected]>    
date     : Sat, 31 Aug 2024 14:32:08 +1200    

Click here for diff

The first test was sensitive to the insert LSN after setting up the  
catalogs, which depended on environmental things like the locales on the  
OS and usernames.  Switch to a new WAL file before the first test, as a  
simple way to put every computer into the same state.  
  
Back-patch to all supported releases.  
  
Reported-by: Anton Voloshin <[email protected]>  
Reported-by: Nathan Bossart <[email protected]>  
Reviewed-by: Tom Lane <[email protected]>  
Reviewed-by: Nathan Bossart <[email protected]>  
Discussion: https://postgr.es/m/b26aeac2-cb6d-4633-a7ea-945baae83dcf%40postgrespro.ru  

M src/test/recovery/t/039_end_of_wal.pl

Clarify restrict_nonsystem_relation_kind description.

commit   : 886549fb105f0c3d6a24064a9ddaf4e8602e0382    
  
author   : Masahiko Sawada <[email protected]>    
date     : Fri, 30 Aug 2024 15:06:02 -0700    
  
committer: Masahiko Sawada <[email protected]>    
date     : Fri, 30 Aug 2024 15:06:02 -0700    

Click here for diff

This change improves the description of the  
restrict_nonsystem_relation_kind parameter in guc_table.c and the  
documentation for better clarity.  
  
Backpatch to 12, where this GUC parameter was introduced.  
  
Reviewed-by: Peter Eisentraut  
Discussion: https://postgr.es/m/6a96f1af-22b4-4a80-8161-1f26606b9ee2%40eisentraut.org  
Backpatch-through: 12  

M doc/src/sgml/config.sgml
M src/backend/utils/misc/guc.c

Disallow USING clause when altering type of generated column

commit   : cf49a606c416634fd6af82eb559331fd6052835d    
  
author   : Peter Eisentraut <[email protected]>    
date     : Thu, 29 Aug 2024 08:38:29 +0200    
  
committer: Peter Eisentraut <[email protected]>    
date     : Thu, 29 Aug 2024 08:38:29 +0200    

Click here for diff

This does not make sense.  It would write the output of the USING  
clause into the converted column, which would violate the generation  
expression.  This adds a check to error out if this is specified.  
  
There was a test for this, but that test errored out for a different  
reason, so it was not effective.  
  
Reported-by: Jian He <[email protected]>  
Reviewed-by: Yugo NAGATA <[email protected]>  
Discussion: https://www.postgresql.org/message-id/flat/c7083982-69f4-4b14-8315-f9ddb20b9834%40eisentraut.org  

M src/backend/commands/tablecmds.c
M src/test/regress/expected/generated.out

Fix a couple of wait event descriptions.

commit   : 5d9170697e4e6dd282b015890bc29baf978c6cb5    
  
author   : Nathan Bossart <[email protected]>    
date     : Tue, 20 Aug 2024 13:43:20 -0500    
  
committer: Nathan Bossart <[email protected]>    
date     : Tue, 20 Aug 2024 13:43:20 -0500    

Click here for diff

The descriptions for ProcArrayGroupUpdate and XactGroupUpdate claim  
that these events mean we are waiting for the group leader "at end  
of a parallel operation," but neither pertains to parallel  
operations.  This commit reverts these descriptions to their  
wording before commit 3048898e73, i.e., "end of a parallel  
operation" is changed to "transaction end."  
  
Author: Sameer Kumar  
Reviewed-by: Amit Kapila  
Discussion: https://postgr.es/m/CAGPeHmh6UMrKQHKCmX%2B5vV5TH9P%3DKw9en3k68qEem6J%3DyrZPUA%40mail.gmail.com  
Backpatch-through: 13  

M doc/src/sgml/monitoring.sgml

Document limit on the number of out-of-line values per table

commit   : e51160fa0bab7203e37094fbb0349b0c324b09e7    
  
author   : John Naylor <[email protected]>    
date     : Tue, 20 Aug 2024 10:02:34 +0700    
  
committer: John Naylor <[email protected]>    
date     : Tue, 20 Aug 2024 10:02:34 +0700    

Click here for diff

Document the hard limit stemming from the size of an OID, and also  
mention the perfomance impact that occurs before the hard limit  
is reached.  
  
Jakub Wartak and Robert Haas  
Backpatch to all supported versions  
  
Discussion: https://postgr.es/m/CAKZiRmwWhp2yxjqJLwbBjHdfbJBcUmmKMNAZyBjjtpgM9AMatQ%40mail.gmail.com  

M doc/src/sgml/limits.sgml

Avoid failure to open dropped detached partition

commit   : be73e7008558cef1f59b0f4a61cefb6ec53c45c5    
  
author   : Alvaro Herrera <[email protected]>    
date     : Mon, 19 Aug 2024 16:09:10 -0400    
  
committer: Alvaro Herrera <[email protected]>    
date     : Mon, 19 Aug 2024 16:09:10 -0400    

Click here for diff

When a partition is detached and immediately dropped, a prepared  
statement could try to compute a new partition descriptor that includes  
it.  This leads to this kind of error:  
ERROR:  could not open relation with OID 457639  
  
Avoid this by skipping the partition in expand_partitioned_rtentry if it  
doesn't exist.  
  
Noted by me while investigating bug #18559.  Kuntal Gosh helped to  
identify the exact failure.  
  
Backpatch to 14, where DETACH CONCURRENTLY was introduced.  
  
Author: Álvaro Herrera <[email protected]>  
Reviewed-by: Kuntal Ghosh <[email protected]>  
Reviewed-by: Junwang Zhao <[email protected]>  
Discussion: https://postgr.es/m/[email protected]  

M src/backend/optimizer/util/inherit.c

Explain dropdb can't use syscache because of TOAST

commit   : e498d22e21358e196c1db9b5f1300eae667ea2bd    
  
author   : Tomas Vondra <[email protected]>    
date     : Mon, 19 Aug 2024 13:31:51 +0200    
  
committer: Tomas Vondra <[email protected]>    
date     : Mon, 19 Aug 2024 13:31:51 +0200    

Click here for diff

Add a comment explaining dropdb() can't rely on syscache. The issue with  
flattened rows was fixed by commit 0f92b230f88b, but better to have  
a clear explanation why the systable scan is necessary. The other places  
doing in-place updates on pg_database have the same comment.  
  
Suggestion and patch by Yugo Nagata. Backpatch to 12, same as the fix.  
  
Author: Yugo Nagata  
Backpatch-through: 12  
Discussion: https://postgr.es/m/CAJTYsWWNkCt+-UnMhg=BiCD3Mh8c2JdHLofPxsW3m2dkDFw8RA@mail.gmail.com  

M src/backend/commands/dbcommands.c

Fix regression in TLS session ticket disabling

commit   : 23c200940eae6e7d9cf5712c3514691bfdaf3904    
  
author   : Daniel Gustafsson <[email protected]>    
date     : Mon, 19 Aug 2024 12:55:11 +0200    
  
committer: Daniel Gustafsson <[email protected]>    
date     : Mon, 19 Aug 2024 12:55:11 +0200    

Click here for diff

Commit 274bbced disabled session tickets for TLSv1.3 on top of the  
already disabled TLSv1.2 session tickets, but accidentally caused  
a regression where TLSv1.2 session tickets were incorrectly sent.  
Fix by unconditionally disabling TLSv1.2 session tickets and only  
disable TLSv1.3 tickets when the right version of OpenSSL is used.  
  
Backpatch to all supported branches.  
  
Reported-by: Cameron Vogt <[email protected]>  
Reported-by: Fire Emerald <[email protected]>  
Reviewed-by: Jacob Champion <[email protected]>  
Discussion: https://postgr.es/m/DM6PR16MB3145CF62857226F350C710D1AB852@DM6PR16MB3145.namprd16.prod.outlook.com  
Backpatch-through: v12  

M src/backend/libpq/be-secure-openssl.c

Fix harmless LC_COLLATE[_MASK] confusion.

commit   : c1bb534bae431f4bbc50abf471507457e1b24efc    
  
author   : Thomas Munro <[email protected]>    
date     : Mon, 19 Aug 2024 21:21:03 +1200    
  
committer: Thomas Munro <[email protected]>    
date     : Mon, 19 Aug 2024 21:21:03 +1200    

Click here for diff

Commit ca051d8b101 called newlocale(LC_COLLATE, ...) instead of  
newlocale(LC_COLLATE_MASK, ...), in code reached only on FreeBSD.  They  
have the same value on that OS, explaining why it worked.  Fix.  
  
Back-patch to 14, where ca051d8b101 landed.  

M src/backend/utils/adt/pg_locale.c

ci: Upgrade MacPorts version to 2.10.1.

commit   : 4247575c637b4d049346b96514ac9ca3363276d5    
  
author   : Thomas Munro <[email protected]>    
date     : Mon, 19 Aug 2024 11:47:37 +1200    
  
committer: Thomas Munro <[email protected]>    
date     : Mon, 19 Aug 2024 11:47:37 +1200    

Click here for diff

MacPorts version 2.9.3 started failing in our ci_macports_packages.sh  
script, for reasons not fully determined, but plausibly linked to the  
release of 2.10.1.  2.10.1 seems to work, so let's switch to it.  
  
Back-patch to 15, where CI began.  
  
Reported-by: Peter Eisentraut <[email protected]>  
Discussion: https://postgr.es/m/81f104e8-f0a9-43c0-85bd-2bbbf590a5b8%40eisentraut.org  

M src/tools/ci/ci_macports_packages.sh

Fix DROP DATABASE for databases with many ACLs

commit   : df9c5fb5837fed76e2c80daa03a2b0443983614b    
  
author   : Tomas Vondra <[email protected]>    
date     : Mon, 19 Aug 2024 00:04:41 +0200    
  
committer: Tomas Vondra <[email protected]>    
date     : Mon, 19 Aug 2024 00:04:41 +0200    

Click here for diff

Commit c66a7d75e652 modified DROP DATABASE so that if interrupted, the  
database is known to be in an invalid state and can only be dropped.  
This is done by setting a flag using an in-place update, so that it's  
not lost in case of rollback.  
  
For databases with many ACLs, this may however fail like this:  
  
  ERROR:  wrong tuple length  
  
This happens because with many ACLs, the pg_database.datacl attribute  
gets TOASTed. The dropdb() code reads the tuple from the syscache, which  
means it's detoasted. But the in-place update expects the tuple length  
to match the on-disk tuple.  
  
Fixed by reading the tuple from the catalog directly, not from syscache.  
  
Report and fix by Ayush Tiwari. Backpatch to 12. The DROP DATABASE fix  
was backpatched to 11, but 11 is EOL at this point.  
  
Reported-by: Ayush Tiwari  
Author: Ayush Tiwari  
Reviewed-by: Tomas Vondra  
Backpatch-through: 12  
Discussion: https://postgr.es/m/CAJTYsWWNkCt+-UnMhg=BiCD3Mh8c2JdHLofPxsW3m2dkDFw8RA@mail.gmail.com  

M src/backend/commands/dbcommands.c

docs: fix incorrect plpgsql error message

commit   : e8f36414afac579f32c06573344c8ff4d854b59d    
  
author   : Bruce Momjian <[email protected]>    
date     : Fri, 16 Aug 2024 22:50:54 -0400    
  
committer: Bruce Momjian <[email protected]>    
date     : Fri, 16 Aug 2024 22:50:54 -0400    

Click here for diff

Change "$1" to "username".  
  
Reported-by: [email protected]  
  
Discussion: https://postgr.es/m/[email protected]  
  
Backpatch-through: 12  

M doc/src/sgml/plpgsql.sgml

Fix creation of partition descriptor during concurrent detach+drop

commit   : 305db95434c9f68811f2489ec57d5a0435608c46    
  
author   : Alvaro Herrera <[email protected]>    
date     : Mon, 12 Aug 2024 18:17:56 -0400    
  
committer: Alvaro Herrera <[email protected]>    
date     : Mon, 12 Aug 2024 18:17:56 -0400    

Click here for diff

If a partition undergoes DETACH CONCURRENTLY immediately followed by  
DROP, this could cause a problem for a concurrent transaction  
recomputing the partition descriptor when running a prepared statement,  
because it tries to dereference a pointer to a tuple that's not found in  
a catalog scan.  
  
The existing retry logic added in commit dbca3469ebf8 is sufficient to  
cope with the overall problem, provided we don't try to dereference a  
non-existant heap tuple.  
  
Arguably, the code in RelationBuildPartitionDesc() has been wrong all  
along, since no check was added in commit 898e5e3290a7 against receiving  
a NULL tuple from the catalog scan; that bug has only become  
user-visible with DETACH CONCURRENTLY which was added in branch 14.  
Therefore, even though there's no known mechanism to cause a crash  
because of this, backpatch the addition of such a check to all supported  
branches.  In branches prior to 14, this would cause the code to fail  
with a "missing relpartbound for relation XYZ" error instead of  
crashing; that's okay, because there are no reports of such behavior  
anyway.  
  
Author: Kuntal Ghosh <[email protected]>  
Reviewed-by: Junwang Zhao <[email protected]>  
Reviewed-by: Tender Wang <[email protected]>  
Discussion: https://postgr.es/m/[email protected]  

M src/backend/partitioning/partdesc.c

Suppress Coverity warnings about Asserts in get_name_for_var_field.

commit   : 16e67bc5f98f2f5691fb5c01d5a8310de1c62b81    
  
author   : Tom Lane <[email protected]>    
date     : Sun, 11 Aug 2024 12:24:56 -0400    
  
committer: Tom Lane <[email protected]>    
date     : Sun, 11 Aug 2024 12:24:56 -0400    

Click here for diff

Coverity thinks dpns->plan could be null at these points.  That  
shouldn't really be possible, but it's easy enough to modify the  
Asserts so they'd not core-dump if it were true.  
  
These are new in b919a97a6.  Back-patch to v13; the v12 version  
of the patch didn't have these Asserts.  

M src/backend/utils/adt/ruleutils.c

Allow adjusting session_authorization and role in parallel workers.

commit   : 2f4e895be76044fc09bdf96617043c94a12079e7    
  
author   : Tom Lane <[email protected]>    
date     : Sat, 10 Aug 2024 15:51:28 -0400    
  
committer: Tom Lane <[email protected]>    
date     : Sat, 10 Aug 2024 15:51:28 -0400    

Click here for diff

The code intends to allow GUCs to be set within parallel workers  
via function SET clauses, but not otherwise.  However, doing so fails  
for "session_authorization" and "role", because the assign hooks for  
those attempt to set the subsidiary "is_superuser" GUC, and that call  
falls foul of the "not otherwise" prohibition.  We can't switch to  
using GUC_ACTION_SAVE for this, so instead add a new GUC variable  
flag GUC_ALLOW_IN_PARALLEL to mark is_superuser as being safe to set  
anyway.  (This is okay because is_superuser has context PGC_INTERNAL  
and thus only hard-wired calls can change it.  We'd need more thought  
before applying the flag to other GUCs; but maybe there are other  
use-cases.)  This isn't the prettiest fix perhaps, but other  
alternatives we thought of would be much more invasive.  
  
While here, correct a thinko in commit 059de3ca4: when rejecting  
a GUC setting within a parallel worker, we should return 0 not -1  
if the ereport doesn't longjmp.  (This seems to have no consequences  
right now because no caller cares, but it's inconsistent.)  Improve  
the comments to try to forestall future confusion of the same kind.  
  
Despite the lack of field complaints, this seems worth back-patching.  
Thanks to Nathan Bossart for the idea to invent a new flag,  
and for review.  
  
Discussion: https://postgr.es/m/[email protected]  

M src/backend/utils/misc/guc.c
M src/include/utils/guc.h
M src/test/regress/expected/select_parallel.out
M src/test/regress/sql/select_parallel.sql

doc: Fix name of CRC algorithm in "Reliability" section.

commit   : 75bb3354e6da6cceae9756d2e3c473088e554b16    
  
author   : Nathan Bossart <[email protected]>    
date     : Fri, 9 Aug 2024 10:52:37 -0500    
  
committer: Nathan Bossart <[email protected]>    
date     : Fri, 9 Aug 2024 10:52:37 -0500    

Click here for diff

This section claims we use CRC-32 for WAL records and two-phase  
state files, but we've actually used CRC-32C since v9.5 (commit  
5028f22f6e).  Fix that.  
  
Reviewed-by: Robert Haas  
Discussion: https://postgr.es/m/ZrUFpLP-w2zTAHqq%40nathan  
Backpatch-through: 12  

M doc/src/sgml/wal.sgml

Fix "failed to find plan for subquery/CTE" errors in EXPLAIN.

commit   : 12010f4146156ae276e5e606400ed9ce39a83e0b    
  
author   : Tom Lane <[email protected]>    
date     : Fri, 9 Aug 2024 11:21:39 -0400    
  
committer: Tom Lane <[email protected]>    
date     : Fri, 9 Aug 2024 11:21:39 -0400    

Click here for diff

To deparse a reference to a field of a RECORD-type output of a  
subquery, EXPLAIN normally digs down into the subquery's plan to try  
to discover exactly which anonymous RECORD type is meant.  However,  
this can fail if the subquery has been optimized out of the plan  
altogether on the grounds that no rows could pass the WHERE quals,  
which has been possible at least since 3fc6e2d7f.  There isn't  
anything remaining in the plan tree that would help us, so fall back  
to printing the field name as "fN" for the N'th column of the record.  
(This will actually be the right thing some of the time, since it  
matches the column names we assign to RowExprs.)  
  
In passing, fix a comment typo in create_projection_plan, which  
I noticed while experimenting with an alternative fix for this.  
  
Per bug #18576 from Vasya B.  Back-patch to all supported branches.  
  
Richard Guo and Tom Lane  
  
Discussion: https://postgr.es/m/[email protected]  

M src/backend/optimizer/plan/createplan.c
M src/backend/utils/adt/ruleutils.c
M src/test/regress/expected/rowtypes.out
M src/test/regress/sql/rowtypes.sql

Refuse ATTACH of a table referenced by a foreign key

commit   : 8c0944ac878d3d3e433da8feb2f7e134be8353f3    
  
author   : Alvaro Herrera <[email protected]>    
date     : Thu, 8 Aug 2024 19:35:13 -0400    
  
committer: Alvaro Herrera <[email protected]>    
date     : Thu, 8 Aug 2024 19:35:13 -0400    

Click here for diff

Trying to attach a table as a partition which is already on the  
referenced side of a foreign key on the partitioned table that it is  
being attached to, leads to strange behavior: we try to clone the  
foreign key from the parent to the partition, but this new FK points to  
the partition itself, and the mix of pg_constraint rows and triggers  
doesn't behave well.  
  
Rather than trying to untangle the mess (which might be possible given  
sufficient time), I opted to forbid the ATTACH.  This doesn't seem a  
problematic restriction, given that we already fail to create the  
foreign key if you do it the other way around, that is, having the  
partition first and the FK second.  
  
Backpatch to all supported branches.  
  
Reported-by: Alexander Lakhin <[email protected]>  
Reviewed-by: Tender Wang <[email protected]>  
Discussion: https://postgr.es/m/[email protected]  

M src/backend/commands/tablecmds.c
M src/test/regress/expected/foreign_key.out
M src/test/regress/sql/foreign_key.sql

Fix pg_rewind debug output to print the source timeline history

commit   : b5a5027c9796e2958392f4682928d47b5b0d0e47    
  
author   : Heikki Linnakangas <[email protected]>    
date     : Thu, 8 Aug 2024 10:20:25 +0300    
  
committer: Heikki Linnakangas <[email protected]>    
date     : Thu, 8 Aug 2024 10:20:25 +0300    

Click here for diff

getTimelineHistory() is called twice, to read the source and the  
target timeline history files. However, the loop to print the file  
with the --debug option used the wrong variable when dealing with the  
source. As a result, the source's history was always printed as empty.  
  
Spotted while debugging bug #18575, but this does not fix that bug,  
just the debugging output. Backpatch to all supported versions.  
  
Discussion: https://www.postgresql.org/message-id/[email protected]  

M src/bin/pg_rewind/pg_rewind.c

Revert ECPG's use of pnstrdup()

commit   : 2de129b356bfde9a02269c174396add065ace260    
  
author   : Peter Eisentraut <[email protected]>    
date     : Wed, 7 Aug 2024 09:21:07 +0200    
  
committer: Peter Eisentraut <[email protected]>    
date     : Wed, 7 Aug 2024 09:21:07 +0200    

Click here for diff

Commit 0b9466fce added a dependency on fe_memutils' pnstrdup() inside  
informix.c.  This adds an exit() path in a library, which we don't  
want.  (Unlike libpq, the ecpg libraries don't have an automated check  
for that, but it makes sense to keep them to a similar standard.)  The  
ecpg code can already handle failure results from the *strdup() call  
by itself.  
  
Author: Jacob Champion <[email protected]>  
Discussion: https://www.postgresql.org/message-id/CAOYmi+=pg=W5L1h=3MEP_EB24jaBu2FyATrLXqQHGe7cpuvwyg@mail.gmail.com  

M src/interfaces/ecpg/compatlib/informix.c

Fix edge case in plpgsql's make_callstmt_target().

commit   : de35207015567da892d825a704933e6681347f19    
  
author   : Tom Lane <[email protected]>    
date     : Wed, 7 Aug 2024 12:54:39 -0400    
  
committer: Tom Lane <[email protected]>    
date     : Wed, 7 Aug 2024 12:54:39 -0400    

Click here for diff

If the plancache entry for the CALL statement is already stale,  
it's possible for us to fetch an old procedure OID out of it,  
and then fail with "cache lookup failed for function NNN".  
In ordinary usage this never happens because make_callstmt_target  
is called just once immediately after building the plancache  
entry.  It can be forced however by setting up an erroneous CALL  
(that causes make_callstmt_target itself to report an error),  
then dropping/recreating the target procedure, then repeating  
the erroneous CALL.  
  
To fix, use SPI_plan_get_cached_plan() to fetch the plancache's  
plan, rather than assuming we can use SPI_plan_get_plan_sources().  
This shouldn't add any noticeable overhead in the normal case,  
and in the stale-plan case we'd have had to replan anyway a little  
further down.  
  
The other callers of SPI_plan_get_plan_sources() seem OK, because  
either they don't need up-to-date plans or they know that the  
query was just (re) planned.  But add some commentary in hopes  
of not falling into this trap again.  
  
Per bug #18574 from Song Hongyu.  Back-patch to v14 where this coding  
was introduced.  (Older branches have comparable code, but it's run  
after any required replanning, so there's no issue.)  
  
Discussion: https://postgr.es/m/[email protected]  

M src/backend/executor/spi.c
M src/pl/plpgsql/src/pl_exec.c

Make fallback MD5 implementation thread-safe on big-endian systems

commit   : a38f5f880d1e86fedf1616de5391df5f0d5e4239    
  
author   : Heikki Linnakangas <[email protected]>    
date     : Wed, 7 Aug 2024 10:43:52 +0300    
  
committer: Heikki Linnakangas <[email protected]>    
date     : Wed, 7 Aug 2024 10:43:52 +0300    

Click here for diff

Replace a static scratch buffer with a local variable, because a  
static buffer makes the function not thread-safe. This function is  
used in client-code in libpq, so it needs to be thread-safe. It was  
until commit b67b57a966, which replaced the implementation with the  
one from pgcrypto.  
  
Backpatch to v14, where we switched to the new implementation.  
  
Reviewed-by: Robert Haas, Michael Paquier  
Discussion: https://www.postgresql.org/message-id/[email protected]  

M src/common/md5.c