]> git.ipfire.org Git - thirdparty/postgresql.git/log
thirdparty/postgresql.git
7 days agolibpq: Extend "read pending" check from SSL to GSS
Heikki Linnakangas [Tue, 7 Jul 2026 15:45:34 +0000 (18:45 +0300)] 
libpq: Extend "read pending" check from SSL to GSS

An extra check for pending bytes in the SSL layer has been part of
pqReadReady() for a very long time (79ff2e96d). But when GSS transport
encryption was added, it didn't receive the same treatment. (As
79ff2e96d notes, "The bug that I fixed in this patch is exceptionally
hard to reproduce reliably.")

Without that check, it's possible to hit a hang in gssencmode, if the
server splits a large libpq message such that the final message in a
streamed response is part of the same wrapped token as the split
message:

    DataRowDataRowDataRowDataRowDataRowData
    -- token boundary --
    RowDataRowCommandCompleteReadyForQuery

If the split message takes up enough memory to nearly fill libpq's
receive buffer, libpq may return from pqReadData() before the later
messages are pulled out of the PqGSSRecvBuffer. Without additional
socket activity from the server, pqReadReady() (via pqSocketCheck())
will never again return true, hanging the connection.

Pull the pending-bytes check into the pqsecure API layer, where both
SSL and GSS now implement it.

Note that this does not fix the root problem! Third party clients of
libpq have no way to call pqsecure_read_is_pending() in their own
polling. This just brings the GSS implementation up to par with the
existing SSL workaround; a broader fix is left to a subsequent commit.

In preparation for the broader fix, this patch already changes the
*_read_pending() functions to return the number of bytes in the buffer
rather than just a boolean. The current callers don't need that, but
the subsequent fix will.

Author: Jacob Champion <jacob.champion@enterprisedb.com>
Discussion: https://postgr.es/m/CAOYmi%2BmpymrgZ76Jre2dx_PwRniS9YZojwH0rZnTuiGHCsj0rA%40mail.gmail.com
Backpatch-through: 14

7 days agoReplace hardcoded mentions of pg_hosts.conf with GUC
Daniel Gustafsson [Tue, 7 Jul 2026 15:34:58 +0000 (17:34 +0200)] 
Replace hardcoded mentions of pg_hosts.conf with GUC

Three error messages were using the default file name pg_hosts.conf
and not the variable backing the GUC, which would make logging be
confusing for users who have renamed the file using the GUC.  Fix
by consistently using the HostsFileName variable.

Backpatch down to v19 where serverside SNI was introduced.

Author: Zsolt Parragi <zsolt.parragi@percona.com>
Reviewed-by: Surya Poondla <suryapoondla4@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CAN4CZFMARYjQfgyRaCKOXDO=Q91kuKn=pSC02DAOOr23ojhEGQ@mail.gmail.com
Backpatch-through: 19

7 days agopg_dump: check for _beginthreadex() failure in parallel dump
Heikki Linnakangas [Tue, 7 Jul 2026 15:11:28 +0000 (18:11 +0300)] 
pg_dump: check for _beginthreadex() failure in parallel dump

ParallelBackupStart() stored _beginthreadex()'s return value as the
worker's thread handle without checking it.  On failure that value is 0,
which would later reach WaitForMultipleObjects() as a null handle, caught
only by an Assert.  The fork() path already calls pg_fatal() when it
fails; do the same for _beginthreadex(), as pgbench does.

Author: Bryan Green <dbryan.green@gmail.com>
Discussion: https://www.postgresql.org/message-id/8c712d76-ecf7-4749-a6d8-dddc01f298ec@gmail.com
Backpatch-through: 14

7 days agodoc: Add reference to CREATE PROCEDURE on CREATE FUNCTION
Daniel Gustafsson [Tue, 7 Jul 2026 13:55:24 +0000 (15:55 +0200)] 
doc: Add reference to CREATE PROCEDURE on CREATE FUNCTION

The reference page for CREATE PROCEDURE had a See Also reference to
CREATE FUNCTION, but the inverse was missing.

Author: Jian He <jian.universality@gmail.com>
Reviewed-by: Laurenz Albe <laurenz.albe@cybertec.at>
Discussion: https://postgr.es/m/CACJufxFTi3ceVRJqWRr3L8GR5q+ZhPCZw=1aDTaBGS1AugweFw@mail.gmail.com

7 days agoFix COUNT's logic for window run condition support
David Rowley [Tue, 7 Jul 2026 11:57:45 +0000 (23:57 +1200)] 
Fix COUNT's logic for window run condition support

9d9c02ccd added code to allow the executor to stop early when processing
WindowAgg nodes where a monotonic window function starts producing
values that result in a pushed-down qual no longer matching, and will
never match again due to the window function's monotonic properties.

That commit requires a SupportRequestWFuncMonotonic to exist on the
window function and for it to detect when the function is monotonic.  For
COUNT(ANY) and COUNT(*), the support function failed to consider some
cases where the WindowClause used EXCLUDE to exclude certain rows from
being aggregated.  Some WindowClause definitions mean we aggregate rows
that come after the current row, and when processing those rows later,
if we EXCLUDE certain rows, the monotonic property can be broken.
Wrongly treating the COUNT(*) or COUNT(ANY) aggregate as monotonic could
lead to rows being filtered that should not be filtered from the result
set.

Another issue was that the support function for the COUNT aggregate
mistakenly thought that a WindowClause without an ORDER BY meant that
the results would be both monotonically increasing and decreasing, but
that's only true when in RANGE mode, where all rows are peers.

It is possible to support various cases that do have an EXCLUDE clause,
but getting the logic correct for the exact set of cases that are valid
is quite complex and would likely better be left for a future project.

Here, we mostly disable run condition pushdown when there is an EXCLUDE
clause unless the clause is for EXCLUDE CURRENT ROW, uses COUNT(*)
(rather than COUNT(ANY)), and the window aggregate has no FILTER clause.

Bug: #19533
Reported-by: Qifan Liu <imchifan@163.com>
Author: Chengpeng Yan <chengpeng_yan@outlook.com>
Author: David Rowley <dgrowleyml@gmail.com>
Reviewed-by: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: John Naylor <johncnaylorls@gmail.com>
Discussion: https://postgr.es/m/19533-413a1014e5d0e766@postgresql.org
Backpatch-through: 15

8 days agoPrint off_t/pgoff_t consistently as %lld
Peter Eisentraut [Tue, 7 Jul 2026 09:50:22 +0000 (11:50 +0200)] 
Print off_t/pgoff_t consistently as %lld

This was the dominant style already, but some places used %llu
instead.  Since off_t/pgoff_t are signed types, using %lld seems a
better match, and it might handle obscure error conditions with
negative values better.

Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/20ce62fa-47fc-457b-b504-12f3c1651726%40eisentraut.org

8 days agoDon't cast pgoff_t to possibly 32-bit types for output
Peter Eisentraut [Tue, 7 Jul 2026 09:45:09 +0000 (11:45 +0200)] 
Don't cast pgoff_t to possibly 32-bit types for output

pgoff_t is most likely a 64-bit integer, so casting it to a 32-bit
type for output could lose data.  In the cases addressed here, the
files cannot actually get that large, so this is only cosmetic and to
set better examples for the future.  (Similar issues that could have
actual practical impact were addressed separately in commit
e8f851d6172.)

In one case, the 32-bit size is baked into the protocol, so here we
add an elog and document this discrepancy.

Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/20ce62fa-47fc-457b-b504-12f3c1651726%40eisentraut.org

8 days agopostgres_fdw: Report ANALYZE to pgstats after importing statistics.
Etsuro Fujita [Tue, 7 Jul 2026 09:40:00 +0000 (18:40 +0900)] 
postgres_fdw: Report ANALYZE to pgstats after importing statistics.

Commit 28972b6fc should have done this, but didn't.

While at it, remove an extra blank line in fetch_remote_statistics()
introduced by that commit.

Reported-by: Chao Li <lic@highgo.com>
Co-authored-by: Chao Li <lic@highgo.com>
Co-authored-by: Etsuro Fujita <etsuro.fujita@gmail.com>
Discussion: https://postgr.es/m/6ED81190-B398-44C9-A1E9-8EFE4ED183AF%40gmail.com
Backpatch-through: 19

8 days agoUpdate GROUP BY ALL comments about window functions
Peter Eisentraut [Tue, 7 Jul 2026 06:37:15 +0000 (08:37 +0200)] 
Update GROUP BY ALL comments about window functions

When GROUP BY ALL was added in commit ef38a4d9756, the SQL standard
working draft was silent on what to do with window functions.  This
has now been fixed in the SQL standard working draft.  Update the
documentation and code comments about that.

Also make the documentation more specific that we are only talking
about aggregate functions referring to the same query level, which is
another thing that has been made more precise in the SQL standard
working draft since.

The PostgreSQL implementation was already doing the right thing for
both aspects, so no functionality changes.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/CAHM0NXjz0kDwtzoe-fnHAqPB1qA8_VJN0XAmCgUZ%2BiPnvP5LbA%40mail.gmail.com

8 days agoEnforce RETURNING typmod on SQL/JSON DEFAULT behavior expressions
Amit Langote [Mon, 6 Jul 2026 23:14:04 +0000 (08:14 +0900)] 
Enforce RETURNING typmod on SQL/JSON DEFAULT behavior expressions

transformJsonBehavior() coerced an ON EMPTY / ON ERROR DEFAULT
expression only when its type differed from the RETURNING type's OID.
When the base type matched but the RETURNING type carried a type
modifier (e.g. numeric(4,1) or varchar(3)), the coercion that enforces
the typmod was skipped, so the DEFAULT value could violate the
declared type:

    SELECT JSON_VALUE(jsonb '{}', '$.a'
                      RETURNING numeric(4,1) DEFAULT 99999.999 ON EMPTY);

returned 99999.999, which 99999.999::numeric(4,1) would reject; the
value could even be stored into a numeric(4,1) column, as later
coercions trust its already-correct type label.

Fix by also coercing when the RETURNING type has a typmod, except for
a NULL constant.  coerce_to_target_type() is a no-op when the typmod
already matches.  The matching-OID short-circuit dates to 74c96699be3.

Reported-by: Ewan Young <kdbase.hack@gmail.com>
Author: Ewan Young <kdbase.hack@gmail.com>
Discussion: https://postgr.es/m/CAON2xHPO9f4cAmyGn1mQ=VqoS7wN5rz4yOiqudxX78zninZpCw@mail.gmail.com
Backpatch-through: 17

8 days agoUse PG_MODULE_MAGIC_EXT in newly introduced modules
Robert Haas [Mon, 6 Jul 2026 19:34:12 +0000 (15:34 -0400)] 
Use PG_MODULE_MAGIC_EXT in newly introduced modules

We forgot to use the PG_MODULE_MAGIC_EXT in some newly added modules:
pg_plan_advice, pg_stash_advice and the pgrepack output plugin and
instead used the older PG_MODULE_MAGIC macro.

Author: Andreas Karlsson <andreas@proxel.se>
Discussion: http://postgr.es/m/ad7b910c-d145-4120-994d-2e55c456aa75@proxel.se
Backpatch-through: 19

8 days agoFix mishandling of leading '\' in nondeterministic LIKE.
Tom Lane [Mon, 6 Jul 2026 18:47:58 +0000 (14:47 -0400)] 
Fix mishandling of leading '\' in nondeterministic LIKE.

The loop in MatchText() processed a leading '\' without regard to
nondeterministic locales, which is problematic if what the '\'
precedes is an ordinary character that should be subject to
nondeterministic matching.  We'd insist on a literal match for it,
which is not right and is not like what happens with a '\' that
follows some ordinary characters.  Worse, we'd then advance the text
and pattern pointers by one byte, so that if the escaped character
is multibyte the next loop iteration would take the nondeterministic
code path starting at a point within the character.  That could very
possibly cause pg_strncoll() to misbehave.

The fix is quite simple: move the stanza that handles '\' down past
the one that handles nondeterminism.  The stanzas for '%' and '_'
are fine where they are, but the '\' stanza is only correct for
deterministic matching.  The logic for nondeterministic cases is
already prepared to do the right things with a '\'.

While here, I replaced tests of "locale && !locale->deterministic"
with a boolean local variable, reasoning that those are in the hot
loop paths so saving a branch and indirect fetch is worth the
trouble.  I also improved a number of related comments.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/391592.1783187986@sss.pgh.pa.us
Backpatch-through: 18

8 days agoFix LIKE matching with nondeterministic collations and backslashes.
Tom Lane [Mon, 6 Jul 2026 18:35:21 +0000 (14:35 -0400)] 
Fix LIKE matching with nondeterministic collations and backslashes.

Commit 85b7efa1c added support for LIKE with nondeterministic
collations, but it included a bug in the de-escaping logic for
literal pattern substrings.  That unconditionally skipped all
backslashes, but when it encounters '\\' it should emit the second
backslash as a de-escaped character.  That led to acting as though
the escaped backslash was not there.

Bug: #19474
Reported-by: Bowen Shi <zxwsbg12138@gmail.com>
Author: Nitin Motiani <nitinmotiani@google.com>
Reviewed-by: Zsolt Parragi <zsolt.parragi@percona.com>
Reviewed-by: Ewan Young <kdbase.hack@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/19474-5b86a95f3d9a7ecb@postgresql.org
Discussion: https://postgr.es/m/CAH5HC94yU+K8Gcdy12M5BS8gwD_SXLSHzc9k5tNk7JDnpBiFMA@mail.gmail.com
Backpatch-through: 18

8 days agoMake PLy_elog() use pg_integer_constant_p().
Tom Lane [Mon, 6 Jul 2026 17:48:42 +0000 (13:48 -0400)] 
Make PLy_elog() use pg_integer_constant_p().

This macro is supposed to work like ereport().  But when
59c2f03d1 adjusted ereport() to be more MSVC-friendly,
it missed updating this copy of the logic.

Discussion: https://postgr.es/m/754534.1783264708@sss.pgh.pa.us
Backpatch-through: 19

8 days agoFix LIKE/regex optimization for indexscan with exact-match pattern.
Tom Lane [Mon, 6 Jul 2026 17:06:21 +0000 (13:06 -0400)] 
Fix LIKE/regex optimization for indexscan with exact-match pattern.

Commit 85b7efa1c introduced support for LIKE with non-deterministic
collations.  By moving some conditionals around, it accidentally broke
the optimization for converting a LIKE or regex exact-match pattern
to an equality indexqual when the index collation doesn't match the
expression collation.  That should be allowed if the expression
collation is deterministic.  This patch re-introduces the optimization
for that common case.

One important beneficiary of this optimization is the "\d tablename"
command in psql.  Without this fix that will do a seqscan on pg_class
instead of an index point lookup.

Reported-by: Andres Freund <andres@anarazel.de>
Author: Jelte Fennema-Nio <postgres@jeltef.nl>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/DHBQIZX8SZVI.ZX614ZMFL645@jeltef.nl
Backpatch-through: 18

8 days agoPrevent satisfies_hash_partition from crashing with VARIADIC NULL.
Robert Haas [Mon, 6 Jul 2026 16:12:41 +0000 (12:12 -0400)] 
Prevent satisfies_hash_partition from crashing with VARIADIC NULL.

Commit f3b0897a1213f46b4d3a99a7f8ef3a4b32e03572 fixed some
related problems, but overlooked this one. That commit first
appeared in PostgreSQL 11, so back-patch to all supported branches.

Backpatch-through: 14
Discussion: http://postgr.es/m/CA+TgmobsvQw3F+KRYT83=N3teh8D2t-oPR=U06QDZJE3viCJRg@mail.gmail.com
Reviewed-by: Tender Wang <tndrwang@gmail.com>
Reviewed-by: Ewan Young <kdbase.hack@gmail.com>
8 days agoRemove switch statements in vector8_shift_{left,right}.
Nathan Bossart [Mon, 6 Jul 2026 16:40:02 +0000 (11:40 -0500)] 
Remove switch statements in vector8_shift_{left,right}.

In commit ec8719ccbf, I added switch statements with all expected
shift counts to vector8_shift_{left,right} because vshlq_n_u32()
and vshrq_n_u32() require integer literals.  But we can use
vshlq_u32() instead for both cases, which does not require an
integer literal, thereby avoiding the need for the switch
statements.  This compiles to the same machine code on newer
versions of popular compilers.

Reviewed-by: John Naylor <johncnaylorls@gmail.com>
Discussion: https://postgr.es/m/akWxkA-mszMm57cV%40nathan

8 days agoAdd comment to describe the various frontend cancel methods
Heikki Linnakangas [Mon, 6 Jul 2026 16:11:04 +0000 (19:11 +0300)] 
Add comment to describe the various frontend cancel methods

Author: Jelte Fennema-Nio <postgres@jeltef.nl>
Discussion: https://www.postgresql.org/message-id/DJPAH0WPJV3K.1PYZ8P0QXZVMX@jeltef.nl

9 days agoRemove apparent support for SECURITY LABEL ON PROPERTY GRAPH
Peter Eisentraut [Mon, 6 Jul 2026 09:44:55 +0000 (11:44 +0200)] 
Remove apparent support for SECURITY LABEL ON PROPERTY GRAPH

Commit 2f094e7ac69 added a mention of SECURITY LABEL ON PROPERTY GRAPH
to the SECURITY LABEL reference page, and it added support to psql tab
completion.  However, security labels on property graphs are not
actually supported (per SecLabelSupportsObjectType()).  The syntax
does work, but that is just a result of how gram.y is factored.  We
don't document or tab-complete the syntax of SECURITY LABEL for other
object types that are not actually supported, so it was inconsistent
to do this for property graphs.  Thus, remove this.

Reported-by: Noah Misch <noah@leadboat.com>
Discussion: https://www.postgresql.org/message-id/flat/20260704221210.08.noahmisch%40microsoft.com

9 days agoForbid generated columns in FOR PORTION OF
Peter Eisentraut [Mon, 6 Jul 2026 07:19:02 +0000 (09:19 +0200)] 
Forbid generated columns in FOR PORTION OF

With virtual generated columns there is no column to assign to, and we
shouldn't assign directly to stored generated columns either.  (Once
we have PERIODs, we will allow a stored generated column here, but we
will assign to its start/end inputs.)

We can't do this in parse analysis, because views haven't yet been
rewritten, so they mask generated columns.

Author: Paul A. Jungwirth <pj@illuminatedcomputing.com>
Discussion: https://www.postgresql.org/message-id/agOOykf2HV26yVfU%40nathan

9 days agoFix qual pushdown past grouping with mismatched equivalence
Richard Guo [Mon, 6 Jul 2026 07:13:14 +0000 (16:13 +0900)] 
Fix qual pushdown past grouping with mismatched equivalence

The planner has two optimizations that move a qual clause across a
grouping boundary: subquery_planner transfers HAVING clauses to WHERE
so they can be evaluated before aggregation, and qual_is_pushdown_safe
pushes outer restriction clauses into a subquery past its DISTINCT,
DISTINCT ON, window PARTITION BY, or set-operation grouping layer.
Both produce wrong results when the moved clause's equivalence
relation disagrees with the grouping's, since the clause then filters
rows the grouping would have merged.

The disagreement has two forms.  A type may belong to multiple btree
opfamilies whose equality operators disagree (e.g. record_ops vs
record_image_ops); or the grouping may use a nondeterministic
collation, where comparing the column under a different collation, or
wrapping it in a function or operator, can distinguish values the
collation considers equal.  Because we cannot prove an arbitrary
expression preserves that equality, a grouping column with a
nondeterministic collation is safe to push only as a direct operand of
a comparison under its own collation.

Fix both call sites through a shared walker parameterized by a
callback that maps each Var to the grouping equality operator for its
column (or InvalidOid for non-grouping Vars).  For HAVING, the
callback recovers the SortGroupClause's eqop via the GROUP Var's
varattno, which requires running before flatten_group_exprs while
havingQual still contains GROUP Vars.  For subquery pushdown, the
callback recovers the eqop from subquery->distinctClause, a window's
partitionClause, or any grouping node in the SetOperationStmt tree.
The walker fires only when there is an equivalence boundary to cross,
gated by either the existing UNSAFE_NOTIN_DISTINCTON_CLAUSE and
UNSAFE_NOTIN_PARTITIONBY_CLAUSE flags or by a recursive check for any
grouping node in the set-op tree.

Back-patch to v18 only.  The HAVING half relies on the RTE_GROUP
mechanism introduced in v18 (commit 247dea89f), which is what lets us
identify grouping expressions via GROUP Vars on pre-flatten
havingQual.  Pre-v18 branches lack that machinery, so a back-patch
there would need a different approach.  Given the absence of field
reports of these bugs on back branches, the risk of carrying a
different fix on stable branches is not justified.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Thom Brown <thom@linux.com>
Reviewed-by: Florin Irion <irionr@gmail.com>
Reviewed-by: Zsolt Parragi <zsolt.parragi@percona.com>
Reviewed-by: Tender Wang <tndrwang@gmail.com>
Reviewed-by: Chengpeng Yan <chengpeng_yan@outlook.com>
Discussion: https://postgr.es/m/CAMbWs4-QLZpn3UVOpeG2fOxxhdnkDNMZ_3Zcm3dqJwRAphz68g@mail.gmail.com
Backpatch-through: 18

9 days agoEmit a warning when io_min_workers exceeds io_max_workers
Michael Paquier [Mon, 6 Jul 2026 02:37:36 +0000 (11:37 +0900)] 
Emit a warning when io_min_workers exceeds io_max_workers

When io_min_workers is set strictly higher than io_max_workers, the
minimum has no effect since the pool will never grow past
io_max_workers.  Previously this was silently accepted, which could
be confusing for users expecting at least io_min_workers workers to
always be running.

In order to avoid noise in the server logs, the following restrictions
are in place:
- The only process printing the WARNING is the IO worker with ID 0, on
startup and reload, which is we know the only process always running
when using IO workers.
- At reload, the message shows only if one of the bounds has changed.

Note that this commit reuses a log message updated by 7905416eef9b.

Author: Baji Shaik <baji.pgdev@gmail.com>
Reviewed-by: Tristan Partin <tristan@partin.io>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Discussion: https://postgr.es/m/CA+fm-RO_O7-XThg2qjj=ir35x9nOFbZYu07gttqAbM5T88QB4Q@mail.gmail.com

9 days agoImprove checks and error messages of pgstat_register_kind()
Michael Paquier [Mon, 6 Jul 2026 01:49:28 +0000 (10:49 +0900)] 
Improve checks and error messages of pgstat_register_kind()

pgstat_register_kind() did not validate that required callbacks are
set, which could lead to NULL pointer dereferences when trying to
register a stats kind.  This adds a couple of checks:
- Fox fixed-sized kinds, init_shmem_cb, reset_all_cb, and snapshot_cb
are required.
- For variable-sized kinds, flush_pending_cb is called when there is
pending data, pending_size being required.

These issues should be easy to notice for someone developing an
extension that relies on the custom pgstats APIs.  No backpatch is done
as it is mainly a life improvement.

Author: Sami Imseih <samimseih@gmail.com>
Discussion: https://postgr.es/m/CAA5RZ0uNoe=xT7QsU1K0mMRg-QAwPtupPWZ2J3weM2PjVL2tiA@mail.gmail.com

9 days agoamcheck: Fix memory leak with gin_index_check()
Michael Paquier [Mon, 6 Jul 2026 00:32:25 +0000 (09:32 +0900)] 
amcheck: Fix memory leak with gin_index_check()

"prev_tuple" was overwritten with a new tuple coming from
CopyIndexTuple() on each loop, leaking memory for every tuple processed
on entry tree pages.  The function uses a dedicated memory context, but
this could leave unused large areas of memory while processing a large
GIN index, the larger the worse.

Oversight in 14ffaece0fb5.

Author: Kirill Reshke <reshkekirill@gmail.com>
Reviewed-by: Ewan Young <kdbase.hack@gmail.com>
Discussion: https://postgr.es/m/CALdSSPjTS6TYe5=5NfMUBYZyQu5cn=ABL6K5_OZjzGWqnwXeBw@mail.gmail.com
Backpatch-through: 18

9 days agoFix psql's pager selection for wrapped expanded output.
Tom Lane [Sun, 5 Jul 2026 22:11:40 +0000 (18:11 -0400)] 
Fix psql's pager selection for wrapped expanded output.

psql decided whether to use the pager in expanded output without
accounting for possible wrapping of column values.  This could
allow it to not use the pager in cases where it should do so.

To fix, move the IsPagerNeeded decision in print_aligned_vertical()
down until after the wrapped data width is known.  Then, if we're in
wrapped mode, prepare a width_wrap array specifying that width (which,
in vertical mode, is the same for all columns).

This is fixing an omission in 27da1a796, so back-patch to v19
where that came in.

Author: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Erik Wienhold <ewie@ewie.name>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/A44110E7-6A03-4C67-95AD-527192A6C768@gmail.com
Backpatch-through: 19

9 days agoSimplify dxsyn_lexize().
Tom Lane [Sun, 5 Jul 2026 20:22:40 +0000 (16:22 -0400)] 
Simplify dxsyn_lexize().

There's no need to create and free a temporary copy of the input,
since str_tolower() is already able to cope with not-certainly-
nul-terminated input.  (Before v18, copying was needed because
this code used lowerstr(), but now we can do without.)

Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/19525-b0be8e4eb7dbaf07@postgresql.org

9 days agoFix properties orphaned by dropping a label
Peter Eisentraut [Sun, 5 Jul 2026 11:47:18 +0000 (13:47 +0200)] 
Fix properties orphaned by dropping a label

AlterPropGraph() cleans up pg_propgraph_property entries that are
orphaned by dropping an element or by dropping properties associated
with an element.  But it did not clean up pg_propgraph_property
entries that are orphaned by dropping labels associated with an
element.  Fix this missing case.

Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Author: zengman <zengman@halodbtech.com>
Discussion: https://www.postgresql.org/message-id/flat/tencent_76F6ACA2364EAA1E5DBD7A47%40qq.com

10 days agoDisallow renaming a rule to "_RETURN".
Tom Lane [Sat, 4 Jul 2026 15:34:26 +0000 (11:34 -0400)] 
Disallow renaming a rule to "_RETURN".

ON SELECT rules must be named "_RETURN", while other kinds of rules
must not be; this ancient restriction is depended on by various client
code.  We successfully enforced this convention in most places, but
ALTER RULE allowed renaming a non-SELECT rule to "_RETURN".  Notably,
that would break dump/restore, since the eventual CREATE RULE command
would reject the name.

While at it, remove DefineQueryRewrite's hack to substitute "_RETURN"
for the convention that was used before 7.3.  We dropped other
server-side code that supported restoring pre-7.3 dumps some time ago
(notably in e58a59975 and nearby commits), but this bit was missed.

Bug: #19543
Reported-by: Adam Pickering <adamkpickering@gmail.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/19543-461228e77f3b32fc@postgresql.org
Backpatch-through: 14

11 days agoMake property graph object descriptions better translatable
Peter Eisentraut [Fri, 3 Jul 2026 21:32:20 +0000 (23:32 +0200)] 
Make property graph object descriptions better translatable

getObjectDescription() currently constructs property graph-related
object descriptions incrementally with appendStringInfo().  This
effectively fixes the word order in English, which makes the messages
difficult to translate naturally into languages such as Japanese.

Author: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Reviewed-by: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/20260528.121622.1662808269492494574.horikyota.ntt%40gmail.com

11 days agoRemove btree_gist's useless logic for encoding-aware truncation.
Tom Lane [Fri, 3 Jul 2026 19:31:58 +0000 (15:31 -0400)] 
Remove btree_gist's useless logic for encoding-aware truncation.

gbt_var_node_cp_len() contained logic to ensure that its choice of
a common prefix length didn't truncate away part of a multibyte
character.  However, that was really dead code, because we have not
allowed truncation of text-string data types since ef770cbb6, and
it seems unlikely that that behavior could ever get resurrected.
The code is still reachable via gbt_var_penalty, but for that
usage it hardly matters if we break in the middle of a multibyte
character: we're just calculating a small correction factor that
is arguably bunkum anyway in non-C locales.

Hence, delete said code.  That actually removes all need for
gbtree_vinfo.eml, which allows const-ification of the gbtree_vinfo
structs in which we were changing it, which removes one headache
for future attempts to thread-ify the backend.

(Curiously, all this infrastructure was itself added by ef770cbb6.
Not sure why Teodor didn't see the contradiction.)

Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Discussion: https://postgr.es/m/AH*AvQCYKhQGVvPWi1GiU4oY.8.1781609375063.Hmail.3020001251@tju.edu.cn

11 days agoTighten up btree_gist's handling of truncated bounds.
Tom Lane [Fri, 3 Jul 2026 19:25:19 +0000 (15:25 -0400)] 
Tighten up btree_gist's handling of truncated bounds.

Truncating an internal node's upper bound can cause it to compare
less than some values that in fact are included in the represented
leaf page.  So we need a hack to make sure it looks large enough
to include all values that could be on the page.  But there's no
equivalent issue for the lower bound.  The fact that the code did
fuzzy comparisons for the lower bound too seems to be the result of
fuzzy thinking.  Or maybe there was a desire to not assume too much
about what the datatype's comparison rule is; but we've already
fully bought into the premise that internal keys compare like bytea.

Hence, remove the useless check against the key's lower bound in
gbt_var_node_pf_match.  The comparable check in gbt_var_penalty may
also be useless, but I'm not quite sure.  In any case that seems
negligible from a performance standpoint, so I left it alone.

Also, in the strategy cases in gbt_var_consistent that only
require comparisons to the lower bound, there's no need to call
gbt_var_node_pf_match at all.  Refactor that logic by inventing
macros lower_is_below_query and upper_is_above_query to directly
express what we need to test.  I also took this opportunity to flip
all the tests around to be "indexkey OP query" rather than mostly
being the reverse: IMO this makes the code less confusing since the
tests now match the names of the strategies.

Also, in the name of consistency, make gbt_num_consistent look
like that too.  There's no functional change there, but this
should be more readable going forward.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Discussion: https://postgr.es/m/AH*AvQCYKhQGVvPWi1GiU4oY.8.1781609375063.Hmail.3020001251@tju.edu.cn

11 days agoSync signatures of gbt_var_consistent() and gbt_num_consistent().
Tom Lane [Fri, 3 Jul 2026 18:23:22 +0000 (14:23 -0400)] 
Sync signatures of gbt_var_consistent() and gbt_num_consistent().

For some odd reason we pass the strategy number to gbt_num_consistent
as "const StrategyNumber *strategy".  There's no reason for that:
it almost certainly costs more at both callers and callee to pass a
pointer than to pass a small integer value.  And it's inconsistent
with gbt_var_consistent(), so fix it.

gbt_var_consistent() had its own infelicity, which was not marking
the input "key" value const.  Fix that too while we're here.

This is primarily cosmetic, so I see no need to backpatch.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/AH*AvQCYKhQGVvPWi1GiU4oY.8.1781609375063.Hmail.3020001251@tju.edu.cn

11 days agoREPACK CONCURRENTLY: Initialize the range table more honestly
Álvaro Herrera [Fri, 3 Jul 2026 18:04:48 +0000 (20:04 +0200)] 
REPACK CONCURRENTLY: Initialize the range table more honestly

We were skipping a bunch of things that are mostly unnecessary for
REPACK.  However, one thing that seems would be better to pass closer to
truth, is the updatedCols bitmapset in the range table entry for the
repacked table.  Cons up an RTE and install it into the EState.

This only has an effect on btree indexes, because certain operations are
optimized in the case of unchanged columns; and even then, correctnesss
is not being compromised.

The values we pass after this commit are not fully trustworthy either,
because we simply say "all columns were updated" for all insert/updates,
regardless of whether their values were actually modified or not.
However, this way we err to the side of caution rather than to the
opposite direction as we were originally doing.  This could be refined
in the future, but there's a trade-off: determining whether the column
was in fact updated could be expensive.

Author: Antonin Houska <ah@cybertec.at>
Reviewed-by: Ewan Young <kdbase.hack@gmail.com>
Backpatch-through: 19
Discussion: https://postgr.es/m/18222.1782126731@localhost

11 days agoFix btree_gist's NotEqual strategy on internal index pages.
Tom Lane [Fri, 3 Jul 2026 17:50:14 +0000 (13:50 -0400)] 
Fix btree_gist's NotEqual strategy on internal index pages.

gbt_var_consistent() handled the <> (BtreeGistNotEqual) strategy without
distinguishing leaf from internal pages, unlike every other strategy.
In particular, it tried to apply the datatype-specific f_eq method,
which is completely wrong since internal keys might not have the same
representation as leaf keys.  This led to OOB reads and potentially
crashes, and most likely to wrong query results as well.

On leaf pages we can apply the inverse of what the Equal strategy does.
On internal pages, use a correct implementation of what the previous
code intended: we can descend if the query value equals both bounds,
*so long as the bounds aren't truncated*.  With truncated bounds we
don't quite know the range of what's below, so we must always descend.

Adjust the code in gbt_num_consistent() to look similar, too.  This
fixes a performance buglet in that there's no need to do two comparisons
on a leaf entry, but the main point is just to keep code consistency.

Reported-by: 王跃林 <violin0613@tju.edu.cn>
Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/AH*AvQCYKhQGVvPWi1GiU4oY.8.1781609375063.Hmail.3020001251@tju.edu.cn
Backpatch-through: 14

11 days agoReverse-engineer some documentation for btree_gist's varlena modules.
Tom Lane [Fri, 3 Jul 2026 17:18:13 +0000 (13:18 -0400)] 
Reverse-engineer some documentation for btree_gist's varlena modules.

There are a number of rather subtle points about the behavior of
this code, which its original authors did not deign to document.
Try to improve that.  In particular, explain how internal and leaf
keys can differ and what the restrictions are on that.

This work arose from trying to fix some bugs, and in the process
I believe I've identified some more, but this patch does not attempt
to fix anything, only document it.  I did make a few purely cosmetic
code changes, such as removing dead (and confusing!) initializations
of variables and choosing more appropriate types for some pointers.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Discussion: https://postgr.es/m/AH*AvQCYKhQGVvPWi1GiU4oY.8.1781609375063.Hmail.3020001251@tju.edu.cn

11 days agoUse the proper comparator in gbt_bit_ssup_cmp.
Tom Lane [Fri, 3 Jul 2026 17:11:14 +0000 (13:11 -0400)] 
Use the proper comparator in gbt_bit_ssup_cmp.

If we're dealing with leaf entries, the function to call is bitcmp
not byteacmp.  Using byteacmp didn't lead to any obvious failure,
but it did result in sorting the entries in a way not matching the
datatype's actual sort order.  Hence the constructed index would be
less efficient than one would expect, and in particular worse than
what you got before this code was added in v18 (by commit e4309f73f).

We might want to recommend that users reindex btree_gist indexes
on bit/varbit columns.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Discussion: https://postgr.es/m/AH*AvQCYKhQGVvPWi1GiU4oY.8.1781609375063.Hmail.3020001251@tju.edu.cn
Backpatch-through: 18

11 days agoResolve unknown-type literals in GRAPH_TABLE COLUMNS
Peter Eisentraut [Fri, 3 Jul 2026 14:58:31 +0000 (16:58 +0200)] 
Resolve unknown-type literals in GRAPH_TABLE COLUMNS

The unknown-type literals in the COLUMNS clause of a GRAPH_TABLE are
now resolved to the appropriate types.  Without that, this could cause
various failures.

Author: Satya Narlapuram <satyanarlapuram@gmail.com>
Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Reviewed-by: Junwang Zhao <zhjwpku@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/CAHg%2BQDcyKNWyzDoKMxiZNjv7C-wAxs8y0ZoNkOV137Y%2Bnk3UXg%40mail.gmail.com

11 days agoPrevent access to other sessions' empty temp tables
Alexander Korotkov [Fri, 3 Jul 2026 12:53:03 +0000 (15:53 +0300)] 
Prevent access to other sessions' empty temp tables

Commit ce146621 ensures that ERROR is raised if a session tries to read
pages of another session's temp table.  But there is a corner case where
the other session's temp table is empty -- in this case the INSERT
command bypasses our checks and executes without any errors.

Such behavior is inconsistent and erroneous: it leaves an invalid buffer
in the temp buffers pool.  Since the buffer was created for another
session's temp table, we get an error "no such file or directory" when
trying to flush it.

This commit fixes it by adding a RELATION_IS_OTHER_TEMP check in the
relation-extension path.

Backpatch to 16, because it is the first release after 31966b151e6, which
introduced a separate local relation extension function
ExtendBufferedRelLocal(), which lacks of RELATION_IS_OTHER_TEMP() check.
As this fix introduces more checks to 013_temp_obj_multisession.pl, backpatch
the whole test script to 16.

Discussion: https://postgr.es/m/CAJDiXgiX2XZBHDNo%2BzBbvku%2BtchrUurvPRaN1_40mEQ1_sG90g%40mail.gmail.com
Author: Daniil Davydov <3danissimo@gmail.com>
Reviewed-by: Jim Jones <jim.jones@uni-muenster.de>
Reviewed-by: Imran Zaheer <imran.zhir@gmail.com>
Reviewed-by: ZizhuanLiu X-MAN <44973863@qq.com>
Backpatch-through: 16

11 days agoFix handling of dropping a property not associated with the given label
Peter Eisentraut [Fri, 3 Jul 2026 14:06:29 +0000 (16:06 +0200)] 
Fix handling of dropping a property not associated with the given label

When dropping a property by name from a label, the code checked only
whether the property existed in the graph's property catalog.  It did
not verify that the property was actually associated with the given
label, resulting in passing InvalidOid to performDeletion().  Fix it
by explicilty checking the label property association.

While at it also rearrange the code so as to avoid multiple ereport
calls for the same error in the same block.

Author: Chao Li <lic@highgo.com>
Reviewed-by: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/1DA5D52A-4AFA-426E-83F7-42ED974D682B%40gmail.com

11 days agoFix tracing of BackendKeyData and CancelRequest
Heikki Linnakangas [Fri, 3 Jul 2026 11:57:35 +0000 (14:57 +0300)] 
Fix tracing of BackendKeyData and CancelRequest

BackendKeyData length was increased from 4 bytes to a variable-length
length (up to 256 bytes) in a460251f0a. However, pqTrace still traces
it as a 4 bytes key, leading to a "mismatched message length" warning
message. The same issue impacts the tracing of CancelRequest.

This patch fixes the issue by using pqTraceOutputNchar instead of
pqTraceOutputInt32 in both cases.

Author: Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com>
Discussion: https://www.postgresql.org/message-id/CAO6_Xqo6gTv9=76H=k2qDRFU+KHuBiY2S=bQynEr6J8gS7L6xA@mail.gmail.com
Backpatch-through: 18

12 days agoFix REPACK CONCURRENTLY for stored generated columns
Álvaro Herrera [Fri, 3 Jul 2026 10:22:37 +0000 (12:22 +0200)] 
Fix REPACK CONCURRENTLY for stored generated columns

In order to replay concurrent changes, REPACK CONCURRENTLY needs the
pg_attrdef tuples for the transient table to be there, in case a tuple
is modified concurrently with REPACK and requires to store the value
from the generated column (which, with the current arrangements, means
all tuples concurrently updated or inserted).  Fix by creating a copy of
them from the original table.  Add a test that tickles the bug.

Author: Antonin Houska <ah@cybertec.at>
Reported-by: Ewan Young <kdbase.hack@gmail.com>
Diagnosed-by: Ewan Young <kdbase.hack@gmail.com>
Reviewed-by: Ewan Young <kdbase.hack@gmail.com>
Backpatch-through: 19
Discussion: https://postgr.es/m/CAON2xHMrELwx9vKg6niSf8fMBA=-MGXmG=MPQU6+vMVhGjF8kQ@mail.gmail.com

12 days agoPrevent dropping the last label from a property graph element
Peter Eisentraut [Fri, 3 Jul 2026 09:52:42 +0000 (11:52 +0200)] 
Prevent dropping the last label from a property graph element

Per SQL/PGQ standard, every graph element must have at least one
label.  When dropping a label from a graph element, ensure that there
exists at least one other label on the element.  If the label being
dropped is the only label on the element, raise an error.

We hold a ShareRowExclusiveLock when modifying a property graph.
Hence the label will not be dropped even when multiple labels are
being dropped concurrently.

Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Author: Satyanarayana Narlapuram <satyanarlapuram@gmail.com>
Reported-by: Satyanarayana Narlapuram <satyanarlapuram@gmail.com>
Discussion: https://www.postgresql.org/message-id/CAHg+QDeP=mTHTV48R23zKMy1SBmCKZ_L7-z5zKnYyw+K0x-gCg@mail.gmail.com

12 days agoAdd commit fdad19e1cf to .git-blame-ignore-revs.
Amit Kapila [Fri, 3 Jul 2026 08:35:21 +0000 (14:05 +0530)] 
Add commit fdad19e1cf to .git-blame-ignore-revs.

12 days agoFix log_statement_max_length test with verbose logs
Fujii Masao [Fri, 3 Jul 2026 05:41:44 +0000 (14:41 +0900)] 
Fix log_statement_max_length test with verbose logs

Buildfarm member prion reported a failure in the test added by commit
c8bd8387c27 to verify that the server logs an empty statement body
when log_statement_max_length = 0.

The test assumed that "statement:" would appear immediately after
"LOG:" in the logged statement message. However, prion runs with
log_error_verbosity = verbose, which inserts the SQLSTATE between
"LOG:" and the message text. As a result, the test failed even though
the server behaved correctly.

Per buildfarm member prion.

Discussion: https://postgr.es/m/CAHGQGwFiQKwvLVG+U0WWNo2kgkQ88FVGhYH_MBZu9Y0SJ8BjDw@mail.gmail.com

12 days agopsql: Fix \df tab completion for procedures
Fujii Masao [Fri, 3 Jul 2026 04:46:35 +0000 (13:46 +0900)] 
psql: Fix \df tab completion for procedures

Commit fb421231daa extended \df to include procedures, but its tab
completion continued not to show procedures.

Update \df tab completion to include procedures as well.

Backpatch to all supported versions.

Author: Erik Wienhold <ewie@ewie.name>
Reviewed-by: Surya Poondla <suryapoondla4@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/10fbfdfe-80f6-4ef9-b8b3-f7be0eb53a50@ewie.name
Backpatch-through: 14

12 days agopgindent fix for commit 53e6f51ee
Richard Guo [Fri, 3 Jul 2026 03:31:15 +0000 (12:31 +0900)] 
pgindent fix for commit 53e6f51ee

12 days agoFix typo in pg_stat_us_to_ms()
Michael Paquier [Fri, 3 Jul 2026 03:22:14 +0000 (12:22 +0900)] 
Fix typo in pg_stat_us_to_ms()

The function converts microseconds to milliseconds, but the parameter
name used "ms".

Thinko in ac8d53dae5ae.

Author: Tatsuya Kawata <kawatatatsuya0913@gmail.com>
Discussion: https://postgr.es/m/CAHza6qfek15rehnA0GXMCpF2z=Gy6C+3vmcWCMVkU4JiRD8k7g@mail.gmail.com

12 days agoSwitch Get[Local]BufferDescriptor() to use a signed value in input
Michael Paquier [Fri, 3 Jul 2026 03:07:30 +0000 (12:07 +0900)] 
Switch Get[Local]BufferDescriptor() to use a signed value in input

GetBufferDescriptor() and GetLocalBufferDescriptor() took a uint32
buffer index, but every real caller derives the index from a Buffer:
- Unsigned value for shared buffers.
- Signed value for local buffers.

Both routines now take in input a signed number, GetBufferDescriptor()
gaining an assertion checking that the input value is in the range
allowed by the GUC shared_buffers.  This work is a follow-up of
e18b0cb7344c, where we found that passing down a value for a local
buffer was undetected and finished outside the range of NBuffers.

While monitoring all the existing callers of *BufferDescriptor(), the
only consumer that passes does an unsigned value is ClockSweepTick(),
whose result is always a module of NBuffers.

Suggested-by: Andres Freund <andres@anarazel.de>
Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CAExHW5uzRMYVZsXXS3HXXT0fG_sNrpUhUqwP4NorhaCqH9JDhA@mail.gmail.com

12 days agoRemove replication slot advice from MultiXact wraparound hints
Fujii Masao [Fri, 3 Jul 2026 02:16:34 +0000 (11:16 +0900)] 
Remove replication slot advice from MultiXact wraparound hints

Previously, MultiXactId wraparound hints suggested dropping stale
replication slots. While that advice is appropriate for transaction ID
wraparound, where replication slots can hold back XID horizons,
it was misleading for MultiXactId wraparound. Following it could lead
users to drop replication slots unnecessarily without helping resolve
the MultiXactId wraparound condition.

MultiXact cleanup is not directly delayed by replication slots.
Instead, it depends on whether old MultiXactIds can still be seen
as live by running transactions.

This commit removes the replication slot advice from MultiXactId
wraparound hints, and documents that stale replication slots are
normally not relevant to resolving MultiXactId wraparound problems.

Backpatch to all supported branches.

BUG #18876
Reported-by: Haruka Takatsuka <harukat@sraoss.co.jp>
Author: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/18876-0d0b53bad5a1f4c1@postgresql.org
Backpatch-through: 14

12 days agoAdd log_statement_max_length GUC to limit logged statement text
Fujii Masao [Thu, 2 Jul 2026 23:47:18 +0000 (08:47 +0900)] 
Add log_statement_max_length GUC to limit logged statement text

Very large statements can make server logs grow unexpectedly. This is
particularly painful when applications accidentally or intentionally
send huge literal values and statement logging is enabled: the full
statement text may be written to the log even when DBA sees only
its leading part is useful for normal operations.

This commit adds log_statement_max_length GUC that limits the number
of bytes of statement text emitted by statement logging. The setting
applies to statements logged by log_statement, log_min_duration_statement,
log_min_duration_sample, and log_transaction_sample_rate. A positive
value truncates the logged statement body to at most that many bytes,
zero  logs an empty statement body, and the default value -1 preserves
the existing behavior of logging statements in full.

Truncation is byte-based, matching the GUC unit, but it clips only
at multibyte character boundaries so that the log output remains valid.
This setting does not affect statements logged because of
log_min_error_statement; handling error-statement logging can be
considered separately.

Author: Jim Jones <jim.jones@uni-muenster.de>
Author: Kirill Gavrilov <diphantxm@gmail.com>
Reviewed-by: Kirill Reshke <reshkekirill@gmail.com>
Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de>
Reviewed-by: Maxym Kharchenko <maxymkharchenko@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/CA+E0NR4S+NC6+QHyY_vUuQZMzLhKqczMx-jJVqtjAxF6+=JwAA@mail.gmail.com

12 days agopg_plan_advice: Don't generate FOREIGN_JOIN advice for a single relation.
Robert Haas [Thu, 2 Jul 2026 19:45:22 +0000 (15:45 -0400)] 
pg_plan_advice: Don't generate FOREIGN_JOIN advice for a single relation.

A foreign scan can target a single relation while still reaching the
fs_relids branch of pgpa_build_scan() -- for example, when postgres_fdw
pushes an aggregate down over one foreign table. In that case, no
advice should be emitted.

Author: Mahendra Singh Thalor <mahi6run@gmail.com>
Co-authored-by: Robert Haas <rhaas@postgresql.org>
Discussion: http://postgr.es/m/CAKYtNAofuAJBz6++SeikpCb=Y=MO1QgEuZNJ+KZOP2johF1r4Q@mail.gmail.com

12 days agoAdd commit d69fdf79b8 to .git-blame-ignore-revs.
Nathan Bossart [Thu, 2 Jul 2026 18:05:50 +0000 (13:05 -0500)] 
Add commit d69fdf79b8 to .git-blame-ignore-revs.

12 days agoRun pgindent and pgperltidy for previous 3 commits.
Nathan Bossart [Thu, 2 Jul 2026 18:05:50 +0000 (13:05 -0500)] 
Run pgindent and pgperltidy for previous 3 commits.

For ease of review, and to be able to put the indentation changes
in .git-blame-ignore-revs, I did not fix the indentation of the
last 3 commits.  Do that now.

Discussion: https://postgr.es/m/adZ4j88Dq9r8y9_9%40nathan

12 days agoRemove psql support for pre-v10 servers.
Nathan Bossart [Thu, 2 Jul 2026 18:05:50 +0000 (13:05 -0500)] 
Remove psql support for pre-v10 servers.

Per discussion, it seems like a good time to bump the minimum
supported version for various applications.  Our current policy is
to support at least 10 previous major versions, so this bumps the
minimum to v10 for the v20 release.  For reference, the minimum was
last bumped to v9.2 in 2021 for v15 (see commits 30e7c175b8,
e469f0aaf3cf0cab868a, and 492046fa9e).

For ease of review, and to be able to put the indentation changes
in .git-blame-ignore-revs, I did not fix the indentation in this
patch.  I'll push a separate pgindent commit after these changes
are applied.

Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/adZ4j88Dq9r8y9_9%40nathan

12 days agoRemove pg_upgrade support for upgrading from pre-v10 servers.
Nathan Bossart [Thu, 2 Jul 2026 18:05:50 +0000 (13:05 -0500)] 
Remove pg_upgrade support for upgrading from pre-v10 servers.

Per discussion, it seems like a good time to bump the minimum
supported version for various applications.  Our current policy is
to support at least 10 previous major versions, so this bumps the
minimum to v10 for the v20 release.  For reference, the minimum was
last bumped to v9.2 in 2021 for v15 (see commits 30e7c175b8,
e469f0aaf3cf0cab868a, and 492046fa9e).

For ease of review, and to be able to put the indentation changes
in .git-blame-ignore-revs, I did not fix the indentation in this
patch.  I'll push a separate pgindent commit after these changes
are applied.

Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/adZ4j88Dq9r8y9_9%40nathan

12 days agoRemove pg_dump/pg_dumpall support for dumping from pre-v10 servers.
Nathan Bossart [Thu, 2 Jul 2026 18:05:50 +0000 (13:05 -0500)] 
Remove pg_dump/pg_dumpall support for dumping from pre-v10 servers.

Per discussion, it seems like a good time to bump the minimum
supported version for various applications.  Our current policy is
to support at least 10 previous major versions, so this bumps the
minimum to v10 for the v20 release.  For reference, the minimum was
last bumped to v9.2 in 2021 for v15 (see commits 30e7c175b8,
e469f0aaf3cf0cab868a, and 492046fa9e).  As in previous changes of
this sort, we aren't removing pg_restore's ability to read older
archive files, though it's fair to wonder how that might be tested
nowadays.

For ease of review, and to be able to put the indentation changes
in .git-blame-ignore-revs, I did not fix the indentation in this
patch.  I'll push a separate pgindent commit after these changes
are applied.

Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/adZ4j88Dq9r8y9_9%40nathan

13 days agoUse ssup_datum_*_cmp in more places
John Naylor [Thu, 2 Jul 2026 08:53:44 +0000 (15:53 +0700)] 
Use ssup_datum_*_cmp in more places

The int2, oid, and oid8 "fastcmp" comparators are functionally
equivalent to the ssup_datum_int32_cmp (for int2) and
ssup_datum_unsigned_cmp (for oid, oid8) functions added by commit
697492434, so simplify by using the latter instead. This has the
added benefit of making these types eligible for radix sort.

Author: Baji Shaik <baji.pgdev@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CA+fm-RMyLC94NfrxCh273+dKs44U0ZJjRczznvzvgw=KtpPNVw@mail.gmail.com

13 days agotest_custom_stats: Fail if loading module outside shared_preload_libraries
Michael Paquier [Thu, 2 Jul 2026 06:52:46 +0000 (15:52 +0900)] 
test_custom_stats: Fail if loading module outside shared_preload_libraries

Previously, test_custom_var_stats and test_custom_fixed_stats silently
skipped pgstat_register_kind() when not loaded via
shared_preload_libraries, behavior inherited from injection_points.
This left the SQL functions callable without the kind registered,
leading to various issues on the backend side.

This code is not designed to work without the pgstats kinds registered.
pgstat_register_kind() gets now called when these libraries are loaded,
with or without shared_preload_libraries, letting the registration fail
if loading the modules at a later step than startup.  test_custom_rmgrs
does the same thing.

Oversight in 31280d96a648.

Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Ewan Young <kdbase.hack@gmail.com>
Discussion: https://postgr.es/m/akS/ldidWeqG1FWk@bdtpg
Backpatch-through: 19

13 days agoFix loss of precision in pg_stat_us_to_ms()
John Naylor [Thu, 2 Jul 2026 06:26:56 +0000 (13:26 +0700)] 
Fix loss of precision in pg_stat_us_to_ms()

Multiplying by the constant 0.001 can produce trailing-digit noise in
displayed values (for example 0.009000000000000001 instead of 0.009,
with default extra_float_digits) because 0.001 cannot be represented
exactly in binary floating point. Use division by 1000.0 instead,
matching code elsewhere in the tree.

Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Discussion: https://postgr.es/m/akIYkMK4bHe9qX/N@bdtpg

13 days agoRemove stale comment
John Naylor [Thu, 2 Jul 2026 06:15:35 +0000 (13:15 +0700)] 
Remove stale comment

Commit 732e6677a added a member to TimeoutType, invalidating the
comment on EnableTimeoutParams.type. Rather than documenting the list,
as is done for vars that should only take a subset of enum values,
just remove the comment.

Author: Xuneng Zhou <xunengzhou@gmail.com>
Discussion: https://postgr.es/m/CABPTF7XuFqwOcBJ1x0rTKvEvvQ+zfZVidmjTybJPmu9_zTL6Ug@mail.gmail.com

13 days agoExpand comment on the slot recheck in drop_local_obsolete_slots().
Amit Kapila [Thu, 2 Jul 2026 04:04:17 +0000 (09:34 +0530)] 
Expand comment on the slot recheck in drop_local_obsolete_slots().

The existing comment explained that a user-created slot could reuse the
same shared memory as 'local_slot' during the window between selecting a
slot to drop and locking its database, and that we therefore recheck
before dropping.  It did not, however, spell out the fuller consequence:
because local_slot points to a reusable slot-array entry, its fields may
already describe a replacement slot, so the earlier drop decision and the
slot_database used for locking could relate to an unrelated slot/database.

Expand the comment to describe this, and note that the recheck prevents
us from dropping a user-created replacement slot while the residual risk
(such as briefly locking an unrelated database) is confined to the cycle
and is acceptable given the race is rare and non-fatal.

No functional change.

Author: Fujii Masao <masao.fujii@gmail.com>
Author: Xuneng Zhou <xunengzhou@gmail.com>
Author: Amit Kapila <amit.kapila16@gmail.com>
Discussion: https://postgr.es/m/CAHGQGwGGyEDL3dh7uJ6qPsGvnq4QK_R8+U=12CaprnzwrwaLGA@mail.gmail.com
Discussion: https://postgr.es/m/CAHGQGwHqQ1PPVFfYKVxLfRyC-byRdwSN0NeaHj9SLYV97oO5cw@mail.gmail.com

13 days agoFix jsonpath .decimal() to honor silent mode
Michael Paquier [Thu, 2 Jul 2026 03:44:29 +0000 (12:44 +0900)] 
Fix jsonpath .decimal() to honor silent mode

The jsonpath .decimal(precision[, scale]) method built its numeric
typmod by calling numerictypmodin() through DirectFunctionCall1(), which
can throw a hard error for an incorrect set of precision and/or scale
vaulues.  This breaks the silent mode supported by this function, that
should not fail.

Most of the jsonpath code uses the soft error reporting to bypass
errors, which is what this fix does by avoiding a direct use of
numerictypmodin().  Its code is refactored to use a new routine called
make_numeric_typmod_safe(), able to take an error context in input.
numerictypmodin() sets no context, mapping to its previous behavior.
The jsonpath code sets or not a context depending on the use of the
silent mode.  This result leads to some nice simplifications:
numerictypmodin() feeds on an array, we can now pass directly values for
the scale and precision.

Oversight in 66ea94e8e606.

Author: Ewan Young <kdbase.hack@gmail.com>
Discussion: https://postgr.es/m/CAON2xHMaigKABiyPBBq3Sjd3gp7uWMJXnnMHt=s85V1ij3KP1w@mail.gmail.com
Backpatch-through: 17

13 days agopgindent fix for commit a5918fddf1.
Amit Kapila [Thu, 2 Jul 2026 03:19:37 +0000 (08:49 +0530)] 
pgindent fix for commit a5918fddf1.

13 days agoAllow logical replication conflicts to be logged to a table.
Amit Kapila [Thu, 2 Jul 2026 02:14:27 +0000 (07:44 +0530)] 
Allow logical replication conflicts to be logged to a table.

Until now, logical replication conflicts were only written as plain text
to the server log, which is hard to query, analyze, or feed into external
monitoring and automation.

This commit adds a conflict_log_destination option to CREATE SUBSCRIPTION
and ALTER SUBSCRIPTION that controls where conflicts are recorded. It
accepts 'log' (the existing behavior), 'table', or 'all'.

When table logging is enabled ('table' or 'all'), an internal log table
named pg_conflict_log_<subid> is created automatically in a dedicated,
system-managed pg_conflict namespace. Using a separate namespace avoids
collisions with user table names and lets the table be shielded from
direct modification. The table is tied to the subscription through an
internal dependency, so it is dropped automatically when the subscription
is removed.

The conflict details, including the local and remote tuples, are stored in
JSON columns, so a single table layout can accommodate rows from tables
with different schemas. The table also records the local and remote
transaction IDs, LSNs, commit timestamps, and the conflict type, providing
a complete record for post-mortem analysis.

A per-subscription table was chosen over a single global log because it
aligns table ownership with the subscription lifecycle. This keeps
permission management simple: the subscription owner can perform the
permitted maintenance operations without the security concerns or
Row-Level Security that a shared table would require.

Because the table is system-managed, it is protected from direct
manipulation: DDL (such as ALTER, DROP, CREATE INDEX, and adding a
trigger, rule, policy, or extended statistics), use as an inheritance
parent or a foreign-key target, and manual INSERT, UPDATE, MERGE, or row
locking are all rejected.  Only DELETE and TRUNCATE are permitted, so that
users can prune old conflict rows.

Conflict log tables are also excluded from publications, even those
defined with FOR ALL TABLES or FOR TABLES IN SCHEMA.

This commit only establishes the conflict log table along with its
creation, cleanup, and protection; recording the conflicts detected
during apply into the table will be handled in a follow-up commit.

Author: Dilip Kumar <dilipbalaut@gmail.com>
Author: Nisha Moond <nisha.moond412@gmail.com>
Author: Amit Kapila <akapila@postgresql.org>
Reviewed-by: Shveta Malik <shveta.malik@gmail.com>
Reviewed-by: Vignesh C <vignesh21@gmail.com>
Reviewed-by: Peter Smith <smithpb2250@gmail.com>
Reviewed-by: Shlok Kyal <shlok.kyal.oss@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Discussion: https://postgr.es/m/CAFiTN-u5D5o_AGNbHRZHaOqAMWkxLf%2BhSk_r9X3gv6HbLOB5%2Bg%40mail.gmail.com

13 days agoAdd system view pg_stat_kind_info
Michael Paquier [Thu, 2 Jul 2026 00:34:21 +0000 (09:34 +0900)] 
Add system view pg_stat_kind_info

This commit adds support for pg_stat_kind_info, that exposes at SQL
level data about the statistics kinds registered into a backend:
- Meta-data of a stats kind (built-in or custom, some properties).
- Number of entries, if tracking is enabled.

We have discussed the possibility of more fields (like shared memory
size for a single entry); this adds the minimum agreed on.

This is in spirit similar to pg_get_loaded_modules() for custom stats
kinds, this view providing detailed information about the stats kinds
when registered through shared_preload_libraries.

Bump catalog version.

Author: Tristan Partin <tristan@partin.io>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Sami Imseih <samimseih@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/DI6OFGHJ1B69.25YVDEP3BABRH@partin.io

13 days agoAdd min() and max() aggregate support for uuid.
Masahiko Sawada [Wed, 1 Jul 2026 18:42:54 +0000 (11:42 -0700)] 
Add min() and max() aggregate support for uuid.

The uuid type already has a full set of comparison operators and a
btree operator class, so it is totally ordered.  min() and max() were
the only common aggregates missing for it. Add the uuid_larger() and
uuid_smaller() support functions and register the min(uuid) and
max(uuid) aggregates that use them.

uuid values are compared lexicographically over their 128 bits.  For
UUIDv7, whose most significant bits encode a Unix timestamp, this
coincides with chronological order, so min() and max() return the
oldest and newest values.

Bump catalog version.

Author: Tristan Partin <tristan@partin.io>
Reviewed-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Reviewed-by: Zsolt Parragi <zsolt.parragi@percona.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Discussion: https://postgr.es/m/DJGML0T9FCDV.3VA29JLODXEHZ@partin.io

13 days agoFix macro-redefinition warning introduced by aeb07c55f.
Tom Lane [Wed, 1 Jul 2026 17:44:45 +0000 (13:44 -0400)] 
Fix macro-redefinition warning introduced by aeb07c55f.

Some platforms provide a definition of unreachable() in standard C
headers, leading to a conflict with unreachable() in the new
timezone code.  It seems best for our purposes to conform to what
pg_unreachable() does, so #undef away the platform version.

Reported-by: Tristan Partin <tristan@partin.io>
Discussion: https://postgr.es/m/DJNDN9UQS9GP.11L4NJ1HHE1ZJ@partin.io

13 days agobtree_gist: fix NaN handling in float4/float8 opclasses.
Tom Lane [Wed, 1 Jul 2026 17:27:22 +0000 (13:27 -0400)] 
btree_gist: fix NaN handling in float4/float8 opclasses.

The float4 and float8 btree_gist opclasses compared keys with raw C
operators (==, <, >).  IEEE 754 makes every comparison involving NaN
false, so GiST disagreed with the regular float comparison operators
and with the btree opclass, which uses float[4|8]_cmp_internal()
(so that all NaNs are equal and NaN sorts after every non-NaN value).

In addition, the penalty and distance functions were not careful
about NaNs, and the penalty functions could also misbehave for IEEE
infinities.  Wrong answers from the penalty functions would probably
do no more than make the index non-optimal, but the distance mistakes
were visible from SQL.

To fix, make the comparison functions rely on the same NaN-aware
comparison functions the core code uses, and rewrite the penalty
and distance functions to follow the rules that NaNs are equal
but maximally far away from non-NaNs.  The penalty_num() code was
formerly shared between integral and float cases, but I chose to make
two copies so that the integral cases are not saddled with the extra
logic for NaNs and infinities/overflows.  I also rewrote it as static
inline functions instead of an unreadable and uncommented macro.

The float penalty functions were previously unreached by the
regression tests, so add new test cases to exercise them.

There's no on-disk format change, but users who have NaN entries
in a btree_gist index would be well advised to reindex it.

Bug: #19501
Bug: #19524
Reported-by: Man Zeng <zengman@halodbtech.com>
Reported-by: Yuelin Wang <3020001251@tju.edu.cn>
Author: Bill Kim <billkimjh@gmail.com>
Co-authored-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/19501-3bff3bbc97f1e7c9@postgresql.org
Discussion: https://postgr.es/m/19524-9559d302c8455664@postgresql.org
Discussion: https://postgr.es/m/CAMQXxcgbtD2LXfX0tpgvOizxP-XxrCHV2ZDy4By_TZnJMsxXWQ@mail.gmail.com
Backpatch-through: 14

13 days agodoc: Fix pg_stat_autovacuum_scores descriptions.
Nathan Bossart [Wed, 1 Jul 2026 15:47:53 +0000 (10:47 -0500)] 
doc: Fix pg_stat_autovacuum_scores descriptions.

The descriptions of the component scores state that values greater
than or equal to the corresponding weight parameter mean autovacuum
will process the table.  However, since the code that determines
whether to vacuum or analyze a table actually checks whether the
threshold is exceeded, it's more accurate to say "greater than"
there.

Author: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Sami Imseih <samimseih@gmail.com>
Discussion: https://postgr.es/m/E3ABDC6B-80CA-4C37-BA0B-A519D49F4C66%40gmail.com
Backpatch-through: 19

13 days agoImprove the names generated for indexes on expressions.
Tom Lane [Wed, 1 Jul 2026 15:33:52 +0000 (11:33 -0400)] 
Improve the names generated for indexes on expressions.

If the user doesn't specify a name for an index, it's generated
based on the names chosen for the index columns (which the user
has no direct control over).  For index columns that are just
columns of the base relation, the index column name is the same as
the base column name; but for index columns that are expressions,
it's less clear what to do.  Up to now, what we have done is
equivalent to the heuristics used to choose SELECT output column
names, except that we fall back to "expr" not "?column?" in the
numerous cases that FigureColname doesn't know what to do with.
This is not tremendously helpful.  More, it frequently leads to
collisions of generated index names, which we can handle but
only at the cost of user confusion; also there's some risk of
concurrent index creations trying to use the same name.
Let's try to do better.

Messing with the FigureColname heuristics would have a very
large blast radius, since that affects the column headings
that applications see.  That doesn't seem wise, but fortunately
SQL queries are seldom directly concerned with index names.
So we should be able to change the index-name generation rules
as long as we decouple them from FigureColname.

The method used in this patch is to dig through the expression,
extract the names of Vars, the string representations of Consts,
and the names of functions, and run those together with underscores
between.  Other expression node types are ignored but descended
through.  We could work harder by handling more node types, but
it seems like this is likely to be sufficient to arrive at unique
index names in many cases.

Notably, this rule ignores the names of operators, for example
both "a + b" and "a * b" will be rendered as "a_b".  This choice
was made to reduce the probability of having to double-quote
the index name.

I've also chosen to strip Const representations down to only
alphanumeric characters (plus non-ASCII characters, which our
parser treats as alphabetic anyway).  So for example "x + 1.0"
would be represented as "x_10".  This likewise avoids possible
quoting problems.  I also considered limiting how many characters
we'd take from each Const, but didn't do that here.

We might tweak these rules some more after we get some experience
with this patch.  It's being committed at the start of a
development cycle to provide as much time as possible to gather
feedback.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Discussion: https://postgr.es/m/876799.1757987810@sss.pgh.pa.us
Discussion: https://postgr.es/m/18959-f63b53b864bb1417@postgresql.org

13 days agoSync our copy of the timezone library with IANA release tzcode2026b.
Tom Lane [Wed, 1 Jul 2026 14:56:46 +0000 (10:56 -0400)] 
Sync our copy of the timezone library with IANA release tzcode2026b.

This was moderately tedious, because upstream has been busy
since we last did this in 2020.

Notably, they changed the signatures of both tzload() and tzparse(),
which we'd unwisely exposed as API for callers to use.  I concluded
that the best answer was to change them both back to "static" and
instead expose a new API function of our own choosing, pg_tzload().

That change may be a sufficient reason not to back-patch this update,
as I'd normally want to do.  There's probably not a good reason for
extensions to be calling those functions, but on the other hand
there are few pressing reasons for a back-patch.  The one bug we have
run into (a Valgrind uninitialized-data complaint about zic) appears
to have no field-visible consequences.

A few of the files generated by this version of zic are not
byte-for-byte the same as before, but "zdump -v" avers that
they represent the same sets of transitions.

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

13 days agoFix CPU-identification macros for RISC-V.
Tom Lane [Wed, 1 Jul 2026 14:10:21 +0000 (10:10 -0400)] 
Fix CPU-identification macros for RISC-V.

Turns out that RISC-V intentionally doesn't follow the common
naming pattern for CPU-identification macros.  But the point of
2ef57e636 is to have a common pattern, so we're going to override
their opinion.

Discussion: https://postgr.es/m/CA+hUKGL8Hs-phHPugrWM=5dAkcT897rXyazYzLw-Szxnzgx-rA@mail.gmail.com

13 days agoClear base backup progress on backup failure
Fujii Masao [Wed, 1 Jul 2026 14:03:08 +0000 (23:03 +0900)] 
Clear base backup progress on backup failure

Previously, if a base backup failed after it had started streaming
files, pg_stat_progress_basebackup could continue to show a stale
progress entry even though the backup was no longer running. This could
be observed when the client kept the replication connection open after
the error. It is normally not observable when using pg_basebackup,
because the client disconnects after the error.

The problem was that progress reporting was cleared only after
successful completion.

This commit moves the progress reporting cleanup into the progress
sink's cleanup callback so that it is cleared after both successful
and failed backups.

Backpatch to v15. v14 has the same issue, but the fix does not apply
cleanly because it lacks the base backup sink infrastructure. Since
the bug does not affect the backup itself and is normally not
observable when using pg_basebackup, skip the v14 backpatch.

Author: Chao Li <lic@highgo.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/EA1A6CD2-EFA6-462B-9A02-03003555AB4A@gmail.com
Backpatch-through: 15

13 days agoWarn on password auth with MD5-encrypted passwords
Fujii Masao [Wed, 1 Jul 2026 11:57:28 +0000 (20:57 +0900)] 
Warn on password auth with MD5-encrypted passwords

Commit bc60ee860 added a connection warning after successful MD5
authentication, but only for the md5 authentication method. A role with
an MD5-encrypted password can also authenticate via the password method,
which left that path without the same deprecation warning.

Emit the MD5 deprecation connection warning after successful
password authentication as well, when the stored password is
MD5-encrypted.

Backpatch to v19, where the MD5 connection warning was introduced.

Author: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Japin Li <japinli@hotmail.com>
Discussion: https://postgr.es/m/CAHGQGwGkWfn5rtHzvdRbVk+PCefQU3gun3hc7QnaMXHFa5Bu3w@mail.gmail.com
Backpatch-through: 19

13 days agoFix mismatched deallocation functions
Peter Eisentraut [Wed, 1 Jul 2026 11:48:45 +0000 (13:48 +0200)] 
Fix mismatched deallocation functions

In fe_memutils.h, we have various allocation functions beginning with
either pg_ or p.  The pg_ functions have a matching pg_free() for
freeing memory, while the p functions use pfree().  In some cases, we
were allocating memory with one set of functions while using the wrong
deallocation functions.  This creates a tiny bit of mental overhead
when reading code.  Matching up allocation and deallocation functions
makes it easier to analyze memory handling in a code path.

Author: Tristan Partin <tristan@partin.io>
Reviewed-by: Zsolt Parragi <zsolt.parragi@percona.com>
Discussion: https://www.postgresql.org/message-id/flat/DIBZE2B6SVF2.28R3EQTYJSWIG@partin.io

2 weeks agoSplit dry-run messages into primary and detail
Peter Eisentraut [Wed, 1 Jul 2026 08:12:33 +0000 (10:12 +0200)] 
Split dry-run messages into primary and detail

Fixup for commit c05dee19112.  It fits better with the style and APIs
to print separate primary and a detail messages instead of one
multiline message.

Reviewed-by: Euler Taveira <euler@eulerto.com>
Reviewed-by: Peter Smith <smithpb2250@gmail.com>
Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de>
Discussion: https://postgr.es/m/CAHut+PsvQJQnQO0KT0S2oegenkvJ8FUuY-QS5syyqmT24R2xFQ@mail.gmail.com

2 weeks agoDon't cast off_t to 32-bit type for output, bug fix
Peter Eisentraut [Wed, 1 Jul 2026 07:39:42 +0000 (09:39 +0200)] 
Don't cast off_t to 32-bit type for output, bug fix

off_t is most likely a 64-bit integer, so casting it to a 32-bit type
for output could lose data.  There are more issues like this in the
tree, but this is an instance where this could actually happen in
practice, since base backups are routinely larger than 4 GB.  So this
is separated out as a bug fix.

Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Discussion: https://www.postgresql.org/message-id/flat/20ce62fa-47fc-457b-b504-12f3c1651726%40eisentraut.org

2 weeks agoUse C11 alignas instead of pg_attribute_aligned
Peter Eisentraut [Mon, 29 Jun 2026 08:46:51 +0000 (10:46 +0200)] 
Use C11 alignas instead of pg_attribute_aligned

Replace pg_attribute_aligned with C11 alignas, for consistency with
current conventions.

(These new uses were added by commit fbc57f2bc2e, which was developed
concurrently with the switch from pg_attribute_aligned to C11 standard
alignas, and it ended up being committed with the "old" style.)

Reviewed-by: John Naylor <johncnaylorls@gmail.com>
Discussion: https://postgr.es/m/CANWCAZaKhE+RD5KKouUFoxx1EbUNrNhcduM1VQ=DkSDadNEFng@mail.gmail.com

2 weeks agoImprove UNION's output row count estimate
Richard Guo [Wed, 1 Jul 2026 06:12:43 +0000 (15:12 +0900)] 
Improve UNION's output row count estimate

A UNION (not UNION ALL) removes duplicates, so its output has no more
rows than its input.  The planner did not account for this: it set the
set-op relation's row count to the total size of the appended input,
as though dedup removed nothing.  That inflated estimate then
propagated to every node above the UNION, leading to poor plan choices
such as a hash join with a full table scan where an index nested loop
would have been cheaper.

This patch estimates the number of distinct output rows as the sum of
the per-child distinct-group estimates instead.  This relies on the
fact that:

  distinct(A union B) <= distinct(A) + distinct(B)

that is, the union cannot have more distinct rows than its children do
in total.  And because each child's distinct-group estimate never
exceeds that child's row-count estimate, this sum is never larger than
the old estimate, so it only tightens the previous over-estimate.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Reviewed-by: Chengpeng Yan <chengpeng_yan@outlook.com>
Discussion: https://postgr.es/m/CAMbWs48Fu1nhGXPa60oc+adj7ge4dn0nHhqngqKvOVVQP61duA@mail.gmail.com

2 weeks agoAvoid useless calls in pg_get_multixact_stats()
Michael Paquier [Wed, 1 Jul 2026 03:17:17 +0000 (12:17 +0900)] 
Avoid useless calls in pg_get_multixact_stats()

MultiXactOffsetStorageSize() and GetMultiXactInfo() are called to gather
the information reported by the function, but were wasteful for the case
where a role does not have the privileges of pg_read_all_stats, where we
return a set of NULLs.  These calls are moved to the code path where
their results are used.

Author: Ranier Vilela <ranier.vf@gmail.com>
Discussion: https://postgr.es/m/CAEudQAonQh7be=wOR-CJFW=bgMBz5wW_bv4t0OFxbgn-794JCQ@mail.gmail.com
Backpatch-through: 19

2 weeks agoDocument wal_compression=on
John Naylor [Wed, 1 Jul 2026 01:50:08 +0000 (08:50 +0700)] 
Document wal_compression=on

Commit 4035cd5d4 added LZ4 compression for full-page writes in WAL, and
retained "on" as a backward-compatible way to specify the builtin PGLZ
method. Document this meaning of "on" and update postgresql.conf.sample
to make the equivalence clear.

Author: Christoph Berg <myon@debian.org>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/akJDHRtXwGLTppsQ@msg.df7cb.de
Backpatch-through: 15

2 weeks agodoc: Add new section describing fast-path locking
Michael Paquier [Wed, 1 Jul 2026 01:08:26 +0000 (10:08 +0900)] 
doc: Add new section describing fast-path locking

Fast-path locking is referenced by pg_stat_lock.fastpath_exceeded, by
pg_locks.fastpath, and in the GUC max_locks_per_transaction.  However,
the documentation has never described in details how this works; one
would need to look at the internals of lock.c, mostly around
EligibleForRelationFastPath().

This commit adds a new subsection called "Fast-Path Locking" to the area
dedicated to locks, with the three places mentioned above linking to it.

Author: Tatsuya Kawata <kawatatatsuya0913@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CAHza6qdKo9dcPy70QBi88vpqhS2gYWViS8=Uj=-+QQbR=ONgSQ@mail.gmail.com

2 weeks agoRemove radius from initdb authentication methods.
Thomas Munro [Tue, 30 Jun 2026 23:25:37 +0000 (11:25 +1200)] 
Remove radius from initdb authentication methods.

Commit a1643d40b removed RADIUS authentication, but apparently
overlooked initdb's list of accepted authentication methods.  As a
result, initdb still accepted radius for --auth, --auth-host, and
--auth-local, allowing it to create a pg_hba.conf that the server could
not load.

Remove radius from initdb's local and host authentication method lists.

Backpatch-through: 19
Author: Chao Li <lic@highgo.com>
Discussion: https://postgr.es/m/983F946B-A7CE-4C93-B5F0-665616F72254%40gmail.com

2 weeks agoDisallow set-returning functions within window OVER clauses.
Tom Lane [Tue, 30 Jun 2026 21:21:23 +0000 (17:21 -0400)] 
Disallow set-returning functions within window OVER clauses.

We previously allowed this, but it leads to odd behaviors, basically
because putting a SRF there is inconsistent with the principle that a
window function doesn't change the number of rows in the query result.
There doesn't seem to be a strong reason to try to make such cases
behave consistently.  Users should put their SRFs in lateral FROM
clauses instead.

This issue has been sitting on the back burner for multiple years
now, partially because it didn't seem wise to back-patch such a
change.  Let's squeeze it into v19 before it's too late.

Bug: #17502
Bug: #19535
Reported-by: Daniel Farkaš <daniel.farkas@datoris.com>
Reported-by: Qifan Liu <imchifan@163.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/17502-281a7aaacfaa872a@postgresql.org
Discussion: https://postgr.es/m/19535-376081d7cc07c86d@postgresql.org
Backpatch-through: 19

2 weeks agodoc: clarify MERGE PARTITIONS adjacency requirement
Alexander Korotkov [Tue, 30 Jun 2026 19:29:43 +0000 (22:29 +0300)] 
doc: clarify MERGE PARTITIONS adjacency requirement

The existing description says the ranges of merged range-partitions
"must be adjacent" only under the heading "If the DEFAULT partition is
not in the list of merged partitions".  That could be misread as
a restriction tied to the presence of a default partition.  In fact,
merging non-adjacent ranges is rejected regardless of whether
the partitioned table has a default partition; spell that out explicitly.

Also, this commit removes a small redundancy in the documentation sentence
stating that "merged range-partitions" are "to be merged".

Reported-by: Justin Pryzby <pryzby@telsasoft.com>
Discussion: https://postgr.es/m/aj6BPoziSb-F8aJz%40pryzbyj2023
Reported-by: Pavel Borisov <pashkin.elfe@gmail.com>
Backpatch-through: 19

2 weeks agoClean up inconsistencies in CPU-identification macros.
Tom Lane [Tue, 30 Jun 2026 16:21:06 +0000 (12:21 -0400)] 
Clean up inconsistencies in CPU-identification macros.

In various places we depend on compiler-defined macros like __x86_64__
to guard CPU-type-specific code.  However, those macros aren't very
well standardized; in particular, it emerges that MSVC doesn't define
any of the ones gcc does, but has its own.  We were not coping with
that consistently, with the result that we're missing some useful
CPU-dependent optimizations in MSVC builds.  There are also some
places that are checking randomly-different spellings that may
have been the only ones recognized by some old compilers, but we
weren't doing that consistently either.

Let's standardize on using gcc's long-form spellings (with trailing
underscores), after putting a stanza into c.h that ensures that these
spellings are defined even when the compiler provides some other one.

I put an "#else #error" branch into the c.h addition so that we'll
get an error if the compiler provides none of the symbols we're
expecting.  That might be best removed in the end, since it might
annoy people trying to port to some new CPU type.  But for testing
this it seems like a good idea, in case we've missed some common
variant spelling.

In addition to enabling some optimizations we previously missed on
MSVC, this cleans up a thinko.  Several places used "_M_X64" in the
apparent belief that that's MSVC's equivalent to __x86_64__, but
it's not: it will also get defined on some but not all ARM64 builds.

Also, guard the x86_feature_available() stuff in pg_cpu.[hc] with
#if defined(__x86_64__) || defined(__i386__)
which seems like a more natural way of specifying what it applies to.

This builds on some previous work by Thomas Munro, but it requires
much less code churn because it re-uses gcc's names for the CPU-type
macros instead of inventing our own.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CA+hUKGL8Hs-phHPugrWM=5dAkcT897rXyazYzLw-Szxnzgx-rA@mail.gmail.com
Discussion: https://postgr.es/m/3035145.1780503430@sss.pgh.pa.us

2 weeks agoRemove pg_spin_delay().
Nathan Bossart [Tue, 30 Jun 2026 15:57:54 +0000 (10:57 -0500)] 
Remove pg_spin_delay().

This code appears to be an artifact from commit b64d92f1a5 that was
never used for anything.

Reviewed-by: Corey Huinker <corey.huinker@gmail.com>
Discussion: https://postgr.es/m/afouZUH_eUkIj4i4%40nathan

2 weeks agoMake SPI_prepare argtypes argument const
Peter Eisentraut [Tue, 30 Jun 2026 13:43:56 +0000 (15:43 +0200)] 
Make SPI_prepare argtypes argument const

This changes the argtypes argument of SPI_prepare(),
SPI_prepare_cursor(), SPI_cursor_open_with_args(), and
SPI_execute_with_args() from Oid *argtypes to const Oid *argtypes.
The underlying functions were already receptive to that, so this
doesn't require any significant changes beyond the function signatures
and some internal variables.

Commit 28972b6fc3dc recently introduced a case where a const had to be
cast away before calling these functions.  This is fixed here.

In passing, make a very similar const addition to SPI_modifytuple().

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Ewan Young <kdbase.hack@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/86b5162f-c472-40fa-997b-0450dece1dec%40eisentraut.org

2 weeks agoFixes for SPI "const Datum *" use
Peter Eisentraut [Tue, 30 Jun 2026 12:03:10 +0000 (14:03 +0200)] 
Fixes for SPI "const Datum *" use

Fixup for commit 8a27d418f8f, which converted many functions to use
"const Datum *" instead of "Datum *", including some SPI functions.

For SPI_cursor_open(), the code was updated but not the documentation.
For SPI_cursor_open_with_args(), the documentation was updated but not
the code.  (Possibly, these two were confused with each other.)  Also,
SPI_execp() and SPI_modifytuple() were not updated, even though they
are closely related to the functions touched by the previous commit
and now look inconsistent.  Fix all these.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/86b5162f-c472-40fa-997b-0450dece1dec%40eisentraut.org

2 weeks agoAdd backend-level lock statistics
Michael Paquier [Tue, 30 Jun 2026 07:59:20 +0000 (16:59 +0900)] 
Add backend-level lock statistics

This commit adds per-backend lock statistics, providing the same
information as pg_stat_lock.  It is now possible to retrieve those stats
(lock wait counts, wait times, and fast-path exceeded count) on a
per-backend basis.

This data can be retrieved with a new system function called
pg_stat_get_backend_lock(), that returns one tuple per lock type based
on the PID provided in input.  Like pg_stat_get_backend_io(), this is
useful if joined with pg_stat_activity to get a live picture of the
locks behavior for each running backend.

pgstat_flush_backend() gains a new flag value, able to control the flush
of the lock stats.

This commit is straight-forward, relying on the infrastructure provided
by 9aea73fc61d4 (backend-level pgstats).

Bump catalog version.  No need to touch PGSTAT_FILE_FORMAT_ID as backend
statistics are never written to disk.

Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Tatsuya Kawata <kawatatatsuya0913@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Tristan Partin <tristan@partin.io>
Reviewed-by: Rui Zhao <zhaorui126@gmail.com>
Discussion: https://postgr.es/m/aiAzEY+cMQb/W8yu@bdtpg

2 weeks agoRefactor pg_stat_get_lock() to use a helper function
Michael Paquier [Tue, 30 Jun 2026 07:24:34 +0000 (16:24 +0900)] 
Refactor pg_stat_get_lock() to use a helper function

This commit extracts the tuple-building logic from pg_stat_get_lock()
into a new static helper pg_stat_lock_build_tuples().  This is in
preparation for a follow-up patch, to add support for backend-level lock
stats, which will reuse the same helper.

This change follows the pattern established by pg_stat_io_build_tuples()
for IO stats and pg_stat_wal_build_tuple() for WAL stats.

Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Tatsuya Kawata <kawatatatsuya0913@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Tristan Partin <tristan@partin.io>
Reviewed-by: Rui Zhao <zhaorui126@gmail.com>
Discussion: https://postgr.es/m/aiAzEY+cMQb/W8yu@bdtpg

2 weeks agoUse placeholders and not GUC names in error message (autovacuum)
Michael Paquier [Tue, 30 Jun 2026 07:16:56 +0000 (16:16 +0900)] 
Use placeholders and not GUC names in error message (autovacuum)

A placeholder %s is now used instead of the GUC names in the error
string of this routine.  This is going to be useful for a follow-up
patch, where we will be able to reuse the same string, hence reducing
the translation work.

Based on a suggestion by me.

Author: Baji Shaik <baji.pgdev@gmail.com>
Discussion: https://postgr.es/m/ajnhfw84reaXgjfO@paquier.xyz

2 weeks agoChange stat_lock.wait_time to double precision
Michael Paquier [Tue, 30 Jun 2026 03:47:34 +0000 (12:47 +0900)] 
Change stat_lock.wait_time to double precision

Other statistics views (pg_stat_io, pg_stat_database, etc.) use float8
for all measured-time columns, the new pg_stat_lock standing out as an
outlier by using bigint.

This commit aligns pg_stat_lock with the other stats views for
consistency.  Like pg_stat_io, the time is stored in microseconds, and
is displayed in milliseconds with a conversion done when the view is
queried.

While on it, replace a use of "long" by PgStat_Counter, the former could
overflow for large wait times where sizeof(long) is 4 bytes (aka WIN32).

Bump catalog version.

Author: Tatsuya Kawata <kawatatatsuya0913@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CAHza6qerEiQehrbW5xaXyxvR0qJe3KBX1R4kocDz1+7Ygu8x-g@mail.gmail.com
Backpatch-through: 19

2 weeks agoRestore comment at appendShellString().
Noah Misch [Tue, 30 Jun 2026 02:41:09 +0000 (19:41 -0700)] 
Restore comment at appendShellString().

Commit b380a56a3f9556588a89013b765d67947d54f7d0 removed a paragraph, but
two of the paragraph's three sentences remained relevant.

Backpatch-through: 19

2 weeks agobufmgr: Fix race in LockBufferForCleanup()
Fujii Masao [Tue, 30 Jun 2026 01:30:47 +0000 (10:30 +0900)] 
bufmgr: Fix race in LockBufferForCleanup()

LockBufferForCleanup() acquires the exclusive content lock, checks the
buffer's shared pin count, and, if other pins remain, registers itself
as the BM_PIN_COUNT_WAITER before waiting for an unpin notification.

Since commits 5310fac6e0f and c75ebc657ffc, however, a shared buffer
pin can be released while BM_LOCKED is set, introducing the following
race:

- LockBufferForCleanup() observes a refcount greater than one.
- Before it sets BM_PIN_COUNT_WAITER, another backend releases the
  last conflicting pin.
- Since BM_PIN_COUNT_WAITER is not yet set, no wakeup is sent.
- LockBufferForCleanup() then sets BM_PIN_COUNT_WAITER and goes to
  sleep, even though only its own pin remains.

As a result, LockBufferForCleanup() can sleep indefinitely because
the wakeup corresponding to the last conflicting unpin has already been
missed.

Fix this by setting BM_PIN_COUNT_WAITER while holding the buffer
header lock, then rechecking the refcount before releasing the content
lock. If only our pin remains, clear the waiter state and proceed
without sleeping. Otherwise, wait as before.

This issue was reported by buildfarm member skink, where it manifested
as intermittent timeouts in 048_vacuum_horizon_floor.pl.

Backpatch to v19, where commits 5310fac6e0f and c75ebc657ffc
introduced the race.

Reported-by: Alexander Lakhin <exclusion@gmail.com>
Author: Xuneng Zhou <xunengzhou@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/7685519a-0bf9-4e17-93ca-7e3aa10fa29c@gmail.com
Backpatch-through: 19

2 weeks agoRemove stray blank line in ParseFuncOrColumn()
Fujii Masao [Tue, 30 Jun 2026 01:28:52 +0000 (10:28 +0900)] 
Remove stray blank line in ParseFuncOrColumn()

Commit 419ce13b701 accidentally left a stray blank line in
ParseFuncOrColumn(). Remove it.

No functional change.

Author: Henson Choi <assam258@gmail.com>
Discussion: https://postgr.es/m/CAAAe_zDLBkZFXXCgR_-NuaeW+aUXUtuDoSgg-2QRz+b2g7G4BA@mail.gmail.com
Backpatch-through: 19

2 weeks agoFix unlogged sequence corruption after standby promotion
Fujii Masao [Mon, 29 Jun 2026 23:48:47 +0000 (08:48 +0900)] 
Fix unlogged sequence corruption after standby promotion

Previously, if an unlogged sequence was created on the primary and
replicated to a standby, reading the sequence after promoting the
standby (for example, with nextval()) could trigger the following
assertion failure:

    TRAP: failed Assert("((const PageHeaderData *) page)->pd_special >= SizeOfPageHeaderData")

In non-assert builds, the same operation could instead fail with an
error such as:

    ERROR:  bad magic number in sequence

The problem was that seq_redo() updated the init fork page in shared
buffers but did not flush it to disk. During promotion,
ResetUnloggedRelations() recreates the main fork of unlogged
relations by copying the init fork from disk, bypassing shared
buffers. As a result, the main fork could be recreated from a stale
init fork instead of the WAL-replayed page.

Fix this by introducing a helper to flush init fork buffers
immediately, and make seq_redo() use it. As a result, the main fork
of an unlogged sequence is recreated from the up-to-date init fork on
disk, allowing the unlogged sequence to be read successfully after
standby promotion.

Backpatch to v15, where unlogged sequences were introduced.

Author: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: vignesh C <vignesh21@gmail.com>
Discussion: https://postgr.es/m/CAHGQGwH1Ssze3XM6wjoTjSLVOR041c6xP+vsdLP951=w8oG8bA@mail.gmail.com
Backpatch-through: 15

2 weeks agoSimplify some stats restore code with InputFunctionCallSafe()
Michael Paquier [Mon, 29 Jun 2026 23:30:08 +0000 (08:30 +0900)] 
Simplify some stats restore code with InputFunctionCallSafe()

statatt_build_stavalues() and array_in_safe() have been relying on
InitFunctionCallInfoData() with a locally-filled state to call a data
type input function.  InputFunctionCallSafe() can be used to achieve the
same job, simplifying some code.

This fixes an over-allocation of FunctionCallInfoBaseData done in
statatt_build_stavalues(), where there was space for 8 elements but only
3 were needed.  The over-allocation exists since REL_18_STABLE, and was
harmless in practice.

While on it, fix some comments for both routines, where elemtypid was
mentioned.

Backpatch down to v19.  This code has been reworked during the last
development cycle while working on the restore of extended statistics,
so this keeps the code consistent across all branches.

Author: Jian He <jian.universality@gmail.com>
Author: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CACJufxEGah9PaiTQ=cG14GMMBsUQ3ohGct9tdSwbMQPQ0-nbbQ@mail.gmail.com
Backpatch-through: 19

2 weeks agoStamp HEAD as 20devel.
Joe Conway [Mon, 29 Jun 2026 20:29:11 +0000 (16:29 -0400)] 
Stamp HEAD as 20devel.

Let the hacking begin ...

2 weeks agoAdd previous 2 commits to .git-blame-ignore-revs.
Joe Conway [Mon, 29 Jun 2026 19:33:52 +0000 (15:33 -0400)] 
Add previous 2 commits to .git-blame-ignore-revs.