users/rhaas/postgres.git
3 years agoavoid stepping on memory that's still needed conveyor_old
Robert Haas [Tue, 14 Dec 2021 20:09:01 +0000 (15:09 -0500)]
avoid stepping on memory that's still needed

3 years agoconveyor_ext
Dilip Kumar [Thu, 14 Oct 2021 14:12:59 +0000 (19:42 +0530)]
conveyor_ext

3 years agoAdd DEADTID_FORK
Dilip Kumar [Sat, 23 Oct 2021 10:03:13 +0000 (15:33 +0530)]
Add DEADTID_FORK

3 years agowhen vacuuming, handle uninitialized index pages without barfing
Robert Haas [Thu, 9 Dec 2021 23:15:56 +0000 (18:15 -0500)]
when vacuuming, handle uninitialized index pages without barfing

3 years agomore (untested) code to remove obsolete index pages
Robert Haas [Thu, 9 Dec 2021 21:06:10 +0000 (16:06 -0500)]
more (untested) code to remove obsolete index pages

3 years agosome infrastructure for removing obsolete index pages
Robert Haas [Tue, 7 Dec 2021 20:12:34 +0000 (15:12 -0500)]
some infrastructure for removing obsolete index pages

3 years agoFix more bugs when inserting a lot of data.
Robert Haas [Fri, 3 Dec 2021 10:50:28 +0000 (05:50 -0500)]
Fix more bugs when inserting a lot of data.

cb_fsmpage_get_fsm_bit was supposed to test whether a certain bit
is set in the page, but randomly used the wrong variable. Fixed.

cbfsmpage_find_free_segment used buggy logic. Replace with logic
modelled on the latest version of cb_metapage_find_free_segment.

ConveyorSearchFSMPages had an off-by-one error in the code that
decides where the last FSM page was, and a separate off-by-one
error in the code that decides whether to extend the relation.
Repair both of those.

All per test case from Dilip Kumar.

3 years agoFix dubious logic in cb_metapage_remove_index_entries.
Robert Haas [Mon, 15 Nov 2021 18:43:36 +0000 (13:43 -0500)]
Fix dubious logic in cb_metapage_remove_index_entries.

Per another problem report from Dilip Kumar.

3 years agoFix calculation of pageoffset when relocating index entries.
Robert Haas [Fri, 12 Nov 2021 14:26:20 +0000 (09:26 -0500)]
Fix calculation of pageoffset when relocating index entries.

The previous formula had no chance of being correct if the number
of pages per segment was >1, and even then it might not have
worked if we'd trimmed a number of index entries straight out
of the metapage that was not a multiple of the number that will
fit in an index page. Try to do better.

Along the way, fix an off-by-one error in a sanity check.

Per test case from Dilip Kumar.

3 years agofix confusion in ConveyorBeltVacuum
Robert Haas [Wed, 10 Nov 2021 15:56:27 +0000 (10:56 -0500)]
fix confusion in ConveyorBeltVacuum

per report from Dilip Kumar

3 years agorudimentary first attmpt at ConveyorBeltVacuum()
Robert Haas [Fri, 5 Nov 2021 19:30:05 +0000 (15:30 -0400)]
rudimentary first attmpt at ConveyorBeltVacuum()

doesn't even try to handle index pages, but theoretically vacuuming
index entries out of the metapage should work. code is untested,
however.

3 years agofix more bugs in conveyor belt insertion
Robert Haas [Thu, 4 Nov 2021 14:31:29 +0000 (10:31 -0400)]
fix more bugs in conveyor belt insertion

- cb_metapage_remove_index_entries didn't properly clear the entries
  that were removed, due to bad math

- ConveyorBeltGetNewPage had an unnecessary call to ConveyorBeltRead

- ConveyorBeltGetNewPage also forget to release the lock and pin
  on a candidate payload page that turned out not to be empty

all per testing with a test case provided by Dilip Kumar

3 years agofix various oversights and omissions in conveyor belt xlog support
Robert Haas [Thu, 4 Nov 2021 14:30:48 +0000 (10:30 -0400)]
fix various oversights and omissions in conveyor belt xlog support

per test case from Dilip Kumar

3 years agoFix assorted bugs related to index pages.
Robert Haas [Tue, 2 Nov 2021 19:02:49 +0000 (15:02 -0400)]
Fix assorted bugs related to index pages.

- cb_metapage_get_insert_state needs to return
  CBM_INSERT_NEEDS_INDEX_SEGMENT not only when the latest index
  segment is full but also when there are no index segments in
  existence yet.

- cb_metapage_remove_index_entries can't treat cbm_index_start
  == cbm_index_metapage_start as an error, or we'll never be able
  to move the first set of index entries out of the metapage.

- ConveyorBeltGetNewPage can allocate a new index segment without
  having a lock on prevbuffer if there are no index segments
  yet, since there is no such things as the previous index segment
  in that case.

- When we create a new index segment and then decide that our next
  action should be to relocate index entries into it, we must use
  the correct value for next_blkno.

- When adding the very first index segment, don't try to pin the
  first page of the previous index segment, since there isn't one.

- When adding a new index segment, use the free buffer we
  identified, rather than an uninitialized variable.

All per a test case from Dilip Kumar.

3 years agorequire std pages, and that newly insert pages are visibly non-empty
Robert Haas [Fri, 15 Oct 2021 19:35:22 +0000 (15:35 -0400)]
require std pages, and that newly insert pages are visibly non-empty

3 years agodivide conveyor.h into sections
Robert Haas [Fri, 15 Oct 2021 18:59:09 +0000 (14:59 -0400)]
divide conveyor.h into sections

3 years agostart of code to identify obsolete index entries + remove them
Robert Haas [Fri, 15 Oct 2021 18:54:18 +0000 (14:54 -0400)]
start of code to identify obsolete index entries + remove them

3 years agoupdate README
Robert Haas [Fri, 15 Oct 2021 14:16:10 +0000 (10:16 -0400)]
update README

3 years agoadd ConveyorBeltLogicalTruncate
Robert Haas [Fri, 15 Oct 2021 14:12:36 +0000 (10:12 -0400)]
add ConveyorBeltLogicalTruncate

3 years agoadd missing 'static' keyword
Robert Haas [Fri, 15 Oct 2021 13:25:21 +0000 (09:25 -0400)]
add missing 'static' keyword

3 years agofix UnlockRelationForExtension second argument some more
Robert Haas [Thu, 14 Oct 2021 14:29:13 +0000 (10:29 -0400)]
fix UnlockRelationForExtension second argument some more

3 years agopartially clean up relation extension logic
Robert Haas [Thu, 7 Oct 2021 18:19:04 +0000 (14:19 -0400)]
partially clean up relation extension logic

3 years agopossibly_not_on_disk_segno -> possibly_not_on_disk_blkno
Robert Haas [Mon, 4 Oct 2021 01:20:47 +0000 (21:20 -0400)]
possibly_not_on_disk_segno -> possibly_not_on_disk_blkno

already had this in one place, but let's expand the practice, as
it seems cleaner

3 years agowire up the code to add index entries, mostly.
Robert Haas [Fri, 1 Oct 2021 19:44:48 +0000 (15:44 -0400)]
wire up the code to add index entries, mostly.

3 years agocbm_flags -> cbm_entries_in_newest_index_segment
Robert Haas [Fri, 1 Oct 2021 18:57:58 +0000 (14:57 -0400)]
cbm_flags -> cbm_entries_in_newest_index_segment

3 years agorip out cbidx_pages_initialized and a bunch of related complexity
Robert Haas [Fri, 1 Oct 2021 17:35:22 +0000 (13:35 -0400)]
rip out cbidx_pages_initialized and a bunch of related complexity

3 years agoadd backstop infinite loop detector to ConveyorBeltGetNewPage
Robert Haas [Fri, 1 Oct 2021 15:35:22 +0000 (11:35 -0400)]
add backstop infinite loop detector to ConveyorBeltGetNewPage

3 years agofix stupid bug
Robert Haas [Wed, 29 Sep 2021 15:06:23 +0000 (11:06 -0400)]
fix stupid bug

3 years agoattempt to unbreak concurrent processes trying to add payload segments
Robert Haas [Tue, 28 Sep 2021 19:08:00 +0000 (15:08 -0400)]
attempt to unbreak concurrent processes trying to add payload segments

3 years agodraft support for (1) allocating a new index page and (2) relocating
Robert Haas [Mon, 27 Sep 2021 19:39:52 +0000 (15:39 -0400)]
draft support for (1) allocating a new index page and (2) relocating
index entries from the metapage to an index page.

this isn't wired into ConveyorBeltGetNewPage yet. it's just stuff
that function will need to call to do this stuff. or so I think.

3 years agoremove some excess parens. rearrange lock ordering slightly.
Robert Haas [Thu, 23 Sep 2021 17:11:51 +0000 (13:11 -0400)]
remove some excess parens. rearrange lock ordering slightly.

3 years agofix dumb mistake
Robert Haas [Thu, 23 Sep 2021 16:50:27 +0000 (12:50 -0400)]
fix dumb mistake
recode something that probably wouldn't work with 1 page per segment
reindent

3 years agolock the buffer
Robert Haas [Thu, 23 Sep 2021 15:36:53 +0000 (11:36 -0400)]
lock the buffer

3 years agocode to extend the relation when adding a payload page, if needed
Robert Haas [Thu, 23 Sep 2021 14:14:41 +0000 (10:14 -0400)]
code to extend the relation when adding a payload page, if needed

also fix failure to get relation extension lock in a related code
path

3 years agofix buffer lock mode
Robert Haas [Wed, 22 Sep 2021 20:43:23 +0000 (16:43 -0400)]
fix buffer lock mode

3 years agotry to fix some sketchy logic for setting can_allocate_segment
Robert Haas [Wed, 22 Sep 2021 20:06:15 +0000 (16:06 -0400)]
try to fix some sketchy logic for setting can_allocate_segment

3 years agoa bit less S
Robert Haas [Wed, 22 Sep 2021 19:22:20 +0000 (15:22 -0400)]
a bit less S

3 years agoreplace cb_metapage_find_free_segment with something less clever but
Robert Haas [Wed, 22 Sep 2021 19:18:53 +0000 (15:18 -0400)]
replace cb_metapage_find_free_segment with something less clever but
maybe more correct

3 years agoadd a function to get the conveyor belt bounds
Robert Haas [Wed, 22 Sep 2021 16:43:48 +0000 (12:43 -0400)]
add a function to get the conveyor belt bounds

per suggestion from Mark

3 years agofix wrong function name in comment
Robert Haas [Tue, 21 Sep 2021 17:30:41 +0000 (13:30 -0400)]
fix wrong function name in comment

per inquiry from Mark Dilger

3 years agoremove code that's not supposed to be there
Robert Haas [Tue, 21 Sep 2021 13:18:19 +0000 (09:18 -0400)]
remove code that's not supposed to be there

per bug report from Mark Dilger

3 years agocode to add index segments
Robert Haas [Mon, 20 Sep 2021 19:21:23 +0000 (15:21 -0400)]
code to add index segments

3 years agocan_allocate_segment could end up true on the first pass through the
Robert Haas [Mon, 20 Sep 2021 18:07:01 +0000 (14:07 -0400)]
can_allocate_segment could end up true on the first pass through the
loop, when we don't hold an exclusive lock. fix.

3 years agolock ordering rules
Robert Haas [Mon, 20 Sep 2021 17:40:15 +0000 (13:40 -0400)]
lock ordering rules

3 years agotry to make README a tad more clear
Robert Haas [Mon, 20 Sep 2021 17:25:38 +0000 (13:25 -0400)]
try to make README a tad more clear

per a question from Mark

3 years agosketch out WAL support for adding index segments
Robert Haas [Mon, 20 Sep 2021 17:21:15 +0000 (13:21 -0400)]
sketch out WAL support for adding index segments

3 years agomove some code to more sensible places, and reindent
Robert Haas [Mon, 20 Sep 2021 16:19:00 +0000 (12:19 -0400)]
move some code to more sensible places, and reindent

3 years agoWIP: Conveyor belt storage.
Robert Haas [Sun, 19 Sep 2021 23:58:12 +0000 (19:58 -0400)]
WIP: Conveyor belt storage.

This code is highly incomplete and even the parts that are written
are likely riddled with bugs.

For an overview of the ideas I have in mind, please check out
src/backend/access/conveyor/README

3 years agoFix hash_array
Peter Eisentraut [Wed, 15 Sep 2021 09:59:34 +0000 (11:59 +0200)]
Fix hash_array

Commit a3d2b1bbe904b0ca8d9fdde20f25295ff3e21f79 neglected to
initialize the type_id field of the synthesized type cache entry, so
it would make a new one on every call.

Also, better use the per-function memory context for this; otherwise
it leaks memory.

Discussion: https://www.postgresql.org/message-id/flat/17158-8a2ba823982537a4%40postgresql.org

3 years agodoc: Clarify refresh options for DROP PUBLICATION
Daniel Gustafsson [Wed, 15 Sep 2021 07:54:45 +0000 (09:54 +0200)]
doc: Clarify refresh options for DROP PUBLICATION

The available refresh options are specified as refresh_options under
REFRESH PUBLICATION, and DROP PUBLICATION itself has an option named
refresh. Clarify what we mean by refresh options to avoid confusion.

Backpatch through v14 where ALTER SUBSCRIPTION ... DROP PUBLICATION
was introduced.

Author: Masahiko Sawada <[email protected]>
Reviewed-by: Amit Kapila <[email protected]>
Reviewed-by: Peter Eisentraut <[email protected]>
Reviewed-by: Peter Smith <[email protected]>
Discussion: https://postgr.es/m/CAD21AoCm1wJ3A8Q9EmBjRbShYkJ+o+Oa_z9O0hvwhvhUa2BSyg@mail.gmail.com
Backpatch-through: 14

3 years agoFix incorrect format placeholders
Peter Eisentraut [Wed, 15 Sep 2021 07:19:01 +0000 (09:19 +0200)]
Fix incorrect format placeholders

Also remove obsolete comments about why the 64-bit integers need to be
printed in a separate buffer.  The reason used to be portability, but
now the remaining reason is that we need the string lengths for the
progress displays.  That is evident by looking at the code right
below, so a new comment doesn't seem necessary.

3 years agoUpdate Unicode data to Unicode 14.0.0
Peter Eisentraut [Wed, 15 Sep 2021 06:04:49 +0000 (08:04 +0200)]
Update Unicode data to Unicode 14.0.0

3 years agoUpdate README for resource owners about the resource types supported
Michael Paquier [Wed, 15 Sep 2021 01:47:44 +0000 (10:47 +0900)]
Update README for resource owners about the resource types supported

All the types supported were listed directly in the README, but it was
very outdated.  Rather than listing all the types supported in the
README, this commit adds a reference to look at ResourceOwnerData in
resowner.c to get this information.

The order of the paragraphs is reworked a bit for clarity.

Author: Amit Langote
Discussion: https://postgr.es/m/CA+HiwqHtfT9z=4H5+F7DOy0OyNHAaVwuRcakt9b2t2uADOaiag@mail.gmail.com

3 years agoImprove log messages from pg_import_system_collations().
Tom Lane [Tue, 14 Sep 2021 22:55:15 +0000 (18:55 -0400)]
Improve log messages from pg_import_system_collations().

pg_import_system_collations() was a bit inconsistent about how it
reported locales (names output by "locale -a") that it didn't make
pg_collation entries for.  IMV we should print some suitable message
for every locale that we reject, except when it matches a pre-existing
pg_collation entry.  (This is all at DEBUG1 log level, though, so as
not to create noise during initdb.)  Add messages for the two cases
that were previously not logged, namely unrecognized encoding and
client-only encoding.  Re-word the existing messages to have a
consistent style.

Anton Voloshin and Tom Lane

Discussion: https://postgr.es/m/429d64ee-188d-3ce1-106a-53a8b45c4fce@postgrespro.ru

3 years agoSend NOTIFY signals during CommitTransaction.
Tom Lane [Tue, 14 Sep 2021 21:18:25 +0000 (17:18 -0400)]
Send NOTIFY signals during CommitTransaction.

Formerly, we sent signals for outgoing NOTIFY messages within
ProcessCompletedNotifies, which was also responsible for sending
relevant ones of those messages to our connected client.  It therefore
had to run during the main-loop processing that occurs just before
going idle.  This arrangement had two big disadvantages:

* Now that procedures allow intra-command COMMITs, it would be
useful to send NOTIFYs to other sessions immediately at COMMIT
(though, for reasons of wire-protocol stability, we still shouldn't
forward them to our client until end of command).

* Background processes such as replication workers would not send
NOTIFYs at all, since they never execute the client communication
loop.  We've had requests to allow triggers running in replication
workers to send NOTIFYs, so that's a problem.

To fix these things, move transmission of outgoing NOTIFY signals
into AtCommit_Notify, where it will happen during CommitTransaction.
Also move the possible call of asyncQueueAdvanceTail there, to
ensure we don't bloat the async SLRU if a background worker sends
many NOTIFYs with no one listening.

We can also drop the call of asyncQueueReadAllNotifications,
allowing ProcessCompletedNotifies to go away entirely.  That's
because commit 790026972 added a call of ProcessNotifyInterrupt
adjacent to PostgresMain's call of ProcessCompletedNotifies,
and that does its own call of asyncQueueReadAllNotifications,
meaning that we were uselessly doing two such calls (inside two
separate transactions) whenever inbound notify signals coincided
with an outbound notify.  We need only set notifyInterruptPending
to ensure that ProcessNotifyInterrupt runs, and we're done.

The existing documentation suggests that custom background workers
should call ProcessCompletedNotifies if they want to send NOTIFY
messages.  To avoid an ABI break in the back branches, reduce it
to an empty routine rather than removing it entirely.  Removal
will occur in v15.

Although the problems mentioned above have existed for awhile,
I don't feel comfortable back-patching this any further than v13.
There was quite a bit of churn in adjacent code between 12 and 13.
At minimum we'd have to also backpatch 51004c717, and a good deal
of other adjustment would also be needed, so the benefit-to-risk
ratio doesn't look attractive.

Per bug #15293 from Michael Powers (and similar gripes from others).

Artur Zakirov and Tom Lane

Discussion: https://postgr.es/m/153243441449.1404.2274116228506175596@wrigleys.postgresql.org

3 years agoFix planner error with multiple copies of an AlternativeSubPlan.
Tom Lane [Tue, 14 Sep 2021 19:11:21 +0000 (15:11 -0400)]
Fix planner error with multiple copies of an AlternativeSubPlan.

It's possible for us to copy an AlternativeSubPlan expression node
into multiple places, for example the scan quals of several
partition children.  Then it's possible that we choose a different
one of the alternatives as optimal in each place.  Commit 41efb8340
failed to consider this scenario, so its attempt to remove "unused"
subplans could remove subplans that were still used elsewhere.

Fix by delaying the removal logic until we've examined all the
AlternativeSubPlans in a given query level.  (This does assume that
AlternativeSubPlans couldn't get copied to other query levels, but
for the foreseeable future that's fine; cf qual_is_pushdown_safe.)

Per report from Rajkumar Raghuwanshi.  Back-patch to v14
where the faulty logic came in.

Discussion: https://postgr.es/m/CAKcux6==O3NNZC3bZ2prRYv3cjm3_Zw1GfzmOjEVqYN4jub2+Q@mail.gmail.com

3 years agoAdd WRITE_INDEX_ARRAY
Peter Eisentraut [Tue, 14 Sep 2021 07:34:50 +0000 (09:34 +0200)]
Add WRITE_INDEX_ARRAY

We have a few WRITE_{name of type}_ARRAY macros, but the one case
using the Index type was hand-coded.  Wrap it into a macro as well.

This also changes the behavior slightly: Before, the field name was
skipped if the length was zero.  Now it prints the field name even in
that case.  This is more consistent with how other array fields are
handled.

Reviewed-by: Jacob Champion <[email protected]>
Discussion: https://www.postgresql.org/message-id/c091e5cd-45f8-69ee-6a9b-de86912cc7e7@enterprisedb.com

3 years agoAdd COPY_ARRAY_FIELD and COMPARE_ARRAY_FIELD
Peter Eisentraut [Tue, 14 Sep 2021 07:34:50 +0000 (09:34 +0200)]
Add COPY_ARRAY_FIELD and COMPARE_ARRAY_FIELD

These handle node fields that are inline arrays (as opposed to
dynamically allocated arrays handled by COPY_POINTER_FIELD and
COMPARE_POINTER_FIELD).  These cases were hand-coded until now.

Reviewed-by: Jacob Champion <[email protected]>
Discussion: https://www.postgresql.org/message-id/c091e5cd-45f8-69ee-6a9b-de86912cc7e7@enterprisedb.com

3 years agoRemove T_Expr
Peter Eisentraut [Tue, 14 Sep 2021 07:34:50 +0000 (09:34 +0200)]
Remove T_Expr

This is an abstract node that shouldn't have a node tag defined.

Reviewed-by: Jacob Champion <[email protected]>
Discussion: https://www.postgresql.org/message-id/c091e5cd-45f8-69ee-6a9b-de86912cc7e7@enterprisedb.com

3 years agojit: Do not try to shut down LLVM state in case of LLVM triggered errors.
Andres Freund [Tue, 14 Sep 2021 01:07:19 +0000 (18:07 -0700)]
jit: Do not try to shut down LLVM state in case of LLVM triggered errors.

If an allocation failed within LLVM it is not safe to call back into LLVM as
LLVM is not generally safe against exceptions / stack-unwinding. Thus errors
while in LLVM code are promoted to FATAL. However llvm_shutdown() did call
back into LLVM even in such cases, while llvm_release_context() was careful
not to do so.

We cannot generally skip shutting down LLVM, as that can break profiling. But
it's OK to do so if there was an error from within LLVM.

Reported-By: Jelte Fennema <[email protected]>
Author: Andres Freund <[email protected]>
Author: Justin Pryzby <[email protected]>
Discussion: https://postgr.es/m/AM5PR83MB0178C52CCA0A8DEA0207DC14F7FF9@AM5PR83MB0178.EURPRD83.prod.outlook.com
Backpatch: 11-, where jit was introduced

3 years agoRemove code duplication for permission checks with replication slots
Michael Paquier [Tue, 14 Sep 2021 01:15:49 +0000 (10:15 +0900)]
Remove code duplication for permission checks with replication slots

Two functions, both named check_permissions(), used the same checks to
verify if a user had required privileges to work on replication slots.
This commit removes the duplication, and moves the function doing the
checks to slot.c to be centralized.

Author: Bharath Rupireddy
Reviewed-by: Nathan Bossart, Euler Taveira
Discussion: https://postgr.es/m/CALj2ACUPpVw1u7sQocFVWrSs0n10pt_G_4NPZKSxXK6cW1dErw@mail.gmail.com

3 years agoClear conn->errorMessage at successful completion of PQconnectdb().
Tom Lane [Mon, 13 Sep 2021 20:53:11 +0000 (16:53 -0400)]
Clear conn->errorMessage at successful completion of PQconnectdb().

Commits ffa2e4670 and 52a10224e caused libpq's connection-establishment
functions to usually leave a nonempty string in the connection's
errorMessage buffer, even after a successful connection.  While that
was intentional on my part, more sober reflection says that it wasn't
a great idea: the string would be a bit confusing.  Also this broke at
least one application that checked for connection success by examining
the errorMessage, instead of using PQstatus() as documented.  Let's
clear the buffer at success exit, restoring the pre-v14 behavior.

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

3 years agoDoc: improve documentation of CREATE/ALTER SUBSCRIPTION.
Tom Lane [Mon, 13 Sep 2021 18:27:02 +0000 (14:27 -0400)]
Doc: improve documentation of CREATE/ALTER SUBSCRIPTION.

Improve the descriptions of some options.  Fix sloppy grammar and markup.

Peter Smith and Tom Lane

Discussion: https://postgr.es/m/CAHut+PtPJDSOxtuMGpO2yDrRPKxcYGL4n7HqJP9HernZE=Cj+g@mail.gmail.com

3 years agoFix EXIT out of outermost block in plpgsql.
Tom Lane [Mon, 13 Sep 2021 16:42:03 +0000 (12:42 -0400)]
Fix EXIT out of outermost block in plpgsql.

Ordinarily, using EXIT this way would draw "control reached end of
function without RETURN".  However, if the function is one where we
don't require an explicit RETURN (such as a DO block), that should
not happen.  It did anyway, because add_dummy_return() neglected to
account for the case.

Per report from Herwig Goemans.  Back-patch to all supported branches.

Discussion: https://postgr.es/m/868ae948-e3ca-c7ec-95a6-83cfc08ef750@gmail.com

3 years agoFix reorder buffer memory accounting for toast changes.
Amit Kapila [Mon, 13 Sep 2021 04:54:00 +0000 (10:24 +0530)]
Fix reorder buffer memory accounting for toast changes.

While processing toast changes in logical decoding, we rejigger the
tuple change to point to in-memory toast tuples instead to on-disk toast
tuples. And, to make sure the memory accounting is correct, we were
subtracting the old change size and then after re-computing the new tuple,
re-adding its size at the end. Now, if there is any error before we add
the new size, we will release the changes and that will update the
accounting info (subtracting the size from the counters). And we were
underflowing there which leads to an assertion failure in assert enabled
builds and wrong memory accounting in reorder buffer otherwise.

Author: Bertrand Drouvot
Reviewed-by: Amit Kapila
Backpatch-through: 13, where memory accounting was introduced
Discussion: https://postgr.es/m/92b0ee65-b8bd-e42d-c082-4f3f4bf12d34@amazon.com

3 years agoFix error handling with threads on OOM in ECPG connection logic
Michael Paquier [Mon, 13 Sep 2021 04:23:50 +0000 (13:23 +0900)]
Fix error handling with threads on OOM in ECPG connection logic

An out-of-memory failure happening when allocating the structures to
store the connection parameter keywords and values would mess up with
the set of connections saved, as on failure the pthread mutex would
still be hold with the new connection object listed but free()'d.

Rather than just unlocking the mutex, which would leave the static list
of connections into an inconsistent state, move the allocation for the
structures of the connection parameters before beginning the test
manipulation.  This ensures that the list of connections and the
connection mutex remain consistent all the time in this code path.

This error is unlikely going to happen, but this could mess up badly
with ECPG clients in surprising ways, so backpatch all the way down.

Reported-by: ryancaicse
Discussion: https://postgr.es/m/17186-b4cfd8f0eb4d1dee@postgresql.org
Backpatch-through: 9.6

3 years agoDoc: Change optional parameters grouping in Create Subscription.
Amit Kapila [Mon, 13 Sep 2021 02:59:10 +0000 (08:29 +0530)]
Doc: Change optional parameters grouping in Create Subscription.

The subscription parameters are rearranged into two groups:
a) those that control what happens during Create Subscription
b) those that control the replication behavior

This makes the documentation of Create Subscription easier to follow.

Author: Peter Smith
Reviewed-by: Amit Kapila
Discussion: https://postgr.es/m/CAHut+PtPJDSOxtuMGpO2yDrRPKxcYGL4n7HqJP9HernZE=Cj+g@mail.gmail.com

3 years agoAdd regression tests for csvlog with the logging collector
Michael Paquier [Mon, 13 Sep 2021 01:23:59 +0000 (10:23 +0900)]
Add regression tests for csvlog with the logging collector

These are added in the existing tests of pg_ctl for log rotation, that
already tested stderr.  The same amount of coverage is added for csvlog:
- Checks for pg_current_logfile().
- Log rotation with expected file name.
- Log contents generated.

This test is refactored to minimize the amount of work required to add
tests for new log formats, easing some upcoming work.

Author: Michael Paquier, Sehrope Sarkuni
Discussion: https://postgr.es/m/CAH7T-aqswBM6JWe4pDehi1uOiufqe06DJWaU5=X7dDLyqUExHg@mail.gmail.com

3 years agoRefactor the syslogger pipe protocol to use a bitmask for its options
Michael Paquier [Mon, 13 Sep 2021 00:03:45 +0000 (09:03 +0900)]
Refactor the syslogger pipe protocol to use a bitmask for its options

The previous protocol expected a set of matching characters to check if
a message sent was the last one or not, that changed depending on the
destination wanted:
- 't' and 'f' tracked the last message of a log sent to stderr.
- 'T' and 'F' tracked the last message of a log sent to csvlog.

This could be extended with more characters when introducing new
destinations, but using a bitmask is much more elegant.  This commit
changes the protocol so as a bitmask is used in the header of a log
chunk message sent to the syslogger, with the following options
available for now:
- log_destination as stderr.
- log_destination as csvlog.
- if a message is the last chunk of a message.

Sehrope found this issue in a patch set to introduce JSON as an option
for log_destination, but his patch made the size of the protocol header
larger.  This commit keeps the same size as the original, and adapts the
protocol as wanted.

Thanks also to Andrew Dunstan and Greg Stark for the discussion.

Author: Michael Paquier, Sehrope Sarkuni
Discussion: https://postgr.es/m/CAH7T-aqswBM6JWe4pDehi1uOiufqe06DJWaU5=X7dDLyqUExHg@mail.gmail.com

3 years agoMake pg_regexec() robust against out-of-range search_start.
Tom Lane [Sat, 11 Sep 2021 19:19:31 +0000 (15:19 -0400)]
Make pg_regexec() robust against out-of-range search_start.

If search_start is greater than the length of the string, we should just
return REG_NOMATCH immediately.  (Note that the equality case should
*not* be rejected, since the pattern might be able to match zero
characters.)  This guards various internal assumptions that the min of a
range of string positions is not more than the max.  Violation of those
assumptions could allow an attempt to fetch string[search_start-1],
possibly causing a crash.

Jaime Casanova pointed out that this situation is reachable with the
new regexp_xxx functions that accept a user-specified start position.
I don't believe it's reachable via any in-core call site in v14 and
below.  However, extensions could possibly call pg_regexec with an
out-of-range search_start, so let's back-patch the fix anyway.

Discussion: https://postgr.es/m/20210911180357.GA6870@ahch-to

3 years agoFix some anomalies with NO SCROLL cursors.
Tom Lane [Fri, 10 Sep 2021 17:18:32 +0000 (13:18 -0400)]
Fix some anomalies with NO SCROLL cursors.

We have long forbidden fetching backwards from a NO SCROLL cursor,
but the prohibition didn't extend to cases in which we rewind the
query altogether and then re-fetch forwards.  I think the reason is
that this logic was mainly meant to protect plan nodes that can't
be run in the reverse direction.  However, re-reading the query output
is problematic if the query is volatile (which includes SELECT FOR
UPDATE, not just queries with volatile functions): the re-read can
produce different results, which confuses the cursor navigation logic
completely.  Another reason for disliking this approach is that some
code paths will either fetch backwards or rewind-and-fetch-forwards
depending on the distance to the target row; so that seemingly
identical use-cases may or may not draw the "cursor can only scan
forward" error.  Hence, let's clean things up by disallowing rewind
as well as fetch-backwards in a NO SCROLL cursor.

Ordinarily we'd only make such a definitional change in HEAD, but
there is a third reason to consider this change now.  Commit ba2c6d6ce
created some new user-visible anomalies for non-scrollable cursors
WITH HOLD, in that navigation in the cursor result got confused if the
cursor had been partially read before committing.  The only good way
to resolve those anomalies is to forbid rewinding such a cursor, which
allows removal of the incorrect cursor state manipulations that
ba2c6d6ce added to PersistHoldablePortal.

To minimize the behavioral change in the back branches (including
v14), refuse to rewind a NO SCROLL cursor only when it has a holdStore,
ie has been held over from a previous transaction due to WITH HOLD.
This should avoid breaking most applications that have been sloppy
about whether to declare cursors as scrollable.  We'll enforce the
prohibition across-the-board beginning in v15.

Back-patch to v11, as ba2c6d6ce was.

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

3 years agoUpdate src/test/kerberos to account for previous commit.
Noah Misch [Fri, 10 Sep 2021 07:44:01 +0000 (00:44 -0700)]
Update src/test/kerberos to account for previous commit.

3 years agoRevoke PUBLIC CREATE from public schema, now owned by pg_database_owner.
Noah Misch [Fri, 10 Sep 2021 06:38:09 +0000 (23:38 -0700)]
Revoke PUBLIC CREATE from public schema, now owned by pg_database_owner.

This switches the default ACL to what the documentation has recommended
since CVE-2018-1058.  Upgrades will carry forward any old ownership and
ACL.  Sites that declined the 2018 recommendation should take a fresh
look.  Recipes for commissioning a new database cluster from scratch may
need to create a schema, grant more privileges, etc.  Out-of-tree test
suites may require such updates.

Reviewed by Peter Eisentraut.

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

3 years agoAvoid fetching from an already-terminated plan.
Tom Lane [Thu, 9 Sep 2021 17:36:31 +0000 (13:36 -0400)]
Avoid fetching from an already-terminated plan.

Some plan node types don't react well to being called again after
they've already returned NULL.  PortalRunSelect() has long dealt
with this by calling the executor with NoMovementScanDirection
if it sees that we've already run the portal to the end.  However,
commit ba2c6d6ce overlooked this point, so that persisting an
already-fully-fetched cursor would fail if it had such a plan.

Per report from Tomas Barton.  Back-patch to v11, as the faulty
commit was.  (I've omitted a test case because the type of plan
that causes a problem isn't all that stable.)

Discussion: https://postgr.es/m/CAPV2KRjd=ErgVGbvO2Ty20tKTEZZr6cYsYLxgN_W3eAo9pf5sw@mail.gmail.com

3 years agopgbench: Stop counting skipped transactions as soon as timer is exceeded.
Fujii Masao [Thu, 9 Sep 2021 16:28:17 +0000 (01:28 +0900)]
pgbench: Stop counting skipped transactions as soon as timer is exceeded.

When throttling is used, transactions that lag behind schedule by
more than the latency limit are counted and reported as skipped.
Previously, there was the case where pgbench counted all skipped
transactions even if the timer specified in -T option was exceeded.
This could take a very long time to do that especially when unrealistically
high rate setting in -R option caused quite a lot of transactions that
lagged behind schedule. This could prevent pgbench from ending
immediately, and so pgbench could look like it got stuck to users.

To fix the issue, this commit changes pgbench so that it stops counting
skipped transactions as soon as the timer is exceeded. The timer can
make pgbench end soon even when there are lots of skipped transactions
that have not been counted yet.

Note that there is no guarantee that all skipped transactions are
counted under -T though there is under -t. This is OK in practice
because it's very unlikely to happen with realistic setting. Also this is
not the issue that this commit newly introdues. There used to be
the case where pgbench ended without counting all skipped
transactions since before.

Back-patch to v14. Per discussion, we decided not to bother
back-patch to the stable branches because it's hard to imagine
the issue happens in practice (with realistic setting).

Author: Yugo Nagata, Fabien COELHO
Reviewed-by: Greg Sabino Mullane, Fujii Masao
Discussion: https://postgr.es/m/20210613040151.265ff59d832f835bbcf8b3ba@sraoss.co.jp

3 years agoCheck for relation length overrun soon enough.
Tom Lane [Thu, 9 Sep 2021 15:45:48 +0000 (11:45 -0400)]
Check for relation length overrun soon enough.

We don't allow relations to exceed 2^32-1 blocks, because block
numbers are 32 bits and the last possible block number is reserved
to mean InvalidBlockNumber.  There is a check for this in mdextend,
but that's really way too late, because the smgr API requires us to
create a buffer for the block-to-be-added, and we do not want to
have any buffer with blocknum InvalidBlockNumber.  (Such a case
can trigger assertions in bufmgr.c, plus I think it might confuse
ReadBuffer's logic for data-past-EOF later on.)  So put the check
into ReadBuffer.

Per report from Christoph Berg.  It's been like this forever,
so back-patch to all supported branches.

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

3 years agoFix issue with WAL archiving in standby.
Fujii Masao [Thu, 9 Sep 2021 14:56:57 +0000 (23:56 +0900)]
Fix issue with WAL archiving in standby.

Previously, walreceiver always closed the currently-opened WAL segment
and created its archive notification file, after it finished writing
the current segment up and received any WAL data that should be
written into the next segment. If walreceiver exited just before
any WAL data in the next segment arrived at standby, it did not
create the archive notification file of the current segment
even though that's known completed. This behavior could cause
WAL archiving of the segment to be delayed until subsequent
restartpoints or checkpoints created its notification file.

To fix the issue, this commit changes walreceiver so that it creates
an archive notification file of a current WAL segment immediately
if that's known completed before receiving next WAL data.

Back-patch to all supported branches.

Reported-by: Kyotaro Horiguchi
Author: Fujii Masao
Reviewed-by: Kyotaro Horiguchi
Discussion: https://postgr.es/m/20200630.165503.1465894182551545886[email protected]

3 years agoFix _equalA_Const
Peter Eisentraut [Thu, 9 Sep 2021 08:23:29 +0000 (10:23 +0200)]
Fix _equalA_Const

639a86e36aaecb84faaf941dcd0b183ba0aba9e9 neglected to make the
necessary adjustments to _equalA_Const.  Found only via
COPY_PARSE_PLAN_TREES.

3 years agoRemove Value node struct
Peter Eisentraut [Thu, 9 Sep 2021 05:58:12 +0000 (07:58 +0200)]
Remove Value node struct

The Value node struct is a weird construct.  It is its own node type,
but most of the time, it actually has a node type of Integer, Float,
String, or BitString.  As a consequence, the struct name and the node
type don't match most of the time, and so it has to be treated
specially a lot.  There doesn't seem to be any value in the special
construct.  There is very little code that wants to accept all Value
variants but nothing else (and even if it did, this doesn't provide
any convenient way to check it), and most code wants either just one
particular node type (usually String), or it accepts a broader set of
node types besides just Value.

This change removes the Value struct and node type and replaces them
by separate Integer, Float, String, and BitString node types that are
proper node types and structs of their own and behave mostly like
normal node types.

Also, this removes the T_Null node tag, which was previously also a
possible variant of Value but wasn't actually used outside of the
Value contained in A_Const.  Replace that by an isnull field in
A_Const.

Reviewed-by: Dagfinn Ilmari Mannsåker <[email protected]>
Reviewed-by: Kyotaro Horiguchi <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/5ba6bc5b-3f95-04f2-2419-f8ddb4c046fb@enterprisedb.com

3 years agoRemove useless casts
Peter Eisentraut [Thu, 9 Sep 2021 05:58:12 +0000 (07:58 +0200)]
Remove useless casts

Casting the argument of strVal() to (Value *) is useless, since
strVal() already does that.

Most code didn't do that anyway; this was apparently just a style that
snuck into certain files.

Reviewed-by: Dagfinn Ilmari Mannsåker <[email protected]>
Reviewed-by: Kyotaro Horiguchi <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/5ba6bc5b-3f95-04f2-2419-f8ddb4c046fb@enterprisedb.com

3 years agoMake shared_memory_size a preset option
Michael Paquier [Thu, 9 Sep 2021 00:57:28 +0000 (09:57 +0900)]
Make shared_memory_size a preset option

bd17880 set up that as a memory parameter, but the docs told a different
story.  A preset parameter is adapted here, as this option is compiled
at startup time.

Reported-by: Fujii Masao
Discussion: https://postgr.es/m/4cc5b434-b174-9aae-197b-737db6cac4e3@oss.nttdata.com

3 years agoAvoid useless malloc/free traffic around getFormattedTypeName().
Tom Lane [Wed, 8 Sep 2021 19:09:42 +0000 (15:09 -0400)]
Avoid useless malloc/free traffic around getFormattedTypeName().

Coverity complained that one caller of getFormattedTypeName() failed
to free the returned string.  Which is true, but rather than fixing
that one, let's get rid of this tedious and error-prone requirement.
Now that getFormattedTypeName() caches its result, strdup'ing that
result and expecting the caller to free it accomplishes little except
to waste cycles.  We do create a leak in the case where getTypes didn't
make a TypeInfo for the type, but that basically shouldn't ever happen.

Back-patch, as commit 6c450a861 was.  This isn't a particularly
interesting bug fix, but the API change seems like a hazard for
future back-patching activity if we don't back-patch it.

3 years agoFix misleading comments about TOAST access macros.
Tom Lane [Wed, 8 Sep 2021 18:11:35 +0000 (14:11 -0400)]
Fix misleading comments about TOAST access macros.

Seems to have been my error in commit aeb1631ed.
Noted by Christoph Berg.

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

3 years agoIn psql tab completion, offer spelled-out commands not abbreviations.
Tom Lane [Wed, 8 Sep 2021 17:21:42 +0000 (13:21 -0400)]
In psql tab completion, offer spelled-out commands not abbreviations.

Various psql backslash commands have both single-letter and long
forms, for example \e and \edit.  Previously, tab completion
generally offered the single-letter form but not the long form.
It seems more sensible to offer the long form, because (a) no
useful completion can happen when you've already typed the single
letter, and (b) if you're not so familiar with the command set
as to know that, the long form is likely to be less confusing.

Haiying Tang, reviewed by Dagfinn Ilmari Mannsåker and myself

Discussion: https://postgr.es/m/OS0PR01MB61136018064660F095CB57A8FB129@OS0PR01MB6113.jpnprd01.prod.outlook.com

3 years agoFix rewriter to set hasModifyingCTE correctly on rewritten queries.
Tom Lane [Wed, 8 Sep 2021 16:05:43 +0000 (12:05 -0400)]
Fix rewriter to set hasModifyingCTE correctly on rewritten queries.

If we copy data-modifying CTEs from the original query to a replacement
query (from a DO INSTEAD rule), we must set hasModifyingCTE properly
in the replacement query.  Failure to do this can cause various
unpleasantness, such as unsafe usage of parallel plans.  The code also
neglected to propagate hasRecursive, though that's only cosmetic at
the moment.

A difficulty arises if the rule action is an INSERT...SELECT.  We
attach the original query's RTEs and CTEs to the sub-SELECT Query, but
data-modifying CTEs are only allowed to appear in the topmost Query.
For the moment, throw an error in such cases.  It would probably be
possible to avoid this error by attaching the CTEs to the top INSERT
Query instead; but that would require a bunch of new code to adjust
ctelevelsup references.  Given the narrowness of the use-case, and
the need to back-patch this fix, it does not seem worth the trouble
for now.  We can revisit this if we get field complaints.

Per report from Greg Nancarrow.  Back-patch to all supported branches.
(The test case added here does not fail before v10, but there are
plenty of places checking top-level hasModifyingCTE in 9.6, so I have
no doubt that this code change is necessary there too.)

Greg Nancarrow and Tom Lane

Discussion: https://postgr.es/m/CAJcOf-f68DT=26YAMz_i0+Au3TcLO5oiHY5=fL6Sfuits6r+_w@mail.gmail.com
Discussion: https://postgr.es/m/CAJcOf-fAdj=nDKMsRhQzndm-O13NY4dL6xGcEvdX5Xvbbi0V7g@mail.gmail.com

3 years agoConsistently use "superuser" instead of "super user"
Daniel Gustafsson [Wed, 8 Sep 2021 15:02:18 +0000 (17:02 +0200)]
Consistently use "superuser" instead of "super user"

The correct nomenclature for the highest privileged user is superuser
and not "super user", this replaces the few instances where that was
used erroneously. No user-visible changes are done as all changes are
in comments, so no back-patching.

Author: Bharath Rupireddy <[email protected]>
Discussion: https://postgr.es/m/CALj2ACW3snGBD8BAQiArMDS1Y43LuX3ymwO+N8aUg1Hrv6hYNw@mail.gmail.com

3 years agoFix typo
Peter Eisentraut [Wed, 8 Sep 2021 14:48:51 +0000 (16:48 +0200)]
Fix typo

3 years agoDisable anonymous record hash support except in special cases
Peter Eisentraut [Wed, 8 Sep 2021 07:25:46 +0000 (09:25 +0200)]
Disable anonymous record hash support except in special cases

Commit 01e658fa74 added hash support for row types.  This also added
support for hashing anonymous record types, using the same approach
that the type cache uses for comparison support for record types: It
just reports that it works, but it might fail at run time if a
component type doesn't actually support the operation.  We get away
with that for comparison because most types support that.  But some
types don't support hashing, so the current state can result in
failures at run time where the planner chooses hashing over sorting,
whereas that previously worked if only sorting was an option.

We do, however, want the record hashing support for path tracking in
recursive unions, and the SEARCH and CYCLE clauses built on that.  In
that case, hashing is the only plan option.  So enable that, this
commit implements the following approach: The type cache does not
report that hashing is available for the record type.  This undoes
that part of 01e658fa74.  Instead, callers that require hashing no
matter what can override that result themselves.  This patch only
touches the callers to make the aforementioned recursive query cases
work, namely the parse analysis of unions, as well as the hash_array()
function.

Reported-by: Sait Talha Nisanci <[email protected]>
Bug: #17158
Discussion: https://www.postgresql.org/message-id/flat/17158-8a2ba823982537a4%40postgresql.org

3 years agopostgres_fdw: Revert unstable tests for postgres_fdw.application_name.
Fujii Masao [Wed, 8 Sep 2021 07:28:43 +0000 (16:28 +0900)]
postgres_fdw: Revert unstable tests for postgres_fdw.application_name.

Commit 449ab63505 added the tests that check that postgres_fdw.application_name
GUC works as expected. But they were unstable and caused some buildfarm
members to report the failure. This commit reverts those unstable tests.

Reported-by: Tom Lane as per buildfarm
Discussion: https://postgr.es/m/3220909.1631054766@sss.pgh.pa.us

3 years agoFix incorrect format placeholders
Peter Eisentraut [Wed, 8 Sep 2021 06:52:29 +0000 (08:52 +0200)]
Fix incorrect format placeholders

3 years agoInvalidate relcache for publications defined for all tables.
Amit Kapila [Wed, 8 Sep 2021 06:20:37 +0000 (11:50 +0530)]
Invalidate relcache for publications defined for all tables.

Updates/Deletes on a relation were allowed even without replica identity
after we define the publication for all tables. This would later lead to
an error on subscribers. The reason was that for such publications we were
not invalidating the relcache and the publication information for
relations was not getting rebuilt. Similarly, we were not invalidating the
relcache after dropping of such publications which will prohibit
Updates/Deletes without replica identity even without any publication.

Author: Vignesh C and Hou Zhijie
Reviewed-by: Hou Zhijie, Kyotaro Horiguchi, Amit Kapila
Backpatch-through: 10, where it was introduced
Discussion: https://postgr.es/m/CALDaNm0pF6zeWqCA8TCe2sDuwFAy8fCqba=nHampCKag-qLixg@mail.gmail.com

3 years agoFix compilation warning in ipci.c
Michael Paquier [Wed, 8 Sep 2021 05:22:52 +0000 (14:22 +0900)]
Fix compilation warning in ipci.c

A Size had better use %zu when printed.

Oversight in bd17880, per buildfarm member lapwing.

3 years agoIntroduce GUC shared_memory_size
Michael Paquier [Wed, 8 Sep 2021 03:02:30 +0000 (12:02 +0900)]
Introduce GUC shared_memory_size

This runtime-computed GUC shows the size of the server's main shared
memory area, taking into account the amount of shared memory allocated
by extensions as this is calculated after processing
shared_preload_libraries.

Author: Nathan Bossart
Discussion: https://postgr.es/m/F2772387-CE0F-46BF-B5F1-CC55516EB885@amazon.com

3 years agoClean up some code using "(expr) ? true : false"
Michael Paquier [Wed, 8 Sep 2021 00:44:04 +0000 (09:44 +0900)]
Clean up some code using "(expr) ? true : false"

All the code paths simplified here were already using a boolean or used
an expression that led to zero or one, making the extra bits
unnecessary.

Author: Justin Pryzby
Reviewed-by: Tom Lane, Michael Paquier, Peter Smith
Discussion: https://postgr.es/m/20210428182936[email protected]

3 years agoConsistently use read-only instead of "read only"
Magnus Hagander [Tue, 7 Sep 2021 19:59:25 +0000 (21:59 +0200)]
Consistently use read-only instead of "read only"

This affects one message and some documentation that used the format
"read only", unlike everything else that used read-only.

Backpatch-through: 14
Discussion: https://postgr.es/m/CABUevExuxKwn0YM3+wdSeQSvK6CRrJ-hewocGVX3R4-xVX4eMw@mail.gmail.com

3 years agowindows: Only consider us to be running as service if stderr is invalid.
Andres Freund [Tue, 7 Sep 2021 18:56:13 +0000 (11:56 -0700)]
windows: Only consider us to be running as service if stderr is invalid.

Previously pgwin32_is_service() would falsely return true when postgres is
started from somewhere within a service, but not as a service. That is
e.g. always the case with windows docker containers, which some CI services
use to run windows tests in.

When postgres falsely thinks its running as a service, no messages are
writting to stdout / stderr. That can be very confusing and causes a few tests
to fail.

To fix additionally check if stderr is invalid in pgwin32_is_service(). For
that to work in backend processes, pg_ctl is changed to pass down handles so
that postgres can do the same check (otherwise "default" handles are created).

While this problem exists in all branches, there have been no reports by
users, the prospective CI usage currently is only for master, and I am not a
windows expert. So doing the change in only master for now seems the sanest
approach.

Author: Andres Freund <[email protected]>
Reviewed-By: Magnus Hagander <[email protected]>
Discussion: https://postgr.es/m/20210305185752[email protected]

3 years agoFix missing words in comment.
Heikki Linnakangas [Tue, 7 Sep 2021 07:28:55 +0000 (10:28 +0300)]
Fix missing words in comment.

Introduced by commit c3928b467a, backpatch to v14 like that one.

Author: Amit Langote
Discussion: https://www.postgresql.org/message-id/CA+HiwqFQgNLS6VGntMcuJV6erBFV425xA6wBVnY=41GK4zC0Bw@mail.gmail.com

3 years agopostgres_fdw: Allow application_name of remote connection to be set via GUC.
Fujii Masao [Tue, 7 Sep 2021 03:27:30 +0000 (12:27 +0900)]
postgres_fdw: Allow application_name of remote connection to be set via GUC.

This commit adds postgres_fdw.application_name GUC which specifies
a value for application_name configuration parameter used
when postgres_fdw establishes a connection to a foreign server.
This GUC setting always overrides application_name option of
the foreign server object. This GUC is useful when we want to
specify our own application_name per remote connection.

Previously application_name of a remote connection could be set
basically only via options of a server object. But which meant that
every session connecting to the same foreign server basically
should use the same application_name. Also if we want to change
the setting, we had to execute "ALTER SERVER ... OPTIONS ..." command.
It was inconvenient.

Author: Hayato Kuroda
Reviewed-by: Masahiro Ikeda, Fujii Masao
Discussion: https://postgr.es/m/TYCPR01MB5870D1E8B949DAF6D3B84E02F5F29@TYCPR01MB5870.jpnprd01.prod.outlook.com

3 years agoLog new catalog xmin candidate in LogicalIncreaseXminForSlot().
Amit Kapila [Tue, 7 Sep 2021 02:37:11 +0000 (08:07 +0530)]
Log new catalog xmin candidate in LogicalIncreaseXminForSlot().

Similar to LogicalIncreaseRestartDecodingForSlot() add a debug message to
LogicalIncreaseXminForSlot() reporting a new catalog_xmin candidate.

This just adds additional diagnostic information during logical decoding that
can aid debugging.

Author: Ashutosh Bapat
Reviewed-by: Masahiko Sawada, Amit Kapila
Discussion: https://postgr.es/m/CAExHW5usQWbiUz0hHOCu5twS1O9DvpcPojf6sor=8q--VUuMbA@mail.gmail.com

3 years agoFurther fix psql query-cancel test.
Tom Lane [Mon, 6 Sep 2021 20:14:49 +0000 (16:14 -0400)]
Further fix psql query-cancel test.

The query to wait for pg_sleep to be running did no such thing,
because the regex pattern it used could match itself.

Report: https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=conchuela&dt=2021-09-06%2018%3A00%3A20