postgresql.git
8 months agoExtend mul_var_short() to 5 and 6-digit inputs.
Dean Rasheed [Thu, 15 Aug 2024 09:33:12 +0000 (10:33 +0100)]
Extend mul_var_short() to 5 and 6-digit inputs.

Commit ca481d3c9a introduced mul_var_short(), which is used by
mul_var() whenever the shorter input has 1-4 NBASE digits and the
exact product is requested. As speculated on in that commit, it can be
extended to work for more digits in the shorter input. This commit
extends it up to 6 NBASE digits (up to 24 decimal digits), for which
it also gives a significant speedup. This covers more cases likely to
occur in real-world queries, for which using base-NBASE^2 arithmetic
provides little benefit.

To avoid code bloat and duplication, refactor it a bit using macros
and exploiting the fact that some portions of the code are shared
between the different cases.

Dean Rasheed, reviewed by Joel Jacobson.

Discussion: https://postgr.es/m/9d8a4a42-c354-41f3-bbf3-199e1957db97%40app.fastmail.com

8 months agoVariable renaming in dbcommands.c
Peter Eisentraut [Thu, 15 Aug 2024 05:08:12 +0000 (07:08 +0200)]
Variable renaming in dbcommands.c

There were several sets of very similar local variable names, such as
"downer" and "dbowner", which was very confusing and error-prone.
Rename the former to "ownerEl" and so on, similar to collationcmds.c
and typecmds.c.

Reviewed-by: Daniel Gustafsson <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/e5bce225-ee04-40c7-a280-ea7214318048%40eisentraut.org

8 months agoFix doc typo: unicode_assigned() return type.
Jeff Davis [Thu, 15 Aug 2024 02:05:39 +0000 (19:05 -0700)]
Fix doc typo: unicode_assigned() return type.

Reported-by: Hironobu SUZUKI
Discussion: https://postgr.es/m/5dd88820-bb00-4b90-904b-738ea2e4ee2e@interdb.jp
Backpatch-through: 17

8 months agoImprove ALTER PUBLICATION validation and error messages
David Rowley [Thu, 15 Aug 2024 01:10:25 +0000 (13:10 +1200)]
Improve ALTER PUBLICATION validation and error messages

Attempting to add a system column for a table to an existing publication
would result in the not very intuitive error message of:

ERROR:  negative bitmapset member not allowed

Here we improve that to have it display the same error message as a user
would see if they tried adding a system column for a table when adding
it to the publication in the first place.

Doing this requires making the function which validates the list of
columns an extern function.  The signature of the static function wasn't
an ideal external API as it made the code more complex than it needed to be.
Here we adjust the function to have it populate a Bitmapset of attribute
numbers.  Doing it this way allows code simplification.

There was no particular bug here other than the weird error message, so
no backpatch.

Bug: #18558
Reported-by: Alexander Lakhin <[email protected]>
Author: Peter Smith, David Rowley
Discussion: https://postgr.es/m/18558-411bc81b03592125@postgresql.org

8 months agoAdd a couple of recent commits to .git-blame-ignore-revs.
Nathan Bossart [Wed, 14 Aug 2024 19:25:54 +0000 (14:25 -0500)]
Add a couple of recent commits to .git-blame-ignore-revs.

8 months agolibpq: Trace responses to SSLRequest and GSSENCRequest
Alvaro Herrera [Wed, 14 Aug 2024 18:53:55 +0000 (14:53 -0400)]
libpq: Trace responses to SSLRequest and GSSENCRequest

Since these are single bytes instead of v2 or v3 messages they need
custom tracing logic.  These "messages" don't even have official names
in the protocol specification, so I (Jelte) called them SSLResponse and
GSSENCResponse here.

Author: Jelte Fennema-Nio <[email protected]>
Discussion: https://postgr.es/m/CAGECzQSoPHtZ4xe0raJ6FYSEiPPS+YWXBhOGo+Y1YecLgknF3g@mail.gmail.com

8 months agoApply PGDLLIMPORT markings to some GUC variables
Peter Eisentraut [Wed, 14 Aug 2024 09:36:12 +0000 (11:36 +0200)]
Apply PGDLLIMPORT markings to some GUC variables

According to the commit message in 8ec569479, we must have all variables
in header files marked with PGDLLIMPORT. In commit d3cc5ffe81f6 some
variables were moved from launch_backend.c file to several header files.

This adds PGDLLIMPORT to moved variables.

Author: Sofia Kopikova <[email protected]>
Reviewed-by: Robert Haas <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/e0b17014-5319-4dd6-91cd-93d9c8fc9539%40postgrespro.ru

8 months agoRemove TRACE_SORT macro
Peter Eisentraut [Wed, 14 Aug 2024 06:02:32 +0000 (08:02 +0200)]
Remove TRACE_SORT macro

The TRACE_SORT macro guarded the availability of the trace_sort GUC
setting.  But it has been enabled by default ever since it was
introduced in PostgreSQL 8.1, and there have been no reports that
someone wanted to disable it.  So just remove the macro to simplify
things.  (For the avoidance of doubt: The trace_sort GUC is still
there.  This only removes the rarely-used macro guarding it.)

Reviewed-by: Heikki Linnakangas <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/be5f7162-7c1d-44e3-9a78-74dcaa6529f2%40eisentraut.org

8 months agoHarmonize MinGW CODESET lookup with MSVC.
Thomas Munro [Wed, 14 Aug 2024 03:02:12 +0000 (15:02 +1200)]
Harmonize MinGW CODESET lookup with MSVC.

Historically, MinGW environments lacked some Windows API calls, so we
took a different code path in win32_langinfo().  Somehow, the code
change in commit 35eeea62 (removing setlocale() calls) caused one
particular 001_initdb.pl test to fail on MinGW + ICU builds, because
pg_import_system_collations() found no collations.  It might take a
MinGW user to discover the exact reason.

Updating that function to use the same code as MSVC seems to fix that
test, so lets do that.  (There are plenty more places that test for MSVC
unnecessarily, to be investigated later.)

While here, also rename the helper function win32_langinfo() to
win32_get_codeset(), to explain what it does less confusingly; it's not
really a general langinfo() substitute.

Noticed by triggering the optional MinGW CI task; no build farm animals
failed.

Discussion: https://postgr.es/m/CA%2BhUKGKBWfhXQ3J%2B2Lj5PhKvQnGD%3DsywA0XQcb7boTCf%3DerVLg%40mail.gmail.com

8 months agoAdd resource statistics reporting to ANALYZE VERBOSE.
Masahiko Sawada [Wed, 14 Aug 2024 02:23:56 +0000 (19:23 -0700)]
Add resource statistics reporting to ANALYZE VERBOSE.

Previously, log_autovacuum_min_duration utilized dedicated code for
logging resource statistics, such as system and buffer usage during
autoanalyze. However, this logging functionality was not utilized by
ANALYZE VERBOSE.

This commit adds resource statistics reporting to ANALYZE VERBOSE by
reusing the same logging code as autoanalyze.

Author: Anthonin Bonnefoy
Reviewed-by: Masahiko Sawada
Discussion: https://postgr.es/m/CAO6_Xqr__kTTCLkftqS0qSCm-J7_xbRG3Ge2rWhucxQJMJhcRA%40mail.gmail.com

8 months agoUse pgBufferUsage for buffer usage tracking in analyze.
Masahiko Sawada [Wed, 14 Aug 2024 01:49:45 +0000 (18:49 -0700)]
Use pgBufferUsage for buffer usage tracking in analyze.

Previously, (auto)analyze used global variables VacuumPageHit,
VacuumPageMiss, and VacuumPageDirty to track buffer usage. However,
pgBufferUsage provides a more generic way to track buffer usage with
support functions.

This change replaces those global variables with pgBufferUsage in
analyze. Since analyze was the sole user of those variables, it
removes their declarations. Vacuum previously used those variables but
replaced them with pgBufferUsage as part of a bug fix, commit
5cd72cc0c.

Additionally, it adjusts the buffer usage message in both vacuum and
analyze for better consistency.

Author: Anthonin Bonnefoy
Reviewed-by: Masahiko Sawada, Michael Paquier
Discussion: https://postgr.es/m/CAO6_Xqr__kTTCLkftqS0qSCm-J7_xbRG3Ge2rWhucxQJMJhcRA%40mail.gmail.com

8 months agoInclude <xlocale.h> for macOS, take II.
Thomas Munro [Tue, 13 Aug 2024 11:42:58 +0000 (23:42 +1200)]
Include <xlocale.h> for macOS, take II.

Fix typo in macro name.

Discussion: https://postgr.es/m/CA%2BhUKG%2Bk-o3N_SyNJNJpAcdtMo_HheN30miAeXehk9yw%3D9WYzA%40mail.gmail.com

8 months agoInclude <xlocale.h> for older macOS.
Thomas Munro [Tue, 13 Aug 2024 11:02:05 +0000 (23:02 +1200)]
Include <xlocale.h> for older macOS.

Commit 35eeea62 forgot to include <xlocale.h> when using locale_t
(which didn't seem to be required on newer Apple SDK as used by CI,
hence mistake).  Let's see if this fixes build farm animals longfin and
sifika.

8 months agoUse thread-safe nl_langinfo_l(), not nl_langinfo().
Thomas Munro [Tue, 13 Aug 2024 10:27:16 +0000 (22:27 +1200)]
Use thread-safe nl_langinfo_l(), not nl_langinfo().

This gets rid of some setlocale() calls.  The remaining call to
setlocale() in pg_get_encoding_from_locale() is a query of the name
of the current locale when none was provided (in a multi-threaded future
that would need more work).

All known non-Windows targets have nl_langinfo_l(), from POSIX 2008, and
for Windows we already do something thread-safe.

Reviewed-by: Heikki Linnakangas <[email protected]>
Discussion: https://postgr.es/m/CA%2BhUKGJqVe0%2BPv9dvC9dSums_PXxGo9SWcxYAMBguWJUGbWz-A%40mail.gmail.com

8 months agoAll POSIX systems have langinfo.h and CODESET.
Thomas Munro [Tue, 13 Aug 2024 10:13:52 +0000 (22:13 +1200)]
All POSIX systems have langinfo.h and CODESET.

We don't need configure probes for HAVE_LANGINFO_H (it is implied by
!WIN32), and we don't need to consider systems that have it but don't
define CODESET (that was for OpenBSD in commit 81cca218, but it has now
had it for 19 years).

Reviewed-by: Heikki Linnakangas <[email protected]>
Discussion: https://postgr.es/m/CA%2BhUKGJqVe0%2BPv9dvC9dSums_PXxGo9SWcxYAMBguWJUGbWz-A%40mail.gmail.com

8 months agoUse errmsg_internal for debug messages
Peter Eisentraut [Tue, 13 Aug 2024 08:01:49 +0000 (10:01 +0200)]
Use errmsg_internal for debug messages

Some newer code was applying this inconsistently.

8 months agoRename C23 keyword
Peter Eisentraut [Tue, 13 Aug 2024 04:15:28 +0000 (06:15 +0200)]
Rename C23 keyword

constexpr is a keyword in C23.  Rename a conflicting identifier for
future-proofing.

Reviewed-by: Robert Haas <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/08abc832-1384-4aca-a535-1a79765b565e%40eisentraut.org

8 months agolibpq: Trace frontend authentication challenges
Alvaro Herrera [Mon, 12 Aug 2024 23:12:54 +0000 (19:12 -0400)]
libpq: Trace frontend authentication challenges

If tracing was enabled during connection startup, these messages would
previously be listed in the trace output as something like this:

F 54 Unknown message: 70
mismatched message length: consumed 4, expected 54

With this commit their type and contents are now correctly listed:

F 36 StartupMessage  3 0 "user" "foo" "database" "alvherre"
F 54 SASLInitialResponse  "SCRAM-SHA-256" 32 'n,,n=,r=nq5zEPR/VREHEpOAZzH8Rujm'
F 108 SASLResponse  'c=biws,r=nq5zEPR/VREHEpOAZzH8RujmVtWZDQ8glcrvy9OMNw7ZqFUn,p=BBwAKe0WjSvigB6RsmmArAC+hwucLeuwJrR5C/HQD5M='

Author: Jelte Fennema-Nio <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
Discussion: https://postgr.es/m/CAGECzQSoPHtZ4xe0raJ6FYSEiPPS+YWXBhOGo+Y1YecLgknF3g@mail.gmail.com

8 months agoFix nls.mk to reflect astreamer files relocation
Alvaro Herrera [Mon, 12 Aug 2024 22:42:18 +0000 (18:42 -0400)]
Fix nls.mk to reflect astreamer files relocation

In the recent commit f80b09bac8, astreamer files were moved to another
directory, but this change was not reflected in nls.mk.  This commit
corrects that oversight.

Author: Kyotaro Horiguchi <[email protected]>
Discussion: https://postgr.es/m/20240806.102123.648178476296575604[email protected]

8 months agoFix creation of partition descriptor during concurrent detach+drop
Alvaro Herrera [Mon, 12 Aug 2024 22:17:56 +0000 (18:17 -0400)]
Fix creation of partition descriptor during concurrent detach+drop

If a partition undergoes DETACH CONCURRENTLY immediately followed by
DROP, this could cause a problem for a concurrent transaction
recomputing the partition descriptor when running a prepared statement,
because it tries to dereference a pointer to a tuple that's not found in
a catalog scan.

The existing retry logic added in commit dbca3469ebf8 is sufficient to
cope with the overall problem, provided we don't try to dereference a
non-existant heap tuple.

Arguably, the code in RelationBuildPartitionDesc() has been wrong all
along, since no check was added in commit 898e5e3290a7 against receiving
a NULL tuple from the catalog scan; that bug has only become
user-visible with DETACH CONCURRENTLY which was added in branch 14.
Therefore, even though there's no known mechanism to cause a crash
because of this, backpatch the addition of such a check to all supported
branches.  In branches prior to 14, this would cause the code to fail
with a "missing relpartbound for relation XYZ" error instead of
crashing; that's okay, because there are no reports of such behavior
anyway.

Author: Kuntal Ghosh <[email protected]>
Reviewed-by: Junwang Zhao <[email protected]>
Reviewed-by: Tender Wang <[email protected]>
Discussion: https://postgr.es/m/18559-b48286d2eacd9a4e@postgresql.org

8 months agoRemove unnecessary check for NULL locale, per Coverity.
Jeff Davis [Mon, 12 Aug 2024 19:26:23 +0000 (12:26 -0700)]
Remove unnecessary check for NULL locale, per Coverity.

Discussion: https://postgr.es/m/3804933.1723394010@sss.pgh.pa.us
Reported-by: Tom Lane
8 months agoGive nbtree move right function internal linkage.
Peter Geoghegan [Mon, 12 Aug 2024 18:36:55 +0000 (14:36 -0400)]
Give nbtree move right function internal linkage.

Declare _bt_moveright() static.  This is a minor modularity win; the
routine was already private to nbtsearch.c for all practical purposes.

Author: Matthias van de Meent <[email protected]>
Discussion: https://postgr.es/m/CAEze2WgWVzCNEXQB_op5MMZMDgJ3fg3AhVm6bq2iZPpJNXGhWw@mail.gmail.com

8 months agoLog more info when wait-for-catchup tests time out.
Tom Lane [Mon, 12 Aug 2024 17:18:36 +0000 (13:18 -0400)]
Log more info when wait-for-catchup tests time out.

Cluster.pm's wait_for_catchup and allied subroutines don't provide
enough information to diagnose the problem when a wait times out.
In hopes of debugging some intermittent buildfarm failures, let's
dump the ending state of the relevant system view when that happens.

Add this to v17 too, but not stable branches.

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

8 months agoAdd user-callable CRC functions.
Nathan Bossart [Mon, 12 Aug 2024 15:35:06 +0000 (10:35 -0500)]
Add user-callable CRC functions.

We've had code for CRC-32 and CRC-32C for some time (for WAL
records, etc.), but there was no way for users to call it, despite
apparent popular demand.  The new crc32() and crc32c() functions
accept bytea input and return bigint (to avoid returning negative
values).

Bumps catversion.

Author: Aleksander Alekseev
Reviewed-by: Peter Eisentraut, Tom Lane
Discussion: https://postgr.es/m/CAJ7c6TNMTGnqnG%3DyXXUQh9E88JDckmR45H2Q%2B%3DucaCLMOW1QQw%40mail.gmail.com

8 months agoFix outdated comments
David Rowley [Mon, 12 Aug 2024 11:41:13 +0000 (23:41 +1200)]
Fix outdated comments

A few fields in ResultRelInfo are now also used for MERGE.  Update the
comments to mention that.

Reported-by: jian he <[email protected]>
Discussion: https://postgr.es/m/CACJufxH8-NvFhLcSZZTTW+1M9AfS4+SOTKmyPG7ZhzNvN=+NkA@mail.gmail.com:wq

8 months agoFix a series of typos and outdated references
David Rowley [Mon, 12 Aug 2024 11:27:09 +0000 (23:27 +1200)]
Fix a series of typos and outdated references

Author: Alexander Lakhin <[email protected]>
Discussion: https://postgr.es/m/c1d63754-cb85-2d8a-8409-bde2c4d2d04b@gmail.com

8 months agoFix bad indentation introduced in commit f011e82c2c
Heikki Linnakangas [Mon, 12 Aug 2024 07:57:03 +0000 (10:57 +0300)]
Fix bad indentation introduced in commit f011e82c2c

8 months agoConsolidate postmaster code to launch background processes
Heikki Linnakangas [Mon, 12 Aug 2024 07:04:26 +0000 (10:04 +0300)]
Consolidate postmaster code to launch background processes

Much of the code in process_pm_child_exit() to launch replacement
processes when one exits or when progressing to next postmaster state
was unnecessary, because the ServerLoop will launch any missing
background processes anyway. Remove the redundant code and let
ServerLoop handle it.

In ServerLoop, move the code to launch all the processes to a new
subroutine, to group it all together.

Reviewed-by: Thomas Munro <[email protected]>
Discussion: https://www.postgresql.org/message-id/8f2118b9-79e3-4af7-b2c9-bd5818193ca4@iki.fi

8 months agoRemove dead code
Peter Eisentraut [Mon, 12 Aug 2024 06:43:47 +0000 (08:43 +0200)]
Remove dead code

After e9931bfb751, the locale argument of SB_lower_char() is never
NULL, so the branch that deals with NULL can be removed (similar to
how e9931bfb751 for example removed those branches in str_tolower()).

Reviewed-by: Jeff Davis <[email protected]>
Discussion: https://www.postgresql.org/message-id/4f562d84-87f4-44dc-8946-01d6c437936f@eisentraut.org

8 months agoRemove fe_memutils from libpgcommon_shlib
Peter Eisentraut [Mon, 12 Aug 2024 06:30:39 +0000 (08:30 +0200)]
Remove fe_memutils from libpgcommon_shlib

libpq must not use palloc/pfree. It's not allowed to exit on allocation
failure, and mixing the frontend pfree with malloc is architecturally
unsound.

Remove fe_memutils from the shlib build entirely, to keep devs from
accidentally depending on it in the future.

Author: Jacob Champion <[email protected]>
Discussion: https://www.postgresql.org/message-id/CAOYmi+=pg=W5L1h=3MEP_EB24jaBu2FyATrLXqQHGe7cpuvwyg@mail.gmail.com

8 months agoRemove support for old realpath() API
Peter Eisentraut [Mon, 12 Aug 2024 05:59:40 +0000 (07:59 +0200)]
Remove support for old realpath() API

The now preferred way to call realpath() is by passing NULL as the
second argument and get a malloc'ed result.  We still supported the
old way of providing our own buffer as a second argument, for some
platforms that didn't support the new way yet.  Those were only
Solaris less than version 11 and some older AIX versions (7.1 and
newer appear to support the new variant).  We don't support those
platforms versions anymore, so we can remove this extra code.

Reviewed-by: Heikki Linnakangas <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/9e638b49-5c3f-470f-a392-2cbedb2f7855%40eisentraut.org

8 months agoRemove "parent" column from pg_backend_memory_contexts
David Rowley [Mon, 12 Aug 2024 03:42:16 +0000 (15:42 +1200)]
Remove "parent" column from pg_backend_memory_contexts

32d3ed816 added the "path" column to pg_backend_memory_contexts to allow
a stable method of obtaining the parent MemoryContext of a given row in
the view.  Using the "path" column is now the preferred method of
obtaining the parent row.

Previously, any queries which were self-joining to this view using the
"name" and "parent" columns could get incorrect results due to the fact
that names are not unique.  Here we aim to explicitly break such queries
so that they can be corrected and use the "path" column instead.

It is possible that there are more innocent users of the parent column
that just need an indication of the parent and having to write out a
self-joining CTE may be an unnecessary hassle for those cases.  Let's
remove the column for now and see if anyone comes back with any
complaints.  This does seem like a good time to attempt to get rid of
the column as we still have around 1 year to revert this if someone comes
back with a valid complaint.  Plus this view is new to v14 and is quite
niche, so perhaps not many people will be affected.

Author: Melih Mutlu <[email protected]>
Discussion: https://postgr.es/m/CAGPVpCT7NOe4fZXRL8XaoxHpSXYTu6GTpULT_3E-HT9hzjoFRA@mail.gmail.com

8 months agoAvoid unneeded nbtree backwards scan buffer locks.
Peter Geoghegan [Sun, 11 Aug 2024 19:42:52 +0000 (15:42 -0400)]
Avoid unneeded nbtree backwards scan buffer locks.

Teach nbtree backwards scans to avoid relocking a just-read leaf page to
read its current left sibling link when it isn't truly necessary.  This
happened inside _bt_readnextpage whenever _bt_readpage had already
determined that there'll be no further matches to the left (or at least
none for the current primitive index scan, for a scan with array keys).

A new precheck inside _bt_readnextpage is all that we need to avoid
these useless lock acquisitions.  Arguably, using a precheck like this
was a missed opportunity for commit 2ed5b87f96, which taught nbtree to
drop leaf page pins early to avoid blocking cleanup by VACUUM.  Forwards
scans already managed to avoid relocking the page like this.

The optimization added by this commit is particularly helpful with
backwards scans that use array keys where the scan must perform multiple
primitive index scans.  Such backwards scans will now avoid a useless
leaf page re-lock at the end of each primitive index scan.

Note that this commit does not attempt to avoid needlessly re-locking a
leaf page that was just read when the scan must follow the leaf page's
left link.  That more ambitious optimization could work by stashing the
left link when the page is first read by a backwards scan, allowing the
subsequent _bt_readnextpage call to optimistically skip re-reading the
original page just to get a new copy of its left link.  For now we only
address cases where we don't care about our original page's left link.

Author: Peter Geoghegan <[email protected]>
Reviewed-By: Matthias van de Meent <[email protected]>
Discussion: https://postgr.es/m/CAH2-Wz=xgs7PojG=EUvhgadwENzu_mY_riNh-w9wFPsaS717ew@mail.gmail.com

8 months agoInitialize HASHCTL differently, to suppress Coverity warning
Heikki Linnakangas [Sun, 11 Aug 2024 17:21:16 +0000 (20:21 +0300)]
Initialize HASHCTL differently, to suppress Coverity warning

Coverity complained that the hash_create() call might access
hash_table_ctl->hctl. That's a false alarm, hash_create() only
accesses that field when passed the HASH_SHARED_MEM flag. Try to
silence it by using a plain local variable instead of a const. That's
how the HASHCTL is initialized in all the other hash_create() calls.

8 months agoSuppress Coverity warnings about Asserts in get_name_for_var_field.
Tom Lane [Sun, 11 Aug 2024 16:24:56 +0000 (12:24 -0400)]
Suppress Coverity warnings about Asserts in get_name_for_var_field.

Coverity thinks dpns->plan could be null at these points.  That
shouldn't really be possible, but it's easy enough to modify the
Asserts so they'd not core-dump if it were true.

These are new in b919a97a6.  Back-patch to v13; the v12 version
of the patch didn't have these Asserts.

8 months agoAllow adjusting session_authorization and role in parallel workers.
Tom Lane [Sat, 10 Aug 2024 19:51:28 +0000 (15:51 -0400)]
Allow adjusting session_authorization and role in parallel workers.

The code intends to allow GUCs to be set within parallel workers
via function SET clauses, but not otherwise.  However, doing so fails
for "session_authorization" and "role", because the assign hooks for
those attempt to set the subsidiary "is_superuser" GUC, and that call
falls foul of the "not otherwise" prohibition.  We can't switch to
using GUC_ACTION_SAVE for this, so instead add a new GUC variable
flag GUC_ALLOW_IN_PARALLEL to mark is_superuser as being safe to set
anyway.  (This is okay because is_superuser has context PGC_INTERNAL
and thus only hard-wired calls can change it.  We'd need more thought
before applying the flag to other GUCs; but maybe there are other
use-cases.)  This isn't the prettiest fix perhaps, but other
alternatives we thought of would be much more invasive.

While here, correct a thinko in commit 059de3ca4: when rejecting
a GUC setting within a parallel worker, we should return 0 not -1
if the ereport doesn't longjmp.  (This seems to have no consequences
right now because no caller cares, but it's inconsistent.)  Improve
the comments to try to forestall future confusion of the same kind.

Despite the lack of field complaints, this seems worth back-patching.
Thanks to Nathan Bossart for the idea to invent a new flag,
and for review.

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

8 months agoAdd tests for pg_wal_replay_wait() errors
Alexander Korotkov [Sat, 10 Aug 2024 18:43:14 +0000 (21:43 +0300)]
Add tests for pg_wal_replay_wait() errors

Improve test coverage for pg_wal_replay_wait() procedure by adding test
cases when it errors out.

8 months agoImprove header comment for WaitLSNSetLatches()
Alexander Korotkov [Sat, 10 Aug 2024 18:43:09 +0000 (21:43 +0300)]
Improve header comment for WaitLSNSetLatches()

Reflect the fact that we remove waiters from the heap, not just set their
latches.

8 months agoAdjust pg_wal_replay_wait() procedure behavior on promoted standby
Alexander Korotkov [Sat, 10 Aug 2024 18:43:02 +0000 (21:43 +0300)]
Adjust pg_wal_replay_wait() procedure behavior on promoted standby

pg_wal_replay_wait() is intended to be called on standby.  However, standby
can be promoted to primary at any moment, even concurrently with the
pg_wal_replay_wait() call.  If recovery is not currently in progress
that doesn't mean the wait was unsuccessful.  Thus, we always need to recheck
if the target LSN is replayed.

Reported-by: Kevin Hale Boyes
Discussion: https://postgr.es/m/CAPpHfdu5QN%2BZGACS%2B7foxmr8_nekgA2PA%2B-G3BuOUrdBLBFb6Q%40mail.gmail.com
Author: Alexander Korotkov

8 months agoLower minimum maintenance_work_mem to 64kB
John Naylor [Tue, 6 Aug 2024 13:38:33 +0000 (20:38 +0700)]
Lower minimum maintenance_work_mem to 64kB

Since the introduction of TID store, vacuum uses far less memory in
the common case than in versions 16 and earlier. Invoking multiple
rounds of index vacuuming in turn requires a much larger table. It'd
be a good idea anyway to cover this case in regression testing, and a
lower limit is less painful for slow buildfarm animals. The reason to
do it now is to re-enable coverage of the bugfix in commit 83c39a1f7f.

For consistency, give autovacuum_work_mem the same treatment.

Suggested by Andres Freund
Tested by Melanie Plageman
Backpatch to v17, where TID store was introduced

Discussion: https://postgr.es/m/20240516205458[email protected]
Discussion: https://postgr.es/m/20240722164745.fvaoh6g6zprisqgp%40awork3.anarazel.de

8 months agoFix inappropriate uses of atol()
Peter Eisentraut [Sat, 10 Aug 2024 06:12:44 +0000 (08:12 +0200)]
Fix inappropriate uses of atol()

Some code using atol() would not work correctly if sizeof(long)==4:

- src/bin/pg_basebackup/pg_basebackup.c: Would miscount size of a
  tablespace over 2 TB.

- src/bin/pg_basebackup/streamutil.c: Would truncate a timeline ID
  beyond INT32_MAX.

- src/bin/pg_rewind/libpq_source.c: Would miscount size of files
  larger than 2 GB (but this currently cannot happen).

Replace these with atoll().

In one case, the use of atol() did not result in incorrect behavior
but seems inconsistent with related code:

- src/interfaces/ecpg/ecpglib/execute.c: Gratuitous, since it
  processes a value from pg_type.typlen, which is int16.

Replace this with atoi().

Reviewed-by: Heikki Linnakangas <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/a52738ad-06bc-4d45-b59f-b38a8a89de49%40eisentraut.org

8 months agolibpq: Trace StartupMessage/SSLRequest/GSSENCRequest correctly
Alvaro Herrera [Fri, 9 Aug 2024 21:55:01 +0000 (17:55 -0400)]
libpq: Trace StartupMessage/SSLRequest/GSSENCRequest correctly

libpq tracing via PQtrace would uselessly print the wrong thing for
these types of messages.  With this commit, their type and contents
would be correctly listed.  (This can be verified with PQconnectStart(),
but we don't use that in libpq_pipeline, so I (Álvaro) haven't bothered
to add any tests.)

Author: Jelte Fennema-Nio <[email protected]>
Discussion: https://postgr.es/m/CAGECzQSoPHtZ4xe0raJ6FYSEiPPS+YWXBhOGo+Y1YecLgknF3g@mail.gmail.com

8 months agoFix comment on processes being kept over a restart
Heikki Linnakangas [Fri, 9 Aug 2024 21:06:19 +0000 (00:06 +0300)]
Fix comment on processes being kept over a restart

All child processes except the syslogger are killed on a restart. The
archiver might be already running though, if it was started during
recovery.

The split in the comments between "other special children" and the
first group of "background tasks" seemed really arbitrary, so I just
merged them all into one group.

Reviewed-by: Thomas Munro <[email protected]>
Discussion: https://www.postgresql.org/message-id/8f2118b9-79e3-4af7-b2c9-bd5818193ca4@iki.fi

8 months agoRefactor code to handle death of a backend or bgworker in postmaster
Heikki Linnakangas [Fri, 9 Aug 2024 21:04:43 +0000 (00:04 +0300)]
Refactor code to handle death of a backend or bgworker in postmaster

Currently, when a child process exits, the postmaster first scans
through BackgroundWorkerList, to see if it the child process was a
background worker. If not found, then it scans through BackendList to
see if it was a regular backend. That leads to some duplication
between the bgworker and regular backend cleanup code, as both have an
entry in the BackendList that needs to be cleaned up in the same way.
Refactor that so that we scan just the BackendList to find the child
process, and if it was a background worker, do the additional
bgworker-specific cleanup in addition to the normal Backend cleanup.

Change HandleChildCrash so that it doesn't try to handle the cleanup
of the process that already exited, only the signaling of all the
other processes. When called for any of the aux processes, the caller
had already cleared the *PID global variable, so the code in
HandleChildCrash() to do that was unused.

On Windows, if a child process exits with ERROR_WAIT_NO_CHILDREN, it's
now logged with that exit code, instead of 0. Also, if a bgworker
exits with ERROR_WAIT_NO_CHILDREN, it's now treated as crashed and is
restarted. Previously it was treated as a normal exit.

If a child process is not found in the BackendList, the log message
now calls it "untracked child process" rather than "server process".
Arguably that should be a PANIC, because we do track all the child
processes in the list, so failing to find a child process is highly
unexpected. But if we want to change that, let's discuss and do that
as a separate commit.

Reviewed-by: Thomas Munro <[email protected]>
Discussion: https://www.postgresql.org/message-id/835232c0-a5f7-4f20-b95b-5b56ba57d741@iki.fi

8 months agoMake BackgroundWorkerList doubly-linked
Heikki Linnakangas [Fri, 9 Aug 2024 19:44:20 +0000 (22:44 +0300)]
Make BackgroundWorkerList doubly-linked

This allows ForgetBackgroundWorker() and ReportBackgroundWorkerExit()
to take a RegisteredBgWorker pointer as argument, rather than a list
iterator. That feels a little more natural. But more importantly, this
paves the way for more refactoring in the next commit.

Reviewed-by: Thomas Munro <[email protected]>
Discussion: https://www.postgresql.org/message-id/835232c0-a5f7-4f20-b95b-5b56ba57d741@iki.fi

8 months agodoc: Standardize use of dashes in references to CRC and SHA.
Nathan Bossart [Fri, 9 Aug 2024 18:16:33 +0000 (13:16 -0500)]
doc: Standardize use of dashes in references to CRC and SHA.

Presently, we inconsistently use dashes in references to these
algorithms (e.g., CRC32C versus CRC-32C).  Some popular web sources
appear to prefer dashes, and with this commit, we will, too.

Reviewed-by: Robert Haas
Discussion: https://postgr.es/m/ZrUFpLP-w2zTAHqq%40nathan

8 months agodoc: Fix name of CRC algorithm in "Reliability" section.
Nathan Bossart [Fri, 9 Aug 2024 15:52:37 +0000 (10:52 -0500)]
doc: Fix name of CRC algorithm in "Reliability" section.

This section claims we use CRC-32 for WAL records and two-phase
state files, but we've actually used CRC-32C since v9.5 (commit
5028f22f6e).  Fix that.

Reviewed-by: Robert Haas
Discussion: https://postgr.es/m/ZrUFpLP-w2zTAHqq%40nathan
Backpatch-through: 12

8 months agoFix "failed to find plan for subquery/CTE" errors in EXPLAIN.
Tom Lane [Fri, 9 Aug 2024 15:21:39 +0000 (11:21 -0400)]
Fix "failed to find plan for subquery/CTE" errors in EXPLAIN.

To deparse a reference to a field of a RECORD-type output of a
subquery, EXPLAIN normally digs down into the subquery's plan to try
to discover exactly which anonymous RECORD type is meant.  However,
this can fail if the subquery has been optimized out of the plan
altogether on the grounds that no rows could pass the WHERE quals,
which has been possible at least since 3fc6e2d7f.  There isn't
anything remaining in the plan tree that would help us, so fall back
to printing the field name as "fN" for the N'th column of the record.
(This will actually be the right thing some of the time, since it
matches the column names we assign to RowExprs.)

In passing, fix a comment typo in create_projection_plan, which
I noticed while experimenting with an alternative fix for this.

Per bug #18576 from Vasya B.  Back-patch to all supported branches.

Richard Guo and Tom Lane

Discussion: https://postgr.es/m/18576-9feac34e132fea9e@postgresql.org

8 months agoRemove obsolete RECHECK keyword completely
Peter Eisentraut [Fri, 9 Aug 2024 05:17:15 +0000 (07:17 +0200)]
Remove obsolete RECHECK keyword completely

This used to be part of CREATE OPERATOR CLASS and ALTER OPERATOR
FAMILY, but it has done nothing (except issue a NOTICE) since
PostgreSQL 8.4.  Commit 30e7c175b81 removed support for dumping from
pre-9.2 servers, so this no longer serves any need.

This now removes it completely, and you'd get a normal parse error if
you used it.

Reviewed-by: Aleksander Alekseev <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/113ef2d2-3657-4353-be97-f28fceddbca1%40eisentraut.org

8 months agoChange the misleading local end_lsn for prepared transactions.
Amit Kapila [Fri, 9 Aug 2024 04:53:57 +0000 (10:23 +0530)]
Change the misleading local end_lsn for prepared transactions.

The apply worker was using XactLastCommitEnd as local end_lsn for applying
prepare and rollback_prepare. The XactLastCommitEnd value is the end lsn
of the last commit applied before the prepare transaction which makes no
sense. This LSN is used to decide whether we can send the acknowledgment
of the corresponding remote LSN to the server.

It is okay not to set the local_end LSN with the actual WAL position for
the prepare because we always flush the prepare record. So, we can send
the acknowledgment of the remote_end LSN as soon as prepare is finished.

The current code is misleading but as such doesn't create any problem, so
decided not to backpatch.

Author: Hayato Kuroda
Reviewed-by: Shveta Malik, Amit Kapila
Discussion: https://postgr.es/m/TYAPR01MB5692FA4926754B91E9D7B5F0F5AA2@TYAPR01MB5692.jpnprd01.prod.outlook.com

8 months agolibpq: Add suppress argument to pqTraceOutputNchar
Alvaro Herrera [Fri, 9 Aug 2024 00:35:12 +0000 (20:35 -0400)]
libpq: Add suppress argument to pqTraceOutputNchar

In future commits we're going to trace authentication related messages.
Some of these messages contain challenge bytes as part of a
challenge-response flow.  Since these bytes are different for every
connection, we want to normalize them when the PQTRACE_REGRESS_MODE
trace flag is set.  This commit modifies pqTraceOutputNchar to take a
suppress argument, which makes it possible to do so.

Author: Jelte Fennema-Nio <[email protected]>
Discussion: https://postgr.es/m/CAGECzQSoPHtZ4xe0raJ6FYSEiPPS+YWXBhOGo+Y1YecLgknF3g@mail.gmail.com

8 months agoRefuse ATTACH of a table referenced by a foreign key
Alvaro Herrera [Thu, 8 Aug 2024 23:35:13 +0000 (19:35 -0400)]
Refuse ATTACH of a table referenced by a foreign key

Trying to attach a table as a partition which is already on the
referenced side of a foreign key on the partitioned table that it is
being attached to, leads to strange behavior: we try to clone the
foreign key from the parent to the partition, but this new FK points to
the partition itself, and the mix of pg_constraint rows and triggers
doesn't behave well.

Rather than trying to untangle the mess (which might be possible given
sufficient time), I opted to forbid the ATTACH.  This doesn't seem a
problematic restriction, given that we already fail to create the
foreign key if you do it the other way around, that is, having the
partition first and the FK second.

Backpatch to all supported branches.

Reported-by: Alexander Lakhin <[email protected]>
Reviewed-by: Tender Wang <[email protected]>
Discussion: https://postgr.es/m/18541-628a61bc267cd2d3@postgresql.org

8 months agoRefactor error messages to reduce duplication
Alvaro Herrera [Thu, 8 Aug 2024 19:17:11 +0000 (15:17 -0400)]
Refactor error messages to reduce duplication

I also took the liberty of changing

errmsg("COPY DEFAULT only available using COPY FROM")
to
errmsg("COPY %s cannot be used with %s", "DEFAULT", "COPY TO")

because the original wording is unlike all other messages that indicate
option incompatibility.  This message was added by commit 9f8377f7a279
(16-era), in whose development thread there was no discussion on this
point.

Backpatch to 17.

8 months agoAdd a caveat to hash_seq_init_with_hash_value() header comment
Alexander Korotkov [Thu, 8 Aug 2024 08:48:57 +0000 (11:48 +0300)]
Add a caveat to hash_seq_init_with_hash_value() header comment

The typical use-case for hash_seq_init_with_hash_value() is syscache
callback.  Add a caveat that the default hash function doesn't match syscache
hash function.  So, one needs to define a custom hash function.

Reported-by: Pavel Stehule
Discussion: https://postgr.es/m/CAFj8pRAXmv6eyYx%3DE_BTfyK%3DO_%2ByOF8sXB%3D0bn9eOBt90EgWRA%40mail.gmail.com
Reviewed-by: Pavel Stehule
8 months agoFix pg_rewind debug output to print the source timeline history
Heikki Linnakangas [Thu, 8 Aug 2024 07:20:25 +0000 (10:20 +0300)]
Fix pg_rewind debug output to print the source timeline history

getTimelineHistory() is called twice, to read the source and the
target timeline history files. However, the loop to print the file
with the --debug option used the wrong variable when dealing with the
source. As a result, the source's history was always printed as empty.

Spotted while debugging bug #18575, but this does not fix that bug,
just the debugging output. Backpatch to all supported versions.

Discussion: https://www.postgresql.org/message-id/092dd515-b7b4-4fd0-8407-ceca2f02f6ec@iki.fi

8 months agoFix names of "Visual Studio" and Meson in a documentation sentence.
Noah Misch [Wed, 7 Aug 2024 18:43:08 +0000 (11:43 -0700)]
Fix names of "Visual Studio" and Meson in a documentation sentence.

Commit 3cffe7946c268be91a340ec9a27081cb93d67d35 missed this.  Back-patch
to v17, which introduced this.

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

8 months agoFix edge case in plpgsql's make_callstmt_target().
Tom Lane [Wed, 7 Aug 2024 16:54:39 +0000 (12:54 -0400)]
Fix edge case in plpgsql's make_callstmt_target().

If the plancache entry for the CALL statement is already stale,
it's possible for us to fetch an old procedure OID out of it,
and then fail with "cache lookup failed for function NNN".
In ordinary usage this never happens because make_callstmt_target
is called just once immediately after building the plancache
entry.  It can be forced however by setting up an erroneous CALL
(that causes make_callstmt_target itself to report an error),
then dropping/recreating the target procedure, then repeating
the erroneous CALL.

To fix, use SPI_plan_get_cached_plan() to fetch the plancache's
plan, rather than assuming we can use SPI_plan_get_plan_sources().
This shouldn't add any noticeable overhead in the normal case,
and in the stale-plan case we'd have had to replan anyway a little
further down.

The other callers of SPI_plan_get_plan_sources() seem OK, because
either they don't need up-to-date plans or they know that the
query was just (re) planned.  But add some commentary in hopes
of not falling into this trap again.

Per bug #18574 from Song Hongyu.  Back-patch to v14 where this coding
was introduced.  (Older branches have comparable code, but it's run
after any required replanning, so there's no issue.)

Discussion: https://postgr.es/m/18574-2ce7ba3249221389@postgresql.org

8 months agoRefactor/reword some error messages to avoid duplicates
Alvaro Herrera [Wed, 7 Aug 2024 15:30:36 +0000 (11:30 -0400)]
Refactor/reword some error messages to avoid duplicates

Also, remove brackets around "EMPTY [ ARRAY ]".  An error message is
not the place to state that a keyword is optional.

Backpatch to 17.

8 months agoImprove file header comments for astramer code.
Robert Haas [Wed, 7 Aug 2024 12:49:41 +0000 (08:49 -0400)]
Improve file header comments for astramer code.

Make it clear that "astreamer" stands for "archive streamer".
Generalize comments that still believe this code can only be used
by pg_basebackup. Add some comments explaining the asymmetry
between the gzip, lz4, and zstd astreamers, in the hopes of making
life easier for anyone who hacks on this code in the future.

Robert Haas, reviewed by Amul Sul.

Discussion: http://postgr.es/m/CAAJ_b97O2kkKVTWxt8MxDN1o-cDfbgokqtiN2yqFf48=gXpcxQ@mail.gmail.com

8 months agoMake fallback MD5 implementation thread-safe on big-endian systems
Heikki Linnakangas [Wed, 7 Aug 2024 07:43:52 +0000 (10:43 +0300)]
Make fallback MD5 implementation thread-safe on big-endian systems

Replace a static scratch buffer with a local variable, because a
static buffer makes the function not thread-safe. This function is
used in client-code in libpq, so it needs to be thread-safe. It was
until commit b67b57a966, which replaced the implementation with the
one from pgcrypto.

Backpatch to v14, where we switched to the new implementation.

Reviewed-by: Robert Haas, Michael Paquier
Discussion: https://www.postgresql.org/message-id/dfa2015d-ad21-4802-a4cc-3850fc5fff3f@iki.fi

8 months agoRevert ECPG's use of pnstrdup()
Peter Eisentraut [Wed, 7 Aug 2024 07:21:07 +0000 (09:21 +0200)]
Revert ECPG's use of pnstrdup()

Commit 0b9466fce added a dependency on fe_memutils' pnstrdup() inside
informix.c.  This adds an exit() path in a library, which we don't
want.  (Unlike libpq, the ecpg libraries don't have an automated check
for that, but it makes sense to keep them to a similar standard.)  The
ecpg code can already handle failure results from the *strdup() call
by itself.

Author: Jacob Champion <[email protected]>
Discussion: https://www.postgresql.org/message-id/CAOYmi+=pg=W5L1h=3MEP_EB24jaBu2FyATrLXqQHGe7cpuvwyg@mail.gmail.com

8 months agoOptimize InvalidateAttoptCacheCallback() and TypeCacheTypCallback()
Alexander Korotkov [Wed, 7 Aug 2024 03:51:29 +0000 (06:51 +0300)]
Optimize InvalidateAttoptCacheCallback() and TypeCacheTypCallback()

These callbacks are receiving hash values as arguments, which doesn't allow
direct lookups for AttoptCacheHash and TypeCacheHash.  This is why subject
callbacks currently use full iteration over corresponding hashes.

This commit avoids full hash iteration in InvalidateAttoptCacheCallback(),
and TypeCacheTypCallback().  At first, we switch AttoptCacheHash and
TypeCacheHash to use same hash function as syscache.  As second, we
use hash_seq_init_with_hash_value() to iterate only hash entries with matching
hash value.

Discussion: https://postgr.es/m/5812a6e5-68ae-4d84-9d85-b443176966a1%40sigaev.ru
Author: Teodor Sigaev
Reviewed-by: Aleksander Alekseev, Tom Lane, Michael Paquier, Roman Zharkov
Reviewed-by: Andrei Lepikhov
8 months agoIntroduce hash_search_with_hash_value() function
Alexander Korotkov [Wed, 7 Aug 2024 03:51:16 +0000 (06:51 +0300)]
Introduce hash_search_with_hash_value() function

This new function iterates hash entries with given hash values.  This function
is designed to avoid full sequential hash search in the syscache invalidation
callbacks.

Discussion: https://postgr.es/m/5812a6e5-68ae-4d84-9d85-b443176966a1%40sigaev.ru
Author: Teodor Sigaev
Reviewed-by: Aleksander Alekseev, Tom Lane, Michael Paquier, Roman Zharkov
Reviewed-by: Andrei Lepikhov
8 months agoUse psprintf to simplify gtsvectorout()
Heikki Linnakangas [Tue, 6 Aug 2024 20:05:25 +0000 (23:05 +0300)]
Use psprintf to simplify gtsvectorout()

The buffer allocation was correct, but looked archaic and scary:

- It was weird to calculate the buffer size before determining which
  format string was used. With the same effort, we could've used the
  right-sized buffer for each branch.

- Commit aa0d3504560 added one more possible return string ("all true
  bits"), but didn't adjust the code at the top of the function to
  calculate the returned string's max size. It was not a live bug,
  because the new string was smaller than the existing ones, but
  seemed wrong in principle.

- Use of sprintf() is generally eyebrow-raising these days

Switch to psprintf(). psprintf() allocates a larger buffer than what
was allocated before, 128 bytes vs 80 bytes, which is acceptable as
this code is not performance or space critical.

Reviewed-by: Andres Freund
Discussion: https://www.postgresql.org/message-id/54c29fb0-edf2-48ea-9814-44e918bbd6e8@iki.fi

8 months agoConstify fields and parameters in spell.c
Heikki Linnakangas [Tue, 6 Aug 2024 20:04:51 +0000 (23:04 +0300)]
Constify fields and parameters in spell.c

I started by marking VoidString as const, and fixing the fallout by
marking more fields and function arguments as const. It proliferated
quite a lot, but all within spell.c and spell.h.

A more narrow patch to get rid of the static VoidString buffer would
be to replace it with '#define VoidString ""', as C99 allows assigning
"" to a non-const pointer, even though you're not allowed to modify
it. But it seems like good hygiene to mark all these as const. In the
structs, the pointers can point to the constant VoidString, or a
buffer allocated with palloc(), or with compact_palloc(), so you
should not modify them.

Reviewed-by: Andres Freund
Discussion: https://www.postgresql.org/message-id/54c29fb0-edf2-48ea-9814-44e918bbd6e8@iki.fi

8 months agoMark misc static global variables as const
Heikki Linnakangas [Tue, 6 Aug 2024 20:04:48 +0000 (23:04 +0300)]
Mark misc static global variables as const

Reviewed-by: Andres Freund
Discussion: https://www.postgresql.org/message-id/54c29fb0-edf2-48ea-9814-44e918bbd6e8@iki.fi

8 months agoMake nullSemAction const, add 'const' decorators to related functions
Heikki Linnakangas [Tue, 6 Aug 2024 20:04:22 +0000 (23:04 +0300)]
Make nullSemAction const, add 'const' decorators to related functions

To make it more clear that these should never be modified.

Reviewed-by: Andres Freund
Discussion: https://www.postgresql.org/message-id/54c29fb0-edf2-48ea-9814-44e918bbd6e8@iki.fi

8 months agoTurn a few 'validnsps' static variables into locals
Heikki Linnakangas [Tue, 6 Aug 2024 20:03:43 +0000 (23:03 +0300)]
Turn a few 'validnsps' static variables into locals

There was no need for these to be static buffers, local variables work
just as well. I think they were marked as 'static' to imply that they
are read-only, but 'const' is more appropriate for that, so change
them to const.

To make it possible to mark the variables as 'const', also add 'const'
decorations to the transformRelOptions() signature.

Reviewed-by: Andres Freund
Discussion: https://www.postgresql.org/message-id/54c29fb0-edf2-48ea-9814-44e918bbd6e8@iki.fi

8 months agoselfuncs.c: use pg_strxfrm() instead of strxfrm().
Jeff Davis [Tue, 6 Aug 2024 18:55:21 +0000 (11:55 -0700)]
selfuncs.c: use pg_strxfrm() instead of strxfrm().

pg_strxfrm() takes a pg_locale_t, so it works properly with all
providers. This improves estimates for ICU when performing linear
interpolation within a histogram bin.

Previously, convert_string_datum() always used strxfrm() and relied on
setlocale(). That did not produce good estimates for non-default or
non-libc collations.

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

8 months agoFix datatypes in comments in instr_time.h
Heikki Linnakangas [Tue, 6 Aug 2024 19:15:55 +0000 (22:15 +0300)]
Fix datatypes in comments in instr_time.h

The INSTR_TIME_GET_NANOSEC(t) and INSTR_TIME_GET_MICROSEC(t) macros
return a signed int64.

Discussion: https://www.postgresql.org/message-id/[email protected]

8 months agoRevert "Fix comments in instr_time.h and remove an unneeded cast to int64"
Heikki Linnakangas [Tue, 6 Aug 2024 19:15:46 +0000 (22:15 +0300)]
Revert "Fix comments in instr_time.h and remove an unneeded cast to int64"

This reverts commit 3dcb09de7b. Tom Lane pointed out that it broke the
abstraction provided by the macros. The callers should not need to
know what the internal type is.

This commit is an exact revert, the next commit will fix the comments
on the macros that incorrectly claim that they return uint64.

Discussion: https://www.postgresql.org/message-id/[email protected]

8 months agoAllow parallel workers to cope with a newly-created session user ID.
Tom Lane [Tue, 6 Aug 2024 16:36:42 +0000 (12:36 -0400)]
Allow parallel workers to cope with a newly-created session user ID.

Parallel workers failed after a sequence like
BEGIN;
CREATE USER foo;
SET SESSION AUTHORIZATION foo;
because check_session_authorization could not see the uncommitted
pg_authid row for "foo".  This is because we ran RestoreGUCState()
in a separate transaction using an ordinary just-created snapshot.
The same disease afflicts any other GUC that requires catalog lookups
and isn't forgiving about the lookups failing.

To fix, postpone RestoreGUCState() into the worker's main transaction
after we've set up a snapshot duplicating the leader's.  This affects
check_transaction_isolation and check_transaction_deferrable, which
think they should only run during transaction start.  Make them
act like check_transaction_read_only, which already knows it should
silently accept the value when InitializingParallelWorker.

This un-reverts commit f5f30c22e.  The original plan was to back-patch
that, but the fact that 0ae5b763e proved to be a pre-requisite shows
that the subtle API change for GUC hooks might actually break some of
them.  The problem we're trying to fix seems not worth taking such a
risk for in stable branches.

Per bug #18545 from Andrey Rachitskiy.

Discussion: https://postgr.es/m/18545-feba138862f19aaa@postgresql.org

8 months agoClean up handling of client_encoding GUC in parallel workers.
Tom Lane [Tue, 6 Aug 2024 16:21:23 +0000 (12:21 -0400)]
Clean up handling of client_encoding GUC in parallel workers.

The previous coding here threw an error from assign_client_encoding
if it was invoked in a parallel worker.  That's a very fundamental
violation of the GUC hook API: assign hooks must not throw errors.
The place to complain is in the check hook, so move the test to
there, and use the regular check-hook API (ie return false) to
report it.

The reason this coding is a problem is that it breaks GUC rollback,
which may occur after we leave InitializingParallelWorker state.
That case seems not actually reachable before now, but commit
f5f30c22e made it reachable, so we need to fix this before that
can be un-reverted.

In passing, improve the commentary in ParallelWorkerMain, and
add a check for failure of SetClientEncoding.  That's another
case that can't happen now but might become possible after
foreseeable code rearrangements (notably, if the shortcut of
skipping PrepareClientEncoding stops being OK).

Discussion: https://postgr.es/m/18545-feba138862f19aaa@postgresql.org

8 months agoRemove volatile qualifiers from pg_stat_statements.c.
Nathan Bossart [Tue, 6 Aug 2024 15:56:37 +0000 (10:56 -0500)]
Remove volatile qualifiers from pg_stat_statements.c.

Prior to commit 0709b7ee72, which changed the spinlock primitives
to function as compiler barriers, access to variables within a
spinlock-protected section required using a volatile pointer, but
that is no longer necessary.

Reviewed-by: Bertrand Drouvot, Michael Paquier
Discussion: https://postgr.es/m/Zqkv9iK7MkNS0KaN%40nathan

8 months agoFix comments in instr_time.h and remove an unneeded cast to int64
Heikki Linnakangas [Tue, 6 Aug 2024 11:28:02 +0000 (14:28 +0300)]
Fix comments in instr_time.h and remove an unneeded cast to int64

03023a2664 represented time as an int64 on all platforms but forgot to
update the comment related to INSTR_TIME_GET_MICROSEC() and provided
an incorrect comment for INSTR_TIME_GET_NANOSEC().

In passing remove an unneeded cast to int64.

Author: Bertrand Drouvot
Discussion: https://www.postgresql.org/message-id/[email protected]

8 months agoRemove unnecessary declaration of heapam_methods
Michael Paquier [Tue, 6 Aug 2024 07:27:38 +0000 (16:27 +0900)]
Remove unnecessary declaration of heapam_methods

This overlaps with the declaration at the end of heapam_handler.c that
lists all the callback routines for the heap table AM.

Author: Japin Li
Discussion: https://postgr.es/m/ME0P300MB04459456D5C4E70D48116896B6B12@ME0P300MB0445.AUSP300.PROD.OUTLOOK.COM

8 months agoRemove support for null pg_locale_t most places.
Jeff Davis [Tue, 6 Aug 2024 01:15:57 +0000 (18:15 -0700)]
Remove support for null pg_locale_t most places.

Previously, passing NULL for pg_locale_t meant "use the libc provider
and the server environment". Now that the database collation is
represented as a proper pg_locale_t (not dependent on setlocale()),
remove special cases for NULL.

Leave wchar2char() and char2wchar() unchanged for now, because the
callers don't always have a libc-based pg_locale_t available.

Discussion: https://postgr.es/m/cfd9eb85-c52a-4ec9-a90e-a5e4de56e57d@eisentraut.org
Reviewed-by: Peter Eisentraut, Andreas Karlsson
8 months agoMove astreamer (except astreamer_inject) to fe_utils.
Robert Haas [Mon, 5 Aug 2024 15:40:29 +0000 (11:40 -0400)]
Move astreamer (except astreamer_inject) to fe_utils.

This allows the code to be used by other frontend applications.

Amul Sul, reviewed by Sravan Kumar, Andres Freund (whose input
I specifically solicited regarding the meson.build changes),
and me.

Discussion: http://postgr.es/m/CAAJ_b94StvLWrc_p4q-f7n3OPfr6GhL8_XuAg2aAaYZp1tF-nw@mail.gmail.com

8 months agoMove recovery injector astreamer to a separate header file.
Robert Haas [Mon, 5 Aug 2024 14:40:23 +0000 (10:40 -0400)]
Move recovery injector astreamer to a separate header file.

Unlike the rest of the astreamer (formerly bbstreamer) infrastructure
which is reusable by other tools, astreamer_inject.c seems extremely
specific to pg_basebackup. Hence, move the corresponding declarations
to a separate header file, so that we can move the rest of the code
without moving this.

Amul Sul, reviewed by Sravan Kumar and by me.

Discussion: http://postgr.es/m/CAAJ_b94StvLWrc_p4q-f7n3OPfr6GhL8_XuAg2aAaYZp1tF-nw@mail.gmail.com

8 months agoRename bbstreamer to astreamer.
Robert Haas [Mon, 5 Aug 2024 13:35:42 +0000 (09:35 -0400)]
Rename bbstreamer to astreamer.

I (rhaas) intended "bbstreamer" to stand for "base backup streamer,"
but that implies that this infrastructure can only ever be used by
pg_basebackup.  In fact, it is a generally useful way of streaming
data from a tar or compressed tar file, and it could be extended to
work with other archive formats as well if we ever wanted to do that.
Hence, rename it to "astreamer" (archive streamer) in preparation for
reusing the infrastructure from pg_verifybackup (and perhaps
eventually also other utilities, such as pg_combinebackup or
pg_waldump).

This is purely a renaming commit. Comment adjustments and relocation
of the actual code to someplace from which it can be reused are left
to future commits.

Amul Sul, reviewed by Sravan Kumar and by me.

Discussion: http://postgr.es/m/CAAJ_b94StvLWrc_p4q-f7n3OPfr6GhL8_XuAg2aAaYZp1tF-nw@mail.gmail.com

8 months agoRestrict accesses to non-system views and foreign tables during pg_dump.
Masahiko Sawada [Mon, 5 Aug 2024 13:05:33 +0000 (06:05 -0700)]
Restrict accesses to non-system views and foreign tables during pg_dump.

When pg_dump retrieves the list of database objects and performs the
data dump, there was possibility that objects are replaced with others
of the same name, such as views, and access them. This vulnerability
could result in code execution with superuser privileges during the
pg_dump process.

This issue can arise when dumping data of sequences, foreign
tables (only 13 or later), or tables registered with a WHERE clause in
the extension configuration table.

To address this, pg_dump now utilizes the newly introduced
restrict_nonsystem_relation_kind GUC parameter to restrict the
accesses to non-system views and foreign tables during the dump
process. This new GUC parameter is added to back branches too, but
these changes do not require cluster recreation.

Back-patch to all supported branches.

Reviewed-by: Noah Misch
Security: CVE-2024-7348
Backpatch-through: 12

8 months agoOptimize JSON escaping using SIMD
David Rowley [Mon, 5 Aug 2024 11:16:44 +0000 (23:16 +1200)]
Optimize JSON escaping using SIMD

Here we adjust escape_json_with_len() to make use of SIMD to allow
processing of up to 16-bytes at a time rather than processing a single
byte at a time.  This has been shown to speed up escaping of JSON
strings significantly.

Escaping is required for both JSON string properties and also the
property names themselves, so this should also help improve the speed of
the conversion from JSON into text for JSON objects that have property
names 16 or more bytes long.

Escaping JSON strings was often a significant bottleneck for longer
strings.  With these changes, some benchmarking has shown a query
performing nearly 4 times faster when escaping a JSON object with a 1MB
text property.  Tests with shorter text properties saw smaller but still
significant performance improvements.  For example, a test outputting 1024
JSON strings with a text property length ranging from 1 char to 1024 chars
became around 2 times faster.

Author: David Rowley
Reviewed-by: Melih Mutlu
Discussion: https://postgr.es/m/CAApHDvpLXwMZvbCKcdGfU9XQjGCDm7tFpRdTXuB9PVgpNUYfEQ@mail.gmail.com

8 months agoFix typo in bufpage.h.
Amit Kapila [Mon, 5 Aug 2024 09:08:00 +0000 (14:38 +0530)]
Fix typo in bufpage.h.

Author: Senglee Choi
Reviewed-by: Tender Wang
Discussion: https://postgr.es/m/CACUsy79U0=S5zWEf6D57F=vB7rOEa86xFY6oovDZ58jRcROCxQ@mail.gmail.com

8 months agoinjection_points: Add some fixed-numbered statistics
Michael Paquier [Mon, 5 Aug 2024 03:29:22 +0000 (12:29 +0900)]
injection_points: Add some fixed-numbered statistics

Like 75534436a477, this acts mainly as a template to show what can be
achieved with fixed-numbered stats (like WAL, bgwriter, etc.) with the
pluggable cumulative statistics APIs introduced in 7949d9594582.

Fixed-numbered stats are defined in their own file, named
injection_stats_fixed.c, separated entirely from the variable-numbered
case in injection_stats.c.  This is mainly for clarity as having both
examples in the same file would be confusing.

Note that this commit uses the helper routines added in 2eff9e678d35.
The stats stored track globally the number of times injection points
have been attached, detached or run.  Two more fields should be added
later for the number of times a point has been cached or loaded, but
what's here is enough as a template.

More TAP tests are added, providing coverage for fixed-numbered custom
stats.

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

8 months agoinjection_points: Add some cumulative stats for injection points
Michael Paquier [Mon, 5 Aug 2024 03:06:54 +0000 (12:06 +0900)]
injection_points: Add some cumulative stats for injection points

This acts as a template of what can be achieved with the pluggable
cumulative stats APIs introduced in 7949d9594582 for the
variable-numbered case where stats entries are stored in the pgstats
dshash, while being potentially useful on its own for injection points,
say to add starting and/or stopping conditions based on the statistics
(want to trigger a callback after N calls, for example?).

Currently, the only data gathered is the number of times an injection
point is run.  More fields can always be added as required.  All the
routines related to the stats are located in their own file, called
injection_stats.c in the test module injection_points, for clarity.

The stats can be used only if the test module is loaded through
shared_preload_libraries.  The key of the dshash uses InvalidOid for the
database, and an int4 hash of the injection point name as object ID.

A TAP test is added to provide coverage for the new custom cumulative
stats APIs, showing the persistency of the data across restarts, for
example.

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

8 months agoAdd helper routines to retrieve data for custom fixed-numbered pgstats
Michael Paquier [Mon, 5 Aug 2024 02:43:33 +0000 (11:43 +0900)]
Add helper routines to retrieve data for custom fixed-numbered pgstats

This is useful for extensions to get snapshot and shmem data for custom
cumulative statistics when these have a fixed number of objects, so as
these do not need to know about the snapshot internals, aka pgStatLocal.

An upcoming commit introducing an example template for custom cumulative
stats with fixed-numbered objects will make use of these.  I have
noticed that this is useful for extension developers while hacking my
own example, actually.

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

8 months agopg_wal_replay_wait(): Fix typo in the doc
Alexander Korotkov [Sun, 4 Aug 2024 17:26:48 +0000 (20:26 +0300)]
pg_wal_replay_wait(): Fix typo in the doc

Reported-by: Kevin Hale Boyes
Discussion: https://postgr.es/m/CADAecHWKpaPuPGXAMOH%3DwmhTpydHWGPOk9KWX97UYhp5GdqCWw%40mail.gmail.com

8 months agoIntroduce pluggable APIs for Cumulative Statistics
Michael Paquier [Sun, 4 Aug 2024 10:41:24 +0000 (19:41 +0900)]
Introduce pluggable APIs for Cumulative Statistics

This commit adds support in the backend for $subject, allowing
out-of-core extensions to plug their own custom kinds of cumulative
statistics.  This feature has come up a few times into the lists, and
the first, original, suggestion came from Andres Freund, about
pg_stat_statements to use the cumulative statistics APIs in shared
memory rather than its own less efficient internals.  The advantage of
this implementation is that this can be extended to any kind of
statistics.

The stats kinds are divided into two parts:
- The in-core "builtin" stats kinds, with designated initializers, able
to use IDs up to 128.
- The "custom" stats kinds, able to use a range of IDs from 128 to 256
(128 slots available as of this patch), with information saved in
TopMemoryContext.  This can be made larger, if necessary.

There are two types of cumulative statistics in the backend:
- For fixed-numbered objects (like WAL, archiver, etc.).  These are
attached to the snapshot and pgstats shmem control structures for
efficiency, and built-in stats kinds still do that to avoid any
redirection penalty.  The data of custom kinds is stored in a first
array in snapshot structure and a second array in the shmem control
structure, both indexed by their ID, acting as an equivalent of the
builtin stats.
- For variable-numbered objects (like tables, functions, etc.).  These
are stored in a dshash using the stats kind ID in the hash lookup key.

Internally, the handling of the builtin stats is unchanged, and both
fixed and variabled-numbered objects are supported.  Structure
definitions for builtin stats kinds are renamed to reflect better the
differences with custom kinds.

Like custom RMGRs, custom cumulative statistics can only be loaded with
shared_preload_libraries at startup, and must allocate a unique ID
shared across all the PostgreSQL extension ecosystem with the following
wiki page to avoid conflicts:
https://wiki.postgresql.org/wiki/CustomCumulativeStats

This makes the detection of the stats kinds and their handling when
reading and writing stats much easier than, say, allocating IDs for
stats kinds from a shared memory counter, that may change the ID used by
a stats kind across restarts.  When under development, extensions can
use PGSTAT_KIND_EXPERIMENTAL.

Two examples that can be used as templates for fixed-numbered and
variable-numbered stats kinds will be added in some follow-up commits,
with tests to provide coverage.

Some documentation is added to explain how to use this plugin facility.

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

8 months agoUse CXXFLAGS instead of CFLAGS for linking C++ code
Peter Eisentraut [Sun, 4 Aug 2024 09:17:46 +0000 (11:17 +0200)]
Use CXXFLAGS instead of CFLAGS for linking C++ code

Otherwise, this would break if using C and C++ compilers from
different families and they understand different options.  It already
used the right flags for compiling, this is only for linking.  Also,
the meson setup already did this correctly.

Reported-by: Tom Lane <[email protected]>
Discussion: https://www.postgresql.org/message-id/228700.1722717983@sss.pgh.pa.us

8 months agoFix incorrect format placeholders in pgstat.c
Michael Paquier [Sat, 3 Aug 2024 18:07:20 +0000 (03:07 +0900)]
Fix incorrect format placeholders in pgstat.c

These should have been switched from %d to %u in 3188a4582a8c in the
debugging elogs added in ca1ba50fcb6f.  PgStat_Kind should never be
higher than INT32_MAX, but let's be clean.

Issue noticed while hacking more on this area.

8 months agoAdd -Wmissing-variable-declarations to the standard compilation flags
Peter Eisentraut [Sat, 3 Aug 2024 09:42:37 +0000 (11:42 +0200)]
Add -Wmissing-variable-declarations to the standard compilation flags

This warning flag detects global variables not declared in header
files.  This is similar to what -Wmissing-prototypes does for
functions.  (More correctly, it is similar to what
-Wmissing-declarations does for functions, but -Wmissing-prototypes is
a superset of that in C.)

This flag is new in GCC 14.  Clang has supported it for a while.

Several recent commits have cleaned up warnings triggered by this, so
it should now be clean.

Reviewed-by: Andres Freund <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/e0a62134-83da-4ba4-8cdb-ceb0111c95ce@eisentraut.org

8 months agoSmall refactoring around ExecCreateTableAs().
Jeff Davis [Fri, 2 Aug 2024 18:49:03 +0000 (11:49 -0700)]
Small refactoring around ExecCreateTableAs().

Since commit 4b74ebf726, the refresh logic is used to populate
materialized views, so we can simplify the error message in
ExecCreateTableAs().

Also, RefreshMatViewByOid() is moved to just after
create_ctas_nodata() call to improve code readability.

Author: Yugo Nagata
Discussion: https://postgr.es/m/20240802161301.d975daca9ba7a706fa05ecd7@sraoss.co.jp

8 months agoFix name of "Visual Studio" in documentation.
Noah Misch [Fri, 2 Aug 2024 19:49:56 +0000 (12:49 -0700)]
Fix name of "Visual Studio" in documentation.

Back-patch to v17, which introduced this.

Aleksander Alekseev

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

8 months agoImplement pg_wal_replay_wait() stored procedure
Alexander Korotkov [Fri, 2 Aug 2024 18:13:05 +0000 (21:13 +0300)]
Implement pg_wal_replay_wait() stored procedure

pg_wal_replay_wait() is to be used on standby and specifies waiting for
the specific WAL location to be replayed.  This option is useful when
the user makes some data changes on primary and needs a guarantee to see
these changes are on standby.

The queue of waiters is stored in the shared memory as an LSN-ordered pairing
heap, where the waiter with the nearest LSN stays on the top.  During
the replay of WAL, waiters whose LSNs have already been replayed are deleted
from the shared memory pairing heap and woken up by setting their latches.

pg_wal_replay_wait() needs to wait without any snapshot held.  Otherwise,
the snapshot could prevent the replay of WAL records, implying a kind of
self-deadlock.  This is why it is only possible to implement
pg_wal_replay_wait() as a procedure working without an active snapshot,
not a function.

Catversion is bumped.

Discussion: https://postgr.es/m/eb12f9b03851bb2583adab5df9579b4b%40postgrespro.ru
Author: Kartyshov Ivan, Alexander Korotkov
Reviewed-by: Michael Paquier, Peter Eisentraut, Dilip Kumar, Amit Kapila
Reviewed-by: Alexander Lakhin, Bharath Rupireddy, Euler Taveira
Reviewed-by: Heikki Linnakangas, Kyotaro Horiguchi
8 months agoFix NLS file reference in pg_createsubscriber
Alvaro Herrera [Fri, 2 Aug 2024 16:05:38 +0000 (12:05 -0400)]
Fix NLS file reference in pg_createsubscriber

pg_createsubscriber is referring to a non-existent message translation
file, causing NLS to not work correctly. This command should use the
same file as pg_basebackup.

Author: Kyotaro Horiguchi <[email protected]>
Discussion: https://postgr.es/m/20240802.115717.1083441453338151622[email protected]

8 months agopg_createsubscriber: Fix bogus error message
Alvaro Herrera [Fri, 2 Aug 2024 16:01:10 +0000 (12:01 -0400)]
pg_createsubscriber: Fix bogus error message

Also some desultory style improvement

8 months agoInclude bison header files into implementation files
Peter Eisentraut [Fri, 2 Aug 2024 07:59:35 +0000 (09:59 +0200)]
Include bison header files into implementation files

Before Bison 3.4, the generated parser implementation files run afoul
of -Wmissing-variable-declarations (in spite of commit ab61c40bfa2)
because declarations for yylval and possibly yylloc are missing.  The
generated header files contain an extern declaration, but the
implementation files don't include the header files.  Since Bison 3.4,
the generated implementation files automatically include the generated
header files, so then it works.

To make this work with older Bison versions as well, include the
generated header file from the .y file.

(With older Bison versions, the generated implementation file contains
effectively a copy of the header file pasted in, so including the
header file is redundant.  But we know this works anyway because the
core grammar uses this arrangement already.)

Discussion: https://www.postgresql.org/message-id/flat/e0a62134-83da-4ba4-8cdb-ceb0111c95ce@eisentraut.org

8 months agoMinor refactoring of assign_backendlist_entry()
Heikki Linnakangas [Thu, 1 Aug 2024 20:23:55 +0000 (23:23 +0300)]
Minor refactoring of assign_backendlist_entry()

Make assign_backendlist_entry() responsible just for allocating the
Backend struct. Linking it to the RegisteredBgWorker is the caller's
responsibility now. Seems more clear that way.

Discussion: https://www.postgresql.org/message-id/835232c0-a5f7-4f20-b95b-5b56ba57d741@iki.fi

8 months agoFix outdated comment; all running bgworkers are in BackendList
Heikki Linnakangas [Thu, 1 Aug 2024 20:23:47 +0000 (23:23 +0300)]
Fix outdated comment; all running bgworkers are in BackendList

Before commit 8a02b3d732, only bgworkers that connected to a database
had an entry in the Backendlist. Commit 8a02b3d732 changed that, but
forgot to update this comment.

Discussion: https://www.postgresql.org/message-id/835232c0-a5f7-4f20-b95b-5b56ba57d741@iki.fi

8 months agoSwitch PgStat_Kind from an enum to a uint32 type
Michael Paquier [Thu, 1 Aug 2024 19:49:34 +0000 (04:49 +0900)]
Switch PgStat_Kind from an enum to a uint32 type

A follow-up patch is planned to make cumulative statistics pluggable,
and using a type is useful in the internal routines used by pgstats as
PgStat_Kind may have a value that was not originally in the enum removed
here, once made pluggable.

While on it, this commit switches pgstat_is_kind_valid() to use
PgStat_Kind rather than an int, to be more consistent with its existing
callers.  Some loops based on the stats kind IDs are switched to use
PgStat_Kind rather than int, for consistency with the new time.

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