]> git.ipfire.org Git - thirdparty/postgresql.git/log
thirdparty/postgresql.git
2 years agoFix assertion failures while processing NEW_CID record in logical decoding.
Amit Kapila [Thu, 20 Oct 2022 04:13:59 +0000 (09:43 +0530)] 
Fix assertion failures while processing NEW_CID record in logical decoding.

When the logical decoding restarts from NEW_CID, since there is no
association between the top transaction and its subtransaction, both are
created as top transactions and have the same LSN. This caused the
assertion failure in AssertTXNLsnOrder().

This patch skips the assertion check until we reach the LSN at which we
start decoding the contents of the transaction, specifically
start_decoding_at LSN in SnapBuild. This is okay because we don't
guarantee to make the association between top transaction and
subtransaction until we try to decode the actual contents of transaction.
The ordering of the records prior to the start_decoding_at LSN should have
been checked before the restart.

The other assertion failure is due to the reason that we forgot to track
that we have considered top-level transaction id in the list of catalog
changing transactions that were committed when one of its subtransactions
is marked as containing catalog change.

Reported-by: Tomas Vondra, Osumi Takamichi
Author: Masahiko Sawada, Kuroda Hayato
Reviewed-by: Amit Kapila, Dilip Kumar, Kuroda Hayato, Kyotaro Horiguchi, Masahiko Sawada
Backpatch-through: 10
Discussion: https://postgr.es/m/a89b46b6-0239-2fd5-71a9-b19b1f7a7145%40enterprisedb.com
Discussion: https://postgr.es/m/TYCPR01MB83733C6CEAE47D0280814D5AED7A9%40TYCPR01MB8373.jpnprd01.prod.outlook.com

2 years agoTrack LLVM 15 changes.
Thomas Munro [Wed, 19 Oct 2022 09:18:54 +0000 (22:18 +1300)] 
Track LLVM 15 changes.

Per https://llvm.org/docs/OpaquePointers.html, support for non-opaque
pointers still exists and we can request that on our context.  We have
until LLVM 16 to move to opaque pointers, a much larger change.

Back-patch to 11, where LLVM support arrived.

Author: Thomas Munro <thomas.munro@gmail.com>
Author: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/CAMHz58Sf_xncdyqsekoVsNeKcruKootLtVH6cYXVhhUR1oKPCg%40mail.gmail.com

2 years agoRework shutdown callback of archiver modules
Michael Paquier [Wed, 19 Oct 2022 05:07:01 +0000 (14:07 +0900)] 
Rework shutdown callback of archiver modules

As currently designed, with a callback registered in a ERROR_CLEANUP
block, the shutdown callback would get called twice when updating
archive_library on SIGHUP, which is something that we want to avoid to
ease the life of extension writers.

Anyway, an ERROR in the archiver process is treated as a FATAL, stopping
it immediately, hence there is no need for a ERROR_CLEANUP block.
Instead of that, the shutdown callback is not called upon
before_shmem_exit(), giving to the modules the opportunity to do any
cleanup actions before the server shuts down its subsystems.

While on it, this commit adds some testing coverage for the shutdown
callback.  Neither shell_archive nor basic_archive have been using it,
and one is added to shell_archive, whose trigger is checked in a TAP
test through a shutdown sequence.

Author: Nathan Bossart, Bharath Rupireddy
Reviewed-by: Kyotaro Horiguchi, Michael Paquier
Discussion: https://postgr.es/m/20221015221328.GB1821022@nathanxps13
Backpatch-through: 15

2 years agoImprove errhint for ALTER SUBSCRIPTION ADD/DROP PUBLICATION
Alvaro Herrera [Tue, 18 Oct 2022 09:46:58 +0000 (11:46 +0200)] 
Improve errhint for ALTER SUBSCRIPTION ADD/DROP PUBLICATION

The original hint says to use SET PUBLICATION when really ADD/DROP
PUBLICATION is called for, so this is arguably a bug fix.

Also, a very similar message elsewhere was using an inconsistent
SQLSTATE.

While at it, unwrap some strings.

Backpatch to 15.

Author: Hou zj <houzj.fnst@fujitsu.com>
Discussion: https://postgr.es/m/OS0PR01MB57160AD0E7386547BA978EB394299@OS0PR01MB5716.jpnprd01.prod.outlook.com

2 years agoRename SetSingleFuncCall() to InitMaterializedSRF()
Michael Paquier [Tue, 18 Oct 2022 01:22:40 +0000 (10:22 +0900)] 
Rename SetSingleFuncCall() to InitMaterializedSRF()

Per discussion, the existing routine name able to initialize a SRF
function with materialize mode is unpopular, so rename it.  Equally, the
flags of this function are renamed, as of:
- SRF_SINGLE_USE_EXPECTED -> MAT_SRF_USE_EXPECTED_DESC
- SRF_SINGLE_BLESS -> MAT_SRF_BLESS
The previous function and flags introduced in 9e98583 are kept around
for compatibility purposes, so as any extension code already compiled
with v15 continues to work as-is.  The declarations introduced here for
compatibility will be removed from HEAD in a follow-up commit.

The new names have been suggested by Andres Freund and Melanie
Plageman.

Discussion: https://postgr.es/m/20221013194820.ciktb2sbbpw7cljm@awork3.anarazel.de
Backpatch-through: 15

2 years agodoc: move the mention of aggregate JSON functions up in section
Bruce Momjian [Mon, 17 Oct 2022 19:21:29 +0000 (15:21 -0400)] 
doc:  move the mention of aggregate JSON functions up in section

It was previously easily overlooked at the end of several tables.

Reported-by: Alex Denman
Discussion: https://postgr.es/m/166335888474.659.16897487975376230364@wrigleys.postgresql.org

Backpatch-through: 10

2 years agodoc: warn pg_stat_reset() can cause vacuum/analyze problems
Bruce Momjian [Mon, 17 Oct 2022 19:07:03 +0000 (15:07 -0400)] 
doc:  warn pg_stat_reset() can cause vacuum/analyze problems

The fix is to run ANALYZE.

Discussion: https://postgr.es/m/YzRr+ys98UzVQJvK@momjian.us,
   https://postgr.es/m/flat/CAKJS1f8DTbCHf9gedU0He6ARsd58E6qOhEHM1caomqj_r9MOiQ%40mail.gmail.com,
   https://postgr.es/m/CAKJS1f80o98hcfSk8j%3DfdN09S7Sjz%2BvuzhEwbyQqvHJb_sZw0g%40mail.gmail.com

Backpatch-through: 10

2 years agoReject non-ON-SELECT rules that are named "_RETURN".
Tom Lane [Mon, 17 Oct 2022 16:14:39 +0000 (12:14 -0400)] 
Reject non-ON-SELECT rules that are named "_RETURN".

DefineQueryRewrite() has long required that ON SELECT rules be named
"_RETURN".  But we overlooked the converse case: we should forbid
non-ON-SELECT rules that are named "_RETURN".  In particular this
prevents using CREATE OR REPLACE RULE to overwrite a view's _RETURN
rule with some other kind of rule, thereby breaking the view.

Per bug #17646 from Kui Liu.  Back-patch to all supported branches.

Discussion: https://postgr.es/m/17646-70c93cfa40365776@postgresql.org

2 years agoGuard against table-AM-less relations in planner.
Tom Lane [Mon, 17 Oct 2022 15:35:23 +0000 (11:35 -0400)] 
Guard against table-AM-less relations in planner.

The executor will dump core if it's asked to execute a seqscan on
a relation having no table AM, such as a view.  While that shouldn't
really happen, it's possible to get there via catalog corruption,
such as a missing ON SELECT rule.  It seems worth installing a defense
against that.  There are multiple plausible places for such a defense,
but I picked the planner's get_relation_info().

Per discussion of bug #17646 from Kui Liu.  Back-patch to v12 where
the tableam APIs were introduced; in older versions you won't get a
SIGSEGV, so it seems less pressing.

Discussion: https://postgr.es/m/17646-70c93cfa40365776@postgresql.org

2 years agoFix calculation related to temporary WAL segment name in basic_archive
Michael Paquier [Mon, 17 Oct 2022 02:40:19 +0000 (11:40 +0900)] 
Fix calculation related to temporary WAL segment name in basic_archive

The file name used for its temporary destination, before renaming it to
the real deal, has been using a microseconds in a timestamp aimed to be
originally in milli-seconds.  This is harmless as this is aimed at being
a safeguard against name collisions (note MyProcPid in the name), but
let's be correct with the maths.

While on it, add a note in the module's makefile to document why
installcheck is not supported.

Author: Nathan Bossart
Reviewed-by: Bharath Rupireddy
Discussion: https://postgr.es/m/20221014044106.GA1673343@nathanxps13
Backpatch-through: 15

2 years agoFix EXPLAIN of SEARCH BREADTH FIRST with a constant initial value.
Tom Lane [Sun, 16 Oct 2022 23:18:08 +0000 (19:18 -0400)] 
Fix EXPLAIN of SEARCH BREADTH FIRST with a constant initial value.

If the non-recursive term of a SEARCH BREADTH FIRST recursive
query has only constants in its target list, the planner will
fold the starting RowExpr added by rewrite into a simple Const
of type RECORD.  The executor doesn't have any problem with
that --- but EXPLAIN VERBOSE will encounter the Const as the
ultimate source of truth about what the field names of the
SET column are, and it didn't know what to do with that.
Fortunately, we can pull the identifying typmod out of the
Const, in much the same way that record_out would.

For reasons that remain a bit obscure to me, this only fails
with SEARCH BREADTH FIRST, not SEARCH DEPTH FIRST or CYCLE.
But I added regression test cases for both of those options
too, just to make sure we don't break it in future.

Per bug #17644 from Matthijs van der Vleuten.  Back-patch
to v14 where these constructs were added.

Discussion: https://postgr.es/m/17644-3bd1f3036d6d7a16@postgresql.org

2 years agoRename parser token REF to REF_P to avoid a symbol conflict.
Tom Lane [Sun, 16 Oct 2022 19:27:04 +0000 (15:27 -0400)] 
Rename parser token REF to REF_P to avoid a symbol conflict.

In the latest version of Apple's macOS SDK, <sys/socket.h>
fails to compile if "REF" is #define'd as something.
Apple may or may not agree that this is a bug, and even if
they do accept the bug report I filed, they probably won't
fix it very quickly.  In the meantime, our back branches will all
fail to compile gram.y.  v15 and HEAD currently escape the problem
thanks to the refactoring done in 98e93a1fc, but that's purely
accidental.  Moreover, since that patch removed a widely-visible
inclusion of <netdb.h>, back-patching it seems too likely to break
third-party code.

Instead, change the token's code name to REF_P, following our usual
convention for naming parser tokens that are likely to have symbol
conflicts.  The effects of that should be localized to the grammar
and immediately surrounding files, so it seems like a safer answer.

Per project policy that we want to keep recently-out-of-support
branches buildable on modern systems, back-patch all the way to 9.2.

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

2 years agoUse libc's snprintf, not sprintf, for special cases in snprintf.c.
Tom Lane [Sun, 16 Oct 2022 15:47:44 +0000 (11:47 -0400)] 
Use libc's snprintf, not sprintf, for special cases in snprintf.c.

snprintf.c has always fallen back on libc's *printf implementation
when printing pointers (%p) and floats.  When this code originated,
we were still supporting some platforms that lacked native snprintf,
so we used sprintf for that.  That's not actually unsafe in our usage,
but nonetheless builds on macOS are starting to complain about sprintf
being unconditionally deprecated; and I wouldn't be surprised if other
platforms follow suit.  There seems little reason to believe that any
platform supporting C99 wouldn't have standards-compliant snprintf,
so let's just use that instead to suppress such warnings.

Back-patch to v12, which is where we started to require C99.  It's
also where we started to use our snprintf.c everywhere, so this
wouldn't be enough to suppress the warning in older branches anyway
--- that is, in older branches these aren't necessarily all our
usages of libc's sprintf.  It is enough in v12+ because any
deprecation annotation attached to libc's sprintf won't apply to
pg_sprintf.  (Whether all our usages of pg_sprintf are adequately
safe is not a matter I intend to address here, but perhaps it could
do with some review.)

Per report from Andres Freund and local testing.

Discussion: https://postgr.es/m/20221015211955.q4cwbsfkyk3c4ty3@awork3.anarazel.de

2 years agoDisallow MERGE cleanly for foreign partitions
Alvaro Herrera [Sat, 15 Oct 2022 17:24:26 +0000 (19:24 +0200)] 
Disallow MERGE cleanly for foreign partitions

While directly targetting a foreign table with MERGE was already
expressly forbidden, we failed to catch the case of a partitioned table
that has a foreign table as a partition; and the result if you try is an
incomprehensible error.  Fix that by adding a specific check.

Backpatch to 15.

Reported-by: Tatsuhiro Nakamori <bt22nakamorit@oss.nttdata.com>
Discussion: https://postgr.es/m/bt22nakamorit@oss.nttdata.com

2 years agolibpq: Reset singlerow flag correctly in pipeline mode
Alvaro Herrera [Fri, 14 Oct 2022 17:06:26 +0000 (19:06 +0200)] 
libpq: Reset singlerow flag correctly in pipeline mode

When a query whose results were requested in single-row mode is the last
in the queue by the time those results are being read, the single-row
flag was not being reset, because we were returning early from
pqPipelineProcessQueue.  Move that stanza up so that the flag is always
reset at the end of sending that query's results.

Add a test for the situation.

Backpatch to 14.

Author: Denis Laxalde <denis.laxalde@dalibo.com>
Discussion: https://postgr.es/m/01af18c5-dacc-a8c8-07ee-aecc7650c3e8@dalibo.com

2 years agoFix typo in CREATE PUBLICATION reference page
Alvaro Herrera [Thu, 13 Oct 2022 11:36:14 +0000 (13:36 +0200)] 
Fix typo in CREATE PUBLICATION reference page

While at it, simplify wording a bit.

Author: Takamichi Osumi <osumi.takamichi@fujitsu.com>
Reviewed-by: Peter Smith <smithpb2250@gmail.com>
Discussion: https://postgr.es/m/TYCPR01MB8373F93F5D094A2BE648990DED259@TYCPR01MB8373.jpnprd01.prod.outlook.com

2 years agodoc: Fix description of replication command CREATE_REPLICATION_SLOT
Michael Paquier [Wed, 12 Oct 2022 23:53:44 +0000 (08:53 +0900)] 
doc: Fix description of replication command CREATE_REPLICATION_SLOT

The output plugin name is a mandatory option when creating a logical
slot, but the grammar documented was not described as such.  While on
it, fix two comments in repl_gram.y to show that TEMPORARY is an
optional grammar choice.

Author: Ayaki Tachikake
Discussion: https://postgr.es/m/OSAPR01MB2852607B2329FFA27834105AF1229@OSAPR01MB2852.jpnprd01.prod.outlook.com
Backpatch-through: 15

2 years agoDoc: improve recommended systemd unit file.
Tom Lane [Wed, 12 Oct 2022 14:51:11 +0000 (10:51 -0400)] 
Doc: improve recommended systemd unit file.

Add
    After=network-online.target
    Wants=network-online.target
to the suggested unit file for starting a Postgres server.
This delays startup until the network interfaces have been
configured; without that, any attempt to bind to a specific
IP address will fail.

If listen_addresses is set to "localhost" or "*", it might be
possible to get away with the less restrictive "network.target",
but I don't think we need to get into such detail here.

Per suggestion from Pablo Federico.

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

2 years agoHarden pmsignal.c against clobbered shared memory.
Tom Lane [Tue, 11 Oct 2022 22:54:31 +0000 (18:54 -0400)] 
Harden pmsignal.c against clobbered shared memory.

The postmaster is not supposed to do anything that depends
fundamentally on shared memory contents, because that creates
the risk that a backend crash that trashes shared memory will
take the postmaster down with it, preventing automatic recovery.
In commit 969d7cd43 I lost sight of this principle and coded
AssignPostmasterChildSlot() in such a way that it could fail
or even crash if the shared PMSignalState structure became
corrupted.  Remarkably, we've not seen field reports of such
crashes; but I managed to induce one while testing the recent
changes around palloc chunk headers.

To fix, make a semi-duplicative state array inside the postmaster
so that we need consult only local state while choosing a "child
slot" for a new backend.  Ensure that other postmaster-executed
routines in pmsignal.c don't have critical dependencies on the
shared state, either.  Corruption of PMSignalState might now
lead ReleasePostmasterChildSlot() to conclude that backend X
failed, when actually backend Y was the one that trashed things.
But that doesn't matter, because we'll force a cluster-wide reset
regardless.

Back-patch to all supported branches, since this is an old bug.

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

2 years agoYet further fixes for multi-row VALUES lists for updatable views.
Tom Lane [Tue, 11 Oct 2022 22:24:14 +0000 (18:24 -0400)] 
Yet further fixes for multi-row VALUES lists for updatable views.

DEFAULT markers appearing in an INSERT on an updatable view
could be mis-processed if they were in a multi-row VALUES clause.
This would lead to strange errors such as "cache lookup failed
for type NNNN", or in older branches even to crashes.

The cause is that commit 41531e42d tried to re-use rewriteValuesRTE()
to remove any SetToDefault nodes (that hadn't previously been replaced
by the view's own default values) appearing in "product" queries,
that is DO ALSO queries.  That's fundamentally wrong because the
DO ALSO queries might not even be INSERTs; and even if they are,
their targetlists don't necessarily match the view's column list,
so that almost all the logic in rewriteValuesRTE() is inapplicable.

What we want is a narrow focus on replacing any such nodes with NULL
constants.  (That is, in this context we are interpreting the defaults
as being strictly those of the view itself; and we already replaced
any that aren't NULL.)  We could add still more !force_nulls tests
to further lobotomize rewriteValuesRTE(); but it seems cleaner to
split out this case to a new function, restoring rewriteValuesRTE()
to the charter it had before.

Per bug #17633 from jiye_sw.  Patch by me, but thanks to
Richard Guo and Japin Li for initial investigation.
Back-patch to all supported branches, as the previous fix was.

Discussion: https://postgr.es/m/17633-98cc85e1fa91e905@postgresql.org

2 years agoDoc: update release date for v15. REL_15_0
Tom Lane [Mon, 10 Oct 2022 20:57:37 +0000 (16:57 -0400)] 
Doc: update release date for v15.

Drat, forgot this ...

2 years agoStamp 15.0.
Tom Lane [Mon, 10 Oct 2022 20:28:16 +0000 (16:28 -0400)] 
Stamp 15.0.

2 years agoTranslation updates
Peter Eisentraut [Mon, 10 Oct 2022 10:03:38 +0000 (12:03 +0200)] 
Translation updates

Source-Git-URL: https://git.postgresql.org/git/pgtranslation/messages.git
Source-Git-Hash: 59f93a503842f7c06b4ea5d022397ab3c2a0acd2

2 years agoUpdate list of acknowledgments in release notes
Peter Eisentraut [Mon, 10 Oct 2022 06:15:29 +0000 (08:15 +0200)] 
Update list of acknowledgments in release notes

current through c3b5992b91c4b0d2c4f4eab0fb856f34854c129d

2 years agopgstat: Prevent stats reset from corrupting slotname by removing slotname
Andres Freund [Sat, 8 Oct 2022 16:33:23 +0000 (09:33 -0700)] 
pgstat: Prevent stats reset from corrupting slotname by removing slotname

Previously PgStat_StatReplSlotEntry contained the slotname, which was mainly
used when writing out the stats during shutdown, to identify the slot in the
serialized data (at runtime the index in ReplicationSlotCtl->replication_slots
is used, but that can change during a restart). Unfortunately the slotname was
overwritten when the slot's stats were reset.

That turned out to only cause "real" problems if the slot was active during
the reset, triggering an assertion failure at the next
pgstat_report_replslot(). In other paths the stats were re-initialized during
pgstat_acquire_replslot().

Fix this by removing slotname from PgStat_StatReplSlotEntry. Instead we can
get the slot's name from the slot itself. Besides fixing a bug, this also is
architecturally cleaner (a name is not really statistics). This is safe
because stats, for a slot removed while shut down, will not be restored at
startup.

In 15 the slotname is not removed, but renamed, to avoid changing the stats
format. In master, bump PGSTAT_FILE_FORMAT_ID.

This commit does not contain a test for the fix. I think this can only be
tested by a tap test starting pg_recvlogical in the background and checking
pg_recvlogical's output. That type of test is notoriously hard to be reliable,
so committing it shortly before the release is wrapped seems like a bad idea.

Reported-by: Jaime Casanova <jcasanov@systemguards.com.ec>
Author: Andres Freund <andres@anarazel.de>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Discussion: https://postgr.es/m/YxfagaTXUNa9ggLb@ahch-to
Backpatch: 15-, where the bug was introduced in 5891c7a8ed8f

2 years agoFix self-referencing foreign keys with partitioned tables
Alvaro Herrera [Fri, 7 Oct 2022 17:37:48 +0000 (19:37 +0200)] 
Fix self-referencing foreign keys with partitioned tables

There are a number of bugs in this area.  Two of them are fixed here,
namely:
1. get_relation_idx_constraint_oid does not restrict the type of
   constraint that's returned, so with sufficient bad luck it can
   return the OID of a foreign key constraint.  This has the effect that
   a primary key in a partition can end up as a child of a foreign key,
   which makes no sense (it needs to be the child of the equivalent
   primary key.)
   Change the API contract so that only index-backed constraints are
   returned, mimicking get_constraint_index().

2. Both CloneFkReferenced and CloneFkReferencing clone a
   self-referencing foreign key, so the partition ends up with
   a duplicate foreign key.  Change the former function to ignore such
   constraints.

Add some tests to verify that things are better now.  (However, these
new tests show some additional misbehavior that will be fixed later --
namely that there's a constraint marked NOT VALID.)

Backpatch to 12, where these constraints are possible at all.

Author: Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
Discussion: https://postgr.es/m/20220603154232.1715b14c@karst

2 years agorelnotes: fix author names
Bruce Momjian [Wed, 5 Oct 2022 20:17:30 +0000 (16:17 -0400)] 
relnotes:  fix author names

Reported-by: Elena Indrupskaya
Discussion: https://postgr.es/m/0af43b49-1646-93d0-ccf1-bb3c635c8c6f@postgrespro.ru

Author: Elena Indrupskaya

Backpatch-through: 15 only

2 years agodoc: clarify description for log_startup_progress_interval
Bruce Momjian [Wed, 5 Oct 2022 19:53:40 +0000 (15:53 -0400)] 
doc:  clarify description for log_startup_progress_interval

Reported-by: Elena Indrupskaya
Discussion: https://postgr.es/m/0af43b49-1646-93d0-ccf1-bb3c635c8c6f@postgrespro.ru

Author: Elena Indrupskaya

Backpatch-through: 15

2 years agoStamp 15rc2. REL_15_RC2
Tom Lane [Mon, 3 Oct 2022 21:03:12 +0000 (17:03 -0400)] 
Stamp 15rc2.

2 years agoFix psql's behavior with \g for a multiple-command string.
Tom Lane [Mon, 3 Oct 2022 19:07:10 +0000 (15:07 -0400)] 
Fix psql's behavior with \g for a multiple-command string.

The pre-v15 behavior was to discard all but the last result,
but with the new behavior of printing all results by default,
we will send each such result to the \g file.  However,
we're still opening and closing the \g file for each result,
so you lose all but the last result anyway.  Move the output-file
state up to ExecQueryAndProcessResults so that we open/close the
\g file only once per command string.

To support this without changing other behavior, we must
adjust PrintQueryResult to have separate FILE * arguments
for query and status output (since status output has never
gone to the \g file).  That in turn makes it a good idea
to push the responsibility for fflush'ing output down to
PrintQueryTuples and PrintQueryStatus.

Also fix an infinite loop if COPY IN/OUT is attempted in \watch.
We used to reject that, but that error exit path got broken
somewhere along the line in v15.  There seems no real reason
to reject it anyway as the code now stands, so just remove
the error exit and make sure that COPY OUT data goes to the
right place.

Also remove PrintQueryResult's unused is_watch parameter,
and make some other cosmetic cleanups (adjust obsolete
comments, break some overly-long lines).

Daniel Vérité and Tom Lane

Discussion: https://postgr.es/m/4333844c-2244-4d6e-a49a-1d483fbe304f@manitou-mail.org

2 years agoDoc: update v15 release notes.
Tom Lane [Mon, 3 Oct 2022 15:06:33 +0000 (11:06 -0400)] 
Doc: update v15 release notes.

2 years agoRevert "Optimize order of GROUP BY keys".
Tom Lane [Mon, 3 Oct 2022 14:56:16 +0000 (10:56 -0400)] 
Revert "Optimize order of GROUP BY keys".

This reverts commit db0d67db2401eb6238ccc04c6407a4fd4f985832 and
several follow-on fixes.  The idea of making a cost-based choice
of the order of the sorting columns is not fundamentally unsound,
but it requires cost information and data statistics that we don't
really have.  For example, relying on procost to distinguish the
relative costs of different sort comparators is pretty pointless
so long as most such comparator functions are labeled with cost 1.0.
Moreover, estimating the number of comparisons done by Quicksort
requires more than just an estimate of the number of distinct values
in the input: you also need some idea of the sizes of the larger
groups, if you want an estimate that's good to better than a factor of
three or so.  That's data that's often unknown or not very reliable.
Worse, to arrive at estimates of the number of calls made to the
lower-order-column comparison functions, the code needs to make
estimates of the numbers of distinct values of multiple columns,
which are necessarily even less trustworthy than per-column stats.
Even if all the inputs are perfectly reliable, the cost algorithm
as-implemented cannot offer useful information about how to order
sorting columns beyond the point at which the average group size
is estimated to drop to 1.

Close inspection of the code added by db0d67db2 shows that there
are also multiple small bugs.  These could have been fixed, but
there's not much point if we don't trust the estimates to be
accurate in-principle.

Finally, the changes in cost_sort's behavior made for very large
changes (often a factor of 2 or so) in the cost estimates for all
sorting operations, not only those for multi-column GROUP BY.
That naturally changes plan choices in many situations, and there's
precious little evidence to show that the changes are for the better.
Given the above doubts about whether the new estimates are really
trustworthy, it's hard to summon much confidence that these changes
are better on the average.

Since we're hard up against the release deadline for v15, let's
revert these changes for now.  We can always try again later.

Note: in v15, I left T_PathKeyInfo in place in nodes.h even though
it's unreferenced.  Removing it would be an ABI break, and it seems
a bit late in the release cycle for that.

Discussion: https://postgr.es/m/TYAPR01MB586665EB5FB2C3807E893941F5579@TYAPR01MB5866.jpnprd01.prod.outlook.com

2 years agoci: macos: Reduce test concurrency
Andres Freund [Sat, 1 Oct 2022 23:55:16 +0000 (16:55 -0700)] 
ci: macos: Reduce test concurrency

Test performance regresses noticably when using all cores. This is more
pronounced with meson than with autoconf, presumably because meson will
schedule the "full number" of tests more consistently.  8 seems to work
OK.

Discussion: https://postgr.es/m/20220927040208.l3shfcidovpzqxfh@awork3.anarazel.de
Backpatch: 15-, where CI was introduced

2 years agodoc: Fix some grammar and typos
Michael Paquier [Sat, 1 Oct 2022 06:28:11 +0000 (15:28 +0900)] 
doc: Fix some grammar and typos

This fixes some areas related to logical replication and custom RMGRs.

Author: Ekaterina Kiryanova
Discussion: https://postgr.es/m/fa4773f1-1396-384a-bcd7-85b5e013f399@postgrespro.ru
Backpatch-through: 15

2 years agoAvoid improbable PANIC during heap_update, redux.
Tom Lane [Fri, 30 Sep 2022 23:36:46 +0000 (19:36 -0400)] 
Avoid improbable PANIC during heap_update, redux.

Commit 34f581c39 intended to ensure that RelationGetBufferForTuple
would acquire a visibility-map page pin in case the otherBuffer's
all-visible bit had become set since we last had lock on that page.
But I missed a case: when we're extending the relation, VM concerns
were dealt with only in the relatively-less-likely case that we
fail to conditionally lock the otherBuffer.  I think I'd believed
that we couldn't need to worry about it if the conditional lock
succeeds, which is true for the target buffer; but the otherBuffer
was unlocked for awhile so its bit might be set anyway.  So we need
to do the GetVisibilityMapPins dance, and then also recheck the
page's free space, in both cases.

Per report from Jaime Casanova.  Back-patch to v12 as the previous
patch was (although there's still no evidence that the bug is
reachable pre-v14).

Discussion: https://postgr.es/m/E1lWLjP-00006Y-Ml@gemulon.postgresql.org

2 years agoFix tab-completion after commit 790bf615ddba
Alvaro Herrera [Fri, 30 Sep 2022 10:53:31 +0000 (12:53 +0200)] 
Fix tab-completion after commit 790bf615ddba

I (Álvaro) broke tab-completion for GRANT .. ALL TABLES IN SCHEMA while
removing ALL from the publication syntax for schemas in the
aforementioned commit.  I also missed to update a bunch of
tab-completion rules for ALTER/CREATE PUBLICATION that match each
individual piece of ALL TABLES IN SCHEMA.  Repair those bugs.

While fixing up that commit, update a couple of outdated comments
related to the same change.

Backpatch to 15.

Author: Shi yu <shiy.fnst@fujitsu.com>
Reviewed-by: Peter Smith <smithpb2250@gmail.com>
Discussion: https://postgr.es/m/OSZPR01MB6310FCE8609185A56344EED2FD559@OSZPR01MB6310.jpnprd01.prod.outlook.com

2 years agodoc: Fix PQsslAttribute docs for compression
Daniel Gustafsson [Fri, 30 Sep 2022 10:03:48 +0000 (12:03 +0200)] 
doc: Fix PQsslAttribute docs for compression

The compression parameter to PQsslAttribute has never returned the
compression method used, it has always returned "on" or "off since
it was added in commit 91fa7b4719ac. Backpatch through v10.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/B9EC60EC-F665-47E8-A221-398C76E382C9@yesql.se
Backpatch-through: v10

2 years agoFix bogus behavior of PQsslAttribute(conn, "library").
Tom Lane [Thu, 29 Sep 2022 21:28:09 +0000 (17:28 -0400)] 
Fix bogus behavior of PQsslAttribute(conn, "library").

Commit ebc8b7d44 intended to change the behavior of
PQsslAttribute(NULL, "library"), but accidentally also changed
what happens with a non-NULL conn pointer.  Undo that so that
only the intended behavior change happens.  Clarify some
associated documentation.

Per bug #17625 from Heath Lord.  Back-patch to v15.

Discussion: https://postgr.es/m/17625-fc47c78b7d71b534@postgresql.org

2 years agoUpdate comment in ExecInsert() regarding batch insertion.
Etsuro Fujita [Thu, 29 Sep 2022 07:55:01 +0000 (16:55 +0900)] 
Update comment in ExecInsert() regarding batch insertion.

Remove the stale text that is a leftover from an earlier version of the
patch to add support for batch insertion, and adjust the wording in the
remaining text.

Back-patch to v14 where batch insertion came in.

Review and wording adjustment by Tom Lane.

Discussion: https://postgr.es/m/CAPmGK14goatHPHQv2Aeu_UTKqZ%2BBO%2BP%2Bzd3HKv5D%2BdyyfWKDSw%40mail.gmail.com

2 years agoRestrict Datum sort optimization to byval types only
David Rowley [Wed, 28 Sep 2022 22:43:40 +0000 (11:43 +1300)] 
Restrict Datum sort optimization to byval types only

91e9e89dc modified nodeSort.c so that it used datum sorts when the
targetlist of the outer node contained only a single column.  That commit
failed to recognise that the Datum returned by tuplesort_getdatum() must
be pfree'd when the type is a byref type.  Ronan Dunklau did originally
propose the patch with that restriction, but that, probably through my own
fault, got lost during further development work.

Due to the timing of this report (PG15 RC1 is almost out the door), let's
just restrict the datum sort optimization to apply for byval types only.
We might want to look harder into making this work for byref types in
PG16.

Reported-by: Önder Kalacı
Diagnosis-by: Tom Lane
Discussion: https://postgr.es/m/CACawEhVxe0ufR26UcqtU7GYGRuubq3p6ZWPGXL4cxy_uexpAAQ@mail.gmail.com
Backpatch-through: 15, where 91e9e89dc was introduced.

2 years agodoc: clarify internal behavior of RECURSIVE CTE queries
Bruce Momjian [Wed, 28 Sep 2022 17:14:38 +0000 (13:14 -0400)] 
doc: clarify internal behavior of RECURSIVE CTE queries

Reported-by: Tom Lane
Discussion: https://postgr.es/m/3976627.1662651004@sss.pgh.pa.us

Backpatch-through: 10

2 years agorevert "warn of SECURITY DEFINER schemas for non-sql_body funcs"
Bruce Momjian [Wed, 28 Sep 2022 17:05:20 +0000 (13:05 -0400)] 
revert "warn of SECURITY DEFINER schemas for non-sql_body funcs"

doc revert of commit 1703726488.  Change was applied to irrelevant
branches, and was not detailed enough to be helpful in relevant
branches.

Reported-by: Peter Eisentraut, Noah Misch
Discussion: https://postgr.es/m/a2dc9de4-24fc-3222-87d3-0def8057d7d8@enterprisedb.com

Backpatch-through: 10

2 years agoChange some errdetail() to errdetail_internal()
Alvaro Herrera [Wed, 28 Sep 2022 15:14:53 +0000 (17:14 +0200)] 
Change some errdetail() to errdetail_internal()

This prevents marking the argument string for translation for gettext,
and it also prevents the given string (which is already translated) from
being translated at runtime.

Also, mark the strings used as arguments to check_rolespec_name for
translation.

Backpatch all the way back as appropriate.  None of this is caught by
any tests (necessarily so), so I verified it manually.

2 years agoRemove publicationcmds.c's expr_allowed_in_node as a function
Alvaro Herrera [Wed, 28 Sep 2022 11:47:25 +0000 (13:47 +0200)] 
Remove publicationcmds.c's expr_allowed_in_node as a function

Its API is quite strange, and since there's only one caller, there's no
reason for it to be a separate function in the first place.  Inline it
instead.

Discussion: https://postgr.es/m/20220927124249.4zdzzlz6had7k3x2@alvherre.pgsql

2 years agoImprove some publication-related error messages
Alvaro Herrera [Tue, 27 Sep 2022 12:11:31 +0000 (14:11 +0200)] 
Improve some publication-related error messages

While at it, remove an unused queryString parameter from
CheckPubRelationColumnList() and make other minor stylistic changes.

Backpatch to 15.

Reported by Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Co-authored-by: Hou zj <houzj.fnst@fujitsu.com>
Discussion: https://postgr.es/m/20220926.160426.454497059203258582.horikyota.ntt@gmail.com

2 years agoFix pg_stat_statements for MERGE
Alvaro Herrera [Tue, 27 Sep 2022 08:44:42 +0000 (10:44 +0200)] 
Fix pg_stat_statements for MERGE

We weren't jumbling the merge action list, so wildly different commands
would be considered to use the same query ID.  Add that, mention it in
the docs, and some test lines.

Backpatch to 15.

Author: Tatsu <bt22nakamorit@oss.nttdata.com>
Reviewed-by: Julien Rouhaud <rjuju123@gmail.com>
Discussion: https://postgr.es/m/d87e391694db75a038abc3b2597828e8@oss.nttdata.com

2 years agoci: Add hint about downloadable logs to README
Andres Freund [Tue, 27 Sep 2022 03:02:26 +0000 (20:02 -0700)] 
ci: Add hint about downloadable logs to README

I (Andres) chose to backpatch this to 15, as it seems better to keep the
README the same.

Author: James Coleman <jtc331@gmail.com>
Discussion: https://postgr.es/m/CAAaqYe_7BXDjpk0Ks_eqf1r6LZpC_rfB7kjhb_T3+eC4t6yiGQ@mail.gmail.com
Backpatch: 15-, where CI came in

2 years agoDoc: last minute adjustment to the release notes
David Rowley [Mon, 26 Sep 2022 21:57:07 +0000 (10:57 +1300)] 
Doc: last minute adjustment to the release notes

The change made in 9d9c02ccd also affects the dense_rank() function.
Mention this in the release notes.

Author: Jonathan S. Katz
Discussion: https://postgr.es/m/5c6d3f50-e9b5-f62d-d58a-7b22eb91d8b8@postgresql.org

2 years agoStamp 15rc1. REL_15_RC1
Tom Lane [Mon, 26 Sep 2022 20:36:49 +0000 (16:36 -0400)] 
Stamp 15rc1.

2 years agoDoc: more tweaking of v15 release notes.
Tom Lane [Mon, 26 Sep 2022 18:32:51 +0000 (14:32 -0400)] 
Doc: more tweaking of v15 release notes.

Per suggestions from Justin Pryzby.

Discussion: https://postgr.es/m/20220925215009.GC21938@telsasoft.com

2 years agoDoc: further adjust notes about pg_upgrade_output.d.
Tom Lane [Mon, 26 Sep 2022 18:19:21 +0000 (14:19 -0400)] 
Doc: further adjust notes about pg_upgrade_output.d.

I'd misunderstood how it worked in 5f1048881.

Discussion: https://postgr.es/m/20220925215009.GC21938@telsasoft.com

2 years agoTranslation updates
Peter Eisentraut [Mon, 26 Sep 2022 11:16:06 +0000 (13:16 +0200)] 
Translation updates

Source-Git-URL: https://git.postgresql.org/git/pgtranslation/messages.git
Source-Git-Hash: 0a336c1e07ac371cf445a0cecac6b27720da228c

2 years agoUpdate list of acknowledgments in release notes
Peter Eisentraut [Mon, 26 Sep 2022 10:57:12 +0000 (12:57 +0200)] 
Update list of acknowledgments in release notes

current through 15113bfb467a84688744b57b74a14550878d0224

2 years agoDoc: Remove the use of a duplicate word.
Amit Kapila [Mon, 26 Sep 2022 03:56:47 +0000 (09:26 +0530)] 
Doc: Remove the use of a duplicate word.

This has been removed in HEAD by commit a234177906, so doing just backpatch
to 15 where it was introduced in commit 860ea46ba7.

Author: Zhang Mingli
Discussion: https://postgr.es/m/OS0PR01MB57162559C01FE2848C12E8F7944D9@OS0PR01MB5716.jpnprd01.prod.outlook.com

2 years agoFix tupdesc lifespan bug with AfterTriggersTableData.storeslot.
Tom Lane [Sun, 25 Sep 2022 21:10:58 +0000 (17:10 -0400)] 
Fix tupdesc lifespan bug with AfterTriggersTableData.storeslot.

Commit 25936fd46 adjusted things so that the "storeslot" we use
for remapping trigger tuples would have adequate lifespan, but it
neglected to consider the lifespan of the tuple descriptor that
the slot depends on.  It turns out that in at least some cases, the
tupdesc we are passing is a refcounted tupdesc, and the refcount for
the slot's reference can get assigned to a resource owner having
different lifespan than the slot does.  That leads to an error like
"tupdesc reference 0x7fdef236a1b8 is not owned by resource owner
SubTransaction".  Worse, because of a second oversight in the same
commit, we'd try to free the same tupdesc refcount again while
cleaning up after that error, leading to recursive errors and an
"ERRORDATA_STACK_SIZE exceeded" PANIC.

To fix the initial problem, let's just make a non-refcounted copy
of the tupdesc we're supposed to use.  That seems likely to guard
against additional problems, since there's no strong reason for
this code to assume that what it's given is a refcounted tupdesc;
in which case there's an independent hazard of the tupdesc having
shorter lifespan than the slot does.  (I didn't bother trying to
free said copy, since it should go away anyway when the (sub)
transaction context is cleaned up.)

The other issue can be fixed by making the code added to
AfterTriggerFreeQuery work like the rest of that function, ie be
sure that it doesn't try to free the same slot twice in the event
of recursive error cleanup.

While here, also clean up minor stylistic issues in the test case
added by 25936fd46: don't use "create or replace function", as any
name collision within the tests is likely to have ill effects
that that won't mask; and don't use function names as generic as
trigger_function1, especially if you're not going to drop them
at the end of the test stanza.

Per bug #17607 from Thomas Mc Kay.  Back-patch to v12, as the
previous fix was.

Discussion: https://postgr.es/m/17607-bd8ccc81226f7f80@postgresql.org

2 years agoAvoid loss of code coverage with unlogged-index test cases.
Tom Lane [Sun, 25 Sep 2022 17:10:10 +0000 (13:10 -0400)] 
Avoid loss of code coverage with unlogged-index test cases.

Commit 4fb5c794e intended to add coverage of some ambuildempty
methods that were not getting reached, without removing any
test coverage.  However, by changing a temp table to unlogged
it managed to negate the intent of 4c51a2d1e, which means that
we didn't have reliable test coverage of ginvacuum.c anymore.
As things stand, much of that file might or might not get reached
depending on timing, which seems pretty undesirable.

Although this is only clearly broken for the GIN test, it seems
best to revert 4fb5c794e altogether and instead add bespoke test
cases covering unlogged indexes for these four AMs.  We don't
need to do very much with them, so the extra tests are cheap.
(Note that btree, hash, and bloom already have similar test cases,
so they need no additional work.)

We can also undo dec8ad367.  Since the testing deficiency that that
hacked around was later fixed by 2f2e24d90, let's intentionally leave
an unlogged table behind to improve test coverage in the modules that
use the regression database for other test purposes.  (The case I used
also leaves an unlogged sequence behind.)

Per report from Alex Kozhemyakin.  Back-patch to v15 where the
faulty test came in.

Discussion: https://postgr.es/m/b00c8ee096ee46cd25c183125562a1a7@postgrespro.ru

2 years agoAdd missing source files to pg_waldump/nls.mk
Alvaro Herrera [Sun, 25 Sep 2022 15:48:03 +0000 (17:48 +0200)] 
Add missing source files to pg_waldump/nls.mk

2 years agoMessage style improvements
Peter Eisentraut [Sat, 24 Sep 2022 22:38:35 +0000 (18:38 -0400)] 
Message style improvements

2 years agoImprove terminology
Peter Eisentraut [Sat, 24 Sep 2022 01:16:08 +0000 (21:16 -0400)] 
Improve terminology

Use "prepared transaction" instead of "two-phrase transaction".  This
is in line with c5d67881d343a507269bde124a49df19e0296157.

2 years agoDoc: make an editorial pass over the v15 release notes.
Tom Lane [Fri, 23 Sep 2022 22:22:33 +0000 (18:22 -0400)] 
Doc: make an editorial pass over the v15 release notes.

Rearrange, reword, clarify, fix markup, etc etc.

Also include commit bd8ac900d.

2 years agoDoc: minor cleanups.
Tom Lane [Fri, 23 Sep 2022 22:20:11 +0000 (18:20 -0400)] 
Doc: minor cleanups.

Improve a couple of things I noticed while working on v15
release notes.

2 years agopgstat: Fix transactional stats dropping for indexes
Andres Freund [Fri, 23 Sep 2022 20:00:55 +0000 (13:00 -0700)] 
pgstat: Fix transactional stats dropping for indexes

Because index creation does not go through heap_create_with_catalog() we
didn't call pgstat_create_relation(), leading to index stats of a newly
created realtion not getting dropped during rollback. To fix, move the
pgstat_create_relation() to heap_create(), which indexes do use.

Similarly, because dropping an index does not go through
heap_drop_with_catalog(), we didn't drop index stats when the transaction
dropping an index committed. Here there's no convenient common path for
indexes and relations, so index_drop() now calls pgstat_drop_relation().

Add tests for transactional index stats handling.

Author: "Drouvot, Bertrand" <bdrouvot@amazon.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Discussion: https://postgr.es/m/51bbf286-2b4a-8998-bd12-eaae4b765d99@amazon.com
Backpatch: 15-, like 8b1dccd37c71, which introduced the bug

2 years agoDoc: update v15 release notes through today.
Tom Lane [Fri, 23 Sep 2022 17:59:29 +0000 (13:59 -0400)] 
Doc: update v15 release notes through today.

Account for commits since 2022-06-11.

2 years agoRemove PQsendQuery support in pipeline mode
Alvaro Herrera [Fri, 23 Sep 2022 16:21:22 +0000 (18:21 +0200)] 
Remove PQsendQuery support in pipeline mode

The extended query protocol implementation I added in commit
acb7e4eb6b1c has bugs when used in pipeline mode.  Rather than spend
more time trying to fix it, remove that code and make the function rely
on simple query protocol only, meaning it can no longer be used in
pipeline mode.

Users can easily change their applications to use PQsendQueryParams
instead.  We leave PQsendQuery in place for Postgres 14, just in case
somebody is using it and has not hit the mentioned bugs; but we should
recommend that it not be used.

Backpatch to 15.

Per bug report from Gabriele Varrazzo.
Discussion: https://postgr.es/m/CA+mi_8ZGSQNmW6-mk_iSR4JZB_LJ4ww3suOF+1vGNs3MrLsv4g@mail.gmail.com

2 years agoStop using PQsendQuery in libpq_pipeline
Alvaro Herrera [Fri, 23 Sep 2022 16:11:48 +0000 (18:11 +0200)] 
Stop using PQsendQuery in libpq_pipeline

The "emulation" I wrote for PQsendQuery in pipeline mode to use extended
query protocol, in commit acb7e4eb6b1c, is problematic.  Due to numerous
bugs we'll soon remove it.  As a first step and for all branches back to
14, stop using PQsendQuery in libpq_pipeline.  Also remove a few test
lines that will no longer be relevant.

Backpatch to 14.

Discussion: https://postgr.es/m/CA+mi_8ZGSQNmW6-mk_iSR4JZB_LJ4ww3suOF+1vGNs3MrLsv4g@mail.gmail.com

2 years agoDoc: add list of major features to the v15 release notes.
Tom Lane [Fri, 23 Sep 2022 15:24:12 +0000 (11:24 -0400)] 
Doc: add list of major features to the v15 release notes.

Jonathan Katz (word-smithed a bit by me)

Discussion: https://postgr.es/m/a6661e2c-72e0-b4bd-9301-9225bdddda4c@postgresql.org

2 years agoAllow publications with schema and table of the same schema.
Amit Kapila [Fri, 23 Sep 2022 02:38:24 +0000 (08:08 +0530)] 
Allow publications with schema and table of the same schema.

We previously thought that allowing such cases can confuse users when they
specify DROP TABLES IN SCHEMA but that doesn't seem to be the case based
on discussion. This helps to uplift the restriction during
ALTER TABLE ... SET SCHEMA which used to ensure that we couldn't end up
with a publication having both a schema and the same schema's table.

To allow this, we need to forbid having any schema on a publication if
column lists on a table are specified (and vice versa). This is because
otherwise we still need a restriction during ALTER TABLE ... SET SCHEMA to
forbid cases where it could lead to a publication having both a schema and
the same schema's table with column list.

Based on suggestions by Peter Eisentraut.

Author: Hou Zhijie and Vignesh C
Reviewed-By: Peter Smith, Amit Kapila
Backpatch-through: 15, where it was introduced
Discussion: https://postgr.es/m/2729c9e2-9aac-8cda-f2f4-34f2bcc18f4e@enterprisedb.com

2 years agoFix race condition where heap_delete() fails to pin VM page.
Jeff Davis [Thu, 22 Sep 2022 17:58:49 +0000 (10:58 -0700)] 
Fix race condition where heap_delete() fails to pin VM page.

Similar to 5f12bc94dc, the code must re-check PageIsAllVisible() after
buffer lock is re-acquired. Backpatching to the same version, 12.

Discussion: https://postgr.es/m/CAEP4nAw9jYQDKd_5Y+-s2E4YiUJq1vqiikFjYGpLShtp-K3gag@mail.gmail.com
Reported-by: Robins Tharakan
Reviewed-by: Robins Tharakan
Backpatch-through: 12

2 years agoRemove ALL keyword from TABLES IN SCHEMA for publication
Alvaro Herrera [Thu, 22 Sep 2022 17:02:25 +0000 (19:02 +0200)] 
Remove ALL keyword from TABLES IN SCHEMA for publication

This may be a bit too subtle, but removing that word from there makes
this clause no longer a perfect parallel of the GRANT variant "ALL
TABLES IN SCHEMA": indeed, for publications what we record is the schema
itself, not the tables therein, which means that any tables added to the
schema in the future are also published.  This is completely different
to what GRANT does, which is affect only the tables that exist when the
command is executed.

There isn't resounding support for this change, but there are a few
positive votes and no opposition.  Because the time to 15 RC1 is very
short, let's get this out now.

Backpatch to 15.

Discussion: https://postgr.es/m/2729c9e2-9aac-8cda-f2f4-34f2bcc18f4e

2 years agoRestore archive_command documentation
Peter Eisentraut [Sat, 17 Sep 2022 09:34:20 +0000 (11:34 +0200)] 
Restore archive_command documentation

Commit 5ef1eefd76f404ddc59b885d50340e602b70f05f, which added
archive_library, purged most mentions of archive_command from the
documentation.  This is inappropriate, since archive_command is still
a feature in use and users will want to see information about it.

This restores all the removed mentions and rephrases things so that
archive_command and archive_library are presented as alternatives of
each other.

Reviewed-by: Nathan Bossart <nathandbossart@gmail.com>
Discussion: https://www.postgresql.org/message-id/9366d634-a917-85a9-4991-b2a4859edaf9@enterprisedb.com

2 years agoUse min/max bounds defined by Zstd for compression level
Michael Paquier [Thu, 22 Sep 2022 11:03:30 +0000 (20:03 +0900)] 
Use min/max bounds defined by Zstd for compression level

The bounds hardcoded in compression.c since ffd5365 (minimum at 1 and
maximum at 22) do not match the reality of what zstd is able to
handle, these values being available via ZSTD_maxCLevel() and
ZSTD_minCLevel() at run-time.  The maximum of 22 is actually correct
in recent versions, but the minimum was not as the library can go down
to -131720 by design.  This commit changes the code to use the run-time
values in the code instead of some hardcoded ones.

Zstd seems to assume that these bounds could change in the future, and
Postgres will be able to adapt automatically to such changes thanks to
what's being done in this commit.

Reported-by: Justin Prysby
Discussion: https://postgr.es/m/20220922033716.GL31833@telsasoft.com
Backpatch-through: 15

2 years agoFix thinko in comment.
Etsuro Fujita [Thu, 22 Sep 2022 06:55:01 +0000 (15:55 +0900)] 
Fix thinko in comment.

This comment has been wrong since its introduction in commit 0d5f05cde;
backpatch to v12 where that came in.

Discussion: https://postgr.es/m/CAPmGK14VGf-xQjGQN4o1QyAbXAaxugU5%3DqfcmTDh1iufUDnV_w%40mail.gmail.com

2 years agoClear ps display of startup process at the end of recovery
Michael Paquier [Thu, 22 Sep 2022 05:25:12 +0000 (14:25 +0900)] 
Clear ps display of startup process at the end of recovery

If the ps display is not cleared at this point, the process could
continue displaying "recovering NNN" even if handling end-of-recovery
steps.  df9274a has tackled that by providing some information with the
end-of-recovery checkpoint but 7ff23c6 has nullified the effect of the
first commit.

Per a suggestion from Justin, just clear the ps display when we are done
with recovery, so as no incorrect information is displayed.  This may
get extended in the future, but for now restore the pre-7ff23c6
behavior.

Author: Justin Prysby
Discussion: https://postgr.es/m/20220913223954.GU31833@telsasoft.com
Backpatch-through: 15

2 years agodocs: Fix snapshot name in SET TRANSACTION docs.
Fujii Masao [Thu, 22 Sep 2022 03:54:26 +0000 (12:54 +0900)] 
docs: Fix snapshot name in SET TRANSACTION docs.

Commit 6c2003f8a1 changed the snapshot names mentioned in
SET TRANSACTION docs, however, there was one place that
the commit missed updating the name.

Back-patch to all supported versions.

Author: Japin Li
Reviewed-by: Fujii Masao
Discussion: https://postgr.es/m/MEYP282MB1669BD4280044501165F8B07B64F9@MEYP282MB1669.AUSP282.PROD.OUTLOOK.COM

2 years agopsql: Improve tab-completion for MERGE.
Fujii Masao [Thu, 22 Sep 2022 00:25:29 +0000 (09:25 +0900)] 
psql: Improve tab-completion for MERGE.

Commit 7103ebb7aa added the tab-completion for MERGE accidentally
in the middle of that for LOCK TABLE. This commit fixes this issue.

This also adds some tab-completion for MERGE.

Back-patch to v15 where MERGE was introduced.

Author: Kotaro Kawamoto, Fujii Masao
Reviewed-by: Shinya Kato, Álvaro Herrera
Discussion: https://postgr.es/m/9f1ad2a87a58cd5e7d64f3993130958d@oss.nttdata.com

2 years agoci: windows: set error mode to not include SEM_NOGPFAULTERRORBOX
Andres Freund [Thu, 22 Sep 2022 00:15:54 +0000 (17:15 -0700)] 
ci: windows: set error mode to not include SEM_NOGPFAULTERRORBOX

Cirrus defaults to SetErrorMode(SEM_NOGPFAULTERRORBOX | ...). That prevents
crash reporting from working unless binaries do SetErrorMode()
themselves. Furthermore, it appears that either python or, more likely, the C
runtime has a bug where SEM_NOGPFAULTERRORBOX can very occasionally *trigger*
a crash on process exit - which is hard to debug, given that it explicitly
prevents crash dumps from working...

Discussion: https://postgr.es/m/20220909235836.lz3igxtkcjb5w7zb%40awork3.anarazel.de
Backpatch: 15-, where CI was added

2 years agoci: Increase requested memory size.
Thomas Munro [Wed, 21 Sep 2022 23:35:46 +0000 (11:35 +1200)] 
ci: Increase requested memory size.

CI builds recently started failing with:

"Memory size for 4.0 vCPU instance should be between 3840MiB and
26624MiB, while 2048MiB is requested."

Ok then, let's ask for 4G instead of 2G.

This may be due to a change in the type of instance used to work around
an outage, per:

https://twitter.com/cirrus_labs/status/1572657320093712384

2 years agoImprove ICU option handling in CREATE DATABASE
Peter Eisentraut [Wed, 21 Sep 2022 14:28:40 +0000 (10:28 -0400)] 
Improve ICU option handling in CREATE DATABASE

We check that the ICU locale is only specified if the ICU locale
provider is selected.  But we did that too early.  We need to wait
until we load the settings of the template database, since that could
also set what the locale provider is.

Reported-by: Marina Polyakova <m.polyakova@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/9ba4cd1ea6ed6b7b15c0ff15e6f540cd@postgrespro.ru

2 years agoTighten pg_get_object_address argument checking
Peter Eisentraut [Wed, 21 Sep 2022 13:34:22 +0000 (09:34 -0400)] 
Tighten pg_get_object_address argument checking

For publication schemas (OBJECT_PUBLICATION_NAMESPACE) and user
mappings (OBJECT_USER_MAPPING), pg_get_object_address() checked the
array length of the second argument, but not of the first argument.
If the first argument was too long, it would just silently ignore
everything but the first argument.  Fix that by checking the length of
the first argument as well.

Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/caaef70b-a874-1088-92ef-5ac38269c33b%40enterprisedb.com

2 years agoImprove some GUC description strings
Alvaro Herrera [Wed, 21 Sep 2022 10:29:38 +0000 (12:29 +0200)] 
Improve some GUC description strings

It is not our usual style to use "we" in messages.  Also, remove some
noise words.  Backpatch to 15.

Noted by Kyotaro Horiguchi.

Discussion: https://postgr.es/m/20220914.111507.13049297635620898.horikyota.ntt@gmail.com

2 years agoDisable -Wdeprecated-non-prototype in the back branches.
Tom Lane [Tue, 20 Sep 2022 22:59:53 +0000 (18:59 -0400)] 
Disable -Wdeprecated-non-prototype in the back branches.

There doesn't seem to be any good ABI-preserving way to silence
clang 15's -Wdeprecated-non-prototype warnings about our tree-walk
APIs.  While we've fixed it properly in HEAD, the only way to not
see hundreds of these in the back branches is to disable the
warnings.  We're not going to do anything about them, so we might
as well disable them.

I noticed that we also get some of these warnings about fmgr.c's
support for V0 function call convention, in branches before v10
where we removed that.  That's another area we aren't going to
change, so turning off the warning seems fine for that too.

Per project policy, this is a candidate for back-patching into
out-of-support branches: it suppresses annoying compiler warnings
but changes no behavior.  Hence, back-patch all the way to 9.2.

Discussion: https://postgr.es/m/CA+hUKGKpHPDTv67Y+s6yiC8KH5OXeDg6a-twWo_xznKTcG0kSA@mail.gmail.com

2 years agoSuppress variable-set-but-not-used warnings from clang 15.
Tom Lane [Tue, 20 Sep 2022 16:04:37 +0000 (12:04 -0400)] 
Suppress variable-set-but-not-used warnings from clang 15.

clang 15+ will issue a set-but-not-used warning when the only
use of a variable is in autoincrements (e.g., "foo++;").
That's perfectly sensible, but it detects a few more cases that
we'd not noticed before.  Silence the warnings with our usual
methods, such as PG_USED_FOR_ASSERTS_ONLY, or in one case by
actually removing a useless variable.

One thing that we can't nicely get rid of is that with %pure-parser,
Bison emits "yynerrs" as a local variable that falls foul of this
warning.  To silence those, I inserted "(void) yynerrs;" in the
top-level productions of affected grammars.

Per recently-established project policy, this is a candidate
for back-patching into out-of-support branches: it suppresses
annoying compiler warnings but changes no behavior.  Hence,
back-patch to 9.5, which is as far as these patches go without
issues.  (A preliminary check shows that the prior branches
need some other set-but-not-used cleanups too, so I'll leave
them for another day.)

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

2 years agoDisable autovacuum in MERGE test script
Alvaro Herrera [Tue, 20 Sep 2022 10:38:48 +0000 (12:38 +0200)] 
Disable autovacuum in MERGE test script

Otherwise, it can fail given sufficient bad luck.

Backpatch to 15.

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

2 years agodoc: Fix parameter name for pg_create_logical_replication_slot()
Michael Paquier [Tue, 20 Sep 2022 10:28:43 +0000 (19:28 +0900)] 
doc: Fix parameter name for pg_create_logical_replication_slot()

The parameter controlling if two-phase transactions can be decoded was
named "two_phase" in the documentation while its procedure defines
"twophase".

Author: Florin Irion
Discussion: https://postgr.es/m/5eeabd10-1aff-ea61-f92d-9fa0d9a7e207@gmail.com
Backpatch-through: 14

2 years agoFix incorrect variable types for origin IDs in decode.c
Michael Paquier [Tue, 20 Sep 2022 09:13:39 +0000 (18:13 +0900)] 
Fix incorrect variable types for origin IDs in decode.c

These variables used XLogRecPtr instead of RepOriginId.

Author: Masahiko Sawada
Discussion: https://postgr.es/m/CAD21AoBm-vNyBSXGp4bmJGvhr=S-EGc5q1dtV70cFTcJvLhC=Q@mail.gmail.com
Backpatch-through: 14

2 years agoFix misleading comment for get_cheapest_group_keys_order
David Rowley [Mon, 19 Sep 2022 22:04:13 +0000 (10:04 +1200)] 
Fix misleading comment for get_cheapest_group_keys_order

The header comment for get_cheapest_group_keys_order() claimed that the
output arguments were set to a newly allocated list which may be freed by
the calling function, however, this was not always true as the function
would simply leave these arguments untouched in some cases.

This tripped me up when working on 1349d2790 as I mistakenly assumed I
could perform a list_concat with the output parameters.  That turned out
bad due to list_concat modifying the original input lists.

In passing, make it more clear that the number of distinct values is
important to reduce tiebreaks during sorts.  Also, explain what the
n_preordered parameter means.

Backpatch-through: 15, where get_cheapest_group_keys_order was introduced.

2 years agoFix out-dated comment in preprocess_groupclause()
David Rowley [Mon, 19 Sep 2022 21:15:04 +0000 (09:15 +1200)] 
Fix out-dated comment in preprocess_groupclause()

The comment claimed we don't consider other orders of the GROUP BY clause,
but this is no longer true as of db0d67db2.

Discussion: https://postgr.es/m/CAApHDvq65=9Ro+hLX1i9ugWEiNDvHrBibAO7ARcTnf38_JE+UQ@mail.gmail.com
Backpatch-through: 15, where db0d67db2 was introduced.

2 years agoFix icu tests with C locale
Peter Eisentraut [Mon, 19 Sep 2022 19:22:43 +0000 (15:22 -0400)] 
Fix icu tests with C locale

Similar to 1e08576691bf1a25c0e28745e5e800c44f2a1c76, but for the icu
test suite.

Reported-by: Christoph Berg <myon@debian.org>
Discussion: https://www.postgresql.org/message-id/YyWeU61YMFwjVdxE@msg.df7cb.de

2 years agoFuture-proof the recursion inside ExecShutdownNode().
Tom Lane [Mon, 19 Sep 2022 16:16:02 +0000 (12:16 -0400)] 
Future-proof the recursion inside ExecShutdownNode().

The API contract for planstate_tree_walker() callbacks is that they
take a PlanState pointer and a context pointer.  Somebody figured
they could save a couple lines of code by ignoring that, and passing
ExecShutdownNode itself as the walker even though it has but one
argument.  Somewhat remarkably, we've gotten away with that so far.
However, it seems clear that the upcoming C2x standard means to
forbid such cases, and compilers that actively break such code
likely won't be far behind.  So spend the extra few lines of code
to do it honestly with a separate walker function.

In HEAD, we might as well go further and remove ExecShutdownNode's
useless return value.  I left that as-is in back branches though,
to forestall complaints about ABI breakage.

Back-patch, with the thought that this might become of practical
importance before our stable branches are all out of service.
It doesn't seem to be fixing any live bug on any currently known
platform, however.

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

2 years agoImprove GUC description punctuation
Peter Eisentraut [Mon, 19 Sep 2022 10:45:23 +0000 (06:45 -0400)] 
Improve GUC description punctuation

partial backpatch of 0b039e3a8489c08ec61b4d40382047c389af91ad

2 years agoAdd missing serial commas
Peter Eisentraut [Mon, 19 Sep 2022 10:35:01 +0000 (06:35 -0400)] 
Add missing serial commas

2 years agoMake check_usermap() parameter names consistent.
Peter Geoghegan [Sat, 17 Sep 2022 23:54:16 +0000 (16:54 -0700)] 
Make check_usermap() parameter names consistent.

The function has a bool argument named "case_insensitive", but that was
spelled "case_sensitive" in the declaration.  Make them consistent now
to avoid confusion in the future.

Author: Peter Geoghegan <pg@bowt.ie>
Reviewed-By: Michael Paquiër <michael@paquier.xyz>
Discussion: https://postgr.es/m/CAH2-WznJt9CMM9KJTMjJh_zbL5hD9oX44qdJ4aqZtjFi-zA3Tg@mail.gmail.com
Backpatch: 10-

2 years agoInclude c.h instead of postgres.h in src/port/*p{read,write}*.c
Andres Freund [Sat, 17 Sep 2022 16:21:59 +0000 (09:21 -0700)] 
Include c.h instead of postgres.h in src/port/*p{read,write}*.c

Frontend code shouldn't include postgres.h. Some files in src/port/ need to
include postgres.h/postgres_fe.h, but these files don't.

Discussion: https://postgr.es/m/20220915022626.5xx3ccgkzpkqw5mq@awork3.anarazel.de
Backpatch: 12-, where 3fd2a7932ef introduced (some) of these files

2 years agopgstat: Create memory contexts below TopMemoryContext
Andres Freund [Fri, 16 Sep 2022 21:08:40 +0000 (14:08 -0700)] 
pgstat: Create memory contexts below TopMemoryContext

So far they were created below CacheMemoryContext. However, that's not
guaranteed to exist in all situations, leading to memory contexts created as
top-level contexts. There isn't actually a good reason anymore to create them
below CacheMemoryContext, so just creating them below TopMemoryContext seems
the best approach.

Reported-by: Reid Thompson <reid.thompson@crunchydata.com>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Author: "Drouvot, Bertrand" <bdrouvot@amazon.com>
Discussion: https://postgr.es/m/b948b729-42fe-f88c-2f4a-0e65d84c049b@amazon.com
Backpatch: 15-

2 years agoMessage style improvements
Peter Eisentraut [Sat, 17 Sep 2022 06:10:59 +0000 (08:10 +0200)] 
Message style improvements

2 years agoFix race condition in stats.sql added in 5264add7847
Andres Freund [Fri, 16 Sep 2022 17:07:12 +0000 (10:07 -0700)] 
Fix race condition in stats.sql added in 5264add7847

Very occasionally the stats test failed due to the number of sessions not
being updated yet. Likely this requires that there is contention on the
database's stats entry. Solve this by forcing pending stats to be flushed
before fetching the stats.

I verified that there are no other test failures after making
pgstat_report_stat() only flush stats when force = true.

Per message from Tom Lane and buildfarm member crake.

Discussion: https://postgr.es/m/3428246.1663271992@sss.pgh.pa.us
Backpatch: 15-, where 5264add7847 added the test

2 years agoImprove plpgsql's ability to handle arguments declared as RECORD.
Tom Lane [Fri, 16 Sep 2022 17:23:01 +0000 (13:23 -0400)] 
Improve plpgsql's ability to handle arguments declared as RECORD.

Treat arguments declared as RECORD as if that were a polymorphic type
(which it is, sort of), in that we substitute the actual argument type
while forming the function cache lookup key.  This allows the specific
composite type to be known in some cases where it was not before,
at the cost of making a separate function cache entry for each named
composite type that's passed to the function during a session.  The
particular symptom discussed in bug #17610 could be solved in other
more-efficient ways, but only at the cost of considerable development
work, and there are other cases where we'd still fail without this.

Per bug #17610 from Martin Jurča.  Back-patch to v11 where we first
allowed plpgsql functions to be declared as taking type RECORD.

Discussion: https://postgr.es/m/17610-fb1eef75bf6c2364@postgresql.org

2 years agoMessage wording improvements
Peter Eisentraut [Fri, 16 Sep 2022 14:37:53 +0000 (16:37 +0200)] 
Message wording improvements

2 years agoFix createdb tests for C locale
Peter Eisentraut [Fri, 16 Sep 2022 09:10:41 +0000 (11:10 +0200)] 
Fix createdb tests for C locale

If the createdb tests run under the C locale, the database cluster
will be initialized with encoding SQL_ASCII.  With the checks added in
c7db01e325a530ec38ec7ba57cd3ed32e123e33c, this will cause several
ICU-related tests to fail because SQL_ASCII is not supported by ICU.
To work around that, use initdb option -E UTF8 for those tests to get
past that check.

2 years agoDon't allow creation of database with ICU locale with unsupported encoding
Peter Eisentraut [Fri, 16 Sep 2022 07:37:54 +0000 (09:37 +0200)] 
Don't allow creation of database with ICU locale with unsupported encoding

Check in CREATE DATABASE and initdb that the selected encoding is
supported by ICU.  Before, they would pass but users would later get
an error from the server when they tried to use the database.

Also document that initdb sets the encoding to UTF8 by default if the
ICU locale provider is chosen.

Author: Marina Polyakova <m.polyakova@postgrespro.ru>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Discussion: https://www.postgresql.org/message-id/6dd6db0984d86a51b7255ba79f111971@postgrespro.ru