]> git.ipfire.org Git - thirdparty/postgresql.git/log
thirdparty/postgresql.git
54 min agoClean up all relid fields of RestrictInfos during join removal. master github/master
Tom Lane [Mon, 20 Apr 2026 18:48:23 +0000 (14:48 -0400)] 
Clean up all relid fields of RestrictInfos during join removal.

The original implementation of remove_rel_from_restrictinfo()
thought it could skate by with removing no-longer-valid relid
bits from only the clause_relids and required_relids fields.
This is quite bogus, although somehow we had not run across a
counterexample before now.  At minimum, the left_relids and
right_relids fields need to be fixed because they will be
examined later by clause_sides_match_join().  But it seems
pretty foolish not to fix all the relid fields, so do that.

This needs to be back-patched as far as v16, because the
bug report shows a planner failure that does not occur
before v16.  I'm a little nervous about back-patching,
because this could cause unexpected plan changes due to
opening up join possibilities that were rejected before.
But it's hard to argue that this isn't a regression.  Also,
the fact that this changes no existing regression test results
suggests that the scope of changes may be fairly narrow.
I'll refrain from back-patching further though, since no
adverse effects have been demonstrated in older branches.

Bug: #19460
Reported-by: François Jehl <francois.jehl@pigment.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Richard Guo <guofenglinux@gmail.com>
Discussion: https://postgr.es/m/19460-5625143cef66012f@postgresql.org
Backpatch-through: 16

5 hours agoMake ExecForPortionOfLeftovers() obey SRF protocol.
Tom Lane [Mon, 20 Apr 2026 14:21:52 +0000 (10:21 -0400)] 
Make ExecForPortionOfLeftovers() obey SRF protocol.

Before each call to the SRF, initialize isnull and isDone, as per the
comments for struct ReturnSetInfo.  This fixes a Coverity warning
about rsi.isDone not being initialized.  The built-in
{multi,}range_minus_multi functions don't return without setting it,
but a user-supplied function might not be as accommodating.

We also add statistics tracking around the function call, which
will be expected once user-defined withoutPortionProcs functions
are supported, and a cross-check on rsi.returnMode just for
paranoia's sake.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Co-authored-by: Paul A Jungwirth <pj@illuminatedcomputing.com>
Discussion: https://postgr.es/m/4126231.1776622202@sss.pgh.pa.us

5 hours agoREPACK: do not require REPLICATION or LOGIN
Álvaro Herrera [Mon, 20 Apr 2026 13:44:23 +0000 (15:44 +0200)] 
REPACK: do not require REPLICATION or LOGIN

Although REPACK (CONCURRENTLY) uses replication slots, there is no
concern that the slot will leak data of other users, because the
MAINTAIN privilege on the table is required anyway; requiring
REPLICATION is user-unfriendly without providing any actual protection.

A related aspect is that the REPLICATION attribute is not needed to
prevent REPACK from stealing slots from logical replication, since
commit e76d8c749c31 made REPACK use a separate pool of replication
slots.

Similarly, there's no reason to require that the table owner has the
LOGIN privilege.  Bypass the default behavior in the background worker
launch sequence.

Because there are now successful concurrent repack runs in the
regression tests, we're forced to run test_plan_advice under
wal_level=replica, so add that.  Also, move the cluster.sql test to a
different parallel group in parallel_schedule: apparently the use of the
repack worker causes it to exceed the maximum limit of processes in some
runs (the actual limit reached is the number of XIDs in a snapshot's xip
array).

Author: Antonin Houska <ah@cybertec.at>
Reported-by: Justin Pryzby <pryzby@telsasoft.com>
Reviewed-by: Chao Li <lic@highgo.com>
Discussion: https://postgr.es/m/aeJHPNmL4vVy3oPw@pryzbyj2023

8 hours agodoc PG 19 relnotes: fix typo, "date" -> "data"
Bruce Momjian [Mon, 20 Apr 2026 11:15:06 +0000 (07:15 -0400)] 
doc PG 19 relnotes:  fix typo, "date" -> "data"

Reported-by: shammat@gmx.net
Discussion: https://postgr.es/m/c0d3dfe1-d3e1-45ff-bcdd-40ded5d37ada@gmx.net

9 hours ago049_wait_for_lsn.pl: create function and procedure at once
Alexander Korotkov [Mon, 20 Apr 2026 10:05:55 +0000 (13:05 +0300)] 
049_wait_for_lsn.pl: create function and procedure at once

Create the PL/pgSQL function and procedure for the top-level WAIT FOR
checks in a single transaction, then wait once for standby replay before
running both tests.  Also revise some surrounding comments.

This avoids an extra 'wait_for_catchup()' on the delayed standby without
changing the test coverage.

Discussion: https://postgr.es/m/CABPTF7WZ1yuYz8V%3Dxsbghg8e7qaAm5MpyNw6BthWcbN7%2BP6biw%40mail.gmail.com
Author: Xuneng Zhou <xunengzhou@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
11 hours agoClean up remove_rel_from_query() after self-join elimination commit
Richard Guo [Mon, 20 Apr 2026 08:00:22 +0000 (17:00 +0900)] 
Clean up remove_rel_from_query() after self-join elimination commit

The self-join elimination (SJE) commit grafted self-join removal onto
remove_rel_from_query(), which was originally written for left-join
removal only.  This resulted in several issues:

- Comments throughout remove_rel_from_query() still assumed only
  left-join removal, making the code misleading.

- ChangeVarNodesExtended was called on phv->phexpr with subst=-1
  during left-join removal, which is pointless and confusing since any
  surviving PHV shouldn't reference the removed rel.

- phinfo->ph_lateral was adjusted for left-join removal, which is
  unnecessary since the removed relid cannot appear in ph_lateral for
  outer joins.

- The comment about attr_needed reconstruction was in
  remove_rel_from_query(), but the actual rebuild is performed by the
  callers.

- EquivalenceClass processing in remove_rel_from_query() is redundant
  for self-join removal, since the caller (remove_self_join_rel)
  already handles ECs via update_eclasses().

- In remove_self_join_rel(), ChangeVarNodesExtended was called on
  root->processed_groupClause, which contains SortGroupClause nodes
  that have no Var nodes to rewrite.  The accompanying comment
  incorrectly mentioned "HAVING clause".

This patch fixes all these issues, clarifying the separation between
left-join removal and self-join elimination code paths within
remove_rel_from_query().  The resulting code is also better structured
for adding new types of join removal (such as inner-join removal) in
the future.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Tender Wang <tndrwang@gmail.com>
Reviewed-by: Andrei Lepikhov <lepihov@gmail.com>
Reviewed-by: wenhui qiu <qiuwenhuifx@gmail.com>
Discussion: https://postgr.es/m/CAMbWs48JC4OVqE=3gMB6se2WmRNNfMyFyYxm-09vgpm+Vwe8Hg@mail.gmail.com

14 hours agoAdd missing Datum conversions
Peter Eisentraut [Mon, 20 Apr 2026 05:22:16 +0000 (07:22 +0200)] 
Add missing Datum conversions

Similar to commit ff89e182d42, for new code added since.

14 hours agoFix incorrect format placeholders
Peter Eisentraut [Mon, 20 Apr 2026 05:09:13 +0000 (07:09 +0200)] 
Fix incorrect format placeholders

14 hours agoFlush statistics during idle periods in parallel apply worker.
Amit Kapila [Mon, 20 Apr 2026 05:01:11 +0000 (10:31 +0530)] 
Flush statistics during idle periods in parallel apply worker.

Parallel apply workers previously failed to report statistics while
waiting for new work in the main loop. This resulted in the stats from the
most recent transaction remaining unbuffered, leading to arbitrary
reporting delays—particularly when streamed transactions were infrequent.

This commit ensures that statistics are explicitly flushed when the worker
is idle, providing timely visibility into accumulated worker activity.

Author: Zhijie Hou <houzj.fnst@fujitsu.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Backpatch-through: 16, where it was introduced
Discussion: https://postgr.es/m/TYRPR01MB1419579F217CC4332B615589594202@TYRPR01MB14195.jpnprd01.prod.outlook.com

16 hours agoMeson: Fix check_header() for readline and gssapi
Michael Paquier [Mon, 20 Apr 2026 03:36:14 +0000 (12:36 +0900)] 
Meson: Fix check_header() for readline and gssapi

Since f039c2244110, the minimum version of meson supported is 0.57.2,
meaning that it is possible to use the result of declare_dependency()
when checking for headers with check_header().  There were two TODOs for
readline and gssapi to change declare_dependency() after upgrading to at
least 0.57.0, which were not addressed yet.

While on it, this fixes a comment related to str.replace().  The
function has been introduced in meson 0.58.0, not 0.56.

Author: Andreas Karlsson <andreas@proxel.se>
Reviewed-by: Tristan Partin <tristan@partin.io>
Discussion: https://postgr.es/m/00cd2e0c-85df-4cf9-a889-125d85e66980@proxel.se

21 hours agoMinor fixes for test_bitmapset.c
David Rowley [Sun, 19 Apr 2026 21:58:40 +0000 (09:58 +1200)] 
Minor fixes for test_bitmapset.c

1. Make it so test_random_operations() can accept a NULL to have the
   function select a random seed.
2. Widen the seed parameter of test_random_operations() to bigint.
   Without that, it'll be impossible to run the function with a seed
   which was selected by GetCurrentTimestamp(), and if a randomly
   selected seed ever results in a failure, we'll likely want to run
   with the same seed to debug the issue.
3. Report the seed in the error messages in test_random_operations().
   If the buildfarm were ever to fail there, we'd certainly want to know
   what this was.
4. Add CHECK_FOR_INTERRUPTS() to test_random_operations().  Someone might
   run with a large num_ops and they'd have no way to cancel the query.
5. Minor cosmetic fixes; header order and whitespace issue.

To allow #1, the STRICT modifier had to be removed.  The additional
prechecks were added as I didn't see how else to handle someone passing
those parameters as NULL.

Author: David Rowley <dgrowleyml@gmail.com>
Reviewed-by: Greg Burd <greg@burd.me>
Discussion: https://postgr.es/m/CAApHDvrDW9W72vAr7h7XeCu7+Qz-_Vff02Q+RPPuVeM0Qf0MCw@mail.gmail.com

32 hours agoFix 64-bit shifting in dynahash.c
Peter Eisentraut [Sun, 19 Apr 2026 10:57:41 +0000 (12:57 +0200)] 
Fix 64-bit shifting in dynahash.c

The switch from long to int64 in commit 13b935cd521 was incomplete.
It was shifting the constant 1L, which is not always 64 bit.  Fix by
using an explicit int64 constant.

MSVC warning:

../src/backend/utils/hash/dynahash.c(1767): warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

Also add the corresponding warning to the standard warning set on
MSVC, to help catch similar issues in the future.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/1142ad86-e475-41b3-aeee-c6ad913064fa%40eisentraut.org

2 days agopg_plan_advice: pgindent
Robert Haas [Fri, 17 Apr 2026 21:45:50 +0000 (17:45 -0400)] 
pg_plan_advice: pgindent

Per buildfarm member koel.

3 days agoChange PointerGetDatum() back to a macro
Heikki Linnakangas [Fri, 17 Apr 2026 19:14:40 +0000 (22:14 +0300)] 
Change PointerGetDatum() back to a macro

The argument was marked as "const void *X", but that might rightly
give the compiler the idea that *X cannot be modified through the
resulting Datum, and make incorrect optimizations based on that. Some
functions use pointer Datums to pass output arguments, like GIN
support functions. Coverity started to complain after commit
6f5ad00ab7 that there's dead code in ginExtractEntries(), because it
didn't see that it passes PointerGetDatum(&nentries) to a function
that sets it.

This issue goes back to commit c8b2ef05f481 (version 16), which
changed PointerGetDatum() from a macro to a static inline function.
This commit changes it back to a macro, but uses a trick with a dummy
conditional expression to still produce a compiler error if you try to
pass a non-pointer as the argument.

Even though this goes back to v16, I'm only committing this to
'master' for now, to verify that this silences the Coverity warning.
If this works, we might want to introduce separate const and non-const
versions of PointerGetDatum() instead of this, but that's a bigger
patch.  It's also not decided yet whether to back-patch this (or some
other fix), given that we haven't yet seen any hard evidence of
compilers actually producing buggy code because of this.

Discussion: https://www.postgresql.org/message-id/342012.1776017102@sss.pgh.pa.us

3 days agopg_plan_advice: Fix another unique-semijoin bug.
Robert Haas [Fri, 17 Apr 2026 18:08:37 +0000 (14:08 -0400)] 
pg_plan_advice: Fix another unique-semijoin bug.

This one occurs when an outer join appears beneath the made-unique
side of a semijoin. The issue is that join RTEs are not featured
out of sj_unique_rels entries. Fix, and add a test case.

Reported-by: Alexander Lakhin <exclusion@gmail.com>
Analyzed-by: Tender Wang <tndrwang@gmail.com>
Discussion: http://postgr.es/m/c0c63979-43c2-4424-8fe8-56949934c9d8@gmail.com

3 days agoDoc: Improve the wording of logical slot prerequisites.
Amit Kapila [Fri, 17 Apr 2026 09:32:15 +0000 (15:02 +0530)] 
Doc: Improve the wording of logical slot prerequisites.

Replace the previous negative phrasing such as "there are no slots whose
... is not true" with a direct expression that all slots must have
conflicting = false.

Similarly, reword the requirement on the new cluster to state that it must
not have any permanent logical slots, clarifying that any existing logical
slots must have temporary set to true.

These changes improve readability without altering the meaning.

Reported-by: <mimidatabase@gmail.com>
Author: Vignesh C <vignesh21@gmail.com>
Reviewed-by: David G. Johnston <david.g.johnston@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Discussion: https://postgr.es/m/177609278737.403059.14174275013090471947%40wrigleys.postgresql.org

3 days agodoc: Improve description of pg_ctl -l log file permissions
Fujii Masao [Fri, 17 Apr 2026 06:30:59 +0000 (15:30 +0900)] 
doc: Improve description of pg_ctl -l log file permissions

The documentation stated only that the log file created by pg_ctl -l is
inaccessible to other users by default. However, since commit c37b3d0,
the actual behavior is that only the cluster owner has access by default,
but users in the same group as the cluster owner may also read the file
if group access is enabled in the cluster.

This commit updates the documentation to describe this behavior
more clearly.

Backpatch to all supported versions.

Author: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Andreas Karlsson <andreas@proxel.se>
Reviewed-by: Xiaopeng Wang <wxp_728@163.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/OS9PR01MB1214959BE987B4839E3046050F54BA@OS9PR01MB12149.jpnprd01.prod.outlook.com
Backpatch-through: 14

3 days agopsql: Fix incorrect tab completion after CREATE PUBLICATION ... EXCEPT (...)
Fujii Masao [Fri, 17 Apr 2026 05:31:05 +0000 (14:31 +0900)] 
psql: Fix incorrect tab completion after CREATE PUBLICATION ... EXCEPT (...)

Previously, tab completion after EXCEPT (...) always suggested FROM SERVER.
This was correct for IMPORT FOREIGN SCHEMA ... EXCEPT (...), but became
incorrect once commit fd366065e06 added CREATE PUBLICATION ... EXCEPT (...).

This commit updates tab completion so FROM SERVER is no longer suggested
after CREATE PUBLICATION ... EXCEPT (...), while preserving the existing
behavior for IMPORT FOREIGN SCHEMA ... EXCEPT (...).

Author: Vignesh C <vignesh21@gmail.com>
Reviewed-by: Shveta Malik <shveta.malik@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/CALDaNm1-Fx6Msw6zcRuSjgQdw6asdTyp2DwP-4TCKGYAT+ndsA@mail.gmail.com

3 days agoReject invalid databases in pg_get_database_ddl()
Amit Langote [Fri, 17 Apr 2026 04:19:56 +0000 (13:19 +0900)] 
Reject invalid databases in pg_get_database_ddl()

An invalid database has datconnlimit set to -2.  pg_get_database_ddl()
emits this verbatim as CONNECTION LIMIT = -2, which ALTER DATABASE
rejects.  Error out early instead.

Reported-by: Lakshmi N <lakshmin.jhs@gmail.com>
Author: Lakshmi N <lakshmin.jhs@gmail.com>
Reviewed-by: Amit Langote <amitlangote09@gmail.com>
Reviewed-by: Euler Taveira <euler@eulerto.com>
Reviewed-by: Hu Xunqi <huxunqi.08@gmail.com>
Discussion: https://postgr.es/m/CA+3i_M8m1k2gFch+tU0JmAQh9FRV+pFrfTXDrJo+BqmwsTmOhg@mail.gmail.com

3 days agodoc PG 19 relnotes: change "free space map" to "visibility map"
Bruce Momjian [Thu, 16 Apr 2026 21:23:55 +0000 (17:23 -0400)] 
doc PG 19 relnotes: change "free space map" to "visibility map"

Reported-by: Melanie Plageman
Author: Melanie Plageman

3 days agoMake psql DETAIL line test unconditionally optional.
Andrew Dunstan [Wed, 15 Apr 2026 18:41:33 +0000 (14:41 -0400)] 
Make psql DETAIL line test unconditionally optional.

Commit 3e2a1496bae6 made the psql TAP test require the DETAIL line on
platforms with SA_SIGINFO, rather than making it optional. This
unexpectedly blew up on OpenBSD buildfarm members, because OpenBSD does
not set si_pid for SIGTERM signals even though it has SA_SIGINFO
defined.

So revert to the test as it was in commit 55890a919454, where the detail
line being missing never causes an error.

Author: Jakub Wartak <jakub.wartak@enterprisedb.com>
Suggested-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/2007157.1776269052%40sss.pgh.pa.us

3 days agoAdd missing initialization
Álvaro Herrera [Thu, 16 Apr 2026 20:27:04 +0000 (22:27 +0200)] 
Add missing initialization

The backend running REPACK can check DecodingWorkerShared->initialized
before the worker could have the chance to initialize it, possibly
leading to wrong behavior.

While at it, remove DecodingWorkerShared->worker_dsm_segment, because
that doesn't actually need to be in shared memory; a simple local-memory
global variable is enough.

Oversights in commit 28d534e2ae0a.

Author: Antonin Houska <ah@cybertec.at>
Reported-by: Alexander Lakhin <exclusion@gmail.com>
Discussion: https://postgr.es/m/18181295-8375-4789-ad32-269d78d6001e@gmail.com

4 days agodoc PG 19 relnotes: add author and move items
Bruce Momjian [Thu, 16 Apr 2026 16:45:40 +0000 (12:45 -0400)] 
doc PG 19 relnotes:  add author and move items

Reported-by: Richard Guo
Author: Richard Guo

Discussion: https://postgr.es/m/CAMbWs4_etzZZPMEzte8hJv2f4Tn6dGskg8v1R_N9uCd2of0kMQ@mail.gmail.com

4 days agoUpdate FSM during prune/freeze replay even if freespace is zero
Melanie Plageman [Thu, 16 Apr 2026 16:10:47 +0000 (12:10 -0400)] 
Update FSM during prune/freeze replay even if freespace is zero

add323da40a started updating the visibility map in the same WAL record
as pruning and freezing. This included updating the freespace map during
replay of a record setting the VM, which we've done since ab7dbd681.

add323da40a, however, conditioned doing so on there being > 0 freespace
on the page, which differed from the previous state for records updating
the VM.

The FSM is not WAL-logged and is instead updated heuristically on
standbys. In rare cases, this heuristic could lead to pages with 0
freespace having outdated entries in the FSM. If the standby is later
promoted and vacuum skips these pages because they are marked
all-visible/all-frozen, overly optimistic values would be propagated up
the FSM tree, causing slowness when searching for freespace for new
tuples.

Fix it by always updating the FSM during replay when setting VM bits.

Author: Melanie Plageman <melanieplageman@gmail.com>
Reported-by: Alexey Makhmutov <a.makhmutov@postgrespro.ru>
Discussion: https://postgr.es/m/ead2f110-c736-48f5-99e1-023dc9acbf0b%40postgrespro.ru

4 days agodoc PG 19 relnotes: update author
Bruce Momjian [Thu, 16 Apr 2026 15:23:55 +0000 (11:23 -0400)] 
doc PG 19 relnotes:  update author

Reported-by: Masahiko Sawada
Author: Masahiko Sawada

Discussion: https://postgr.es/m/CAD21AoCLCZnzEFam8H07qq-=fUpDwmTmV7+4RPnT2x_xoJBrgg@mail.gmail.com

4 days agodoc PG 19 relnotes: corrections reported to me privately
Bruce Momjian [Thu, 16 Apr 2026 14:43:17 +0000 (10:43 -0400)] 
doc PG 19 relnotes:  corrections reported to me privately

4 days agoUse XLogRecPtrIsValid() consistently for WAL position checks
Fujii Masao [Thu, 16 Apr 2026 14:02:34 +0000 (23:02 +0900)] 
Use XLogRecPtrIsValid() consistently for WAL position checks

Commit a2b02293bc6 switched various checks to use XLogRecPtrIsValid(),
but later changes reintroduced XLogRecPtrIsInvalid() and direct comparisons
with InvalidXLogRecPtr.

This commit replaces those uses with XLogRecPtrIsValid() for better
readability and consistency.

Author: Vignesh C <vignesh21@gmail.com>
Reviewed-by: Xiaopeng Wang <wxp_728@163.com>
Reviewed-by: Amul Sul <sulamul@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/CALDaNm16knMFtcqyAG3XYSkyagmVXfhaR0T=hau8UTAU0+eLQQ@mail.gmail.com

4 days agodoc: Add missing GUCs to SSL SNI docs
Daniel Gustafsson [Thu, 16 Apr 2026 09:18:57 +0000 (11:18 +0200)] 
doc: Add missing GUCs to SSL SNI docs

The ssl_sni and hosts_file GUCs were missing from the configuration
section of the documentation, they were only described in the main
SSL SNI subsection.  This adds the GUCs to the relevant sections as
well as rewords the existing SSL SNI documentation to refer to the
settings along with a few smaller fixups.

Author: Daniel Gustafsson <daniel@yesql.se>
Reported-by: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/CAHGQGwESD2Pty+J1kP3mXmWwMKZ5uJmknZdJsSGrMSRR6CQBmw@mail.gmail.com

4 days agoMSVC: Turn missing function declaration into an error
Peter Eisentraut [Thu, 16 Apr 2026 07:53:03 +0000 (09:53 +0200)] 
MSVC: Turn missing function declaration into an error

Calling an undeclared function should be an error as of C99, and GCC
and Clang do that, but MSVC doesn't even warn about it in the default
warning level.  (Commit c86d2ccdb35 fixed an instance of this
problem.)  This turns on this warning and makes it an error by
default, to match other compilers.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/1142ad86-e475-41b3-aeee-c6ad913064fa%40eisentraut.org

4 days agoAdd missing include
Peter Eisentraut [Thu, 16 Apr 2026 07:35:05 +0000 (09:35 +0200)] 
Add missing include

"utils/pg_locale.h" is needed when under MSVC for wchar2char(),
introduced by commit 65707ed9afc.  Surprisingly, MSVC doesn't warn by
default about calling undeclared functions.  This will be addressed in
a separate commit.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/1142ad86-e475-41b3-aeee-c6ad913064fa%40eisentraut.org

4 days agoFix comments for Korean encodings in encnames.c
Thomas Munro [Thu, 16 Apr 2026 06:17:05 +0000 (18:17 +1200)] 
Fix comments for Korean encodings in encnames.c

  * JOHAB: replace the incorrect "simplified Chinese" description with
    a correct one that identifies it as the Korean combining (Johab)
    encoding standardized in KS X 1001 annex 3.

  * EUC_KR: drop a stray space before the comma in the existing
    comment, and note that the encoding covers the KS X 1001
    precomposed (Wansung) form.

  * UHC: spell out "Unified Hangul Code", clarify that it is
    Microsoft Windows CodePage 949, and describe its relationship to
    EUC-KR (superset covering all 11,172 precomposed Hangul syllables).

Backpatch-through: 14
Author: Henson Choi <assam258@gmail.com>
Discussion: https://postgr.es/m/CAAAe_zAFz1v-3b7Je4L%2B%3DwZM3UGAczXV47YVZfZi9wbJxspxeA%40mail.gmail.com

4 days agoFix pg_overexplain to emit valid output with RANGE_TABLE option.
Amit Langote [Thu, 16 Apr 2026 04:47:07 +0000 (13:47 +0900)] 
Fix pg_overexplain to emit valid output with RANGE_TABLE option.

overexplain_range_table() emitted the "Unprunable RTIs" and "Result
RTIs" properties before closing the "Range Table" group.  In the JSON
and YAML formats the Range Table group is rendered as an array of RTE
objects, so emitting key/value pairs inside it produced structurally
invalid output.  The XML format had a related oddity, with these
elements nested inside <Range-Table> rather than appearing as its
siblings.

These fields are properties of the PlannedStmt as a whole, not of any
individual RTE, so close the Range Table group before emitting them.
They now appear as siblings of "Range Table" in the parent Query
object, which is what was intended.

Also add a test exercising FORMAT JSON with RANGE_TABLE so that any
future regression in the output structure is caught.

Reported-by: Satyanarayana Narlapuram <satyanarlapuram@gmail.com>
Author: Satyanarayana Narlapuram <satyanarlapuram@gmail.com>
Reviewed-by: Amit Langote <amitlangote09@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/CAHg+QDdDrdqMr98a_OBYDYmK3RaT7XwCEShZfvDYKZpZTfOEjQ@mail.gmail.com
Backpatch-through: 18

4 days agoFix incorrect comment in JsonTablePlanJoinNextRow()
Amit Langote [Thu, 16 Apr 2026 04:45:33 +0000 (13:45 +0900)] 
Fix incorrect comment in JsonTablePlanJoinNextRow()

The comment on the return-false path when both UNION siblings are
exhausted said "there are more rows," which is the opposite of what
the code does. The code itself is correct, returning false to signal
no more rows, but the misleading comment could tempt a reader into
"fixing" the return value, which would cause UNION plans to loop
indefinitely.

Back-patch to 17, where JSON_TABLE was introduced.

Author: Chuanwen Hu <463945512@qq.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/tencent_4CC6316F02DECA61ACCF22F933FEA5C12806@qq.com
Backpatch-through: 17

4 days agoUse proc_exit() for walreceiver exit in WalRcvWaitForStartPosition()
Fujii Masao [Thu, 16 Apr 2026 03:33:17 +0000 (12:33 +0900)] 
Use proc_exit() for walreceiver exit in WalRcvWaitForStartPosition()

Previously, when the walreceiver exited from WalRcvWaitForStartPosition()
at the startup process's request, it called exit(1) directly. This could
skip cleanup performed by the callback functions.

This commit makes the walreceiver to use proc_exit() instead, ensuring
normal cleanup is executed on exit.

Also this commit updates comments describing walreceiver termination.

Apply to master only, as this has not caused practical issues so far.

Author: Chao Li <lic@highgo.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Andreas Karlsson <andreas@proxel.se>
Reviewed-by: Xuneng Zhou <xunengzhou@gmail.com>
Discussion: https://postgr.es/m/74381238-4E8A-4621-B794-57025DCCE0BA@gmail.com

4 days agodoc PG 19 relnotes: remove doc author from "Allow autovacuum"
Bruce Momjian [Wed, 15 Apr 2026 20:58:11 +0000 (16:58 -0400)] 
doc PG 19 relnotes:  remove doc author from "Allow autovacuum"

Reported-by: Aleksander Alekseev
Discussion: https://postgr.es/m/CAJ7c6TO-FHg4SGF48PJ9dnV3cg1-_xW9=P4t8-cd-+JWvZAPyQ@mail.gmail.com

4 days agodoc PG 19 relnotes: add free space map all-visible item
Bruce Momjian [Wed, 15 Apr 2026 20:52:17 +0000 (16:52 -0400)] 
doc PG 19 relnotes:  add free space map all-visible item

Reported-by: Melanie Plageman
Discussion: https://postgr.es/m/CAAKRu_bzN6ioG+h7agjCF847whVpS2WEiJB3UXAtkJ3WVXOZwA@mail.gmail.com

4 days agodoc PG 19 relnotes: fixes for commands and authors
Bruce Momjian [Wed, 15 Apr 2026 20:18:51 +0000 (16:18 -0400)] 
doc PG 19 relnotes:  fixes for commands and authors

Reported-by: jian he
Discussion: https://postgr.es/m/CANzqJaCKn_AahetGkZWKJVi6MKyGKqr1JrziquyHt1-SRwQpSw@mail.gmail.com

4 days agodoc PG 19 relnotes: remove "Lakshmi N" as author of checksums
Bruce Momjian [Wed, 15 Apr 2026 19:43:36 +0000 (15:43 -0400)] 
doc PG 19 relnotes:  remove "Lakshmi N" as author of checksums

Reported-by: Daniel Gustafsson
Discussion: https://postgr.es/m/762DAF2F-7055-4F52-9DF7-23C4A19478A0@yesql.se

5 days agodoc PG 19 relnotes: fix "now targets"
Bruce Momjian [Wed, 15 Apr 2026 19:37:00 +0000 (15:37 -0400)] 
doc PG 19 relnotes:  fix "now targets"

Reported-by: Laurenz Albe
Discussion: https://postgr.es/m/27be2ef070e3a0ca55b478e0493fac0124d4f95e.camel@cybertec.at

5 days agodoc PG 19 relnotes: addjust CREATE/ALTER PUBLICATION "EXCEPT"
Bruce Momjian [Wed, 15 Apr 2026 19:35:23 +0000 (15:35 -0400)] 
doc PG 19 relnotes: addjust CREATE/ALTER PUBLICATION "EXCEPT"

Reported-by: Peter Smith
Backpatch-through: CAHut+Psb41Lou8+BS4ZYmZJFG8pF99wEr+xcP17PCZP1MaY_+Q@mail.gmail.com

5 days agodoc PG 19 relnotes: add missing March 16 autovacuum score item
Bruce Momjian [Wed, 15 Apr 2026 18:42:57 +0000 (14:42 -0400)] 
doc PG 19 relnotes:  add missing March 16 autovacuum score item

Also fix "deformed" tuples.

Reported-by: David Rowley
Backpatch-through: CAApHDvrsyD3QKBO=dypNkyFzYOzQEbgy+xJLwn=y+h+bLSDd-g@mail.gmail.com

5 days agodoc PG 19 relnotes: adjust ShmemRequestStruct item
Bruce Momjian [Wed, 15 Apr 2026 17:03:29 +0000 (13:03 -0400)] 
doc PG 19 relnotes: adjust ShmemRequestStruct item

Reported-by: Ashutosh Bapat
Author: Ashutosh Bapat

Discussion: https://postgr.es/m/CAExHW5vjpd=mWauQZsTbKX9QqD8yxDUABBGQAT5n+CT+nr8QHw@mail.gmail.com

5 days agoFix COPY TO FORMAT JSON to exclude generated columns.
Andrew Dunstan [Wed, 15 Apr 2026 11:47:12 +0000 (07:47 -0400)] 
Fix COPY TO FORMAT JSON to exclude generated columns.

COPY TO with FORMAT json was including generated columns in the
output, unlike TEXT and CSV formats.  Virtual generated columns
appeared as null, and stored ones showed their computed values.

The JSON code path only built a restricted TupleDesc when an explicit
column list was given (attnamelist != NIL), but CopyGetAttnums()
also excludes generated columns from the default list.  Fix by
checking whether the attnumlist is shorter than the full TupleDesc
instead.

Bug introduced in 7dadd38cda9.

Author: Satya Narlapuram <satya.narlapuram@gmail.com>
Reviewed-by: Jian He <jian.universality@gmail.com>
Discussion: https://postgr.es/m/CAHg+QDcfpGDoPL3fvfjXRtfn=fny6DdJR6BAy6TpS1Xj2EZfXA@mail.gmail.com

5 days agoRework signal handler infrastructure to pass sender info as argument.
Andrew Dunstan [Tue, 14 Apr 2026 20:13:08 +0000 (16:13 -0400)] 
Rework signal handler infrastructure to pass sender info as argument.

Commit 095c9d4cf06 added errdetail() reporting of the PID and UID of
the process that sent a termination signal.  However, as noted by
Andres Freund, the implementation had architectural problems:

1. wrapper_handler() in pqsignal.c contained SIGTERM-specific logic
   (setting ProcDieSenderPid/Uid), violating its role as a generic
   signal dispatch wrapper.

2. Using globals to pass sender info between wrapper_handler and the
   real handler is unsafe when signals nest on some platforms.

3. The syncrep.c errdetail used psprintf() to conditionally embed
   text via %s, breaking translatability.

Adopt the approach proposed by Andres Freund: introduce a
pg_signal_info struct that is passed as an argument to all signal
handlers via the SIGNAL_ARGS macro.  wrapper_handler populates it
from siginfo_t when SA_SIGINFO is available, or with zeros otherwise.
This keeps wrapper_handler fully generic and avoids any globals for
passing signal metadata.

Since pqsigfunc now has a different signature from the system's
signal handler type, SIG_IGN and SIG_DFL can no longer be passed
directly to pqsignal().  Introduce PG_SIG_IGN and PG_SIG_DFL macros
that cast to the new pqsigfunc type, and update all call sites.
The legacy pqsignal() in libpq retains its original signature via
a local typedef.

Only die() reads pg_siginfo today, copying the sender PID/UID into
ProcDieSenderPid/Uid for later use by ProcessInterrupts().  Only the
first SIGTERM's sender info is recorded.

Also fix the syncrep.c translatability issue by using separate ereport
calls with complete, independently translatable errdetail strings.

Also make the psql TAP test require the DETAIL line on platforms with
SA_SIGINFO, rather than making it unconditionally optional.

On Windows, pg_signal_info uses uint32_t for pid and uid fields
since pid_t/uid_t are not available early enough in the include
chain.  The Windows signal dispatch in pgwin32_dispatch_queued_signals()
passes a zeroed pg_signal_info to handlers.

Author: Andres Freund <andres@anarazel.de>
Author: Jakub Wartak <jakub.wartak@enterprisedb.com>
Reviewed-by: Andrew Dunstan <andrew@dunslane.net>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/cwyyryh2veejuxbj5ifzyaejw7jhhqc5mrdeq56xckknsdecn2@6hzfcxde2nm5
Discussion: https://postgr.es/m/jygesyr7mwg7ovdbxpmjvvbi3hccptpkcreqb645h7f56puwbz@hmkkwi3melfe

5 days agodoc: first draft of PG 19 release notes
Bruce Momjian [Wed, 15 Apr 2026 01:06:07 +0000 (21:06 -0400)] 
doc:  first draft of PG 19 release notes

5 days agoFix var_is_nonnullable() to handle invalid NOT NULL constraints
Richard Guo [Wed, 15 Apr 2026 00:38:56 +0000 (09:38 +0900)] 
Fix var_is_nonnullable() to handle invalid NOT NULL constraints

The NOTNULL_SOURCE_SYSCACHE code path in var_is_nonnullable() used
get_attnotnull() to check pg_attribute.attnotnull, which is true for
both valid and invalid (NOT VALID) NOT NULL constraints.  An invalid
constraint does not guarantee the absence of NULLs, so this could lead
to incorrect results.  For example, query_outputs_are_not_nullable()
could wrongly conclude that a subquery's output is non-nullable,
causing NOT IN to be incorrectly converted to an anti-join.

Fix by checking the attnullability field in the relation's tuple
descriptor instead, which correctly distinguishes valid from invalid
constraints, consistent with what the NOTNULL_SOURCE_HASHTABLE code
path already does.

While at it, rename NOTNULL_SOURCE_SYSCACHE to NOTNULL_SOURCE_CATALOG
to reflect that this code path no longer uses a syscache lookup, and
remove the now-unused get_attnotnull() function.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: SATYANARAYANA NARLAPURAM <satyanarlapuram@gmail.com>
Discussion: https://postgr.es/m/CAMbWs48ALW=mR0ydQ62dGS-Q+3D7WdDSh=EWDezcKp19xi=TUA@mail.gmail.com

5 days agoFix pfree crash in pg_get_role_ddl() and pg_get_database_ddl().
Andrew Dunstan [Tue, 14 Apr 2026 22:25:36 +0000 (18:25 -0400)] 
Fix pfree crash in pg_get_role_ddl() and pg_get_database_ddl().

DatumGetArrayTypeP() can return a pointer into the tuple when the
datum is stored as a short varlena, so pfree() on the result crashes.
Use DatumGetArrayTypePCopy() to always get a palloc'd copy.

Bug introduced in 76e514ebb4b and a4f774cf1c7.

Reported-by: Jeff Davis <pgsql@j-davis.com>
Author: Satya Narlapuram <satya.narlapuram@gmail.com>
Discussion: https://postgr.es/m/CAHg+QDdWtv9PKtPZEokwGCNtbv4MVnfYw5wMZrsEj4xizSNe5Q@mail.gmail.com

5 days agoCheck for unterminated strings when calling uloc_getLanguage().
Jeff Davis [Tue, 14 Apr 2026 19:06:02 +0000 (12:06 -0700)] 
Check for unterminated strings when calling uloc_getLanguage().

Missed by commit 1671f990dd66.

Author: Andreas Karlsson <andreas@proxel.se>
Discussion: https://postgr.es/m/118ca69e-47eb-42e1-83e9-72ccf40dd6fd@proxel.se
Backpatch-through: 16

5 days agoAdd tests for low-level PGLZ [de]compression routines
Michael Paquier [Tue, 14 Apr 2026 20:09:05 +0000 (05:09 +0900)] 
Add tests for low-level PGLZ [de]compression routines

The goal of this module is to provide an entry point for the coverage of
the low-level compression and decompression PGLZ routines.  The new test
is moved to a new parallel group, with all the existing
compression-related tests added to it.

This includes tests for the cases detected by fuzzing that emulate
corrupted compressed data, as fixed by 2b5ba2a0a141:
- Set control bit with read of a match tag, where no data follows.
- Set control bit with read of a match tag, where 1 byte follows.
- Set control bit with match tag where length nibble is 3 bytes
(extended case).

While on it, some tests are added for compress/decompress roundtrips,
and for check_complete=false/true.  Like 2b5ba2a0a141, backpatch to all
the stable branches.

Discussion: https://postgr.es/m/adw647wuGjh1oU6p@paquier.xyz
Backpatch-through: 14

6 days agoReplace deprecated StaticAssertStmt() with StaticAssertDecl()
Heikki Linnakangas [Tue, 14 Apr 2026 09:03:30 +0000 (12:03 +0300)] 
Replace deprecated StaticAssertStmt() with StaticAssertDecl()

Commit 6f5ad00ab763 added another use of StaticAssertStmt(), but it
was marked as deprecated in commit d50c86e74375.

Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Discussion: https://www.postgresql.org/message-id/adeNWH5pDawDvvR2@ip-10-97-1-34.eu-west-3.compute.internal

6 days agoAdd missing period to HINT messages.
Amit Kapila [Tue, 14 Apr 2026 04:07:18 +0000 (09:37 +0530)] 
Add missing period to HINT messages.

Author: Peter Smith <smithpb2250@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Robert Treat <rob@xzilla.net>
Discussion: https://postgr.es/m/CAHut+PvikGr4AtoFSs=jq=hmTybVF2NCMEZ57-sjwbGudfuqsQ@mail.gmail.com

7 days agoFix overrun when comparing with unterminated ICU language string.
Jeff Davis [Mon, 13 Apr 2026 18:19:04 +0000 (11:19 -0700)] 
Fix overrun when comparing with unterminated ICU language string.

The overrun was introduced in commit c4ff35f10.

Author: Andreas Karlsson <andreas@proxel.se>
Reported-by: Alexander Lakhin <exclusion@gmail.com>
Discussion: https://postgr.es/m/96d80a47-f17f-42fa-82b1-2908efbd6541@gmail.com
Backpatch-through: 18

7 days agodoc: Remove stray word from pg_stash_advice docs.
Robert Haas [Mon, 13 Apr 2026 16:51:04 +0000 (12:51 -0400)] 
doc: Remove stray word from pg_stash_advice docs.

Commit c10edb102ada607eb054bc9e23690109d86849ef left behind the
word "both" where it no longer makes sense.

Reported-by: Erik Rijkers <er@xs4all.nl>
Discussion: http://postgr.es/m/8912b2e5-ccad-4cbd-ab53-869b0b9ecec5@xs4all.nl

7 days agodoc: Fix a couple of mistakes in pgplanadvice.sgml
Robert Haas [Mon, 13 Apr 2026 16:45:57 +0000 (12:45 -0400)] 
doc: Fix a couple of mistakes in pgplanadvice.sgml

It said FOREIGN_SCAN where it should say FOREIGN_JOIN.

NESTED_LOOP_MEMOIZE was mistakenly omitted from the list of join
methods.

Author: Lakshmi N <lakshmin.jhs@gmail.com>
Reviewed-by: jie wang <jugierwang@gmail.com>
Discussion: http://postgr.es/m/CA+3i_M-mo7Of=Pn8WzRfJLt=fc=gDTn1oOdj8v8BEtgXh9ZMCg@mail.gmail.com

7 days agopg_plan_advice: Export feedback-related definitions.
Robert Haas [Mon, 13 Apr 2026 15:47:40 +0000 (11:47 -0400)] 
pg_plan_advice: Export feedback-related definitions.

It turns out that our main regression test suite queries tables upon
which concurrent DDL is occurring, which can, rarely, cause
test_plan_advice failures. We're not quite ready to fix that problem
just yet, because we want to gather some more information about how
often it actually happens first. But, our plan is going to require
test_plan_advice to access a few bits of pg_plan_advice that have
been considered internal up until now, so this commit rejiggers
things to expose those bits.

First, test_plan_advice is going to need to be able to interpret
the PGPA_TE_* constants which have been declared in pgpa_trove.h.
The "TE" stands for "trove entry" but that's kind of a silly name;
change the naming to "FB" (for "feedback") and move the declarations
to pg_plan_advice.h, which is a header file that's already installed.
This has the side benefit of making these constants available to any
other extensions that may want to examine plan advice feedback.

Second, test_plan_advice is going to call pgpa_planner_feedback_warning,
so make that function non-static and mark it PGDLLEXPORT.

Discussion: http://postgr.es/m/CA+TgmobOOmmXSJz3e+cjTY-bA1+W0dqVDqzxUBEvGtW62whYGg@mail.gmail.com

7 days agopg_plan_advice: Fix a bug when a subquery is pruned away entirely.
Robert Haas [Mon, 13 Apr 2026 14:34:09 +0000 (10:34 -0400)] 
pg_plan_advice: Fix a bug when a subquery is pruned away entirely.

If a subquery is proven empty, and if that subquery contained a
semijoin, and if making one side or the other of that semijoin
unique and performing an inner join was a possible strategy, then
the previous code would fail with ERROR: no rtoffset for plan %s
when attempting to generate advice. Fix that.

Reported-by: Alexander Lakhin <exclusion@gmail.com>
Discussion: http://postgr.es/m/CA+TgmobOOmmXSJz3e+cjTY-bA1+W0dqVDqzxUBEvGtW62whYGg@mail.gmail.com

7 days agopg_plan_advice: Add alternatives test to Makefile.
Robert Haas [Mon, 13 Apr 2026 14:09:20 +0000 (10:09 -0400)] 
pg_plan_advice: Add alternatives test to Makefile.

Oversight in commit 6455e55b0da47255f332a96f005ba0dd1c7176c2.

Discussion: http://postgr.es/m/CA+TgmobOOmmXSJz3e+cjTY-bA1+W0dqVDqzxUBEvGtW62whYGg@mail.gmail.com

7 days agopg_plan_advice: Handle non-repeatable TABLESAMPLE scans.
Robert Haas [Mon, 13 Apr 2026 12:46:25 +0000 (08:46 -0400)] 
pg_plan_advice: Handle non-repeatable TABLESAMPLE scans.

When a tablesample routine says that it is not repeatable across
scans, set_tablesample_rel_pathlist will (usually) materialize it,
confusing pg_plan_advice's plan walker machinery. To fix, update that
machinery to view such Material paths as essentially an extension of
the underlying scan.

Reported-by: Alexander Lakhin <exclusion@gmail.com>
Discussion: http://postgr.es/m/CA+TgmobOOmmXSJz3e+cjTY-bA1+W0dqVDqzxUBEvGtW62whYGg@mail.gmail.com

7 days agoExplicitly forbid non-top-level WAIT FOR execution
Alexander Korotkov [Mon, 13 Apr 2026 11:04:52 +0000 (14:04 +0300)] 
Explicitly forbid non-top-level WAIT FOR execution

Previously we were relying on a snapshot-based check to detect invalid
execution contexts.  However, when WAIT FOR is wrapped into a stored
procedure or a DO block, it could pass this check, causing an error
elsewhere.

This commit implements an explicit isTopLevel check to reject WAIT FOR
when called from within a function, procedure, or DO block.  The
isTopLevel check catches these cases early with a clear error message,
matching the pattern used by other utility commands like VACUUM and
REINDEX.  The snapshot check is retained for the remaining case:
top-level execution within a transaction block using an isolation level
higher than READ COMMITTED.

Also adds tests for WAIT FOR LSN wrapped in a procedure and DO block,
complementing the existing test that uses a function wrapper.  Relevant
documentation paragraph is also added.

Reported-by: Satyanarayana Narlapuram <satyanarlapuram@gmail.com>
Discussion: https://postgr.es/m/CAHg%2BQDcN-n3NUqgRtj%3DBQb9fFQmH8-DeEROCr%3DPDbw_BBRKOYA%40mail.gmail.com
Author: Satyanarayana Narlapuram <satyanarlapuram@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Xuneng Zhou <xunengzhou@gmail.com>
7 days agoUpdate Unicode data to CLDR 48.2
Peter Eisentraut [Mon, 13 Apr 2026 09:12:35 +0000 (11:12 +0200)] 
Update Unicode data to CLDR 48.2

No actual changes result.

Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://www.postgresql.org/message-id/flat/2a668979-ed92-49a3-abf9-a3ec2d460ec2%40eisentraut.org

7 days agopg_createsubscriber: Don't use MAXPGPATH
Peter Eisentraut [Mon, 13 Apr 2026 08:59:08 +0000 (10:59 +0200)] 
pg_createsubscriber: Don't use MAXPGPATH

Use dynamic allocation instead.  Using MAXPGPATH is unnecessary in new
code like this..

Discussion: https://www.postgresql.org/message-id/flat/CAEqnbaUthOQARV1dscGvB_EsqC-YfxiM6rWkVDHc%2BG%2Bf4oSUHw%40mail.gmail.com

7 days agopg_createsubscriber: Remove separate logfile_open() function
Peter Eisentraut [Mon, 13 Apr 2026 08:52:19 +0000 (10:52 +0200)] 
pg_createsubscriber: Remove separate logfile_open() function

This seems like an excessive indirection.

Discussion: https://www.postgresql.org/message-id/flat/CAEqnbaUthOQARV1dscGvB_EsqC-YfxiM6rWkVDHc%2BG%2Bf4oSUHw%40mail.gmail.com

7 days agopg_createsubscriber: Use logging.c log file callback
Peter Eisentraut [Mon, 13 Apr 2026 08:44:14 +0000 (10:44 +0200)] 
pg_createsubscriber: Use logging.c log file callback

This reverts commit 6b5b7eae3ae, where a new logging API layer was
introduced locally in pg_createsubscriber.  Instead, use the log file
callback introduced in logging.c.  This new approach is simpler,
eliminates code duplication, and doesn't require any caller changes or
NLS updates (which the previous commit missed).

Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/CAEqnbaUthOQARV1dscGvB_EsqC-YfxiM6rWkVDHc%2BG%2Bf4oSUHw%40mail.gmail.com

7 days agoAdd log file support to logging.c
Peter Eisentraut [Mon, 13 Apr 2026 08:44:02 +0000 (10:44 +0200)] 
Add log file support to logging.c

This adds the ability for users of logging.c to provide a file handle
for a log file, where log messages are also written in addition to
stderr.

Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/CAEqnbaUthOQARV1dscGvB_EsqC-YfxiM6rWkVDHc%2BG%2Bf4oSUHw%40mail.gmail.com

7 days agoFix capitalization in publication describe output.
Amit Kapila [Mon, 13 Apr 2026 05:24:16 +0000 (10:54 +0530)] 
Fix capitalization in publication describe output.

Consistent with existing psql metadata display conventions, update the
description tags for EXCEPT publications to use lowercase for the second
word (e.g., "Except tables" instead of "Except Tables"). This aligns the
output style with other publication describe commands.

Author: Peter Smith <smithpb2250@gmail.com>
Reviewed-by: vignesh C <vignesh21@gmail.com>
Discussion: https://postgr.es/m/CAHut+Pt3t_tCYwDStkj5fG4Z=YXrHvPBA7iGdh745QipC5zKeg@mail.gmail.com

7 days agoFix excessive logging in idle slotsync worker.
Amit Kapila [Mon, 13 Apr 2026 04:36:50 +0000 (10:06 +0530)] 
Fix excessive logging in idle slotsync worker.

The slotsync worker was incorrectly identifying no-op states as successful
updates, triggering a busy loop to sync slots that logged messages every
200ms. This patch corrects the logic to properly classify these states,
enabling the worker to respect normal sleep intervals when no work is
performed.

Reported-by: Fujii Masao <masao.fujii@gmail.com>
Author: Zhijie Hou <houzj.fnst@fujitsu.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: shveta malik <shveta.malik@gmail.com>
Backpatch-through: 17, where it was introduced
Discussion: https://postgr.es/m/CAHGQGwF6zG9Z8ws1yb3hY1VqV-WT7hR0qyXCn2HdbjvZQKufDw@mail.gmail.com

7 days agoImprove various new-to-v19 appendStringInfo calls
David Rowley [Mon, 13 Apr 2026 01:16:48 +0000 (13:16 +1200)] 
Improve various new-to-v19 appendStringInfo calls

Similar to 928394b66 and 8461424fd, here we adjust a few new locations
which were not using the most suitable appendStringInfo* or
appendPQExpBuffer* function for the intended purpose.

Author: David Rowley <drowleyml@gmail.com>
Discussion: https://postgr.es/m/CAApHDvohYOdrvhVxXzCJNX_GYMSWBfjTTtB6hgDauEtZ8Nar2A@mail.gmail.com

7 days agotest_saslprep: Fix issue with copy of input bytea
Michael Paquier [Mon, 13 Apr 2026 00:06:17 +0000 (09:06 +0900)] 
test_saslprep: Fix issue with copy of input bytea

The data given in input of the function may not be null-terminated,
causing strlcpy() to complain with an invalid read.

Issue spotted using valgrind.

Reported-by: Alexander Lakhin <exclusion@gmail.com>
Discussion: https://postgr.es/m/09df9d75-13e7-45fe-89af-33fe118e797b@gmail.com

7 days agoFix unlikely overflow bug in bms_next_member()
David Rowley [Sun, 12 Apr 2026 23:39:15 +0000 (11:39 +1200)] 
Fix unlikely overflow bug in bms_next_member()

... and bms_prev_member().

Both of these functions won't work correctly when given a prevbit of
INT_MAX and would crash when operating on a Bitmapset that happened to
have a member with that value.

Here we fix that by using an unsigned int to calculate which member to
look for next.

I've also adjusted bms_prev_member() to check for < 0 rather than == -1
for starting the loop.  This was done as it's safer and comes at zero
extra cost.

With our current use cases, it's likely impossible to have a Bitmapset
with an INT_MAX member, so no backpatch here.  I only noticed this issue
when working on a bms function to bitshift a Bitmapset.

Author: David Rowley <dgrowleyml@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/CAApHDvr1B2gbf6JF69QmueM2QNRvbQeeKLxDnF=w9f9--022uA@mail.gmail.com

7 days agoUse stack-allocated StringInfoDatas, where possible
David Rowley [Sun, 12 Apr 2026 22:43:19 +0000 (10:43 +1200)] 
Use stack-allocated StringInfoDatas, where possible

6d0eba662 already did most of the changes, but some new ones snuck in
just prior to that commit, so these got missed.

Having these short-lived StringInfoDatas on the stack rather than having
them get palloc'd by makeStringInfo() is simply for performance as it
saves doing a 2nd palloc.

Since this code is new to v19, it makes sense to improve it now rather
than wait until we branch as having v19 and v20 differ here just makes it
harder to backpatch fixes in this area.

Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/adt4wpj4FZwR+S7I@ip-10-97-1-34.eu-west-3.compute.internal

8 days agoDoc: use "an SQL" consistently rather than "a SQL"
David Rowley [Sun, 12 Apr 2026 10:49:27 +0000 (22:49 +1200)] 
Doc: use "an SQL" consistently rather than "a SQL"

Per the precedent set by 04539e73f, adjust article prefixes for "SQL" to
use "an" consistently rather than "a", i.e., "an es-que-ell" rather than
"a sequel".

Also see b51f86e49b1b13d2b5d866f0374 and 7bdd489d3.

Author: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/CAApHDvp3osQwQam+wNTp9BdhP+QfWO6aY6ZTixQQMfM-UArKCw@mail.gmail.com

9 days agoHonor passed-in database OIDs in pgstat_database.c
Michael Paquier [Sat, 11 Apr 2026 08:02:52 +0000 (17:02 +0900)] 
Honor passed-in database OIDs in pgstat_database.c

Three routines in pgstat_database.c incorrectly ignore the database OID
provided by their caller, using MyDatabaseId instead:
- pgstat_report_connect()
- pgstat_report_disconnect()
- pgstat_reset_database_timestamp()

The first two functions, for connection and disconnection, each have a
single caller that already passes MyDatabaseId.  This was harmless,
still incorrect.

The timestamp reset function also has a single caller, but in this case
the issue has a real impact: it fails to reset the timestamp for the
shared-database entry (datid=0) when operating on shared objects.  This
situation can occur, for example, when resetting counters for shared
relations via pg_stat_reset_single_table_counters().

There is currently one test in the tree that checks the reset of a
shared relation, for pg_shdescription, we rely on it to check what is
stored in pg_stat_database.  As stats_reset may be NULL, two resets are
done to provide a baseline for comparison.

Author: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Dapeng Wang <wangdp20191008@gmail.com>
Discussion: https://postgr.es/m/ABBD5026-506F-4006-A569-28F72C188693@gmail.com
Backpatch-through: 15

9 days agoFix estimate_array_length error with set-operation array coercions
Richard Guo [Sat, 11 Apr 2026 07:38:47 +0000 (16:38 +0900)] 
Fix estimate_array_length error with set-operation array coercions

When a nested set operation's output type doesn't match the parent's
expected type, recurse_set_operations builds a projection target list
using generate_setop_tlist with varno 0.  If the required type
coercion involves an ArrayCoerceExpr, estimate_array_length could be
called on such a Var, and would pass it to examine_variable, which
errors in find_base_rel because varno 0 has no valid relation entry.

Fix by skipping the statistics lookup for Vars with varno 0.

Bug introduced by commit 9391f7152.  Back-patch to v17, where
estimate_array_length was taught to use statistics.

Reported-by: Justin Pryzby <pryzby@telsasoft.com>
Author: Tender Wang <tndrwang@gmail.com>
Reviewed-by: Richard Guo <guofenglinux@gmail.com>
Discussion: https://postgr.es/m/adjW8rfPDkplC7lF@pryzbyj2023
Backpatch-through: 17

9 days agoread_stream: Remove obsolete comment.
Thomas Munro [Fri, 10 Apr 2026 23:23:26 +0000 (11:23 +1200)] 
read_stream: Remove obsolete comment.

This comment was describing the v17 implementation (or io_method=sync).

Backpatch-through: 18

9 days agoFix unstable log verification in test_autovacuum.
Masahiko Sawada [Fri, 10 Apr 2026 23:01:42 +0000 (16:01 -0700)] 
Fix unstable log verification in test_autovacuum.

The test in test_autovacuum was unstable because it called
log_contains() immediately after verifying autovacuum_count in
pg_stat_user_tables. This created a race condition where the
statistics could be updated before the autovacuum logs were fully
flushed to disk.

This commit replaces log_contains() with wait_for_log() to ensure the
test waits for the parallel vacuum messages to appear. Additionally,
remove the checks of the autovacuum count. Verifying the log messages
is sufficient to confirm parallel autovacuum behavior, as logging is
only enabled for the specific table under test.

Per report from buildfarm member flaviventris.

Author: Sami Imseih <samimseih@gmail.com>
Discussion: https://postgr.es/m/525d0f48-93f7-493f-a988-f39b460a79bc@gmail.com

10 days agodoc: Improve consistency of parallel vacuum description.
Masahiko Sawada [Fri, 10 Apr 2026 17:59:24 +0000 (10:59 -0700)] 
doc: Improve consistency of parallel vacuum description.

Use consistent phrasing for parallel vacuum descriptions between
manual VACUUM and autovacuum. Specifically, clarify that the parallel
worker count is limited by the respective options only if they are
explicitly specified.

Also, fix a typo in the parallel vacuum section.

Author: Aleksander Alekseev <aleksander@tigerdata.com>
Discussion: https://postgr.es/m/CAJ7c6TPcSqzhbhrsiCMmVwmE8F7pwS7i9J49SP1zPKS_ER+vcA@mail.gmail.com

10 days agoAdjust log level of logical decoding messages by context
Fujii Masao [Fri, 10 Apr 2026 13:59:34 +0000 (22:59 +0900)] 
Adjust log level of logical decoding messages by context

Commit 21b018e7eab lowered some logical decoding messages from LOG to DEBUG1.
However, per discussion on pgsql-hackers, messages from background activity
(e.g., walsender or slotsync worker) should remain at LOG, as they are less
frequent and more likely to indicate issues that DBAs should notice.

For foreground SQL functions (e.g., pg_logical_slot_peek_binary_changes()),
keep these messages at DEBUG1 to avoid excessive log noise. They can still be
enabled by lowering client_min_messages or log_min_messages for the session.

This commit updates logical decoding to log these messages at LOG for
background activity and at DEBUG1 for foreground execution.

Suggested-by: Robert Haas <robertmhaas@gmail.com>
Author: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Discussion: https://postgr.es/m/CA+TgmoYsu2+YAo9eLGkDp5VP-pfQ-jOoX382vS4THKHeRTNgew@mail.gmail.com

10 days agoRevert "Add built-in fuzzing harnesses for security testing."
Andrew Dunstan [Fri, 10 Apr 2026 13:53:58 +0000 (09:53 -0400)] 
Revert "Add built-in fuzzing harnesses for security testing."

This reverts commit 4a18907b412e77684bf888ad6d1b4844d220196a.

inadvertenly pushed, mea culpa

10 days agoUse size_t instead of Size in pg_waldump
Andrew Dunstan [Fri, 10 Apr 2026 13:29:00 +0000 (09:29 -0400)] 
Use size_t instead of Size in pg_waldump

In commit b15c1513984 I missed the memo about not using Size in new
code.

Per complaint from Thomas Munro

Discussion: https://postgr.es/m/CA+hUKGJkeTVuq5u5WKJm6xkwmW577UuQ7fA=PyBCSR3h9g2GtQ@mail.gmail.com

10 days agoAdd built-in fuzzing harnesses for security testing.
Andrew Dunstan [Thu, 9 Apr 2026 18:20:40 +0000 (14:20 -0400)] 
Add built-in fuzzing harnesses for security testing.

Add 12 libFuzzer-compatible fuzzing harnesses behind a new -Dfuzzing=true
meson option.  Each harness implements LLVMFuzzerTestOneInput() and can
also be built in standalone mode (reading from files) when no fuzzer
engine is detected.

Frontend targets (no backend dependencies):
  fuzz_json            - non-incremental JSON parser (pg_parse_json)
  fuzz_json_incremental - incremental/chunked JSON parser
  fuzz_conninfo        - libpq connection string parser (PQconninfoParse)
  fuzz_pglz            - PGLZ decompressor (pglz_decompress)
  fuzz_unescapebytea   - libpq bytea unescape (PQunescapeBytea)
  fuzz_b64decode       - base64 decoder (pg_b64_decode)
  fuzz_saslprep        - SASLprep normalization (pg_saslprep)
  fuzz_parsepgarray    - array literal parser (parsePGArray)
  fuzz_pgbench_expr    - pgbench expression parser (via Bison/Flex)

Backend targets (link against postgres_lib):
  fuzz_rawparser       - SQL raw parser (raw_parser)
  fuzz_regex           - regex engine (pg_regcomp/pg_regexec)
  fuzz_typeinput       - type input functions (numeric/date/timestamp/interval)

10 days agoFix heap-buffer-overflow in pglz_decompress() on corrupt input.
Andrew Dunstan [Thu, 9 Apr 2026 15:48:55 +0000 (11:48 -0400)] 
Fix heap-buffer-overflow in pglz_decompress() on corrupt input.

When decoding a match tag, pglz_decompress() reads 2 bytes (or 3
for extended-length matches) from the source buffer before checking
whether enough data remains.  The existing bounds check (sp > srcend)
occurs after the reads, so truncated compressed data that ends
mid-tag causes a read past the allocated buffer.

Fix by validating that sufficient source bytes are available before
reading each part of the match tag.  The post-read sp > srcend
check is no longer needed and is removed.

Found by fuzz testing with libFuzzer and AddressSanitizer.

10 days agoFix incremental JSON parser numeric token reassembly across chunks.
Andrew Dunstan [Thu, 9 Apr 2026 11:57:07 +0000 (07:57 -0400)] 
Fix incremental JSON parser numeric token reassembly across chunks.

When the incremental JSON parser splits a numeric token across chunk
boundaries, it accumulates continuation characters into the partial
token buffer.  The accumulator's switch statement unconditionally
accepted '+', '-', '.', 'e', and 'E' as valid numeric continuations
regardless of position, which violated JSON number grammar
(-? int [frac] [exp]).  For example, input "4-" fed in single-byte
chunks would accumulate the '-' into the numeric token, producing an
invalid token that later triggered an assertion failure during
re-lexing.

Fix by tracking parser state (seen_dot, seen_exp, prev character)
across the existing partial token and incoming bytes, so that each
character class is accepted only in its grammatically valid position.

10 days agoAdd test case for same-type reordered FK columns
Amit Langote [Fri, 10 Apr 2026 08:44:06 +0000 (17:44 +0900)] 
Add test case for same-type reordered FK columns

The test added in 980c1a85d819 covered reordered FK columns with
different types, which triggered an "operator not a member of opfamily"
error in the fast-path prior to that commit.  Add a test for the
same-type case, which is also fixed by that commit but where the wrong
scan key ordering instead produced a spurious FK violation without any
internal error.

Reported-by: Fredrik Widlert <fredrik.widlert@digpro.se>
Discussion: https://postgr.es/m/CADfhSr8hYc-4Cz7vfXH_oV-Jq81pyK9W4phLrOGspovsg2W7Kw@mail.gmail.com

10 days agoMove afterTriggerFiringDepth into AfterTriggersData
Amit Langote [Fri, 10 Apr 2026 07:16:07 +0000 (16:16 +0900)] 
Move afterTriggerFiringDepth into AfterTriggersData

The static variable afterTriggerFiringDepth introduced by commit
5c54c3ed1b9 is logically part of the after-trigger state and in
hindsight should have been a field in AfterTriggersData alongside
query_depth and the other per-transaction after-trigger state.
Move it there as firing_depth.  Also update its comment to
accurately reflect its sole remaining purpose: signaling to
AfterTriggerIsActive() that after-trigger firing is active.

Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/CA+HiwqFt4NGTNk7BinOsHHM48E9zGAa852vCfGoSe1bbL=JNFQ@mail.gmail.com

10 days agoFix var_is_nonnullable() to account for varreturningtype
Richard Guo [Fri, 10 Apr 2026 06:51:00 +0000 (15:51 +0900)] 
Fix var_is_nonnullable() to account for varreturningtype

var_is_nonnullable() failed to consider varreturningtype, which meant
it could incorrectly claim a Var is non-nullable based on a column's
NOT NULL constraint even when the Var refers to a non-existent row.
Specifically, OLD.col is NULL for INSERT (no old row exists) and
NEW.col is NULL for DELETE (no new row exists), regardless of any NOT
NULL constraint on the column.

This caused the planner's constant folding in eval_const_expressions
to incorrectly simplify IS NULL / IS NOT NULL tests on such Vars.  For
example, "old.a IS NULL" in an INSERT's RETURNING clause would be
folded to false when column "a" has a NOT NULL constraint, even though
the correct result is true.

Fix by returning false from var_is_nonnullable() when varreturningtype
is not VAR_RETURNING_DEFAULT, since such Vars can be NULL regardless
of table constraints.

Author: SATYANARAYANA NARLAPURAM <satyanarlapuram@gmail.com>
Reviewed-by: Tender Wang <tndrwang@gmail.com>
Reviewed-by: Richard Guo <guofenglinux@gmail.com>
Discussion: https://postgr.es/m/CAHg+QDfaAipL6YzOq2H=gAhKBbcUTYmfbAv+W1zueOfRKH43FQ@mail.gmail.com

10 days agoAssert index_attnos[0] == 1 in ri_FastPathFlushArray()
Amit Langote [Fri, 10 Apr 2026 06:24:38 +0000 (15:24 +0900)] 
Assert index_attnos[0] == 1 in ri_FastPathFlushArray()

ri_FastPathFlushArray() handles single-column FKs only, so
index_attnos[0] is always 1.  Add an Assert to make this invariant
explicit, as a followup to 980c1a85d819.

Suggested-by: Junwang Zhao <zhjwpku@gmail.com> (offlist)
Discussion: https://www.postgresql.org/message-id/CADfhSr-pCkbDxmiOVYSAGE5QGjsQ48KKH_W424SPk%2BpwzKZFaQ%40mail.gmail.com

10 days agoFix FK fast-path scan key ordering for mismatched column order
Amit Langote [Fri, 10 Apr 2026 04:33:55 +0000 (13:33 +0900)] 
Fix FK fast-path scan key ordering for mismatched column order

The fast-path foreign key check introduced in 2da86c1ef9b assumed that
constraint key positions directly correspond to index column positions.
This is not always true as a FK constraint can reference PK columns in a
different order than they appear in the PK's unique index.

For example, if the PK is (a, b, c) and the FK references them as
(a, c, b), the constraint stores keys in the FK-specified order, but
the index has columns in PK order. The buggy code used the constraint
key index to access rd_opfamily[i], which retrieved the wrong operator
family when columns were reordered, causing "operator X is not a member
of opfamily Y" errors.

After fixing the opfamily lookup, a second issue started to happen:
btree index scans require scan keys to be ordered by attribute number.
The code was placing scan keys at array position i with attribute number
idx_attno, producing out-of-order keys when columns were swapped. This
caused "btree index keys must be ordered by attribute" errors.

The fix adds an index_attnos array to FastPathMeta that maps each
constraint key position to its corresponding index column position.
In ri_populate_fastpath_metadata(), we search indkey to find the actual
index column for each pk_attnums[i] and use that position for the
opfamily lookup. In build_index_scankeys(), we place each scan key at
the array position corresponding to its index column
(skeys[idx_attno-1]) rather than at the constraint key position,
ensuring scan keys are properly ordered by attribute number as btree
requires.

Reported-by: Fredrik Widlert <fredrik.widlert@digpro.se>
Author: Matheus Alcantara <matheusssilv97@gmail.com>
Reviewed-by: Junwang Zhao <zhjwpku@gmail.com>
Discussion: https://www.postgresql.org/message-id/CADfhSr-pCkbDxmiOVYSAGE5QGjsQ48KKH_W424SPk%2BpwzKZFaQ%40mail.gmail.com

10 days agoFix typo left by 34a30786293
Amit Langote [Fri, 10 Apr 2026 04:32:38 +0000 (13:32 +0900)] 
Fix typo left by 34a30786293

Reported-by: jie wang <jugierwang@gmail.com>
Reported-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/CAJnZyeDyaS=X-eYN=9rDYqK=6ma1gMLa0qDgfNbZKK0e0+q99Q@mail.gmail.com

10 days agoFix RI fast-path crash under nested C-level SPI
Amit Langote [Fri, 10 Apr 2026 03:40:09 +0000 (12:40 +0900)] 
Fix RI fast-path crash under nested C-level SPI

When a C-language function uses SPI_connect/SPI_execute/SPI_finish to
INSERT into a table with FK constraints, the FK AFTER triggers fire
and schedule ri_FastPathEndBatch via
RegisterAfterTriggerBatchCallback(), opening PK relations under
CurrentResourceOwner at the time of the SPI call.  The query_depth > 0
guard in FireAfterTriggerBatchCallbacks suppresses the callback at
that nesting level, deferring teardown to the outer query's
AfterTriggerEndQuery. By then the resource owner active during the SPI
call may have been released, decrementing the cached relations'
refcounts to zero. ri_FastPathTeardown, running under the outer
query's resource owner, then crashes in assert builds when it attempts
to close relations whose refcounts are already zero:

  TRAP: failed Assert("rel->rd_refcnt > 0")

Fix by storing batch callbacks at the level where they should fire:
in AfterTriggersQueryData.batch_callbacks for immediate constraints
(fired by AfterTriggerEndQuery) and in AfterTriggersData.batch_callbacks
for deferred constraints (fired by AfterTriggerFireDeferred and
AfterTriggerSetState).  RegisterAfterTriggerBatchCallback() routes the
callback to the current query-level list when query_depth >= 0, and to
the top-level list otherwise.  FireAfterTriggerBatchCallbacks() takes a
list parameter and simply iterates and invokes it; memory cleanup is
handled by the caller.  This replaces the query_depth > 0 guard with
list-level scoping.  Note that deferred constraints are unaffected by
this bug: their callbacks fire at commit via AfterTriggerFireDeferred,
under the outer transaction's resource owner, which remains valid
throughout.

Also add firing_batch_callbacks to AfterTriggersData to enforce that
callbacks do not register new callbacks during
FireAfterTriggerBatchCallbacks(), which would be unsafe as it could
modify the list being iterated.  An Assert in
RegisterAfterTriggerBatchCallback() enforces this discipline for
future callers.  The flag is reset at transaction and subtransaction
boundaries to handle cases where an error thrown by a callback is
caught and the subtransaction is rolled back.

While at it, ensure callbacks are properly accounted for at all
transaction boundaries, as cleanup of b7b27eb41a5c: discard any
remaining top-level callbacks on both commit and abort in
AfterTriggerEndXact(), and clean up query-level callbacks in
AfterTriggerFreeQuery().

Note that ri_PerformCheck() calls SPI with fire_triggers=false, which
skips AfterTriggerBeginQuery/EndQuery for that SPI command.  Any
triggers queued during that SPI command are not fired immediately but
deferred to the outer query level.  Since the fast-path check for
those triggers runs under the outer query's resource owner rather than
a nested SPI resource owner, and ri_PerformCheck() does not create
a dedicated child resource owner, the bug described above does not
apply.

Reported-by: Evan Montgomery-Recht <montge@mianetworks.net>
Reported-by: Sandro Santilli <strk@kbt.io>
Analyzed-by: Evan Montgomery-Recht <montge@mianetworks.net>
Author: Amit Langote <amitlangote09@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/CAEg7pwcKf01FmDqFAf-Hzu_pYnMYScY_Otid-pe9uw3BJ6gq9g@mail.gmail.com

10 days agoDocument new catalog columns, missed in commit 8185bb5347.
Jeff Davis [Fri, 10 Apr 2026 03:29:42 +0000 (20:29 -0700)] 
Document new catalog columns, missed in commit 8185bb5347.

Reported-by: "Shinoda, Noriyoshi (PSD Japan FSI)" <noriyoshi.shinoda@hpe.com>
Co-authored-by: "Shinoda, Noriyoshi (PSD Japan FSI)" <noriyoshi.shinoda@hpe.com>
Discussion: https://postgr.es/m/LV8PR84MB3787135EBDBF7747A05731F3EE592@LV8PR84MB3787.NAMPRD84.PROD.OUTLOOK.COM

10 days agoZero-fill private_data when attaching an injection point
Michael Paquier [Fri, 10 Apr 2026 02:17:09 +0000 (11:17 +0900)] 
Zero-fill private_data when attaching an injection point

InjectionPointAttach() did not initialize the private_data buffer of the
shared memory entry before (perhaps partially) overwriting it.  When the
private data is set to NULL by the caler, the buffer was left
uninitialized.  If set, it could have stale contents.

The buffer is initialized to zero, so as the contents recorded when a
point is attached are deterministic.

Author: Sami Imseih <samimseih@gmail.com>
Discussion: https://postgr.es/m/CAA5RZ0tsGHu2h6YLnVu4HiK05q+gTE_9WVUAqihW2LSscAYS-g@mail.gmail.com
Backpatch-through: 17

11 days agoFix double-free in pg_stat_autovacuum_scores.
Nathan Bossart [Thu, 9 Apr 2026 18:07:06 +0000 (13:07 -0500)] 
Fix double-free in pg_stat_autovacuum_scores.

Presently, relation_needs_vacanalyze() unconditionally frees the
pgstat entry returned by pgstat_fetch_stat_tabentry_ext().  This
behavior was first added by commit 02502c1bca to avoid memory
leakage in autovacuum.  While this is fine for autovacuum since it
forces stats_fetch_consistency to "none", it is not okay for other
callers that use "cache" or "snapshot".  This manifests as a
double-free when pg_stat_autovacuum_scores is called multiple times
in the same transaction.

To fix, add a "bool *may_free" parameter to
pgstat_fetch_stat_tabentry_ext() that returns whether it is safe
for the caller to explicitly pfree() the result.  If a caller would
rather leave it to the memory context machinery to free the result,
it can pass NULL as the "may_free" argument (or just ignore its
value).

Oversight in commit 87f61f0c82.

Reported-by: Tender Wang <tndrwang@gmail.com>
Reported-by: Alexander Lakhin <exclusion@gmail.com>
Suggested-by: Andres Freund <andres@anarazel.de>
Suggested-by: Tom Lane <tgl@sss.pgh.pa.us>
Author: Sami Imseih <samimseih@gmail.com>
Discussion: https://postgr.es/m/CAHewXNkJKdwb3D5OnksrdOqzqUnXUEMpDam1TPW0vfUkW%3D7jUw%40mail.gmail.com
Discussion: https://postgr.es/m/5684f479-858e-4c5d-b8f5-bcf05de1f909%40gmail.com

11 days agoRemove an unstable wait from parallel autovacuum regression test.
Masahiko Sawada [Thu, 9 Apr 2026 16:13:32 +0000 (09:13 -0700)] 
Remove an unstable wait from parallel autovacuum regression test.

The test 001_parallel_autovacuum.pl verified that vacuum delay
parameters are propagated to parallel vacuum workers by using
injection points. It previously waited for autovacuum to complete on
the test_autovac table. However, since injection points are
cluster-wide, an autovacuum worker could be triggered on tables in
other databases (e.g., template1) and get stuck at the same injection
point. This could lead to a timeout when the test waits for the
expected table's autovacuum to finish.

This commit removes the wait for autovacuum completion from this
specific test case. Since the primary goal is to verify the
propagation of parameter updates, which is already confirmed via log
messages, waiting for the entire vacuum process to finish is
unnecessary and prone to instability in concurrent test environments.

Author: Sami Imseih <samimseih@gmail.com>
Discussion: https://postgr.es/m/CAA5RZ0s+kZZRMSF4HW7tZ9W2jS1o4B+Fg8dr5a-T6mANX+mdQA@mail.gmail.com

11 days agoinstrumentation: Avoid CPUID 0x15/0x16 for Hypervisor TSC frequency
Andres Freund [Thu, 9 Apr 2026 15:50:24 +0000 (11:50 -0400)] 
instrumentation: Avoid CPUID 0x15/0x16 for Hypervisor TSC frequency

This restricts the retrieval of the TSC frequency whilst under a Hypervisor to
either Hypervisor-specific CPUID registers (0x40000010), or TSC
calibration. We previously allowed retrieving from the traditional CPUID
registers for TSC frequency (0x15/0x16) like on bare metal, but it turns out
that they are not trustworthy when virtualized and can report wildly incorrect
frequencies, like 7 kHz when the actual calibrated frequencty is 2.5 GHz.

Per report from buildfarm member drongo.

Author: Lukas Fittl <lukas@fittl.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/jr4hk2sxhqcfpb67ftz5g4vw33nm67cgf7go3wwmqsafu5aclq%405m67ukuhyszz

11 days agoAdd LOG_NEVER error level code.
Nathan Bossart [Thu, 9 Apr 2026 15:18:15 +0000 (10:18 -0500)] 
Add LOG_NEVER error level code.

This logging level means not to emit the log, which is useful for
functions like relation_needs_vacanalyze().  This function accepts
a log level argument but not all callers want it to emit logs.

Suggested-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/3101163.1775676098%40sss.pgh.pa.us

11 days agoFix integer overflow in nodeWindowAgg.c
Richard Guo [Thu, 9 Apr 2026 10:28:33 +0000 (19:28 +0900)] 
Fix integer overflow in nodeWindowAgg.c

In nodeWindowAgg.c, the calculations for frame start and end positions
in ROWS and GROUPS modes were performed using simple integer addition.
If a user-supplied offset was sufficiently large (close to INT64_MAX),
adding it to the current row or group index could cause a signed
integer overflow, wrapping the result to a negative number.

This led to incorrect behavior where frame boundaries that should have
extended indefinitely (or beyond the partition end) were treated as
falling at the first row, or where valid rows were incorrectly marked
as out-of-frame.  Depending on the specific query and data, these
overflows can result in incorrect query results, execution errors, or
assertion failures.

To fix, use overflow-aware integer addition (ie, pg_add_s64_overflow)
to check for overflows during these additions.  If an overflow is
detected, the boundary is now clamped to INT64_MAX.  This ensures the
logic correctly treats the boundary as extending to the end of the
partition.

Bug: #19405
Reported-by: Alexander Lakhin <exclusion@gmail.com>
Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Tender Wang <tndrwang@gmail.com>
Discussion: https://postgr.es/m/19405-1ecf025dda171555@postgresql.org
Backpatch-through: 14

11 days agoUpdate config.guess and config.sub
Peter Eisentraut [Thu, 9 Apr 2026 09:26:14 +0000 (11:26 +0200)] 
Update config.guess and config.sub

11 days agoStrip PlaceHolderVars from partition pruning operands
Richard Guo [Thu, 9 Apr 2026 07:41:31 +0000 (16:41 +0900)] 
Strip PlaceHolderVars from partition pruning operands

When pulling up a subquery, its targetlist items may be wrapped in
PlaceHolderVars to enforce separate identity or as a result of outer
joins.  This causes any upper-level WHERE clauses referencing these
outputs to contain PlaceHolderVars, which prevents partprune.c from
recognizing that they match partition key columns, defeating partition
pruning.

To fix, strip PlaceHolderVars from operands before comparing them to
partition keys.  A PlaceHolderVar with empty phnullingrels appearing
in a relation-scan-level expression is effectively a no-op, so
stripping it is safe.  This parallels the existing treatment in
indxpath.c for index matching.

In passing, rename strip_phvs_in_index_operand() to strip_noop_phvs()
and move it from indxpath.c to placeholder.c, since it is now a
general-purpose utility used by both index matching and partition
pruning code.

Back-patch to v18.  Although this issue exists before that, changes in
that version made it common enough to notice.  Given the lack of field
reports for older versions, I am not back-patching further.  In the
v18 back-patch, strip_phvs_in_index_operand() is retained as a thin
wrapper around the new strip_noop_phvs() to avoid breaking third-party
extensions that may reference it.

Reported-by: Cándido Antonio Martínez Descalzo <candido@ninehq.com>
Diagnosed-by: David Rowley <dgrowleyml@gmail.com>
Author: Richard Guo <guofenglinux@gmail.com>
Discussion: https://postgr.es/m/CAH5YaUwVUWETTyVECTnhs7C=CVwi+uMSQH=cOkwAUqMdvXdwWA@mail.gmail.com
Backpatch-through: 18

11 days agoAdd nkeys parameter to recheck_matched_pk_tuple()
Amit Langote [Thu, 9 Apr 2026 05:45:31 +0000 (14:45 +0900)] 
Add nkeys parameter to recheck_matched_pk_tuple()

The function looped over ii_NumIndexKeyAttrs elements of the skeys
array, but one caller (ri_FastPathFlushArray) passes a one-element
array since it only handles single-column FKs.  The function
signature did not communicate this constraint, which static analysis
flags as a potential out-of-bounds read.

Add an nkeys parameter and assert that it matches
ii_NumIndexKeyAttrs, then use it in the loop.  The call sites
already know the key count.

Reported-by: Evan Montgomery-Recht <montge@mianetworks.net>
Discussion: https://postgr.es/m/CAEg7pwcKf01FmDqFAf-Hzu_pYnMYScY_Otid-pe9uw3BJ6gq9g@mail.gmail.com

11 days agoReduce presence of syscache.h in src/include/
Michael Paquier [Wed, 8 Apr 2026 23:49:36 +0000 (08:49 +0900)] 
Reduce presence of syscache.h in src/include/

ee642cccc43c has added syscache.h in inval.h and objectaddress.h,
enlarging by a lot the footprint of this header, particularly via
objectaddress.h.  A change in syscache.h would cause a lot more files to
be recompiled.

This commit reduces the presence of syscache.h by switching to a direct
use of syscache_ids.h in inval.h and objectaddress.h, where the enum
SysCacheIdentifier is defined.  genbki.pl gains an #ifndef block for
this header, so as its inclusion is more controlled.

Reported-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/vlcexdcimsmvu3aplt2yxpfndkgtuvjsrms2fdl46rbw3k2kug@drspkoxlaije