users/rhaas/postgres.git
2 weeks agopg_createsubscriber: Improve handling of automated recovery configuration
Michael Paquier [Thu, 8 Jan 2026 01:12:33 +0000 (10:12 +0900)]
pg_createsubscriber: Improve handling of automated recovery configuration

When repurposing a standby to a logical replica, pg_createsubscriber
uses for the new replica a set of configuration parameters saved into
postgresql.auto.conf, to force recovery patterns when the physical
replica is promoted.

While not wrong in practice, this approach can cause issues when forcing
again recovery on a logical replica or its base backup as the recovery
parameters are not reset on the target server once pg_createsubscriber
is done with the node.

This commit aims at improving the situation, by changing the way
recovery parameters are saved on the target node.  Instead of writing
all the configuration to postgresql.auto.conf, this file now uses an
include_if_exists, that points to a pg_createsubscriber.conf.  This new
file contains all the recovery configuration, and is renamed to
pg_createsubscriber.conf.disabled when pg_createsubscriber exits.  This
approach resets the recovery parameters, and offers the benefit to keep
a trace of the setup used when the target node got promoted, for
debugging purposes.  If pg_createsubscriber.conf cannot be renamed
(unlikely scenario), a warning is issued to inform users that a manual
intervention may be required to reset this configuration.

This commit includes a test case to demonstrate the problematic case: a
standby node created from a base backup of what was the target node of
pg_createsubscriber does not get confused when started.  If removing
this new logic, the test fails with the standby not able to start due
to an incorrect recovery target setup, where the startup process fails
quickly with a FATAL.

I have provided the design idea for the patch, that Alyona has written
(with some code adjustments from me).  This could be considered as a
bug, but after discussion this is put into the bucket for improvements.
Redesigning pg_createsubscriber would not be acceptable in the stable
branches anyway.

Author: Alyona Vinter <dlaaren8@gmail.com>
Reviewed-by: Ilyasov Ian <ianilyasov@outlook.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Andrey Rudometov <unlimitedhikari@gmail.com>
Discussion: https://postgr.es/m/CAGWv16K6L6Pzm99i1KiXLjFWx2bUS3DVsR6yV87-YR9QO7xb3A@mail.gmail.com

2 weeks agopsql: Add tab completion for pstdin and pstdout in \copy.
Masahiko Sawada [Thu, 8 Jan 2026 00:22:42 +0000 (16:22 -0800)]
psql: Add tab completion for pstdin and pstdout in \copy.

This commit adds tab completion support for the keywords "pstdin" and
"pstdout" in the \copy command. "pstdin" is now suggested after FROM,
and "pstdout" is suggested after TO, alongside filenames and other
keywords.

Author: Yugo Nagata <nagata@sraoss.co.jp>
Reviewed-by: Srinath Reddy Sadipiralla <srinath2133@gmail.com>
Reviewed-by: Kirill Reshke <reshkekirill@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Discussion: https://postgr.es/m/20251231183953.95132e171e43abd5e9b78084@sraoss.co.jp

2 weeks agoReplace flaky CIC/RI isolation tests with a TAP test
Álvaro Herrera [Wed, 7 Jan 2026 22:44:57 +0000 (19:44 -0300)]
Replace flaky CIC/RI isolation tests with a TAP test

The isolation tests for INSERT ON CONFLICT behavior during CREATE INDEX
CONCURRENTLY and REINDEX CONCURRENTLY (added by bc32a12e0db2,
2bc7e886fc1b, and 90eae926abbb) were disabled in 77038d6d0b49 due to
persistent CI flakiness, after several attempts at stabilization.

This commit removes them and introduces a TAP test in test_misc module
(010_index_concurrently_upsert.pl) that covers the same scenarios.  This
new test should hopefully be more stable while providing assurance that
the fixes in all those commits (plus 81f72115cf18) continue to work.

Author: Mihail Nikalayeu <mihailnikalayeu@gmail.com>
Reported-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de>
Discussion: https://postgr.es/m/ccssrhafzbp3a3beju3ptyc56a7gbfimj4vwkbokoldofckrc7@bso37rxskjtf
Discussion: https://postgr.es/m/CANtu0ogv+6wqRzPK241jik4U95s1pW3MCZ3rX5ZqbFdUysz7Qw@mail.gmail.com
Discussion: https://postgr.es/m/202512112014.icpomgc37zx4@alvherre.pgsql

2 weeks agoMSVC: Support building for AArch64.
Nathan Bossart [Wed, 7 Jan 2026 19:42:57 +0000 (13:42 -0600)]
MSVC: Support building for AArch64.

This commit does the following to get tests passing for
MSVC/AArch64:

* Implements spin_delay() with an ISB instruction (like we do for
gcc/clang on AArch64).

* Sets USE_ARMV8_CRC32C unconditionally.  Vendor-supported versions
of Windows for AArch64 require at least ARMv8.1, which is where CRC
extension support became mandatory.

* Implements S_UNLOCK() with _InterlockedExchange().  The existing
implementation for MSVC uses _ReadWriteBarrier() (a compiler
barrier), which is insufficient for this purpose on non-TSO
architectures.

There are likely other changes required to take full advantage of
the hardware (e.g., atomics/arch-arm.h, simd.h,
pg_popcount_aarch64.c), but those can be dealt with later.

Author: Niyas Sait <niyas.sait@linaro.org>
Co-authored-by: Greg Burd <greg@burd.me>
Co-authored-by: Dave Cramer <davecramer@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: John Naylor <johncnaylorls@gmail.com>
Reviewed-by: Peter Eisentraut <peter@eisentraut.org>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Thomas Munro <thomas.munro@gmail.com>
Tested-by: Andrew Dunstan <andrew@dunslane.net>
Discussion: https://postgr.es/m/A6152C7C-F5E3-4958-8F8E-7692D259FF2F%40greg.burd.me
Discussion: https://postgr.es/m/CAFPTBD-74%2BAEuN9n7caJ0YUnW5A0r-KBX8rYoEJWqFPgLKpzdg%40mail.gmail.com

2 weeks agoFix nbtree skip array transformation comments.
Peter Geoghegan [Wed, 7 Jan 2026 17:53:07 +0000 (12:53 -0500)]
Fix nbtree skip array transformation comments.

Fix comments that incorrectly described transformations performed by the
"Avoid extra index searches through preprocessing" mechanism introduced
by commit b3f1a13f.

Author: Yugo Nagata <nagata@sraoss.co.jp>
Reviewed-By: Chao Li <li.evan.chao@gmail.com>
Reviewed-By: Peter Geoghegan <pg@bowt.ie>
Discussion: https://postgr.es/m/20251230190145.c3c88c5eb0f88b136adda92f@sraoss.co.jp
Backpatch-through: 18

2 weeks agodoc: Remove deprecated clauses from CREATE USER/GROUP syntax synopsis.
Fujii Masao [Wed, 7 Jan 2026 16:10:36 +0000 (01:10 +0900)]
doc: Remove deprecated clauses from CREATE USER/GROUP syntax synopsis.

The USER and IN GROUP clauses of CREATE ROLE are deprecated, and
commit 8e78f0a1 removed them from the CREATE ROLE syntax syntax
synopsis in the docs. However, previously CREATE USER and
CREATE GROUP docs still listed these clauses.

Since CREATE USER is equivalent to CREATE ROLE ... WITH LOGIN and
CREATE GROUP is equivalent to CREATE ROLE, their documented syntax
synopsis should match CREATE ROLE to avoid confusion.

Therefore this commit removes the deprecated USER and IN GROUP
clauses from the CREATE USER and CREATE GROUP syntax synopsis
in the docs.

Author: Japin Li <japinli@hotmail.com>
Reviewed-by: wenhui qiu <qiuwenhuifx@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/MEAPR01MB3031C30E72EF16CFC08C8565B687A@MEAPR01MB3031.ausprd01.prod.outlook.com

2 weeks agoRevert "Use WAIT FOR LSN in PostgreSQL::Test::Cluster::wait_for_catchup()"
Alexander Korotkov [Wed, 7 Jan 2026 14:29:58 +0000 (16:29 +0200)]
Revert "Use WAIT FOR LSN in PostgreSQL::Test::Cluster::wait_for_catchup()"

This reverts commit f30848cb05d4d63e1a5a2d6a9d72604f3b63370d.  Due to
buildfarm failures related to recovery conflicts while executing the
WAIT FOR command.  It appears that WAIT FOR still holds xmin for a while.

Reported-by: Thomas Munro <thomas.munro@gmail.com>
Discussion: https://postgr.es/m/CA%2BhUKG%2BL0OQR8dQtsNBSaA3FNNyQeFabdeRVzurm0b7Xtp592g%40mail.gmail.com

2 weeks agoFix typo
Peter Eisentraut [Wed, 7 Jan 2026 14:47:02 +0000 (15:47 +0100)]
Fix typo

Reported-by: Xueyu Gao <gaoxueyu_hope@163.com>
Discussion: https://www.postgresql.org/message-id/42b5c99a.856d.19b73d858e2.Coremail.gaoxueyu_hope%40163.com

2 weeks agocreateuser: Update docs to reflect defaults
John Naylor [Wed, 7 Jan 2026 09:02:19 +0000 (16:02 +0700)]
createuser: Update docs to reflect defaults

Commit c7eab0e97 changed the default password_encryption setting to
'scram-sha-256', so update the example for creating a user with an
assigned password.

In addition, commit 08951a7c9 added new options that in turn pass
default tokens NOBYPASSRLS and NOREPLICATION to the CREATE ROLE
command, so fix this omission as well for v16 and later.

Reported-by: Heikki Linnakangas <hlinnaka@iki.fi>
Discussion: https://postgr.es/m/cff1ea60-c67d-4320-9e33-094637c2c4fb%40iki.fi
Backpatch-through: 14

2 weeks agoFix unexpected reversal of lists during catcache rehash
Michael Paquier [Wed, 7 Jan 2026 08:52:54 +0000 (17:52 +0900)]
Fix unexpected reversal of lists during catcache rehash

During catcache searches, the most-recently searched entries are kept at
the head of the list to speed up subsequent searches, keeping the
"freshest" entries at its beginning.  A rehash of the catcache was doing
the opposite: fresh entries were moved to the tail of the newly-created
buckets, causing a rehash to slow down a bit.

When a rehash is done, this commit switches the code to use
dlist_push_tail() instead of dlist_push_head(), so as fresh entries are
kept at the head of the lists, not their tail.

Author: ChangAo Chen <cca5507@qq.com>
Reviewed-by: John Naylor <johncnaylorls@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/tencent_9EA10D8512B5FE29E7323F780A0749768708@qq.com

2 weeks agoFix grammar in datatype.sgml
Michael Paquier [Wed, 7 Jan 2026 05:13:18 +0000 (14:13 +0900)]
Fix grammar in datatype.sgml

Introduced in b139bd3b6ef0.

Reported-by: Man Zeng <zengman@halodbtech.com>
Discussion: https://postgr.es/m/tencent_121C1BB152CAF3195C99D56C@qq.com

2 weeks agoFurther doc updates to reflect MD5 deprecation
John Naylor [Wed, 7 Jan 2026 04:55:01 +0000 (11:55 +0700)]
Further doc updates to reflect MD5 deprecation

Followup to 44f49511b.

Author: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Discussion: https://postgr.es/m/CAHGQGwH_UfN96vcvLGA%3DYro%2Bo6qCn0nEgEGoviwzEiLTHtt2Pw%40mail.gmail.com
Backpatch-through: 18

2 weeks agodoc: Add glossary and index entries for GUC.
Fujii Masao [Wed, 7 Jan 2026 04:58:07 +0000 (13:58 +0900)]
doc: Add glossary and index entries for GUC.

GUC is a commonly used term but previously appeared only
in the acronym documentation. This commit adds glossary and
documentation index entries for GUC to make it easier to find
and understand.

Author: Robert Treat <rob@xzilla.net>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/CABV9wwPQnkeo_G6-orMGnHPK9SXGVWm7ajJPzsbE6944tDx=hQ@mail.gmail.com

2 weeks agodoc: Add index entry for Git.
Fujii Masao [Wed, 7 Jan 2026 04:57:36 +0000 (13:57 +0900)]
doc: Add index entry for Git.

This commit adds Git to the documentation index, pointing to
the source code repository documentation.

Author: Robert Treat <rob@xzilla.net>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/CABV9wwPQnkeo_G6-orMGnHPK9SXGVWm7ajJPzsbE6944tDx=hQ@mail.gmail.com

2 weeks agoImprove portability of test with oid8 comparison function
Michael Paquier [Wed, 7 Jan 2026 03:55:16 +0000 (12:55 +0900)]
Improve portability of test with oid8 comparison function

Oversight in b139bd3b6ef0, per reports from buildfarm members longfin
and prion, that use -DSTRESS_SORT_INT_MIN.  Thanks to Tom Lane for the
poke.

Discussion: https://postgr.es/m/1656709.1767754981@sss.pgh.pa.us

2 weeks agoAdd data type oid8, 64-bit unsigned identifier
Michael Paquier [Wed, 7 Jan 2026 02:37:00 +0000 (11:37 +0900)]
Add data type oid8, 64-bit unsigned identifier

This new identifier type provides support for 64-bit unsigned values,
to be used in catalogs, like OIDs.  An advantage of a new data type is
that it becomes easier to grep for it in the code when assigning this
type to a catalog attribute, linking it to dedicated APIs and internal
structures.

The following operators are added in this commit, with dedicated tests:
- Casts with integer types and OID.
- btree and hash operators
- min/max functions.
- C type with related macros and defines, named around "Oid8".

This has been mentioned as useful on its own on the thread to add
support for 64-bit TOAST values, so as it becomes possible to attach
this data type to the TOAST code and catalog definitions.  However, as
this concept can apply to many more areas, it is implemented as its own
independent change.  This is based on a discussion with Andres Freund
and Tom Lane.

Bump catalog version.

Author: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Greg Burd <greg@burd.me>
Reviewed-by: Nikhil Kumar Veldanda <veldanda.nikhilkumar17@gmail.com>
Discussion: https://postgr.es/m/1891064.1754681536@sss.pgh.pa.us

2 weeks agoClean up ICU includes.
Jeff Davis [Wed, 7 Jan 2026 01:19:51 +0000 (17:19 -0800)]
Clean up ICU includes.

Remove ICU includes from pg_locale.h, and instead include them in the
few C files that need ICU. Clean up a few other includes in passing.

Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/48911db71d953edec66df0d2ce303563d631fbe0.camel@j-davis.com

2 weeks agoFix buggy interaction between array subscripts and subplan params
Andres Freund [Wed, 7 Jan 2026 00:51:10 +0000 (19:51 -0500)]
Fix buggy interaction between array subscripts and subplan params

In a7f107df2 I changed subplan param evaluation to happen within the
containing expression. As part of that, ExecInitSubPlanExpr() was changed to
evaluate parameters via a new EEOP_PARAM_SET expression step. These parameters
were temporarily stored into ExprState->resvalue/resnull, with some reasoning
why that would be fine. Unfortunately, that analysis was wrong -
ExecInitSubscriptionRef() evaluates the input array into "resv"/"resnull",
which will often point to ExprState->resvalue/resnull. This means that the
EEOP_PARAM_SET, if inside an array subscript, would overwrite the input array
to array subscript.

The fix is fairly simple - instead of evaluating into
ExprState->resvalue/resnull, store the temporary result of the subplan in the
subplan's return value.

Bug: #19370
Reported-by: Zepeng Zhang <redraiment@gmail.com>
Diagnosed-by: Tom Lane <tgl@sss.pgh.pa.us>
Diagnosed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/19370-7fb7a5854b7618f1@postgresql.org
Backpatch-through: 18

2 weeks agoICU: use UTF8-optimized case conversion API
Jeff Davis [Tue, 6 Jan 2026 22:09:07 +0000 (14:09 -0800)]
ICU: use UTF8-optimized case conversion API

Initializes a UCaseMap object once for use across calls, and uses
UTF8-optimized APIs.

Author: Andreas Karlsson <andreas@proxel.se>
Reviewed-by: zengman <zengman@halodbtech.com>
Discussion: https://postgr.es/m/5a010b27-8ed9-4739-86fe-1562b07ba564@proxel.se

2 weeks agoImprove portability of new worker_spi test
Michael Paquier [Tue, 6 Jan 2026 11:24:17 +0000 (20:24 +0900)]
Improve portability of new worker_spi test

The new test 002_worker_terminate relies on the generation of a LOG
entry to check that a worker has been started, but missed the fact that
a node set with log_error_verbosity = verbose would add an error code.
The regexp used for the matching check did not take this case into
account, making the test fail on a timeout.  The regexp is now fixed to
handle the verbose case correctly.

Per buildfarm member prion, that uses log_error_verbosity = verbose.
The error was reproducible by setting this GUC the same way in the test.

Oversight in f1e251be80a0.

2 weeks agoAdd test coverage for indirection transformation
Peter Eisentraut [Tue, 6 Jan 2026 08:37:19 +0000 (09:37 +0100)]
Add test coverage for indirection transformation

These tests cover nested arrays of composite data types,
single-argument functions, and casting using dot-notation, providing a
baseline for future enhancements to jsonb dot-notation support.

Author: Alexandra Wang <alexandra.wang.oss@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/CAK98qZ1JNNAx4QneJG+eX7iLesOhd6A68FNQVvvHP6Up_THf3A@mail.gmail.com

2 weeks agoFix variable usage in wakeupWaiters()
Alexander Korotkov [Tue, 6 Jan 2026 08:03:26 +0000 (10:03 +0200)]
Fix variable usage in wakeupWaiters()

Mistakenly, `i` was used both as an integer representation of lsnType and
an index in wakeUpProcs array.

Discussion: https://postgr.es/m/CA%2BhUKG%2BL0OQR8dQtsNBSaA3FNNyQeFabdeRVzurm0b7Xtp592g%40mail.gmail.com
Reviewed-by: Thomas Munro <thomas.munro@gmail.com>
Reviewed-by: Ruikai Peng <ruikai@pwno.io>
2 weeks agoUse relation_close() more consistently in contrib/
Michael Paquier [Tue, 6 Jan 2026 07:17:59 +0000 (16:17 +0900)]
Use relation_close() more consistently in contrib/

All the code paths updated here have been using index_close() to
close a relation that was opened with relation_open(), in pgstattuple
and pageinspect.  index_close() does the same thing as relation_close(),
so there is no harm, but being inconsistent could lead to issues if the
internals of these close() functions begin to introduce some specific
logic in the future.

In passing, this commit adds some comments explaining why we are using
relation_open() instead of index_open() in a few places, which is due to
the fact that partitioned indexes are not allowed in these functions.

Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Japin Li <japinli@hotmail.com>
Discussion: https://postgr.es/m/aUKamYGiDKO6byp5@ip-10-97-1-34.eu-west-3.compute.internal

2 weeks agoAllow bgworkers to be terminated for database-related commands
Michael Paquier [Tue, 6 Jan 2026 05:24:29 +0000 (14:24 +0900)]
Allow bgworkers to be terminated for database-related commands

Background workers gain a new flag, called BGWORKER_INTERRUPTIBLE, that
offers the possibility to terminate the workers when these are connected
to a database that is involved in one of the following commands:
ALTER DATABASE RENAME TO
ALTER DATABASE SET TABLESPACE
CREATE DATABASE
DROP DATABASE

This is useful to give background workers the same behavior as backends
and autovacuum workers, which are stopped when these commands are
executed.  The default behavior, that exists since 9.3, is still to
never terminate bgworkers connected to the database involved in any of
these commands.  The new flag has to be set to terminate the workers.

A couple of tests are added to worker_spi to track the commands that
impact the termination of the workers.  There is a test case for a
non-interruptible worker, additionally, that relies on an injection
point to make the wait time in CountOtherDBBackends() reduced from 5s to
0.3s for faster test runs.  The tests rely on the contents of the server
logs to check if a worker has been started or terminated:
- LOG generated by worker_spi_main() at startup, once connection to
database is done.
- FATAL in bgworker_die() when terminated.
A couple of tests run in the CI have showed that this method is stable
enough.  The safe_psql() calls that scan pg_stat_activity could be
replaced with some poll_query_until() for more stability, if the current
method proves to be an issue in the buildfarm.

Author: Aya Iwata <iwata.aya@fujitsu.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Ryo Matsumura <matsumura.ryo@fujitsu.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Peter Smith <smithpb2250@gmail.com>
Discussion: https://postgr.es/m/OS7PR01MB11964335F36BE41021B62EAE8EAE4A@OS7PR01MB11964.jpnprd01.prod.outlook.com

2 weeks agoUpdate comments atop ReplicationSlotCreate.
Amit Kapila [Tue, 6 Jan 2026 05:02:25 +0000 (05:02 +0000)]
Update comments atop ReplicationSlotCreate.

Since commit 1462aad2e4, which introduced the ability to modify the
two_phase property of a slot, the comments above ReplicationSlotCreate
have become outdated. We have now added a cautionary note in the comments
above ReplicationSlotAlter explaining when it is safe to modify the
two_phase property of a slot.

Author: Daniil Davydov <3danissimo@gmail.com>
Author: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Backpatch-through: 18
Discussion: https://postgr.es/m/CAJDiXggZXQZ7bD0QcTizDt6us9aX6ZKK4dWxzgb5x3+TsVHjqQ@mail.gmail.com

2 weeks agoFix issue with EVENT TRIGGERS and ALTER PUBLICATION
David Rowley [Tue, 6 Jan 2026 04:29:12 +0000 (17:29 +1300)]
Fix issue with EVENT TRIGGERS and ALTER PUBLICATION

When processing the "publish" options of an ALTER PUBLICATION command,
we call SplitIdentifierString() to split the options into a List of
strings.  Since SplitIdentifierString() modifies the delimiter
character and puts NULs in their place, this would overwrite the memory
of the AlterPublicationStmt.  Later in AlterPublicationOptions(), the
modified AlterPublicationStmt is copied for event triggers, which would
result in the event trigger only seeing the first "publish" option
rather than all options that were specified in the command.

To fix this, make a copy of the string before passing to
SplitIdentifierString().

Here we also adjust a similar case in the pgoutput plugin.  There's no
known issues caused by SplitIdentifierString() here, so this is being
done out of paranoia.

Thanks to Henson Choi for putting together an example case showing the
ALTER PUBLICATION issue.

Author: sunil s <sunilfeb26@gmail.com>
Reviewed-by: Henson Choi <assam258@gmail.com>
Reviewed-by: zengman <zengman@halodbtech.com>
Backpatch-through: 14

2 weeks agoFix typo in slot.c.
Amit Kapila [Tue, 6 Jan 2026 04:13:40 +0000 (04:13 +0000)]
Fix typo in slot.c.

Author: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/AC9B87F1-ED04-4547-B85C-9443B4253A08@gmail.com
Discussion: https://postgr.es/m/CAJDiXggZXQZ7bD0QcTizDt6us9aX6ZKK4dWxzgb5x3+TsVHjqQ@mail.gmail.com

2 weeks agoFix typo in planner.c
Michael Paquier [Tue, 6 Jan 2026 03:30:01 +0000 (12:30 +0900)]
Fix typo in planner.c

b8cfcb9e00da did not get this change right.

Author: Alexander Law <exclusion@gmail.com>
Discussion: https://postgr.es/m/CAJ0YPFFWhJXs-e-=7iJz-FLp=b1dXfJA_qtrVAgto=bZmzD9zQ@mail.gmail.com

2 weeks agoAdd TAP test for GUC settings passed via CONNECTION in logical replication.
Fujii Masao [Tue, 6 Jan 2026 02:57:12 +0000 (11:57 +0900)]
Add TAP test for GUC settings passed via CONNECTION in logical replication.

Commit d926462d819 restored the behavior of passing GUC settings from
the CONNECTION string to the publisher's walsender, allowing per-connection
configuration.

This commit adds a TAP test to verify that behavior works correctly.

Since commit d926462d819 was recently applied and backpatched to v15,
this follow-up commit is also backpatched accordingly.

Author: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Chao Li <lic@highgo.com>
Reviewed-by: Kirill Reshke <reshkekirill@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Japin Li <japinli@hotmail.com>
Discussion: https://postgr.es/m/CAHGQGwGYV+-abbKwdrM2UHUe-JYOFWmsrs6=QicyJO-j+-Widw@mail.gmail.com
Backpatch-through: 15

2 weeks agoHonor GUC settings specified in CREATE SUBSCRIPTION CONNECTION.
Fujii Masao [Tue, 6 Jan 2026 02:52:22 +0000 (11:52 +0900)]
Honor GUC settings specified in CREATE SUBSCRIPTION CONNECTION.

Prior to v15, GUC settings supplied in the CONNECTION clause of
CREATE SUBSCRIPTION were correctly passed through to
the publisher's walsender. For example:

        CREATE SUBSCRIPTION mysub
            CONNECTION 'options=''-c wal_sender_timeout=1000'''
            PUBLICATION ...

would cause wal_sender_timeout to take effect on the publisher's walsender.

However, commit f3d4019da5d changed the way logical replication
connections are established, forcing the publisher's relevant
GUC settings (datestyle, intervalstyle, extra_float_digits) to
override those provided in the CONNECTION string. As a result,
from v15 through v18, GUC settings in the CONNECTION string were
always ignored.

This regression prevented per-connection tuning of logical replication.
For example, using a shorter timeout for walsender connecting
to a nearby subscriber and a longer one for walsender connecting
to a remote subscriber.

This commit restores the intended behavior by ensuring that
GUC settings in the CONNECTION string are again passed through
and applied by the walsender, allowing per-connection configuration.

Backpatch to v15, where the regression was introduced.

Author: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Chao Li <lic@highgo.com>
Reviewed-by: Kirill Reshke <reshkekirill@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Japin Li <japinli@hotmail.com>
Discussion: https://postgr.es/m/CAHGQGwGYV+-abbKwdrM2UHUe-JYOFWmsrs6=QicyJO-j+-Widw@mail.gmail.com
Backpatch-through: 15

2 weeks agoSimplify GetOperatorFromCompareType() code
David Rowley [Tue, 6 Jan 2026 02:25:13 +0000 (15:25 +1300)]
Simplify GetOperatorFromCompareType() code

The old code would set *opid = InvalidOid to determine if the
get_opclass_opfamily_and_input_type() worked or not.  This means more
moving parts that what's really needed here.  Let's just fail
immediately if the get_opclass_opfamily_and_input_type() lookup fails.

Author: Paul A Jungwirth <pj@illuminatedcomputing.com>
Reviewed-by: Neil Chen <carpenter.nail.cz@gmail.com>
Discussion: https://postgr.es/m/CA+renyXOrjLacP_nhqEQUf2W+ZCoY2q5kpQCfG05vQVYzr8b9w@mail.gmail.com

2 weeks agoFix misleading comment for GetOperatorFromCompareType
David Rowley [Tue, 6 Jan 2026 02:16:14 +0000 (15:16 +1300)]
Fix misleading comment for GetOperatorFromCompareType

The comment claimed *strat got set to InvalidStrategy when the function
lookup fails.  This isn't true; an ERROR is raised when that happens.

Author: Paul A Jungwirth <pj@illuminatedcomputing.com>
Reviewed-by: Neil Chen <carpenter.nail.cz@gmail.com>
Discussion: https://postgr.es/m/CA+renyXOrjLacP_nhqEQUf2W+ZCoY2q5kpQCfG05vQVYzr8b9w@mail.gmail.com
Backpatch-through: 18

2 weeks agodoc: Fix outdated doc in pg_rewind.
Fujii Masao [Tue, 6 Jan 2026 02:00:54 +0000 (11:00 +0900)]
doc: Fix outdated doc in pg_rewind.

Update pg_rewind documentation to reflect the change that data checksums are
now enabled by default during initdb.

Backpatch to v18, where data checksums were changed to be enabled by default.

Author: Zhijie Hou <houzj.fnst@fujitsu.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/TY4PR01MB16907D62F3A0A377B30FDBEA794B2A@TY4PR01MB16907.jpnprd01.prod.outlook.com
Backpatch-through: 18

2 weeks agoClarify where various catcache.h dlist_nodes are used
David Rowley [Tue, 6 Jan 2026 01:39:36 +0000 (14:39 +1300)]
Clarify where various catcache.h dlist_nodes are used

Also remove a comment which mentions we don't currently divide the
per-cache lists into hash buckets.  Since 473182c95, we do.

Author: ChangAo Chen <cca5507@qq.com>
Discussion: https://postgr.es/m/tencent_7732789707C8768EA13785A7B5EA29103208@qq.com

2 weeks agopg_visibility: Fix incorrect buffer lock description in comment.
Masahiko Sawada [Mon, 5 Jan 2026 23:49:43 +0000 (15:49 -0800)]
pg_visibility: Fix incorrect buffer lock description in comment.

Although the comment in collect_corrupt_items() stated that the buffer
is locked in exclusive mode, it is actually locked in shared mode.

Author: Chao Li <lic@highgo.com>
Discussion: https://postgr.es/m/CAEoWx2kkhxgfp=kinPMetnwHaa0JjR6YBkO_0gg0oiy6mu7Zjw@mail.gmail.com

2 weeks agoFix meson build of snowball code.
Tom Lane [Mon, 5 Jan 2026 21:51:36 +0000 (16:51 -0500)]
Fix meson build of snowball code.

include/snowball/libstemmer has to be in the -I search path,
as it is in the autoconf build.  It's not apparent to me how
this ever worked before, nor why my recent commit made it
stop working.

Discussion: https://postgr.es/m/ld2iurl7kzexwydxmdfhdgarpa7xxsfrgvggqhbblt4rvt3h6t@bxsk6oz5x7cc

3 weeks agoUpdate to latest Snowball sources.
Tom Lane [Mon, 5 Jan 2026 20:22:12 +0000 (15:22 -0500)]
Update to latest Snowball sources.

It's been almost a year since we last did this, and upstream has
been busy.  They've added stemmers for Polish and Esperanto,
and also deprecated their old Dutch stemmer in favor of the
Kraaij-Pohlmann algorithm.  (The "dutch" stemmer is now the
latter, and "dutch_porter" is the old algorithm.)

Upstream also decided to rename their internal header "header.h"
to something less generic: "snowball_runtime.h".  Seems like a good
thing, but it complicates this patch a bit because we were relying on
interposing our own version of "header.h" to control system header
inclusion order.  (We're partially failing at that now, because now the
generated stemmer files include <stddef.h> before snowball_runtime.h.
I think that'll be okay, but if the buildfarm complains then we'll
have to do more-extensive editing of the generated files.)

I realized that we weren't documenting the available stemmers in
any user-visible place, except indirectly through sample \dFd output.
That's incomplete because we only provide built-in dictionaries for
the recommended stemmers for each language, not alternative stemmers
such as dutch_porter.  So I added a list to the documentation.

I did not do anything with the stopword lists.  If those are still
available from snowballstem.org, they are mighty well hidden.

Discussion: https://postgr.es/m/1185975.1767569534@sss.pgh.pa.us

3 weeks agoci: Remove ulimit -p for netbsd/openbsd
Andres Freund [Mon, 5 Jan 2026 18:09:03 +0000 (13:09 -0500)]
ci: Remove ulimit -p for netbsd/openbsd

Previously the ulimit -p 256 was needed to increase the limit on
openbsd. However, sometimes the limit actually was too low, causing
  "could not fork new process for connection: Resource temporarily unavailable"
errors.  Most commonly on netbsd, but also on openbsd.

The ulimit on openbsd couldn't trivially be increased with ulimit, because of
hitting the hard limit.

Instead of increasing the limit in the CI script, the CI image generation now
increases the limits: https://github.com/anarazel/pg-vm-images/pull/129

Backpatch-through: 18

3 weeks agoFix typo in parallel.c.
Masahiko Sawada [Mon, 5 Jan 2026 18:16:28 +0000 (10:16 -0800)]
Fix typo in parallel.c.

Author: kelan <ke_lan1@qq.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Discussion: https://postgr.es/m/tencent_38B5875E2D440C8DA8C0C022ABD999F9C207@qq.com

3 weeks agoUse WAIT FOR LSN in PostgreSQL::Test::Cluster::wait_for_catchup()
Alexander Korotkov [Mon, 5 Jan 2026 17:41:31 +0000 (19:41 +0200)]
Use WAIT FOR LSN in PostgreSQL::Test::Cluster::wait_for_catchup()

When the standby is passed as a PostgreSQL::Test::Cluster instance,
use the WAIT FOR LSN command on the standby server to implement
wait_for_catchup() for replay, write, and flush modes.  This is more
efficient than polling pg_stat_replication on the upstream, as the
WAIT FOR LSN command uses a latch-based wakeup mechanism.

The optimization applies when:
- The standby is passed as a Cluster object (not just a name string)
- The mode is 'replay', 'write', or 'flush' (not 'sent')
- The standby is in recovery

For 'sent' mode, when the standby is passed as a string (e.g., a
subscription name for logical replication), or when the standby has
been promoted, the function falls back to the original polling-based
approach using pg_stat_replication on the upstream.

Discussion: https://postgr.es/m/CABPTF7UiArgW-sXj9CNwRzUhYOQrevLzkYcgBydmX5oDes1sjg%40mail.gmail.com
Author: Xuneng Zhou <xunengzhou@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Alvaro Herrera <alvherre@kurilemu.de>
3 weeks agoAdd tab completion for the WAIT FOR LSN MODE option
Alexander Korotkov [Mon, 5 Jan 2026 17:41:09 +0000 (19:41 +0200)]
Add tab completion for the WAIT FOR LSN MODE option

Update psql tab completion to support the optional MODE option in the
WAIT FOR LSN command.  After specifying an LSN value, completion now offers
both MODE and WITH keywords.  The MODE option specifies which LSN type to wait
for.  In particular, it controls whether the wait is evaluated from the
standby or primary perspective.

When MODE is specified, the completion suggests the valid mode values:
standby_replay, standby_write, standby_flush, and primary_flush.

Discussion: https://postgr.es/m/CABPTF7UiArgW-sXj9CNwRzUhYOQrevLzkYcgBydmX5oDes1sjg%40mail.gmail.com
Author: Xuneng Zhou <xunengzhou@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Alvaro Herrera <alvherre@kurilemu.de>
3 weeks agoAdd the MODE option to the WAIT FOR LSN command
Alexander Korotkov [Mon, 5 Jan 2026 17:40:44 +0000 (19:40 +0200)]
Add the MODE option to the WAIT FOR LSN command

This commit extends the WAIT FOR LSN command with an optional MODE option in
the WITH clause that specifies which LSN type to wait for:

  WAIT FOR LSN '<lsn>' [WITH (MODE '<mode>', ...)]

where mode can be:
 - 'standby_replay' (default): Wait for WAL to be replayed to the specified
   LSN,
 - 'standby_write': Wait for WAL to be written (received) to the specified
   LSN,
 - 'standby_flush': Wait for WAL to be flushed to disk at the specified LSN,
 - 'primary_flush': Wait for WAL to be flushed to disk on the primary server.

The default mode is 'standby_replay', matching the original behavior when MODE
is not specified. This follows the pattern used by COPY and EXPLAIN
commands, where options are specified as string values in the WITH clause.

Modes are explicitly named to distinguish between primary and standby
operations:
- Standby modes ('standby_replay', 'standby_write', 'standby_flush') can only
  be used during recovery (on a standby server),
- Primary mode ('primary_flush') can only be used on a primary server.

The 'standby_write' and 'standby_flush' modes are useful for scenarios where
applications need to ensure WAL has been received or persisted on the standby
without necessarily waiting for replay to complete. The 'primary_flush' mode
allows waiting for WAL to be flushed on the primary server.

This commit also includes includes:
- Documentation updates for the new syntax and mode descriptions,
- Test coverage for all four modes, including error cases and concurrent
  waiters,
- Wakeup logic in walreceiver for standby write/flush waiters,
- Wakeup logic in WAL writer for primary flush waiters.

Discussion: https://postgr.es/m/CABPTF7UiArgW-sXj9CNwRzUhYOQrevLzkYcgBydmX5oDes1sjg%40mail.gmail.com
Author: Xuneng Zhou <xunengzhou@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Alvaro Herrera <alvherre@kurilemu.de>
3 weeks agoExtend xlogwait infrastructure with write and flush wait types
Alexander Korotkov [Mon, 5 Jan 2026 17:40:31 +0000 (19:40 +0200)]
Extend xlogwait infrastructure with write and flush wait types

Add support for waiting on WAL write and flush LSNs in addition to the
existing replay LSN wait type. This provides the foundation for
extending the WAIT FOR command with MODE parameter.

Key changes are following.
- Add WAIT_LSN_TYPE_STANDBY_WRITE and WAIT_LSN_TYPE_STANDBY_FLUSH to
  WaitLSNType.
- Add GetCurrentLSNForWaitType() to retrieve the current LSN for each wait
  type.
- Add new wait events WAIT_EVENT_WAIT_FOR_WAL_WRITE and
  WAIT_EVENT_WAIT_FOR_WAL_FLUSH for pg_stat_activity visibility.
- Update WaitForLSN() to use GetCurrentLSNForWaitType() internally.

Discussion: https://postgr.es/m/CABPTF7UiArgW-sXj9CNwRzUhYOQrevLzkYcgBydmX5oDes1sjg%40mail.gmail.com
Author: Xuneng Zhou <xunengzhou@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Alvaro Herrera <alvherre@kurilemu.de>
3 weeks agoAdjust errcode in checkPartition()
Alexander Korotkov [Mon, 5 Jan 2026 17:38:03 +0000 (19:38 +0200)]
Adjust errcode in checkPartition()

Replace ERRCODE_UNDEFINED_TABLE with ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE
for the case where we don't find a parent-child relationship between the
partitioned table and its partition.  In this case, tables are present, but
they are not in a prerequisite state (no relationship).

Discussion: https://postgr.es/m/CAHewXNmBM%2B5qbrJMu60NxPn%2B0y-%3D2wXM-QVVs3xRp8NxFvDb9A%40mail.gmail.com
Author: Tender Wang <tndrwang@gmail.com>
Reviewed-by: Kirill Reshke <reshkekirill@gmail.com>
3 weeks agoRemove redundant SET enable_partitionwise_join = on.
Robert Haas [Mon, 5 Jan 2026 16:57:24 +0000 (11:57 -0500)]
Remove redundant SET enable_partitionwise_join = on.

partition_join.sql keeps partitionwise join enabled for the entire file,
so we don't need to enable it for this test case individually.

Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Discussion: http://postgr.es/m/CAExHW5uRW=Z==bmLR=NXm6Vv3JGH4rUvb+Rfft8TfjrfzUUm3g@mail.gmail.com

3 weeks agoFix comment in tableam.c
Michael Paquier [Mon, 5 Jan 2026 10:15:55 +0000 (19:15 +0900)]
Fix comment in tableam.c

Author: shiyu qin <qinshy510@gmail.com>
Discussion: https://postgr.es/m/CAJUCM3uJjoLR1zfKoZD4J71T-hdeFdFw1kTQoMkywKZP0hZsvw@mail.gmail.com

3 weeks agoSeparate read and write pointers in pg_saslprep
Peter Eisentraut [Mon, 5 Jan 2026 09:50:27 +0000 (10:50 +0100)]
Separate read and write pointers in pg_saslprep

Use separate pointers for reading const input ('p') and writing to
mutable output ('outp'), avoiding the need to cast away const on the
input parameter.

Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Discussion: https://postgr.es/m/aUQHy/MmWq7c97wK%40ip-10-97-1-34.eu-west-3.compute.internal

3 weeks agoTighten up assertion on a local variable
Heikki Linnakangas [Mon, 5 Jan 2026 09:33:35 +0000 (11:33 +0200)]
Tighten up assertion on a local variable

'lineindex' is 0-based, as mentioned in the comments.

Backpatch to v18 where the assertion was added.

Author: ChangAo Chen <cca5507@qq.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://www.postgresql.org/message-id/tencent_A84F3C810365BB9BD08442955AE494141907@qq.com
Backpatch-through: 18

3 weeks agoUse the GetPGProcByNumber() macro when possible
David Rowley [Mon, 5 Jan 2026 08:19:03 +0000 (21:19 +1300)]
Use the GetPGProcByNumber() macro when possible

A few places were accessing &ProcGlobal->allProcs directly, so adjust
them to use the accessor macro instead.

Author: Maksim Melnikov <m.melnikov@postgrespro.ru>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/80621c00-aba6-483c-88b1-a845461d1165@postgrespro.ru

3 weeks agoImprove the comments atop build_replindex_scan_key().
Amit Kapila [Mon, 5 Jan 2026 03:06:55 +0000 (03:06 +0000)]
Improve the comments atop build_replindex_scan_key().

Author: zourenli <398740848@qq.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/tencent_C2DC8157CC05C8F5C36E12678A7864554809@qq.com

3 weeks agoRemove unneeded probes from configure and meson
Michael Paquier [Mon, 5 Jan 2026 02:03:43 +0000 (11:03 +0900)]
Remove unneeded probes from configure and meson

7d854bdc5b72 has removed two symbols from pg_config.h.in.  This file is
automatically generated.  The correct cleanup needs to be done in the
build scripts, instead.  autoheader produces now a consistent
pg_config.h.in, without the symbols that were removed in the previous
commit.

Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/1193764.1767573683@sss.pgh.pa.us

3 weeks agoRemove unneeded defines from pg_config.h.in
Michael Paquier [Mon, 5 Jan 2026 00:27:19 +0000 (09:27 +0900)]
Remove unneeded defines from pg_config.h.in

This commit removes HAVE_ATOMIC_H and HAVE_MBARRIER_H from
pg_config.h.in, cleanup that could have been done in 25f36066dd2a.

Author: Alexander Lakhin <exclusion@gmail.com>
Discussion: https://postgr.es/m/b2c0d0b7-3944-487d-a03d-d155851958ff@gmail.com

3 weeks agoFix typos and inconsistencies in code and comments
Michael Paquier [Mon, 5 Jan 2026 00:19:15 +0000 (09:19 +0900)]
Fix typos and inconsistencies in code and comments

This change is a cocktail of harmonization of function argument names,
grammar typos, renames for better consistency and unused code (see
ltree).  All of these have been spotted by the author.

Author: Alexander Lakhin <exclusion@gmail.com>
Discussion: https://postgr.es/m/b2c0d0b7-3944-487d-a03d-d155851958ff@gmail.com

3 weeks agoAllow role created by new test to log in on Windows.
Tom Lane [Sun, 4 Jan 2026 23:14:02 +0000 (18:14 -0500)]
Allow role created by new test to log in on Windows.

We must tell init about each role name we plan to connect as,
else SSPI auth fails.  Similar to previous patches such as
da44d71e7.

Oversight in f3c9e341c, per buildfarm member drongo.

3 weeks agoInclude error location in errors from ComputeIndexAttrs().
Tom Lane [Sun, 4 Jan 2026 19:16:15 +0000 (14:16 -0500)]
Include error location in errors from ComputeIndexAttrs().

Make use of IndexElem's new location field to localize these
errors better.

Author: jian he <jian.universality@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CACJufxH3OgXF1hrzGAaWyNtye2jHEmk9JbtrtGv-KJK6tsGo5w@mail.gmail.com

3 weeks agoAdd parse location to IndexElem.
Tom Lane [Sun, 4 Jan 2026 18:23:26 +0000 (13:23 -0500)]
Add parse location to IndexElem.

This patch mostly just fills in the field, although a few error
reports in resolve_unique_index_expr() are adjusted to use it.
The next commit will add more uses.

catversion bump out of an abundance of caution: I'm not sure
IndexElem can appear in stored rules, but I'm not sure it can't
either.

Author: Álvaro Herrera <alvherre@kurilemu.de>
Co-authored-by: jian he <jian.universality@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CACJufxH3OgXF1hrzGAaWyNtye2jHEmk9JbtrtGv-KJK6tsGo5w@mail.gmail.com
Discussion: https://postgr.es/m/202512121327.f2zimsr6guso@alvherre.pgsql

3 weeks agoFix partial read handling in pg_upgrade's multixact conversion
Heikki Linnakangas [Sun, 4 Jan 2026 18:04:36 +0000 (20:04 +0200)]
Fix partial read handling in pg_upgrade's multixact conversion

Author: Man Zeng <zengman@halodbtech.com>
Discussion: https://www.postgresql.org/message-id/tencent_566562B52163DB1502F4F7A4@qq.com

3 weeks agoRemove bogus const qualifier on PageGetItem() argument
Peter Eisentraut [Sun, 4 Jan 2026 15:00:15 +0000 (16:00 +0100)]
Remove bogus const qualifier on PageGetItem() argument

The function ends up casting away the const qualifier, so it was a
lie.  No callers appear to rely on the const qualifier on the
argument, so the simplest solution is to just remove it.

Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://www.postgresql.org/message-id/beusplf77varvhip6ryuhd2fchsx26qmmhduqz432bnglq634b%402dx4k6yxj4cm

3 weeks agoDoc: add missing punctuation
David Rowley [Sun, 4 Jan 2026 08:12:23 +0000 (21:12 +1300)]
Doc: add missing punctuation

Author: Daisuke Higuchi <higuchi.daisuke11@gmail.com>
Reviewed-by: Robert Treat <rob@xzilla.net>
Discussion: https://postgr.es/m/CAEVT6c-yWYstu76YZ7VOxmij2XA8vrOEvens08QLmKHTDjEPBw@mail.gmail.com
Backpatch-through: 14

3 weeks agoFix selectivity estimation integer overflow in contrib/intarray
David Rowley [Sun, 4 Jan 2026 07:32:40 +0000 (20:32 +1300)]
Fix selectivity estimation integer overflow in contrib/intarray

This fixes a poorly written integer comparison function which was
performing subtraction in an attempt to return a negative value when
a < b and a positive value when a > b, and 0 when the values were equal.
Unfortunately that didn't always work correctly due to two's complement
having the INT_MIN 1 further from zero than INT_MAX.  This could result
in an overflow and cause the comparison function to return an incorrect
result, which would result in the binary search failing to find the
value being searched for.

This could cause poor selectivity estimates when the statistics stored
the value of INT_MAX (2147483647) and the value being searched for was
large enough to result in the binary search doing a comparison with that
INT_MAX value.

Author: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/CAEoWx2ng1Ot5LoKbVU-Dh---dFTUZWJRH8wv2chBu29fnNDMaQ@mail.gmail.com
Backpatch-through: 14

3 weeks agoImprove a couple of error messages.
Tom Lane [Sat, 3 Jan 2026 22:18:39 +0000 (17:18 -0500)]
Improve a couple of error messages.

Change "function" to "function or procedure" in
PreventInTransactionBlock, and improve grammar of ExecWaitStmt's
complaint about having an active snapshot.

Author: Pavel Stehule <pavel.stehule@gmail.com>
Reviewed-by: Andreas Karlsson <andreas@proxel.se>
Reviewed-by: Marcos Pegoraro <marcos@f10.com.br>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAFj8pRCveWPR06bbad9GnMb0Kcr6jnXPttv9XOaOB+oFCD1Tsg@mail.gmail.com

3 weeks agoFix spelling mistake in fk-snapshot-3.spec
David Rowley [Fri, 2 Jan 2026 04:53:07 +0000 (17:53 +1300)]
Fix spelling mistake in fk-snapshot-3.spec

Author: Aditya Gollamudi <adigollamudi@gmail.com>
Discussion: https://postgr.es/m/CAD-KL_EdOOWp_cmPk9%3D5vNxo%2BabTTRpNx4vex-gVUm8u3GnkTg%40mail.gmail.com

3 weeks agoUpdate copyright for 2026
Bruce Momjian [Thu, 1 Jan 2026 18:24:10 +0000 (13:24 -0500)]
Update copyright for 2026

Backpatch-through: 14

3 weeks agoAdd paths of extensions to pg_available_extensions
Andrew Dunstan [Thu, 1 Jan 2026 17:11:37 +0000 (12:11 -0500)]
Add paths of extensions to pg_available_extensions

Add a new "location" column to the pg_available_extensions and
pg_available_extension_versions views, exposing the directory where
the extension is located.

The default system location is shown as '$system', the same value
that can be used to configure the extension_control_path GUC.

User-defined locations are only visible for super users, otherwise
'<insufficient privilege>' is returned as a column value, the same
behaviour that we already use in pg_stat_activity.

I failed to resist the temptation to do a little extra editorializing of
the TAP test script.

Catalog version bumped.

Author: Matheus Alcantara <mths.dev@pm.me>
Reviewed-By: Chao Li <li.evan.chao@gmail.com>
Reviewed-By: Rohit Prasad <rohit.prasad@arm.com>
Reviewed-By: Michael Banck <mbanck@gmx.net>
Reviewed-By: Manni Wood <manni.wood@enterprisedb.com>
Reviewed-By: Euler Taveira <euler@eulerto.com>
Reviewed-By: Quan Zongliang <quanzongliang@yeah.net>
3 weeks agoFix macro name for io_uring_queue_init_mem check.
Masahiko Sawada [Wed, 31 Dec 2025 19:18:14 +0000 (11:18 -0800)]
Fix macro name for io_uring_queue_init_mem check.

Commit f54af9f2679d added a check for
io_uring_queue_init_mem(). However, it used the macro name
HAVE_LIBURING_QUEUE_INIT_MEM in both meson.build and the C code, while
the Autotools build script defined HAVE_IO_URING_QUEUE_INIT_MEM. As a
result, the optimization was never enabled in builds configured with
Autotools, as the C code checked for the wrong macro name.

This commit changes the macro name to HAVE_IO_URING_QUEUE_INIT_MEM in
meson.build and the C code. This matches the actual function
name (io_uring_queue_init_mem), following the standard HAVE_<FUNCTION>
convention.

Backpatch to 18, where the macro was introduced.

Bug: #19368
Reported-by: Evan Si <evsi@amazon.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/19368-016d79a7f3a1c599@postgresql.org
Backpatch-through: 18

3 weeks agoDoc: remove obsolete, confused <note> about rowtype I/O syntax.
Tom Lane [Wed, 31 Dec 2025 18:19:27 +0000 (13:19 -0500)]
Doc: remove obsolete, confused <note> about rowtype I/O syntax.

This <note> was originally written to describe the double levels
of de-backslashing encountered when a backslash-aware string
literal is used to hold the text representation of a composite
value.  It still made sense when we switched to mostly using E'...'
syntax for that type of literal.  However, commit f77de4b0c mangled
it completely by changing the example literal to be SQL-standard.
The extra pass of de-backslashing described in the text doesn't
actually occur with the example as written, unless you happen to
be using standard_conforming_strings = off.

We could restore this <note> to self-consistency by reverting the
change from f77de4b0c, but on the whole I judge that its time has
passed.  standard_conforming_strings = off is nearly obsolete,
and may soon be fully so.  But without that, the behavior isn't
so complicated as to justify a discursive note.  I observe that
the nearby section about array I/O syntax has no equivalent text,
although that syntax is equally subject to this issue.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/2998401.1767038920@sss.pgh.pa.us
Discussion: https://postgr.es/m/3279216.1767072538@sss.pgh.pa.us

3 weeks agojit: Fix jit_profiling_support when unavailable.
Thomas Munro [Wed, 31 Dec 2025 00:24:17 +0000 (13:24 +1300)]
jit: Fix jit_profiling_support when unavailable.

jit_profiling_support=true captures profile data for Linux perf.  On
other platforms, LLVMCreatePerfJITEventListener() returns NULL and the
attempt to register the listener would crash.

Fix by ignoring the setting in that case.  The documentation already
says that it only has an effect if perf support is present, and we
already did the same for older LLVM versions that lacked support.

No field reports, unsurprisingly for an obscure developer-oriented
setting.  Noticed in passing while working on commit 1a28b4b4.

Backpatch-through: 14
Reviewed-by: Matheus Alcantara <matheusssilv97@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/CA%2BhUKGJgB6gvrdDohgwLfCwzVQm%3DVMtb9m0vzQn%3DCwWn-kwG9w%40mail.gmail.com

3 weeks agoChange IndexAmRoutines to be statically-allocated structs.
Tom Lane [Tue, 30 Dec 2025 23:26:23 +0000 (18:26 -0500)]
Change IndexAmRoutines to be statically-allocated structs.

Up to now, index amhandlers were expected to produce a new, palloc'd
struct on each call.  That requires palloc/pfree overhead, and creates
a risk of memory leaks if the caller fails to pfree, and the time
taken to fill such a large structure isn't nil.  Moreover, we were
storing these things in the relcache, eating several hundred bytes for
each cached index.  There is not anything in these structs that needs
to vary at runtime, so let's change the definition so that an
amhandler can return a pointer to a "static const" struct of which
there's only one copy per index AM.  Mark all the core code's
IndexAmRoutine pointers const so that we catch anyplace that might
still try to change or pfree one.

(This is similar to the way we were already handling TableAmRoutine
structs.  This commit does fix one comment that was infelicitously
copied-and-pasted into tableamapi.c.)

This commit needs to be called out in the v19 release notes as an API
change for extension index AMs.  An un-updated AM will still work
(as of now, anyway) but it risks memory leaks and will be slower than
necessary.

Author: Matthias van de Meent <boekewurm+postgres@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAEoWx2=vApYk2LRu8R0DdahsPNEhWUxGBZ=rbZo1EXE=uA+opQ@mail.gmail.com

3 weeks agoAdd dead items memory usage to VACUUM (VERBOSE) and autovacuum logs.
Masahiko Sawada [Tue, 30 Dec 2025 21:12:10 +0000 (13:12 -0800)]
Add dead items memory usage to VACUUM (VERBOSE) and autovacuum logs.

This commit adds the total memory allocated during vacuum, the number
of times the dead items storage was reset, and the configured memory
limit. This helps users understand how much memory VACUUM required,
and such information can be used to avoid multiple index scans.

Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/CAHza6qcPitBCkyiKJosDTt3bmxMvzZOTONoebwCkBZrr3rk65Q%40mail.gmail.com

3 weeks agoFix a race condition in updating procArray->replication_slot_xmin.
Masahiko Sawada [Tue, 30 Dec 2025 18:56:30 +0000 (10:56 -0800)]
Fix a race condition in updating procArray->replication_slot_xmin.

Previously, ReplicationSlotsComputeRequiredXmin() computed the oldest
xmin across all slots without holding ProcArrayLock (when
already_locked is false), acquiring the lock just before updating the
replication slot xmin.

This could lead to a race condition: if a backend created a new slot
and updates the global replication slot xmin, another backend
concurrently running ReplicationSlotsComputeRequiredXmin() could
overwrite that update with an invalid or stale value. This happens
because the concurrent backend might have computed the aggregate xmin
before the new slot was accounted for, but applied the update after
the new slot had already updated the global value.

In the reported failure, a walsender for an apply worker computed
InvalidTransactionId as the oldest xmin and overwrote a valid
replication slot xmin value computed by a walsender for a tablesync
worker. Consequently, the tablesync worker computed a transaction ID
via GetOldestSafeDecodingTransactionId() effectively without
considering the replication slot xmin. This led to the error "cannot
build an initial slot snapshot as oldest safe xid %u follows
snapshot's xmin %u", which was an assertion failure prior to commit
240e0dbacd3.

To fix this, we acquire ReplicationSlotControlLock in exclusive mode
during slot creation to perform the initial update of the slot
xmin. In ReplicationSlotsComputeRequiredXmin(), we hold
ReplicationSlotControlLock in shared mode until the global slot xmin
is updated in ProcArraySetReplicationSlotXmin(). This prevents
concurrent computations and updates of the global xmin by other
backends during the initial slot xmin update process, while still
permitting concurrent calls to ReplicationSlotsComputeRequiredXmin().

Backpatch to all supported versions.

Author: Zhijie Hou <houzj.fnst@fujitsu.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Pradeep Kumar <spradeepkumar29@gmail.com>
Reviewed-by: Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/CAA4eK1L8wYcyTPxNzPGkhuO52WBGoOZbT0A73Le=ZUWYAYmdfw@mail.gmail.com
Backpatch-through: 14

3 weeks agoFix comment in lsyscache.c
Michael Paquier [Tue, 30 Dec 2025 07:42:21 +0000 (16:42 +0900)]
Fix comment in lsyscache.c

Author: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/CAEoWx2miv0KGcM9j29ANRN45-Vz-2qAqrM0cv9OtaLx8e_WCMQ@mail.gmail.com

3 weeks agojit: Drop redundant LLVM configure probes.
Thomas Munro [Tue, 30 Dec 2025 03:39:19 +0000 (16:39 +1300)]
jit: Drop redundant LLVM configure probes.

We currently require LLVM 14, so these probes for LLVM 9 functions
always succeeded.  Even when the features aren't enabled in an LLVM
build, dummy functions are defined (a problem for a later commit).

The whole PGAC_CHECK_LLVM_FUNCTIONS macro and Meson equivalent are
removed, because we switched to testing LLVM_VERSION_MAJOR at compile
time in subsequent work and these were the last holdouts.  That suits
the nature of LLVM API evolution better, and also allows for strictly
mechanical pruning in future commits like 820b5af7 and 972c2cd2.  They
advanced the minimum LLVM version but failed to spot these.

Reviewed-by: Matheus Alcantara <matheusssilv97@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/CA%2BhUKGJgB6gvrdDohgwLfCwzVQm%3DVMtb9m0vzQn%3DCwWn-kwG9w%40mail.gmail.com

3 weeks agoAdd pg_get_multixact_stats()
Michael Paquier [Tue, 30 Dec 2025 06:38:50 +0000 (15:38 +0900)]
Add pg_get_multixact_stats()

This new function exposes at SQL level some information related to
multixacts, not available until now.  This data is useful for monitoring
purposes, especially for workloads that make a heavy use of multixacts:
- num_mxids, number of MultiXact IDs in use.
- num_members, number of member entries in use.
- members_size, bytes used by num_members in pg_multixact/members/.
- oldest_multixact: oldest MultiXact still needed.

This patch has been originally proposed when MultiXactOffset was still
32 bits, to monitor wraparound.  This part is not relevant anymore since
bd8d9c9bdfa0 that has widen MultiXactOffset to 64 bits.  The monitoring
of disk space usage for the members is still relevant.

Some tests are added to check this function, in the shape of one
isolation test with concurrent transactions that take a ROW SHARE lock,
and some SQL tests for pg_read_all_stats.  Some documentation is added
to explain some patterns that can come from the information provided by
the function.

Bump catalog version.

Author: Naga Appani <nagnrik@gmail.com>
Reviewed-by: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Atsushi Torikoshi <torikoshia@oss.nttdata.com>
Discussion: https://postgr.es/m/CA+QeY+AAsYK6WvBW4qYzHz4bahHycDAY_q5ECmHkEV_eB9ckzg@mail.gmail.com

3 weeks agoAdd MultiXactOffsetStorageSize() to multixact_internal.h
Michael Paquier [Tue, 30 Dec 2025 05:13:40 +0000 (14:13 +0900)]
Add MultiXactOffsetStorageSize() to multixact_internal.h

This function calculates in bytes the storage taken between two
multixact offsets.  This will be used in an upcoming patch, introduced
separately here as this piece can be useful on its own.

Author: Naga Appani <nagnrik@gmail.com>
Co-authored-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/aUyTvZMq2CLgNEB4@paquier.xyz

3 weeks agoChange GetMultiXactInfo() to return the next multixact offset
Michael Paquier [Tue, 30 Dec 2025 05:03:49 +0000 (14:03 +0900)]
Change GetMultiXactInfo() to return the next multixact offset

This routine returned a number of members as a MultiXactOffset,
calculated based on the difference between the next-to-be-assigned
offset and the oldest offset.  However, this number is not actually an
offset but a number.

This type confusion comes from the original implementation of
MultiXactMemberFreezeThreshold(), in 53bb309d2d5a.  The number of
members is now defined as a uint64, large enough for MultiXactOffset.
This change will be used in a follow-up patch.

Reviewed-by: Naga Appani <nagnrik@gmail.com>
Discussion: https://postgr.es/m/aUyTvZMq2CLgNEB4@paquier.xyz

3 weeks agojit: Remove -Wno-deprecated-declarations in 18+.
Thomas Munro [Tue, 30 Dec 2025 01:11:37 +0000 (14:11 +1300)]
jit: Remove -Wno-deprecated-declarations in 18+.

REL_18_STABLE and master have commit ee485912, so they always use the
newer LLVM opaque pointer functions.  Drop -Wno-deprecated-declarations
(commit a56e7b660) for code under jit/llvm in those branches, to catch
any new deprecation warnings that arrive in future version of LLVM.

Older branches continued to use functions marked deprecated in LLVM 14
and 15 (ie switched to the newer functions only for LLVM 16+), as a
precaution against unforeseen compatibility problems with bitcode
already shipped.  In those branches, the comment about warning
suppression is updated to explain that situation better.  In theory we
could suppress warnings only for LLVM 14 and 15 specifically, but that
isn't done here.

Backpatch-through: 14
Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/1407185.1766682319%40sss.pgh.pa.us

4 weeks agoEnsure sanity of hash-join costing when there are no MCV statistics.
Tom Lane [Mon, 29 Dec 2025 18:01:27 +0000 (13:01 -0500)]
Ensure sanity of hash-join costing when there are no MCV statistics.

estimate_hash_bucket_stats is defined to return zero to *mcv_freq if
it cannot obtain a value for the frequency of the most common value.
Its sole caller final_cost_hashjoin ignored this provision and would
blindly believe the zero value, resulting in computing zero for the
largest bucket size.  In consequence, the safety check that intended
to prevent the largest bucket from exceeding get_hash_memory_limit()
was ineffective, allowing very silly plans to be chosen if statistics
were missing.

After fixing final_cost_hashjoin to disregard zero results for
mcv_freq, a second problem appeared: some cases that should use hash
joins failed to.  This is because estimate_hash_bucket_stats was
unaware of the fact that ANALYZE won't store MCV statistics if it
doesn't find any multiply-occurring values.  Thus the lack of an MCV
stats entry doesn't necessarily mean that we know nothing; we may
well know that the column is unique.  The former coding returned zero
for *mcv_freq in this case, which was pretty close to correct, but now
final_cost_hashjoin doesn't believe it and disables the hash join.
So check to see if there is a HISTOGRAM stats entry; if so, ANALYZE
has in fact run for this column and must have found it to be unique.
In that case report the MCV frequency as 1 / rows, instead of claiming
ignorance.

Reporting a more accurate *mcv_freq in this case can also affect the
bucket-size skew adjustment further down in estimate_hash_bucket_stats,
causing hash-join cost estimates to change slightly.  This affects
some plan choices in the core regression tests.  The first diff in
join.out corresponds to a case where we have no stats and should not
risk a hash join, but the remaining changes are caused by producing
a better bucket-size estimate for unique join columns.  Those are all
harmless changes so far as I can tell.

The existing behavior was introduced in commit 4867d7f62 in v11.
It appears from the commit log that disabling the bucket-size safety
check in the absence of statistics was intentional; but we've now seen
a case where the ensuing behavior is bad enough to make that seem like
a poor decision.  In any case the lack of other problems with that
safety check after several years helps to justify enforcing it more
strictly.  However, we won't risk back-patching this, in case any
applications are depending on the existing behavior.

Bug: #19363
Reported-by: Jinhui Lai <jinhui.lai@qq.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/2380165.1766871097@sss.pgh.pa.us
Discussion: https://postgr.es/m/19363-8dd32fc7600a1153@postgresql.org

4 weeks agoFurther stabilize a postgres_fdw test case.
Tom Lane [Mon, 29 Dec 2025 17:53:49 +0000 (12:53 -0500)]
Further stabilize a postgres_fdw test case.

This patch causes one postgres_fdw test case to revert to the plan
it used before aa86129e1, i.e., using a remote sort in preference to
local sort.  That decision is actually a coin-flip because cost_sort()
will give the same answer on both sides, so that the plan choice comes
down to little more than roundoff error.  In consequence, the test
output can change as a result of even minor changes in nearby costs,
as we saw in aa86129e1 (compare also b690e5fac and 4b14e1871).

b690e5fac's solution to stabilizing the adjacent test case was to
disable sorting locally, and here we extend that to the currently-
problematic case.  Without this, the following patch would cause this
plan choice to change back in this same way, for even less apparent
reason.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/2551253.1766952956@sss.pgh.pa.us

4 weeks agoFix Mkvcbuild.pm builds of test_cloexec.c.
Thomas Munro [Mon, 29 Dec 2025 02:22:16 +0000 (15:22 +1300)]
Fix Mkvcbuild.pm builds of test_cloexec.c.

Mkvcbuild.pm scrapes Makefile contents, but couldn't understand the
change made by commit bec2a0aa.  Revealed by BF animal hamerkop in
branch REL_16_STABLE.

1.  It used += instead of =, which didn't match the pattern that
Mkvcbuild.pm looks for.  Drop the +.

2.  Mkvcbuild.pm doesn't link PROGRAM executables with libpgport.  Apply
a local workaround to REL_16_STABLE only (later branches dropped
Mkvcbuild.pm).

Backpatch-through: 16
Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/175163.1766357334%40sss.pgh.pa.us

4 weeks agoIgnore PlaceHolderVars when looking up statistics
Richard Guo [Mon, 29 Dec 2025 02:40:45 +0000 (11:40 +0900)]
Ignore PlaceHolderVars when looking up statistics

When looking up statistical data about an expression, we failed to
look through PlaceHolderVar nodes, treating them as opaque.  This
could prevent us from matching an expression to base columns, index
expressions, or extended statistics, as examine_variable() relies on
strict structural matching.

As a result, queries involving PlaceHolderVar nodes often fell back to
default selectivity estimates, potentially leading to poor plan
choices.

This patch updates examine_variable() to strip PlaceHolderVars before
analysis.  This is safe during estimation because PlaceHolderVars are
transparent for the purpose of statistics lookup: they do not alter
the value distribution of the underlying expression.

To minimize performance overhead on this hot path, a lightweight
walker first checks for the presence of PlaceHolderVars.  The more
expensive mutator is invoked only when necessary.

There is one ensuing plan change in the regression tests, which is
expected and demonstrates the fix: the rowcount estimate becomes much
more accurate with this patch.

Back-patch to v18.  Although this issue exists before that, changes in
this version made it common enough to notice.  Given the lack of field
reports for older versions, I am not back-patching further.

Reported-by: Haowu Ge <gehaowu@bitmoe.com>
Author: Richard Guo <guofenglinux@gmail.com>
Discussion: https://postgr.es/m/62af586c-c270-44f3-9c5e-02c81d537e3d.gehaowu@bitmoe.com
Backpatch-through: 18

4 weeks agoStrip PlaceHolderVars from index operands
Richard Guo [Mon, 29 Dec 2025 02:38:49 +0000 (11:38 +0900)]
Strip PlaceHolderVars from index operands

When pulling up a subquery, we may need to wrap its targetlist items
in PlaceHolderVars to enforce separate identity or as a result of
outer joins.  However, this causes any upper-level WHERE clauses
referencing these outputs to contain PlaceHolderVars, which prevents
indxpath.c from recognizing that they could be matched to index
columns or index expressions, potentially affecting the planner's
ability to use indexes.

To fix, explicitly strip PlaceHolderVars from index operands.  A
PlaceHolderVar appearing in a relation-scan-level expression is
effectively a no-op.  Nevertheless, to play it safe, we strip only
PlaceHolderVars that are not marked nullable.

The stripping is performed recursively to handle cases where
PlaceHolderVars are nested or interleaved with other node types.  To
minimize performance impact, we first use a lightweight walker to
check for the presence of strippable PlaceHolderVars.  The expensive
mutator is invoked only if a candidate is found, avoiding unnecessary
memory allocation and tree copying in the common case where no
PlaceHolderVars are present.

Back-patch to v18.  Although this issue exists before that, changes in
this version made it common enough to notice.  Given the lack of field
reports for older versions, I am not back-patching further.

Reported-by: Haowu Ge <gehaowu@bitmoe.com>
Author: Richard Guo <guofenglinux@gmail.com>
Discussion: https://postgr.es/m/62af586c-c270-44f3-9c5e-02c81d537e3d.gehaowu@bitmoe.com
Backpatch-through: 18

4 weeks agoChange some Datum to void * for opaque pass-through pointer
Peter Eisentraut [Sun, 28 Dec 2025 13:34:12 +0000 (14:34 +0100)]
Change some Datum to void * for opaque pass-through pointer

Here, Datum was used to pass around an opaque pointer between a group
of functions.  But one might as well use void * for that; the use of
Datum doesn't achieve anything here and is just distracting.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/1c5d23cb-288b-4154-b1cd-191fe2301707%40eisentraut.org

4 weeks agoSplit some long Makefile lists
Michael Paquier [Sun, 28 Dec 2025 00:17:42 +0000 (09:17 +0900)]
Split some long Makefile lists

This change makes more readable code diffs when adding new items or
removing old items, while ensuring that lines do not get excessively
long.  Some SUBDIRS, PROGRAMS and REGRESS lists are split.

Note that there are a few more REGRESS lists that could be split,
particularly in contrib/.

Author: Jelte Fennema-Nio <postgres@jeltef.nl>
Co-Authored-By: Jacob Champion <jacob.champion@enterprisedb.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Japin Li <japinli@hotmail.com>
Reviewed-by: Man Zeng <zengman@halodbtech.com>
Discussion: https://postgr.es/m/DF6HDGB559U5.3MPRFCWPONEAE@jeltef.nl

4 weeks agoFix incorrectly spelled city name
Daniel Gustafsson [Sat, 27 Dec 2025 22:47:40 +0000 (23:47 +0100)]
Fix incorrectly spelled city name

The correct spelling is Beijing, fix in regression test
and docs.

Author: JiaoShuntian <jiaoshuntian@gmail.com>
Reviewed-by: Kirill Reshke <reshkekirill@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Discussion: https://postgr.es/m/ebfa3ec2-dc3c-4adb-be2a-4a882c2e85a7@gmail.com

4 weeks agoRemove MsgType type
Peter Eisentraut [Sat, 27 Dec 2025 21:50:46 +0000 (22:50 +0100)]
Remove MsgType type

Presumably, the C type MsgType was meant to hold the protocol message
type in the pre-version-3 era, but this was never fully developed even
then, and the name is pretty confusing nowadays.  It has only one
vestigial use for cancel requests that we can get rid of.  Since a
cancel request is indicated by a special protocol version number, we
can use the ProtocolVersion type, which MsgType was based on.

Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/505e76cb-0ca2-4e22-ba0f-772b5dc3f230%40eisentraut.org

4 weeks agoAdd oauth_validator_libraries to variable_is_guc_list_quote
Daniel Gustafsson [Sat, 27 Dec 2025 22:05:48 +0000 (23:05 +0100)]
Add oauth_validator_libraries to variable_is_guc_list_quote

The variable_is_guc_list_quote function need to know about all
GUC_QUOTE variables, this adds oauth_validator_libraries which
was missing.  Backpatch to v18 where OAuth was introduced.

Author: ChangAo Chen <cca5507@qq.com>
Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Discussion: https://postgr.es/m/tencent_03D4D2A5C0C8DCE0CD1DB4D945858E15420A@qq.com
Backpatch-through: 18

4 weeks agoFix pg_stat_get_backend_activity() to use multi-byte truncated result
Michael Paquier [Sat, 27 Dec 2025 08:23:30 +0000 (17:23 +0900)]
Fix pg_stat_get_backend_activity() to use multi-byte truncated result

pg_stat_get_backend_activity() calls pgstat_clip_activity() to ensure
that the reported query string is correctly truncated when it finishes
with an incomplete multi-byte sequence.  However, the result returned by
the function was not what pgstat_clip_activity() generated, but the
non-truncated, original, contents from PgBackendStatus.st_activity_raw.

Oversight in 54b6cd589ac2, so backpatch all the way down.

Author: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/CAEoWx2mDzwc48q2EK9tSXS6iJMJ35wvxNQnHX+rXjy5VgLvJQw@mail.gmail.com
Backpatch-through: 14

4 weeks agodoc: warn about the use of "ctid" queries beyond the examples
Bruce Momjian [Fri, 26 Dec 2025 22:34:17 +0000 (17:34 -0500)]
doc:  warn about the use of "ctid" queries beyond the examples

Also be more assertive that "ctid" should not be used for long-term
storage.

Reported-by: Bernice Southey
Discussion: https://postgr.es/m/CAEDh4nyn5swFYuSfcnGAbpQrKOc47Hh_ZyKVSPYJcu2P=51Luw@mail.gmail.com

Backpatch-through: 17

4 weeks agodoc: Remove duplicate word in ECPG description
Michael Paquier [Fri, 26 Dec 2025 06:25:46 +0000 (15:25 +0900)]
doc: Remove duplicate word in ECPG description

Author: Laurenz Albe <laurenz.albe@cybertec.at>
Reviewed-by: vignesh C <vignesh21@gmail.com>
Discussion: https://postgr.es/m/d6d6a800f8b503cd78d5f4fa721198e40eec1677.camel@cybertec.at
Backpatch-through: 14

4 weeks agoUpgrade BufFile to use int64 for byte positions
Michael Paquier [Thu, 25 Dec 2025 23:41:56 +0000 (08:41 +0900)]
Upgrade BufFile to use int64 for byte positions

This change has the advantage of removing some weird type casts, caused
by offset calculations based on pgoff_t but saved as int (on older
branches we use off_t, which could be 4 or 8 bytes depending on the
environment).  These are safe currently because capped by
MAX_PHYSICAL_FILESIZE, but we would run into problems when to make
MAX_PHYSICAL_FILESIZE larger or allow callers of these routines to use a
larger physical max size on demand.

While on it, this improves BufFileDumpBuffer() so as we do not use an
offset for "availbytes".  It is not a file offset per-set, but a number
of available bytes.

This change should lead to no functional changes.

Author: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/aUStrqoOCDRFAq1M@paquier.xyz

4 weeks agoFix typo in stat_utils.c
Michael Paquier [Thu, 25 Dec 2025 22:53:46 +0000 (07:53 +0900)]
Fix typo in stat_utils.c

Introduced by 213a1b895270.

Reported-by: Tender Wang <tndrwang@gmail.com>
Discussion: https://postgr.es/m/CAHewXNku-jz-FPKeJVk25fZ1pV2buYh5vpeqGDOB=bFQhKxXhw@mail.gmail.com

4 weeks agoMove attribute statistics functions to stat_utils.c
Michael Paquier [Thu, 25 Dec 2025 06:13:39 +0000 (15:13 +0900)]
Move attribute statistics functions to stat_utils.c

Many of the operations done for attribute stats in attribute_stats.c
share the same logic as extended stats, as done by a patch under
discussion to add support for extended stats import and export.  All the
pieces necessary for extended statistics are moved to stats_utils.c,
which is the file where common facilities are shared for stats files.

The following renames are done:
* get_attr_stat_type() -> statatt_get_type()
* init_empty_stats_tuple() -> statatt_init_empty_tuple()
* set_stats_slot() -> statatt_set_slot()
* get_elem_stat_type() -> statatt_get_elem_type()

While on it, this commit adds more documentation for all these
functions, describing more their internals and the dependencies that
have been implied for attribute statistics.  The same concepts apply to
extended statistics, at some degree.

Author: Corey Huinker <corey.huinker@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Yu Wang <wangyu_runtime@163.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CADkLM=dpz3KFnqP-dgJ-zvRvtjsa8UZv8wDAQdqho=qN3kX0Zg@mail.gmail.com

4 weeks agoFix planner error with SRFs and grouping sets
Richard Guo [Thu, 25 Dec 2025 03:12:52 +0000 (12:12 +0900)]
Fix planner error with SRFs and grouping sets

If there are any SRFs in a PathTarget, we must separate it into
SRF-computing and SRF-free targets.  This is because the executor can
only handle SRFs that appear at the top level of the targetlist of a
ProjectSet plan node.

If we find a subexpression that matches an expression already computed
in the previous plan level, we should treat it like a Var and should
not split it again.  setrefs.c will later replace the expression with
a Var referencing the subplan output.

However, when processing the grouping target for grouping sets, the
planner can fail to recognize that an expression is already computed
in the scan/join phase.  The root cause is a mismatch in the
nullingrels bits.  Expressions in the grouping target carry the
grouping nulling bit in their nullingrels to indicate that they can be
nulled by the grouping step.  However, the corresponding expressions
in the scan/join target do not have these bits.

As a result, the exact match check in list_member() fails, leading the
planner to incorrectly believe that the expression needs to be
re-evaluated from its arguments, which are often not available in the
subplan.  This can lead to planner errors such as "variable not found
in subplan target list".

To fix, ignore the grouping nulling bit when checking whether an
expression from the grouping target is available in the pre-grouping
input target.  This aligns with the matching logic in setrefs.c.

Backpatch to v18, where this issue was introduced.

Bug: #19353
Reported-by: Marian MULLER REBEYROL <marian.muller@serli.com>
Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Tender Wang <tndrwang@gmail.com>
Discussion: https://postgr.es/m/19353-aaa179bba986a19b@postgresql.org
Backpatch-through: 18

4 weeks agopsql: Fix tab completion for VACUUM option values.
Masahiko Sawada [Wed, 24 Dec 2025 21:55:29 +0000 (13:55 -0800)]
psql: Fix tab completion for VACUUM option values.

Commit 8a3e4011 introduced tab completion for the ONLY option of
VACUUM and ANALYZE, along with some code simplification using
MatchAnyN. However, it caused a regression in tab completion for
VACUUM option values. For example, neither ON nor OFF was suggested
after "VACUUM (VERBOSE". In addition, the ONLY keyword was not
suggested immediately after a completed option list.

Backpatch to v18.

Author: Yugo Nagata <nagata@sraoss.co.jp>
Discussion: https://postgr.es/m/20251223021509.19bba68ecbbc70c9f983c2b4@sraoss.co.jp
Backpatch-through: 18

4 weeks agodoc: change "can not" to "cannot"
Bruce Momjian [Wed, 24 Dec 2025 20:12:01 +0000 (15:12 -0500)]
doc:  change "can not" to "cannot"

Reported-by: Chao Li
Author: Chao Li

Discussion: https://postgr.es/m/CAEoWx2kyiD+7-vUoOYhH=y2Hrmvqyyhm4EhzgKyrxGBXOMWCxw@mail.gmail.com

4 weeks agoFix regression test failure when wal_level is set to minimal.
Masahiko Sawada [Wed, 24 Dec 2025 18:48:27 +0000 (10:48 -0800)]
Fix regression test failure when wal_level is set to minimal.

Commit 67c209 removed the WARNING for insufficient wal_level from the
expected output, but the WARNING may still appear on buildfarm members
that run with wal_level=minimal.

To avoid unstable test output depending on wal_level, this commit the
test to use ALTER PUBLICATION for verifying the same behavior,
ensuring the output remains consistent regardless of the wal_level
setting.

Per buildfarm member thorntail.

Author: Zhijie Hou <houzj.fnst@fujitsu.com>
Discussion: https://postgr.es/m/TY4PR01MB16907680E27BAB146C8EB1A4294B2A@TY4PR01MB16907.jpnprd01.prod.outlook.com

4 weeks agodoc: Use proper tags in pg_overexplain documentation.
Fujii Masao [Wed, 24 Dec 2025 15:27:19 +0000 (00:27 +0900)]
doc: Use proper tags in pg_overexplain documentation.

The pg_overexplain documentation previously used the <literal> tag for
some file names, struct names, and commands. Update the markup to
use the more appropriate tags: <filename>, <structname>, and <command>.

Backpatch to v18, where pg_overexplain was introduced.

Author: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Shixin Wang <wang-shi-xin@outlook.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/CAHGQGwEyYUzz0LjBV_fMcdwU3wgmu0NCoT+JJiozPa8DG6eeog@mail.gmail.com
Backpatch-through: 18

4 weeks agoFix CREATE SUBSCRIPTION failure when the publisher runs on pre-PG19.
Fujii Masao [Wed, 24 Dec 2025 14:43:30 +0000 (23:43 +0900)]
Fix CREATE SUBSCRIPTION failure when the publisher runs on pre-PG19.

CREATE SUBSCRIPTION with copy_data=true and origin='none' previously
failed when the publisher was running a version earlier than PostgreSQL 19,
even though this combination should be supported.

The failure occurred because the command issued a query calling
pg_get_publication_sequences function on the publisher. That function
does not exist before PG19 and the query is only needed for logical
replication sequence synchronization, which is supported starting in PG19.

This commit fixes this issue by skipping that query when the
publisher runs a version earlier than PG19.

Author: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Shlok Kyal <shlok.kyal.oss@gmail.com>
Discussion: https://postgr.es/m/CAHGQGwEx4twHtJdiPWTyAXJhcBPLaH467SH2ajGSe-41m65giA@mail.gmail.com

4 weeks agoFix version check for retain_dead_tuples subscription option.
Fujii Masao [Wed, 24 Dec 2025 14:25:00 +0000 (23:25 +0900)]
Fix version check for retain_dead_tuples subscription option.

The retain_dead_tuples subscription option is supported only when
the publisher runs PostgreSQL 19 or later. However, it could previously
be enabled even when the publisher was running an earlier version.

This was caused by check_pub_dead_tuple_retention() comparing
the publisher server version against 19000 instead of 190000.

Fix this typo so that the version check correctly enforces the PG19+
requirement.

Author: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Shlok Kyal <shlok.kyal.oss@gmail.com>
Discussion: https://postgr.es/m/CAHGQGwEx4twHtJdiPWTyAXJhcBPLaH467SH2ajGSe-41m65giA@mail.gmail.com

4 weeks agoUpdate comments to reflect changes in 8e0d32a4a1.
Amit Kapila [Wed, 24 Dec 2025 10:29:53 +0000 (10:29 +0000)]
Update comments to reflect changes in 8e0d32a4a1.

Commit 8e0d32a4a1 fixed an issue by allowing the replication origin to be
created while marking the table sync state as SUBREL_STATE_DATASYNC.
Update the comment in check_old_cluster_subscription_state() to accurately
describe this corrected behavior.

Author: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Backpatch-through: 17, where the code was introduced
Discussion: https://postgr.es/m/CAA4eK1+KaSf5nV_tWy+SDGV6MnFnKMhdt41jJjSDWm6yCyOcTw@mail.gmail.com
Discussion: https://postgr.es/m/aUTekQTg4OYnw-Co@paquier.xyz