users/c2main/postgres.git
3 months agoRemove PrintBufferDescs() and PrintPinnedBufs(). master
Tom Lane [Sun, 19 Jan 2025 19:00:22 +0000 (14:00 -0500)]
Remove PrintBufferDescs() and PrintPinnedBufs().

These have been #ifdef'd out for a long time, and in fact have
been uncompilable since commit 48354581a of 2016-04-10.  The
fact that nobody noticed for so long demonstrates their lack of
usefulness, so let's remove them rather than fix them.

Author: Jacob Brazeal <[email protected]>
Discussion: https://postgr.es/m/CA+COZaB+9CN_f63PPRoVhHjYmCwwmb_9CWLxqCJdMWDqs1a-JA@mail.gmail.com

3 months agoBe clearer about when jsonapi's need_escapes is needed
Andrew Dunstan [Sun, 19 Jan 2025 14:09:58 +0000 (09:09 -0500)]
Be clearer about when jsonapi's need_escapes is needed

Most operations beyond pure json parsing need to set need_escapes to
true to get access to field names and string scalars. Document this
fact more explicitly.

Slightly tweaked patch from:

Author: Corey Huinker <[email protected]>

Discussion: https://postgr.es/m/CADkLM=c49Vkfg2+A8ubSuEtaGEjuaKZXCA6SrXA8kdwHjx3uxQ@mail.gmail.com

3 months agoSupport PG_UNICODE_FAST locale in the builtin collation provider.
Jeff Davis [Fri, 17 Jan 2025 23:56:30 +0000 (15:56 -0800)]
Support PG_UNICODE_FAST locale in the builtin collation provider.

The PG_UNICODE_FAST locale uses code point sort order (fast,
memcmp-based) combined with Unicode character semantics. The character
semantics are based on Unicode full case mapping.

Full case mapping can map a single codepoint to multiple codepoints,
such as "ß" uppercasing to "SS". Additionally, it handles
context-sensitive mappings like the "final sigma", and it uses
titlecase mappings such as "Dž" when titlecasing (rather than plain
uppercase mappings).

Importantly, the uppercasing of "ß" as "SS" is specifically mentioned
by the SQL standard. In Postgres, UCS_BASIC uses plain ASCII semantics
for case mapping and pattern matching, so if we changed it to use the
PG_UNICODE_FAST locale, it would offer better compliance with the
standard. For now, though, do not change the behavior of UCS_BASIC.

Discussion: https://postgr.es/m/ddfd67928818f138f51635712529bc5e1d25e4e7[email protected]
Discussion: https://postgr.es/m/27bb0e52-801d-4f73-a0a4-02cfdd4a9ada@eisentraut.org
Reviewed-by: Peter Eisentraut, Daniel Verite
3 months agoSupport Unicode full case mapping and conversion.
Jeff Davis [Fri, 17 Jan 2025 23:56:20 +0000 (15:56 -0800)]
Support Unicode full case mapping and conversion.

Generate tables from Unicode SpecialCasing.txt to support more
sophisticated case mapping behavior:

 * support case mappings to multiple codepoints, such as "ß"
   uppercasing to "SS"
 * support conditional case mappings, such as the "final sigma"
 * support titlecase variants, such as "dž" uppercasing to "DŽ" but
   titlecasing to "Dž"

Discussion: https://postgr.es/m/ddfd67928818f138f51635712529bc5e1d25e4e7[email protected]
Discussion: https://postgr.es/m/27bb0e52-801d-4f73-a0a4-02cfdd4a9ada@eisentraut.org
Reviewed-by: Peter Eisentraut, Daniel Verite
3 months agovacuumdb: Fix comment for vacuum_one_database().
Nathan Bossart [Fri, 17 Jan 2025 21:23:14 +0000 (15:23 -0600)]
vacuumdb: Fix comment for vacuum_one_database().

Since commit e0c2933a76, vacuum_one_database() always uses a
catalog query to discover the tables to process, but this comment
still notes the special case for which we used a catalog query
before that commit.  Let's just remove that note.

Also, commit 7781f4e3e7 renamed the "tables" parameter to "objects"
but missed updating this comment.  This commit fixes that as well.

3 months agoAdd documentation about calling version-1 C functions from C.
Tom Lane [Fri, 17 Jan 2025 19:37:38 +0000 (14:37 -0500)]
Add documentation about calling version-1 C functions from C.

This topic wasn't really covered before, so fill in some details.

Author: Florents Tselai <[email protected]>
Reviewed-by: Pavel Stehule <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/90853055-5BBD-493D-91E5-721677C7C59B@gmail.com

3 months agoFix parsing of qualified relation names in RETURNING.
Dean Rasheed [Fri, 17 Jan 2025 10:35:07 +0000 (10:35 +0000)]
Fix parsing of qualified relation names in RETURNING.

Given a qualified refname, refnameNamespaceItem() will search for a
matching namespace item by relation OID, rather than by name. Commit
80feb727c8 broke this by adding additional namespace items for OLD and
NEW in the RETURNING list, which have the same relation OID, causing
ambiguity. Fix this by ignoring these in the search, which is correct
since they don't match the qualified relation name, and so there is no
real ambiguity.

Reported by Richard Guo.

Discussion: https://postgr.es/m/CAMbWs49MBjWYWDROJ8MZ%3DY%2B4UgRQa10wzik1tWrD5yto9eoGXg%40mail.gmail.com

3 months agoSpeed up hex_encode with bytewise lookup
John Naylor [Wed, 15 Jan 2025 06:28:26 +0000 (13:28 +0700)]
Speed up hex_encode with bytewise lookup

Previously, hex_encode looked up each nibble of the input
separately. We now use a larger lookup table containing the two-byte
encoding of every possible input byte, resulting in a 1/3 reduction
in encoding time.

Reviewed by Tom Lane, Michael Paquier, Nathan Bossart, David Rowley

Discussion: https://postgr.es/m/CANWCAZZvXuJMgqMN4u068Yqa19CEjS31tQKZp_qFFFbgYfaXqQ%40mail.gmail.com

3 months agoRemove flex version checks
Peter Eisentraut [Fri, 17 Jan 2025 07:35:52 +0000 (08:35 +0100)]
Remove flex version checks

Remove the flex version checks from configure and meson.  The cutoff
versions are all so ancient that this is no longer relevant, and what
the actual cutoff should be is a bit fuzzy.

This also removes the ancient behavior that configure would also
accept a "lex" program if it is actuall flex.  This aligns the check
with meson in this respect.

For future reference, as of this commit, these are relevant flex
versions:

- The hard required minimum is flex 2.5.34 as of commit b1ef48980dd,
  but this has not actually been tested.

- Prior to this, the minimum enforced by configure/meson was flex
  2.5.35, which is the oldest present in the buildfarm right now.

- As of commit 6fdd5d95634, the oldest version that will compile
  without warnings due to flex-generated code is flex 2.5.36.

- The oldest version that probably still has some practical relevance
  is flex 2.5.37, which ships with CentOS/RHEL 7.

Discussion: https://www.postgresql.org/message-id/1a204ccd-7ae6-478c-a431-407b5c48ccc6@eisentraut.org

3 months agoAdd pg_nodiscard decorations to base64 functions
Peter Eisentraut [Fri, 17 Jan 2025 07:06:24 +0000 (08:06 +0100)]
Add pg_nodiscard decorations to base64 functions

The result of pg_b64_encode() and pg_b64_decode() should be checked
for errors.  This attribute could detect mistakes such as those fixed
in commit ff030ebe250 and d278541be42.

Reviewed-by: Michael Paquier <[email protected]>
Reviewed-by: Ranier Vilela <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/CAEudQAq-3yHsSdWoOOaw%2BgAQYgPMpMGuB5pt2yCXgv-YuxG2Hg%40mail.gmail.com

3 months agoRevert recent changes related to handling of 2PC files at recovery
Michael Paquier [Fri, 17 Jan 2025 04:27:39 +0000 (13:27 +0900)]
Revert recent changes related to handling of 2PC files at recovery

This commit reverts 8f67f994e8ea (down to v13) and c3de0f9eed38 (down to
v17), as these are proving to not be completely correct regarding two
aspects:
- In v17 and newer branches, c3de0f9eed38's check for epoch handling is
incorrect, and does not correctly handle frozen epochs.  A logic closer
to widen_snapshot_xid() should be used.  The 2PC code should try to
integrate deeper with FullTransactionIds, 5a1dfde8334b being not enough.
- In v13 and newer branches, 8f67f994e8ea is a workaround for the real
issue, which is that we should not attempt CLOG lookups without reaching
consistency.  This exists since 728bd991c3c4, and this is reachable with
ProcessTwoPhaseBuffer() called by restoreTwoPhaseData() at the beginning
of recovery.

Per discussion with Noah Misch.

Discussion: https://postgr.es/m/20250116010051[email protected]
Backpatch-through: 13

3 months agoRemove redefinitions of SIG_* macros in win32_port.h.
Nathan Bossart [Fri, 17 Jan 2025 02:55:24 +0000 (20:55 -0600)]
Remove redefinitions of SIG_* macros in win32_port.h.

It is not clear why these were originally added.  One hypothesis is
that an ancient version of MinGW didn't define them.  In any case,
they appear to now be superfluous, so let's remove them.  If
nothing else, the buildfarm might offer us clues to their origins.

Reviewed-by: Thomas Munro
Discussion: https://postgr.es/m/Z4chOKfnthRH71mw%40nathan

3 months agoFix setrefs.c's failure to do expression processing on prune steps.
Tom Lane [Fri, 17 Jan 2025 01:40:07 +0000 (20:40 -0500)]
Fix setrefs.c's failure to do expression processing on prune steps.

We should run the expression subtrees of PartitionedRelPruneInfo
structs through fix_scan_expr.  Failure to do so means that
AlternativeSubPlans within those expressions won't be cleaned up
properly, resulting in "unrecognized node type" errors since v14.

It seems fairly likely that at least some of the other steps done
by fix_scan_expr are important here as well, resulting in as-yet-
undetected bugs.  Therefore, I've chosen to back-patch this to
all supported branches including v13, even though the known
symptom doesn't manifest in v13.

Per bug #18778 from Alexander Lakhin.

Discussion: https://postgr.es/m/18778-24cd399df6c806af@postgresql.org

3 months agoAdd and use BitmapHeapScanDescData struct
Melanie Plageman [Thu, 16 Jan 2025 23:42:39 +0000 (18:42 -0500)]
Add and use BitmapHeapScanDescData struct

Move the several members of HeapScanDescData which are specific to
Bitmap Heap Scans into a new struct, BitmapHeapScanDescData, which
inherits from HeapScanDescData.

This reduces the size of the HeapScanDescData for other types of scans
and will allow us to add additional bitmap heap scan-specific members in
the future without fear of bloating the HeapScanDescData.

Reviewed-by: Tomas Vondra
Discussion: https://postgr.es/m/c736f6aa-8b35-4e20-9621-62c7c82e2168%40vondra.me

3 months agoRework macro pgstat_is_ioop_tracked_in_bytes()
Michael Paquier [Thu, 16 Jan 2025 23:26:17 +0000 (08:26 +0900)]
Rework macro pgstat_is_ioop_tracked_in_bytes()

As written, it was triggering a compilation warning for old versions of
clang, as reported by buildfarm members ayu, batfish and demoiselle.
Forcing a cast with "unsigned int" should fix the warning.

While on it, the macro is moved to pgstat.h, closer to the declaration
of IOOp, per suggestion from Tom Lane.

Reported-by: Tom Lane
Reviewed-by: Bertrand Drouvot, Tom Lane, Nazir Bilal Yavuz
Discussion: https://postgr.es/m/1272824.1736961543@sss.pgh.pa.us

3 months agoConvert libpgport's pqsignal() to a void function.
Nathan Bossart [Thu, 16 Jan 2025 22:41:05 +0000 (16:41 -0600)]
Convert libpgport's pqsignal() to a void function.

The protections added by commit 3b00fdba9f introduced race
conditions to this function that can lead to bogus return values.
Since nobody seems to inspect the return value, this is of little
consequence, but it would have been nice to convert it to a void
function to avoid any possibility of a bogus return value.  I
originally thought that doing so would have required also modifying
legacy-pqsignal.c's version of the function (which would've
required an SONAME bump), but commit 9a45a89c38 gave
legacy-pqsignal.c its own dedicated extern for pqsignal(), thereby
decoupling it enough that libpgport's pqsignal() can be modified.

This commit also adds an assertion for the return value of
sigaction()/signal().  Since a failure most likely indicates a
coding error, and nobody has ever bothered to check pqsignal()'s
return value, it's probably not worth the effort to do anything
fancier.

Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/Z4chOKfnthRH71mw%40nathan

3 months agoAvoid calling pqsignal() with invalid signals on Windows frontends.
Nathan Bossart [Thu, 16 Jan 2025 21:56:39 +0000 (15:56 -0600)]
Avoid calling pqsignal() with invalid signals on Windows frontends.

As noted by the comment at the top of port/pqsignal.c, Windows
frontend programs can only use pqsignal() with the 6 signals
required by C.  Most places avoid using invalid signals via #ifndef
WIN32, but initdb and pg_test_fsync check whether the signal itself
is defined, which doesn't work because win32_port.h defines many
extra signals for the signal emulation code.  pg_regress seems to
have missed the memo completely.  These issues aren't causing any
real problems today because nobody checks the return value of
pqsignal(), but a follow-up commit will add some error checking.

To fix, surround all frontend calls to pqsignal() that use signals
that are invalid on Windows with #ifndef WIN32.  We cannot simply
skip defining the extra signals in win32_port.h for frontends
because they are needed in places such as pgkill().

Reviewed-by: Thomas Munro
Discussion: https://postgr.es/m/Z4chOKfnthRH71mw%40nathan

3 months agoSeek zone abbreviations in the IANA data before timezone_abbreviations.
Tom Lane [Thu, 16 Jan 2025 19:11:19 +0000 (14:11 -0500)]
Seek zone abbreviations in the IANA data before timezone_abbreviations.

If a time zone abbreviation used in datetime input is defined in
the currently active timezone, use that definition in preference
to looking in the timezone_abbreviations list.  That allows us to
correctly handle abbreviations that have different meanings in
different timezones.  Also, it eliminates an inconsistency between
datetime input and datetime output: the non-ISO datestyles for
timestamptz have always printed abbreviations taken from the IANA
data, not from timezone_abbreviations.  Before this fix, it was
possible to demonstrate cases where casting a timestamp to text
and back fails or changes the value significantly because of that
inconsistency.

While this change removes the ability to override the IANA data about
an abbreviation known in the current zone, it's not clear that there's
any real use-case for doing so.  But it is clear that this makes life
a lot easier for dealing with abbreviations that have conflicts across
different time zones.

Also update the pg_timezone_abbrevs view to report abbreviations
that are recognized via the IANA data, and *not* report any
timezone_abbreviations entries that are thereby overridden.
Under the hood, there are now two SRFs, one that pulls the IANA
data and one that pulls timezone_abbreviations entries.  They're
combined by logic in the view.  This approach was useful for
debugging (since the functions can be called on their own).
While I don't intend to document the functions explicitly,
they might be useful to call directly.

Also improve DecodeTimezoneAbbrev's caching logic so that it can
cache zone abbreviations found in the IANA data.  Without that,
this patch would have caused a noticeable degradation of the
runtime of timestamptz_in.

Per report from Aleksander Alekseev and additional investigation.

Discussion: https://postgr.es/m/CAJ7c6TOATjJqvhnYsui0=CO5XFMF4dvTGH+skzB--jNhqSQu5g@mail.gmail.com

3 months agoMake pg_interpret_timezone_abbrev() check sp->defaulttype too.
Tom Lane [Thu, 16 Jan 2025 17:43:03 +0000 (12:43 -0500)]
Make pg_interpret_timezone_abbrev() check sp->defaulttype too.

This omission caused it to not recognize the furthest-back zone
abbreviation when working with timezone data compiled with relatively
recent zic (2018f or newer).  Older versions of zic produced a dummy
DST transition at the Big Bang, so that the oldest abbreviation could
always be found in the sp->types[] array; but newer versions don't do
that, so that we must examine defaulttype as well as the types[] array
to be sure of seeing all the abbreviations.

While this has been broken for six or so years, we'd managed not
to notice for two reasons: (1) many platforms are still using
ancient zic for compatibility reasons, so that the issue did not
manifest in builds using --with-system-tzdata; (2) the oldest
zone abbreviation is almost always "LMT", which we weren't
supporting anyway (but an upcoming patch will accept that).

While at it, update pg_next_dst_boundary() to use sp->defaulttype
as the time type for non-DST zones and times before the oldest
DST transition.  The existing code there predates upstream's
invention of the sp->defaulttype field, and its heuristic for
finding the oldest time type has now been subsumed into the
code that sets sp->defaulttype.

Possibly this should be back-patched, but I'm not currently aware
of any visible consequences of this bug in released branches.

Per report from Aleksander Alekseev and additional investigation.

Discussion: https://postgr.es/m/CAJ7c6TOATjJqvhnYsui0=CO5XFMF4dvTGH+skzB--jNhqSQu5g@mail.gmail.com

3 months agoFix nbtree contradictory array element comment.
Peter Geoghegan [Thu, 16 Jan 2025 16:26:41 +0000 (11:26 -0500)]
Fix nbtree contradictory array element comment.

Oversight in commit 5bf748b8, which enhanced nbtree ScalarArrayOp
execution.

3 months agoSplit ATExecValidateConstraint into reusable pieces
Álvaro Herrera [Thu, 16 Jan 2025 15:44:24 +0000 (16:44 +0100)]
Split ATExecValidateConstraint into reusable pieces

With this, we have separate functions to add validation requests to
ALTER TABLE's phase 3 queue for check and foreign key constraints, which
allows reusing them in future commits -- particularly this will allow us
to perform validation of invalid foreign key constraints in partitioned
tables.

We could have let the check constraint code alone since we don't need to
reuse that for anything at this point, but it seems cleaner and more
consistent to do both at the same time.

Author: Amul Sul <[email protected]>
Discussion: https://postgr.es/m/CAAJ_b96Bp=-ZwihPPtuaNX=SrZ0U6ZsXD3+fgARO0JuKa8v2jQ@mail.gmail.com

3 months agoAdd OLD/NEW support to RETURNING in DML queries.
Dean Rasheed [Thu, 16 Jan 2025 14:57:35 +0000 (14:57 +0000)]
Add OLD/NEW support to RETURNING in DML queries.

This allows the RETURNING list of INSERT/UPDATE/DELETE/MERGE queries
to explicitly return old and new values by using the special aliases
"old" and "new", which are automatically added to the query (if not
already defined) while parsing its RETURNING list, allowing things
like:

  RETURNING old.colname, new.colname, ...

  RETURNING old.*, new.*

Additionally, a new syntax is supported, allowing the names "old" and
"new" to be changed to user-supplied alias names, e.g.:

  RETURNING WITH (OLD AS o, NEW AS n) o.colname, n.colname, ...

This is useful when the names "old" and "new" are already defined,
such as inside trigger functions, allowing backwards compatibility to
be maintained -- the interpretation of any existing queries that
happen to already refer to relations called "old" or "new", or use
those as aliases for other relations, is not changed.

For an INSERT, old values will generally be NULL, and for a DELETE,
new values will generally be NULL, but that may change for an INSERT
with an ON CONFLICT ... DO UPDATE clause, or if a query rewrite rule
changes the command type. Therefore, we put no restrictions on the use
of old and new in any DML queries.

Dean Rasheed, reviewed by Jian He and Jeff Davis.

Discussion: https://postgr.es/m/CAEZATCWx0J0-v=Qjc6gXzR=KtsdvAE7Ow=D=mu50AgOe+pvisQ@mail.gmail.com

3 months agoRemove dead code
Peter Eisentraut [Thu, 16 Jan 2025 13:37:28 +0000 (14:37 +0100)]
Remove dead code

As of commit 9895b35cb88, AlterDomainAddConstraint() can only be
called with constraints of type CONSTR_CHECK and CONSTR_NOTNULL.  So
all the code to check for and reject other constraint type values is
dead and can be removed.

Author: jian he <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/CACJufxHitd5LGLBSSAPShhtDWxT0ViVKTHinkYW-skBX93TcpA@mail.gmail.com

3 months agorefactor: split ATExecAlterConstrRecurse()
Peter Eisentraut [Thu, 16 Jan 2025 12:22:01 +0000 (13:22 +0100)]
refactor: split ATExecAlterConstrRecurse()

This splits out a couple of subroutines from
ATExecAlterConstrRecurse().  This makes the main function a bit
smaller, and a future patch (NOT ENFORCED foreign-key constraints)
will also want to call some of the pieces separately.

Author: Amul Sul <[email protected]>
Reviewed-by: jian he <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/CAAJ_b962c5AcYW9KUt_R_ER5qs3fUGbe4az-SP-vuwPS-w-AGA%40mail.gmail.com

3 months agoFix error handling of pg_b64_decode()
Peter Eisentraut [Thu, 16 Jan 2025 08:02:21 +0000 (09:02 +0100)]
Fix error handling of pg_b64_decode()

Fix for commit 761c79508e7.  The previous error handling logic was not
quite correct.

Discussion: https://www.postgresql.org/message-id/flat/CAEudQAq-3yHsSdWoOOaw%2BgAQYgPMpMGuB5pt2yCXgv-YuxG2Hg%40mail.gmail.com

3 months agoCheck return of pg_b64_encode() for error
Peter Eisentraut [Thu, 16 Jan 2025 07:35:57 +0000 (08:35 +0100)]
Check return of pg_b64_encode() for error

Forgotten in commit 761c79508e7.

Author: Ranier Vilela <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/CAEudQAq-3yHsSdWoOOaw%2BgAQYgPMpMGuB5pt2yCXgv-YuxG2Hg%40mail.gmail.com

3 months agoDoc: Improve the Replica Identity information.
Amit Kapila [Thu, 16 Jan 2025 03:03:02 +0000 (08:33 +0530)]
Doc: Improve the Replica Identity information.

This commit improves the Replica Identity information and clarifies its
related restrictions.

Reported-by: James Coleman
Author: Peter Smith
Co-authored-by: Robert Treat
Reviewed-by: Laurenz Albe, Amit Kapila
Discussion: https://postgr.es/m/CAAaqYe_=7qFSqW7qavvhVy58mmzk1uSQ0RReRiUHyKO5znvr7g@mail.gmail.com

3 months agoMove routines to manipulate WAL into PostgreSQL::Test::Cluster
Michael Paquier [Thu, 16 Jan 2025 00:25:29 +0000 (09:25 +0900)]
Move routines to manipulate WAL into PostgreSQL::Test::Cluster

These facilities were originally in the recovery TAP test
039_end_of_wal.pl.  A follow-up bug fix with a TAP test doing similar
WAL manipulations requires them, and all these had better not be
duplicated due to their complexity.  The routine names are tweaked to
use "wal" more consistently, similarly to the existing "advance_wal".

In v14 and v13, the new routines are moved to PostgresNode.pm.
039_end_of_wal.pl is updated to use the refactored routines, without
changing its coverage.

Reviewed-by: Alexander Kukushkin
Discussion: https://postgr.es/m/CAFh8B=mozC+e1wGJq0H=0O65goZju+6ab5AU7DEWCSUA2OtwDg@mail.gmail.com
Backpatch-through: 13

3 months agoFix cpluspluscheck for "Change gist stratnum function to use CompareType"
Peter Eisentraut [Wed, 15 Jan 2025 22:11:08 +0000 (23:11 +0100)]
Fix cpluspluscheck for "Change gist stratnum function to use CompareType"

Commit 630f9a43cec introduced an enum forward declaration, which
doesn't work in C++.  To fix, just include the header file to get the
type.

3 months agoAdd more general summary to vacuumlazy.c
Melanie Plageman [Wed, 15 Jan 2025 19:16:38 +0000 (14:16 -0500)]
Add more general summary to vacuumlazy.c

Add more comments at the top of vacuumlazy.c on heap relation vacuuming
implementation.

Previously vacuumlazy.c only had details related to dead TID storage.
This commit adds a more general summary to help future developers
understand the heap relation vacuum design and implementation at a high
level.

Reviewed-by: Alena Rybakina, Robert Haas, Andres Freund, Bilal Yavuz
Discussion: https://postgr.es/m/flat/CAAKRu_ZF_KCzZuOrPrOqjGVe8iRVWEAJSpzMgRQs%3D5-v84cXUg%40mail.gmail.com

3 months agoAdd a bit of documentation related to IWYU
Peter Eisentraut [Wed, 15 Jan 2025 17:57:53 +0000 (18:57 +0100)]
Add a bit of documentation related to IWYU

Add some basic information about IWYU to src/tools/pginclude/README.

Discussion: https://www.postgresql.org/message-id/flat/9395d484-eff4-47c2-b276-8e228526c8ae@eisentraut.org

3 months agoIWYU pragmas for catalog headers
Peter Eisentraut [Wed, 15 Jan 2025 17:57:53 +0000 (18:57 +0100)]
IWYU pragmas for catalog headers

Add "IWYU pragma: export" annotations in each catalog header file so
that, for instance, including "catalog/pg_aggregate.h" is considered
acceptable in place of "catalog/pg_aggregate_d.h".  This is very
common and it seems better to silence IWYU about it than trying to fix
this up.

Discussion: https://www.postgresql.org/message-id/flat/9395d484-eff4-47c2-b276-8e228526c8ae@eisentraut.org

3 months agoIWYU widely useful pragmas
Peter Eisentraut [Wed, 15 Jan 2025 17:57:53 +0000 (18:57 +0100)]
IWYU widely useful pragmas

Add various widely useful "IWYU pragma" annotations, such as

- Common header files such as c.h, postgres.h should be "always_keep".

- System headers included in c.h, postgres.h etc. should be considered
  "export".

- Some portability headers such as getopt_long.h should be
  "always_keep", so they are not considered superfluous on some
  platforms.

- Certain system headers included from portability headers should be
  considered "export" because the purpose of the portability header is
  to wrap them.

- Superfluous includes marked as "for backward compatibility" get a
  formal IWYU annotation.

- Generated header included in utils/syscache.h is marked exported.
  This is a very commonly used include and this avoids lots of
  complaints.

Discussion: https://www.postgresql.org/message-id/flat/9395d484-eff4-47c2-b276-8e228526c8ae@eisentraut.org

3 months agopostgres_fdw: SCRAM authentication pass-through
Peter Eisentraut [Wed, 15 Jan 2025 16:55:18 +0000 (17:55 +0100)]
postgres_fdw: SCRAM authentication pass-through

This enables SCRAM authentication for postgres_fdw when connecting to
a foreign server without having to store a plain-text password on user
mapping options.

This is done by saving the SCRAM ClientKey and ServeryKey from the
client authentication and using those instead of the plain-text
password for the server-side SCRAM exchange.  The new foreign-server
or user-mapping option "use_scram_passthrough" enables this.

Co-authored-by: Matheus Alcantara <[email protected]>
Co-authored-by: Peter Eisentraut <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/27b29a35-9b96-46a9-bc1a-914140869dac@gmail.com

3 months agoDowngrade error in object_aclmask_ext() to internal
Peter Eisentraut [Wed, 15 Jan 2025 15:53:53 +0000 (16:53 +0100)]
Downgrade error in object_aclmask_ext() to internal

The "does not exist" error in object_aclmask_ext() was written as
ereport(), suggesting that it is user-facing.  This is problematic:
get_object_class_descr() is meant to be for internal errors only and
does not support translation.

For the has_xxx_privilege functions, the error has not been
user-facing since commit 403ac226ddd.  The remaining users are
pg_database_size() and pg_tablespace_size().  The call stack here is
pretty deep and this dependency is not obvious.  Here we can put in an
explicit existence check with a bespoke error message early in the
function.

Then we can downgrade the error in object_aclmask_ext() to a normal
"cache lookup failed" internal error.

Reviewed-by: Alvaro Herrera <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/da2f8942-be6d-48d0-ac1c-a053370a6b1f@eisentraut.org

3 months agoDowngrade errors in object_ownercheck() to internal
Peter Eisentraut [Wed, 15 Jan 2025 15:53:53 +0000 (16:53 +0100)]
Downgrade errors in object_ownercheck() to internal

The "does not exist" errors in object_ownership() were written as
ereport(), suggesting that they are user-facing.  But no code path
except one can reach this function without first checking that the
object exists.  If this were actually a user-facing error message,
then there would be some problems: get_object_class_descr() is meant
to be for internal errors only and does not support translation.

The one case that can reach this without first checking the object
existence is from be_lo_unlink().  (This makes some sense since large
objects are referred to by their OID directly.)  In this one case, we
can add a line of code to check the object existence explicitly,
consistent with other LO code.

For the rest, downgrade the error messages to elog()s.  The new
message wordings are the same as in DropObjectById().

Reviewed-by: Alvaro Herrera <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/da2f8942-be6d-48d0-ac1c-a053370a6b1f@eisentraut.org

3 months agoDrop warning-free support for Flex 2.5.35
Peter Eisentraut [Wed, 15 Jan 2025 14:35:08 +0000 (15:35 +0100)]
Drop warning-free support for Flex 2.5.35

This removes all the various workarounds for avoiding compiler
warnings with Flex 2.5.35.  Several recent patches have added
additional warnings that would either need to be fixed along the lines
of the existing workarounds, or we decide to no longer care about
this, which we do here.

Flex 2.5.35 is extremely outdated, and you can't even download it
anymore from any of the Flex project sites, so it's nearly impossible
to support.

After this, using Flex 2.5.35 will still work, but the generated code
will produce numerous compiler warnings.

Reviewed-by: Tom Lane <[email protected]>
Discussion: https://www.postgresql.org/message-id/1a204ccd-7ae6-478c-a431-407b5c48ccc6@eisentraut.org

3 months agoChange gist stratnum function to use CompareType
Peter Eisentraut [Wed, 15 Jan 2025 10:28:39 +0000 (11:28 +0100)]
Change gist stratnum function to use CompareType

This changes commit 7406ab623fe in that the gist strategy number
mapping support function is changed to use the CompareType enum as
input, instead of the "well-known" RT*StrategyNumber strategy numbers.

This is a bit cleaner, since you are not dealing with two sets of
strategy numbers.  Also, this will enable us to subsume this system
into a more general system of using CompareType to define operator
semantics across index methods.

Discussion: https://www.postgresql.org/message-id/flat/E72EAA49-354D-4C2E-8EB9-255197F55330@enterprisedb.com

3 months agoRename RowCompareType to CompareType
Peter Eisentraut [Wed, 15 Jan 2025 07:31:46 +0000 (08:31 +0100)]
Rename RowCompareType to CompareType

RowCompareType served as a way to describe the fundamental meaning of
an operator, notionally independent of an operator class (although so
far this was only really supported for btrees).  Its original purpose
was for use inside RowCompareExpr, and it has also found some small
use outside, such as for get_op_btree_interpretation().

We want to expand this now, as a more general way to describe operator
semantics for other index access methods, including gist (to improve
GistTranslateStratnum()) and others not written yet.  To avoid future
confusion, we rename the type to CompareType and the symbols from
ROWCOMPARE_XXX to COMPARE_XXX to reflect their more general purpose.

Reviewed-by: Mark Dilger <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/E72EAA49-354D-4C2E-8EB9-255197F55330@enterprisedb.com

3 months agoAvoid symbol collisions between pqsignal.c and legacy-pqsignal.c.
Tom Lane [Tue, 14 Jan 2025 23:50:24 +0000 (18:50 -0500)]
Avoid symbol collisions between pqsignal.c and legacy-pqsignal.c.

In the name of ABI stability (that is, to avoid a library major
version bump for libpq), libpq still exports a version of pqsignal()
that we no longer want to use ourselves.  However, since that has
the same link name as the function exported by src/port/pqsignal.c,
there is a link ordering dependency determining which version will
actually get used by code that uses libpq as well as libpgport.a.

It now emerges that the wrong version has been used by pgbench and
psql since commit 06843df4a rearranged their link commands.  This
can result in odd failures in pgbench with the -T switch, since its
SIGALRM handler will now not be marked SA_RESTART.  psql may have
some edge-case problems in \watch, too.

Since we don't want to depend on link ordering effects anymore,
let's fix this in the same spirit as b6c7cfac8: use macros to change
the actual link names of the competing functions.  We cannot change
legacy-pqsignal.c's exported name of course, so the victim has to be
src/port/pqsignal.c.

In master, rename its exported name to be pqsignal_fe in frontend or
pqsignal_be in backend.  (We could perhaps have gotten away with using
the same symbol in both cases, but since the FE and BE versions now
work a little differently, it seems advisable to use different names.)

In back branches, rename to pqsignal_fe in frontend but keep it as
pqsignal in backend.  The frontend change could affect third-party
code that is calling pqsignal from libpgport.a or libpgport_shlib.a,
but only if the code is compiled against port.h from a different minor
release than libpgport.  Since we don't support using libpgport as a
shared library, it seems unlikely that there will be such a problem.
I left the backend symbol unchanged to avoid an ABI break for
extensions.  This means that the link ordering hazard still exists
for any extension that links against libpq.  However, none of our own
extensions use both pqsignal() and libpq, and we're not making things
any worse for third-party extensions that do.

Report from Andy Fan, diagnosis by Fujii Masao, patch by me.
Back-patch to all supported branches, as 06843df4a was.

Discussion: https://postgr.es/m/[email protected]

3 months agoSynchronize guc_tables.c categories with vacuum docs categories
Melanie Plageman [Tue, 14 Jan 2025 20:30:13 +0000 (15:30 -0500)]
Synchronize guc_tables.c categories with vacuum docs categories

ca9c6a5680d consolidated most of the vacuum-related GUCs' documentation
into a new subsection. af2317652d5daf8b then enforced this order in
postgresql.conf.sample. This commit reorganizes the GUC groups in
guc_tables.c/h to match the updated ordering in the docs.

Reported-by: Álvaro Herrera
Reviewed-by: Álvaro Herrera, Alena Rybakina
Discussion: https://postgr.es/m/202501132046.m4mcvxxswznu%40alvherre.pgsql

3 months agopsql: Add option to use expanded mode to all list commands.
Dean Rasheed [Tue, 14 Jan 2025 16:29:15 +0000 (16:29 +0000)]
psql: Add option to use expanded mode to all list commands.

This allows "x" to be appended to any psql list-like meta-command,
forcing its output to be displayed in expanded mode. This improves
readability in cases where the output is very wide. For example,
"\dfx+" (or equivalently "\df+x") will produce a list of functions,
with additional details, in expanded mode.

This works with all \d* meta-commands, plus \l, \z, and \lo_list, with
the one exception that the expanded mode option "x" cannot be appended
to "\d" by itself, since "\dx" already means something else.

Dean Rasheed, reviewed by Greg Sabino Mullane.

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

3 months agoecpg: Restore detection of unsupported COPY FROM STDIN.
Fujii Masao [Tue, 14 Jan 2025 16:23:02 +0000 (01:23 +0900)]
ecpg: Restore detection of unsupported COPY FROM STDIN.

The ecpg command includes code to warn about unsupported COPY FROM STDIN
statements in input files. However, since commit 3d009e45bd,
this functionality has been broken due to a bug introduced in that commit,
causing ecpg to fail to detect the statement.

This commit resolves the issue, restoring ecpg's ability to detect
COPY FROM STDIN and issue a warning as intended.

Back-patch to all supported versions.

Author: Ryo Kanbayashi
Reviewed-by: Hayato Kuroda, Tom Lane
Discussion: https://postgr.es/m/CANOn0Ez_t5uDCUEV8c1YORMisJiU5wu681eEVZzgKwOeiKhkqQ@mail.gmail.com

3 months agoConsistently spell "leakproof" without a hyphen.
Dean Rasheed [Tue, 14 Jan 2025 13:50:54 +0000 (13:50 +0000)]
Consistently spell "leakproof" without a hyphen.

The overwhelming majority of places already did this, but a small
handful of places had a hyphen.

Yugo Nagata.

Discussion: https://postgr.es/m/CAEZATCXnnuORE2BoGwHw2zbtVvsPOLhbfVmEk9GxRzK%2Bx3OW-Q%40mail.gmail.com

3 months agopsql: Add leakproof indicator to \df+, \do+, \dAo+, and \dC+ output.
Dean Rasheed [Tue, 14 Jan 2025 13:23:24 +0000 (13:23 +0000)]
psql: Add leakproof indicator to \df+, \do+, \dAo+, and \dC+ output.

This allows users to determine whether particular functions are
leakproof, and whether the underlying functions used by operators and
casts are leakproof. This is useful to determine whether indexes can
be used in queries on security barrier views or tables with row-level
security policies.

Yugo Nagata, reviewed by Erik Wienhold and Dean Rasheed.

Discussion: https://postgr.es/m/20240701220817.483f9b645b95611f8b1f65da%40sranhm.sraoss.co.jp

3 months agoFix catcache invalidation of a list entry that's being built
Heikki Linnakangas [Tue, 14 Jan 2025 12:28:49 +0000 (14:28 +0200)]
Fix catcache invalidation of a list entry that's being built

If a new catalog tuple is inserted that belongs to a catcache list
entry, and cache invalidation happens while the list entry is being
built, the list entry might miss the newly inserted tuple.

To fix, change the way we detect concurrent invalidations while a
catcache entry is being built. Keep a stack of entries that are being
built, and apply cache invalidation to those entries in addition to
the real catcache entries. This is similar to the in-progress list in
relcache.c.

Back-patch to all supported versions.

Reviewed-by: Noah Misch
Discussion: https://www.postgresql.org/message-id/2234dc98-06fe-42ed-b5db-ac17384dc880@iki.fi

3 months agoBump PGSTAT_FILE_FORMAT_ID
Michael Paquier [Tue, 14 Jan 2025 06:17:22 +0000 (15:17 +0900)]
Bump PGSTAT_FILE_FORMAT_ID

Oversight in f92c854cf406, that has changed the definition of
PgStat_BktypeIO, impacting PgStat_IO which is the on-disk data for IO
pgstats data.

3 months agoFix potential integer overflow in bringetbitmap()
Michael Paquier [Tue, 14 Jan 2025 06:12:56 +0000 (15:12 +0900)]
Fix potential integer overflow in bringetbitmap()

This function expects an "int64" as result and stores the number of
pages to add to the index scan bitmap as an "int", multiplying its final
result by 10.  For a relation large enough, this can theoretically
overflow if counting more than (INT32_MAX / 10) pages, knowing that the
number of pages is upper-bounded by MaxBlockNumber.

To avoid the overflow, this commit redefines "totalpages", used to
calculate the result, to be an "int64" rather than an "int".

Reported-by: Evgeniy Gorbanyov
Author: James Hunter
Discussion: https://www.postgresql.org/message-id/07704817-6fa0-460c-b1cf-cd18f7647041@basealt.ru
Backpatch-through: 13

3 months agoMove information about pgstats kinds into its own header pgstat_kind.h
Michael Paquier [Tue, 14 Jan 2025 03:43:07 +0000 (12:43 +0900)]
Move information about pgstats kinds into its own header pgstat_kind.h

This includes all the definitions for the various PGSTAT_KIND_* values,
the range allowed for custom stats kinds and some macros related all
that.

One use-case behind this split is the possibility to use this
information for frontend tools, without having to rely on pgstat.h and a
backend footprint.

Author: Michael Paquier
Reviewed-by: Bertrand Drouvot
Discussion: https://postgr.es/m/[email protected]

3 months agoRemove assertion in pgstat_count_io_op()
Michael Paquier [Tue, 14 Jan 2025 03:19:51 +0000 (12:19 +0900)]
Remove assertion in pgstat_count_io_op()

An equivalent check is done with pgstat_is_ioop_tracked_in_bytes(), so
there is no need for this extra one.  Small cleanup that should have
been included in f92c854cf406.

Author: Nazir Bilal Yavuz
Reviewed-by: Bertrand Drouvot
Discussion: https://postgr.es/m/CAN55FZ0oqxBaaHAEsj=xFqkzE3n5P=3RA1V_igXwL-RV7QRzyw@mail.gmail.com

3 months agoMake pg_stat_io count IOs as bytes instead of blocks for some operations
Michael Paquier [Tue, 14 Jan 2025 03:14:29 +0000 (12:14 +0900)]
Make pg_stat_io count IOs as bytes instead of blocks for some operations

Currently in pg_stat_io view, IOs are counted as blocks of size
BLCKSZ.  There are two limitations with this design:
* The actual number of I/O requests sent to the kernel is lower because
I/O requests may be merged before being sent.  Additionally, it gives
the impression that all I/Os are done in block size, which shadows the
benefits of merging I/O requests.
* Some patches are under work to extend pg_stat_io for the tracking of
operations that may not be linked to the block size.  For example, WAL
read IOs are done in variable bytes and it is not possible to correctly
show these IOs in pg_stat_io view, and we want to keep all this data in
a single system view rather than spread it across multiple relations to
ease monitoring.

WaitReadBuffers() can now be tracked as a single read operation
worth N blocks.  Same for ExtendBufferedRelShared() and
ExtendBufferedRelLocal() for extensions.

Three columns are added to pg_stat_io for reads, writes and extensions
for the byte calculations.  op_bytes, which was always hardcoded to
BLCKSZ, is removed.  IO backend statistics are updated to reflect these
changes.

Bump catalog version.

Author: Nazir Bilal Yavuz
Reviewed-by: Bertrand Drouvot, Melanie Plageman
Discussion: https://postgr.es/m/CAN55FZ0oqxBaaHAEsj=xFqkzE3n5P=3RA1V_igXwL-RV7QRzyw@mail.gmail.com

3 months agoRevert "TupleHashTable: store additional data along with tuple."
Jeff Davis [Mon, 13 Jan 2025 22:14:07 +0000 (14:14 -0800)]
Revert "TupleHashTable: store additional data along with tuple."

This reverts commit e0ece2a981ee9068f50c4423e303836c2585eb02 due to
performance regressions.

Reported-by: David Rowley
3 months agoReorder vacuum GUCs in postgresql.conf.sample to match docs
Melanie Plageman [Mon, 13 Jan 2025 20:21:04 +0000 (15:21 -0500)]
Reorder vacuum GUCs in postgresql.conf.sample to match docs

ca9c6a5680d consolidated most of vacuum-related GUCs' documentation into
a new subsection. It neglected, however, to reorganize
postgresql.conf.sample to match the new order. Do this now.

Reported-by: Álvaro Herrera
Discussion: https://postgr.es/m/202501110902.5banlseavz7c%40alvherre.pgsql

3 months agoAdd BTOPTIONS_PROC comments to nbtree.h.
Peter Geoghegan [Mon, 13 Jan 2025 20:02:14 +0000 (15:02 -0500)]
Add BTOPTIONS_PROC comments to nbtree.h.

Add comments explaining the purpose of B-Tree support function 5 to
nbtree.h for consistency (all other support functions were already
described by nearby comments).

This fixes what was arguably an oversight in commit 911e702077, or in
follow-up doc commit 15cb2bd2 (which documented support function 5 in
btree.sgml, but neglected to add anything to nbtree.h).

3 months agoMove nbtree preprocessing into new .c file.
Peter Geoghegan [Mon, 13 Jan 2025 17:15:00 +0000 (12:15 -0500)]
Move nbtree preprocessing into new .c file.

Quite a bit of code within nbtutils.c is only called during nbtree
preprocessing.  Move that code into a new .c file, nbtpreprocesskeys.c.
Also reorder some of the functions within the new file for clarity.

This commit has no functional impact.  It is strictly mechanical.

Author: Peter Geoghegan <[email protected]>
Suggested-by: Heikki Linnakangas <[email protected]>
Discussion: https://postgr.es/m/CAH2-WznwNn1BDOpWxHBUK1f3Rdw8pO9UCenWXnvT=n9GO8GnLA@mail.gmail.com
Discussion: https://postgr.es/m/86930045-5df5-494a-b4f1-815bc3fbcce0%40iki.fi

3 months agoAdd commit 6e826278f1 to .git-blame-ignore-revs.
Nathan Bossart [Mon, 13 Jan 2025 15:37:32 +0000 (09:37 -0600)]
Add commit 6e826278f1 to .git-blame-ignore-revs.

3 months agoFix pgindent damage
Richard Guo [Mon, 13 Jan 2025 02:27:32 +0000 (11:27 +0900)]
Fix pgindent damage

Oversight in commit e0ece2a98.

3 months agoFix HBA option count
Daniel Gustafsson [Sun, 12 Jan 2025 22:44:39 +0000 (23:44 +0100)]
Fix HBA option count

Commit 27a1f8d108 missed updating the max HBA option count to
account for the new option added.  Fix by bumping the counter
and adjust the relevant comment to match.  Backpatch down to
all supported branches like the erroneous commit.

Reported-by: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/286764.1736697356@sss.pgh.pa.us
Backpatch-through: v13

3 months agoFix JsonExpr deparsing to quote variable names in the PASSING clause.
Dean Rasheed [Sun, 12 Jan 2025 13:35:12 +0000 (13:35 +0000)]
Fix JsonExpr deparsing to quote variable names in the PASSING clause.

When deparsing a JsonExpr, variable names in the PASSING clause were
not quoted. However, since they are parsed as ColLabel tokens, some
variable names require double quotes to ensure that they are properly
interpreted. Fix by using quote_identifier() in the deparsing code.

This oversight was limited to the SQL/JSON query functions
JSON_EXISTS(), JSON_QUERY(), and JSON_VALUE().

Back-patch to v17, where these functions were added.

Dean Rasheed, reviewed by Tom Lane.

Discussion: https://postgr.es/m/CAEZATCXTpAS%3DncfLNTZ7YS6O5puHeLg_SUYAit%2Bcs7wsrd9Msg%40mail.gmail.com

3 months agoFix XMLTABLE() deparsing to quote namespace names if necessary.
Dean Rasheed [Sun, 12 Jan 2025 12:54:32 +0000 (12:54 +0000)]
Fix XMLTABLE() deparsing to quote namespace names if necessary.

When deparsing an XMLTABLE() expression, XML namespace names were not
quoted. However, since they are parsed as ColLabel tokens, some names
require double quotes to ensure that they are properly interpreted.
Fix by using quote_identifier() in the deparsing code.

Back-patch to all supported versions.

Dean Rasheed, reviewed by Tom Lane.

Discussion: https://postgr.es/m/CAEZATCXTpAS%3DncfLNTZ7YS6O5puHeLg_SUYAit%2Bcs7wsrd9Msg%40mail.gmail.com

3 months agoRepair memory leaks in plpython.
Tom Lane [Sat, 11 Jan 2025 16:45:56 +0000 (11:45 -0500)]
Repair memory leaks in plpython.

PLy_spi_execute_plan (PLyPlan.execute) and PLy_cursor_plan
(plpy.cursor) use PLy_output_convert to convert Python values
into Datums that can be passed to the query-to-execute.  But they
failed to pay much attention to its warning that it can leave "cruft
generated along the way" behind.  Repeated use of these methods can
result in a substantial memory leak for the duration of the calling
plpython function.

To fix, make a temporary memory context to invoke PLy_output_convert
in.  This also lets us get rid of the rather fragile code that was
here for retail pfree's of the converted Datums.  Indeed, we don't
need the PLyPlanObject.values field anymore at all, though I left it
in place in the back branches in the name of ABI stability.

Mat Arye and Tom Lane, per report from Mat Arye.  Back-patch to all
supported branches.

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

3 months agoAdd support for NOT ENFORCED in CHECK constraints
Peter Eisentraut [Sat, 11 Jan 2025 09:45:17 +0000 (10:45 +0100)]
Add support for NOT ENFORCED in CHECK constraints

This adds support for the NOT ENFORCED/ENFORCED flag for constraints,
with support for check constraints.

The plan is to eventually support this for foreign key constraints,
where it is typically more useful.

Note that CHECK constraints do not currently support ALTER operations,
so changing the enforceability of an existing constraint isn't
possible without dropping and recreating it.  This could be added
later.

Author: Amul Sul <[email protected]>
Reviewed-by: Peter Eisentraut <[email protected]>
Reviewed-by: jian he <[email protected]>
Tested-by: Triveni N <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/CAAJ_b962c5AcYW9KUt_R_ER5qs3fUGbe4az-SP-vuwPS-w-AGA@mail.gmail.com

3 months agoFix a compiler warning in initStringInfo().
Tatsuo Ishii [Sat, 11 Jan 2025 06:52:37 +0000 (15:52 +0900)]
Fix a compiler warning in initStringInfo().

Fix a compiler warning found by Cfbot. This was caused by commit
bb86e85e442.

3 months agoFix redefinition of type in commit e0ece2a981.
Jeff Davis [Sat, 11 Jan 2025 01:45:27 +0000 (17:45 -0800)]
Fix redefinition of type in commit e0ece2a981.

3 months agoTupleHashTable: store additional data along with tuple.
Jeff Davis [Sat, 11 Jan 2025 01:14:37 +0000 (17:14 -0800)]
TupleHashTable: store additional data along with tuple.

Previously, the caller needed to allocate the memory and the
TupleHashTable would store a pointer to it. That wastes space for the
palloc overhead as well as the size of the pointer itself.

Now, the TupleHashTable relies on the caller to correctly specify the
additionalsize, and allocates that amount of space. The caller can
then request a pointer into that space.

Discussion: https://postgr.es/m/b9cbf0219a9859dc8d240311643ff4362fd9602c[email protected]
Reviewed-by: Heikki Linnakangas
3 months agoMake verify_compact_attribute available in non-assert builds
David Rowley [Sat, 11 Jan 2025 00:45:54 +0000 (13:45 +1300)]
Make verify_compact_attribute available in non-assert builds

6f3820f37 adjusted the assert-enabled validation of the CompactAttribute
to call a new external function to perform the validation.  That commit
made it so the function was only available when building with
USE_ASSERT_CHECKING, and because TupleDescCompactAttr() is a static
inline function, the call to verify_compact_attribute() was compiled
into any extension which uses TupleDescCompactAttr().  This caused issues
for such extensions when loading the assert-enabled extension into
PostgreSQL versions without asserts enabled due to that function being
unavailable in core.

To fix this, make verify_compact_attribute() available unconditionally,
but make it do nothing unless building with USE_ASSERT_CHECKING.

Author: Andrew Kane <[email protected]>
Reviewed-by: David Rowley <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/CAOdR5yHfMEMW00XGo=v1zCVUS6Huq2UehXdvKnwtXPTcZwXhmg@mail.gmail.com

3 months agoAdd new StringInfo APIs to allow callers to specify the buffer size.
Tatsuo Ishii [Fri, 10 Jan 2025 23:02:56 +0000 (08:02 +0900)]
Add new StringInfo APIs to allow callers to specify the buffer size.

Previously StringInfo APIs allocated buffers with fixed initial
allocation size of 1024 bytes. This may be too large and inappropriate
for some callers that can do with smaller memory buffers. To fix this,
introduce new APIs that allow callers to specify initial buffer size.

extern StringInfo makeStringInfoExt(int initsize);
extern void initStringInfoExt(StringInfo str, int initsize);

Existing APIs (makeStringInfo() and initStringInfo()) are changed to
call makeStringInfoExt and initStringInfoExt respectively (via inline
helper functions makeStringInfoInternal and initStringInfoInternal),
with the default buffer size of 1024.

Reviewed-by: Nathan Bossart, David Rowley, Michael Paquier, Gurjeet Singh
Discussion: https://postgr.es/m/20241225.123704.1194662271286702010.ishii%40postgresql.org

3 months agoConsolidate docs for vacuum-related GUCs in new subsection
Melanie Plageman [Fri, 10 Jan 2025 23:20:16 +0000 (18:20 -0500)]
Consolidate docs for vacuum-related GUCs in new subsection

GUCs related to vacuum's freezing behavior were documented in a
subsection of the Client Connection Defaults documentation. These GUCs
don't belong there, as they affect the freezing behavior of all vacuums
-- including autovacuums.

There wasn't a clear alternative location, so this commit makes a new
"Server Configuration" docs subsection, "Vacuuming", with a subsection
for "Freezing". It also moves the "Automatic Vacuuming" subsection and
the docs on GUCs controlling cost-based vacuum delay under the new
"Vacuuming" subsection.

The other vacuum-related GUCs under the "Resource Consumption"
subsection have been left in their current location, as they seem to fit
there.

The GUCs' documentation was largely lifted and shifted. The only
modification made was the addition of a few missing <literal> tags.

Reviewed-by: Daniel Gustafsson <[email protected]>
Discussion: https://postgr.es/m/flat/CAAKRu_aQUOaMYrcjNuXeSkJtaX9oRUzKP57bsYbC0gVVWS%2BcbA%40mail.gmail.com

3 months agoFix missing ldapscheme option in pg_hba_file_rules()
Daniel Gustafsson [Fri, 10 Jan 2025 21:02:58 +0000 (22:02 +0100)]
Fix missing ldapscheme option in pg_hba_file_rules()

The ldapscheme option was missed when inspecing the HbaLine for
assembling rows for the pg_hba_file_rules function.  Backpatch
to all supported versions.

Author: Laurenz Albe <[email protected]>
Reported-by: Laurenz Albe <[email protected]>
Reviewed-by: Daniel Gustafsson <[email protected]>
Bug: 18769
Discussion: https://postgr.es/m/18769-dd8610cbc0405172@postgresql.org
Backpatch-through: v13

3 months agoFix obsolete nbtree README left link remarks.
Peter Geoghegan [Fri, 10 Jan 2025 20:42:17 +0000 (15:42 -0500)]
Fix obsolete nbtree README left link remarks.

Oversight in commit 1bd4bc85, which made nbtree backwards scans operate
off of a copy of each page's left link as of the time of its call to
_bt_readpage.

3 months agoUse a non-locking initial test in TAS_SPIN on AArch64.
Nathan Bossart [Fri, 10 Jan 2025 19:18:04 +0000 (13:18 -0600)]
Use a non-locking initial test in TAS_SPIN on AArch64.

Our testing showed that this is helpful at sufficiently high
contention levels and doesn't hurt performance on smaller machines.
The new TAS_SPIN macro for AArch64 is identical to the ones added
for PPC and x86_64 (see commits bc2a050d40 and b03d196be0).

Reported-by: Salvatore Dipietro
Reviewed-by: Jingtang Zhang, Andres Freund
Tested-by: Tom Lane
Discussion: https://postgr.es/m/ZxgDEb_VpWyNZKB_%40nathan

3 months agopostmaster: Rename some shutdown related PMState phase names
Andres Freund [Fri, 10 Jan 2025 16:08:17 +0000 (11:08 -0500)]
postmaster: Rename some shutdown related PMState phase names

The previous names weren't particularly clear. Future patches will add more
shutdown phases, making it even more important to have understandable shutdown
phases.

Suggested-by: Heikki Linnakangas <[email protected]>
Reviewed-by: Nazir Bilal Yavuz <[email protected]>
Discussion: https://postgr.es/m/d2cd8fd3-396a-4390-8f0b-74be65e72899@iki.fi

3 months agopostmaster: Make btmask_add() variadic
Andres Freund [Fri, 10 Jan 2025 16:08:17 +0000 (11:08 -0500)]
postmaster: Make btmask_add() variadic

Suggested-by: Heikki Linnakangas <[email protected]>
Discussion: https://postgr.es/m/d2cd8fd3-396a-4390-8f0b-74be65e72899@iki.fi

3 months agopostmaster: Introduce variadic btmask_all_except()
Andres Freund [Fri, 10 Jan 2025 16:08:17 +0000 (11:08 -0500)]
postmaster: Introduce variadic btmask_all_except()

Upcoming patches would otherwise need btmask_all_except3().

Reviewed-by: Heikki Linnakangas <[email protected]>
Discussion: https://postgr.es/m/w3z6w3g4aovivs735nk4pzjhmegntecesm3kktpebchegm5o53@aonnq2kn27xi

3 months agopostmaster: Improve logging of signals sent by postmaster
Andres Freund [Fri, 10 Jan 2025 16:08:17 +0000 (11:08 -0500)]
postmaster: Improve logging of signals sent by postmaster

Previously many, in some cases important, signals we never logged. In other
cases the signal name was only included numerically.

As part of this, change the debug log level the signal is logged at to DEBUG3,
previously some where DEBUG2, some DEBUG4.

Also move from direct use of kill() to signal the av launcher to
signal_child(). There doesn't seem to be a reason for directly using kill().

Reviewed-by: Heikki Linnakangas <[email protected]>
Reviewed-by: Bertrand Drouvot <[email protected]>
Reviewed-by: Nazir Bilal Yavuz <[email protected]>
Discussion: https://postgr.es/m/kgng5nrvnlv335evmsuvpnh354rw7qyazl73kdysev2cr2v5zu@m3cfzxicm5kp

3 months agopostmaster: Update pmState via a wrapper function
Andres Freund [Fri, 10 Jan 2025 16:08:17 +0000 (11:08 -0500)]
postmaster: Update pmState via a wrapper function

This makes logging of state changes easier - state transitions are now logged
at DEBUG1. Without that logging it was surprisingly hard to understand the
current state of the system while debugging.

Reviewed-by: Heikki Linnakangas <[email protected]>
Reviewed-by: Bertrand Drouvot <[email protected]>
Reviewed-by: Nazir Bilal Yavuz <[email protected]>
Discussion: https://postgr.es/m/kgng5nrvnlv335evmsuvpnh354rw7qyazl73kdysev2cr2v5zu@m3cfzxicm5kp

3 months agoAdjust signature of cluster_rel() and its subroutines
Álvaro Herrera [Fri, 10 Jan 2025 12:09:38 +0000 (13:09 +0100)]
Adjust signature of cluster_rel() and its subroutines

cluster_rel() receives the OID of the relation to process, which it
opens and locks; but then its subroutine copy_table_data() also receives
the relation OID and opens it by itself.  This is a bit wasteful.  It's
better to have cluster_rel() receive the relation already open, and pass
it down to its subroutines as necessary; then cluster_rel closes the rel
before returning.  This simplifies things.

But a better motivation to make this change is that a future command to
do logical-decoding-based "concurrent VACUUM FULL" will need to release
all locks on the relation (and possibly on the clustering index) at some
point.  Since it makes little sense to keep the relation reference
without the lock, the cluster_rel() function will also close it (and
the index).  With this arrangement, neither the function nor its
subroutines need open extra references, which, again, makes things simpler.

Author: Antonin Houska <[email protected]>
Discussion: https://postgr.es/m/82651.1720540558@antos

3 months agoFix UNION planner datatype issue
David Rowley [Fri, 10 Jan 2025 01:30:25 +0000 (14:30 +1300)]
Fix UNION planner datatype issue

66c0185a3 gave the planner the ability to have union child queries
provide the union planner with pre-sorted input so that UNION queries
could be more efficiently implemented using Merge Append.

That commit overlooked checking that the UNION target list and the union
child target list's types all match.  In some corner cases, this could
result in the planner producing sorts using the sort operator of the
top-level UNION's target list type rather than of the union child's
target list's type.  The implications of this range from silently
working correctly, despite using the wrong sort operator all the way up
to a segmentation fault.

Here we fix by adjusting the planner so it makes no attempt to have the
subquery produce pre-sorted results when the data type of the UNION
target list and the types from the subquery target list don't match
exactly.

Backpatch to 17, where 66c0185a3 was introduced.

Reported-by: Jason Smith <[email protected]>
Diagnosed-by: Tom Lane <[email protected]>
Bug: 18764
Discussion: https://postgr.es/m/18764-63ad667ea26e877a%40postgresql.org
Backpatch-through: 17

3 months agoMerge pgstat_count_io_op_n() and pgstat_count_io_op()
Michael Paquier [Fri, 10 Jan 2025 00:57:27 +0000 (09:57 +0900)]
Merge pgstat_count_io_op_n() and pgstat_count_io_op()

The pgstat_count_io_op() function, which counts a single I/O operation,
wraps pgstat_count_io_op_n() with a counter value of 1.  The latter is
declared in pgstat.h and used nowhere in the code, so let's remove it in
favor of the former.

This change makes also the code more symmetric with
pgstat_count_io_op_time(), that already uses a similar set of arguments,
except that it counts also the I/O time.  This will ease a bit the
integration of a follow-up patch that adds byte-level tracking in
pg_stat_io for some of its attributes, lifting the current restriction
based on BLCKSZ as all I/O operations are assumed to be block-based.

Author: Nazir Bilal Yavuz
Reviewed-by: Bertrand Drouvot
Discussion: https://postgr.es/m/CAN55FZ32ze812=yjyZg1QeXhKvACUM_Nu0_gyPQcUKKuVHL5xA@mail.gmail.com

3 months agoRefactor some code related to backend statistics
Michael Paquier [Fri, 10 Jan 2025 00:00:48 +0000 (09:00 +0900)]
Refactor some code related to backend statistics

This commit changes the way pending backend statistics are tracked by
moving them into a new structure called PgStat_BackendPending, removing
PgStat_BackendPendingIO.  PgStat_BackendPending currently only includes
PgStat_PendingIO for the pending I/O stats.

pgstat_flush_backend() is extended with a "flags" argument to control
which parts of the stats of a backend should be flushed.

With this refactoring, it becomes easier to plug into backend statistics
more data.  A patch to add information related to WAL in this stats kind
is under discussion.

Author: Bertrand Drouvot
Discussion: https://postgr.es/m/Z3zqc4o09dM/[email protected]

3 months agoFix an ALTER GROUP ... DROP USER error message.
Nathan Bossart [Thu, 9 Jan 2025 23:10:13 +0000 (17:10 -0600)]
Fix an ALTER GROUP ... DROP USER error message.

This error message stated the privileges required to add a member
to a group even if the user was trying to drop a member:

postgres=> alter group a drop user b;
ERROR:  permission denied to alter role
DETAIL:  Only roles with the ADMIN option on role "a" may add members.

Since the required privileges for both operations are the same, we
can fix this by modifying the message to mention both adding and
dropping members:

postgres=> alter group a drop user b;
ERROR:  permission denied to alter role
DETAIL:  Only roles with the ADMIN option on role "a" may add or drop members.

Author: ChangAo Chen
Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/tencent_FAA0D00E3514AAF0BBB6322542A6094FEF05%40qq.com
Backpatch-through: 16

3 months agoUse @extschema:name@ notation in contrib transform modules.
Tom Lane [Thu, 9 Jan 2025 20:16:56 +0000 (15:16 -0500)]
Use @extschema:name@ notation in contrib transform modules.

Harden hstore_plperl, hstore_plpython, and ltree_plpython
against search-path-based attacks by using @extschema:name@
notation to refer to the underlying hstore or ltree data type.

This allows removal of the previous documentation warning
suggesting that they must be installed in the same schema as
the underlying data type.  In passing, also improve a para in
extend.sgml to suggest using @extschema:name@ for such purposes.

Discussion: https://postgr.es/m/692480.1736021695@sss.pgh.pa.us

3 months agoSimplify signature of RewriteTable
Álvaro Herrera [Thu, 9 Jan 2025 13:17:12 +0000 (14:17 +0100)]
Simplify signature of RewriteTable

This function doesn't need the lockmode to be passed: it was being used
to lock the new heap, but that's bogus, because the only caller has
already obtained the appropriate lock on the new heap (which is
unimportant anyway, because the relation's creation is not yet committed
and so no other session can see it).

Noticed while reviewed Antonin Houska's patch to add VACUUM FULL
CONCURRENTLY.

3 months agodoc: Clarify synchronous_standby_names parameter.
Fujii Masao [Thu, 9 Jan 2025 12:04:49 +0000 (21:04 +0900)]
doc: Clarify synchronous_standby_names parameter.

The synchronous_standby_names GUC allows specifying num_sync,
the number of synchronous standbys transactions must wait for
replies from. This value must be an integer greater than zero.
This commit updates the documentation to clarify this requirement.

Reported-by: Asphator <[email protected]>
Discussion: https://postgr.es/m/18663-b02f75cb919f1b60@postgresql.org

3 months agoFix SLRU bank selection code
Álvaro Herrera [Thu, 9 Jan 2025 06:33:52 +0000 (07:33 +0100)]
Fix SLRU bank selection code

The originally submitted code (using bit masking) was correct when the
number of slots was restricted to be a power of two -- but that
limitation was removed during development that led to commit
53c2a97a9266, which made the bank selection code incorrect.  This led to
always using a smaller number of banks than available.  Change said code
to use integer modulo instead, which works correctly with an arbitrary
number of banks.

It's likely that we could improve on this to avoid runtime use of
integer division.  But with this change we're, at least, not wasting
memory on unused banks, and more banks mean less contention, which is
likely to have a much higher performance impact than a single
instruction's latency.

Author: Yura Sokolov <[email protected]>
Reviewed-by: Andrey Borodin <[email protected]>
Discussion: https://postgr.es/m/9444dc46-ca47-43ed-9058-89c456316306@postgrespro.ru

3 months agoFix off_t overflow in pg_basebackup on Windows.
Thomas Munro [Thu, 9 Jan 2025 00:17:36 +0000 (13:17 +1300)]
Fix off_t overflow in pg_basebackup on Windows.

walmethods.c used off_t to navigate around a pg_wal.tar file that could
exceed 2GB, which doesn't work on Windows and would fail with misleading
errors.  Use pgoff_t instead.

Back-patch to all supported branches.

Author: Davinder Singh <[email protected]>
Reported-by: Jakub Wartak <[email protected]>
Discussion: https://postgr.es/m/CAKZiRmyM4YnokK6Oenw5JKwAQ3rhP0YTz2T-tiw5dAQjGRXE3Q%40mail.gmail.com

3 months agoProvide 64-bit ftruncate() and lseek() on Windows.
Thomas Munro [Wed, 8 Jan 2025 23:10:26 +0000 (12:10 +1300)]
Provide 64-bit ftruncate() and lseek() on Windows.

Change our ftruncate() macro to use the 64-bit variant of chsize(), and
add a new macro to redirect lseek() to _lseeki64().

Back-patch to all supported releases, in preparation for a bug fix.

Tested-by: Davinder Singh <[email protected]>
Discussion: https://postgr.es/m/CAKZiRmyM4YnokK6Oenw5JKwAQ3rhP0YTz2T-tiw5dAQjGRXE3Q%40mail.gmail.com

3 months agoFix duplicate typedef from commit a2f17f004d.
Jeff Davis [Wed, 8 Jan 2025 23:25:05 +0000 (15:25 -0800)]
Fix duplicate typedef from commit a2f17f004d.

Reported-by: Thomas Munro
3 months agoControl collation behavior with a method table.
Jeff Davis [Wed, 8 Jan 2025 22:26:33 +0000 (14:26 -0800)]
Control collation behavior with a method table.

Previously, behavior branched based on the provider. A method table is
less error-prone and more flexible.

The ctype behavior will be addressed in an upcoming commit.

Reviewed-by: Andreas Karlsson
Discussion: https://postgr.es/m/2830211e1b6e6a2e26d845780b03e125281ea17b.camel%40j-davis.com

3 months agoMove code for collation version into provider-specific files.
Jeff Davis [Wed, 8 Jan 2025 21:54:07 +0000 (13:54 -0800)]
Move code for collation version into provider-specific files.

Author: Andreas Karlsson
Discussion: https://postgr.es/m/4548a168-62cd-457b-8d06-9ba7b985c477%40proxel.se

3 months agoDisallow NAMEDTUPLESTORE RTEs in stored views, rules, etc.
Tom Lane [Wed, 8 Jan 2025 21:35:54 +0000 (16:35 -0500)]
Disallow NAMEDTUPLESTORE RTEs in stored views, rules, etc.

A named tuplestore is necessarily a transient object, so it makes
no sense to reference one in a persistent object such as a view.
We didn't previously prevent that, with the result that if you
tried you would get some weird failure about how the executor
couldn't find the tuplestore.

We can mechanize a check for this case cheaply by making dependency
extraction complain if it comes across such an RTE.  This is a
plausible way of dealing with it since part of the problem is that we
have no way to make a pg_depend representation of a named tuplestore.

Report and fix by Yugo Nagata.  Although this is an old problem,
it's a very weird corner case and there have been no reports from
end users.  So it seems sufficient to fix it in master.

Discussion: https://postgr.es/m/20240726160714.e74d0db579f2c017e1ca0b7e@sraoss.co.jp

3 months agoSet exit status for pgindent if pg_bsd_indent fails
Andrew Dunstan [Wed, 8 Jan 2025 15:56:12 +0000 (10:56 -0500)]
Set exit status for pgindent if pg_bsd_indent fails

Also document the exit codes in the script.

The new exit code is 3, and is not overridden by the exit code set in
--check mode.

Author: Ashutosh Bapat

Discussion: https://postgr.es/m/CAExHW5sPRSiFeLdP-u1Fa5ba7YS2f0gvLjmKOobopKadJwQ_GQ@mail.gmail.com

3 months agoplpgsql: pure parser and reentrant scanner
Peter Eisentraut [Wed, 8 Jan 2025 08:20:01 +0000 (09:20 +0100)]
plpgsql: pure parser and reentrant scanner

The plpgsql scanner is a wrapper around the core scanner, which
already uses the flex %option reentrant.  This patch only pushes up a
few levels the place where the scanner handle is allocated.  Before,
it was allocated in pl_scanner.c in a global variable, so to the
outside the scanner was not reentrant.  Now, it is allocated in
pl_comp.c and is passed as an argument to yyparse(), similar to how it
is handled in other reentrant scanners.

Also use flex yyextra to handle context information, instead of global
variables.  Again, this uses the existing yyextra support in the core
scanner.  This complements the other changes to make the scanner
reentrant.

The bison option %pure-parser is used to make the generated parser
pure.  This happens in the usual way, since plpgsql has its own bison
parser definition.

Reviewed-by: Heikki Linnakangas <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/eb6faeac-2a8a-4b69-9189-c33c520e5b7b@eisentraut.org

3 months agoRemove useless function declaration
Peter Eisentraut [Wed, 8 Jan 2025 07:21:05 +0000 (08:21 +0100)]
Remove useless function declaration

This function apparently never existed.

3 months agopg_freespacemap: Fix declaration of pg_freespace(regclass)
Michael Paquier [Wed, 8 Jan 2025 04:16:43 +0000 (13:16 +0900)]
pg_freespacemap: Fix declaration of pg_freespace(regclass)

This function called generate_series() without enforcing its input
argument types, making possible for an attacker to catch this call, by
defining for example a generate_series(int,bigint).

The internals of pg_freespace(regclass) are changed to force the use of
bigint for the inputs of generate_series().  A more consistent style is
applied for all its hardcoded values, while on it.

Issue introduced in 3f323eba89fb.

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

3 months agoExecInitAgg: update aggstate->numaggs and ->numtrans earlier.
Jeff Davis [Tue, 7 Jan 2025 23:13:50 +0000 (15:13 -0800)]
ExecInitAgg: update aggstate->numaggs and ->numtrans earlier.

Functions hash_agg_entry_size() and build_hash_tables() make use of
those values for memory size estimates.

Because this change only affects memory estimates, don't backpatch.

Discussion: https://postgr.es/m/7530bd8783b1a78d53a3c70383e38d8da0a5ffe5.camel%40j-davis.com

3 months agonodeSetOp.c: missing additionalsize for BuildTupleHashTable().
Jeff Davis [Tue, 7 Jan 2025 22:55:53 +0000 (14:55 -0800)]
nodeSetOp.c: missing additionalsize for BuildTupleHashTable().

Provide additionalsize argument, which can affect the calculations for
'nbuckets'. Also, future work for Hash Aggregation will rely on the
correct additionalsize.

Discussion: https://postgr.es/m/7530bd8783b1a78d53a3c70383e38d8da0a5ffe5.camel%40j-davis.com

3 months agoRemove unused TupleHashTableData->entrysize.
Jeff Davis [Tue, 7 Jan 2025 22:49:18 +0000 (14:49 -0800)]
Remove unused TupleHashTableData->entrysize.

Discussion: https://postgr.es/m/7530bd8783b1a78d53a3c70383e38d8da0a5ffe5.camel%40j-davis.com

3 months agoAdd missing typedefs.list entry for AggStatePerGroupData.
Jeff Davis [Tue, 7 Jan 2025 22:32:37 +0000 (14:32 -0800)]
Add missing typedefs.list entry for AggStatePerGroupData.

Discussion: https://postgr.es/m/7530bd8783b1a78d53a3c70383e38d8da0a5ffe5.camel%40j-davis.com

3 months agoUse PqMsg_* macros in postgres.c.
Nathan Bossart [Tue, 7 Jan 2025 21:34:19 +0000 (15:34 -0600)]
Use PqMsg_* macros in postgres.c.

Commit f4b54e1ed9, which introduced macros for protocol characters,
missed updating a couple of places in postgres.c.

Author: Dave Cramer
Reviewed-by: Fabrízio de Royes Mello
Discussion: https://postgr.es/m/CADK3HHJUVBPoVOmFesPB-fN8_dYt%2BQELV2UB6jxOW2Z40qF-qw%40mail.gmail.com
Backpatch-through: 17