1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00
Commit Graph

65084 Commits

Author SHA1 Message Date
Daniel Gustafsson
dd13dd39db Reorder function prototypes to match definition order
While purely aesthetic, it makes reading the code easier to rearrange
before the feature has shipped since doing it after risk backpatching
conflicts.  Also add missing prototypes.

Backpatch to v19 where online checksums were introduced.

Author: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/CAHGQGwEQ1-+iPQnUpTXYiHmzSz9ufFVkOK4kL_uyTdYt7jgg0Q@mail.gmail.com
Backpatch-through: 19
2026-08-17 22:40:26 +02:00
Daniel Gustafsson
ed6775db84 Make data checksums launcher cancel its worker at SIGINT
Make sure the launcher cancels the currently running worker by calling
TerminateBackgroundWorker when it receives SIGINT.  In order to handle
cases where SIGINT arrives while tje launcher is waiting for a worker
to start or exit, implement a version of WaitForBackgroundWorkerStartup
and WaitForBackgroundWorkerShutdown which checks the abort_requested
signalling.  A new test which kills processing with SIGINT is added.

Backpatch to v19 where online checksums were introduced.

Author: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Discussion: https://postgr.es/m/CAHGQGwEQ1-+iPQnUpTXYiHmzSz9ufFVkOK4kL_uyTdYt7jgg0Q@mail.gmail.com
Backpatch-through: 19
2026-08-17 22:40:22 +02:00
Peter Eisentraut
c9fd8ee14f Replace printf format %i by %d
as is PostgreSQL standard
2026-08-17 22:07:47 +02:00
Nathan Bossart
c66e7531e4 Add an "unset" value for vacuum_index_cleanup.
This commit adds a new value to StdRdOptIndexCleanup to distinguish
whether it is explicitly set, similar to ViewOptCheckOption's
VIEW_OPTION_CHECK_OPTION_NOT_SET.  This changes only the internal
representation; an unset value still defaults to AUTO, and the
option accepts the same input as before.

This is preparatory work for a follow-up commit that will make use
of the new "unset" state.

Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Sami Imseih <samimseih@gmail.com>
Tested-by: Greg Burd <greg@burd.me>
Tested-by: solai v <solai.cdac@gmail.com>
Discussion: https://postgr.es/m/aFRxC1W_kZU9OjJ9%40nathan
2026-08-17 14:41:59 -05:00
Tom Lane
131444cd16 Make plperl's handling of Perl arrays safer and more consistent.
plperl_func_handler()'s stanza for handling an arrayref result in
a SETOF function could loop forever (or at least till OOM) when
given a tied array, since av_fetch won't necessarily ever return
a null pointer in that case.  Be consistent with the other places
where we traverse a perl array: call av_len() once and use len+1
as the loop limit, silently ignoring any null pointers we get back
from that range of subscripts.

But actually, Perl's preferred locution for this seems to be to
use av_count() not av_len()+1.  av_count() seems better since
there's less risk of forgetting to add 1.  Also, both of those
functions return Size_t (or SSize_t) not int, creating at least
a theoretical overflow hazard.  While we're modernizing this,
let's use the correct variable type where we can, and include an
overflow check where we can't.

Reported-by: Claude Code (via Noah Misch)
Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Andrey Rachitskiy <pl0h0yp1@gmail.com>
Discussion: https://postgr.es/m/569769.1786901901@sss.pgh.pa.us
Backpatch-through: 14
2026-08-17 15:06:02 -04:00
Nathan Bossart
3d8f71a370 Make autovacuum_enabled a ternary reloption.
This commit reimplements autovacuum_enabled as a ternary, using the
support added in commit 4d6a66f675 and following the example of
vacuum_truncate.  This changes only the internal representation: an
unset value still behaves as enabled, and the option accepts the
same input as before.

This is preparatory work for a follow-up commit that will make use
of the new "unset" state.

Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Greg Burd <greg@burd.me>
Reviewed-by: Sami Imseih <samimseih@gmail.com>
Tested-by: solai v <solai.cdac@gmail.com>
Discussion: https://postgr.es/m/aFRxC1W_kZU9OjJ9%40nathan
2026-08-17 13:17:12 -05:00
Nathan Bossart
0499c6ccf5 Remove extract_autovac_opts().
extract_autovac_opts() returns a palloc'd copy of just the
AutoVacOpts portion of a relation's reloptions, but upcoming work
needs the other StdRdOptions fields, too.  Remove it in favor of
calling extractRelOptions() directly.  av_relation now caches the
main table's whole StdRdOptions.

Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Sami Imseih <samimseih@gmail.com>
Tested-by: Greg Burd <greg@burd.me>
Tested-by: solai v <solai.cdac@gmail.com>
Discussion: https://postgr.es/m/aFRxC1W_kZU9OjJ9%40nathan
2026-08-17 12:16:03 -05:00
Michael Paquier
51c43a5dbd Use safer allocation routines in more places of the tree
This is part of a more global effort to modernize the code tree with
safer allocation functions, which offer more protection in terms of:
- stronger type safety guarantees
- size overflow checks, particulary for arrays.

This set of updates includes allocation changes based on
palloc_object(), palloc_array() and repalloc_array().  This work is
similar to 1b105f9472, expanding more the new APIs in the tree in an
incremental fashion.

Author: Tristan Partin <tristan@partin.io>
Discussion: https://postgr.es/m/DKJB5887LGX9.359DV1UMZ1URK@partin.io
2026-08-17 16:15:45 +09:00
Michael Paquier
4fb6e9eb75 psql: Fix \d+ display of REPLICA IDENTITY NOTHING
Commit 18954ce7f6 has replaced hardcoded relreplident values in
describe.c with CppAsString2 macros, but used a DEFAULT instead of a
NOTHING at one location.  This caused \d+ on a table with REPLICA
IDENTITY NOTHING to show incorrect data.

Author: Shinya Kato <shinya11.kato@gmail.com>
Discussion: https://postgr.es/m/CAOzEurRHWt+9XLBrbXQOSVkE45NksJ4F28twuqgZ7veW0RzpUQ@mail.gmail.com
Backpatch-through: 18
2026-08-17 09:20:52 +09:00
Michael Paquier
803583ce74 Fix ASAN failure after flex errors in GUC file parsing
As detected by ASAN, the scanner value used when parsing GUC files can
be indeterminate when the flex error handler sigjumps to the old cleanup
path, before yylex_init() is called.

The flex scanner state is now made volatile in ParseConfigFp(), since
its value is assigned after sigsetjmp() and cna be accessed after
siglongjmp().  yylex_init() cannot use a volatile pointer; a temporary
variable is used before assigning the result of yylex_init() to it.

While on it, yy_create_buffer() is changed to detect the case where it
returns a NULL value.  Based on my read of the flex code, this cannot be
reached currently.  Future upstream changes or changes in the error
logic of the GUC file parsing could make that reachable, and it is four
extra lines of code.

Oversight in d663f150b5.

Reported-by: Ilia Kashintsev <ilia.kashintsev@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Andrey Rachitskiy <pl0h0yp1@gmail.com>
Discussion: https://postgr.es/m/19612-24ccb4fc6da7786f@postgresql.org
Backpatch-through: 18
2026-08-17 08:53:22 +09:00
Jeff Davis
3d00537feb Clarify logic in CreateSubscription().
No bug found in previous code, but it unnecessarily relied on grammar
rules. Per complaint from Coverity.

Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/1787286.1786328153@sss.pgh.pa.us
Backpatch-through: 19
2026-08-15 09:42:23 -07:00
Fujii Masao
4d85fd59c7 Add previous commit to .git-blame-ignore-revs 2026-08-15 23:26:23 +09:00
Fujii Masao
de8370d631 pgindent fix for commit 7b7c4a8dcc
Per buildfarm member koel.
2026-08-15 23:15:31 +09:00
Fujii Masao
7b7c4a8dcc Rename EXISTS-to-ANY converted subplan to exists_to_any
Simple EXISTS subplans can be converted to hashed ANY subplans as
an alternative implementation. Previously, both the original EXISTS
subplan and the converted ANY subplan used names with the
exists_ prefix, making EXPLAIN output harder to read and
pg_plan_advice targets less clear.

Use the exists_to_any_ prefix for converted ANY subplans so that
their names distinguish them from the original EXISTS alternative.
This only changes the names shown by EXPLAIN and used by plan advice;
it does not affect planner behavior.

Author: Yugo Nagata <nagata@sraoss.co.jp>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: solai v <solai.cdac@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/20260605165641.3950f99ace0aad8f807abe96@sraoss.co.jp
Backpatch-through: 19
2026-08-15 18:12:14 +09:00
Nathan Bossart
7e6e294e4e doc: Clarify the logging collector's guarantees.
Presently, the documentation for logging_collector says that the
collector "is designed to never lose messages," which reads as a
stronger promise than we actually make.  The collector does not
fsync the log file or retry failed writes, so log messages can go
missing after an operating system crash, power loss, or a write
error.  Reword that sentence and add a note about what is not
guaranteed.

Author: Daniel Bauman <danielbaniel@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Zhenwei Shang <a934172442@gmail.com>
Reviewed-by: Robert Treat <rob@xzilla.net>
Discussion: https://postgr.es/m/CAMtj0_a86DdDKkW-ReVpQpqjndVS6GMrwXVpQY4G3-SGY7saMQ%40mail.gmail.com
Backpatch-through: 14
2026-08-14 15:27:16 -05:00
Daniel Gustafsson
1b87dd4303 Use correct data type for version identifier
PGSS_PG_MAJOR_VERSION is written as an uint32 field, but was read back
into an int32.  Fix to make sure reading and writing use the same data
type.

Author: Karina Litskevich <litskevichkarina@gmail.com>
Discussion: https://postgr.es/m/CACiT8iYTkc33YWaA2D3t51Y5s=GqBO7T1zX7bkpSmet2njcLLw@mail.gmail.com
2026-08-14 21:52:21 +02:00
Daniel Gustafsson
3374850360 Use int64 for number of entries in pg_stat_statements
Commit 13b935cd changed hash_get_num_entries to return int64 instead
of long.  This fixes a few more users of hash_get_num_entries which
were missed in the original commit.

PGSS_FILE_HEADER is left unchanged since this only affects as of yet
unreleased versions of PostgreSQL.  Backpatch to v19 where the int64
change was performed.

Author: Karina Litskevich <litskevichkarina@gmail.com>
Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Discussion: https://postgr.es/m/CACiT8iYTkc33YWaA2D3t51Y5s=GqBO7T1zX7bkpSmet2njcLLw@mail.gmail.com
Backpatch-through: 19
2026-08-14 21:51:53 +02:00
Nathan Bossart
e6bccd5abe Add missing PGDLLIMPORT marker.
Oversight in commit ffca23839c.

Reported-by: Anton Voloshin <a.voloshin@postgrespro.ru>
Author: Anton Voloshin <a.voloshin@postgrespro.ru>
Backpatch-through: 14
2026-08-14 13:41:32 -05:00
Nathan Bossart
40af05bb61 Retire PQfn().
PQfn() has been documented as somewhat obsolete since commit
efc3a25bb0 (2003), and commit bd48114937 recently marked it unsafe
because it may write past the end of result_buf when result_is_int
is 0.  Furthermore, searches of publicly available code turned up
no callers, only language bindings that expose the function
without using it, so removing it seems unlikely to cause too much
trouble.

Since the symbol is exported, deleting it outright isn't an option,
so instead this commit teaches PQfn() to fail unconditionally with
an error that suggests alternatives.  The documentation for the
fast-path interface is replaced with a stub in the "Obsolete or
Renamed Features" appendix.  The server's fast-path support is
retained for the benefit of older clients and the frontend large
object interface.

The frontend large object interface, the only in-tree caller, now
uses PQnfn(), the private version of PQfn() added by commit
bd48114937.  I considered converting this code away from the
fast-path protocol entirely, but prepared statements can be
deallocated out from under libpq (e.g., by DISCARD ALL), and
PQexecParams() proved noticeably slower, so that is left as a
future exercise.

Reviewed-by: Christoph Berg <myon@debian.org>
Reviewed-by: Jacob Champion <jacob.champion@enterprisedb.com>
Reviewed-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://postgr.es/m/ahXE28klgxIJXBLq%40nathan
2026-08-14 11:29:21 -05:00
Tom Lane
0d7baa209a psql: count every COPY FROM STDIN when scanning a query string.
When SendQuery() is not told how many COPY FROM STDIN commands the
query string contains (as for -c, \gexec, and \watch), it scans the
string to count them itself.  But it called psql_scan() only once,
which stops at the first semicolon, so any COPY FROM STDIN past the
first sub-command was not counted, causing failure of cases that used
to work.  Oversight in commit 3045a25ba.

Author: Zsolt Parragi <zsolt.parragi@percona.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAN4CZFPqa6c+u4uX5jJ8LANHTQ4dxM3m4_8G9WmX_A4-2wuv2A@mail.gmail.com
Backpatch-through: 14
2026-08-14 12:14:23 -04:00
Peter Eisentraut
a82e33a83d Make generate_queries_for_path_pattern_recurse() interruptible
In case of a very long path pattern with each element pattern being
resolved to many graph elements
generate_queries_for_path_pattern_recurse() may take very long time to
generate all the possible graph paths.  Make
generate_queries_for_path_pattern_recurse() interruptible so that a
user may be able to cancel such a query if required and the interrupts
are processed in timely manner.

Author: Satyanarayana Narlapuram <satyanarlapuram@gmail.com>
Reviewed-by: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/CAHg%2BQDfDwcM4%3DDSiAV6Ly89YQ5EcMhzO1-9x%3DmGG1WJzODcAig%40mail.gmail.com
2026-08-14 15:08:36 +02:00
Peter Eisentraut
9924e2d900 Enforce WITH CHECK OPTION on DELETE FOR PORTION OF leftovers
DELETE FOR PORTION OF inserts temporal leftovers through ExecInsert(),
but the rewriter only attached view WCOs for INSERT/UPDATE.  Leftover
rows could therefore silently escape a WITH CHECK OPTION view, while
the equivalent UPDATE correctly raised an error.

This commit fixes it by attaching the WCOs for FOR PORTION OF deletes
too.

Author: Zsolt Parragi <zsolt.parragi@percona.com>
Co-authored-by: Paul A Jungwirth <pj@illuminatedcomputing.com>
Reviewed-by: solai v <solai.cdac@gmail.com>
Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/CAN4CZFOuTyhGspG0Nyits8PiK2keoNXkLj-u3APzc66aRcWY9A%40mail.gmail.com
2026-08-14 13:47:11 +02:00
Etsuro Fujita
9a08585e8e postgres_fdw: Rename option "restore_stats" to "import_stats".
The option added by commit 28972b6fc was named "restore_stats", because
it was calling pg_restore_relation_stats()/pg_restore_attribute_stats()
in place of fetching a remote rowsample.  However, those code paths have
been replaced with calls to
import_relation_statistics()/import_attribute_statistics() (cf. commit
54cd6fc83), so the option is now slightly misnamed.

Switch the option to "import_stats", which more closely reflects both
the functions being called internally, and the user's perception of what
the operation is doing.

Back-patch to v19 where commit 28972b6fc went in.

Suggested-by: Etsuro Fujita <etsuro.fujita@gmail.com>
Author: Corey Huinker <corey.huinker@gmail.com>
Discussion: https://postgr.es/m/CADkLM%3DezuspTk3VD-2EM6XtFP-Dfz7cJKtnbn0cB6gocsAgu1g%40mail.gmail.com
Backpatch-through: 19
2026-08-14 17:40:00 +09:00
Michael Paquier
eb983d0a94 Add string-based injection point wait in 051_effective_wal_level.pl
This serves as an in-core example of the condition-string API of
injection_points introduced in 0fd73cdffc, where a wait at the
beginning of a replication slot creation is tightened to happen only for
a specific slot name.

Author: Sami Imseih <samimseih@gmail.com>
Discussion: https://postgr.es/m/CAA5RZ0tsGHu2h6YLnVu4HiK05q+gTE_9WVUAqihW2LSscAYS-g@mail.gmail.com
2026-08-14 15:13:30 +09:00
Michael Paquier
0fd73cdffc injection_points: Add support for string comparison in conditions
injection_points is extended so as a caller can attach a string value to
a point, checked with a value provided at runtime.  There are a couple
of use cases where this can be useful, to be able to target points for
specific object names.

PID and string conditions can be combined together, so as a point can be
allowed for a specific process and string value at the same time.

The condition string is capped at 255 characters.  As the attach SQL
function now takes an optional condition string, it is no longer STRICT,
and rejects NULL inputs.  Empty condition strings are also rejected, as
they don't make sense.

Author: Sami Imseih <samimseih@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CAA5RZ0tsGHu2h6YLnVu4HiK05q+gTE_9WVUAqihW2LSscAYS-g@mail.gmail.com
2026-08-14 14:44:48 +09:00
Michael Paquier
1f97b252df Fix thinko in error of algorithm type lookup for channel binding
The error printed would always use a NULL value, due to OBJ_nid2sn()
known to fail.  This updates the error message to use the algorithm
number instead.

Oversight in 28995f051e, in the shape of copy-pasto failure.

Reported-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/CAHGQGwGPjENxX1SmkPrv9Rb-Fnij8jN4ginObmSTnWXqROS2+g@mail.gmail.com
2026-08-14 09:45:24 +09:00
Michael Paquier
f2ccb8e6c5 Refactor PgStat_TableStatus to new PgStat_RelationStatus
This new structure is split depending on the stats kind it deals with:
- PGSTAT_KIND_RELATION, for tables.
- PGSTAT_KIND_INDEX, for indexes.

This change designs a cleaner barrier for the handling of stats data
related to tables and indexes, by being able to track precisely what are
the counters used by one or the other for pending data.  Using a common
ground for both eases the tracking of Relations in the relcache, with a
structure based on a union separated by stats kind.

The code originally pointed to some counters that may not be used at
all.  For example, indexes have no need for the tracking of
sub-transaction data, still the code implied that these could be touched
for an index.  A consequence is that PgStat_TableXactStatus is not
renamed, as it is not used by indexes.

Some asserts are added as an extra layer of protection to prevent the
update of fields that should not be touched.  find_tabstat_entry() and
find_tabstat_entry_kind() are removed, replaced by a single
find_relstat_entry_kind() able to work for indexes and the rest.

72a6dad1c9 took care of the shared memory and on-disk part of the
split.  This focuses on the pending data part at backend level.

Author: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Discussion: https://postgr.es/m/f572abe7-a1bb-e13b-48c7-2ca150546822@gmail.com
2026-08-14 09:07:54 +09:00
Michael Paquier
28995f051e Use explicit fetching of digests in channel binding (OpenSSL >= 3.0)
This commit touches both the libpq and backend-side code of channel
binding where respectively pgtls_get_peer_certificate_hash() and
be_tls_get_certificate_hash() are upgraded to retrieve digests using the
method recommended by OpenSSL 3.0: no more direct EVP_sha256() or
similar, just a EVP_MD_fetch() through EVP to get an algorythm type,
based on a name.

The pre-3.0 code is still required for LibreSSL and as long as we
support OpenSSL 1.1.1.

Similar work has been done in b91f79cd08 and 1f3b9bb109.

Author: Mark Atwood <mark@reviewcommit.com>
Co-authored-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/178596055149.1584250.13974609482797470185@reviewcommit.com
2026-08-14 07:37:01 +09:00
Nathan Bossart
a8261c7660 Fix authorization check for role membership changes.
Presently, check_role_membership_authorization() decides whether
the current user may grant or revoke membership in a role by
calling is_admin_of_role(), which recurses through all grants,
while it chooses the grantor to record for the resulting entry by
calling select_best_admin(), which recurses only through inherited
grants.  When the two disagree, the permission check passes and the
grantor lookup then comes up empty, so the user sees an internal
"no possible grantors" error.  ALTER GROUP ... ADD USER reaches the
same error through the separate check in AlterRole().

To fix, teach both checks to search the same way
select_best_admin() does via a new has_admin_privs_of_role().  The
new check passes exactly when the grantor lookup was going to
succeed, so nothing that works today starts failing; the internal
error simply becomes a proper permission error.  Note that this
leaves the other callers of is_admin_of_role() alone, so a role
reachable only through a non-inherited grant can still be dropped,
renamed, or altered.  Whether that ought to change as well is left
as a future exercise.

Oversight in commit ce6b672e44.

Reported-by: ChangAo Chen <cca5507@qq.com>
Author: ChangAo Chen <cca5507@qq.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Pretham <prezza672@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Jacob Champion <jacob.champion@enterprisedb.com>
Discussion: https://postgr.es/m/tencent_ADCE2B34B230A9B631854806104FEF40C105%40qq.com
Discussion: https://postgr.es/m/CAJUn_kN%2BMhbb8fYP5xxQCq1KEziOinM6HgYx4ts_pPDnQ2y1nQ%40mail.gmail.com
Backpatch-through: 16
2026-08-13 16:35:07 -05:00
Nathan Bossart
ac5cea86e8 Reject CLUSTER (ANALYZE).
The introduction of the REPACK command also added support for
CLUSTER (ANALYZE).  Presumably this was unintentional, as the
CLUSTER docs make no mention of it.  CLUSTER (ANALYZE) on an
ordinary table succeeds and does indeed analyze the table, but a
database-wide CLUSTER (ANALYZE) or one on a partitioned table
fails with an error like:

    ERROR:  cannot execute REPACK (ANALYZE) on multiple tables

Rather than improving support for CLUSTER (ANALYZE) and thereby
encouraging folks to use CLUSTER instead of REPACK, let's just
reject it.  This commit does so by teaching ExecRepack() to ERROR
for the ANALYZE option in anything except REPACK commands.  Note
that VACUUM (FULL, ANALYZE) does not go through ExecRepack() and
therefore is unaffected by this change.

Oversight in commit ac58465e06.

Reported-by: Zsolt Parragi <zsolt.parragi@percona.com>
Author: Zsolt Parragi <zsolt.parragi@percona.com>
Discussion: https://postgr.es/m/CAN4CZFMVcgv1b2G-i%2Bkhs2MDnzWSr7O_53j_x%2BuhAxUV5rwWqw%40mail.gmail.com
Backpatch-through: 19
2026-08-13 15:28:34 -05:00
Tom Lane
957d4eae52 Consistently enforce tsvector/tsquery maximum lengths.
Some places rejected individual tokens longer than MAXSTRLEN, while
others rejected ones longer than MAXSTRLEN-1.  The data structure is
perfectly capable of handling MAXSTRLEN, so there's nothing wrong
with using the looser bound.  Moreover, as things stand there is a
dump/reload hazard: some code paths permit construction of a tsvector
or tsquery that would later be rejected by tsvectorin or tsqueryin.
So standardize on using MAXSTRLEN.

Identical remarks apply to MAXSTRPOS (the total data length),
so fix that too.

Back-patch, in hopes of avoiding cases where a value acceptable to
one supported release is not acceptable to another.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Zsolt Parragi <zsolt.parragi@percona.com>
Discussion: https://postgr.es/m/CAN4CZFNYQo4zfbRR435uD0vSfuy5y7dnFOXDfKr9zYoL1JnAxA@mail.gmail.com
Backpatch-through: 14
2026-08-13 11:20:27 -04:00
Heikki Linnakangas
2ae459b085 Fix misc spelling mistakes in comments, docs and tests 2026-08-13 15:04:40 +03:00
Heikki Linnakangas
776348900b Remove unnecessary #include <poll.h>
Commit cba5b994c9 removed the call to poll() that needed it.
2026-08-13 15:03:22 +03:00
Heikki Linnakangas
a2b64736bb Fix missing hash_seq_term()
This was harmless because the function (ThereAreNoReadyPortals()) has
only one caller, and that caller throws an error if the function
returns false and transaction abort cleans up the in-progress hash
searches.  But if someone called the function in some other way,
they'd get a warning about a leaked hash_seq_search scan.
2026-08-13 15:03:15 +03:00
Daniel Gustafsson
e8a8ccc3ca pgcrypto: remove unused field mdc_checked from PGP_Context
mdc_finish used to set this field once it had successfully verified
the MDC packet, with its only reader in the same function.  This was
removed by a59ee88197 when mdc_finish stopped being called through
the pullf_read API, the field has been unused since.

Note that MDC verification does not rely on it: process_data_packets
tracks whether an MDC packet was seen in its local got_mdc variable
and rejects the message if a required MDC is missing, while the
use_mdcbuf_filter path checks the hash in mdcbuf_finish().

Author: Aleksander Alekseev <aleksander@tigerdata.com>
Discussion: https://postgr.es/m/CAJ7c6TNmHnnCkn3uZwRUE7WWYftW--48JFoDVDqoZqMrLYxUZw@mail.gmail.com
2026-08-13 13:18:12 +02:00
Fujii Masao
72e6184cd5 vacuumdb: Use ANALYZE ONLY for partitioned tables
When vacuumdb --analyze-only or --analyze-in-stages enumerates
tables itself, it can select both a partitioned table and its
partitions as separate work items. Previously, it generated plain
ANALYZE for the partitioned table, which recursively analyzed its
partitions as well.

This caused duplicate work when the partitions were already selected by
vacuumdb. With --analyze-in-stages, the redundant work could be
repeated at every stage.

Fix this by generating ANALYZE ONLY for automatically selected
partitioned tables when connected to servers that support it. This
updates inherited statistics for the partitioned table while leaving
per-partition statistics to the separately selected partition entries.
For older servers that do not support ANALYZE ONLY, vacuumdb falls back
to the previous plain ANALYZE command.

This also applies when partitioned tables are selected by schema
filters. In that case, partitions matching the filters are analyzed as
separate targets, while per-partition statistics for partitions outside
the filters are not updated via the partitioned parent.

This commit does not change the behavior for partitioned tables
specified explicitly with --table, i.e., in that case, vacuumdb
continues to generate plain ANALYZE, recursively analyzing the specified
partitioned table and its partitions.

Suggested-by: Justin Pryzby <pryzby@telsasoft.com>
Author: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Discussion: https://postgr.es/m/aKZ7lMYGnnIo35c0@pryzbyj2023
Backpatch-through: 19
2026-08-13 14:22:39 +09:00
Amit Kapila
8d795a3658 Doc: Clarify ALTER PUBLICATION's REFRESH PUBLICATION wording.
The note used a confusing "tables/except tables/schemas" slash-list,
omitted DROP from the operations requiring a subscriber refresh, and
called out "unset ALL SEQUENCES" without its symmetric "unset ALL TABLES"
case. Reword for clarity and consistency.

Author: Peter Smith <smithpb2250@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Backpatch-through: 19
Discussion: https://postgr.es/m/CAHut+PuGKrWhVMvuFyf-wSdF-Tai_jPTz2UCSCqsYM-82ATY5w@mail.gmail.com
2026-08-13 10:00:35 +05:30
Fujii Masao
bcb15f4878 doc: Clarify pgbench reporting with --continue-on-error
Clarify that transactions failed under --continue-on-error are reported
separately and are not counted as transactions actually processed, while
time spent on them can lower reported TPS. Also adjust the latency
description to avoid implying that failed transactions are generally included
in latency measurements.

Backpatch to v19, where pgbench's --continue-on-error option was introduced.

Author: Chao Li <lic@highgo.com>
Reviewed-by: Yugo Nagata <nagata@sraoss.co.jp>
Reviewed-by: Xuneng Zhou <xunengzhou@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/597C9755-4386-488D-A289-16D50AD81FBF@gmail.com
Backpatch-through: 19
2026-08-13 13:26:47 +09:00
Álvaro Herrera
bdaad789c8 Reject REPLICA IDENTITY USING INDEX on column with invalid NOT NULL
ALTER TABLE ... REPLICA IDENTITY USING INDEX verified key columns by
reading pg_attribute.attnotnull, but commit a379061a22 made
attnotnull true also for unvalidated (NOT VALID) not-null constraints,
which do not prove the column null-free.  An index over such a column
could thus be marked as replica identity even though the column might
contain NULLs, causing apply-side divergence for UPDATE/DELETE on the
nullable rows.

Fix by additionally requiring convalidated for the underlying
constraint, mirroring the fix d9ffc27291 applied to ATExecAddIdentity
for the analogous identity-column case.

Author: Ante Krešić <ante@tigerdata.com>
Reviewed-by: Aleksander Alekseev <aleksander@tigerdata.com>
Reviewed-by: solai v <solai.cdac@gmail.com>
Backpatch-through: 18
Discussion: https://postgr.es/m/CABXQ4dJUibZzN91qvWmsfA7MUDn9YRCNyu3CcukdyokbH1=41Q@mail.gmail.com
2026-08-12 19:15:48 +02:00
Tom Lane
7774249d0b Fix float8_regr_accum() for Inf/NaN with constant other input.
Commit 649828769 improved this code to keep Sxx, Syy, and Sxy
exactly zero so long as we see only a single value of the input(s).
However, if any values of the other input are Inf or NaN, we'd
better set Sxy to NaN instead.  Otherwise we risk reporting zero
variance when the result is really undefined.  The old coding handled
this implicitly, but in the short-circuit path we have to take care
of it explicitly.

Bug: #19615
Reported-by: Junwen An <feasiblechart@gmail.com>
Author: Andrey Rachitskiy <pl0h0yp1@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/19615-c7e390593416f6b6@postgresql.org
Backpatch-through: 19
2026-08-12 12:49:00 -04:00
Álvaro Herrera
aaf67e4825 Avoid recalculating pgprocno in ProcArrayAdd()
The value is already stored in a local variable a few lines above.
This is just a cosmetic change.

Author: Shinya Kato <shinya11.kato@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: solai v <solai.cdac@gmail.com>
Reviewed-by: Pierre Forstmann <pierre.forstmann@gmail.com>
Discussion: https://postgr.es/m/CAOzEurTJO2aqd9ewQmo9vjCrFUAD8Lk+raujCfK5oWoLGUP_3w@mail.gmail.com
2026-08-12 16:48:21 +02:00
Álvaro Herrera
b495c5685a Fix stale comments/signature after commit 28d534e2ae
Commit db89a47115 added an 'options' argument to table_tuple_update()
and table_tuple_delete(), correctly documenting it as recognizing no
values.  It also (correctly) added pg_attribute_unused() to the
corresponding heap_update() argument.  Commit 28d534e2ae then added
TABLE_UPDATE_NO_LOGICAL and TABLE_DELETE_NO_LOGICAL, but failed to
(correctly) update the comment and heap_update()'s signature.

In table_tuple_update(), move the correct explanation of 'options' to
the right place, remove the bogus one.

In table_tuple_delete(), add the missing TABLE_DELETE_NO_LOGICAL doc.

In heap_update(), remove the pg_attribute_unused() marker.

Author: Nikhil Sontakke <nikhil@planetscale.com>
Backpatch-through: 19
Discussion: https://postgr.es/m/CA+UBoq21SzkjThYMSwSpVU-jwzpuEsf22Hq1FPbcKcDc43C29g@mail.gmail.com
2026-08-12 11:53:10 +02:00
Fujii Masao
d6bf0ab170 Add common LSN parser for user-supplied locations
pg_waldump (--start/--end), pg_recvlogical (--startpos/--endpos), and
pg_receivewal (--endpos) parsed user-supplied WAL locations with
sscanf("%X/%08X").  That accepts several forms rejected by pg_lsn input
and can proceed with a different location than the user specified:
overlong components, trailing characters, leading whitespace, signs, and
0x prefixes.

Add pg_parse_lsn() to src/common and use it for those command-line
options.  The helper accepts the pg_lsn text syntax only: one to eight
hexadecimal digits, a slash, one to eight hexadecimal digits, and no
trailing characters.  Each frontend tool keeps its existing error
message.

Use the same helper from pg_lsn_in_safe(), leaving only backend-specific
soft error reporting there.  This keeps frontend command-line validation
and backend pg_lsn input tied to one parser.

Bug: #19598
Reported-by: Michael Malis <malis@pgrust.com>
Author: Zexin Li <lizi.openmind@gmail.com>
Reviewed-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/19598-aa67c8f4331611b4@postgresql.org
2026-08-12 17:03:46 +09:00
Daniel Gustafsson
2eb9a8e84a Use per-query timeout in subscription test
A buildfarm failure in subscription/038_walsnd_shutdown_timeout was
diagnosed to the background psql session timing out due to a backup
taking a long time.  The session was using a single timeout for all
queries, so switch to resetting the timer for each query to make it
survive slow backups due to constrained buildfarm machines.

Backpatch to v19 where the test was introduced.

Author: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Discussion: https://postgr.es/m/OS9PR01MB12149AA18EEA475D2AA22FD3BF5D12@OS9PR01MB12149.jpnprd01.prod.outlook.com
Backpatch-through: 19
2026-08-12 09:41:44 +02:00
Michael Paquier
6828b03b06 Fix poll_query_until() timeout handling with an undefined query in Cluster.pm
On timeout, poll_query_until() would fail to print its report when
"$query" was undefined.  Instead of the expected report, this prevented
the contents of stdout and stderr from being shown.

Note that some of the in-core tests use an undefined query for
connection-only polls.

Author: Bryan Green <dbryan.green@gmail.com>
Reviewed-by: Jonathan Gonzalez V. <jonathan.abdiel@gmail.com>
Discussion: https://postgr.es/m/0f515c6d-6032-4c5f-80ac-5c78faae9522@gmail.com
Backpatch-through: 14
2026-08-12 16:23:04 +09:00
Amit Kapila
cc1ea710dc Remove unnecessary list_free() calls in OpenTableList().
OpenTableList() is invoked at most once per DDL statement, from
CreatePublication() and AlterPublicationTables(), and everything it
builds (relids, relids_with_rf, and relids_with_collist) is allocated
in the command's own memory context. That context is reclaimed as
soon as the command finishes, so explicitly freeing relids and
relids_with_rf here served no purpose.

Reported-by: Peter Smith <smithpb2250@gmail.com>
Suggested-by: Tom Lane <tgl@sss.pgh.pa.us>
Author: Peter Smith <smithpb2250@gmail.com>
Reviewed-by: shveta malik <shveta.malik@gmail.com>
Reviewed-by: shihao zhong <zhong950419@gmail.com>
Reviewed-by: surya poondla <suryapoondla4@gmail.com>
Discussion: https://postgr.es/m/CAHut+Pt3bgyt==d6GCj=p9qu4sVSH_KQWLN7cMaH0RdJCO-K_Q@mail.gmail.com
2026-08-12 11:28:30 +05:30
Fujii Masao
33c77cfad3 Avoid unnecessary matview populated-state updates
REFRESH MATERIALIZED VIEW currently calls SetMatViewPopulatedState()
even when the materialized view's relispopulated value already matches
the state requested by the command.  That performs a catalog update of
pg_class without changing the visible state of the materialized view.

The extra update creates a dead pg_class tuple and causes the usual
catalog-update side effects, including relcache invalidation and WAL,
for no semantic benefit.  The effect is especially visible for
REFRESH MATERIALIZED VIEW CONCURRENTLY, where the refresh updates the
materialized view contents with DML and otherwise need not change
pg_class just to keep relispopulated set to true.

Check the current populated state before calling SetMatViewPopulatedState(),
and update pg_class only when the value would actually change.  This
preserves the required state transitions for WITH DATA and WITH NO DATA
while avoiding catalog churn for repeated refreshes that leave the
populated state unchanged.

Author: ChangAo Chen <cca5507@qq.com>
Reviewed-by: Zizhuan Liu <44973863@qq.com>
Reviewed-by: Adam Brusselback <adambrusselback@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/tencent_DF2D8533B5412908326F7806075B7637A108@qq.com
2026-08-12 14:42:57 +09:00
Michael Paquier
72a6dad1c9 Move index statistics into their own stats kind
This commit splits the relation and index stats data, where the index
data is now moved to a new kind called PGSTAT_KIND_INDEX.  A benefit of
this refactoring is a reduction of the shared memory required for each
index, the new PgStat_StatIdxEntry including only the fields required
for indexes.  This leads to less data flushed to disk on shutdown.
Another benefit is that the addition of new fields for relation-level
stats is easier to think about.  Note that indexes have no need for most
of the xact-level fields that relations care about, clarifying the role
of each counter for each relkind.

System views are updated to use the index-level functions.  Note this
split means a possible break for tools that had the idea to call the
SQL functions for relation stats (not documented), as now these would
return 0 when queried for an index.  These tools can use the new index
functions to achieve the same result.

As of this change, the pending statistics are still controlled by
PgStat_TableStatus for both relation and index kinds.  This is left as a
follow-up piece, this one being good enough on its own.  This commit is
focused on the changes required for the SQL interface, shared memory
management and the on-disk format.

Bump catalog version.
Bump PGSTAT_FILE_FORMAT_ID.

Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Author: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/f572abe7-a1bb-e13b-48c7-2ca150546822@gmail.com
2026-08-12 12:06:05 +09:00
Michael Paquier
feb15361b3 Fix unlink() error report in KeepFileRestoredFromArchive()
KeepFileRestoredFromArchive() has been using an incorrect WAL segment
name in the error report for an unlink() failure.

Even without 1200dfd60c, this was of consequence only on WIN32, where
we would miss to report a segment name suffixed by ".deleted%u".

Oversight in 60df192aea, for what looks like a copy-pasto to me.

Reported-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/CAHGQGwHSbJnUmWCuF-QNUsGYF=iSSuzLRx1z_dLfYFwfbTu4Cw@mail.gmail.com
2026-08-12 09:45:03 +09:00
Michael Paquier
afd63e0ad2 Improve GrantLockLocal() handling on out-of-memory errors
On the first LockAcquire for a lock tag, LockAcquireExtended() creates
a LOCALLOCK entry in the hash table LockMethodLocalHash, with lockOwners
set to NULL.  lockOwners is then allocated in TopMemoryContext.

If the allocation fails, the hash entry would persist with lockOwners
still NULL and maxLockOwners already set to 8.  A follow-up
LockAcquire() on the same entry would crash on a NULL pointer
dereference.

This commit adds an extra layer of safety for such a case, by
re-attempting MemoryContextAlloc() if a LOCALLOCK entry exists but its
lockOwners is still NULL due to a previous in-flight allocation failure.

This problem is unlikely going to show up in practice, so no backpatch
is done.

Author: Bryan Green <dbryan.green@gmail.com>
Author: Mark Dilger <mark.dilger@enterprisedb.com>
Discussion: https://postgr.es/m/c9a5eeb1-4d31-46e1-bb9e-33448a23a5d3@gmail.com
2026-08-12 09:09:58 +09:00