Michael Paquier [Sun, 12 Nov 2023 07:43:12 +0000 (16:43 +0900)]
Add ability to reset all shared stats types in pg_stat_reset_shared()
Currently, pg_stat_reset_shared() can use an argument to specify the
target of statistics to reset, doing nothing for NULL as it is strict.
This patch adds to pg_stat_reset_shared() the possibility to reset all
the stats types already handled in this function rather than do nothing
if the argument value given is NULL or if nothing is specified
(proisstrict is switched to false). Like previously, SLRUs are not
included in what gets reset.
The idea to use NULL or no argument to control if all the shared stats
already covered by this function should be reset has been proposed by
Andres Freund.
Bump catalog version.
Author: Atsushi Torikoshi
Reviewed-by: Kyotaro Horiguchi, Michael Paquier, Bharath Rupireddy,
Matthias van de Meent
Discussion: https://postgr.es/m/
4291a55137ddda77cf7cc5f46e846daf@oss.nttdata.com
Michael Paquier [Sun, 12 Nov 2023 01:06:51 +0000 (10:06 +0900)]
Fix inconsistencies for queries on pg_class in type_sanity.sql
Three queries did not consider partitioned indexes and tables, and
surrounding comments have not been updated in a while.
Like
4b9fbd6be442, this is only cosmetic currently as no such relkinds
exist at this stage of the regression tests, but running these queries
on existing clusters could lead to incorrect results.
Author: Jian He, Michael Paquier
Discussion: https://postgr.es/m/CACJufxGsB1ciahkNDccyxhw-Pfp_-_y+Wx+1BOdRyVVxKojAbg@mail.gmail.com
Alexander Korotkov [Fri, 10 Nov 2023 20:46:46 +0000 (22:46 +0200)]
Fix how SJE checks against PHVs
It seems that a PHV evaluated/needed at or below the self join should not have
a problem if we remove the self join. But this requires further investigation.
For now, we just do not remove self joins if the rel to be removed is laterally
referenced by PHVs.
Discussion: https://postgr.es/m/CAMbWs4-ns73VF9gi37q61G3dS6Xuos+HtryMaBh37WQn=BsaJw@mail.gmail.com
Author: Richard Guo
Peter Eisentraut [Fri, 10 Nov 2023 10:56:52 +0000 (11:56 +0100)]
Fix whitespace
Fix trailing whitespace from commit
322f55bdbd.
Amit Kapila [Fri, 10 Nov 2023 03:15:01 +0000 (08:45 +0530)]
Prohibit max_slot_wal_keep_size to value other than -1 during upgrade.
We don't want existing slots in the old cluster to get invalidated during
the upgrade. During an upgrade, we set this variable to -1 via the command
line in an attempt to prevent such invalidations, but users have ways to
override it. This patch ensures the value is not overridden by the user.
Author: Kyotaro Horiguchi
Reviewed-by: Peter Smith, Alvaro Herrera
Discussion: http://postgr.es/m/
20231027.115759.
2206827438943188717[email protected]
Bruce Momjian [Thu, 9 Nov 2023 22:51:19 +0000 (17:51 -0500)]
doc: fix wording describing the checkpoint_flush_after GUC
Reported-by: Evan Macbeth
Discussion: https://postgr.es/m/
155208475619.1380.
12815553062985622271@wrigleys.postgresql.org
Backpatch-through: master
Bruce Momjian [Thu, 9 Nov 2023 21:44:39 +0000 (16:44 -0500)]
doc: remove unnecessary comma in postgres-fdw
Backpatch-through: master
Tom Lane [Thu, 9 Nov 2023 20:46:16 +0000 (15:46 -0500)]
Fix computation of varnullingrels when const-folding field selection.
We can simplify FieldSelect on a whole-row Var into a plain Var
for the selected field. However, we should copy the whole-row Var's
varnullingrels when we do so, because the new Var is clearly nullable
by exactly the same rels as the original. Failure to do this led to
errors like "wrong varnullingrels (b) (expected (b 3)) for Var 2/2".
Richard Guo, per bug #18184 from Marian Krucina. Back-patch to
v16 where varnullingrels was introduced.
Discussion: https://postgr.es/m/18184-
5868dd258782058e@postgresql.org
Peter Eisentraut [Thu, 9 Nov 2023 14:05:58 +0000 (15:05 +0100)]
meson: Install missing example files
Install the example files from contrib/spi/, to match makefiles.
Reviewed-by: Tristan Partin <[email protected]>
Reviewed-by: Andres Freund <[email protected]>
Discussion: https://www.postgresql.org/message-id/
b018b577-38a2-49c6-8727-
adfb577de317@eisentraut.org
Peter Eisentraut [Thu, 9 Nov 2023 14:05:58 +0000 (15:05 +0100)]
meson: Fix doc installation path computation
This applies the logic from
8f6858064b (append "postgresql" to some
installation paths if it does not already contain "pgsql" or
"postgres") also to the doc installation directory.
Reviewed-by: Tristan Partin <[email protected]>
Reviewed-by: Andres Freund <[email protected]>
Discussion: https://www.postgresql.org/message-id/
b018b577-38a2-49c6-8727-
adfb577de317@eisentraut.org
Alexander Korotkov [Thu, 9 Nov 2023 12:06:11 +0000 (14:06 +0200)]
Fix the way SJE removes references from PHVs
Add missing replacement of relids in phv->phexpr. Also, remove extra
replace_relid() over phv->phrels.
Reported-by: Zuming Jiang
Bug: #18187
Discussion: https://postgr.es/m/flat/18187-
831da249cbd2ff8e%40postgresql.org
Author: Richard Guo
Reviewed-by: Andrei Lepikhov
Dean Rasheed [Thu, 9 Nov 2023 12:10:14 +0000 (12:10 +0000)]
Avoid integer overflow hazard in interval_time().
When casting an interval to a time, the original code suffered from
64-bit integer overflow for inputs with a sufficiently large negative
"time" field, leading to bogus results.
Fix by rewriting the algorithm in a simpler form, that more obviously
cannot overflow. While at it, improve the test coverage to include
negative interval inputs.
Discussion: https://postgr.es/m/CAEZATCXoUKHkcuq4q63hkiPsKZJd0kZWzgKtU%2BNT0aU4wbf_Pw%40mail.gmail.com
Dean Rasheed [Thu, 9 Nov 2023 11:23:42 +0000 (11:23 +0000)]
Fix AFTER ROW trigger execution in MERGE cross-partition update.
When executing a MERGE UPDATE action, if the UPDATE is turned into a
cross-partition DELETE then INSERT, do not attempt to invoke AFTER
UPDATE ROW triggers, or any of the other post-update actions in
ExecUpdateEpilogue().
For consistency with a plain UPDATE command, such triggers should not
be fired (and typically fail anyway), and similarly, other post-update
actions, such as WCO/RLS checks should not be executed, and might also
lead to unexpected failures.
Therefore, as with ExecUpdate(), make ExecMergeMatched() return
immediately if ExecUpdateAct() reports that a cross-partition update
was done, to be sure that no further processing is done for that
tuple.
Back-patch to v15, where MERGE was introduced.
Discussion: https://postgr.es/m/CAEZATCWjBgagyNZs02vgDF0DvASYj-iHTFtXG2-nP3orZhmtcw%40mail.gmail.com
David Rowley [Thu, 9 Nov 2023 11:15:54 +0000 (00:15 +1300)]
Ensure we use the correct spelling of "ensure"
We seem to have accidentally used "insure" in a few places. Correct
that.
Author: Peter Smith
Discussion: https://postgr.es/m/CAHut+Pv0biqrhA3pMhu40aDsj343mTsD75khKnHsLqR8P04f=Q@mail.gmail.com
Backpatch-through: 12, oldest supported version
Dean Rasheed [Thu, 9 Nov 2023 09:50:23 +0000 (09:50 +0000)]
Fix corner-case 64-bit integer subtraction bug on some platforms.
When computing "0 - INT64_MIN", most platforms would report an
overflow error, which is correct. However, platforms without integer
overflow builtins or 128-bit integers would fail to spot the overflow,
and incorrectly return INT64_MIN.
Back-patch to all supported branches.
Patch be me. Thanks to Jian He for initial investigation, and Laurenz
Albe and Tom Lane for review.
Discussion: https://postgr.es/m/CAEZATCUNK-AZSD0jVdgkk0N%3DNcAXBWeAEX-QU9AnJPensikmdQ%40mail.gmail.com
Amit Kapila [Thu, 9 Nov 2023 03:56:40 +0000 (09:26 +0530)]
Fix uninitialized slot array access during the upgrade.
Commit
29d0a77fa introduced fetching slot information from the old cluster
but didn't initialize the required array in all the code paths. So when
trying to access the array in verbose mode for the new cluster, it leads
to an uninitialized memory access.
Author: Vignesh C
Discussion: http://postgr.es/m/CALDaNm1tntGP5=CtMz=v+k3_PGv7kE9t6iWSgX-QiurAaFkhZw@mail.gmail.com
Michael Paquier [Thu, 9 Nov 2023 01:04:31 +0000 (10:04 +0900)]
pg_stat_statements: Remove duplicated tests for SET statements
This looks like a copy-paste mistake introduced in
de2aca288569, that
has added checks for more patterns of SET statements while ignoring the
original test block that existed.
Backpatch down to where this has been introduced, as this shaves some
cycles.
Author: Sergei Kornilov
Discussion: https://postgr.es/m/
5689421699428803@mail-sendbernar-production-main-46.myt.yp-c.yandex.net
Backpatch-through: 16
Heikki Linnakangas [Wed, 8 Nov 2023 23:33:14 +0000 (01:33 +0200)]
Fix bug in the new ResourceOwner implementation.
When the hash table is in use, ResoureOwnerSort() moves any elements
from the small fixed-size array to the hash table, and sorts it. When
the hash table is not in use, it sorts the elements in the small
fixed-size array directly. However, ResourceOwnerSort() and
ResourceOwnerReleaseAll() had different idea on when the hash table is
in use: ResourceOwnerSort() checked owner->nhash != 0, and
ResourceOwnerReleaseAll() checked owner->hash != NULL. If the hash
table was allocated but was currently empty, you hit an assertion
failure.
Reported-by: Alexander Lakhin <[email protected]>
Discussion: https://www.postgresql.org/message-id/
be58d565-9e95-d417-4e47-
f6bd408dea4b@gmail.com
Bruce Momjian [Wed, 8 Nov 2023 21:48:43 +0000 (16:48 -0500)]
doc:: simplify introductory text
Reported-by: Joshua D. Drake
Discussion: https://postgr.es/m/
5ac2c96d-37a6-18aa-08c4-
327a6fbff24b@commandprompt.com
Author: Joshua D. Drake
Backpatch-through: master
Bruce Momjian [Wed, 8 Nov 2023 21:36:18 +0000 (16:36 -0500)]
README: remove duplicate download link & mention related softw.
Reported-by: Daniel Westermann
Discussion: https://postgr.es/m/DB6PR0902MB2184F7965C9EA9070ACFCA43D2A80@DB6PR0902MB2184.eurprd09.prod.outlook.com
Backpatch-through: master
Bruce Momjian [Wed, 8 Nov 2023 21:16:20 +0000 (16:16 -0500)]
doc: change "system" to "cluster" where appropriate
Reported-by: Jeff Davis
Discussion: https://postgr.es/m/
d040a1144e0127a49e335d1244a4de102a2a443b[email protected]
Backpatch-through: master
Bruce Momjian [Wed, 8 Nov 2023 21:04:42 +0000 (16:04 -0500)]
doc: mention that ANALYZE does block DDL
Reported-by: Aramaki Zyake
Discussion: https://postgr.es/m/
156628723253.1296.
7377373462603881976%40wrigleys.postgresql.org
Author: Aramaki Zyake
Backpatch-through: master
Alvaro Herrera [Wed, 8 Nov 2023 17:44:54 +0000 (18:44 +0100)]
Check stack depth in new recursive functions
Commit
b0e96f311985 introduced a bunch of recursive functions, but
failed to make them check for stack depth. This can cause the backend
to crash when operating on inheritance hierarchies several thousands
deep. Protect the code by adding the missing stack depth checks.
Reported-by: Alexander Lakhin <[email protected]>
Discussion: https://postgr.es/m/
b2ac2392-9727-5f76-e890-
721ac80c1615@gmail.com
Tom Lane [Wed, 8 Nov 2023 17:01:28 +0000 (12:01 -0500)]
Fix some issues with tracking nesting level in pg_stat_statements.
When we decide that we don't want to track execution time of a
specific planner or ProcessUtility call, we still have to increment
the nesting depth, or we'll make the wrong determination of whether
we are at top level when considering nested statements. (PREPARE
and EXECUTE are exceptions, for reasons explained in the code.)
Counting planner nesting depth separately from executor nesting depth
was a mistake: it causes us to make the wrong determination of whether
we are at top level when considering nested statements that get
executed during planning (as a result of constant-folding of
functions, for example). Merge those counters into one.
In passing, get rid of the PGSS_HANDLED_UTILITY macro in favor of
explicitly listing statement types. It seems somewhat coincidental
that PREPARE and EXECUTE are handled alike in each of the places where
that was used: the reasoning tends to be different for each one.
Thus, the macro seems as likely to encourage future bugs as prevent
them, since it's quite unclear whether any future statement type that
might need special-casing here would also need the same choices at
each spot.
Sergei Kornilov, Julien Rouhaud, and Tom Lane, per bug #17552 from
Maxim Boguk. This is pretty clearly a bug fix, but it's also a
behavioral change that might surprise somebody, so no back-patch.
Discussion: https://postgr.es/m/17552-
213b534c56ab5d02@postgresql.org
Alvaro Herrera [Wed, 8 Nov 2023 15:44:08 +0000 (16:44 +0100)]
Call pqPipelineFlush from PQsendFlushRequest
When PQsendFlushRequest() was added by commit
69cf1d5429d4, we argued
against adding a PQflush() call in it[1]. This is still the right
decision: if the user wants a flush to occur, they can just call that.
However, we failed to realize that the message bytes could still be
given to the kernel for transmitting when this can be made without
blocking. That's what pqPipelineFlush() does, and it is done for every
single other message type sent by libpq, so do that.
(When the socket is in blocking mode this may indeed block, but that's
what all the other libpq message-sending routines do, too.)
[1] https://www.postgresql.org/message-id/
202106252352.5ca4byasfun5%40alvherre.pgsql
Author: Jelte Fennema-Nio <
[email protected]>
Discussion: https://postgr.es/m/CAGECzQTxZRevRWkKodE-SnJk1Yfm4eKT+8E4Cyq3MJ9YKTnNew@mail.gmail.com
Heikki Linnakangas [Wed, 8 Nov 2023 11:30:55 +0000 (13:30 +0200)]
Change pgcrypto to use the new ResourceOwner mechanism.
This is a nice example of how extensions can now use ResourceOwners to
track extension-specific resource kinds
Reviewed-by: Peter Eisentraut, Andres Freund
Discussion: https://www.postgresql.org/message-id/
d746cead-a1ef-7efe-fb47-
933311e876a3%40iki.fi
Heikki Linnakangas [Wed, 8 Nov 2023 11:30:52 +0000 (13:30 +0200)]
Use a faster hash function in resource owners.
This buys back some of the performance loss that we otherwise saw from the
previous commit.
Reviewed-by: Aleksander Alekseev, Michael Paquier, Julien Rouhaud
Reviewed-by: Kyotaro Horiguchi, Hayato Kuroda, Álvaro Herrera, Zhihong Yu
Reviewed-by: Peter Eisentraut, Andres Freund
Discussion: https://www.postgresql.org/message-id/
d746cead-a1ef-7efe-fb47-
933311e876a3%40iki.fi
Heikki Linnakangas [Wed, 8 Nov 2023 11:30:50 +0000 (13:30 +0200)]
Make ResourceOwners more easily extensible.
Instead of having a separate array/hash for each resource kind, use a
single array and hash to hold all kinds of resources. This makes it
possible to introduce new resource "kinds" without having to modify
the ResourceOwnerData struct. In particular, this makes it possible
for extensions to register custom resource kinds.
The old approach was to have a small array of resources of each kind,
and if it fills up, switch to a hash table. The new approach also uses
an array and a hash, but now the array and the hash are used at the
same time. The array is used to hold the recently added resources, and
when it fills up, they are moved to the hash. This keeps the access to
recent entries fast, even when there are a lot of long-held resources.
All the resource-specific ResourceOwnerEnlarge*(),
ResourceOwnerRemember*(), and ResourceOwnerForget*() functions have
been replaced with three generic functions that take resource kind as
argument. For convenience, we still define resource-specific wrapper
macros around the generic functions with the old names, but they are
now defined in the source files that use those resource kinds.
The release callback no longer needs to call ResourceOwnerForget on
the resource being released. ResourceOwnerRelease unregisters the
resource from the owner before calling the callback. That needed some
changes in bufmgr.c and some other files, where releasing the
resources previously always called ResourceOwnerForget.
Each resource kind specifies a release priority, and
ResourceOwnerReleaseAll releases the resources in priority order. To
make that possible, we have to restrict what you can do between
phases. After calling ResourceOwnerRelease(), you are no longer
allowed to remember any more resources in it or to forget any
previously remembered resources by calling ResourceOwnerForget. There
was one case where that was done previously. At subtransaction commit,
AtEOSubXact_Inval() would handle the invalidation messages and call
RelationFlushRelation(), which temporarily increased the reference
count on the relation being flushed. We now switch to the parent
subtransaction's resource owner before calling AtEOSubXact_Inval(), so
that there is a valid ResourceOwner to temporarily hold that relcache
reference.
Other end-of-xact routines make similar calls to AtEOXact_Inval()
between release phases, but I didn't see any regression test failures
from those, so I'm not sure if they could reach a codepath that needs
remembering extra resources.
There were two exceptions to how the resource leak WARNINGs on commit
were printed previously: llvmjit silently released the context without
printing the warning, and a leaked buffer io triggered a PANIC. Now
everything prints a WARNING, including those cases.
Add tests in src/test/modules/test_resowner.
Reviewed-by: Aleksander Alekseev, Michael Paquier, Julien Rouhaud
Reviewed-by: Kyotaro Horiguchi, Hayato Kuroda, Álvaro Herrera, Zhihong Yu
Reviewed-by: Peter Eisentraut, Andres Freund
Discussion: https://www.postgresql.org/message-id/
cbfabeb0-cd3c-e951-a572-
19b365ed314d%40iki.fi
Heikki Linnakangas [Wed, 8 Nov 2023 11:30:46 +0000 (13:30 +0200)]
Move a few ResourceOwnerEnlarge() calls for safety and clarity.
These are functions where a lot of things happen between the
ResourceOwnerEnlarge and ResourceOwnerRemember calls. It's important
that there are no unrelated ResourceOwnerRemember calls in the code in
between, otherwise the reserved entry might be used up by the
intervening ResourceOwnerRemember and not be available at the intended
ResourceOwnerRemember call anymore. I don't see any bugs here, but the
longer the code path between the calls is, the harder it is to verify.
In bufmgr.c, there is a function similar to ResourceOwnerEnlarge,
ReservePrivateRefCountEntry(), to ensure that the private refcount
array has enough space. The ReservePrivateRefCountEntry() calls were
made at different places than the ResourceOwnerEnlargeBuffers()
calls. Move the ResourceOwnerEnlargeBuffers() and
ReservePrivateRefCountEntry() calls together for consistency.
Reviewed-by: Aleksander Alekseev, Michael Paquier, Julien Rouhaud
Reviewed-by: Kyotaro Horiguchi, Hayato Kuroda, Álvaro Herrera, Zhihong Yu
Reviewed-by: Peter Eisentraut, Andres Freund
Discussion: https://www.postgresql.org/message-id/
cbfabeb0-cd3c-e951-a572-
19b365ed314d%40iki.fi
Peter Eisentraut [Wed, 8 Nov 2023 10:27:28 +0000 (11:27 +0100)]
Don't install ldap_password_func in meson
It should be handled as a test module per commit
b6a0d469ca.
Michael Paquier [Wed, 8 Nov 2023 08:29:02 +0000 (17:29 +0900)]
Fix use of OPENSSL in SSL tests if command is not found
`openssl` is an optional dependency in the meson build as it may not be
installed in an environment even if SSL libraries are around. The meson
scripts assume that, but the SSL tests thought that it was a hard
dependency, causing a meson installation to fail if `openssl` could not
be found. Like similar tests that depend on external commands, and to
be consistent with ./configure for the SSL tests, this commit makes the
command existence optional in the tests.
Author: Tristan Partin
Discussion: https://postgr.es/m/
[email protected]
Backpatch-through: 16
Michael Paquier [Wed, 8 Nov 2023 05:06:26 +0000 (14:06 +0900)]
Enlarge assertion in bloom_init() for false_positive_rate
false_positive_rate is a parameter that can be set with the bloom
opclass in BRIN, and setting it to a value of exactly 0.25 would trigger
an assertion in the first INSERT done on the index with value set.
The assertion changed here relied on BLOOM_{MIN|MAX}_FALSE_POSITIVE_RATE
that are somewhat arbitrary values, and specifying an out-of-range value
would also trigger a failure when defining such an index. So, as-is,
the assertion was just doubling on the min-max check of the reloption.
This is now enlarged to check that it is a correct percentage value,
instead, based on a suggestion by Tom Lane.
Author: Alexander Lakhin
Reviewed-by: Tom Lane, Shihao Zhong
Discussion: https://postgr.es/m/17969-
a6c54de48026d694@postgresql.org
Backpatch-through: 14
Alvaro Herrera [Tue, 7 Nov 2023 18:26:39 +0000 (19:26 +0100)]
Stop including parsenodes.h in plannodes.h
I added it by mistake in commit
7103ebb7aae8. To clean up, struct
MergeAction needs to be moved to primnodes.h from parsenodes.h. (This
forces us to also move OverridingKind to primnodes.h).
Having to add parsenodes.h to bootstrap.h as fallout is a bit
surprising, since nothing nominally needs it there. However, per
comments in bootscanner.l, it is needed so that YYSTYPE can be declared.
I think this only started with commit
dac048f71ebb, but I didn't
actually verify that.
In passing, stop including parsenodes.h in tcopprot.h. Nothing needs it
there.
Per discussion on a patch by Ashutosh Bapat.
Reviewed-by: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/
202311071106[email protected]
Peter Eisentraut [Tue, 7 Nov 2023 06:58:14 +0000 (07:58 +0100)]
citext: Allow tests to pass in OpenSSL FIPS mode
citext doesn't define an md5() function, so the value of using it in
its tests is dubious. At best this shows in an indirect way that the
cast from citext to text works. Avoid the issue and remove the test.
Discussion: https://www.postgresql.org/message-id/flat/
dbbd927f-ef1f-c9a1-4ec6-
c759778ac852%40enterprisedb.com
Amit Kapila [Tue, 7 Nov 2023 06:02:33 +0000 (11:32 +0530)]
Fix the test 003_logical_slots.
pg_upgrade test 003_logical_slots was leaving files like
delete_old_cluster.sh in the source directory for VPATH and meson builds.
The fix is to change the directory to tmp_check before running the test as
is done in the similar test in 002_pg_upgrade.
Reported-by: Peter Eisentraut, Andrew Dunstan
Author: Hayato Kuroda based on a suggestion by Andrew Dunstan
Reviewed-by: Peter Smith, Hou Zhijie
Discussion: http://postgr.es/m/
b4fb612d-ef0b-4db7-81b9-
cf0701275491@eisentraut.org
Discussion: http://postgr.es/m/TYAPR01MB5866D7B89DC5688256D980C2F5A9A@TYAPR01MB5866.jpnprd01.prod.outlook.com
Michael Paquier [Tue, 7 Nov 2023 02:55:13 +0000 (11:55 +0900)]
Reorder two functions in inval.c
This file separates public and static functions with a separator
comment, but two routines were not defined in a location reflecting
that, so reorder them.
Author: Aleksander Alekseev
Reviewed-by: Álvaro Herrera, Michael Paquier
Discussion: https://postgr.es/m/CAJ7c6TMX2dd0g91UKvcC+CVygKQYJkKJq1+ZzT4rOK42+b53=w@mail.gmail.com
David Rowley [Mon, 6 Nov 2023 22:16:43 +0000 (11:16 +1300)]
Make use of initReadOnlyStringInfo() in more places
f0efa5aec introduced the concept of "read-only" StringInfos which makes
use of an existing, possibly not NUL terminated, buffer.
Here we adjust two places that make use of StringInfos to receive data
to avoid using appendBinaryStringInfo() in cases where a NUL termination
character is not required. This saves a possible palloc() and saves
having to needlessly memcpy() from one buffer to another.
Here we adjust two places which were using appendBinaryStringInfo().
Neither of these cases seem particularly performance-critical. In the
case of XLogWalRcvProcessMsg(), the appendBinaryStringInfo() was only
appending 24 bytes. The change made here does mean that we can get rid
of the incoming_message global variable and make that local instead.
The apply_spooled_messages() case applies in logical decoding when
applying (possibly large) changes which have been serialized to a file.
Reviewed-by: Amit Kapila
Discussion: https://postgr.es/m/CAApHDvoxYUDHwqPf-ShvchsERf1RzmkGoLwg63JNvHCkDCuyKQ@mail.gmail.com
Tom Lane [Mon, 6 Nov 2023 15:56:43 +0000 (10:56 -0500)]
Detect integer overflow while computing new array dimensions.
array_set_element() and related functions allow an array to be
enlarged by assigning to subscripts outside the current array bounds.
While these places were careful to check that the new bounds are
allowable, they neglected to consider the risk of integer overflow
in computing the new bounds. In edge cases, we could compute new
bounds that are invalid but get past the subsequent checks,
allowing bad things to happen. Memory stomps that are potentially
exploitable for arbitrary code execution are possible, and so is
disclosure of server memory.
To fix, perform the hazardous computations using overflow-detecting
arithmetic routines, which fortunately exist in all still-supported
branches.
The test cases added for this generate (after patching) errors that
mention the value of MaxArraySize, which is platform-dependent.
Rather than introduce multiple expected-files, use psql's VERBOSITY
parameter to suppress the printing of the message text. v11 psql
lacks that parameter, so omit the tests in that branch.
Our thanks to Pedro Gallegos for reporting this problem.
Security: CVE-2023-5869
Tom Lane [Mon, 6 Nov 2023 15:38:00 +0000 (10:38 -0500)]
Compute aggregate argument types correctly in transformAggregateCall().
transformAggregateCall() captures the datatypes of the aggregate's
arguments immediately to construct the Aggref.aggargtypes list.
This seems reasonable because the arguments have already been
transformed --- but there is an edge case where they haven't been.
Specifically, if we have an unknown-type literal in an ANY argument
position, nothing will have been done with it earlier. But if we
also have DISTINCT, then addTargetToGroupList() converts the literal
to "text" type, resulting in the aggargtypes list not matching the
actual runtime type of the argument. The end result is that the
aggregate tries to interpret a "text" value as being of type
"unknown", that is a zero-terminated C string. If the text value
contains no zero bytes, this could result in disclosure of server
memory following the text literal value.
To fix, move the collection of the aggargtypes list to the end
of transformAggregateCall(), after DISTINCT has been handled.
This requires slightly more code, but not a great deal.
Our thanks to Jingzhou Fu for reporting this problem.
Security: CVE-2023-5868
Peter Eisentraut [Mon, 6 Nov 2023 13:51:52 +0000 (14:51 +0100)]
Remove distprep
A PostgreSQL release tarball contains a number of prebuilt files, in
particular files produced by bison, flex, perl, and well as html and
man documentation. We have done this consistent with established
practice at the time to not require these tools for building from a
tarball. Some of these tools were hard to get, or get the right
version of, from time to time, and shipping the prebuilt output was a
convenience to users.
Now this has at least two problems:
One, we have to make the build system(s) work in two modes: Building
from a git checkout and building from a tarball. This is pretty
complicated, but it works so far for autoconf/make. It does not
currently work for meson; you can currently only build with meson from
a git checkout. Making meson builds work from a tarball seems very
difficult or impossible. One particular problem is that since meson
requires a separate build directory, we cannot make the build update
files like gram.h in the source tree. So if you were to build from a
tarball and update gram.y, you will have a gram.h in the source tree
and one in the build tree, but the way things work is that the
compiler will always use the one in the source tree. So you cannot,
for example, make any gram.y changes when building from a tarball.
This seems impossible to fix in a non-horrible way.
Second, there is increased interest nowadays in precisely tracking the
origin of software. We can reasonably track contributions into the
git tree, and users can reasonably track the path from a tarball to
packages and downloads and installs. But what happens between the git
tree and the tarball is obscure and in some cases non-reproducible.
The solution for both of these issues is to get rid of the step that
adds prebuilt files to the tarball. The tarball now only contains
what is in the git tree (*). Getting the additional build
dependencies is no longer a problem nowadays, and the complications to
keep these dual build modes working are significant. And of course we
want to get the meson build system working universally.
This commit removes the make distprep target altogether. The make
dist target continues to do its job, it just doesn't call distprep
anymore.
(*) - The tarball also contains the INSTALL file that is built at make
dist time, but not by distprep. This is unchanged for now.
The make maintainer-clean target, whose job it is to remove the
prebuilt files in addition to what make distclean does, is now just an
alias to make distprep. (In practice, it is probably obsolete given
that git clean is available.)
The following programs are now hard build requirements in configure
(they were already required by meson.build):
- bison
- flex
- perl
Reviewed-by: Michael Paquier <[email protected]>
Reviewed-by: Andres Freund <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/
e07408d9-e5f2-d9fd-5672-
f53354e9305e@eisentraut.org
Noah Misch [Mon, 6 Nov 2023 14:14:13 +0000 (06:14 -0800)]
Set GUC "is_superuser" in all processes that set AuthenticatedUserId.
It was always false in single-user mode, in autovacuum workers, and in
background workers. This had no specifically-identified security
consequences, but non-core code or future work might make it
security-relevant. Back-patch to v11 (all supported versions).
Jelte Fennema-Nio. Reported by Jelte Fennema-Nio.
Noah Misch [Mon, 6 Nov 2023 14:14:13 +0000 (06:14 -0800)]
Ban role pg_signal_backend from more superuser backend types.
Documentation says it cannot signal "a backend owned by a superuser".
On the contrary, it could signal background workers, including the
logical replication launcher. It could signal autovacuum workers and
the autovacuum launcher. Block all that. Signaling autovacuum workers
and those two launchers doesn't stall progress beyond what one could
achieve other ways. If a cluster uses a non-core extension with a
background worker that does not auto-restart, this could create a denial
of service with respect to that background worker. A background worker
with bugs in its code for responding to terminations or cancellations
could experience those bugs at a time the pg_signal_backend member
chooses. Back-patch to v11 (all supported versions).
Reviewed by Jelte Fennema-Nio. Reported by Hemanth Sandrana and
Mahendrakar Srinivasarao.
Security: CVE-2023-5870
Daniel Gustafsson [Mon, 6 Nov 2023 08:38:29 +0000 (09:38 +0100)]
Add XMLText function (SQL/XML X038)
This function implements the standard XMLTest function, which
converts text into xml text nodes. It uses the libxml2 function
xmlEncodeSpecialChars to escape predefined entities (&"<>), so
that those do not cause any conflict when concatenating the text
node output with existing xml documents.
This also adds a note in features.sgml about not supporting
XML(SEQUENCE). The SQL specification defines a RETURNING clause
to a set of XML functions, where RETURNING CONTENT or RETURNING
SEQUENCE can be defined. Since PostgreSQL doesn't support
XML(SEQUENCE) all of these functions operate with an
implicit RETURNING CONTENT.
Author: Jim Jones <
[email protected]>
Reviewed-by: Vik Fearing <[email protected]>
Discussion: https://postgr.es/m/
86617a66-ec95-581f-8d54-
08059cca8885@uni-muenster.de
Peter Eisentraut [Mon, 6 Nov 2023 08:05:17 +0000 (09:05 +0100)]
pg_resetwal: Add more tests and test coverage
pg_resetwal had poor test coverage. There are some TAP tests, but
they all run with -n, so they don't actually test the full
functionality. (There is a non-dry-run call of pg_resetwal in the
recovery test suite, but that is incidental.)
This adds a bunch of more tests to test all the different options and
scenarios.
Reviewed-by: Aleksander Alekseev <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/
0f3ab4a1-ae80-56e8-3426-
6b4a02507687@eisentraut.org
Peter Eisentraut [Mon, 6 Nov 2023 07:17:54 +0000 (08:17 +0100)]
doc: pg_resetwal: Add comments how the multipliers are derived
Reviewed-by: Aleksander Alekseev <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/
0f3ab4a1-ae80-56e8-3426-
6b4a02507687@eisentraut.org
Alexander Korotkov [Mon, 6 Nov 2023 08:02:52 +0000 (10:02 +0200)]
Fix allocation of UniqueRelInfo
Reported-by: Richard Guo
Discussion: https://postgr.es/m/CAMbWs4_STsG1PKQBuvQC8W4sPo3KvML3=jOTjKLUYQuK3g8cpQ@mail.gmail.com
Peter Eisentraut [Sun, 5 Nov 2023 20:59:04 +0000 (21:59 +0100)]
More consistent behavior of GetDataDirectoryCreatePerm on Windows
On Windows, GetDataDirectoryCreatePerm() just did nothing. The way
the code in some callers is structured, this is the first function
that tries to access the data directory. So it also ends up the place
that is responsible for reporting that a data directory does not exist
or similar. Therefore, on Windows, these scenarios end up on
potentially completely different code paths.
To unify this, to make testing more consistent across platforms, have
GetDataDirectoryCreatePerm() run the stat() call on Windows as well,
even though it won't do anything with the result. That way, file
system errors are reporting to callers in the same way as on
non-Windows.
Reviewed-by: Aleksander Alekseev <[email protected]>
Discussion: https://www.postgresql.org/message-id/
15a59bca-0383-183c-9383-
0446da9b87e1%40eisentraut.org
David Rowley [Sat, 4 Nov 2023 02:41:16 +0000 (15:41 +1300)]
Try again to fix the MSVC build
My last attempt in
39c959ef2 mistakenly conditionally added the missing
file based on some unrelated condition.
Reported-by: Thomas Munro
Discussion: https://postgr.es/m/CA+hUKGLovvAXim9Fytn=jxks9s=JhP5=8Oyy0cbxGG-ggALJtg@mail.gmail.com
Alexander Korotkov [Sat, 4 Nov 2023 01:30:18 +0000 (03:30 +0200)]
Fix usage of the parse tree for estimate_num_groups() in set operations
recurse_set_operations() uses the parse tree for the group number estimation,
because of the "varno 0" hack. At the same time
2489d76c49 made root->parse
and corresponding parent_root->simple_rte_array[]->subquery distinct copies
of the parse tree, while
d3d55ce571 introduced self-join removal replacing
relid of removed relation only in one of the copies.
The present commit fixes this bug by making recurse_set_operations() call
estimate_num_groups() with the copy of the parse tree processed by self-join
removal.
In future, we may think about maintaining just one copy of the parse tree
and/or keeping removed relids as aliases.
Reported-by: Zuming Jiang
Bug: #18170
Discussion: https://postgr.es/m/flat/18170-
f1d17bf9a0d58b24%40postgresql.org
Author: Richard Guo, Alexander Korotkov
Reviewed-by: Andrei Lepikhov
Andres Freund [Fri, 3 Nov 2023 18:46:52 +0000 (11:46 -0700)]
meson: docs: Install all manpages, not just ones in man1
In
f13eb16485f I made a mistake leading to only man1 being installed. I will
report a bug suggesting that meson warn about mistakes of this sort.
Reported-by: Christoph Berg <[email protected]>
Discussion: https://postgr.es/m/
[email protected]
Backpatch: 16-, where the meson build was introduced
Bruce Momjian [Fri, 3 Nov 2023 18:03:22 +0000 (14:03 -0400)]
doc: move HBA reload instructions above the syntax details
Reported-by: John <[email protected]>
Discussion: https://postgr.es/m/
165947088723.651.
7641196693246068619@wrigleys.postgresql.org
Backpatch-through: master
Bruce Momjian [Fri, 3 Nov 2023 17:57:59 +0000 (13:57 -0400)]
doc: \copy can get data values \. and end-of-input confused
Reported-by: Svante Richter
Discussion: https://postgr.es/m/
fcd57e4-8f23-4c3e-a5db-
2571d09208e2@beta.fastmail.com
Backpatch-through: 11
Bruce Momjian [Fri, 3 Nov 2023 17:39:50 +0000 (13:39 -0400)]
doc: CREATE DATABASE doesn't copy db-level perms. from template
Reported-by: [email protected]
Discussion: https://postgr.es/m/
166007719137.995877.
13951579839074751714@wrigleys.postgresql.org
Backpatch-through: 11
Bruce Momjian [Fri, 3 Nov 2023 17:05:27 +0000 (13:05 -0400)]
doc: mention ORDER BY for some aggregates, add ORDER BY examples
Discussion: https://postgr.es/m/CAKFQuwb+4SWnfrfQKB-UM1P1x97Xk+ybSar4xM32XGLd=fq9bA@mail.gmail.com
Co-authored-by: David G. Johnston
Backpatch-through: master
Tom Lane [Fri, 3 Nov 2023 15:48:23 +0000 (11:48 -0400)]
Doc: update CREATE RULE ref page's hoary discussion of views.
This text left one with the impression that an ON SELECT rule could
be attached to a plain table, which has not been true since commit
264c06820 (meaning the text was already misleading when written,
evidently by me in
96bd67f61). However, it didn't get really bad
until
b23cd185f removed the convert-a-table-to-a-view logic, which
had made it possible for scripts that thought they were attaching
ON SELECTs to tables to still work.
Rewrite into a form that makes it clear that an ON SELECT rule
is better regarded as an implementation detail of a view.
Pre-v16, point out that adding ON SELECT to a table actually
converts it to a view.
Per bug #18178 from Joshua Uyehara. Back-patch to all supported
branches.
Discussion: https://postgr.es/m/18178-
05534d7064044d2d@postgresql.org
Bruce Momjian [Fri, 3 Nov 2023 13:51:53 +0000 (09:51 -0400)]
doc: ALTER DEFAULT PRIVILEGES does not affect inherited roles
Reported-by: Jordi Gutiérrez Hermoso
Discussion: https://postgr.es/m/
72652d72e1816bfc3c05d40f9e0e0373d07823c8[email protected]
Co-authored-by: Laurenz Albe
Backpatch-through: 11
David Rowley [Fri, 3 Nov 2023 07:12:36 +0000 (20:12 +1300)]
Add missing unicode_category.c to MSVC build scripts
Fixes MSVC build failure introduced by
a02b37fc0
David Rowley [Thu, 2 Nov 2023 23:35:37 +0000 (12:35 +1300)]
Stabilize postgres_fdw tests on 32-bit machines
cac169d68 adjusted DEFAULT_FDW_TUPLE_COST and that seems to have caused
a test to become unstable on 32-bit machines.
4b14e1871 tried to fix this as originally the plan was flipping between
a Nested Loop and Hash Join. That commit forced the Nested Loop, but
there's still flexibility to push or not push the sort to the remote
server and 32-bit seems to prefer to push and on 64-bit, the costs
prefer not to.
Here let's just turn off enable_sort to significantly encourage the sort
to take place on the remote server.
Reported-by: Michael Paquier, Richard Guo
Discussion: https://postgr.es/m/
[email protected]
Tom Lane [Thu, 2 Nov 2023 15:53:36 +0000 (11:53 -0400)]
Make GetConfigOption/GetConfigOptionResetString return "" for NULL.
As per the preceding commit, GUC APIs generally expose NULL-valued
string variables as empty strings. Extend that policy to
GetConfigOption() and GetConfigOptionResetString(), eliminating
a crash hazard for unwary callers, as well as a fundamental
ambiguity in GetConfigOption()'s API.
No back-patch, since this is an API change and conceivably somebody
somewhere is depending on this corner case.
Xing Guo, Aleksander Alekseev, Tom Lane
Discussion: https://postgr.es/m/CACpMh+AyDx5YUpPaAgzVwC1d8zfOL4JoD-uyFDnNSa1z0EsDQQ@mail.gmail.com
Tom Lane [Thu, 2 Nov 2023 15:47:33 +0000 (11:47 -0400)]
Be more wary about NULL values for GUC string variables.
get_explain_guc_options() crashed if a string GUC marked GUC_EXPLAIN
has a NULL boot_val. Nosing around found a couple of other places
that seemed insufficiently cautious about NULL string values, although
those are likely unreachable in practice. Add some commentary
defining the expectations for NULL values of string variables,
in hopes of forestalling future additions of more such bugs.
Xing Guo, Aleksander Alekseev, Tom Lane
Discussion: https://postgr.es/m/CACpMh+AyDx5YUpPaAgzVwC1d8zfOL4JoD-uyFDnNSa1z0EsDQQ@mail.gmail.com
David Rowley [Thu, 2 Nov 2023 10:16:34 +0000 (23:16 +1300)]
Attempt to stabilize postgres_fdw tests
cac169d68 adjusted DEFAULT_FDW_TUPLE_COST and that seems to have caused
a test to become unstable on 32-bit machines. Try to make it stable
again.
Reported-by: Michael Paquier
Discussion: https://postgr.es/m/
[email protected]
Jeff Davis [Thu, 2 Nov 2023 05:47:06 +0000 (22:47 -0700)]
Additional unicode primitive functions.
Introduce unicode_version(), icu_unicode_version(), and
unicode_assigned().
The latter requires introducing a new lookup table for the Unicode
General Category, which is generated along with the other Unicode
lookup tables.
Discussion: https://postgr.es/m/CA+TgmoYzYR-yhU6k1XFCADeyj=Oyz2PkVsa3iKv+keM8wp-F_A@mail.gmail.com
Reviewed-by: Peter Eisentraut
Michael Paquier [Thu, 2 Nov 2023 05:34:51 +0000 (14:34 +0900)]
Prevent startup of logical replication launcher during pg_upgrade
The logical replication launcher may start apply workers during an
upgrade. This could be the cause of corruptions on a new cluster if
these are able to apply changes before the physical files are copied
over to the new cluster.
The chance of being able to do so is small as pg_upgrade uses its own
port and unix domain directory (the latter is customizable with
--socketdir), but just preventing the launcher to start is safer at the
end, because we are then sure that no changes will be applied. Like
29d0a77fa660 for max_slot_wal_keep_size, this is only set when a cluster
uses v17 or newer.
Author: Vignesh C
Discussion: https://postgr.es/m/CALDaNm2g9ZKf=y8X6z6MsLCuh8WwU-=Q6pLj35NFi2M5BZNS_A@mail.gmail.com
Michael Paquier [Thu, 2 Nov 2023 03:38:05 +0000 (12:38 +0900)]
Fix 003_check_guc.pl when loading modules with custom GUCs
The test missed that custom GUCs need to be ignored from the list of
parameters that can exist in postgresql.conf.sample. This caused the
test to fail on a server where such a module is loaded, when using
EXTRA_INSTALL and TEMP_CONFIG, for instance.
Author: Anton A. Melnikov
Discussion: https://postgr.es/m/
fc5509ce-5144-4dac-8d13-
21793da44fc5@postgrespro.ru
Backpatch-through: 15
David Rowley [Thu, 2 Nov 2023 01:30:15 +0000 (14:30 +1300)]
Increase DEFAULT_FDW_TUPLE_COST from 0.01 to 0.2
0.01 was unrealistically low as it's the same as the default
cpu_tuple_cost and 10x cheaper than the default parallel_tuple_cost.
It's hard to imagine a situation where fetching a tuple from a foreign
server would be cheaper than fetching one from a parallel worker.
After some experimentation on a loopback server, somewhere between 0.15
and 0.3 seems more realistic. Here we split the difference and set it
to 0.2.
This will cause operations that reduce the number of tuples (e.g.
aggregation) to be more likely to take place on the foreign server.
Adjusting this causes some plan changes in the postgres_fdw regression
tests. This is because penalizing each Path with the additional tuple
costs causes some dilution of the costs of the other operations being
charged for and results in various paths appearing to be closer to the
same costs such that add_path's STD_FUZZ_FACTOR is more likely to see two
paths as costing (fuzzily) the same. This isn't ideal, but it shouldn't
be reason enough to use artificially low costs.
Discussion: https://postgr.es/m/CAApHDvopVjjfh5c1Ed2HRvDdfom2dEpMwwiu5-f1AnmYprJngA@mail.gmail.com
Michael Paquier [Wed, 1 Nov 2023 22:33:02 +0000 (07:33 +0900)]
doc: Replace reference to ERRCODE_RAISE_EXCEPTION by "raise_exception"
This part of the documentation refers to exceptions as handled by
PL/pgSQL, and using the internal error code is confusing.
Per thinko in
66bde49d96a9.
Reported-by: Euler Taveira, Bruce Momjian
Discussion: https://postgr.es/m/
[email protected]
Backpatch-through: 11
Bruce Momjian [Wed, 1 Nov 2023 17:57:04 +0000 (13:57 -0400)]
doc: add reference to wire protocol details
Discussion: https://postgr.es/m/
143A51B2-80B1-4ECD-AF67-
F7061377FF63@hotmail.com
Author: Li Japin
Backpatch-through: master
Daniel Gustafsson [Wed, 1 Nov 2023 10:46:30 +0000 (11:46 +0100)]
Fix function name in comment
The name of the function resulting from the macro expansion was
incorrectly stated.
Backpatch to 16 where it was introduced.
Author: Kyotaro Horiguchi <
[email protected]>
Discussion: https://postgr.es/m/
20231101.172308.
1740861597185391383[email protected]
Backpatch-through: v16
Michael Paquier [Wed, 1 Nov 2023 05:54:13 +0000 (14:54 +0900)]
doc: Expand section related to LWLocks and shared memory
The documentation includes a section describing how to define custom
LWLocks in extensions using the shmem hooks. However, it has never
mentioned the second, more flexible method based on the following
routines:
- LWLockNewTrancheId() to allocate a tranche ID.
- LWLockRegisterTranche() to associate a name to a tranche ID.
- LWLockInitialize() to initialize a LWLock with a tranche ID.
autoprewarm.c is the only example of extension in the tree that
allocates a LWLock this way.
This commit adds some documentation about all that. While on it, a
comment is added about the need of AddinShmemInitLock. This is required
especially for EXEC_BACKEND builds (aka Windows, normally), as per a
remark from Alexander, because backends can execute shmem initialization
paths concurrently.
Author: Aleksander Alekseev, Michael Paquier
Discussion: https://postgr.es/m/CAJ7c6TPKhFgL+54cdTD9yGpG4+sNcyJ+N1GvQqAxgWENAOa3VA@mail.gmail.com
Bruce Momjian [Tue, 31 Oct 2023 17:18:42 +0000 (13:18 -0400)]
doc: add missing word to sentence about Paris
Reported-by: Tang <[email protected]>
Discussion: https://postgr.es/m/OS0PR01MB6113393560A1DF115ADFB153FB2D9@OS0PR01MB6113.jpnprd01.prod.outlook.com
Backpatch-through: master
Bruce Momjian [Tue, 31 Oct 2023 15:59:14 +0000 (11:59 -0400)]
C comment: mention why no setting lasterrno in dir_existsfile()
Reported-by: Wei Sun
Discussion: https://postgr.es/m/
[email protected]
Backpatch-through: master
Bruce Momjian [Tue, 31 Oct 2023 15:42:02 +0000 (11:42 -0400)]
C comment: improve statistics computation comment example
Discussion: https://postgr.es/m/CAKFQuwbD672Sc0EXv0ifx3pzfQ5UAEpiAeaBGKz_Ox-4d2NGCA@mail.gmail.com
Author: David G. Johnston
Backpatch-through: master
Bruce Momjian [Tue, 31 Oct 2023 15:02:04 +0000 (11:02 -0400)]
C comment: adjust statistics mention
No need to talk about the statistics collector.
Discussion: https://postgr.es/m/
8a82417cdb6e8038fe276d4960e3207a@oss.nttdata.com
Author: Álvaro Herrera
Backpatch-through: master
Bruce Momjian [Tue, 31 Oct 2023 14:21:32 +0000 (10:21 -0400)]
doc: improve ALTER SYSTEM description of value list quoting
Reported-by: [email protected]
Discussion: https://postgr.es/m/
167105927893.1897.
13227723035830709578@wrigleys.postgresql.org
Backpatch-through: 11
Bruce Momjian [Tue, 31 Oct 2023 14:13:11 +0000 (10:13 -0400)]
doc: improve bpchar and character type length details
Reported-by: Jeff Davis
Discussion: https://postgr.es/m/
32a9b8357e8e29b04f395f92c53b64e015a4caf1[email protected]
Author: Jeff Davis, adjustments by me
Backpatch-through: 16
Bruce Momjian [Tue, 31 Oct 2023 13:23:09 +0000 (09:23 -0400)]
doc: add function argument and query parameter limits
Also reorder entries and add commas.
Reported-by: David G. Johnston
Discussion: https://postgr.es/m/CAKFQuwYeNPxeocV3_0+Zx=_Xwvg+sNyEMdzyG5s2E2e0hZLQhg@mail.gmail.com
Author: David G. Johnston (partial)
Backpatch-through: 12
Bruce Momjian [Tue, 31 Oct 2023 13:10:35 +0000 (09:10 -0400)]
doc: 1-byte varlena headers can be used for user PLAIN storage
This also updates some C comments.
Reported-by: [email protected]
Discussion: https://postgr.es/m/
167336599095.
2667301.
15497893107226841625@wrigleys.postgresql.org
Author: Laurenz Albe (doc patch)
Backpatch-through: 11
Bruce Momjian [Tue, 31 Oct 2023 12:51:12 +0000 (08:51 -0400)]
improve alignment of postgresql.conf comments
Discussion: https://postgr.es/m/CAHut+Ps5MdQ1b4jp9rd63zfE2X25mV58y1W+hm2v53svtGDxBQ@mail.gmail.com
Author: Peter Smith
Backpatch-through: master
David Rowley [Tue, 31 Oct 2023 03:42:08 +0000 (16:42 +1300)]
Adjust the order of the prechecks in pgrowlocks()
4b8266415 added a precheck to pgrowlocks() to ensure the given object's
pg_class.relam is HEAP_TABLE_AM_OID, however, that check was put before
another check which was checking if the given object was a partitioned
table. Since the pg_class.relam is always InvalidOid for partitioned
tables, if pgrowlocks() was called passing a partitioned table, then the
"only heap AM is supported" error would be raised instead of the intended
error about the given object being a partitioned table.
Here we simply move the pg_class.relam check to after the check that
verifies that we are in fact working with a normal (non-partitioned)
table.
Reported-by: jian he
Discussion: https://postgr.es/m/CACJufxFaSp_WguFCf0X98951zFVX+dXFnF1mxAb-G3g1HiHOow@mail.gmail.com
Backpatch-through: 12, where
4b8266415 was introduced.
Noah Misch [Mon, 30 Oct 2023 21:46:05 +0000 (14:46 -0700)]
Diagnose !indisvalid in more SQL functions.
pgstatindex failed with ERRCODE_DATA_CORRUPTED, of the "can't-happen"
class XX. The other functions succeeded on an empty index; they might
have malfunctioned if the failed index build left torn I/O or other
complex state. Report an ERROR in statistics functions pgstatindex,
pgstatginindex, pgstathashindex, and pgstattuple. Report DEBUG1 and
skip all index I/O in maintenance functions brin_desummarize_range,
brin_summarize_new_values, brin_summarize_range, and
gin_clean_pending_list. Back-patch to v11 (all supported versions).
Discussion: https://postgr.es/m/
20231001195309[email protected]
Noah Misch [Mon, 30 Oct 2023 21:46:05 +0000 (14:46 -0700)]
amcheck: Distinguish interrupted page deletion from corruption.
This prevents false-positive reports about "the first child of leftmost
target page is not leftmost of its level", "block %u is not leftmost"
and "left link/right link pair". They appeared if amcheck ran before
VACUUM cleaned things, after a cluster exited recovery between the
first-stage and second-stage WAL records of a deletion. Back-patch to
v11 (all supported versions).
Reviewed by Peter Geoghegan.
Discussion: https://postgr.es/m/
20231005025232[email protected]
Bruce Momjian [Mon, 30 Oct 2023 18:52:35 +0000 (14:52 -0400)]
pgindent run to fix commits
de64268561 and
5ae2087202a
Reported-by: Michael Paquier
Discussion: https://postgr.es/m/
[email protected]
Backpatch-through: master
Peter Eisentraut [Mon, 30 Oct 2023 10:08:53 +0000 (06:08 -0400)]
Fill in more of ObjectProperty
Fill in .objtype field where an appropriate value exists.
These cases are currently not used (see also comments at
get_object_type()), but we might as well fill in what's possible in
case additional uses arise.
Discussion: https://www.postgresql.org/message-id/flat/
75ae5875-3abc-dafc-8aec-
73247ed41cde@eisentraut.org
Amit Kapila [Mon, 30 Oct 2023 09:06:21 +0000 (14:36 +0530)]
Add STREAM_START/STREAM_STOP for transactional messages during decoding.
In test_decoding module, when skip_empty_xacts option was specified, add
stream_start/stop for streaming transactional messages. This makes the
handling of transactional messages stream consistent irrespective of
whether skip_empty_xacts option was specified.
Commit
26dd0284b9 made a similar change for non-streaming messages but
forgot to update the streaming cases.
Author: Peter Smith
Reviewed-by: Amit Kapila
Discussion: http://postgr.es/m/OS0PR01MB5716AEBD2988F8F5E9D5985794DFA@OS0PR01MB5716.jpnprd01.prod.outlook.com
Alexander Korotkov [Mon, 30 Oct 2023 08:34:15 +0000 (10:34 +0200)]
Fix indentation in contrib/amcheck/verify_nbtree.c
Reported-by: Michael Paquier
Discussion: https://postgr.es/m/ZT9YoDPEQBUMrIHg%40paquier.xyz
Michael Paquier [Mon, 30 Oct 2023 08:19:24 +0000 (17:19 +0900)]
Expand regression tests for pg_stat_reset_shared()
This commit adds coverage for the stats reset of recovery_prefetch, and
for the case where an invalid value is given in input of the function.
Author: Bharath Rupireddy
Discussion: https://postgr.es/m/CALj2ACW9Uk7x61oSix9qK0xR4Jhy3cgg6pobQ-Q3GNsUbFrn8A@mail.gmail.com
Michael Paquier [Mon, 30 Oct 2023 06:28:20 +0000 (15:28 +0900)]
Delay recovery mode LOG after reading backup_label and/or checkpoint record
When beginning recovery, a LOG is displayed by the startup process to
show which recovery mode will be used depending on the .signal file(s)
set in the data folder, like "standby mode", recovery up to a given
target type and value, or archive recovery.
A different patch is under discussion to simplify the startup code by
requiring the presence of recovery.signal and/or standby.signal when a
backup_label file is read. Delaying a bit this LOG ensures that the
correct recovery mode would be reported, and putting it at this position
does not make it lose its value.
While on it, this commit adds a few comments documenting a bit more the
initial recovery steps and their dependencies, and fixes an incorrect
comment format. This introduces no behavior changes.
Extracted from a larger patch by me.
Reviewed-by: David Steele, Bowen Shi
Discussion: https://postgr.es/m/
[email protected]
Amit Kapila [Mon, 30 Oct 2023 05:16:31 +0000 (10:46 +0530)]
Doc: Make link names consistent in logical replication commands.
Commit
536f410111 added links in the ALTER SUBSCRIPTION command page. The
link names used were slightly different from what other logical
replication commands like CREATE SUBSCRIPTION/PUBLICATION have but were
consistent with other docs. This patch changes the link names for all the
parameters to have 'params' word in the CREATE SUBSCRIPTION/PUBLICATION
pages.
Author: Peter Smith
Reviewed-by: Amit Kapila
Discussion: http://postgr.es/m/CAHut%2BPu2S4RdzYKR7H5_E7QYWyq5hB0hL4EFrYbP91Qso62jeg%40mail.gmail.com
Michael Paquier [Mon, 30 Oct 2023 04:56:02 +0000 (13:56 +0900)]
Mention standby.signal in FATALs for checkpoint record missing at recovery
When beginning recovery from a base backup by reading a backup_label
file, it may be possible that no checkpoint record is available
depending on the method used when the case backup was taken, which would
prevent recovery from beginning. In this case, the FATAL messages
issued, initially added by
c900c15269f0f, mentioned recovery.signal as
an option to do recovery but not standby.signal. Let's add it as an
available option, for clarity.
Per suggestion from Bowen Shi, extracted from a larger patch by me.
Author: Michael Paquier
Discussion: https://postgr.es/m/CAM_vCudkSjr7NsNKSdjwtfAm9dbzepY6beZ5DP177POKy8=2aw@mail.gmail.com
Michael Paquier [Mon, 30 Oct 2023 00:47:16 +0000 (09:47 +0900)]
Introduce pg_stat_checkpointer
Historically, the statistics of the checkpointer have been always part
of pg_stat_bgwriter. This commit removes a few columns from
pg_stat_bgwriter, and introduces pg_stat_checkpointer with equivalent,
renamed columns (plus a new one for the reset timestamp):
- checkpoints_timed -> num_timed
- checkpoints_req -> num_requested
- checkpoint_write_time -> write_time
- checkpoint_sync_time -> sync_time
- buffers_checkpoint -> buffers_written
The fields of PgStat_CheckpointerStats and its SQL functions are renamed
to match with the new field names, for consistency. Note that
background writer and checkpointer have been split into two different
processes in commits
806a2aee3791 and
bf405ba8e460. The pgstat
structures were already split, making this change straight-forward.
Bump catalog version.
Author: Bharath Rupireddy
Reviewed-by: Bertrand Drouvot, Andres Freund, Michael Paquier
Discussion: https://postgr.es/m/CALj2ACVxX2ii=66RypXRweZe2EsBRiPMj0aHfRfHUeXJcC7kHg@mail.gmail.com
Michael Paquier [Sun, 29 Oct 2023 23:23:39 +0000 (08:23 +0900)]
Refactor some code related to transaction-level statistics for relations
This commit refactors find_tabstat_entry() so as transaction counters
for inserted, updated and deleted tuples are included in the result
returned. If a shared entry is found for a relation, its result is now
a copy of the PgStat_TableStatus entry retrieved from shared memory.
This idea has been proposed by Andres Freund.
While on it, the following SQL functions, used in system views, are
refactored with macros, in the same spirit as
83a1a1b56645, reducing the
amount of code:
- pg_stat_get_xact_tuples_deleted()
- pg_stat_get_xact_tuples_inserted()
- pg_stat_get_xact_tuples_updated()
There is now only one caller of find_tabstat_entry() in the tree.
Author: Bertrand Drouvot
Discussion: https://postgr.es/m/
b9e1f543-ee93-8168-d530-
d961708ad9d3@gmail.com
Alexander Korotkov [Sun, 29 Oct 2023 22:23:53 +0000 (01:23 +0300)]
Fix instable 006_login_trigger.pl test
Handling of login trigger FATAL error could cause a timing-dependant panic of
IPC::Run. This commit excludes checks which involves handling of such errors.
Reported-by: Tom Lane
Discussion: https://postgr.es/m/
2268825.
1698618066%40sss.pgh.pa.us
Tom Lane [Sun, 29 Oct 2023 16:56:24 +0000 (12:56 -0400)]
Teach pg_dump about the new pg_subscription.subrunasowner option.
Among numerous other oversights, commit
482675987 neglected to fix
pg_dump to dump this new subscription option. Since the new default
is "false" while the previous behavior corresponds to "true", this
would cause legacy subscriptions to silently change behavior during
dump/reload or pg_upgrade. That seems like a bad idea. Even if it
was intended, failing to preserve the option once set in a new
installation is certainly not OK.
While here, reorder associated stanzas in pg_dump to match the
field order in pg_subscription, in hopes of reducing the impression
that all this code was written with the aid of a dartboard.
Back-patch to v16 where this new field was added.
Philip Warner (cosmetic tweaks by me)
Discussion: https://postgr.es/m/
20231027042539.
01A3A220F0A@thebes.rime.com.au
Dean Rasheed [Sun, 29 Oct 2023 15:46:04 +0000 (15:46 +0000)]
Guard against overflow in make_interval().
The original code did very little to guard against integer or floating
point overflow when computing the interval's fields. Detect any such
overflows and error out, rather than silently returning bogus results.
Joseph Koshakow, reviewed by Ashutosh Bapat and me.
Discussion: https://postgr.es/m/CAAvxfHcm1TPwH_zaGWuFoL8pZBestbRZTU6Z%3D-RvAdSXTPbKfg%40mail.gmail.com
Dean Rasheed [Sun, 29 Oct 2023 11:14:37 +0000 (11:14 +0000)]
btree_gin: Fix calculation of leftmost interval value.
Formerly, the value computed by leftmostvalue_interval() was a long
way short of the minimum possible interval value. As a result, an
index scan on a GIN index on an interval column with < or <= operators
would miss large negative interval values.
Fix by setting all fields of the leftmost interval to their minimum
values, ensuring that the result is less than any other possible
interval. Since this only affects index searches, no index rebuild is
necessary.
Back-patch to all supported branches.
Dean Rasheed, reviewed by Heikki Linnakangas.
Discussion: https://postgr.es/m/CAEZATCV80%2BgOfF8ehNUUfaKBZgZMDfCfL-g1HhWGb6kC3rpDfw%40mail.gmail.com
Tom Lane [Sat, 28 Oct 2023 18:04:42 +0000 (14:04 -0400)]
Fix intra-query memory leak when a SRF returns zero rows.
When looping around after finding that the set-returning function
returned zero rows for the current input tuple, ExecProjectSet
neglected to reset either of the two memory contexts it's
responsible for cleaning out. Typically this wouldn't cause much
problem, because once the SRF does return at least one row, the
contexts would get reset on the next call. However, if the SRF
returns no rows for many input tuples in succession, quite a lot
of memory could be transiently consumed.
To fix, make sure we reset both contexts while looping around.
Per bug #18172 from Sergei Kornilov. Back-patch to all supported
branches.
Discussion: https://postgr.es/m/18172-
9b8c5fc1d676ded3@postgresql.org
Bruce Momjian [Sat, 28 Oct 2023 18:02:46 +0000 (14:02 -0400)]
doc: add links to Postgres features intro
Reported-by: Elena Indrupskaya
Discussion: https://postgr.es/m/
1a666b2e-d373-1c94-1005-
1700e023670d@postgrespro.ru
Backpatch-through: master
Bruce Momjian [Sat, 28 Oct 2023 16:58:32 +0000 (12:58 -0400)]
doc: comment wording improvement
Discussion: https://postgr.es/m/CAEG8a3L7UoZXH1VmzpV-VDkex2kt68nWKuW1WiohoT=RrzYKWA@mail.gmail.com
Author: Junwang Zhao
Backpatch-through: master
Tom Lane [Sat, 28 Oct 2023 15:54:40 +0000 (11:54 -0400)]
Remove PHOT from our default timezone abbreviations list.
Debian recently decided to split out a bunch of "obsolete" timezone
names into a new tzdata-legacy package, which isn't installed by
default. One of these zone names is Pacific/Enderbury, and that
breaks our regression tests (on --with-system-tzdata builds)
because our default timezone abbreviations list defines PHOT as
Pacific/Enderbury.
Pacific/Enderbury got renamed to Pacific/Kanton in tzdata 2021b,
so that in distros that still have this entry it's just a symlink
to Pacific/Kanton anyway. So one answer would be to redefine PHOT
as Pacific/Kanton. However, then things would fail if the
installed tzdata predates 2021b, which is recent enough that that
seems like a real problem.
Instead, let's just remove PHOT from the default list. That seems
likely to affect nobody in the real world, because (a) it was an
abbreviation that the tzdb crew made up in the first place, with
no evidence of real-world usage, and (b) the total human population
of the Phoenix Islands is less than two dozen persons, per Wikipedia.
If anyone does use this zone abbreviation they can easily put it back
via a custom abbreviations file.
We'll keep PHOT in the Pacific.txt reference file, but change it
to Pacific/Kanton there, as that definition seems more likely to
be useful to future readers of that file.
Per report from Victor Wagner. Back-patch to all supported
branches.
Discussion: https://postgr.es/m/
20231027152049.
4b5c8044@wagner.wagner.home
Tom Lane [Sat, 28 Oct 2023 01:50:44 +0000 (21:50 -0400)]
Allow relkind 'I' in type_sanity test.
This is cosmetic at present, since no partitioned indexes have
been created yet at the stage of the regression tests when
type_sanity runs. But it's confusing that this list of allowed
values doesn't match reality, so fix it.
Noted by Jian He.
Discussion: https://postgr.es/m/CACJufxHhr58q-YoBeqnY5P-u8Xe2X5sMtsr3LYE1nQDwdqjB4w@mail.gmail.com