pgsql: Remove state.tmp when failing to save a replication slot

2025-10-18 Thread Michael Paquier
Remove state.tmp when failing to save a replication slot An error happening while a slot data is saved on disk in SaveSlotToPath() could cause a state.tmp file (temporary file holding the slot state data, renamed to its permanent name at the end of the function) to remain around after it has been

pgsql: Expose sequence page LSN via pg_get_sequence_data.

2025-10-18 Thread Amit Kapila
Expose sequence page LSN via pg_get_sequence_data. This patch enhances the pg_get_sequence_data function to include the page-level LSN (Log Sequence Number) of the sequence. This additional metadata will be used by upcoming patches to support synchronization of sequences during logical replication

pgsql: Fix Coverity issue reported in commit 2273fa32bce.

2025-10-18 Thread Tatsuo Ishii
Fix Coverity issue reported in commit 2273fa32bce. Coverity complains that the return value from gettuple_eval_partition (stored in variable "datum") in a do..while loop in WinGetFuncArgInPartition is overwritten when exiting the while loop. This commit tries to fix the issue by changing the gettu

pgsql: Fix two typos in xlogstats.h and xlogstats.c

2025-10-18 Thread Michael Paquier
Fix two typos in xlogstats.h and xlogstats.c Issue found while browsing this area of the code, introduced and copy-pasted around by 2258e76f90bf. Backpatch-through: 15 Branch -- REL_17_STABLE Details --- https://git.postgresql.org/pg/commitdiff/ede2f6b893219296d953177de11df4f43a593e81

pgsql: Avoid warnings in tests when openssl binary isn't available

2025-10-18 Thread Daniel Gustafsson
Avoid warnings in tests when openssl binary isn't available The SSL tests for pg_stat_ssl tries to exactly match the serial from the certificate by extracting it with the openssl binary. If that fails due to the binary not being available, a fallback match is used, but the attempt to execute a mis

pgsql: pgstattuple: Improve reports generated for indexes (hash, gist,

2025-10-18 Thread Michael Paquier
pgstattuple: Improve reports generated for indexes (hash, gist, btree) pgstattuple checks the state of the pages retrieved for gist and hash using some check functions from each index AM, respectively gistcheckpage() and _hash_checkpage(). When these are called, they would fail when bumping on da

pgsql: Cleanup VACUUM option processing error messages

2025-10-18 Thread David Rowley
Cleanup VACUUM option processing error messages The processing of the PARALLEL option for VACUUM was not quite following what the DefElem code had intended. defGetInt32() already has code to handle missing parameters and returns a perfectly good error message for when that happens. Here we get r

pgsql: Fix lookups in pg_{clear,restore}_{attribute,relation}_stats().

2025-10-18 Thread Nathan Bossart
Fix lookups in pg_{clear,restore}_{attribute,relation}_stats(). Presently, these functions look up the relation's OID, lock it, and then check privileges. Not only does this approach provide no guarantee that the locked relation matches the arguments of the lookup, but it also allows users to bri

pgsql: Remove overzealous _bt_killitems assertion.

2025-10-18 Thread Peter Geoghegan
Remove overzealous _bt_killitems assertion. An assertion in _bt_killitems expected the scan's currPos state to contain a valid LSN, saved from when currPos's page was initially read. The assertion failed to account for the fact that even logged relations can have leaf pages with an invalid LSN whe

pgsql: dblink: Avoid locking relation before privilege check.

2025-10-18 Thread Nathan Bossart
dblink: Avoid locking relation before privilege check. The present coding of dblink's get_rel_from_relname() predates the introduction of RangeVarGetRelidExtended(), which provides a way to check permissions before locking the relation. This commit adjusts get_rel_from_relname() to use that funct

pgsql: Allow private state in certain planner data structures.

2025-10-18 Thread Robert Haas
Allow private state in certain planner data structures. Extension that make extensive use of planner hooks may want to coordinate their efforts, for example to avoid duplicate computation, but that's currently difficult because there's no really good way to pass data between different hooks. To m

pgsql: Add pg_database_locale() to retrieve database default locale.

2025-10-18 Thread Jeff Davis
Add pg_database_locale() to retrieve database default locale. Reviewed-by: Peter Eisentraut Discussion: https://postgr.es/m/[email protected] Branch -- master Details --- https://git.postgresql.org/pg/commitdiff/e533524b23b8dd504d38c09c9f84b3828

pgsql: Add pg_iswxdigit(), useful for tsearch.

2025-10-18 Thread Jeff Davis
Add pg_iswxdigit(), useful for tsearch. Reviewed-by: Peter Eisentraut Discussion: https://postgr.es/m/[email protected] Branch -- master Details --- https://git.postgresql.org/pg/commitdiff/67a8b49e96caf0782b556521c8d6650e78f2d88e Modified File

pgsql: Doc: clarify n_distinct_inherited setting

2025-10-18 Thread David Rowley
Doc: clarify n_distinct_inherited setting There was some confusion around how to adjust the n_distinct estimates for partitioned tables. Here we try and clarify that n_distinct_inherited needs to be adjusted rather than n_distinct. Also fix some slightly misleading text which was talking about t

pgsql: Avoid warnings in tests when openssl binary isn't available

2025-10-18 Thread Daniel Gustafsson
Avoid warnings in tests when openssl binary isn't available The SSL tests for pg_stat_ssl tries to exactly match the serial from the certificate by extracting it with the openssl binary. If that fails due to the binary not being available, a fallback match is used, but the attempt to execute a mis

pgsql: Use SOCK_ERRNO[_SET] in fe-secure-gssapi.c.

2025-10-18 Thread Tom Lane
Use SOCK_ERRNO[_SET] in fe-secure-gssapi.c. On Windows, this code did not handle error conditions correctly at all, since it looked at "errno" which is not used for socket-related errors on that platform. This resulted, for example, in failure to connect to a PostgreSQL server with GSSAPI enabled

pgsql: Allow role created by new test to log in on Windows.

2025-10-18 Thread Tom Lane
Allow role created by new test to log in on Windows. We must tell init about each role name we plan to connect as, else SSPI auth fails. Similar to previous patches such as 14793f471, 973542866. Oversight in 208927e65, per buildfarm member drongo. (Although that was back-patched to v13, the test

pgsql: Allow role created by new test to log in on Windows.

2025-10-18 Thread Tom Lane
Allow role created by new test to log in on Windows. We must tell init about each role name we plan to connect as, else SSPI auth fails. Similar to previous patches such as 14793f471, 973542866. Oversight in 208927e65, per buildfarm member drongo. (Although that was back-patched to v13, the test

pgsql: Allow role created by new test to log in on Windows.

2025-10-18 Thread Tom Lane
Allow role created by new test to log in on Windows. We must tell init about each role name we plan to connect as, else SSPI auth fails. Similar to previous patches such as 14793f471, 973542866. Oversight in 208927e65, per buildfarm member drongo. (Although that was back-patched to v13, the test

pgsql: Allow role created by new test to log in on Windows.

2025-10-18 Thread Tom Lane
Allow role created by new test to log in on Windows. We must tell init about each role name we plan to connect as, else SSPI auth fails. Similar to previous patches such as 14793f471, 973542866. Oversight in 208927e65, per buildfarm member drongo. (Although that was back-patched to v13, the test

pgsql: Add extension_state member to PlannedStmt.

2025-10-18 Thread Robert Haas
Add extension_state member to PlannedStmt. Extensions can stash data computed at plan time into this list using planner_shutdown_hook (or perhaps other mechanisms) and then access it from any code that has access to the PlannedStmt (such as explain hooks), allowing for extensible debugging and ins

pgsql: Improve planner's width estimates for set operations

2025-10-18 Thread David Rowley
Improve planner's width estimates for set operations For UNION, EXCEPT and INTERSECT, we were not very good at estimating the PathTarget.width for the set operation. Since the targetlist of the set operation is made up of Vars with varno==0, this would result in get_expr_width() applying a defaul

pgsql: Implement Eager Aggregation

2025-10-18 Thread Richard Guo
Implement Eager Aggregation Eager aggregation is a query optimization technique that partially pushes aggregation past a join, and finalizes it once all the relations are joined. Eager aggregation may reduce the number of input rows to the join and thus could result in a better overall plan. In

pgsql: pgbench: Fix error reporting in readCommandResponse().

2025-10-18 Thread Fujii Masao
pgbench: Fix error reporting in readCommandResponse(). pgbench uses readCommandResponse() to process server responses. When readCommandResponse() encounters an error during a call to PQgetResult() to fetch the current result, it attempts to report it with an additional error message from PQerrorMe

pgsql: ecpg: check return value of replace_variables()

2025-10-18 Thread Daniel Gustafsson
ecpg: check return value of replace_variables() The function returns false if it fails to allocate memory, so make sure to check the return value in callsites. Author: Aleksander Alekseev Reviewed-by: Daniel Gustafsson Discussion: https://postgr.es/m/caj7c6tnpru8zxgdfn3pygy1tzo0bgszx+kkqw0z7zt

pgsql: Fix EvalPlanQual handling of foreign/custom joins in ExecScanFet

2025-10-18 Thread Etsuro Fujita
Fix EvalPlanQual handling of foreign/custom joins in ExecScanFetch. If inside an EPQ recheck, ExecScanFetch would run the recheck method function for foreign/custom joins even if they aren't descendant nodes in the EPQ recheck plan tree, which is problematic at least in the foreign-join case, beca

pgsql: Fix update-po for the PGXS case

2025-10-18 Thread Álvaro Herrera
Fix update-po for the PGXS case The original formulation failed to take into account the fact that for the PGXS case, the source dir is not $(top_srcdir), so it ended up not doing anything. Handle it explicitly. Author: Ryo Matsumura Reviewed-by: Bryan Green Backpatch-through: 13 Discussion:

pgsql: Tidyup truncate_useless_pathkeys() function

2025-10-18 Thread David Rowley
Tidyup truncate_useless_pathkeys() function This removes a few static functions and replaces them with 2 functions which aim to be more reusable. The upper planner's pathkey requirements can be simplified down to operations which require pathkeys in the same order as the pathkeys for the given op

pgsql: Fix EvalPlanQual handling of foreign/custom joins in ExecScanFet

2025-10-18 Thread Etsuro Fujita
Fix EvalPlanQual handling of foreign/custom joins in ExecScanFetch. If inside an EPQ recheck, ExecScanFetch would run the recheck method function for foreign/custom joins even if they aren't descendant nodes in the EPQ recheck plan tree, which is problematic at least in the foreign-join case, beca

pgsql: Fix issue with reading zero bytes in Gzip_read.

2025-10-18 Thread Tom Lane
Fix issue with reading zero bytes in Gzip_read. pg_dump expects a read request of zero bytes to be a no-op; see for example ReadStr(). Gzip_read got this wrong and falsely supposed that the resulting gzret == 0 indicated an error. We could complicate that error-checking logic some more, but it s

pgsql: Don't include execnodes.h in replication/conflict.h

2025-10-18 Thread Álvaro Herrera
Don't include execnodes.h in replication/conflict.h ... which silently propagates a lot of headers into many places via pgstat.h, as evidenced by the variety of headers that this patch needs to add to seemingly random places. Add a minimum of typedefs to conflict.h to be able to remove execnodes.

pgsql: Change reset_extra into a config_generic common field

2025-10-18 Thread Peter Eisentraut
Change reset_extra into a config_generic common field This is not specific to the GUC parameter type, so it can be part of the generic struct rather than the type-specific struct (like the related "extra" field). This allows for some code simplifications. Reviewed-by: Chao Li Discussion: https

pgsql: Add test for pg_stat_reset_single_table_counters() on index

2025-10-18 Thread Michael Paquier
Add test for pg_stat_reset_single_table_counters() on index stats.sql is already doing some tests coverage on index statistics, by retrieving for example idx_scan and friends in pg_stat_all_tables. pg_stat_reset_single_table_counters() is supported for an index for a long time, but the case was ne

pgsql: Consistently handle tab delimiters for wait event names

2025-10-18 Thread Daniel Gustafsson
Consistently handle tab delimiters for wait event names Format validation and element extraction for intermediate line strings were inconsistent in their handling of tab delimiters, which resulted in an unclear error when multiple tab characters were used as a delimiter. This fixes it by using ca

Re: pgsql: doc: Remove trailing whitespace in xref

2025-10-18 Thread Daniel Gustafsson
> On 22 Sep 2025, at 10:17, Daniel Gustafsson > wrote: > > doc: Remove trailing whitespace in xref > > Remove stray whitespace in xref tag. > > This was found due to a regression in xmllint 2.15.0 which flagged > this as an error, and at the time of this commit no fix for xmllint > has shipped

pgsql: Fix two typos in xlogstats.h and xlogstats.c

2025-10-18 Thread Michael Paquier
Fix two typos in xlogstats.h and xlogstats.c Issue found while browsing this area of the code, introduced and copy-pasted around by 2258e76f90bf. Backpatch-through: 15 Branch -- REL_16_STABLE Details --- https://git.postgresql.org/pg/commitdiff/fa30f0cb06a184d13078832efc0052b9792de6f8

pgsql: Fix two typos in xlogstats.h and xlogstats.c

2025-10-18 Thread Michael Paquier
Fix two typos in xlogstats.h and xlogstats.c Issue found while browsing this area of the code, introduced and copy-pasted around by 2258e76f90bf. Backpatch-through: 15 Branch -- REL_15_STABLE Details --- https://git.postgresql.org/pg/commitdiff/5bc057d1f3afe6f6f0d902e3da89aa3770c79ceb

pgsql: Fix EvalPlanQual handling of foreign/custom joins in ExecScanFet

2025-10-18 Thread Etsuro Fujita
Fix EvalPlanQual handling of foreign/custom joins in ExecScanFetch. If inside an EPQ recheck, ExecScanFetch would run the recheck method function for foreign/custom joins even if they aren't descendant nodes in the EPQ recheck plan tree, which is problematic at least in the foreign-join case, beca

Re: pgsql: Fix EPQ crash from missing partition directory in EState

2025-10-18 Thread Amit Langote
On Thu, Oct 16, 2025 at 2:03 PM Amit Langote wrote: > Fix EPQ crash from missing partition directory in EState > > EvalPlanQualStart() failed to propagate es_partition_directory into > the child EState used for EPQ rechecks. When execution time partition > pruning ran during the EPQ scan, executor

pgsql: Fix two comments in numeric.c

2025-10-18 Thread Michael Paquier
Fix two comments in numeric.c The comments at the top of numeric_int4_safe() and numeric_int8_safe() mentioned respectively int4_numeric() and int8_numeric(). The intention is to refer to numeric_int4() and numeric_int8(). Oversights in 4246a977bad6. Reported-by: jian he Discussion: https://p

pgsql: Avoid warnings in tests when openssl binary isn't available

2025-10-18 Thread Daniel Gustafsson
Avoid warnings in tests when openssl binary isn't available The SSL tests for pg_stat_ssl tries to exactly match the serial from the certificate by extracting it with the openssl binary. If that fails due to the binary not being available, a fallback match is used, but the attempt to execute a mis

pgsql: Revert "pg_createsubscriber: Add log message when no publication

2025-10-18 Thread Masahiko Sawada
Revert "pg_createsubscriber: Add log message when no publications exist to drop." This reverts commit 74ac377d75135e02064fc4427bec401277b4f60c. The previous change contained a misconception about how publications are cleaned up on the subscriber. The newly added log message could confuse users,

pgsql: Add helper for freeze determination to heap_page_prune_and_freez

2025-10-18 Thread Melanie Plageman
Add helper for freeze determination to heap_page_prune_and_freeze After scanning the line pointers on a heap page during the first phase of vacuum, we use the information collected to decide whether to use the assembled freeze plans. Move this decision logic into a helper function to improve read

pgsql: Add log_autoanalyze_min_duration

2025-10-18 Thread Peter Eisentraut
Add log_autoanalyze_min_duration The log output functionality of log_autovacuum_min_duration applies to both VACUUM and ANALYZE, so it is not possible to separate the VACUUM and ANALYZE log output thresholds. Logs are likely to be output only for VACUUM and not for ANALYZE. Therefore, we decided

pgsql: Optimize hex_encode() and hex_decode() using SIMD.

2025-10-18 Thread Nathan Bossart
Optimize hex_encode() and hex_decode() using SIMD. The hex_encode() and hex_decode() functions serve as the workhorses for hexadecimal data for bytea's text format conversion functions, and some workloads are sensitive to their performance. This commit adds new implementations that use routines f

pgsql: Fix comment in eager_aggregate.sql

2025-10-18 Thread Richard Guo
Fix comment in eager_aggregate.sql The comment stated that eager aggregation is disabled by default, which is no longer true. This patch removes that comment as well as the related GUC set statement. Reported-by: David Rowley Discussion: https://postgr.es/m/caaphdvr4ywpimr3rsgywjwv-u8xorqtakri

pgsql: docs: Fix protocol version 3.2 message format of CancelRequest

2025-10-18 Thread Magnus Hagander
docs: Fix protocol version 3.2 message format of CancelRequest Since protocol version 3.2 the CancelRequest does not have a fixed size length anymore. The protocol docs still listed the length field to be a constant number though. This fixes that. Author: Jelte Fennema-Nio Reported-by: Dmitry Ig

pgsql: Use SOCK_ERRNO[_SET] in fe-secure-gssapi.c.

2025-10-18 Thread Tom Lane
Use SOCK_ERRNO[_SET] in fe-secure-gssapi.c. On Windows, this code did not handle error conditions correctly at all, since it looked at "errno" which is not used for socket-related errors on that platform. This resulted, for example, in failure to connect to a PostgreSQL server with GSSAPI enabled

pgsql: Fix matching check in recovery test 042_low_level_backup

2025-10-18 Thread Michael Paquier
Fix matching check in recovery test 042_low_level_backup 042_low_level_backup compared the result of a query two times with a comparison operator based on an integer, while the result should be compared with a string. The outcome of the tests is currently not impacted by this change. However, it

pgsql: Fix access-to-already-freed-memory issue in pgoutput.

2025-10-18 Thread Masahiko Sawada
Fix access-to-already-freed-memory issue in pgoutput. While pgoutput caches relation synchronization information in RelationSyncCache that resides in CacheMemoryContext, each entry's information (such as row filter expressions and column lists) is stored in the entry's private memory context (entr

pgsql: Fix update-po for the PGXS case

2025-10-18 Thread Álvaro Herrera
Fix update-po for the PGXS case The original formulation failed to take into account the fact that for the PGXS case, the source dir is not $(top_srcdir), so it ended up not doing anything. Handle it explicitly. Author: Ryo Matsumura Reviewed-by: Bryan Green Backpatch-through: 13 Discussion:

pgsql: Remove overzealous _bt_killitems assertion.

2025-10-18 Thread Peter Geoghegan
Remove overzealous _bt_killitems assertion. An assertion in _bt_killitems expected the scan's currPos state to contain a valid LSN, saved from when currPos's page was initially read. The assertion failed to account for the fact that even logged relations can have leaf pages with an invalid LSN whe

pgsql: Stop creating constraints during DETACH CONCURRENTLY

2025-10-18 Thread Álvaro Herrera
Stop creating constraints during DETACH CONCURRENTLY Commit 71f4c8c6f74b (which implemented DETACH CONCURRENTLY) added code to create a separate table constraint when a table is detached concurrently, identical to the partition constraint, on the theory that such a constraint was needed in case th

pgsql: Remove state.tmp when failing to save a replication slot

2025-10-18 Thread Michael Paquier
Remove state.tmp when failing to save a replication slot An error happening while a slot data is saved on disk in SaveSlotToPath() could cause a state.tmp file (temporary file holding the slot state data, renamed to its permanent name at the end of the function) to remain around after it has been

pgsql: Fix version number calculation for data folder flush in pg_combi

2025-10-18 Thread Michael Paquier
Fix version number calculation for data folder flush in pg_combinebackup The version number calculated by read_pg_version_file() is multiplied once by 1, to be able to do comparisons based on PG_VERSION_NUM or equivalents with a minor version included. However, the version number given sync_p

pgsql: Adjust new TAP test to work on macOS.

2025-10-18 Thread Tom Lane
Adjust new TAP test to work on macOS. Seems Apple's version of "wc -l" puts spaces before the number. (I wonder why the cfbot didn't find this.) While here, make the failure case log what it got, to aid debugging future issues. Per buildfarm. Branch -- master Details --- https://git.po

pgsql: Use designated initializers for guc_tables

2025-10-18 Thread Peter Eisentraut
Use designated initializers for guc_tables This makes the generating script simpler and the output easier to read. In the future, it will make it easier to reorder and rearrange the underlying C structures. Reviewed-by: Chao Li Discussion: https://www.postgresql.org/message-id/flat/8fdfb91e-60

pgsql: pg_regc_locale.c: rename some static functions.

2025-10-18 Thread Jeff Davis
pg_regc_locale.c: rename some static functions. Use the more specific prefix "regc_" rather than the generic prefix "pg_". A subsequent commit will create generic versions of some of these functions that can be called from other modules. Discussion: https://postgr.es/m/0151ad01239e2cc7b31396443

Re: pgsql: Move gramparse.h to src/backend/parser

2025-10-18 Thread Anton A. Melnikov
Hi! On 15.09.2022 06:52, John Naylor wrote: On Thu, Sep 15, 2022 at 4:04 AM Andres Freund wrote: The most general solution I can see would be diff --git i/src/backend/common.mk w/src/backend/common.mk index fa96a82b1a0..61861f5c7eb 100644 --- i/src/backend/common.mk +++ w/src/backend/common.

pgsql: Fix EPQ crash from missing partition directory in EState

2025-10-18 Thread Amit Langote
Fix EPQ crash from missing partition directory in EState EvalPlanQualStart() failed to propagate es_partition_directory into the child EState used for EPQ rechecks. When execution time partition pruning ran during the EPQ scan, executor code dereferenced a NULL partition directory and crashed. Pr

pgsql: Fix matching check in recovery test 042_low_level_backup

2025-10-18 Thread Michael Paquier
Fix matching check in recovery test 042_low_level_backup 042_low_level_backup compared the result of a query two times with a comparison operator based on an integer, while the result should be compared with a string. The outcome of the tests is currently not impacted by this change. However, it

pgsql: Stop creating constraints during DETACH CONCURRENTLY

2025-10-18 Thread Álvaro Herrera
Stop creating constraints during DETACH CONCURRENTLY Commit 71f4c8c6f74b (which implemented DETACH CONCURRENTLY) added code to create a separate table constraint when a table is detached concurrently, identical to the partition constraint, on the theory that such a constraint was needed in case th

pgsql: Fix determination of not-null constraint "locality" for inherite

2025-10-18 Thread Álvaro Herrera
Fix determination of not-null constraint "locality" for inherited columns It is possible to have a non-inherited not-null constraint on an inherited column, but we were failing to preserve such constraints during pg_upgrade where the source is 17 or older, because of a bug in the pg_dump query for

pgsql: Fix determination of not-null constraint "locality" for inherite

2025-10-18 Thread Álvaro Herrera
Fix determination of not-null constraint "locality" for inherited columns It is possible to have a non-inherited not-null constraint on an inherited column, but we were failing to preserve such constraints during pg_upgrade where the source is 17 or older, because of a bug in the pg_dump query for

pgsql: Fix determination of not-null constraint "locality" for inherite

2025-10-18 Thread Álvaro Herrera
Fix determination of not-null constraint "locality" for inherited columns It is possible to have a non-inherited not-null constraint on an inherited column, but we were failing to preserve such constraints during pg_upgrade where the source is 17 or older, because of a bug in the pg_dump query for

pgsql: Fix access-to-already-freed-memory issue in pgoutput.

2025-10-18 Thread Masahiko Sawada
Fix access-to-already-freed-memory issue in pgoutput. While pgoutput caches relation synchronization information in RelationSyncCache that resides in CacheMemoryContext, each entry's information (such as row filter expressions and column lists) is stored in the entry's private memory context (entr

pgsql: Fix pg_dump sorting of foreign key constraints

2025-10-18 Thread Álvaro Herrera
Fix pg_dump sorting of foreign key constraints Apparently, commit 04bc2c42f765 failed to notice that DO_FK_CONSTRAINT objects require identical handling as DO_CONSTRAINT ones, which causes some pg_upgrade tests in debug builds to fail spuriously. Add that. Author: Álvaro Herrera Backpatch-throu

pgsql: Fix pg_dump sorting of foreign key constraints

2025-10-18 Thread Álvaro Herrera
Fix pg_dump sorting of foreign key constraints Apparently, commit 04bc2c42f765 failed to notice that DO_FK_CONSTRAINT objects require identical handling as DO_CONSTRAINT ones, which causes some pg_upgrade tests in debug builds to fail spuriously. Add that. Author: Álvaro Herrera Backpatch-throu

pgsql: Fix pg_dump sorting of foreign key constraints

2025-10-18 Thread Álvaro Herrera
Fix pg_dump sorting of foreign key constraints Apparently, commit 04bc2c42f765 failed to notice that DO_FK_CONSTRAINT objects require identical handling as DO_CONSTRAINT ones, which causes some pg_upgrade tests in debug builds to fail spuriously. Add that. Author: Álvaro Herrera Backpatch-throu

pgsql: Assign each subquery a unique name prior to planning it.

2025-10-18 Thread Robert Haas
Assign each subquery a unique name prior to planning it. Previously, subqueries were given names only after they were planned, which makes it difficult to use information from a previous execution of the query to guide future planning. If, for example, you knew something about how you want "InitPl

pgsql: Remove preprocessor guards from injection points

2025-10-18 Thread Daniel Gustafsson
Remove preprocessor guards from injection points When defining an injection point there is no need to wrap the definition with USE_INJECTION_POINT guards, the INJECTION_POINT macro is available in all builds. Remove to make the code consistent. Author: Hayato Kuroda Reviewed-by: Michael Paquier

pgsql: Fix pg_dump sorting of foreign key constraints

2025-10-18 Thread Álvaro Herrera
Fix pg_dump sorting of foreign key constraints Apparently, commit 04bc2c42f765 failed to notice that DO_FK_CONSTRAINT objects require identical handling as DO_CONSTRAINT ones, which causes some pg_upgrade tests in debug builds to fail spuriously. Add that. Author: Álvaro Herrera Backpatch-throu

pgsql: Fix pg_dump sorting of foreign key constraints

2025-10-18 Thread Álvaro Herrera
Fix pg_dump sorting of foreign key constraints Apparently, commit 04bc2c42f765 failed to notice that DO_FK_CONSTRAINT objects require identical handling as DO_CONSTRAINT ones, which causes some pg_upgrade tests in debug builds to fail spuriously. Add that. Author: Álvaro Herrera Backpatch-throu

pgsql: Fix pg_dump sorting of foreign key constraints

2025-10-18 Thread Álvaro Herrera
Fix pg_dump sorting of foreign key constraints Apparently, commit 04bc2c42f765 failed to notice that DO_FK_CONSTRAINT objects require identical handling as DO_CONSTRAINT ones, which causes some pg_upgrade tests in debug builds to fail spuriously. Add that. Author: Álvaro Herrera Backpatch-throu

pgsql: Fix pg_dump sorting of foreign key constraints

2025-10-18 Thread Álvaro Herrera
Fix pg_dump sorting of foreign key constraints Apparently, commit 04bc2c42f765 failed to notice that DO_FK_CONSTRAINT objects require identical handling as DO_CONSTRAINT ones, which causes some pg_upgrade tests in debug builds to fail spuriously. Add that. Author: Álvaro Herrera Backpatch-throu

pgsql: Use ereport rather than elog in WinCheckAndInitializeNullTreatme

2025-10-18 Thread Tatsuo Ishii
Use ereport rather than elog in WinCheckAndInitializeNullTreatment. Previously WinCheckAndInitializeNullTreatment() used elog() to emit an error message. ereport() should be used instead because it's a user-facing error. Also use existing get_func_name() to get a function's name, rather than own i

pgsql: Use SOCK_ERRNO[_SET] in fe-secure-gssapi.c.

2025-10-18 Thread Tom Lane
Use SOCK_ERRNO[_SET] in fe-secure-gssapi.c. On Windows, this code did not handle error conditions correctly at all, since it looked at "errno" which is not used for socket-related errors on that platform. This resulted, for example, in failure to connect to a PostgreSQL server with GSSAPI enabled

pgsql: Fix LOCK_TIMEOUT handling during parallel apply.

2025-10-18 Thread Amit Kapila
Fix LOCK_TIMEOUT handling during parallel apply. Previously, the parallel apply worker used SIGINT to receive a graceful shutdown signal from the leader apply worker. However, SIGINT is also used by the LOCK_TIMEOUT handler to trigger a query-cancel interrupt. This overlap caused the parallel appl

pgsql: Align the data block sizes of pg_dump's various compression mode

2025-10-18 Thread Tom Lane
Align the data block sizes of pg_dump's various compression modes. After commit fe8192a95, compress_zstd.c tends to produce data block sizes around 128K, and we don't really have any control over that unless we want to overrule ZSTD_CStreamOutSize(). Which seems like a bad idea. But let's try to

pgsql: Remove overzealous _bt_killitems assertion.

2025-10-18 Thread Peter Geoghegan
Remove overzealous _bt_killitems assertion. An assertion in _bt_killitems expected the scan's currPos state to contain a valid LSN, saved from when currPos's page was initially read. The assertion failed to account for the fact that even logged relations can have leaf pages with an invalid LSN whe

pgsql: Add stats_reset to pg_stat_all_{tables,indexes} and related view

2025-10-18 Thread Michael Paquier
Add stats_reset to pg_stat_all_{tables,indexes} and related views It is possible to call pg_stat_reset_single_table_counters() on a relation (index or table) but the reset time was missing from the system views showing their statistics. This commit adds the reset time as an attribute of pg_stat_a

pgsql: Override log_error_verbosity to "default" in test 009_log_temp_f

2025-10-18 Thread Michael Paquier
Override log_error_verbosity to "default" in test 009_log_temp_files Per report from buildfarm member prion. The CI does not use this parameter, and this buildfarm member sets log_error_verbosity to "verbose". This would generate extra LOCATION entries in the logs, causing the regexps of the tes

pgsql: dbase_redo: Fix Valgrind-reported memory leak

2025-10-18 Thread Álvaro Herrera
dbase_redo: Fix Valgrind-reported memory leak Introduced by my (Álvaro's) commit 9e4f914b5eba, which was itself backpatched to pg10, though only pg15 and up contain the problem because of commit 9c08aea6a309. This isn't a particularly significant leak, but given the fix is trivial, we might as we

pgsql: Fix incorrect message-printing in win32security.c.

2025-10-18 Thread Tom Lane
Fix incorrect message-printing in win32security.c. log_error() would probably fail completely if used, and would certainly print garbage for anything that needed to be interpolated into the message, because it was failing to use the correct printing subroutine for a va_list argument. This bug lik

pgsql: bufmgr: Don't lock buffer header in StrategyGetBuffer()

2025-10-18 Thread Andres Freund
bufmgr: Don't lock buffer header in StrategyGetBuffer() Previously StrategyGetBuffer() acquired the buffer header spinlock for every buffer, whether it was reusable or not. If reusable, it'd be returned, with the lock held, to GetVictimBuffer(), which then would pin the buffer with PinBuffer_Locke

pgsql: Avoid unnecessary GinFormTuple() calls for incompressible postin

2025-10-18 Thread Masahiko Sawada
Avoid unnecessary GinFormTuple() calls for incompressible posting lists. Previously, we attempted to form a posting list tuple even when ginCompressPostingList() failed to compress the posting list due to its size. While there was no functional failure, it always wasted one GinFormTuple() call whe

pgsql: dbase_redo: Fix Valgrind-reported memory leak

2025-10-18 Thread Álvaro Herrera
dbase_redo: Fix Valgrind-reported memory leak Introduced by my (Álvaro's) commit 9e4f914b5eba, which was itself backpatched to pg10, though only pg15 and up contain the problem because of commit 9c08aea6a309. This isn't a particularly significant leak, but given the fix is trivial, we might as we

pgsql: Fix issue with reading zero bytes in Gzip_read.

2025-10-18 Thread Tom Lane
Fix issue with reading zero bytes in Gzip_read. pg_dump expects a read request of zero bytes to be a no-op; see for example ReadStr(). Gzip_read got this wrong and falsely supposed that the resulting gzret == 0 indicated an error. We could complicate that error-checking logic some more, but it s

pgsql: Stamp 18.0.

2025-10-18 Thread Tom Lane
Stamp 18.0. Branch -- REL_18_STABLE Details --- https://git.postgresql.org/pg/commitdiff/3d6a828938a5fa0444275d3d2f67b64ec3199eb7 Modified Files -- configure| 18 +- configure.ac | 2 +- meson.build | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-

pgsql: Correct prune WAL record opcode name in comment

2025-10-18 Thread Melanie Plageman
Correct prune WAL record opcode name in comment f83d709760d8 incorrectly refers to a XLOG_HEAP2_PRUNE_FREEZE WAL record opcode. No such code exists. The relevant opcodes are XLOG_HEAP2_PRUNE_ON_ACCESS, XLOG_HEAP2_PRUNE_VACUUM_SCAN, and XLOG_HEAP2_PRUNE_VACUUM_CLEANUP. Correct it. Author: Melanie

pgsql: Remove unused nbtree array advancement variable.

2025-10-18 Thread Peter Geoghegan
Remove unused nbtree array advancement variable. Remove a variable that is no longer in use following commit 9a2e2a28. It's not immediately clear why there were no compiler warnings about this oversight. Author: Peter Geoghegan Backpatch-through: 18 Branch -- REL_18_STABLE Details ---

pgsql: Add mem_exceeded_count column to pg_stat_replication_slots.

2025-10-18 Thread Masahiko Sawada
Add mem_exceeded_count column to pg_stat_replication_slots. This commit introduces a new column mem_exceeded_count to the pg_stat_replication_slots view. This counter tracks how often the memory used by logical decoding exceeds the logical_decoding_work_mem limit. The new statistic helps users det

pgsql: Add support for tracking of entry count in pgstats

2025-10-18 Thread Michael Paquier
Add support for tracking of entry count in pgstats Stats kinds can set a new option called "track_entry_count" (disabled by default, available for variable-numbered stats) that will make pgstats track the number of entries that exist in its shared hashtable. As there is only one code path where a

pgsql: Inline TransactionIdFollows/Precedes[OrEquals]()

2025-10-18 Thread Melanie Plageman
Inline TransactionIdFollows/Precedes[OrEquals]() These functions appeared prominently in a profile of a patch that sets the visibility map on-access. Inline them to remove call overhead and make them cheaper to use in hot paths. Author: Melanie Plageman Reviewed-by: Kirill Reshke Reviewed-by: A

pgsql: Remove unnecessary include of "utils/fmgroids.h"

2025-10-18 Thread Richard Guo
Remove unnecessary include of "utils/fmgroids.h" In initsplan.c, no macros for built-in function OIDs are used, so this include is unnecessary and can be removed. This was my oversight in commit 8e1185910. Discussion: https://postgr.es/m/CAMbWs4_-sag-cAKrLJ+X+5njL1=oudk=+KfLmsLZ5a2jckn=k...@mai

pgsql: Use bms_add_members() instead of bms_union() when possible

2025-10-18 Thread David Rowley
Use bms_add_members() instead of bms_union() when possible bms_union() causes a new set to be allocated. What this caller needs is members added to an existing set. bms_add_members() is the tool for that job. This is just a matter of fixing an inefficiency due to surplus memory allocations. No

pgsql: Fix incorrect targetlist in dummy UNIONs

2025-10-18 Thread David Rowley
Fix incorrect targetlist in dummy UNIONs The prior code, added in 03d40e4b5 attempted to use the targetlist of the first UNION child when all UNION children were proven as dummy rels. That's not going to work when some operation atop of the Result node must find target entries within the Result's

pgsql: Remove state.tmp when failing to save a replication slot

2025-10-18 Thread Michael Paquier
Remove state.tmp when failing to save a replication slot An error happening while a slot data is saved on disk in SaveSlotToPath() could cause a state.tmp file (temporary file holding the slot state data, renamed to its permanent name at the end of the function) to remain around after it has been

pgsql: Doc: clarify n_distinct_inherited setting

2025-10-18 Thread David Rowley
Doc: clarify n_distinct_inherited setting There was some confusion around how to adjust the n_distinct estimates for partitioned tables. Here we try and clarify that n_distinct_inherited needs to be adjusted rather than n_distinct. Also fix some slightly misleading text which was talking about t

pgsql: Doc: clarify n_distinct_inherited setting

2025-10-18 Thread David Rowley
Doc: clarify n_distinct_inherited setting There was some confusion around how to adjust the n_distinct estimates for partitioned tables. Here we try and clarify that n_distinct_inherited needs to be adjusted rather than n_distinct. Also fix some slightly misleading text which was talking about t

  1   2   >