Alvaro Herrera [Wed, 28 Feb 2024 08:39:52 +0000 (09:39 +0100)]
Rename SLRU elements in view pg_stat_slru
The new names are intended to match those in an upcoming patch that adds
a few GUCs to configure the SLRU buffer sizes.
Backwards compatibility concern: this changes the accepted names for
function pg_stat_slru_rest(). Since this function recognizes "any other
string" as a request to reset the entry for "other", this means that
calling it with the old names would silently reset "other" instead of
doing nothing or throwing an error.
Reviewed-by: Andrey M. Borodin <[email protected]>
Discussion: https://postgr.es/m/
202402261616[email protected]
Michael Paquier [Wed, 28 Feb 2024 03:51:35 +0000 (12:51 +0900)]
Remove last NULL element in config_group_names[]
This has not been needed since
9d77708d83ee where there was a loop to
print all the possible GUC groups, relying on the last element to be
NULL.
Author: Japin Li
Reviewed-By: Jelte Fennema-Nio
Discussion: https://postgr.es/m/CAGECzQT3caUbcCcszNewCCmMbCuyP7XNAm60J3ybd6PN5kH2Dw@mail.gmail.com
David Rowley [Wed, 28 Feb 2024 01:20:43 +0000 (14:20 +1300)]
Refactor AllocSetAlloc(), separating hot and cold paths
Allocating from a free list or from a block which contains enough space
already, we deem to be common code paths and want to optimize for those.
Having to allocate a new block, either a normal block or a dedicated one
for a large allocation, we deem to be less common, therefore we class
that as "cold". Both cold paths require a malloc so are going to be
slower as a result of that regardless.
The main motivation here is to remove the calls to malloc() in the hot
path and because of this, the compiler is now free to not bother setting
up the stack frame in AllocSetAlloc(), thus making the hot path much
cheaper.
Author: Andres Freund
Reviewed-by: David Rowley
Discussion: https://postgr.es/m/
20210719195950[email protected]
Michael Paquier [Tue, 27 Feb 2024 23:42:36 +0000 (08:42 +0900)]
Use C99-designated initializer syntax for more arrays
This is in the same spirit as
ef5e2e90859a, updating this time some
arrays in parser.c, relpath.c, guc_tables.c and pg_dump_sort.c so as the
order of their elements has no need to match the enum structures they
are based on anymore.
Author: Jelte Fennema-Nio
Reviewed-by: Jian He, Japin Li
Discussion: https://postgr.es/m/CAGECzQT3caUbcCcszNewCCmMbCuyP7XNAm60J3ybd6PN5kH2Dw@mail.gmail.com
Nathan Bossart [Tue, 27 Feb 2024 15:44:59 +0000 (09:44 -0600)]
Fix comments for the dshash_parameters struct.
A recent commit added a copy_function member to the
dshash_parameters struct, but it missed updating a couple of
comments that refer to the function pointer members of this struct.
One of those comments also refers to a tranche_name member and non-
arg variants of the function pointer members, all of which were
either removed during development or removed shortly after dshash
table support was committed.
Oversights in commits
8c0d7bafad,
d7694fc148, and
42a1de3013.
Discussion: https://postgr.es/m/
20240227045213.GA2329190%40nathanxps13
Andrew Dunstan [Tue, 27 Feb 2024 06:31:40 +0000 (01:31 -0500)]
Rationalize and improve error messages for some jsonpath items
This is a followup to commit
66ea94e8e6.
Error mssages concerning incorrect formats for date-time types are
unified and parameterized, instead of using a fully separate error
message for each type.
Similarly, error messages regarding numeric and string arguments to
certain items are standardized, and instead of saying that the argument
is out of range simply say that it is invalid. The actual invalid
arguments to these itesm are now shown in the error message.
Error messages relating to numeric inputs of Nan or Infinity are
made more informative.
Jeevan Chalke and Kyotaro Horiguchi, with some input from Tom Lane.
Discussion: https://postgr.es/m/
20240129.121200.
235012930453045390[email protected]
Michael Paquier [Tue, 27 Feb 2024 06:18:17 +0000 (15:18 +0900)]
Remove unnecessary array object_classes[] in dependency.c
object_classes[] provided unnecessary indirection between catalog OIDs
and the enum ObjectClass when calling add_object_address(). This array
has been originally introduced in
30ec31604d5 and was useful because not
all relation OIDs were compile-time constants back then, which has not
been the case for a long time now for all the elements of ObjectClass.
This commit removes object_classes[], switching to the catalog OIDs
when calling add_object_address(). This shaves some code while saving
in maintenance because it was necessary to maintain the enum ObjectClass
and the array in sync when adding new object types.
Reported-by: Jeff Davis
Author: Jelte Fennema-Nio
Reviewed-by: Jian He, Michael Paquier
Discussion: https://postgr.es/m/CAGECzQT3caUbcCcszNewCCmMbCuyP7XNAm60J3ybd6PN5kH2Dw@mail.gmail.com
David Rowley [Tue, 27 Feb 2024 03:39:42 +0000 (16:39 +1300)]
Adjust memory allocation functions to allow sibling calls
Many modern compilers are able to optimize function calls to functions
where the parameters of the called function match a leading subset of
the calling function's parameters. If there are no instructions in the
calling function after the function is called, then the compiler is free
to avoid any stack frame setup and implement the function call as a
"jmp" rather than a "call". This is called sibling call optimization.
Here we adjust the memory allocation functions in mcxt.c to allow this
optimization. This requires moving some responsibility into the memory
context implementations themselves. It's now the responsibility of the
MemoryContext to check for malloc failures. This is good as it both
allows the sibling call optimization, but also because most small and
medium allocations won't call malloc and just allocate memory to an
existing block. That can't fail, so checking for NULLs in that case
isn't required.
Also, traditionally it's been the responsibility of palloc and the other
allocation functions in mcxt.c to check for invalid allocation size
requests. Here we also move the responsibility of checking that into the
MemoryContext. This isn't to allow the sibling call optimization, but
more because most of our allocators handle large allocations separately
and we can just add the size check when doing large allocations. We no
longer check this for non-large allocations at all.
To make checking the allocation request sizes and ERROR handling easier,
add some helper functions to mcxt.c for the allocators to use.
Author: Andres Freund
Reviewed-by: David Rowley
Discussion: https://postgr.es/m/
20210719195950[email protected]
Michael Paquier [Mon, 26 Feb 2024 23:19:39 +0000 (08:19 +0900)]
Fix comment thinko in sequence.c
One comment mentioned indexes, but the relation opened should be
sequences.
Reported-by: Matthias van de Meent
Discussion: https://postgr.es/m/CAEze2WiMGNG9XK3NSUen-5BARhCnP=u=FXnf8pvpL2qDKeOsZg@mail.gmail.com
Nathan Bossart [Mon, 26 Feb 2024 21:47:13 +0000 (15:47 -0600)]
Add helper functions for dshash tables with string keys.
Presently, string keys are not well-supported for dshash tables.
The dshash code always copies key_size bytes into new entries'
keys, and dshash.h only provides compare and hash functions that
forward to memcmp() and tag_hash(), both of which do not stop at
the first NUL. This means that callers must pad string keys so
that the data beyond the first NUL does not adversely affect the
results of copying, comparing, and hashing the keys.
To better support string keys in dshash tables, this commit does
a couple things:
* A new copy_function field is added to the dshash_parameters
struct. This function pointer specifies how the key should be
copied into new table entries. For example, we only want to copy
up to the first NUL byte for string keys. A dshash_memcpy()
helper function is provided and used for all existing in-tree
dshash tables without string keys.
* A set of helper functions for string keys are provided. These
helper functions forward to strcmp(), strcpy(), and
string_hash(), all of which ignore data beyond the first NUL.
This commit also adjusts the DSM registry's dshash table to use the
new helper functions for string keys.
Reviewed-by: Andy Fan
Discussion: https://postgr.es/m/
20240119215941.GA1322079%40nathanxps13
Nathan Bossart [Mon, 26 Feb 2024 21:46:01 +0000 (15:46 -0600)]
Use NULL instead of 0 for 'arg' argument in dshash_create() calls.
A couple of dshash_create() callers provide 0 for the 'void *arg'
argument, which might give readers the incorrect impression that
this is some sort of "flags" parameter.
Reviewed-by: Andy Fan
Discussion: https://postgr.es/m/
20240119215941.GA1322079%40nathanxps13
Alvaro Herrera [Mon, 26 Feb 2024 17:19:03 +0000 (18:19 +0100)]
Revise MERGE documentation
Add a note about the additional privileges required after the fix in
4989ce72644b (wording per Tom Lane); also change marked-up mentions of
"target_table_name" to be simply "the target table" or the like. Also,
note that "join_condition" is scouted for requisite privileges.
Backpatch to 15.
Discussion: https://postgr.es/m/
202402211653[email protected]
Alvaro Herrera [Mon, 26 Feb 2024 15:49:50 +0000 (16:49 +0100)]
slru.c: Reduce scope of variables in 'for' blocks
Pretty boring.
Michael Paquier [Mon, 26 Feb 2024 08:03:18 +0000 (17:03 +0900)]
Group more closely cache updates for backends in sequence.c
Information of sequences is cached for each backend for currval() and
nextval(), and the update of some cached information was mixed in the
middle of computations based on the other properties of a sequence, for
the increment value in nextval() and the cached state when altering a
sequence.
Grouping them makes the code easier to follow and to refactor in the
future, when splitting the computation and the SeqTable change parts.
Note that the cached data is untouched between the areas where these
cache updates are moved.
Issue noticed while doing some refactoring of the sequence code.
Author: Michael Paquier
Reviewed-by: Tomas Vondra
Discussion: https://postgr.es/m/
[email protected]
Michael Paquier [Mon, 26 Feb 2024 07:04:59 +0000 (16:04 +0900)]
Introduce sequence_*() access functions
Similarly to tables and indexes, these functions are able to open
relations with a sequence relkind, which is useful to make a distinction
with the other relation kinds. Previously, commands/sequence.c used a
mix of table_{close,open}() and relation_{close,open}() routines when
manipulating sequence relations, so this clarifies the code.
A direct effect of this change is to align the error messages produced
when attempting DDLs for sequences on relations with an unexpected
relkind, like a table or an index with ALTER SEQUENCE, providing an
extra error detail about the relkind of the relation used in the DDL
query.
Author: Michael Paquier
Reviewed-by: Tomas Vondra
Discussion: https://postgr.es/m/
[email protected]
Peter Eisentraut [Mon, 26 Feb 2024 06:16:31 +0000 (07:16 +0100)]
Fix incorrect format placeholder
Not only did the format placeholder not match the variable, the
variable also didn't match the function it was getting its value from.
Tom Lane [Sun, 25 Feb 2024 21:15:07 +0000 (16:15 -0500)]
Promote assertion about !ReindexIsProcessingIndex to runtime error.
When this assertion was installed (in commit
d2f60a3ab), I thought
it was only for catching server logic errors that caused accesses to
catalogs that were undergoing index rebuilds. However, it will also
fire in case of a user-defined index expression that attempts to
access its own table. We occasionally see reports of people trying
to do that, and typically getting unintelligible low-level errors
as a result. We can provide a more on-point message by making this
a regular runtime check.
While at it, adjust the similar error check in
systable_beginscan_ordered to use the same message text. That one
is (probably) not reachable without a coding bug, but we might as
well use a translatable message if we have one.
Per bug #18363 from Alexander Lakhin. Back-patch to all supported
branches.
Discussion: https://postgr.es/m/18363-
e3598a5a572d0699@postgresql.org
Tom Lane [Sun, 25 Feb 2024 20:29:09 +0000 (15:29 -0500)]
Doc: fix minor typos in two ECPG function descriptions.
Noted by Aidar Imamov.
Discussion: https://postgr.es/m/
170869935022.643.
3709087848818148291@wrigleys.postgresql.org
Alexander Korotkov [Sun, 25 Feb 2024 18:30:17 +0000 (20:30 +0200)]
Improve documentation and GUC description for transaction_timeout
Reported-by: Alexander Lakhin
Alexander Korotkov [Sun, 25 Feb 2024 18:00:03 +0000 (20:00 +0200)]
Remove flaky isolation tests for timeouts
51efe38cb92f introduced bunch of tests for idle_in_transaction_session_timeout,
transaction_timeout and statement_timeout. These tests were too flaky on some
slow buildfarm machines, so we plan to replace them with TAP tests using
injection points. This commit removes flaky tests.
Discussion: https://postgr.es/m/CAAhFRxiQsRs2Eq5kCo9nXE3HTugsAAJdSQSmxncivebAxdmBjQ%40mail.gmail.com
Author: Andrey Borodin
Alexander Korotkov [Fri, 23 Feb 2024 23:49:06 +0000 (01:49 +0200)]
Multiple revisions to the GROUP BY reordering tests
Discussion: https://postgr.es/m/CAMbWs4-NKLa%2BSs%2BX%3DWR6h0x%3DT07YBJoAz70ZGHzc-2zcHUHb0A%40mail.gmail.com
Author: Richard Guo
Reviewed-by: Andrei Lepikhov, Alexander Korotkov
Alexander Korotkov [Fri, 23 Feb 2024 22:34:52 +0000 (00:34 +0200)]
Replace lateral references to removed rels in subqueries
This commit introduces a new field 'sublevels_up' in ReplaceVarnoContext,
and enhances replace_varno_walker() to:
1) recurse into subselects with sublevels_up increased, and
2) perform the replacement only when varlevelsup is equal to sublevels_up.
This commit also fixes some outdated comments. And besides adding relevant
test cases, it makes some unification over existing SJE test cases.
Discussion: https://postgr.es/m/CAMbWs4-%3DPO6Mm9gNnySbx0VHyXjgnnYYwbN9dth%3DTLQweZ-M%2Bg%40mail.gmail.com
Author: Richard Guo
Reviewed-by: Andrei Lepikhov, Alexander Korotkov
Tom Lane [Fri, 23 Feb 2024 20:21:53 +0000 (15:21 -0500)]
Avoid dangling-pointer problem with partitionwise joins under GEQO.
build_child_join_sjinfo creates a derived SpecialJoinInfo in
the short-lived GEQO context, but afterwards the semi_rhs_exprs
from that may be used in a UniquePath for a child base relation.
This breaks the expectation that all base-relation-level structures
are in the planning-lifespan context, leading to use of a dangling
pointer with probable ensuing crash later on in create_unique_plan.
To fix, copy the expression trees when making a UniquePath.
Per bug #18360 from Alexander Lakhin. This has been broken since
partitionwise joins were added, so back-patch to all supported
branches.
Discussion: https://postgr.es/m/18360-
a23caf3157f34e62@postgresql.org
Heikki Linnakangas [Fri, 23 Feb 2024 15:39:27 +0000 (17:39 +0200)]
Fix compiler warning on typedef redeclaration
bulk_write.c:78:3: error: redefinition of typedef 'BulkWriteState' is a C11 feature [-Werror,-Wtypedef-redefinition]
} BulkWriteState;
^
../../../../src/include/storage/bulk_write.h:20:31: note: previous definition is here
typedef struct BulkWriteState BulkWriteState;
^
1 error generated.
Per buildfarm animals 'sifaka' and 'longfin'.
Discussion: https://www.postgresql.org/message-id/
9e1f63c3-ef16-404c-b3cb-
859a96eaba39@iki.fi
Heikki Linnakangas [Fri, 23 Feb 2024 14:10:51 +0000 (16:10 +0200)]
Introduce a new smgr bulk loading facility.
The new facility makes it easier to optimize bulk loading, as the
logic for buffering, WAL-logging, and syncing the relation only needs
to be implemented once. It's also less error-prone: We have had a
number of bugs in how a relation is fsync'd - or not - at the end of a
bulk loading operation. By centralizing that logic to one place, we
only need to write it correctly once.
The new facility is faster for small relations: Instead of of calling
smgrimmedsync(), we register the fsync to happen at next checkpoint,
which avoids the fsync latency. That can make a big difference if you
are e.g. restoring a schema-only dump with lots of relations.
It is also slightly more efficient with large relations, as the WAL
logging is performed multiple pages at a time. That avoids some WAL
header overhead. The sorted GiST index build did that already, this
moves the buffering to the new facility.
The changes to pageinspect GiST test needs an explanation: Before this
patch, the sorted GiST index build set the LSN on every page to the
special GistBuildLSN value, not the LSN of the WAL record, even though
they were WAL-logged. There was no particular need for it, it just
happened naturally when we wrote out the pages before WAL-logging
them. Now we WAL-log the pages first, like in B-tree build, so the
pages are stamped with the record's real LSN. When the build is not
WAL-logged, we still use GistBuildLSN. To make the test output
predictable, use an unlogged index.
Reviewed-by: Andres Freund
Discussion: https://www.postgresql.org/message-id/
30e8f366-58b3-b239-c521-
422122dd5150%40iki.fi
Peter Eisentraut [Fri, 23 Feb 2024 13:40:25 +0000 (14:40 +0100)]
Fix mistake in SQL features list
Fix for
c9f57541d97: Feature F302-02 was renamed to F305, but that
commit failed to delete the old line.
Reported-by: Satoru Koizumi (小泉 悟) <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/
170866661469.645.
14101429540172934386%40wrigleys.postgresql.org
Amit Kapila [Thu, 22 Feb 2024 12:56:40 +0000 (18:26 +0530)]
Fix BF failure in commit
93db6cbda0.
The code to match the required LOG in the test was not robust enough to
match it. It was using a very specific format to search the required
message which doesn't work when one uses log_error_verbosity = verbose.
Author: Hou Zhijie
Discussion: https://postgr.es/m/CAA4eK1KcQSk7wzC7Zfrth9OhrjW2HvxL4tKgU42qqH7p6jn+FA@mail.gmail.com
Michael Paquier [Thu, 22 Feb 2024 10:59:58 +0000 (19:59 +0900)]
Make GetSlotInvalidationCause() return RS_INVAL_NONE on unexpected input
943f7ae1c869 has changed GetSlotInvalidationCause() so as it would
return the last element of SlotInvalidationCauses[] when an incorrect
conflict reason name is given by a caller, but this should return
RS_INVAL_NONE in such cases, even if such a state should never be
reached in practice.
Per gripe from Peter Smith.
Reviewed-by: Bharath Rupireddy
Discussion: https://postgr.es/m/CAHut+PtsrSWxczpGkSaSVtJo+BXrvJ3Hwp5gES14bbL-G+HL7A@mail.gmail.com
Amit Kapila [Thu, 22 Feb 2024 09:55:15 +0000 (15:25 +0530)]
Add a new slot sync worker to synchronize logical slots.
By enabling slot synchronization, all the failover logical replication
slots on the primary (assuming configurations are appropriate) are
automatically created on the physical standbys and are synced
periodically. The slot sync worker on the standby server pings the primary
server at regular intervals to get the necessary failover logical slots
information and create/update the slots locally. The slots that no longer
require synchronization are automatically dropped by the worker.
The nap time of the worker is tuned according to the activity on the
primary. The slot sync worker waits for some time before the next
synchronization, with the duration varying based on whether any slots were
updated during the last cycle.
A new parameter sync_replication_slots enables or disables this new
process.
On promotion, the slot sync worker is shut down by the startup process to
drop any temporary slots acquired by the slot sync worker and to prevent
the worker from trying to fetch the failover slots.
A functionality to allow logical walsenders to wait for the physical will
be done in a subsequent commit.
Author: Shveta Malik, Hou Zhijie based on design inputs by Masahiko Sawada and Amit Kapila
Reviewed-by: Masahiko Sawada, Bertrand Drouvot, Peter Smith, Dilip Kumar, Ajin Cherian, Nisha Moond, Kuroda Hayato, Amit Kapila
Discussion: https://postgr.es/m/
514f6f2f-6833-4539-39f1-
96cd1e011f23@enterprisedb.com
Peter Eisentraut [Thu, 22 Feb 2024 06:59:15 +0000 (07:59 +0100)]
pgindent fix
for commit
489072ab7a
Amit Kapila [Thu, 22 Feb 2024 06:36:44 +0000 (12:06 +0530)]
Fix the intermittent buildfarm failures in 031_column_list.
The reason was that the ALTER SUBSCRIPTION .. SET PUBLICATION will lead to
the restarting of apply worker and after the restart, the apply worker
will use the existing slot and replication origin corresponding to the
subscription. Now, it is possible that before restart the origin has not
been updated and the WAL start location points to a location before where
PUBLICATION exists which can lead to the error "publication ... does not
exist".
Fix it by recreating the subscription as a newly created subscription will
start processing WAL from the recent WAL location and will see the
required publication.
This behavior has existed from the time logical replication was introduced
but is exposed by this test and we have started a discussion for a better
fix for this problem.
As per Buildfarm
Diagnosed-by: Amit Kapila
Author: Vignesh C
Discussion: https://postgr.es/m/
3307255.
1706911634@sss.pgh.pa.us
Peter Eisentraut [Thu, 22 Feb 2024 06:07:12 +0000 (07:07 +0100)]
Remove custom Constraint node read/write implementations
This is part of an effort to reduce the number of special cases in the
automatically generated node support functions.
Allegedly, only certain fields of the Constraint node are valid based
on contype. But this has historically not been kept up to date in the
read/write functions. The Constraint node is only used for debugging
DDL statements, so there are no strong requirements for its output,
and there is no enforcement for its correctness. (There was no read
support before
a6bc3301925.) Commits
e7a552f303c and
abf46ad9c7b are
examples of where omissions were fixed.
This patch just removes the custom read/write implementations for the
Constraint node type. Now we just output all the fields, which is a
bit more than before, but at least we don't have to maintain these
functions anymore. Also, we lose the string representation of the
contype field, but for this marginal use case that seems tolerable.
This patch also changes the documentation of the Constraint struct to
put less emphasis on grouping fields by constraint type but rather
document for each field how it's used.
Reviewed-by: Paul Jungwirth <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/
4b27fc50-8cd6-46f5-ab20-
88dbaadca645@eisentraut.org
Amit Kapila [Thu, 22 Feb 2024 05:47:00 +0000 (11:17 +0530)]
Improve ERROR/LOG messages added by commits
ddd5f4f54a and
7a424ece48.
Additionally, in slotsync.c, replace one StringInfoData variable usage
with a constant string to avoid palloc/pfree. Also, replace the inclusion
of "logical.h" with "slot.h" to prevent the exposure of unnecessary
implementation details.
Reported-by: Kyotaro Horiguchi, Masahiko Sawada
Author: Shveta Malik based on suggestions by Robert Haas and Amit Kapila
Reviewed-by: Kyotaro Horiguchi, Amit Kapila
Discussion: https://postgr.es/m/
20240214.162652.
773291409747353211[email protected]
Discussion: https://postgr.es/m/
20240219.134015.
1888940527023074780[email protected]
Discussion: https://postgr.es/m/CAD21AoCYXhDYOQDAS-rhGasC2T+tYbV=8Y18o94sB=5AxcW+yA@mail.gmail.com
Michael Paquier [Thu, 22 Feb 2024 01:02:55 +0000 (10:02 +0900)]
Speed up uuid_out() by not relying on a StringInfo
Since the size of the string representation of an uuid is fixed, there
is no benefit in using a StringInfo. This commit simplifies uuid_oud()
to not rely on a StringInfo, where avoiding the overhead of the string
manipulation makes the function substantially faster.
A COPY TO on a relation with one UUID attribute can show up to a 40%
speedup when the bottleneck is the COPY computation with uuid_out()
showing up at the top of the profiles (numbered measure here, Laurenz
has mentioned something closer to 20% faster runtimes), for example when
the data is fully in shared buffers or the OS cache.
Author: Laurenz Albe
Reviewed-by: Andres Freund, Michael Paquier
Description: https://postgr.es/m/
679d5455cbbb0af667ccb753da51a475bae1eaed[email protected]
Michael Paquier [Wed, 21 Feb 2024 23:40:40 +0000 (08:40 +0900)]
Add lookup table for replication slot conflict reasons
This commit switches the handling of the conflict cause strings for
replication slots to use a table rather than being explicitly listed,
using a C99-designated initializer syntax for the array elements. This
makes the whole more readable while easing future maintenance with less
areas to update when adding a new conflict reason.
This is similar to
74a730631065, but the scale of the change is smaller
as there are less conflict causes than LWLock builtin tranche names.
Author: Bharath Rupireddy
Reviewed-by: Jelte Fennema-Nio
Discussion: https://postgr.es/m/CALj2ACUxSLA91QGFrJsWNKs58KXb1C03mbuwKmzqqmoAKLwJaw@mail.gmail.com
Heikki Linnakangas [Wed, 21 Feb 2024 23:21:34 +0000 (01:21 +0200)]
Remove superfluous 'pgprocno' field from PGPROC
It was always just the index of the PGPROC entry from the beginning of
the proc array. Introduce a macro to compute it from the pointer
instead.
Reviewed-by: Andres Freund
Discussion: https://www.postgresql.org/message-id/
8171f1aa-496f-46a6-afc3-
c46fe7a9b407@iki.fi
Alvaro Herrera [Wed, 21 Feb 2024 16:18:52 +0000 (17:18 +0100)]
MERGE ... DO NOTHING: require SELECT privileges
Verify that a user running MERGE with a DO NOTHING clause has
privileges to read the table, even if no columns are referenced. Such
privileges were already required if the ON clause or any of the WHEN
conditions referenced any column at all, so there's no functional change
in practice.
This change fixes an assertion failure in the case where no column is
referenced by the command and the WHEN clauses are all DO NOTHING.
Backpatch to 15, where MERGE was introduced.
Reported-by: Alena Rybakina <[email protected]>
Reported-by: Alexander Lakhin <[email protected]>
Discussion: https://postgr.es/m/
4d65a385-7efa-4436-a825-
0869f89d9d92@postgrespro.ru
Alvaro Herrera [Tue, 20 Feb 2024 09:54:34 +0000 (10:54 +0100)]
Fix typo
Daniel Gustafsson [Wed, 21 Feb 2024 08:08:28 +0000 (09:08 +0100)]
doc: Fix link to pg_ident_file_mappings view
Commit
a2c84990bea7 accidentally used the link for pg_hba_file_rules
when linking to pg_ident_file_mappings. Backpatch to v16 where this
was introduced.
Author: Erik Wienhold <
[email protected]>
Discussion: https://postgr.es/m/qt5hvgvfi4qzlgml2dfssaut2t2x5nwf7b5l63fklr7fpxwm6g@hle3mtglpm4y
Backpatch-through: v16
Michael Paquier [Wed, 21 Feb 2024 04:28:51 +0000 (13:28 +0900)]
Add option force_initdb to PostgreSQL::Test::Cluster:init()
This option is useful to bypass the default behavior of init() which
would create the data folder of a new cluster by copying it from a
template previously initdb'd, if any. Copying the data folder is much
cheaper than running initdb, but some tests may want to force that. For
example, one scenario of pg_combinebackup updated in this commit needs a
different system ID for two nodes.
Previously, this could only be achieved by unsetting
$ENV{'INITDB_TEMPLATE'}, which could become a problem in complex node
setups by making tests less efficient.
Author: Amul Sul
Reviewed-by: Robert Haas, Michael Paquier
Discussion: https://postgr.es/m/
[email protected]
Alexander Korotkov [Wed, 21 Feb 2024 00:46:56 +0000 (02:46 +0200)]
Remove extra check_stack_depth() from dropconstraint_internal()
The second check was added by
d57b7cc33 without taking into account there
is already a check since
b0f7dd915.
Reported-by: Ashutosh Bapat, Alexander Lakhin
Discussion: https://postgr.es/m/CAExHW5sBZWDjeBUFs_ehEDM%2BuhWxTiBkPbLiat7ZjWkb-DWQWw%40mail.gmail.com
Tom Lane [Tue, 20 Feb 2024 19:35:12 +0000 (14:35 -0500)]
Doc: improve explanation of type interval, especially extract().
The explanation of interval's behavior in datatype.sgml wasn't wrong
exactly, but it was unclear, partly because it buried the lede about
there being three internal fields. Rearrange and wordsmith for more
clarity.
The discussion of extract() claimed that input of type date was
handled by casting, but actually there's been a separate SQL function
taking date for a very long time. Also, it was mostly silent about
how interval inputs are handled, but there are several field types
for which it seems useful to be specific.
Improve discussion of justify_days()/justify_hours() too.
In passing, remove vertical space in some groups of examples,
as there was little consistency about whether to have such space
or not. (I only did this within the datetime functions section;
there are some related inconsistencies elsewhere.)
Per discussion of bug #18348 from Michael Bondarenko. There
may be some code changes coming out of that discussion too,
but we likely won't back-patch them. This docs-only patch
seems useful to back-patch, though I only carried it back to
v13 because it didn't apply easily in v12.
Discussion: https://postgr.es/m/18348-
b097a3587dfde8a4@postgresql.org
Alexander Korotkov [Tue, 20 Feb 2024 12:10:10 +0000 (14:10 +0200)]
Replace relids in lateral subquery parse tree during SJE
Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/
56ee4520-e9d1-d519-54fe-
c8bff880ce9b%40gmail.com
Author: Alexander Korotkov, Andrei Lepikhov
Peter Eisentraut [Tue, 20 Feb 2024 10:10:59 +0000 (11:10 +0100)]
Revert "Improve compression and storage support with inheritance"
This reverts commit
0413a556990ba628a3de8a0b58be020fd9a14ed0.
pg_dump cannot currently dump all the structures that are allowed by
this patch. This needs more work in pg_dump and more test coverage.
Discussion: https://www.postgresql.org/message-id/flat/
24656cec-d6ef-4d15-8b5b-
e8dfc9c833a7@eisentraut.org
David Rowley [Tue, 20 Feb 2024 05:34:21 +0000 (18:34 +1300)]
Minor corrections for partition pruning
When the partition pruning code finds an OpExpr with an operator that
does not belong to the partition key's opfamily, the code checks to see
if the negator of the operator is the opfamily's BTEqualStrategyNumber
operator so that partition pruning can support that operator and invert
the matching partitions. Doing this only works for LIST partitioned
tables.
Here we fix a minor correctness issue where when we discover we're not
pruning for a LIST partitioned table, we return PARTCLAUSE_NOMATCH.
PARTCLAUSE_NOMATCH is only meant to be used when the clause may match
another partitioned key column. For this case, the clause is not going
to be any more useful to another partitioned key as the partition strategy
is not going to change from one key to the next.
Noticed while working
4c2369ac5. No backpatch because returning
PARTCLAUSE_NOMATCH instead of PARTCLAUSE_UNSUPPORTED mostly just causes
wasted effort checking subsequent partition keys against a clause that
will never be used for pruning.
In passing, correct a comment for get_matching_range_bounds() which
mentions that an 'opstrategy' of 0 is supported. It's not, so fix the
comment. This was pointed out by Alexander Lakhin.
Discussion: https://postgr.es/m/CAApHDvqriy8mPOFJ_Bd66YGXJ4+XULpv-4YdB+ePdCQFztyisA@mail.gmail.com
Discussion: https://postgr.es/m/
312fb507-9b5e-cf83-d8ed-
cd0da72a902c@gmail.com
Michael Paquier [Tue, 20 Feb 2024 04:43:51 +0000 (13:43 +0900)]
Fix race leading to incorrect conflict cause in InvalidatePossiblyObsoleteSlot()
The invalidation of an active slot is done in two steps:
- Termination of the backend holding it, if any.
- Report that the slot is obsolete, with a conflict cause depending on
the slot's data.
This can be racy because between these two steps the slot mutex would be
released while doing system calls, which means that the effective_xmin
and effective_catalog_xmin could advance during that time, detecting a
conflict cause different than the one originally wanted before the
process owning a slot is terminated.
Holding the mutex longer is not an option, so this commit changes the
code to record the LSNs stored in the slot during the termination of the
process owning the slot.
Bonus thanks to Alexander Lakhin for the various tests and the analysis.
Author: Bertrand Drouvot
Reviewed-by: Michael Paquier, Bharath Rupireddy
Discussion: https://postgr.es/m/
[email protected]
Backpatch-through: 16
Michael Paquier [Tue, 20 Feb 2024 02:59:03 +0000 (11:59 +0900)]
doc: Use system-username instead of system-user
This inconsistency has been introduced in
efb6f4a4f9b6.
Reported-by: Julien Rouhaud
Author: Bertrand Drouvot
Discussion: https://postgr.es/m/
[email protected]
Backpatch-through: 16
David Rowley [Mon, 19 Feb 2024 23:49:37 +0000 (12:49 +1300)]
Fix incorrect pruning of NULL partition for boolean IS NOT clauses
Partition pruning wrongly assumed that, for a table partitioned on a
boolean column, a clause in the form "boolcol IS NOT false" and "boolcol
IS NOT true" could be inverted to correspondingly become "boolcol IS true"
and "boolcol IS false". These are not equivalent as the NOT version
matches the opposite boolean value *and* NULLs. This incorrect assumption
meant that partition pruning pruned away partitions that could contain
NULL values.
Here we fix this by correctly not pruning partitions which could store
NULLs.
To be affected by this, the table must be partitioned by a NULLable boolean
column and queries would have to contain "boolcol IS NOT false" or "boolcol
IS NOT true". This could result in queries filtering out NULL values
with a LIST partitioned table and "ERROR: invalid strategy number 0"
for RANGE and HASH partitioned tables.
Reported-by: Alexander Lakhin
Bug: #18344
Discussion: https://postgr.es/m/18344-
8d3f00bada6d09c6@postgresql.org
Backpatch-through: 12
Noah Misch [Mon, 19 Feb 2024 20:52:28 +0000 (12:52 -0800)]
Fix test race between primary XLOG_RUNNING_XACTS and standby logical slot.
Before the previous commit, the test could hang until
LOG_SNAPSHOT_INTERVAL_MS (15s), until checkpoint_timeout (300s), or
indefinitely. An indefinite hang was awfully improbable. It entailed
the test reaching checkpoint_timeout before the
DecodingContextFindStartpoint() of a CREATE SUBSCRIPTION, yet after the
preceding WAL record. Back-patch to v16, which introduced the test.
Bertrand Drouvot, reported by Noah Misch.
Discussion: https://postgr.es/m/
20240211010227[email protected]
Noah Misch [Mon, 19 Feb 2024 20:52:07 +0000 (12:52 -0800)]
Bound waits in 035_standby_logical_decoding.pl.
One IPC::Run::start() used an IPC::Run::timer() without checking for
expiration. The other used no timeout or timer. Back-patch to v16,
which introduced the test.
Reviewed by Bertrand Drouvot.
Discussion: https://postgr.es/m/
20240211010227[email protected]
Tom Lane [Mon, 19 Feb 2024 19:17:11 +0000 (14:17 -0500)]
Doc: fix typo in SECURITY LABEL synopsis.
One case missed its trailing "|".
Reported by Tim Needham.
Discussion: https://postgr.es/m/
170833547220.
3279712.
700702770281879175@wrigleys.postgresql.org
Alexander Korotkov [Mon, 19 Feb 2024 12:11:50 +0000 (14:11 +0200)]
Get rid of pg_class usage in SJE regression tests
Usage of pg_class led to instability, see the buildfarm failure.
https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=prion&dt=2024-02-15%2021%3A58%3A04
Reported-by: Andrei Lepikhov
Discussion: https://postgr.es/m/
250c4cec-e459-4311-8fd6-
da2558b3fb0a@postgrespro.ru
Peter Eisentraut [Mon, 19 Feb 2024 08:21:49 +0000 (09:21 +0100)]
ci: Add test coverage of different pg_upgrade modes
Run freebsd with --link and macos with --clone, to get some coverage
of the non-default modes.
Author: Justin Pryzby <
[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/
20220528153741[email protected]
Amit Kapila [Mon, 19 Feb 2024 05:06:05 +0000 (10:36 +0530)]
Fix 004_subscription.pl to allow its usage in --link mode.
The test was failing when executed in --link mode and the reason was that
we were using the old cluster from a previously successful upgrade test.
Re-arrange the tests so that the successful test case is at the end.
Reported-by: Justin Pryzby, Peter Eisentraut
Author: Kuroda Hayato
Reviewed-by: Vignesh C, Amit Kapila
Discussion: https://postgr.es/m/ZcvZipRoi_kopIpb@pryzbyj2023
Discussion: https://postgr.es/m/
25f7f4bf-9e75-4453-b666-
7818000cefe6@eisentraut.org
Michael Paquier [Mon, 19 Feb 2024 02:38:18 +0000 (11:38 +0900)]
ecpg: Fix zero-termination of string generated by intoasc()
intoasc(), a wrapper for PGTYPESinterval_to_asc that converts an
interval to its textual representation, used a plain memcpy() when
copying its result. This could miss a zero-termination in the result
string, leading to an incorrect result.
The routines in informix.c do not provide the length of their result
buffer, which would allow a replacement of strcpy() to safer strlcpy()
calls, but this requires an ABI breakage and that cannot happen in
back-branches.
Author: Oleg Tselebrovskiy
Reviewed-by: Ashutosh Bapat
Discussion: https://postgr.es/m/
bf47888585149f83b276861a1662f7e4@postgrespro.ru
Backpatch-through: 12
Michael Paquier [Mon, 19 Feb 2024 00:05:51 +0000 (09:05 +0900)]
ecpg: Fix error handling on OOMs when parsing timestamps
pgtypes_alloc() can return NULL when failing an allocation, which is
something that PGTYPEStimestamp_defmt_asc() has forgotten about when
translating a timestamp for 'D', 'r', 'R' and 'T' as these require a
temporary allocation.
This is unlikely going to be a problem in practice, so no backpatch is
done.
Author: Oleg Tselebrovskiy
Discussion: https://postgr.es/m/
bf47888585149f83b276861a1662f7e4@postgrespro.ru
Alexander Korotkov [Fri, 16 Feb 2024 21:58:44 +0000 (23:58 +0200)]
Remove remaining references to timeouts-long
Reported-by: Alexander Lakhin
Nathan Bossart [Fri, 16 Feb 2024 20:05:36 +0000 (14:05 -0600)]
Use new overflow-safe integer comparison functions.
Commit
6b80394781 introduced integer comparison functions designed
to be as efficient as possible while avoiding overflow. This
commit makes use of these functions in many of the in-tree qsort()
comparators to help ensure transitivity. Many of these comparator
functions should also see a small performance boost.
Author: Mats Kindahl
Reviewed-by: Andres Freund, Fabrízio de Royes Mello
Discussion: https://postgr.es/m/CA%2B14426g2Wa9QuUpmakwPxXFWG_1FaY0AsApkvcTBy-YfS6uaw%40mail.gmail.com
Nathan Bossart [Fri, 16 Feb 2024 19:37:02 +0000 (13:37 -0600)]
Introduce overflow-safe integer comparison functions.
This commit adds integer comparison functions that are designed to
be as efficient as possible while avoiding overflow. A follow-up
commit will make use of these functions in many of the in-tree
qsort() comparators. The new functions are not better in all cases
(e.g., when the comparator function is inlined), so it is important
to consider the context before using them.
Author: Mats Kindahl
Reviewed-by: Tom Lane, Heikki Linnakangas, Andres Freund, Thomas Munro, Andrey Borodin, Fabrízio de Royes Mello
Discussion: https://postgr.es/m/CA%2B14426g2Wa9QuUpmakwPxXFWG_1FaY0AsApkvcTBy-YfS6uaw%40mail.gmail.com
Jeff Davis [Fri, 16 Feb 2024 19:09:11 +0000 (11:09 -0800)]
Pass correct count to WALRead().
Previously, some callers requested XLOG_BLCKSZ bytes
unconditionally. While this did not cause a problem, because the extra
bytes are ignored, it's confusing and makes it harder to add safety
checks. Additionally, the comment about zero padding was incorrect.
With this commit, all callers request the number of bytes they
actually need.
Author: Bharath Rupireddy
Reviewed-by: Kyotaro Horiguchi
Discussion: https://postgr.es/m/CALj2ACWBRFac2TingD3PE3w2EBHXUHY3=AEEZPJmqhpEOBGExg@mail.gmail.com
Jeff Davis [Fri, 16 Feb 2024 18:35:42 +0000 (10:35 -0800)]
Add assert to WALReadFromBuffers().
Per suggestion from Andres.
Discussion: https://postgr.es/m/
20240214025508[email protected]
Nathan Bossart [Fri, 16 Feb 2024 17:37:50 +0000 (11:37 -0600)]
Replace calls to pg_qsort() with the qsort() macro.
Calls to this function might give the impression that pg_qsort()
is somehow different than qsort(), when in fact there is a qsort()
macro in port.h that expands all in-tree uses to pg_qsort().
Reviewed-by: Mats Kindahl
Discussion: https://postgr.es/m/CA%2B14426g2Wa9QuUpmakwPxXFWG_1FaY0AsApkvcTBy-YfS6uaw%40mail.gmail.com
Alexander Korotkov [Fri, 16 Feb 2024 14:02:00 +0000 (16:02 +0200)]
Add missing check_stack_depth() to some recursive functions
Reported-by: Egor Chindyaskin, Alexander Lakhin
Discussion: https://postgr.es/m/
1672760457.
940462079%40f306.i.mail.ru
Alexander Korotkov [Fri, 16 Feb 2024 13:57:37 +0000 (15:57 +0200)]
Remove timeouts-long.out
bf82f43790 removes timeouts-long.spec, but forgets to remove timeouts-long.out.
Reported-by: Alexander Lakhin
Peter Eisentraut [Fri, 16 Feb 2024 10:51:35 +0000 (11:51 +0100)]
Improve compression and storage support with inheritance
A child table can specify a compression or storage method different
from its parents. This was previously an error. (But this was
inconsistently enforced because for example the settings could be
changed later using ALTER TABLE.) This now also allows an explicit
override if multiple parents have different compression or storage
settings, which was previously an error that could not be overridden.
The compression and storage properties remains unchanged in a child
inheriting from parent(s) after its creation, i.e., when using ALTER
TABLE ... INHERIT. (This is not changed.)
Before this change, the error detail would mention the first pair of
conflicting parent compression or storage methods. But with this
change it waits till the child specification is considered by which
time we may have encountered many such conflicting pairs. Hence the
error detail after this change does not include the conflicting
compression/storage methods. Those can be obtained from parent
definitions if necessary. The code to maintain list of all
conflicting methods or even the first conflicting pair does not seem
worth the convenience it offers. This change is inline with what we
do with conflicting default values.
Before this commit, the specified storage method could be stored in
ColumnDef::storage (CREATE TABLE ... LIKE) or ColumnDef::storage_name
(CREATE TABLE ...). This caused the MergeChildAttribute() and
MergeInheritedAttribute() to ignore a storage method specified in the
child definition since it looked only at ColumnDef::storage. This
commit removes ColumnDef::storage and instead uses
ColumnDef::storage_name to save any storage method specification. This
is similar to how compression method specification is handled.
Author: Ashutosh Bapat <
[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/
24656cec-d6ef-4d15-8b5b-
e8dfc9c833a7@eisentraut.org
Peter Eisentraut [Fri, 16 Feb 2024 10:39:09 +0000 (11:39 +0100)]
Remove non-existing file from .gitattributes
The file was removed by
ac25173cdbc.
Author: Jelte Fennema-Nio <
[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/CAGECzQQGzbroAXi%2BYicp3HvcCo4%3Dg84kaOgjuvQ5MW9F0ubOGg%40mail.gmail.com
Amit Kapila [Fri, 16 Feb 2024 09:12:50 +0000 (14:42 +0530)]
Disable autovacuum on primary in 040_standby_failover_slots_sync test.
Disable autovacuum to avoid generating xid during stats update as
otherwise the new XID could then be replicated to standby at some random
point making slots at primary lag behind standby during slot sync.
As per buildfarm
Author: Hou Zhijie
Discussion: https://postgr.es/m/
514f6f2f-6833-4539-39f1-
96cd1e011f23@enterprisedb.com
Discussion: https://postgr.es/m/CAA4eK1Jun8SGCoc6JEktxY_+L7GmoJWrdsx-KCEP=GL-SsWggQ@mail.gmail.com
Amit Kapila [Fri, 16 Feb 2024 06:04:11 +0000 (11:34 +0530)]
Fix the incorrect format specifier used in commit
7a424ece48.
Author: Hou Zhijie
Discussion: https://postgr.es/m/
514f6f2f-6833-4539-39f1-
96cd1e011f23@enterprisedb.com
Discussion: https://postgr.es/m/OS0PR01MB5716CB015BAD807B29BC55BE944C2@OS0PR01MB5716.jpnprd01.prod.outlook.com
Amit Kapila [Fri, 16 Feb 2024 04:43:51 +0000 (10:13 +0530)]
Change the LOG level in 040_standby_failover_slots_sync.pl to DEBUG2.
Temporarily change the log level of 040_standby_failover_slots_sync.pl to
DEBUG2. This is to get more information about BF failures. We will reset
it back to default once the tests are stabilized.
Author: Hou Zhijie
Reviewed-by: Amit Kapila
Discussion: https://postgr.es/m/
514f6f2f-6833-4539-39f1-
96cd1e011f23@enterprisedb.com
Discussion: https://postgr.es/m/OS0PR01MB571633C23B2A4CAC5FB0371A944C2@OS0PR01MB5716.jpnprd01.prod.outlook.com
Amit Kapila [Fri, 16 Feb 2024 03:32:54 +0000 (09:02 +0530)]
Add more LOG and DEBUG messages for slot synchronization.
This provides more information about remote slots during synchronization
which helps in debugging bugs and BF failures due to test case issues. We
might later want to change the LOG message added by this patch to DEBUG1.
Author: Hou Zhijie
Reviewed-by: Amit Kapila, Bertrand Drouvot
Discussion: https://postgr.es/m/
514f6f2f-6833-4539-39f1-
96cd1e011f23@enterprisedb.com
Discussion: https://postgr.es/m/OS0PR01MB571633C23B2A4CAC5FB0371A944C2@OS0PR01MB5716.jpnprd01.prod.outlook.com
David Rowley [Fri, 16 Feb 2024 02:01:29 +0000 (15:01 +1300)]
Attempt to stabilize flapping regression test
Per buildfarm animal mylodon, the plan for this test was sometimes
swapping the join order for tenk1 and tenk2. Given that add_path() has
no code that would cause this fluctuation when given paths with consistent
costs, this indicates that the costs must be fluctuating in some runs.
The only proven reason I've seen where that could happen was slight
variations in pg_class.relpages for some tables. This was demonstrated to
be true by
f03a9ca43 and related discussion. Manually adjusting tenk2's
pg_class.relpages by subtracting just 1 page does cause the plan to change
for this test.
Here we've not gone to the same lengths to prove that's what's going on
in this case. Proving that does not seem worth the time. Let's just
shrink one side of the join so the additional cost of the swapped join
order is sufficiently different that if the relpages estimate is off a few
pages that the planner still shouldn't swap the join order.
Reported-by: Thomas Munro
Author: Andy Fan, David Rowley
Discussion: https://postgr.es/m/CA+hUKGLqC-NobKYfjxNM3Gexv9OJ-Fhvy9bugUcXsZjTqH7W=Q@mail.gmail.com
Alexander Korotkov [Fri, 16 Feb 2024 01:36:38 +0000 (03:36 +0200)]
Followup fixes for transaction_timeout
Don't deal with transaction timeout in PostgresMain(). Instead, release
transaction timeout activated by StartTransaction() in
CommitTransaction()/AbortTransaction()/PrepareTransaction(). Deal with both
enabling and disabling transaction timeout in assign_transaction_timeout().
Also, remove potentially flaky timeouts-long isolation test, which has no
guarantees to pass on slow/busy machines.
Reported-by: Andres Freund
Discussion: https://postgr.es/m/
20240215230856.pc6k57tqxt7fhldm%40awork3.anarazel.de
Alexander Korotkov [Thu, 15 Feb 2024 21:34:11 +0000 (23:34 +0200)]
Introduce transaction_timeout
This commit adds timeout that is expected to be used as a prevention
of long-running queries. Any session within the transaction will be
terminated after spanning longer than this timeout.
However, this timeout is not applied to prepared transactions.
Only transactions with user connections are affected.
Discussion: https://postgr.es/m/CAAhFRxiQsRs2Eq5kCo9nXE3HTugsAAJdSQSmxncivebAxdmBjQ%40mail.gmail.com
Author: Andrey Borodin <
[email protected]>
Author: Japin Li <
[email protected]>
Author: Junwang Zhao <
[email protected]>
Reviewed-by: Nikolay Samokhvalov <[email protected]>
Reviewed-by: Andres Freund <[email protected]>
Reviewed-by: Fujii Masao <[email protected]>
Reviewed-by: bt23nguyent <[email protected]>
Reviewed-by: Yuhang Qiu <[email protected]>
Tom Lane [Thu, 15 Feb 2024 21:45:03 +0000 (16:45 -0500)]
Doc: improve a couple of comments in postgresql.conf.sample.
Clarify comments associated with max_parallel_workers and
related settings.
Per bug #18343 from Christopher Kline.
Discussion: https://postgr.es/m/18343-
3a5e903d1d3692ab@postgresql.org
Alexander Korotkov [Thu, 15 Feb 2024 10:05:52 +0000 (12:05 +0200)]
Pull up ANY-SUBLINK with the necessary lateral support.
For ANY-SUBLINK, we adopted a two-stage pull-up approach to handle
different types of scenarios. In the first stage, the sublink is pulled up
as a subquery. Because of this, when writing this code, we did not have
the ability to perform lateral joins, and therefore, we were unable to
pull up Var with varlevelsup=1. Now that we have the ability to use
lateral joins, we can eliminate this limitation.
Author: Andy Fan <
[email protected]>
Author: Tom Lane <
[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Reviewed-by: Richard Guo <[email protected]>
Reviewed-by: Alena Rybakina <[email protected]>
Reviewed-by: Andrey Lepikhov <[email protected]>
Peter Eisentraut [Thu, 15 Feb 2024 08:52:08 +0000 (09:52 +0100)]
Allow passing extra options to initdb for tests
Setting the environment variable PG_TEST_INITDB_EXTRA_OPTS passes
extra options to initdb run by pg_regress or
PostgreSQL::Test::Cluster's init.
This can be useful for a wide variety of uses, like running all tests
with checksums enabled, or with JIT enabled, or with different GUC
settings, or with different locale settings. (Not all tests are going
to pass with arbitrary options, but it is useful to run this against
specific test suites.)
Reviewed-by: Ian Lawrence Barwick <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/
d4d2ad9f-1c1d-47a1-bb4d-
c10a747d4f15%40eisentraut.org
Amit Kapila [Thu, 15 Feb 2024 05:07:28 +0000 (10:37 +0530)]
Another try to fix BF failure introduced in commit
ddd5f4f54a.
Before attempting to sync the slot on standby by
pg_sync_replication_slots(), ensure that on the primary restart_lsn for
the slot has moved to a recent WAL position, by re-creating the
subscription and the logical slot.
Author: Hou Zhijie
Discussion: https://postgr.es/m/CAA4eK1+d5Lne8vCAn0un4SP9x-ZBr2-xfxg01uSfeBTSCKFZoQ@mail.gmail.com
David Rowley [Thu, 15 Feb 2024 05:01:28 +0000 (18:01 +1300)]
Simplify PathKey checking code
pathkeys_useful_for_ordering() contained some needless checks to return
0 when either root->query_pathkeys or pathkeys lists were empty. This is
already handled by pathkeys_count_contained_in(), so let's have it do the
work instead of having redundant checks.
Similarly, in pathkeys_useful_for_grouping(), checking pathkeys is an
empty list just before looping over it isn't required. Technically,
neither is the list empty check for group_pathkeys, but I felt a bit
more work would have to be done to get the equivalent behavior if we'd
left it up to the foreach loop to call list_member_ptr().
This was noticed by Andy while he was reviewing a patch to improve the
UNION planner. Since that patch adds another function similar to
pathkeys_useful_for_ordering() and since I wasn't planning to copy these
redundant checks over to the new function, let's adjust the existing
code so that both functions will be consistent.
Author: Andy Fan
Discussion: https://postgr.es/m/
[email protected]
David Rowley [Thu, 15 Feb 2024 00:13:31 +0000 (13:13 +1300)]
Clarify the 'rows' parameter in create_append_path
This is extracted from a larger patch to improve the UNION planner.
While working on that, I found myself having to check what the 'rows'
parameter is for. It's not obvious that passing a negative number is the
way to have the rows estimate calculated and to find that out you need
to read code in create_append_path() and in cost_append().
Discussion: https://postgr.es/m/CAApHDvpb_63XQodmxKUF8vb9M7CxyUyT4sWvEgqeQU-GB7QFoQ@mail.gmail.com
Nathan Bossart [Wed, 14 Feb 2024 23:09:31 +0000 (17:09 -0600)]
Remove obsolete check in SIGTERM handler for the startup process.
Thanks to commit
3b00fdba9f, this check in the SIGTERM handler for
the startup process is now obsolete and can be removed. Instead of
leaving around the dead function write_stderr_signal_safe(), I've
opted to just remove it for now.
This partially reverts commit
97550c0711.
Reviewed-by: Andres Freund, Noah Misch
Discussion: https://postgr.es/m/
20231121212008.GA3742740%40nathanxps13
Nathan Bossart [Wed, 14 Feb 2024 22:34:18 +0000 (16:34 -0600)]
Centralize logic for restoring errno in signal handlers.
Presently, we rely on each individual signal handler to save the
initial value of errno and then restore it before returning if
needed. This is easily forgotten and, if missed, often goes
undetected for a long time.
In commit
3b00fdba9f, we introduced a wrapper signal handler
function that checks whether MyProcPid matches getpid(). This
commit moves the aforementioned errno restoration code from the
individual signal handlers to the new wrapper handler so that we no
longer need to worry about missing it.
Reviewed-by: Andres Freund, Noah Misch
Discussion: https://postgr.es/m/
20231121212008.GA3742740%40nathanxps13
Nathan Bossart [Wed, 14 Feb 2024 20:52:14 +0000 (14:52 -0600)]
Check that MyProcPid == getpid() in backend signal handlers.
In commit
97550c0711, we added a similar check to the SIGTERM
handler for the startup process. This commit adds this check to
backend signal handlers installed with pqsignal(). This is done by
using a wrapper function that performs the check before calling the
actual handler.
The hope is that this will offer more general protection against
child processes of Postgres backends inadvertently modifying shared
memory due to inherited signal handlers. Another potential
follow-up improvement is to use this wrapper handler function to
restore errno instead of relying on each individual handler
function to do so.
This commit makes the changes in commit
97550c0711 obsolete but
leaves reverting it for a follow-up commit.
Reviewed-by: Andres Freund, Noah Misch
Discussion: https://postgr.es/m/
20231121212008.GA3742740%40nathanxps13
Nathan Bossart [Wed, 14 Feb 2024 17:48:29 +0000 (11:48 -0600)]
Allow pg_monitor to execute pg_current_logfile().
We allow roles with privileges of pg_monitor to execute functions
like pg_ls_logdir(), so it seems natural that such roles would also
be able to execute this function.
Bumps catversion.
Co-authored-by: Pavlo Golub
Reviewed-by: Daniel Gustafsson
Discussion: https://postgr.es/m/CAK7ymcLmEYWyQkiCZ64WC-HCzXAB0omM%3DYpj9B3rXe8vUAFMqw%40mail.gmail.com
Tom Lane [Wed, 14 Feb 2024 16:30:39 +0000 (11:30 -0500)]
Fix multiranges to behave more like dependent types.
For most purposes, multiranges act like dependent objects of the
associated range type: you can't create them separately or drop them
separately. This is like the way that autogenerated array types
behave. However, a couple of points were overlooked: array types
automatically track the ownership of their base type, and array types
do not have their own permissions but use those of the base type,
while multiranges didn't emulate those behaviors. This is fairly
broken, mainly because pg_dump doesn't think it needs to worry about
multiranges as separate objects, and thus it fails to dump/restore
ownership or permissions of multiranges.
There's no apparent value in letting a multirange diverge from
its parent's ownership or permissions, so let's make them act like
arrays in these respects. However, we continue to let multiranges
be renamed or moved to a different schema independently of their
parent, since that doesn't break anything.
Discussion: https://postgr.es/m/
1580383.
1705343264@sss.pgh.pa.us
Amit Kapila [Wed, 14 Feb 2024 10:46:08 +0000 (16:16 +0530)]
Fix BF introduced in commit
ddd5f4f54a.
The failure is that the remote slot is not synchronized after the same
slot on standby gets invalidated. The reason was that remote_slot's
restart_lsn was lagged behind the standby's oldest WAL segment. The test
didn't ensure that remote_slot's LSN was advanced to the latest position
before we tried to sync the slots via new the function
pg_sync_replication_slots().
Discussion: https://postgr.es/m/CAA4eK1JLBi3HzenB6do3_hd78kN0UDD1mz-vumWE52XHHEq5Bw@mail.gmail.com
Daniel Gustafsson [Wed, 14 Feb 2024 10:05:10 +0000 (11:05 +0100)]
doc: Remove links to further reading from pgcrypto docs
The pgcrypto docs contained a set of links for useful reading and
technical references. These sets of links were however not actively
curated and had stale content and dead links. Rather than investing
time into maintining these, this removes them altogether since there
are lots of resources online which are actively maintained.
Backpatch to all supported versions since these links have been in
the docs for a long time.
Reported-by: Hanefi Onaldi <[email protected]>
Reviewed-by: Magnus Hagander <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/
170774255387.
3279713.
2822272755998870925@wrigleys.postgresql.org
Backpatch-through: v12
Amit Kapila [Wed, 14 Feb 2024 04:15:36 +0000 (09:45 +0530)]
Add a slot synchronization function.
This commit introduces a new SQL function pg_sync_replication_slots()
which is used to synchronize the logical replication slots from the
primary server to the physical standby so that logical replication can be
resumed after a failover or planned switchover.
A new 'synced' flag is introduced in pg_replication_slots view, indicating
whether the slot has been synchronized from the primary server. On a
standby, synced slots cannot be dropped or consumed, and any attempt to
perform logical decoding on them will result in an error.
The logical replication slots on the primary can be synchronized to the
hot standby by using the 'failover' parameter of
pg-create-logical-replication-slot(), or by using the 'failover' option of
CREATE SUBSCRIPTION during slot creation, and then calling
pg_sync_replication_slots() on standby. For the synchronization to work,
it is mandatory to have a physical replication slot between the primary
and the standby aka 'primary_slot_name' should be configured on the
standby, and 'hot_standby_feedback' must be enabled on the standby. It is
also necessary to specify a valid 'dbname' in the 'primary_conninfo'.
If a logical slot is invalidated on the primary, then that slot on the
standby is also invalidated.
If a logical slot on the primary is valid but is invalidated on the
standby, then that slot is dropped but will be recreated on the standby in
the next pg_sync_replication_slots() call provided the slot still exists
on the primary server. It is okay to recreate such slots as long as these
are not consumable on standby (which is the case currently). This
situation may occur due to the following reasons:
- The 'max_slot_wal_keep_size' on the standby is insufficient to retain
WAL records from the restart_lsn of the slot.
- 'primary_slot_name' is temporarily reset to null and the physical slot
is removed.
The slot synchronization status on the standby can be monitored using the
'synced' column of pg_replication_slots view.
A functionality to automatically synchronize slots by a background worker
and allow logical walsenders to wait for the physical will be done in
subsequent commits.
Author: Hou Zhijie, Shveta Malik, Ajin Cherian based on an earlier version by Peter Eisentraut
Reviewed-by: Masahiko Sawada, Bertrand Drouvot, Peter Smith, Dilip Kumar, Nisha Moond, Kuroda Hayato, Amit Kapila
Discussion: https://postgr.es/m/
514f6f2f-6833-4539-39f1-
96cd1e011f23@enterprisedb.com
Michael Paquier [Wed, 14 Feb 2024 01:07:22 +0000 (10:07 +0900)]
Revert "Refactor CopyReadAttributes{CSV,Text}() to use a callback in COPY FROM"
This reverts commit
95fb5b49024, for reasons similar to what led to
1aa8324b81fa. In this case, the callback was called once per row, which
is less worse than the previous callback introduced for COPY TO called
once per argument for each row, still the patch set discussed to plug in
custom routines to the COPY paths would be able to know which subroutine
to use depending on its CopyFromState, so this led to a suboptimal
approach at the end.
For now, this part is reverted to consider better which approach to use.
Discussion: https://postgr.es/m/
20240206014125[email protected]
Michael Paquier [Tue, 13 Feb 2024 23:59:05 +0000 (08:59 +0900)]
pgcrypto: Fix incorrect argument vs PG_GETARG*() mappings
The following functions use a mix of bytea and text arguments, but their
C internals always used PG_GETARG_BYTEA_PP(), creating an incorrect mix
with the argument types expected by encrypt_internal():
- pgp_sym_encrypt_bytea(bytea,text[,text])
- pgp_sym_encrypt(text,text[,text])
- pgp_sym_decrypt_bytea(bytea,text[,text])
- pgp_sym_decrypt(bytea,text[,text])
- pgp_pub_encrypt_bytea(bytea,bytea[,text])
- pgp_pub_encrypt(text,bytea[,text])
- pgp_pub_decrypt_bytea(bytea, bytea[,text[,text]])
- pgp_pub_decrypt(bytea,bytea[,text[,text]])
This commit fixes the inconsistencies between the PG_GETARG*() macros
and the argument types of each function.
Both BYTEA_PP() and TEXT_PP() rely on PG_DETOAST_DATUM_PACKED(), that
returns an unaligned pointer, so this was not leading to an actual
problem as far as I know, but let's be consistent.
Author: Shihao Zhong
Discussion: https://postgr.es/m/CAGRkXqRfiWT--DzVPx_UGpNHTt0YT5Jo8eV2CtT56jNP=QpXSQ@mail.gmail.com
Michael Paquier [Tue, 13 Feb 2024 22:20:15 +0000 (07:20 +0900)]
Improve comment about query_id_enabled in queryjumblefuncs.c
The comment was inexact because query_id_enabled will not be switched to
"true" even if compute_query_id is "on", unless a module requests for
it.
While on it, this adds a comment to mention that IsQueryIdEnabled()
should be used to check if query ID computation is enabled or not.
Author: Yugo Nagata
Reviewed-by: Julien Rouhaud
Discussion: https://postgr.es/m/
20240209153823.
e29a68cadb14225f1362a2cf@sraoss.co.jp
Tom Lane [Tue, 13 Feb 2024 20:58:40 +0000 (15:58 -0500)]
Catch overflow when rounding intervals in AdjustIntervalForTypmod.
Previously, an interval microseconds field close to INT64_MAX or
INT64_MIN could overflow, producing a result with not even the
correct sign, while being rounded to match a precision specification.
This seems worth fixing, but not worth back-patching, in part
because the ereturn() notation doesn't exist very far back.
Report and patch by Joseph Koshakow (some cosmetic mods by me)
Discussion: https://postgr.es/m/CAAvxfHfpuLgqJYzkUcher466Z1LpmE+5Sm+zc8L6zKCOQ+6TDQ@mail.gmail.com
Heikki Linnakangas [Tue, 13 Feb 2024 19:23:41 +0000 (21:23 +0200)]
Fix 'mmap' DSM implementation with allocations larger than 4 GB
Fixes bug #18341. Backpatch to all supported versions.
Discussion: https://www.postgresql.org/message-id/18341-
ce16599e7fd6228c@postgresql.org
Tom Lane [Tue, 13 Feb 2024 17:18:25 +0000 (12:18 -0500)]
Use a safer outfuncs/readfuncs representation for BitStrings.
For a long time, our outfuncs.c code has supposed that the string
contents of a BitString node could just be printed literally with
no concern for quoting/escaping. Now, that's okay if the string
literal contains only valid binary or hex digits ... but our lexer
doesn't check that, preferring to let bitin() be the sole authority
on what's valid. So we could have raw parse trees that contain
incorrect BitString literals, and that can result in failures when
WRITE_READ_PARSE_PLAN_TREES debugging is enabled.
Fix by using outToken() to print the string field, and debackslash()
to read it. This results in a change in the emitted representation
only in cases that would have failed before, and don't represent valid
SQL in the first place. Between that and the fact that we don't store
raw parse trees in the catalogs, I judge this safe to apply without a
catversion bump.
Per bug #18340 from Alexander Lakhin. Back-patch to v16; before that,
we lacked readfuncs support for BitString nodes, so that the problem
was only cosmetic.
Discussion: https://postgr.es/m/18340-
4aa1ae6ed4121912@postgresql.org
Daniel Gustafsson [Tue, 13 Feb 2024 12:47:12 +0000 (13:47 +0100)]
Skip .DS_Store files in server side utils
The macOS Finder application creates .DS_Store files in directories
when opened, which creates problems for serverside utilities which
expect all files to be PostgreSQL specific files. Skip these files
when encountered in pg_checksums, pg_rewind and pg_basebackup.
This was extracted from a larger patchset for skipping hidden files
and system files, where the concencus was to just skip these. Since
this is equally likely to happen in every version, backpatch to all
supported versions.
Reported-by: Mark Guertin <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
Reviewed-by: Tobias Bussmann <[email protected]>
Discussion: https://postgr.es/m/
E258CE50-AB0E-455D-8AAD-
BB4FE8F882FB@gmail.com
Backpatch-through: v12
Peter Eisentraut [Tue, 13 Feb 2024 05:54:58 +0000 (06:54 +0100)]
Use correct format placeholder for timeline IDs
Should be %u rather than %d.
Amit Kapila [Tue, 13 Feb 2024 04:15:01 +0000 (09:45 +0530)]
Doc: Improve upgrade for streaming replication section.
Currently the documentation of upgrade for streaming replication section
says that logical replication slots will be copied, but the logical
replication slots are copied only if the old primary is version 17.0 or
later.
Author: Shubham Khanna
Discussion: https://postgr.es/m/CAHv8RjJHCw0jpUo9PZxjcguzGt3j2W1_NH=QuREoN0nYiVdVeA@mail.gmail.com
Jeff Davis [Mon, 12 Feb 2024 18:36:18 +0000 (10:36 -0800)]
Read WAL directly from WAL buffers.
If available, read directly from WAL buffers, avoiding the need to go
through the filesystem. Only for physical replication for now, but can
be expanded to other callers.
In preparation for replicating unflushed WAL data.
Author: Bharath Rupireddy
Discussion: https://postgr.es/m/CALj2ACXKKK%3DwbiG5_t6dGao5GoecMwRkhr7GjVBM_jg54%2BNa%3DQ%40mail.gmail.com
Reviewed-by: Andres Freund, Alvaro Herrera, Nathan Bossart, Dilip Kumar, Nitin Jadhav, Melih Mutlu, Kyotaro Horiguchi
Heikki Linnakangas [Mon, 12 Feb 2024 09:57:45 +0000 (11:57 +0200)]
Remove "#ifdef WIN32" guards from src/port/win32*.c
These files are only compiled on Windows, and most of them didn't have
"#ifdef WIN32" guards. Remove them from the few that did, for
consistency.
Author: Tristan Partin
Discussion: https://www.postgresql.org/message-id/
[email protected]
Heikki Linnakangas [Mon, 12 Feb 2024 08:59:45 +0000 (10:59 +0200)]
Remove unnecessary smgropen() calls
Now that RelationCreateStorage() returns the SmgrRelation (since
commit
5c1560606dc), use that.
Author: Japin Li
Discussion: https://www.postgresql.org/message-id/ME3P282MB316600FA62F6605477F26F6AB6742@ME3P282MB3166.AUSP282.PROD.OUTLOOK.COM
Alexander Korotkov [Sun, 11 Feb 2024 22:33:51 +0000 (00:33 +0200)]
Fix some typos in event trigger docs
Discussion: https://postgr.es/m/CALj2ACWFUW4jX9EW7CLxbzSS%2Bb7b0Z%3DxKYrqzj2Rstc9MCEx7g%40mail.gmail.com
Author: Bharath Rupireddy