postgresql.git
90 min agoDoc: improve documentation about width_bucket(). master github/master
Tom Lane [Sat, 21 Jun 2025 16:52:37 +0000 (12:52 -0400)]
Doc: improve documentation about width_bucket().

Specify whether the bucket bounds are inclusive or exclusive,
and improve some other vague language.  Explain the behavior that
occurs when the "low" bound is greater than the "high" bound.
Make width_bucket_numeric's comment more like that for
width_bucket_float8, in particular noting that infinite
bounds are rejected (since they became possible in v14).

Reported-by: Ben Peachey Higdon <[email protected]>
Author: Robert Treat <[email protected]>
Co-authored-by: Tom Lane <[email protected]>
Reviewed-by: Dean Rasheed <[email protected]>
Discussion: https://postgr.es/m/2BD74F86-5B89-4AC1-8F13-23CED3546AC1@gmail.com
Backpatch-through: 13

14 hours agodoc PG 18 relnotes: update to current, add one commit
Bruce Momjian [Sat, 21 Jun 2025 03:53:15 +0000 (23:53 -0400)]
doc PG 18 relnotes:  update to current, add one commit

14 hours agodoc PG 18 relnotes: indent tag blocks
Bruce Momjian [Sat, 21 Jun 2025 03:37:30 +0000 (23:37 -0400)]
doc PG 18 relnotes:  indent tag blocks

15 hours agodoc PG 18 relnotes: add remaining missing link tags
Bruce Momjian [Sat, 21 Jun 2025 02:44:18 +0000 (22:44 -0400)]
doc PG 18 relnotes:  add remaining missing link tags

22 hours agoRemove planner's have_dangerous_phv() join-order restriction.
Tom Lane [Fri, 20 Jun 2025 19:55:12 +0000 (15:55 -0400)]
Remove planner's have_dangerous_phv() join-order restriction.

Commit 85e5e222b, which added (a forerunner of) this logic,
argued that

    Adding the necessary complexity to make this work doesn't seem like
    it would be repaid in significantly better plans, because in cases
    where such a PHV exists, there is probably a corresponding join order
    constraint that would allow a good plan to be found without using the
    star-schema exception.

The flaw in this claim is that there may be other join-order
restrictions that prevent us from finding a join order that doesn't
involve a "dangerous" PHV.  In particular we now recognize that
small join_collapse_limit or from_collapse_limit could prevent it.
Therefore, let's bite the bullet and make the case work.

We don't have to extend the executor's support for nestloop parameters
as I thought at the time, because we can instead push the evaluation
of the placeholder's expression into the left-hand input of the
NestLoop node.  So there's not really a lot of downside to this
solution, and giving the planner more join-order flexibility should
have value beyond just avoiding failure.

Having said that, there surely is a nonzero risk of introducing
new bugs.  Since this failure mode escaped detection for ten years,
such cases don't seem common enough to justify a lot of risk.
Therefore, let's put this fix into master but leave the back branches
alone (for now anyway).

Bug: #18953
Reported-by: Alexander Lakhin <[email protected]>
Diagnosed-by: Richard Guo <[email protected]>
Author: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/18953-1c9883a9d4afeb30@postgresql.org

24 hours agoUse SnapshotDirty when checking for conflicting index names.
Tom Lane [Fri, 20 Jun 2025 17:41:11 +0000 (13:41 -0400)]
Use SnapshotDirty when checking for conflicting index names.

While choosing an autogenerated name for an index, look for
pre-existing relations using a SnapshotDirty snapshot, instead of the
previous behavior that considered only committed-good pg_class rows.
This allows us to detect and avoid conflicts against indexes that are
still being built.

It's still possible to fail due to a race condition, but the window
is now just the amount of time that it takes DefineIndex to validate
all its parameters, call smgrcreate(), and enter the index's pg_class
row.  Formerly the race window covered the entire time needed to
create and fill an index, which could be very long if the table is
large.  Worse, if the conflicting index creation is part of a larger
transaction, it wouldn't be visible till COMMIT.

So this isn't a complete solution, but it should greatly ameliorate
the problem, and the patch is simple enough to be back-patchable.

It might at some point be useful to do the same for pg_constraint
entries (cf. ChooseConstraintName, ConstraintNameExists, and related
functions).  However, in the absence of field complaints, I'll leave
that alone for now.  The relation-name test should be good enough for
index-based constraints, while foreign-key constraints seem to be okay
since they require exclusive locks to create.

Bug: #18959
Reported-by: Maximilian Chrzan <[email protected]>
Author: Tom Lane <[email protected]>
Reviewed-by: Dilip Kumar <[email protected]>
Discussion: https://postgr.es/m/18959-f63b53b864bb1417@postgresql.org
Backpatch-through: 13

26 hours agopgxs.mk: remove unreachable rule for deleting regress.def.
Tom Lane [Fri, 20 Jun 2025 16:12:29 +0000 (12:12 -0400)]
pgxs.mk: remove unreachable rule for deleting regress.def.

We never create regress.def, and if we did this code would fail to
delete it, because "win" is not the correct PORTNAME for Windows.

This thinko seems to have originated in commit 7a6b562fd from 1999,
although it got moved around multiple times since then.

Author: Christoph Berg <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/[email protected]

43 hours agoImprove runtime and output of tests for replication slots checkpointing.
Alexander Korotkov [Thu, 19 Jun 2025 22:41:28 +0000 (01:41 +0300)]
Improve runtime and output of tests for replication slots checkpointing.

The TAP tests that verify logical and physical replication slot behavior
during checkpoints (046_checkpoint_logical_slot.pl and
047_checkpoint_physical_slot.pl) inserted two batches of 2 million rows each,
generating approximately 520 MB of WAL.  On slow machines, or when compiled
with '-DRELCACHE_FORCE_RELEASE -DCATCACHE_FORCE_RELEASE', this caused the
tests to run for 8-9 minutes and occasionally time out, as seen on the
buildfarm animal prion.

This commit modifies the mentioned tests to utilize the $node->advance_wal()
function, thereby reducing runtime. Once we do not use the generated data,
the proposed function is a good alternative, which cuts the total wall-clock
run time.

While here, remove superfluous '\n' characters from several note() calls;
these appeared literally in the build-farm logs and looked odd.  Also, remove
excessive 'shared_preload_libraries' GUC from the config and add a check for
'injection_points' extension availability.

Reported-by: Alexander Lakhin <[email protected]>
Reported-by: Tom Lane <[email protected]>
Author: Alexander Korotkov <[email protected]>
Author: Vitaly Davydov <[email protected]>
Reviewed-by: Hayato Kuroda <[email protected]>
Discussion: https://postgr.es/m/fbc5d94e-6fbd-4a64-85d4-c9e284a58eb2%40gmail.com
Backpatch-through: 17

45 hours agodoc PG 18 relnotes: add links to command and struct tags
Bruce Momjian [Thu, 19 Jun 2025 21:13:58 +0000 (17:13 -0400)]
doc PG 18 relnotes:  add links to command and struct tags

46 hours agoCorrect docs about partitions and EXCLUDE constraints.
Jeff Davis [Thu, 19 Jun 2025 19:43:27 +0000 (12:43 -0700)]
Correct docs about partitions and EXCLUDE constraints.

In version 17 we added support for cross-partition EXCLUDE
constraints, as long as they included all partition key columns and
compared them with equality (see 8c852ba9a4). I updated the docs for
exclusion constraints, but I missed that the docs for CREATE TABLE
still said that they were not supported. This commit fixes that.

Author: Paul A. Jungwirth <[email protected]>
Co-authored-by: Jeff Davis <[email protected]>
Discussion: https://postgr.es/m/c955d292-b92d-42d1-a2a0-1ec6715a2546@illuminatedcomputing.com
Backpatch-through: 17

2 days agodoc PG 18 relnotes: add links for applications
Bruce Momjian [Thu, 19 Jun 2025 15:59:00 +0000 (11:59 -0400)]
doc PG 18 relnotes:  add links for applications

2 days agodoc: add xreflabel text for libpq and PL/Python
Bruce Momjian [Thu, 19 Jun 2025 15:50:50 +0000 (11:50 -0400)]
doc:  add xreflabel text for libpq and PL/Python

to be used for PG 18 release notes

2 days agoImprove pg_dump/pg_dumpall help synopses and terminology
Peter Eisentraut [Thu, 19 Jun 2025 11:53:12 +0000 (13:53 +0200)]
Improve pg_dump/pg_dumpall help synopses and terminology

Increase consistency of --help and man page synopses between pg_dump
and pg_dumpall.  These should now be very similar, as pg_dumpall can
now also produce non-text dump output.  But actually, they had drifted
further apart.

- Use verb "export" consistently, instead of "dump" or "extract".
- Use "SQL script" instead of just "script" or "text file".
- Maintain consistent distinction between SQL script and other
  formats/archives (which is relevant for pg_restore).

Reviewed-by: Robert Treat <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/3f71d8a7-095b-4829-9b0b-fce09e9866b3%40eisentraut.org

2 days agoImprove log messages and docs for slot synchronization.
Amit Kapila [Thu, 19 Jun 2025 04:18:08 +0000 (09:48 +0530)]
Improve log messages and docs for slot synchronization.

Improve the clarity of LOG messages when a failover logical slot
synchronization fails, making the reasons more explicit for easier
debugging.

Update the documentation to outline scenarios where slot synchronization
can fail, especially during the initial sync, and emphasize that
pg_sync_replication_slot() is primarily intended for testing and
debugging purposes.

We also discussed improving the functionality of
pg_sync_replication_slot() so that it can be used reliably, but we would
take up that work for next version after some more discussion and review.

Reported-by: Suraj Kharage <[email protected]>
Author: shveta malik <[email protected]>
Reviewed-by: Zhijie Hou <[email protected]>
Reviewed-by: Peter Smith <[email protected]>
Reviewed-by: Amit Kapila <[email protected]>
Backpatch-through: 17, where it was introduced
Discussion: https://postgr.es/m/CAF1DzPWTcg+m+x+oVVB=y4q9=PYYsL_mujVp7uJr-_oUtWNGbA@mail.gmail.com

2 days agodoc PG 18 relnotes: add links for server variables
Bruce Momjian [Thu, 19 Jun 2025 01:19:42 +0000 (21:19 -0400)]
doc PG 18 relnotes:  add links for server variables

2 days agodoc: Mention GIN indexes support parallel builds.
Fujii Masao [Thu, 19 Jun 2025 00:12:34 +0000 (09:12 +0900)]
doc: Mention GIN indexes support parallel builds.

Commit 8492feb98f6 added support for parallel CREATE INDEX on GIN indexes.
However, previously two places in the documentation and two in the source
code comments still stated that only B-tree and BRIN indexes support
parallel builds.

This commit updates those references to correctly include GIN indexes.

Author: Fujii Masao <[email protected]>
Reviewed-by: Robert Treat <[email protected]>
Discussion: https://postgr.es/m/7d27d068-90e2-4022-9bd7-09b0fd3d4f47@oss.nttdata.com

2 days agodoc: Fix incorrect description of INCLUDING COMMENTS in CREATE FOREIGN TABLE.
Fujii Masao [Thu, 19 Jun 2025 00:07:19 +0000 (09:07 +0900)]
doc: Fix incorrect description of INCLUDING COMMENTS in CREATE FOREIGN TABLE.

Commit 302cf157592 added support for LIKE in CREATE FOREIGN TABLE.
In this feature, since indexes are not created for foreign tables,
comments on indexes are not copied either.

However, the documentation incorrectly stated that index comments
would be copied when using INCLUDING COMMENTS. This commit
corrects that by removing the mention of index comments.

Author: Fujii Masao <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
Discussion: https://postgr.es/m/f86cd84f-a6a3-4451-bae7-5cca9e63b06d@oss.nttdata.com

2 days agodoc: fix for commit 09f7d36ba16 in changing "_" to "-".
Bruce Momjian [Wed, 18 Jun 2025 20:48:26 +0000 (16:48 -0400)]
doc:  fix for commit 09f7d36ba16 in changing "_" to "-".

I thought underscores wouldn't even work in "id"s, so I never checked to
see if anything referenced it, but it seems it does work, so adjust the
calling site for the dash syntax.

2 days agodoc config.sgml: use "-" and not "_" for varlistentry "id"s
Bruce Momjian [Wed, 18 Jun 2025 20:43:27 +0000 (16:43 -0400)]
doc config.sgml:  use "-" and not "_" for varlistentry "id"s

Change "id"s of file_copy_method and enable_self_join_elimination for
consistency with the rest of the guc "id"s.  These are new entries for
PG 18.

3 days agopg_dump: Allow pg_dump to dump the statistics for foreign tables.
Fujii Masao [Wed, 18 Jun 2025 05:53:55 +0000 (14:53 +0900)]
pg_dump: Allow pg_dump to dump the statistics for foreign tables.

Commit 1fd1bd87101 introduced support for dumping statistics with
pg_dump and pg_dumpall, covering tables, materialized views, and indexes.
However, it overlooked foreign tables, even though functions like
pg_restore_relation_stats() support them.

This commit fixes that oversight by allowing pg_dump and pg_dumpall
to include statistics for foreign tables.

Author: Fujii Masao <[email protected]>
Reviewed-by: Corey Huinker <[email protected]>
Reviewed-by: Nathan Bossart <[email protected]>
Discussion: https://postgr.es/m/3772e4e4-ef39-4deb-bb76-aa8165f33fb6@oss.nttdata.com

3 days agoDocument "relrewrite" at the top of heap_create_with_catalog()
Michael Paquier [Wed, 18 Jun 2025 02:03:21 +0000 (11:03 +0900)]
Document "relrewrite" at the top of heap_create_with_catalog()

This parameter has been introduced in 325f2ec5557f, and it was not
documented contrary to all the other arguments of
heap_create_with_catalog().

Reviewed-by: Yugo Nagata <[email protected]>
Reviewed-by: Steven Niu <[email protected]>
Discussion: https://postgr.es/m/[email protected]

3 days agodoc: Reorder protocol version option descriptions in libpq docs.
Fujii Masao [Wed, 18 Jun 2025 00:18:40 +0000 (09:18 +0900)]
doc: Reorder protocol version option descriptions in libpq docs.

Commit 285613c60a7 introduced the min_protocol_version and
max_protocol_version connection options for libpq, but their descriptions
were placed in the middle of the unrelated ssl_min_protocol_version and
ssl_max_protocol_version entries.

This commit moves the min_protocol_version and max_protocol_version
descriptions to appear after the SSL-related options. This improves
the logical order and makes it easier for users to locate the relevant
settings in the libpq documentation.

Author: Fujii Masao <[email protected]>
Reviewed-by: Jelte Fennema-Nio <[email protected]>
Discussion: https://postgr.es/m/a3391f36-30f5-4d4a-825b-232476819de8@oss.nttdata.com

3 days agodoc PG 18 relnotes: add markup, still need to add links
Bruce Momjian [Wed, 18 Jun 2025 00:00:38 +0000 (20:00 -0400)]
doc PG 18 relnotes:  add markup, still need to add links

3 days agoFix allocation check to test the right variable
Daniel Gustafsson [Tue, 17 Jun 2025 20:42:38 +0000 (22:42 +0200)]
Fix allocation check to test the right variable

The memory allocation for cancelConn->be_cancel_key was accidentally
checking the be_cancel_key member in the conn object instead of the
one in cancelConn.

Author: Ranier Vilela <[email protected]>
Reviewed-by: Daniel Gustafsson <[email protected]>
Discussion: https://postgr.es/m/CAEudQAq4ySDR6dsg9xwurBXwud02hX7XCOZZAcZx-JMn6A06nA@mail.gmail.com

4 days agoamcheck: Fix posting tree checks in gin_index_check()
Tomas Vondra [Tue, 17 Jun 2025 14:48:09 +0000 (16:48 +0200)]
amcheck: Fix posting tree checks in gin_index_check()

Fix two issues in parent_key validation in posting trees:

* It's not enough to check stack->parentblk is valid to determine if the
  parentkey is valid. It's possible parentblk is set to a valid block
  number, but parentkey is invalid. So check parentkey directly.

* We don't need to invalidate parentkey for all child pages of the
  rightmost page. It's enough to invalidate it for the rightmost child
  only, which means we can check more cases (less false negatives).

Issues reported by Arseniy Mukhin, along with a proposed patch. Review
by Andrey M. Borodin, cleanup and improvements by me.

Author: Arseniy Mukhin <[email protected]>
Reviewed-by: Andrey M. Borodin <[email protected]>
Discussion: https://postgr.es/m/CAE7r3MJ611B9TE=YqBBncewp7-k64VWs+sjk7XF6fJUX77uFBA@mail.gmail.com

4 days agoamcheck: Fix parent key check in gin_index_check()
Tomas Vondra [Tue, 17 Jun 2025 13:46:26 +0000 (15:46 +0200)]
amcheck: Fix parent key check in gin_index_check()

The checks introduced by commit 14ffaece0fb5 did not get the parent key
checks quite right, missing some data corruption cases. In particular:

* The "rightlink" check was not working as intended, because rightlink
  is a BlockNumber, and InvalidBlockNumber is 0xFFFFFFFF, so

    !GinPageGetOpaque(page)->rightlink

  almost always evaluates to false (except for rightlink=0). So in most
  cases parenttup was left NULL, preventing any checks against parent.

* Use GinGetDownlink() to retrieve child blkno to avoid triggering
  Assert, same as the core GIN code.

Issues reported by Arseniy Mukhin, along with a proposed patch. Review
by Andrey M. Borodin, cleanup and improvements by me.

Author: Arseniy Mukhin <[email protected]>
Reviewed-by: Andrey M. Borodin <[email protected]>
Discussion: https://postgr.es/m/CAE7r3MJ611B9TE=YqBBncewp7-k64VWs+sjk7XF6fJUX77uFBA@mail.gmail.com

4 days agoamcheck: Fix checks of entry order for GIN indexes
Tomas Vondra [Tue, 17 Jun 2025 12:55:27 +0000 (14:55 +0200)]
amcheck: Fix checks of entry order for GIN indexes

This tightens a couple checks in checking GIN indexes, which might have
resulted in incorrect results (false positives/negatives).

* The code skipped ordering checks if the entries were for different
  attributes (for multi-column GIN indexes), possibly missing some cases
  of data corruption. But the attribute number is part of the ordering,
  so we can check that.

* The root page was skipped when checking entry order, but that is
  unnecessary. The root page is subject to the same ordering rules, we
  can process it just like any other page.

* The high key on the right-most page was not checked, but that is
  needed only for inner pages (we don't store the high key for those).
  For leaf pages we can check the high key just fine.

* Correct the detection of split pages. If the page gets split, the
  cached parent key is greater than the current child key (not less, as
  the code incorrectly expected).

Issues reported by Arseniy Mukhin, along with a proposed patch. Review
by Andrey M. Borodin, cleanup and improvements by me.

Author: Arseniy Mukhin <[email protected]>
Reviewed-by: Andrey M. Borodin <[email protected]>
Discussion: https://postgr.es/m/CAE7r3MJ611B9TE=YqBBncewp7-k64VWs+sjk7XF6fJUX77uFBA@mail.gmail.com

4 days agoamcheck: Remove unused GinScanItem->parentlsn field
Tomas Vondra [Tue, 17 Jun 2025 12:16:35 +0000 (14:16 +0200)]
amcheck: Remove unused GinScanItem->parentlsn field

The field was introduced by commit 14ffaece0fb5, but is unused and
unnecessary. So remove it.

Issues reported by Arseniy Mukhin, along with a proposed patch. Review
by Andrey M. Borodin, cleanup and minor improvements by me.

Author: Arseniy Mukhin <[email protected]>
Reviewed-by: Andrey M. Borodin <[email protected]>
Discussion: https://postgr.es/m/CAE7r3MJ611B9TE=YqBBncewp7-k64VWs+sjk7XF6fJUX77uFBA@mail.gmail.com

4 days agoamcheck: Test gin_index_check on a multicolumn index
Tomas Vondra [Tue, 17 Jun 2025 12:14:36 +0000 (14:14 +0200)]
amcheck: Test gin_index_check on a multicolumn index

Adds a regression test with gin_index_check() on a multicolumn index,
to verify it's handled correctly and improve test coverage for code
introduced by 14ffaece0fb5.

Author: Arseniy Mukhin <[email protected]>
Reviewed-by: Andrey M. Borodin <[email protected]>
Discussion: https://postgr.es/m/CAE7r3MJ611B9TE=YqBBncewp7-k64VWs+sjk7XF6fJUX77uFBA@mail.gmail.com

4 days agodoc: Mention the default io_method
Peter Eisentraut [Tue, 17 Jun 2025 05:39:43 +0000 (07:39 +0200)]
doc: Mention the default io_method

It was previously not documented.

Author: Daniel Westermann (DWE) <[email protected]>
Reviewed-by: Pavel Stehule <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/ZR0P278MB04279CB0C1D8F49DE68F168ED2AF2%40ZR0P278MB0427.CHEP278.PROD.OUTLOOK.COM

4 days agodoc PG 18 relnotes: add author for initdb commit 04bec894a04
Bruce Momjian [Tue, 17 Jun 2025 01:04:14 +0000 (21:04 -0400)]
doc PG 18 relnotes:  add author for initdb commit 04bec894a04

Needed to run src/tools//add_commit_links.pl.

4 days agoFix re-distributing previously distributed invalidation messages during logical decoding.
Masahiko Sawada [Tue, 17 Jun 2025 00:36:01 +0000 (17:36 -0700)]
Fix re-distributing previously distributed invalidation messages during logical decoding.

Commit 4909b38af0 introduced logic to distribute invalidation messages
from catalog-modifying transactions to all concurrent in-progress
transactions. However, since each transaction distributes not only its
original invalidation messages but also previously distributed
messages to other transactions, this leads to an exponential increase
in allocation request size for invalidation messages, ultimately
causing memory allocation failure.

This commit fixes this issue by tracking distributed invalidation
messages separately per decoded transaction and not redistributing
these messages to other in-progress transactions. The maximum size of
distributed invalidation messages that one transaction can store is
limited to MAX_DISTR_INVAL_MSG_PER_TXN (8MB). Once the size of the
distributed invalidation messages exceeds this threshold, we
invalidate all caches in locations where distributed invalidation
messages need to be executed.

Back-patch to all supported versions where we introduced the fix by
commit 4909b38af0.

Note that this commit adds two new fields to ReorderBufferTXN to store
the distributed transactions. This change breaks ABI compatibility in
back branches, affecting third-party extensions that depend on the
size of the ReorderBufferTXN struct, though this scenario seems
unlikely.

Additionally, it adds a new flag to the txn_flags field of
ReorderBufferTXN to indicate distributed invalidation message
overflow. This should not affect existing implementations, as it is
unlikely that third-party extensions use unused bits in the txn_flags
field.

Bug: #18938 #18942
Author: vignesh C <[email protected]>
Reported-by: Duncan Sands <[email protected]>
Reported-by: John Hutchins <[email protected]>
Reported-by: Laurence Parry <[email protected]>
Reported-by: Max Madden <[email protected]>
Reported-by: Braulio Fdo Gonzalez <[email protected]>
Reviewed-by: Masahiko Sawada <[email protected]>
Reviewed-by: Amit Kapila <[email protected]>
Reviewed-by: Hayato Kuroda <[email protected]>
Discussion: https://postgr.es/m/680bdaf6-f7d1-4536-b580-05c2760c67c6@deepbluecap.com
Discussion: https://postgr.es/m/18942-0ab1e5ae156613ad@postgresql.org
Discussion: https://postgr.es/m/18938-57c9a1c463b68ce0@postgresql.org
Discussion: https://postgr.es/m/CAD1FGCT2sYrP_70RTuo56QTizyc+J3wJdtn2gtO3VttQFpdMZg@mail.gmail.com
Discussion: https://postgr.es/m/CANO2=B=2BT1hSYCE=nuuTnVTnjidMg0+-FfnRnqM6kd23qoygg@mail.gmail.com
Backpatch-through: 13

4 days agoFix possible Assert failure in verify_compact_attribute()
David Rowley [Mon, 16 Jun 2025 22:49:36 +0000 (10:49 +1200)]
Fix possible Assert failure in verify_compact_attribute()

Sometimes the TupleDesc used in verify_compact_attribute() is shared
among backends, and since CompactAttribute.attcacheoff gets updated
during tuple deformation, it was possible that another backend would
set attcacheoff on a given CompactAttribute in the small window of time
from when the attcacheoff from the live CompactAttribute was being set
in the 'tmp' CompactAttribute and before the Assert verifying that the
live and tmp CompactAttributes matched.

Here we adjust the code to make a copy of the live CompactAttribute so
that we're not trying to Assert against a shared copy of it.

Author: David Rowley <[email protected]>
Reported-by: Alexander Lakhin <[email protected]>
Discussion: https://postgr.es/m/7195e408-758c-4031-8e61-4f842c716ac0@gmail.com

5 days agoaio: Add missing memory barrier when waiting for IO handle
Andres Freund [Mon, 16 Jun 2025 16:36:01 +0000 (12:36 -0400)]
aio: Add missing memory barrier when waiting for IO handle

Previously there was no memory barrier enforcing correct memory ordering when
waiting for a free IO handle. However, in the much more common case of waiting
for IO to complete, memory barriers already were present.

On strongly ordered architectures like x86 this had no negative consequences,
but on some armv8 hardware (observed on Apple hardware), it was possible for
the update, in the IO worker, to PgAioHandle->state to become visible before
->distilled_result becoming visible, leading to rather confusing assertion
failures. The failures were rare enough that the bug sometimes took days to
reproduce when running 027_stream_regress in a loop.

Once finally debugged, it was easy enough to come up with a much quicker
repro: Trigger a lot of very fast IO by limiting io_combine_limit to 1 and
ensure that we always have to wait for a free handle by setting
io_max_concurrency to 1. Triggering lots of concurrent seqscans in that setup
triggers the issue within seconds.

One reason this was hard to debug was that the assertion failure most commonly
happened in WaitReadBuffers(), rather than in the AIO subsystem itself. The
assertions added in this commit make problems like this easier to understand.

Also add a comment to the IO worker explaining that we rely on the lwlock
acquisition for correct memory ordering.

I think it'd be good to add a tap test that stress tests buffer IO, but that's
material for a separate patch.

Thanks a lot to Alexander and Konstantin for all the debugging help.

Reported-by: Tom Lane <[email protected]>
Reported-by: Alexander Lakhin <[email protected]>
Investigated-by: Andres Freund <[email protected]>
Investigated-by: Alexander Lakhin <[email protected]>
Investigated-by: Konstantin Knizhnik <[email protected]>
Discussion: https://postgr.es/m/2dkz7azclpeiqcmouamdixyn5xhlzy4rvikxrbovyzvi6rnv5c@pz7o7osv2ahf

5 days agodoc: Clean up title case use
Peter Eisentraut [Mon, 16 Jun 2025 09:43:52 +0000 (11:43 +0200)]
doc: Clean up title case use

5 days agolibpq-oauth: Add exports.list to .gitignore
Peter Eisentraut [Mon, 16 Jun 2025 09:16:52 +0000 (11:16 +0200)]
libpq-oauth: Add exports.list to .gitignore

5 days agoMessage style improvements
Peter Eisentraut [Mon, 16 Jun 2025 09:14:39 +0000 (11:14 +0200)]
Message style improvements

Some message style improvements in new code, and some small
refactorings to make translations easier.

5 days agoWorkaround code generation bug in clang
John Naylor [Mon, 16 Jun 2025 02:27:15 +0000 (09:27 +0700)]
Workaround code generation bug in clang

At optimization level -O0, builds on recent clang fail to produce the
correct CRC32C with our AVX-512 implementation. For now, just disable
the runtime check for clang at -O0. When this is fixed upstream and we
know the extent of the breakage, we can adjust to be version-specific.

Reported-by: Soumyadeep Chakraborty <[email protected]>
Reported-by: Andy Fan <[email protected]>
Tested-by: Andy Fan <[email protected]>
Discussion: https://postgr.es/m/CAE-ML%2B-OV6p9uvCFBcSQjZUEh__y0h-KjN%2BBseyGJHt7u8EP%2Bw%40mail.gmail.com
Discussion: https://postgr.es/m/87o6uqd3iv.fsf%40163.com

6 days agoAdd commit b27644bad to .git-blame-ignore-revs.
Tom Lane [Sun, 15 Jun 2025 17:11:04 +0000 (13:11 -0400)]
Add commit b27644bad to .git-blame-ignore-revs.

6 days agoSync typedefs.list with the buildfarm.
Tom Lane [Sun, 15 Jun 2025 17:04:24 +0000 (13:04 -0400)]
Sync typedefs.list with the buildfarm.

Our maintenance of typedefs.list has been a little haphazard
(and apparently we can't alphabetize worth a darn).  Replace
the file with the authoritative list from our buildfarm, and
run pgindent using that.

I also updated the additions/exclusions lists in pgindent where
necessary to keep pgindent from messing things up significantly.
Notably, now that regex_t and some related names are macros not real
typedefs, we have to whitelist them explicitly.  The exclusions list
has also drifted noticeably, presumably due to changes of system
headers on the buildfarm animals that contribute to the list.

Unlike in prior years, I've not manually added typedef names that
are missing from the buildfarm's list because they are not used to
declare any variables or fields.  So there are a few places where
the typedef declaration itself is formatted worse than before,
e.g. typedef enum IoMethod.  I could preserve the names that were
manually added to the list previously, but I'd really prefer to find
a less manual way of dealing with these cases.  A quick grep finds
about 75 such symbols, most of which have never gotten any special
treatment.

Per discussion among pgsql-release, doing this now seems appropriate
even though we're still a week or two away from making the v18 branch.

6 days agopsql: Change new \conninfo to use SSL instead of TLS
Peter Eisentraut [Sun, 15 Jun 2025 08:59:30 +0000 (10:59 +0200)]
psql: Change new \conninfo to use SSL instead of TLS

Commit bba2fbc6238 introduced a new implementation of the \conninfo
command in psql.  That new code uses the term "TLS" while the rest of
PostgreSQL, including the rest of psql, consistently uses "SSL".  This
is uselessly confusing.  This changes the new code to use "SSL" as
well.

Reviewed-by: Alvaro Herrera <[email protected]>
Discussion: https://www.postgresql.org/message-id/f4ff9294-b491-4053-83f5-11c10ab8c999@eisentraut.org

7 days agoImprove comments for TidRangeEval
David Rowley [Sat, 14 Jun 2025 05:18:31 +0000 (17:18 +1200)]
Improve comments for TidRangeEval

Here we provide a bit more detail on why TidRangeEval() does return false
when trss_mintid is greater than trss_maxtid.

Reported-by: Junwang Zhao <[email protected]>
Author: David Rowley <[email protected]>
Reviewed-by: Junwang Zhao <[email protected]>
Discussion: https://postgr.es/m/CAEG8a3KUbUUqQgfK5X8Sj-%2BppPtGNTU%2BZiep0Rxr7SLjoR%2BB6w%40mail.gmail.com

7 days agodoc: Add note about "Client User" and "Superuser" fields in \conninfo output.
Fujii Masao [Sat, 14 Jun 2025 01:39:26 +0000 (10:39 +0900)]
doc: Add note about "Client User" and "Superuser" fields in \conninfo output.

In the \conninfo psql command, the "Client User" column shows the user who
established the connection, while the "Superuser" column reflects whether
the current user in the current execution context is a superuser. This means
the users referred to in these columns can differ, for example, if the current
user was changed with the SET ROLE command.

This commit adds a note to the \conninfo documentation to clarify
this behavior and avoid potential confusion.

Author: Fujii Masao <[email protected]>
Reviewed-by: Robert Treat <[email protected]>
Reviewed-by: David G. Johnston <[email protected]>
Discussion: https://postgr.es/m/685961b8-b6ce-40bb-b2d5-c2ff135d3388@oss.nttdata.com

7 days agopsql: Report full protocol version in \conninfo output.
Fujii Masao [Sat, 14 Jun 2025 01:37:12 +0000 (10:37 +0900)]
psql: Report full protocol version in \conninfo output.

Commit bba2fbc6238 modified \conninfo to display the protocol version
used by the current connection, but it only showed the major version (e.g., 3).

This commit updates \conninfo to display the full protocol version (e.g., 3.2).
Since support for new version 3.2 was added in v18, and the server supports
both 3.0 and 3.2, showing the complete version helps users understand
exactly which protocol version the current session is using.

Although this is a minor behavior change, it's considered a fix for
an oversight in the original patch and is included in v18.

Author: Fujii Masao <[email protected]>
Reviewed-by: David G. Johnston <[email protected]>
Discussion: https://postgr.es/m/685961b8-b6ce-40bb-b2d5-c2ff135d3388@oss.nttdata.com

7 days agoAdd TAP tests to check replication slot advance during the checkpoint
Alexander Korotkov [Sat, 14 Jun 2025 00:35:27 +0000 (03:35 +0300)]
Add TAP tests to check replication slot advance during the checkpoint

The new tests verify that logical and physical replication slots are still
valid after an immediate restart on checkpoint completion when the slot was
advanced during the checkpoint.

This commit introduces two new injection points to make these tests possible:

* checkpoint-before-old-wal-removal - triggered in the checkpointer process
  just before old WAL segments cleanup;
* logical-replication-slot-advance-segment - triggered in
  LogicalConfirmReceivedLocation() when restart_lsn was changed enough to
  point to the next WAL segment.

Discussion: https://postgr.es/m/flat/1d12d2-67235980-35-19a406a0%4063439497
Author: Vitaly Davydov <[email protected]>
Author: Tomas Vondra <[email protected]>
Reviewed-by: Alexander Korotkov <[email protected]>
Reviewed-by: Amit Kapila <[email protected]>
Backpatch-through: 17

7 days agoKeep WAL segments by slot's last saved restart LSN
Alexander Korotkov [Sat, 14 Jun 2025 00:36:04 +0000 (03:36 +0300)]
Keep WAL segments by slot's last saved restart LSN

The patch fixes the issue with the unexpected removal of old WAL segments
after checkpoint, followed by an immediate restart.  The issue occurs when
a slot is advanced after the start of the checkpoint and before old WAL
segments are removed at the end of the checkpoint.

The patch introduces a new in-memory state for slots: last_saved_restart_lsn,
which is used to calculate the oldest LSN for removing WAL segments. This
state is updated every time with the current restart_lsn at the moment when
the slot is saved to disk.

This fix changes the shared memory layout.  It's applied to HEAD only because
we don't have to preserve ABI compatibility during the beta stage.  Another
fix that doesn't affect the ABI is committed to back branches.

Discussion: https://postgr.es/m/1d12d2-67235980-35-19a406a0%4063439497
Author: Vitaly Davydov <[email protected]>
Author: Alexander Korotkov <[email protected]>
Reviewed-by: Amit Kapila <[email protected]>
7 days agonbtree: _bt_readnextpage doesn't affect markPos.
Peter Geoghegan [Fri, 13 Jun 2025 23:58:47 +0000 (19:58 -0400)]
nbtree: _bt_readnextpage doesn't affect markPos.

_bt_readnextpage expects so->currPos.buf to be InvalidBuffer (and for
the position's page to be unlocked) when called.  However, it does not
expect there to be no pins held on any page.  In particular, so->markPos
might hold a separate pin, both before and after the call.  Fix some
comments that seemed to suggest otherwise.

Follow-up commit to commit 7c319f54, which made _bt_killitems drop pins
it acquired itself.

8 days agoComment fixups from 626df47ad9.
Jeff Davis [Fri, 13 Jun 2025 17:02:24 +0000 (10:02 -0700)]
Comment fixups from 626df47ad9.

Reported-by: Peter Smith <[email protected]>
Discussion: https://postgr.es/m/CAHut+PspbHQmRCBL1c-opoJeTUKUaFFfUQJd2rhDZqwUrWCi7w@mail.gmail.com

8 days agopsql: Reword help message and docs for WATCH_INTERVAL
Daniel Gustafsson [Fri, 13 Jun 2025 13:13:09 +0000 (15:13 +0200)]
psql: Reword help message and docs for WATCH_INTERVAL

Reword the documentation around the default value to make interaction
between WATCH_INTERVAL and the \watch command clearer.  While there,
also remove a stray parenthesis left over from a previous version of
the patch.

Reported-by: Peter Eisentraut <[email protected]>
Reviewed-by: David G. Johnston <[email protected]>
Discussion: https://postgr.es/m/c34a650b-6f8b-4da7-9ebb-b6df03ce009d@eisentraut.org

8 days agopsql: Forbid use of COPY and \copy while in a pipeline
Michael Paquier [Fri, 13 Jun 2025 01:15:17 +0000 (10:15 +0900)]
psql: Forbid use of COPY and \copy while in a pipeline

Running COPY within a pipeline can break protocol synchronization in
multiple ways.  psql is limited in terms of result processing if mixing
COPY commands with normal queries while controlling a pipeline with the
new meta-commands, as an effect of the following reasons:
- In COPY mode, the backend ignores additional Sync messages and will
not send a matching ReadyForQuery expected by the frontend.  Doing a
\syncpipeline just after COPY will leave the frontend waiting for a
ReadyForQuery message that won't be sent, leaving psql out-of-sync.
- libpq automatically sends a Sync with the Copy message which is not
tracked in the command queue, creating an unexpected synchronisation
point that psql cannot really know about.  While it is possible to track
such activity for a \copy, this cannot really be done sanely with plain
COPY queries.  Backend failures during a COPY would leave the pipeline
in an aborted state while the backend would be in a clean state, ready
to process commands.

At the end, fixing those issues would require modifications in how libpq
handles pipeline and COPY.  So, rather than implementing workarounds in
psql to shortcut the libpq internals (with command queue handling for
one), and because meta-commands for pipelines in psql are a new feature
with COPY in a pipeline having a limited impact compared to other
queries, this commit forbids the use of COPY within a pipeline to avoid
possible break of protocol synchronisation within psql.  If there is a
use-case for COPY support within pipelines in libpq, this could always
be added in the future, if necessary.

Most of the changes of this commit impacts the tests for psql pipelines,
removing the tests related to COPY.  Some TAP tests still exist for COPY
TO/FROM and \copy to/from, to check that that connections are aborted
when this operation is attempted.

Reported-by: Nikita Kalinin <[email protected]>
Author: Anthonin Bonnefoy <[email protected]>
Discussion: https://postgr.es/m/AC468509-06E8-4E2A-A4B1-63046A4AC6AB@postgrespro.ru

8 days agoReplace %llu by PRIu64 in AIO io_uring code
Michael Paquier [Thu, 12 Jun 2025 23:59:47 +0000 (08:59 +0900)]
Replace %llu by PRIu64 in AIO io_uring code

This is a continuation of 15a79c73111f, cleaning up the AIO io_uring
code that has been committed after that while still using %llu.

The code changed here is new in v18, so cleaning things now means less
conflicts if this area of the code changes on backpatch once the 18
stable branch is created.

Reviewed-by: Nathan Bossart <[email protected]>
Reviewed-by: Peter Eisentraut <[email protected]>
Discussion: https://postgr.es/m/[email protected]

9 days agopg_restore: Fix wrong descriptions of --with-{schema,data,statistics} options.
Fujii Masao [Thu, 12 Jun 2025 14:25:21 +0000 (23:25 +0900)]
pg_restore: Fix wrong descriptions of --with-{schema,data,statistics} options.

Commit bde2fb797aa added the --with-schema, --with-data, and --with-statistics
options to pg_restore. These options control whether to restore schema, data,
or statistics if present in the archive. However, the help message and
documentation incorrectly described them as affecting what gets dumped.

This commit corrects those descriptions to clarify that the options control
restoration, not dumping.

Bug: #18952
Reported-by: TAKATSUKA Haruka <[email protected]>
Author: Fujii Masao <[email protected]>
Reviewed-by: TAKATSUKA Haruka <[email protected]>
Reviewed-by: Daniel Gustafsson <[email protected]>
Discussion: https://postgr.es/m/18952-be40a620f8b1e755@postgresql.org

9 days agoFix squashing algorithm for query texts
Álvaro Herrera [Thu, 12 Jun 2025 12:21:21 +0000 (14:21 +0200)]
Fix squashing algorithm for query texts

The algorithm to squash lists of constants added by commit 62d712ecfd94
was a bit too simplistic; we wanted to avoid adding unnecessary
complexity, but cases like direct function calls of typecasting
functions (and others) were missed, and bogus SQL syntax was being shown
in pg_stat_statements normalized query text field.  To fix normalization
for those cases, we need the parser to transmit information about were
each list of constant values starts and ends, so add that to a couple of
nodes.  Also add a few more test cases to make sure we're doing the
right thing.

The patch initially submitted by Sami added a new private struct in
gram.y to carry the start/end information for A_Expr, but I (Álvaro)
decided that a better fix was to remove the parser indirection via the
in_expr production, and instead create separate components in the a_expr
rule.  I'm surprised that this works and doesn't require more changes,
but I assume (without checking) that the grammar used to be more complex
and got simplified at some point.

Bump catversion.

Author: Sami Imseih <[email protected]>
Author: Dmitry Dolgov <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
Discussion: https://postgr.es/m/CAA5RZ0tRXoPG2y6bMgBCWNDt0Tn=unRerbzYM=oW0syi1=C1OA@mail.gmail.com

9 days agodoc: Document that MAINTAIN privilege allows statistics manipulation functions.
Fujii Masao [Thu, 12 Jun 2025 05:53:32 +0000 (14:53 +0900)]
doc: Document that MAINTAIN privilege allows statistics manipulation functions.

Database object statistics manipulation functions were introduced
in PostgreSQL 18 and are permitted under the MAINTAIN privilege.
However, the documentation previously did not mention these functions
in the list of allowed operations.

This commit updates the MAINTAIN privilege documentation to
explicitly include statistics manipulation functions, clarifying
what the privilege covers.

Author: Fujii Masao <[email protected]>
Reviewed-by: Robert Treat <[email protected]>
Discussion: https://postgr.es/m/7c7e1ad5-fdf9-486f-bc63-40ac99b0461d@oss.nttdata.com

9 days agoRevert support for improved tracking of nested queries
Michael Paquier [Thu, 12 Jun 2025 01:08:55 +0000 (10:08 +0900)]
Revert support for improved tracking of nested queries

This commit reverts the two following commits:
499edb09741b, track more precisely query locations for nested
statements.
06450c7b8c70, a follow-up fix of 499edb09741b with query locations.
The test introduced in this commit is not reverted.  This is proving
useful to track a problem that only pgaudit was able to detect.

These prove to have issues with the tracking of SELECT statements, when
these use multiple parenthesis which is something supported by the
grammar.  Incorrect location and lengths are causing pg_stat_statements
to become confused, failing its job in query normalization with
potential out-of-bound writes because the location and the length may
not match with what can be handled.  A lot of the query patterns
discussed when this issue was reported have no test coverage in the main
regression test suite, or the recovery test 027_stream_regress.pl would
have caught the problems as pg_stat_statements is loaded by the node
running the regression tests.  A first step would be to improve the test
coverage to stress more the query normalization logic.

A different portion of this work was done in 45e0ba30fc40, with the
addition of tests for nested queries.  These can be left in the tree.
They are useful to track the way inner queries are currently tracked by
PGSS with non-top-level entries, and will be useful when reconsidering
in the future the work reverted here.

Reported-by: Alexander Kozhemyakin <[email protected]>
Discussion: https://postgr.es/m/18947-cdd2668beffe02bf@postgresql.org

9 days agoRevert "nbtree: Remove useless row compare arg."
Peter Geoghegan [Wed, 11 Jun 2025 22:16:15 +0000 (18:16 -0400)]
Revert "nbtree: Remove useless row compare arg."

This reverts commit 54c6ea8c81db718508eeea50991d3c1c5dff54a5.

Further analysis has shown that the forcenonrequired row compare
behavior is in fact necessary, despite the new restrictions on
RowCompares imposed by _bt_set_startikey following commit 5f4d98d4.

Discussion: https://postgr.es/m/CAH2-Wzm3bKcz3TbHGem3_+SinEyG=VZVPbApQghp7YiZj+MM3g@mail.gmail.com

9 days agoRevert a few small patches that were intended for version 19.
Jeff Davis [Wed, 11 Jun 2025 22:03:52 +0000 (15:03 -0700)]
Revert a few small patches that were intended for version 19.

4c787a24e7e220a60022e47c1776f22f72902899
78bd364ee39ca70a8f9cb8719282389866a08e14
7a6880fadc177873d5663961ec3a02d67e34dcbe
8898082a5d3e94eef073f0e08124137e096e78ef

Suggested-by: Robert Haas <[email protected]>
Discussion: https://postgr.es/m/CA+TgmoZ=J=PVNZUNKaxULu+KUVSt3Y-aJ1DZ9Y3Co6mu0z62jA@mail.gmail.com
Discussion: https://postgr.es/m/60e8c6d0a6c08e67f15dbbe9e53df0119c710065[email protected]

9 days agoAdd tab completion for REJECT_LIMIT option.
Masahiko Sawada [Wed, 11 Jun 2025 18:44:25 +0000 (11:44 -0700)]
Add tab completion for REJECT_LIMIT option.

This addresses an oversight in commit 4ac2a9bec, which introduced the
REJECT_LIMIT option to the COPY command.

Author: Atsushi Torikoshi <[email protected]>
Reviewed-by: Yugo Nagata <[email protected]>
Discussion: https://postgr.es/m/ac23e824d1d602f113a89c91ee56fb23@oss.nttdata.com

10 days agoMake _bt_killitems drop pins it acquired itself.
Peter Geoghegan [Wed, 11 Jun 2025 13:17:35 +0000 (09:17 -0400)]
Make _bt_killitems drop pins it acquired itself.

Teach nbtree's _bt_killitems to leave the so->currPos page that it sets
LP_DEAD items on in whatever state it was in when _bt_killitems was
called.  In particular, make sure that so->dropPin scans don't acquire a
pin whose reference is saved in so->currPos.buf.

Allowing _bt_killitems to change so->currPos.buf like this is wrong.
The immediate consequence of allowing it is that code in _bt_steppage
(that copies so->currPos into so->markPos) will behave as if the scan is
a !so->dropPin scan.  so->markPos will therefore retain the buffer pin
indefinitely, even though _bt_killitems only needs to acquire a pin
(along with a lock) for long enough to mark known-dead items LP_DEAD.

This issue came to light following a report of a failure of an assertion
from recent commit e6eed40e.  The test case in question involves the use
of mark and restore.  An initial call to _bt_killitems takes place that
leaves so->currPos.buf in a state that is inconsistent with the scan
being so->dropPin.  A subsequent call to _bt_killitems for the same
position (following so->currPos being saved in so->markPos, and then
restored as so->currPos) resulted in the failure of an assertion that
tests that so->currPos.buf is InvalidBuffer when the scan is so->dropPin
(non-assert builds got a "resource was not closed" WARNING instead).

The same problem exists on earlier releases, though the issue is far
more subtle there.  Recent commit e6eed40e introduced the so->dropPin
field as a partial replacement for testing so->currPos.buf directly.
Earlier releases won't get an assertion failure (or buffer pin leak),
but they will allow the second _bt_killitems call from the test case to
behave as if a buffer pin was consistently held since the original call
to _bt_readpage.  This is wrong; there will have been an initial window
during which no pin was held on the so->currPos page, and yet the second
_bt_killitems call will neglect to check if so->currPos.lsn continues to
match the page's now-current LSN.

As a result of all this, it's just about possible that _bt_killitems
will set the wrong items LP_DEAD (on release branches).  This could only
happen with merge joins (the sole user of nbtree mark/restore support),
when a concurrently inserted index tuple used a recently-recycled TID
(and only when the new tuple was inserted onto the same page as a
distinct concurrently-removed tuple with the same TID).  This is exactly
the scenario that _bt_killitems' check of the page's now-current LSN
against the LSN stashed in currPos was supposed to prevent.

A follow-up commit will make nbtree completely stop conditioning whether
or not a position's pin needs to be dropped on whether the 'buf' field
is set.  All call sites that might need to drop a still-held pin will be
taught to rely on the scan-level so->dropPin field recently introduced
by commit e6eed40e.  That will make bugs of the same general nature as
this one impossible (or make them much easier to detect, at least).

Author: Peter Geoghegan <[email protected]>
Reported-By: Alexander Lakhin <[email protected]>
Discussion: https://postgr.es/m/545be1e5-3786-439a-9257-a90d30f8b849@gmail.com
Backpatch-through: 13

10 days agopsql: Remove PARTITION BY clause in tab completion for unlogged tables
Michael Paquier [Wed, 11 Jun 2025 00:27:28 +0000 (09:27 +0900)]
psql: Remove PARTITION BY clause in tab completion for unlogged tables

CREATE UNLOGGED TABLE was still being recommended by psql's tab
completion as a possible pattern, but the backend is rejecting this
option since e2bab2d79204.

Reported-by: Shinya Kato <[email protected]>
Reviewed-by: Nathan Bossart <[email protected]>
Reviewed-by: Shinya Kato <[email protected]>
Discussion: https://postgr.es/m/CAOzEurQZ1a+6d1K8b=+Ww1NFQVwAt9KSCQsBWXYBaPnYCenK3g@mail.gmail.com

10 days agoDon't reduce output request size on non-Unix-socket connections.
Tom Lane [Tue, 10 Jun 2025 22:39:34 +0000 (18:39 -0400)]
Don't reduce output request size on non-Unix-socket connections.

Traditionally, libpq's pqPutMsgEnd has rounded down the amount-to-send
to be a multiple of 8K when it is eagerly writing some data.  This
still seems like a good idea when sending through a Unix socket, as
pipes typically have a buffer size of 8K or some fraction/multiple of
that.  But there's not much argument for it on a TCP connection, since
(a) standard MTU values are not commensurate with that, and (b) the
kernel typically applies its own packet splitting/merging logic.

Worse, our SSL and GSSAPI code paths both have API stipulations that
if they fail to send all the data that was offered in the previous
write attempt, we mustn't offer less data in the next attempt; else
we may get "SSL error: bad length" or "GSSAPI caller failed to
retransmit all data needing to be retried".  The previous write
attempt might've been pqFlush attempting to send everything in the
buffer, so pqPutMsgEnd can't safely write less than the full buffer
contents.  (Well, we could add some more state to track exactly how
much the previous write attempt was, but there's little value evident
in such extra complication.)  Hence, apply the round-down only on
AF_UNIX sockets, where we never use SSL or GSSAPI.

Interestingly, we had a very closely related bug report before,
which I attempted to fix in commit d053a879b.  But the test case
we had then seemingly didn't trigger this pqFlush-then-pqPutMsgEnd
scenario, or at least we failed to recognize this variant of the bug.

Bug: #18907
Reported-by: Dorjpalam Batbaatar <[email protected]>
Author: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/18907-d41b9bcf6f29edda@postgresql.org
Backpatch-through: 13

10 days agoinet_net_pton.c: use pg_ascii_tolower() rather than tolower().
Jeff Davis [Tue, 10 Jun 2025 18:23:20 +0000 (11:23 -0700)]
inet_net_pton.c: use pg_ascii_tolower() rather than tolower().

Avoid dependence on setlocale(). No behavior change.

Discussion: https://postgr.es/m/9875f7f9-50f1-4b5d-86fc-ee8b03e8c162@eisentraut.org
Reviewed-by: Peter Eisentraut <[email protected]>
10 days agoisn.c: use pg_ascii_toupper() instead of toupper().
Jeff Davis [Tue, 10 Jun 2025 18:23:11 +0000 (11:23 -0700)]
isn.c: use pg_ascii_toupper() instead of toupper().

Avoid dependence on setlocale(). No behavior change.

Discussion: https://postgr.es/m/9875f7f9-50f1-4b5d-86fc-ee8b03e8c162@eisentraut.org
Reviewed-by: Peter Eisentraut <[email protected]>
10 days agocontrib/spi/refint.c: use pg_ascii_tolower() instead.
Jeff Davis [Tue, 10 Jun 2025 18:23:05 +0000 (11:23 -0700)]
contrib/spi/refint.c: use pg_ascii_tolower() instead.

Avoid dependence on setlocale(). No behavior change.

Discussion: https://postgr.es/m/9875f7f9-50f1-4b5d-86fc-ee8b03e8c162@eisentraut.org
Reviewed-by: Peter Eisentraut <[email protected]>
11 days agocopyfromparse.c: use pg_ascii_tolower() rather than tolower().
Jeff Davis [Tue, 10 Jun 2025 18:22:57 +0000 (11:22 -0700)]
copyfromparse.c: use pg_ascii_tolower() rather than tolower().

Avoid dependence on setlocale(). No behavior change.

Discussion: https://postgr.es/m/9875f7f9-50f1-4b5d-86fc-ee8b03e8c162@eisentraut.org
Reviewed-by: Peter Eisentraut <[email protected]>
11 days agoUse exported symbols list on macOS for loadable modules as well
Peter Eisentraut [Tue, 10 Jun 2025 05:04:43 +0000 (07:04 +0200)]
Use exported symbols list on macOS for loadable modules as well

On macOS, when building with the make system, the exported symbols
list $(SHLIB_EXPORTS) was ignored.  This was probably not intentional,
it was probably just forgotten, since that combination has never
actually been used until now (for libpq-oauth).

The meson build system handles this correctly.  Also, other platforms
have been doing this correctly.

This fixes it.  It also does a bit of refactoring to make the code
match the layout for other platforms.

Reviewed-by: Jacob Champion <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/c70ca32e-b109-460d-9810-6e23ebb4473f%40eisentraut.org

12 days agopg_restore: fix incompatibility with old directory-format dumps.
Tom Lane [Sun, 8 Jun 2025 21:06:39 +0000 (17:06 -0400)]
pg_restore: fix incompatibility with old directory-format dumps.

pg_restore failed to restore large objects (blobs) out of
directory-format dumps made by versions before PG v12.
That's because, due to a bug fixed in commit 548e50976, those
old versions put the wrong filename into the BLOBS TOC entry.
Said bug was harmless before v17, because we ignored the
incorrect filename field --- but commit a45c78e32 assumed it
would be correct.

Reported-by: Pavel Stehule <[email protected]>
Author: Pavel Stehule <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/CAFj8pRCrZ=_e1Rv1N+6vDaH+6gf=9A2mE2J4RvnvKA1bLiXvXA@mail.gmail.com
Backpatch-through: 17

13 days agoRevert "postgres_fdw: Inherit the local transaction's access/deferrable modes."
Etsuro Fujita [Sun, 8 Jun 2025 08:30:00 +0000 (17:30 +0900)]
Revert "postgres_fdw: Inherit the local transaction's access/deferrable modes."

We concluded that commit e5a3c9d9b is a feature rather than a fix; since
it was added after feature freeze, revert it.

Reported-by: Fujii Masao <[email protected]>
Reported-by: Michael Paquier <[email protected]>
Reported-by: Robert Haas <[email protected]>
Discussion: https://postgr.es/m/ed2296f1-1a6b-4932-b870-5bb18c2591ae%40oss.nttdata.com

2 weeks agodoc PG 18 relnotes: add AFTER trigger user change item
Bruce Momjian [Sat, 7 Jun 2025 15:25:17 +0000 (11:25 -0400)]
doc PG 18 relnotes:  add AFTER trigger user change item

Reported-by: Noah Misch
Discussion: https://postgr.es/m/20250603172123[email protected]

2 weeks agodoc PG 18 relnotes: adjust wording of initdb item 48814415d5a
Bruce Momjian [Sat, 7 Jun 2025 15:06:25 +0000 (11:06 -0400)]
doc PG 18 relnotes:  adjust wording of initdb item 48814415d5a

And move to the top of the incompatibility list.  This will impact users
more than any other incompatibility item because of pg_upgrade.

2 weeks agoplpython: Remove obsolete test expected file
Peter Eisentraut [Sat, 7 Jun 2025 07:03:11 +0000 (09:03 +0200)]
plpython: Remove obsolete test expected file

Move plpython_error_5.out to plpython_error.out, since the pre-3.5
version is no longer needed, since we raised the Python requirement to
3.6 (commit 45363fca637).

Reviewed-by: Tom Lane <[email protected]>
Reviewed-by: Jacob Champion <[email protected]>
Discussion: https://www.postgresql.org/message-id/d620e7c6-becc-4a8e-9b43-eea0da55faf2@eisentraut.org

2 weeks agoImprove CREATE DATABASE error message for invalid libc locale.
Jeff Davis [Fri, 6 Jun 2025 22:28:51 +0000 (15:28 -0700)]
Improve CREATE DATABASE error message for invalid libc locale.

Discussion: https://postgr.es/m/73959a14-267b-49c1-8293-291b175682cb@manitou-mail.org
Reviewed-by: Daniel Verite <[email protected]>
2 weeks agoUse NULL instead of 0 for pointer arguments.
Nathan Bossart [Fri, 6 Jun 2025 17:08:17 +0000 (12:08 -0500)]
Use NULL instead of 0 for pointer arguments.

Commit 5fe08c006c fixed this for calls to dshash_create().  This
commit fixes calls to dshash_attach() and dsa_create_in_place().

Reviewed-by: Masahiko Sawada <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
Discussion: https://postgr.es/m/aECi_gSD9JnVWQ8T%40nathan

2 weeks agoFixed signed/unsigned mismatch in test_dsm_registry.
Nathan Bossart [Fri, 6 Jun 2025 16:40:52 +0000 (11:40 -0500)]
Fixed signed/unsigned mismatch in test_dsm_registry.

Oversight in commit 8b2bcf3f28.

Reviewed-by: Masahiko Sawada <[email protected]>
Discussion: https://postgr.es/m/aECi_gSD9JnVWQ8T%40nathan
Backpatch-through: 17

2 weeks agoAvoid BufferGetLSNAtomic() calls during nbtree scans.
Peter Geoghegan [Fri, 6 Jun 2025 14:19:44 +0000 (10:19 -0400)]
Avoid BufferGetLSNAtomic() calls during nbtree scans.

Delay calling BufferGetLSNAtomic() until we finish reading a page that
actually contains items that btgettuple will return to the executor.
This reduces the number of calls during plain index scans (we'll only
call BufferGetLSNAtomic() when _bt_readpage returns true), and totally
eliminates calls during index-only scans, bitmap index scans, and plain
index scans of an unlogged relation.

Currently, when checksums (or wal_log_hints) are enabled, acquiring a
page's LSN in BufferGetLSNAtomic() involves locking the buffer header
(which involves the use of spinlocks).  Testing has shown that enabling
page-level checksums causes large regressions with certain workloads,
especially on larger multi-socket systems.

The regression isn't tied to any Postgres 18 commit.  However, Postgres
18 commit 04bec894 made initdb use checksums by default, so it seems
prudent to address the problem now.

Author: Peter Geoghegan <[email protected]>
Reviewed-By: Tomas Vondra <[email protected]>
Discussion: https://postgr.es/m/941f0190-e3c6-4622-9ac7-c04e936e5fdb@vondra.me
Discussion: https://postgr.es/m/CAH2-Wzk-Dg5XWs_jDuiHt4_7ryrSY+n=vxmHY51EVqPDFsKXmg@mail.gmail.com

2 weeks agopg_prewarm: Allow autoprewarm to use more than 1GB to dump blocks.
Robert Haas [Fri, 6 Jun 2025 12:18:27 +0000 (08:18 -0400)]
pg_prewarm: Allow autoprewarm to use more than 1GB to dump blocks.

Reported-by: Daria Shanina <[email protected]>
Author: Daria Shanina <[email protected]>
Author: Robert Haas <[email protected]>
Backpatch-through: 13

2 weeks agoDoc: improve description of which role runs a trigger.
Tom Lane [Thu, 5 Jun 2025 19:24:15 +0000 (15:24 -0400)]
Doc: improve description of which role runs a trigger.

Refine wording from commit 01463e1cc.

Author: Noah Misch <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/20250605163441[email protected]

2 weeks agonbtree: Remove useless row compare arg.
Peter Geoghegan [Thu, 5 Jun 2025 18:50:43 +0000 (14:50 -0400)]
nbtree: Remove useless row compare arg.

Use of a RowCompare key makes nbtree index scans ineligible to use
pstate.forcenonrequired following recent bugfix commit 5f4d98d4.
There's no longer any need for _bt_check_rowcompare to accept a
forcenonrequired argument, so remove it.

2 weeks agoAvoid bogus scans of partitions when marking FKs enforced
Álvaro Herrera [Thu, 5 Jun 2025 16:39:06 +0000 (18:39 +0200)]
Avoid bogus scans of partitions when marking FKs enforced

Similar to commit cc733ed164c5: when an unenforced foreign key that
references a partitioned table is altered to be enforced, we scan
the constrained table based on each partition on the referenced
partitioned table.  This is bogus and likely to cause the ALTER TABLE to
fail: we must only scan the constrained table as pointing to the
top-level partitioned table.  Oversight in commit eec0040c4bcd.  Fix by
eliding those scans.

Author: Amul Sul <[email protected]>
Reported-by: jian he <[email protected]>
Discussion: https://postgr.es/m/CACJufxF1e_gPOLtsDoaE4VCgQPC8KZW_kPAjPR5Rvv4Ew=fb2A@mail.gmail.com

2 weeks agoDoc: you must own the target object to use SECURITY LABEL.
Tom Lane [Thu, 5 Jun 2025 15:29:24 +0000 (11:29 -0400)]
Doc: you must own the target object to use SECURITY LABEL.

For some reason this wasn't mentioned before.

Author: Patrick Stählin <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/931e012a-57ba-41ba-9b88-24323a46dec5@packi.ch
Backpatch-through: 13

2 weeks agoAvoid bogus scans of partitions when validating FKs to partitioned tables
Álvaro Herrera [Thu, 5 Jun 2025 15:17:13 +0000 (17:17 +0200)]
Avoid bogus scans of partitions when validating FKs to partitioned tables

Validating an unvalidated foreign key that references a partitioned
table would try to queue validations for each individual partition of
the referenced table, but this is wrong: each individual partition would
not necessarily have all the referenced rows, so errors would be raised.
Avoid doing that.  The pg_constraint rows that cause this to happen are
only there to support the action triggers that implement the DELETE/
UPDATE actions of the FK, so no validating scan is necessary.

This was an oversight in commit b663b9436e75.

An equivalent oversight exists for NOT ENFORCED constraints, which is
not fixed in this commit.

Author: Amul Sul <[email protected]>
Reported-by: Antonin Houska <[email protected]>
Reviewed-by: jian he <[email protected]>
Reviewed-by: Tender Wang <[email protected]>
Discussion: https://postgr.es/m/26983.1748418675@localhost

2 weeks agoChange role names used in trigger test.
Tom Lane [Thu, 5 Jun 2025 15:05:53 +0000 (11:05 -0400)]
Change role names used in trigger test.

The choices made in commit 01463e1cc might pose copyright hazards,
and are more cutesy than informative anyway.

Reported-by: Noah Misch <[email protected]>
Author: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/20250415155850[email protected]

2 weeks agopsql: fix order of join clauses when listing extensions
Magnus Hagander [Thu, 5 Jun 2025 07:54:16 +0000 (09:54 +0200)]
psql: fix order of join clauses when listing extensions

Commit d696406a9b2 added a new join to the query for extensions, but did
so in the wrong place, causing the AND clause to be applied to the wrong
join.

Author: Suraj Kharage <[email protected]>
Reviewed-By: Dilip Kumar <[email protected]>
Discussion: https://postgr.es/m/CAF1DzPVBrN-cmPB2zb7ZU=2J4vEF2fNdArGCG9w+9fnKq4v8tg@mail.gmail.com

2 weeks agoFix copy-pasto with process count calculation in method_io_uring.c
Michael Paquier [Thu, 5 Jun 2025 00:39:24 +0000 (09:39 +0900)]
Fix copy-pasto with process count calculation in method_io_uring.c

This commit replaces the formula used for "TotalProcs" with a call to
pgaio_uring_procs() in pgaio_uring_shmem_init() for the shared memory
initialization, which is exactly the same, removing a duplication.

pgaio_uring_procs() is used for shared memory sizing and a sanity check,
and it has some documentation explaining some reasoning behind the
formula.

Author: Japin Li <[email protected]>
Discussion: https://postgr.es/m/ME0P300MB044521067A1EDDA9EDEC3793B66DA@ME0P300MB0445.AUSP300.PROD.OUTLOOK.COM

2 weeks agodoc: Remove notes about "unencrypted" passwords.
Nathan Bossart [Wed, 4 Jun 2025 14:47:25 +0000 (09:47 -0500)]
doc: Remove notes about "unencrypted" passwords.

The documentation for the pg_authid system catalog and the
pg_shadow system view indicates that passwords might be stored in
cleartext, but that hasn't been possible for some time.

Oversight in commit eb61136dc7.

Reviewed-by: Michael Paquier <[email protected]>
Discussion: https://postgr.es/m/aD2yKkZro4nbl5ol%40nathan
Backpatch-through: 13

2 weeks agodoc: Update description of pg_constraint.convalidated
Peter Eisentraut [Wed, 4 Jun 2025 13:27:44 +0000 (15:27 +0200)]
doc: Update description of pg_constraint.convalidated

The previous description listed the constraint types that this column
was used for, but that was outdated, since not-valid not-null
constraints are now possible.  So just remove that qualification,
rather than trying to keep it updated.

Author: jian he <[email protected]>
Reviewed-by: Robert Treat <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/CACJufxFo4yTwzbSZrP%2BzQiR6_M00skoZMFaUnNJCdY6he%3DuQfA%40mail.gmail.com

2 weeks agodoc PG 18 relnotes: Add incompatibility note about checksums now default
Peter Eisentraut [Wed, 4 Jun 2025 10:03:25 +0000 (12:03 +0200)]
doc PG 18 relnotes: Add incompatibility note about checksums now default

Reviewed-by: Tomas Vondra <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/CAKAnmmKwiMHik5AHmBEdf5vqzbOBbcwEPHo4-PioWeAbzwcTOQ%40mail.gmail.com

2 weeks agoDon't strip $libdir from LOAD command
Peter Eisentraut [Wed, 4 Jun 2025 09:21:24 +0000 (11:21 +0200)]
Don't strip $libdir from LOAD command

Commit 4f7f7b03758 implemented the extension_control_path GUC, and to
make it work it was decided that we should strip the $libdir/ on
module_pathname from .control files, so that extensions don't need to
worry about this change.

This strip logic was implemented on expand_dynamic_library_name()
which works fine when executing the SQL functions from extensions, but
this function is also called when the LOAD command is executed, and
since the user may explicitly pass the $libdir prefix on LOAD
parameter, we should not strip in this case.

This commit fixes this issue by moving the strip logic from
expand_dynamic_library_name() to load_external_function() that is
called when the running the SQL script from extensions.

Reported-by: Evan Si <[email protected]>
Author: Matheus Alcantara <[email protected]>
Reviewed-by: Nathan Bossart <[email protected]>
Reviewed-by: Rahila Syed <[email protected]>
Bug: #18920
Discussion: https://www.postgresql.org/message-id/flat/18920-b350b1c0a30af006%40postgresql.org

2 weeks agopsql: Abort connection when using \syncpipeline after COPY TO/FROM
Michael Paquier [Wed, 4 Jun 2025 00:01:29 +0000 (09:01 +0900)]
psql: Abort connection when using \syncpipeline after COPY TO/FROM

When the backend reads COPY data, it ignores all sync messages, as per
c01641f8aed0.  With psql pipelines, it is possible to manually send sync
messages with \sendpipeline which leaves the frontend in an
unrecoverable state as the backend will not send the necessary
ReadyForQuery message that is expected to feed psql result consumption
logic.

It could be possible to artificially reduce the piped_syncs and
requested_results, however libpq's state would still have queued sync
messages in its command queue, and the only way to consume those without
directly calling pqCommandQueueAdvance() is to process ReadyForQuery
messages that won't be sent since the backend ignores these.  Perhaps
this could be improved in the future, but I am not really excited about
introducing this amount of complications in libpq to manipulate the
message queues without a better use case to support it.

Hence, this patch aborts the connection if we detect excessive sync
messages after a COPY in a pipeline to avoid staying in an inconsistent
protocol state, which is the best thing we can do with pipelines in
psql for now.  Note that this change does not prevent wrapping a set
of queries inside a block made of \startpipeline and \endpipeline, only
the use of \syncpipeline for a COPY.

Reported-by: Nikita Kalinin <[email protected]>
Author: Anthonin Bonnefoy <[email protected]>
Discussion: https://postgr.es/m/18944-8a926c30f68387dd@postgresql.org

2 weeks agoFix incorrect format placeholders
Peter Eisentraut [Tue, 3 Jun 2025 19:38:04 +0000 (21:38 +0200)]
Fix incorrect format placeholders

2 weeks agoFix a pg_dump scenario for platforms where SEEK_CUR != 1.
Noah Misch [Tue, 3 Jun 2025 18:18:52 +0000 (11:18 -0700)]
Fix a pg_dump scenario for platforms where SEEK_CUR != 1.

POSIX allows such platforms.  Given the lack of complaints, we may not
currently test on such a platform.  This is new in v18 (commit
7d5c83b4e90c7156655f98b7312a30ae5eeb4d27), so no back-patch.

2 weeks agoRename log_lock_failure GUC to log_lock_failures for consistency.
Fujii Masao [Tue, 3 Jun 2025 01:02:55 +0000 (10:02 +0900)]
Rename log_lock_failure GUC to log_lock_failures for consistency.

This commit renames the GUC log_lock_failure to log_lock_failures
to align with the existing similar setting log_lock_waits, which uses
the plural form. This improves naming consistency across related GUCs.

Suggested-by: Peter Eisentraut <[email protected]>
Author: Fujii Masao <[email protected]
Reviewed-by: Peter Eisentraut <[email protected]>
Discussion: https://postgr.es/m/7a8198b6-d5b8-4910-b41e-8d3efcbb015d@eisentraut.org

2 weeks agoDisallow "=" in names of reloptions and foreign-data options.
Tom Lane [Mon, 2 Jun 2025 19:22:44 +0000 (15:22 -0400)]
Disallow "=" in names of reloptions and foreign-data options.

We store values for these options as array elements with the syntax
"name=value", hence a name containing "=" confuses matters when
it's time to read the array back in.  Since validation of the
options is often done (long) after this conversion to array format,
that leads to confusing and off-point error messages.  We can
improve matters by rejecting names containing "=" up-front.

(Probably a better design would have involved pairs of array
elements, but it's too late now --- and anyway, there's no
evident use-case for option names like this.  We already
reject such names in some other contexts such as GUCs.)

Reported-by: Chapman Flack <[email protected]>
Author: Tom Lane <[email protected]>
Reviewed-by: Chapman Flack <[email protected]>
Discussion: https://postgr.es/m/6830EB30.8090904@acm.org
Backpatch-through: 13

2 weeks agoCorrect heap vacuum boundary state setup ordering
Melanie Plageman [Mon, 2 Jun 2025 14:54:07 +0000 (10:54 -0400)]
Correct heap vacuum boundary state setup ordering

052026c9b9 mistakenly reordered setup steps in heap_vacuum_rel(),
incorrectly moving RelationGetNumberOfBlocks() before
vacuum_get_cutoffs().

OldestXmin must be determined before RelationGetNumberOfBlocks()
calculates the number of blocks in the relation that will be vacuumed.
Otherwise tuples older than OldestXmin may be inserted into the end of
the relation into blocks that are not vacuumed. If additional tuples
newer than those inserted into unscanned blocks but older than
OldestXmin are inserted into free space earlier in the relation, the
result could be advancing pg_class.relfrozenxid to a newer value than an
unfrozen XID in one of the unscanned heap pages.

Assigning an incorrect relfrozenxid can lead to data loss, so it is
imperative that it correctly reflect the oldest unfrozen xid.

Reported-by: Peter Geoghegan <[email protected]>
Author: Melanie Plageman <[email protected]>
Reviewed-by: Peter Geoghegan <[email protected]>
Discussion: https://postgr.es/m/CAH2-WzntqvVEdbbpqG5JqSZGuLWmy4PBfUO-OswfivKchr2gvw%40mail.gmail.com

2 weeks agoFix incorrect format placeholders
Peter Eisentraut [Mon, 2 Jun 2025 08:12:58 +0000 (10:12 +0200)]
Fix incorrect format placeholders

Fixes for return type of dclist_count().

2 weeks agoRename gist stratnum support function
Peter Eisentraut [Mon, 2 Jun 2025 06:33:04 +0000 (08:33 +0200)]
Rename gist stratnum support function

Commit 7406ab623fe added a gist support function that we internally
refer to by the symbol GIST_STRATNUM_PROC.  This translated from
"well-known" strategy numbers to opfamily-specific strategy numbers.
However, we later (commit 630f9a43cec) changed this to fit into
index-AM-level compare type mapping, so this function actually now
maps from compare type to opfamily-specific strategy numbers.  So this
name is no longer fitting.

Moreover, the index AM level also supports the opposite, a function to
map from strategy number to compare type.  This is currently not
supported in gist, but one might wonder what this function is supposed
to be called when it is added.

This patch changes the naming of the gist-level functionality to be
more in line with the index-AM-level functionality.  This makes sense
because these are essentially the same thing on different levels.
This also changes the names of the externally visible functions that
are provided for use as such a support function.

Reviewed-by: Paul A Jungwirth <[email protected]>
Discussion: https://www.postgresql.org/message-id/37ebb1d9-9036-485f-a215-e55435689917%40eisentraut.org

2 weeks agoUse replay LSN as target for cascading logical WAL senders
Michael Paquier [Mon, 2 Jun 2025 03:03:59 +0000 (12:03 +0900)]
Use replay LSN as target for cascading logical WAL senders

A cascading WAL sender doing logical decoding (as known as doing its
work on a standby) has been using as flush LSN the value returned by
GetStandbyFlushRecPtr() (last position safely flushed to disk).  This is
incorrect as such processes are only able to decode changes up to the
LSN that has been replayed by the startup process.

This commit changes cascading logical WAL senders to use the replay LSN,
as returned by GetXLogReplayRecPtr().  This distinction is important
particularly during shutdown, when WAL senders need to send any
remaining available data to their clients, switching WAL senders to a
caught-up state.  Using the latest flush LSN rather than the replay LSN
could cause the WAL senders to be stuck in an infinite loop preventing
them to shut down, as the startup process does not run when WAL senders
attempt to catch up, so they could keep waiting for work that would
never happen.

Backpatch down to v16, where logical decoding on standbys has been
introduced.

Author: Alexey Makhmutov <[email protected]>
Reviewed-by: Ajin Cherian <[email protected]>
Reviewed-by: Bertrand Drouvot <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
Discussion: https://postgr.es/m/52138028-7246-421c-9161-4fa108b88070@postgrespro.ru
Backpatch-through: 16

2 weeks agoAdd commit 4672b6223 to .git-blame-ignore-revs.
Tom Lane [Sun, 1 Jun 2025 18:58:42 +0000 (14:58 -0400)]
Add commit 4672b6223 to .git-blame-ignore-revs.

2 weeks agoRun pgindent on the previous commit.
Tom Lane [Sun, 1 Jun 2025 18:55:24 +0000 (14:55 -0400)]
Run pgindent on the previous commit.

Clean up after rearranging PG_TRY blocks.

Author: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/2954090.1748723636@sss.pgh.pa.us
Backpatch-through: 13

2 weeks agoFix edge-case resource leaks in PL/Python error reporting.
Tom Lane [Sun, 1 Jun 2025 18:48:35 +0000 (14:48 -0400)]
Fix edge-case resource leaks in PL/Python error reporting.

PLy_elog_impl and its subroutine PLy_traceback intended to avoid
leaking any PyObject reference counts, but their coverage of the
matter was sadly incomplete.  In particular, out-of-memory errors
in most of the string-construction subroutines could lead to
reference count leaks, because those calls were outside the
PG_TRY blocks responsible for dropping reference counts.

Fix by (a) adjusting the scopes of the PG_TRY blocks, and
(b) moving the responsibility for releasing the reference counts
of the traceback-stack objects to PLy_elog_impl.  This requires
some additional "volatile" markers, but not too many.

In passing, fix an ancient thinko: use of the "e_module_o" PyObject
was guarded by "if (e_type_s)", where surely "if (e_module_o)"
was meant.  This would only have visible consequences if the
"__name__" attribute were present but the "__module__" attribute
wasn't, which apparently never happens; but someday it might.

Rearranging the PG_TRY blocks requires indenting a fair amount
of code one more tab stop, which I'll do separately for clarity.

Author: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/2954090.1748723636@sss.pgh.pa.us
Backpatch-through: 13