pgsql: Skip WAL recycling and preallocation during archive recovery.

2025-04-05 Thread Michael Paquier
Skip WAL recycling and preallocation during archive recovery. The previous commit addressed the chief consequences of a race condition between InstallXLogFileSegment() and KeepFileRestoredFromArchive(). Fix three lesser consequences. A spurious durable_rename_excl() LOG message remained possible

pgsql: Reset InstallXLogFileSegmentActive after walreceiver self-initia

2025-04-05 Thread Michael Paquier
Reset InstallXLogFileSegmentActive after walreceiver self-initiated exit. After commit cc2c7d65fc27e877c9f407587b0b92d46cd6dd16 added this flag, failure to reset it caused assertion failures. In non-assert builds, it made the system fail to achieve the objectives listed in that commit; chiefly, w

pgsql: Reset InstallXLogFileSegmentActive after walreceiver self-initia

2025-04-05 Thread Michael Paquier
Reset InstallXLogFileSegmentActive after walreceiver self-initiated exit. After commit cc2c7d65fc27e877c9f407587b0b92d46cd6dd16 added this flag, failure to reset it caused assertion failures. In non-assert builds, it made the system fail to achieve the objectives listed in that commit; chiefly, w

pgsql: Skip WAL recycling and preallocation during archive recovery.

2025-04-05 Thread Michael Paquier
Skip WAL recycling and preallocation during archive recovery. The previous commit addressed the chief consequences of a race condition between InstallXLogFileSegment() and KeepFileRestoredFromArchive(). Fix three lesser consequences. A spurious durable_rename_excl() LOG message remained possible

pgsql: Don't ERROR on PreallocXlogFiles() race condition.

2025-04-05 Thread Michael Paquier
Don't ERROR on PreallocXlogFiles() race condition. Before a restartpoint finishes PreallocXlogFiles(), a startup process KeepFileRestoredFromArchive() call can unlink the preallocated segment. If a CHECKPOINT sql command had elicited the restartpoint experiencing the race condition, that sql comma

pgsql: Don't ERROR on PreallocXlogFiles() race condition.

2025-04-05 Thread Michael Paquier
Don't ERROR on PreallocXlogFiles() race condition. Before a restartpoint finishes PreallocXlogFiles(), a startup process KeepFileRestoredFromArchive() call can unlink the preallocated segment. If a CHECKPOINT sql command had elicited the restartpoint experiencing the race condition, that sql comma

pgsql: Revert "Add HINT for restartpoint race with KeepFileRestoredFrom

2025-04-05 Thread Michael Paquier
Revert "Add HINT for restartpoint race with KeepFileRestoredFromArchive()." This reverts commit 8ad6c5dbbe5a, which was a commit specific to v14 and older branches as the race condition between restartpoints and KeepFileRestoredFromArchive() still existed. 1f95181b44c8 has worsened the situation

pgsql: Revert "Add HINT for restartpoint race with KeepFileRestoredFrom

2025-04-05 Thread Michael Paquier
Revert "Add HINT for restartpoint race with KeepFileRestoredFromArchive()." This reverts commit 8ad6c5dbbe5a, which was a commit specific to v14 and older branches as the race condition between restartpoints and KeepFileRestoredFromArchive() still existed. 1f95181b44c8 has worsened the situation

pgsql: Remove XLogFileInit() ability to unlink a pre-existing file.

2025-04-05 Thread Michael Paquier
Remove XLogFileInit() ability to unlink a pre-existing file. Only initdb used it. initdb refuses to operate on a non-empty directory and generally does not cope with pre-existing files of other kinds. Hence, use the opportunity to simplify. This commit has been applied as of 421484f79c0b in v15

pgsql: Remove XLogFileInit() ability to unlink a pre-existing file.

2025-04-05 Thread Michael Paquier
Remove XLogFileInit() ability to unlink a pre-existing file. Only initdb used it. initdb refuses to operate on a non-empty directory and generally does not cope with pre-existing files of other kinds. Hence, use the opportunity to simplify. This commit has been applied as of 421484f79c0b in v15

pgsql: In XLogFileInit(), fix *use_existent postcondition to suit calle

2025-04-05 Thread Michael Paquier
In XLogFileInit(), fix *use_existent postcondition to suit callers. Infrequently, the mismatch caused log_checkpoints messages and TRACE_POSTGRESQL_CHECKPOINT_DONE() to witness an "added" count too high by one. Since that consequence is so minor, no back-patch. This commit has been applied as of

pgsql: In XLogFileInit(), fix *use_existent postcondition to suit calle

2025-04-05 Thread Michael Paquier
In XLogFileInit(), fix *use_existent postcondition to suit callers. Infrequently, the mismatch caused log_checkpoints messages and TRACE_POSTGRESQL_CHECKPOINT_DONE() to witness an "added" count too high by one. Since that consequence is so minor, no back-patch. This commit has been applied as of

pgsql: Remove XLogFileInit() ability to skip ControlFileLock.

2025-04-05 Thread Michael Paquier
Remove XLogFileInit() ability to skip ControlFileLock. Cold paths, initdb and end-of-recovery, used it. Don't optimize them. This commit has been applied as of c53c6b98d38a in v15 and newer versions. This is required on stable branches of v13 and v14 to fix a regression reported by Noah Misch,

pgsql: Remove XLogFileInit() ability to skip ControlFileLock.

2025-04-05 Thread Michael Paquier
Remove XLogFileInit() ability to skip ControlFileLock. Cold paths, initdb and end-of-recovery, used it. Don't optimize them. This commit has been applied as of c53c6b98d38a in v15 and newer versions. This is required on stable branches of v13 and v14 to fix a regression reported by Noah Misch,

pgsql: Quote filename in error message

2025-04-05 Thread Daniel Gustafsson
Quote filename in error message Project standard is to quote filenames in error and log messages, which commit 2da74d8d640 missed in two error messages. Author: Kyotaro Horiguchi Reported-by: Kyotaro Horiguchi Reviewed-by: Daniel Gustafsson Discussion: https://postgr.es/m/20250404.120328.1035

pgsql: Fix parse_cte.c's failure to examine sub-WITHs in DML statements

2025-04-05 Thread Tom Lane
Fix parse_cte.c's failure to examine sub-WITHs in DML statements. makeDependencyGraphWalker thought that only SelectStmt nodes could contain a WithClause. Which was true in our original implementation of WITH, but astonishingly we missed updating this code when we added the ability to attach WITH

pgsql: Fix parse_cte.c's failure to examine sub-WITHs in DML statements

2025-04-05 Thread Tom Lane
Fix parse_cte.c's failure to examine sub-WITHs in DML statements. makeDependencyGraphWalker thought that only SelectStmt nodes could contain a WithClause. Which was true in our original implementation of WITH, but astonishingly we missed updating this code when we added the ability to attach WITH

pgsql: Fix parse_cte.c's failure to examine sub-WITHs in DML statements

2025-04-05 Thread Tom Lane
Fix parse_cte.c's failure to examine sub-WITHs in DML statements. makeDependencyGraphWalker thought that only SelectStmt nodes could contain a WithClause. Which was true in our original implementation of WITH, but astonishingly we missed updating this code when we added the ability to attach WITH

pgsql: Fix parse_cte.c's failure to examine sub-WITHs in DML statements

2025-04-05 Thread Tom Lane
Fix parse_cte.c's failure to examine sub-WITHs in DML statements. makeDependencyGraphWalker thought that only SelectStmt nodes could contain a WithClause. Which was true in our original implementation of WITH, but astonishingly we missed updating this code when we added the ability to attach WITH

pgsql: Fix parse_cte.c's failure to examine sub-WITHs in DML statements

2025-04-05 Thread Tom Lane
Fix parse_cte.c's failure to examine sub-WITHs in DML statements. makeDependencyGraphWalker thought that only SelectStmt nodes could contain a WithClause. Which was true in our original implementation of WITH, but astonishingly we missed updating this code when we added the ability to attach WITH

pgsql: Fix parse_cte.c's failure to examine sub-WITHs in DML statements

2025-04-05 Thread Tom Lane
Fix parse_cte.c's failure to examine sub-WITHs in DML statements. makeDependencyGraphWalker thought that only SelectStmt nodes could contain a WithClause. Which was true in our original implementation of WITH, but astonishingly we missed updating this code when we added the ability to attach WITH

pgsql: pg_basebackup: Add missing PQclear in error path

2025-04-05 Thread Daniel Gustafsson
pg_basebackup: Add missing PQclear in error path This adds a missing PQclear in the error path of StreamLogicalLog, a fix in the same vein as e889422d98e with an equivalent low impact. Author: Steven Niu Reviewed-by: Daniel Gustafsson Discussion: https://postgr.es/m/c4b1c627-a3e4-4347-a670-1e28

pgsql: docs: Reframe track_io_timing related docs as wait time

2025-04-05 Thread Andres Freund
docs: Reframe track_io_timing related docs as wait time With AIO it does not make sense anymore to track the time for each individual IO, as multiple IOs can be in-flight at the same time. Instead we now track the time spent *waiting* for IOs. This should be reflected in the docs. While, so far,

pgsql: Fix planner's failure to identify multiple hashable ScalarArrayO

2025-04-05 Thread David Rowley
Fix planner's failure to identify multiple hashable ScalarArrayOpExprs 50e17ad28 (v14) and 29f45e299 (v15) made it so the planner could identify IN and NOT IN clauses which have Const lists as right-hand arguments and when an appropriate hash function is available for the data types, mark the Scal

pgsql: Create accessor functions for TupleHashEntry.

2025-04-05 Thread Jeff Davis
Create accessor functions for TupleHashEntry. Refactor for upcoming optimizations. Reviewed-by: David Rowley Discussion: https://postgr.es/m/1cc3b400a0e8eead18ff967436fa9e42c0c14cfb.ca...@j-davis.com Branch -- master Details --- https://git.postgresql.org/pg/commitdiff/4d143509cbfae02

pgsql: pg_overexplain: Additional EXPLAIN options for debugging.

2025-04-05 Thread Robert Haas
pg_overexplain: Additional EXPLAIN options for debugging. There's a fair amount of information in the Plan and PlanState trees that isn't printed by any existing EXPLAIN option. This means that, when working on the planner, it's often necessary to rely on facilities such as debug_print_plan, which

pgsql: postgres_fdw: Remove redundant check in semijoin_target_ok()

2025-04-05 Thread Alexander Korotkov
postgres_fdw: Remove redundant check in semijoin_target_ok() If a var belongs to the innerrel of the joinrel, it's not possible that it belongs to the outerrel. This commit removes the redundant check from the if-clause but keeps it as an assertion. Discussion: https://postgr.es/m/flat/CAHewXN=

pgsql: Remove duplicated comment in get_relation_constraints

2025-04-05 Thread Richard Guo
Remove duplicated comment in get_relation_constraints The check for non-inheritable constraints is performed later, and the same comment is included at that point. While we're here, remove one extraneous blank line. Author: jian he Reviewed-by: Kirill Reshke Reviewed-by: Richard Guo Discussio

pgsql: Avoid mixing designated and non-designated field initializers.

2025-04-05 Thread Tom Lane
Avoid mixing designated and non-designated field initializers. As revised by commit 9324c8c58, PG_MODULE_MAGIC constructed a struct initializer containing both designated fields and a non-designated "0". That's okay in C, but not in C++, with the result that extensions written in C++ failed to co

Re: pgsql: Add vacuum_truncate configuration parameter.

2025-04-05 Thread David Rowley
On Fri, 21 Mar 2025 at 04:30, Tom Lane wrote: > > Nathan Bossart writes: > > Since there's presently no way to determine whether a Boolean > > storage parameter is explicitly set or has just picked up the > > default value, this commit also introduces an isset_offset member > > to relopt_parse_el

pgsql: Get rid of WALBufMappingLock

2025-04-05 Thread Alexander Korotkov
Get rid of WALBufMappingLock Allow multiple backends to initialize WAL buffers concurrently. This way `MemSet((char *) NewPage, 0, XLOG_BLCKSZ);` can run in parallel without taking a single LWLock in exclusive mode. The new algorithm works as follows: * reserve a page for initialization using X

pgsql: Fix rare assertion failure in standby, if primary is restarted

2025-04-05 Thread Heikki Linnakangas
Fix rare assertion failure in standby, if primary is restarted During hot standby, ExpireAllKnownAssignedTransactionIds() and ExpireOldKnownAssignedTransactionIds() functions mark old transactions as no-longer running, but they failed to update xactCompletionCount and latestCompletedXid. AFAICS it

pgsql: Doc: add information about partition locking

2025-04-05 Thread David Rowley
Doc: add information about partition locking The documentation around locking of partitions for the executor startup phase of run-time partition pruning wasn't clear about which partitions were being locked. Fix that. Reviewed-by: Tender Wang Discussion: https://postgr.es/m/CAApHDvp738G75HfkKc

pgsql: Improve error message when standby does accept connections.

2025-04-05 Thread Fujii Masao
Improve error message when standby does accept connections. Even after reaching the minimum recovery point, if there are long-lived write transactions with 64 subtransactions on the primary, the recovery snapshot may not yet be ready for hot standby, delaying read-only connections on the standby.

pgsql: Use streaming read I/O in btree vacuuming

2025-04-05 Thread Melanie Plageman
Use streaming read I/O in btree vacuuming Btree vacuum processes all index pages in physical order. Now it uses the read stream API to get the next buffer instead of explicitly invoking ReadBuffer(). It is possible for concurrent insertions to cause page splits during index vacuuming. This can le

pgsql: Inline CRC computation for small fixed-length input on x86

2025-04-05 Thread John Naylor
Inline CRC computation for small fixed-length input on x86 pg_crc32c.h now has a simplified copy of the loop in pg_crc32c_sse42.c suitable for inlining where possible. This may slightly reduce contention for the WAL insertion lock, but that hasn't been tested. The motivation for this change is av

pgsql: meson: Flush stdout in testwrap

2025-04-05 Thread Andres Freund
meson: Flush stdout in testwrap Otherwise the progress won't reliably be displayed during a test. Reviewed-by: Noah Misch Discussion: https://postgr.es/m/kx6xu7suexal5vwsxpy7ybgkcznx6hgywbuhkr6qabcwxjqax2@i4pcpk75jvaa Backpatch-through: 16 Branch -- REL_17_STABLE Details --- https://g

pgsql: refactor: Pass relation OID instead of Relation to createForeign

2025-04-05 Thread Peter Eisentraut
refactor: Pass relation OID instead of Relation to createForeignKeyCheckTriggers() Currently, createForeignKeyCheckTriggers() takes a Relation type as its first argument, but it doesn't use that argument directly. Instead, it fetches the relation OID by calling RelationGetRelid(). Therefore, it w

pgsql: Show plperl version in the meson setup summary.

2025-04-05 Thread Andrew Dunstan
Show plperl version in the meson setup summary. Also, use perl 'version' instead of 'api_versionstring' to sync with the configure script. Author: Roman Zharkov Discussion: https://postgr.es/m/93e7f77bf4e1ef4640e4ee733f9e2...@postgrespro.ru Branch -- master Details --- https://git.pos

pgsql: Fix rare assertion failure in standby, if primary is restarted

2025-04-05 Thread Heikki Linnakangas
Fix rare assertion failure in standby, if primary is restarted During hot standby, ExpireAllKnownAssignedTransactionIds() and ExpireOldKnownAssignedTransactionIds() functions mark old transactions as no-longer running, but they failed to update xactCompletionCount and latestCompletedXid. AFAICS it

pgsql: Fix rare assertion failure in standby, if primary is restarted

2025-04-05 Thread Heikki Linnakangas
Fix rare assertion failure in standby, if primary is restarted During hot standby, ExpireAllKnownAssignedTransactionIds() and ExpireOldKnownAssignedTransactionIds() functions mark old transactions as no-longer running, but they failed to update xactCompletionCount and latestCompletedXid. AFAICS it

pgsql: Add modern SHA-2 based password hashes to pgcrypto.

2025-04-05 Thread Álvaro Herrera
Add modern SHA-2 based password hashes to pgcrypto. This adapts the publicly available reference implementation on https://www.akkadia.org/drepper/SHA-crypt.txt and adds the new hash algorithms sha256crypt and sha512crypt to crypt() and gen_salt() respectively. Author: Bernd Helmle Reviewed-by:

pgsql: aio: Add errcontext for processing I/Os for another backend

2025-04-05 Thread Melanie Plageman
aio: Add errcontext for processing I/Os for another backend Push an ErrorContextCallback adding additional detail about the process performing the I/O and the owner of the I/O when those are not the same. For io_method worker, this adds context specifying which process owns the I/O that the I/O w

pgsql: Update Unicode data to CLDR 47

2025-04-05 Thread Peter Eisentraut
Update Unicode data to CLDR 47 No actual changes result. Branch -- master Details --- https://git.postgresql.org/pg/commitdiff/84fea854c990a59d00d2fec15f81a96565d4bce4 Modified Files -- src/Makefile.global.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)

pgsql: Be more paranoid in configure's checks for CRC and POPCNT intrin

2025-04-05 Thread Tom Lane
Be more paranoid in configure's checks for CRC and POPCNT intrinsics. In these tests, we need to verify not only that the compiler has heard of these intrinsics, but that lower-level tools cope with them too. (For example, the assembler must also know the instructions, and on some platforms there

pgsql: docs: Update phrase on message lengths in the protocol

2025-04-05 Thread Heikki Linnakangas
docs: Update phrase on message lengths in the protocol The reasoning for why all the message formats are parseable without the explicit message length field is anachronistic; the real reason is that protocol version 2 did not have a message length field. There's nothing wrong with relying on the m

Re: pgsql: Improve accounting for memory used by shared hash tables

2025-04-05 Thread Tomas Vondra
On 4/4/25 01:43, Tomas Vondra wrote: > On 4/4/25 00:57, David Rowley wrote: >> On Thu, 3 Apr 2025 at 04:16, Tomas Vondra >> wrote: >>> Improve accounting for memory used by shared hash tables >> >> I've not looked into why, but this is causing an issue in the >> join_rel_hash during add_join_rel(

pgsql: Need to do CommandCounterIncrement after StoreAttrMissingVal.

2025-04-05 Thread Tom Lane
Need to do CommandCounterIncrement after StoreAttrMissingVal. Without this, an additional change to the same pg_attribute row within the same command will fail. This is possible at least with ALTER TABLE ADD COLUMN on a multiple-inheritance-pathway structure. (Another potential hazard is that imm

pgsql: Add missing declarations to pg_config.h.in

2025-04-05 Thread Daniel Gustafsson
Add missing declarations to pg_config.h.in Add missing pg_config.h.in declarations from 09be39112654 where the corresponding autoconf/meson declarations were added. Reviewed-by: Heikki Linnakangas Discussion: https://postgr.es/m/70145721-6949-4abf-bb54-63f866488...@yesql.se Branch -- master

Re: pgsql: aio: Add core asynchronous I/O infrastructure

2025-04-05 Thread Andres Freund
Hi, On 2025-03-18 11:03:36 -0400, Tom Lane wrote: > Andres Freund writes: > > aio: Add core asynchronous I/O infrastructure > > Some of the buildfarm is mildly unhappy with this. > So far I see > > ayu | 2025-03-18 13:08:04 | aio_callback.c:83:12: warning: > comparison of constant 1

pgsql: Remove HeapBitmapScan's skip_fetch optimization

2025-04-05 Thread Andres Freund
Remove HeapBitmapScan's skip_fetch optimization The optimization does not take the removal of TIDs by a concurrent vacuum into account. The concurrent vacuum can remove dead TIDs and make pages ALL_VISIBLE while those dead TIDs are referenced in the bitmap. This can lead to a skip_fetch scan retur

Re: pgsql: aio: Add core asynchronous I/O infrastructure

2025-04-05 Thread Aleksander Alekseev
Hi Andres, > aio: Add core asynchronous I/O infrastructure > > [...] I noticed that aio.c references README.md: ``` * aio.c *AIO - Core Logic * * For documentation about how AIO works on a higher level, including a * schematic example, see README.md. ``` However the file seems to be mi

pgsql: doc: Adjust some notes about pg_upgrade's file transfer modes.

2025-04-05 Thread Nathan Bossart
doc: Adjust some notes about pg_upgrade's file transfer modes. --copy-file-range and --swap were not mentioned in a few places that discuss the available file transfer modes. This entire page would likely benefit from an overhaul, but that's v19 material at this point. Oversights in commits d936

pgsql: Avoid double transformation of json_array()'s subquery.

2025-04-05 Thread Tom Lane
Avoid double transformation of json_array()'s subquery. transformJsonArrayQueryConstructor() applied transformStmt() to the same subquery tree twice. While this causes no issue in many cases, there are some where it causes a coredump, thanks to the parser's habit of scribbling on its input. Fix

pgsql: Avoid double transformation of json_array()'s subquery.

2025-04-05 Thread Tom Lane
Avoid double transformation of json_array()'s subquery. transformJsonArrayQueryConstructor() applied transformStmt() to the same subquery tree twice. While this causes no issue in many cases, there are some where it causes a coredump, thanks to the parser's habit of scribbling on its input. Fix

pgsql: Avoid double transformation of json_array()'s subquery.

2025-04-05 Thread Tom Lane
Avoid double transformation of json_array()'s subquery. transformJsonArrayQueryConstructor() applied transformStmt() to the same subquery tree twice. While this causes no issue in many cases, there are some where it causes a coredump, thanks to the parser's habit of scribbling on its input. Fix

Re: pgsql: Prevent redeclaration of typedef TocEntry.

2025-04-05 Thread Nathan Bossart
Sorry, I missed this one last night. On Sat, Apr 05, 2025 at 02:10:10AM -0400, Tom Lane wrote: > =?utf-8?Q?=C3=81lvaro?= Herrera writes: >> ... AFAICS we could move both DefnDumperPtr and >> DataDumperPtr typedefs to pg_backup_archiver.h, together with struct >> _tocEntry (the only place where th

pgsql: Clean up from commit 1495eff7bdb

2025-04-05 Thread Andrew Dunstan
Clean up from commit 1495eff7bdb Fix some comments, and remove the hacky way of quoting database names in favor of appendStringLiteralConn. Branch -- master Details --- https://git.postgresql.org/pg/commitdiff/5db3bf7391d77ae86bc9b5f580141e022803b744 Modified Files -- src/bi

pgsql: Set log_statement=none in t/002_pg_upgrade.pl

2025-04-05 Thread Álvaro Herrera
Set log_statement=none in t/002_pg_upgrade.pl This should make the test a wee bit faster on high-load machines (e.g., when running under valgrind). Per complaint from Andres Freund. Discussion: https://postgr.es/m/cwbcyjp2ts7o7xgy5y5gwtcd4zltvncsj67el7xgci7xbwrhlu@k363vk5tce4g Branch -- ma

pgsql: pg_dump: Tiny header cleanup

2025-04-05 Thread Álvaro Herrera
pg_dump: Tiny header cleanup In commits 9c02e3a986da and 8ec0aaeae094, Nathan added a duplicate TocEntry typedef forward declaration (plus assorted #ifdef hackery to avoid C99 preprocessor issues) to deal with some very old untidyness regarding DefnDumperPtr function prototype being located in pg_

Re: pgsql: pg_upgrade: Fix inconsistency in memory freeing

2025-04-05 Thread Michael Paquier
On Sun, Mar 30, 2025 at 11:12:20AM -0700, Jeff Davis wrote: > Why pg_strdup() the "NULL" at all in that case? Usually I see that done > so that there doesn't need to be a conditional when freeing, but here > there's a conditional anyway. > > Perhaps something like the attached? I am back to a lap