postgresql.git
4 years agoAdditional doc fixes for configurable TOAST compression.
Robert Haas [Thu, 6 May 2021 12:27:20 +0000 (08:27 -0400)]
Additional doc fixes for configurable TOAST compression.

The grammar changes in commit bbe0a81db69bd10bd166907c3701492a29aca294
allow SET COMPRESSION to be used with ALTER MATERIALIZED VIEW as
well as with ALTER TABLE, so update those docs to say that it works.

Also, update the documentation for the pg_column_compression()
to explain that it will return NULL when there's no relevant value.

Patch by me, per concerns from Michael Paquier.

Discussion: http://postgr.es/m/CA+Tgmob9h5u4iNL9KM0drZgkY-JL4oCVW0dWrMqtLPQ1zHkquA@mail.gmail.com

4 years agodocs: Clarify how ALTER TABLE .. SET COMPRESSION works.
Robert Haas [Thu, 6 May 2021 12:22:45 +0000 (08:22 -0400)]
docs: Clarify how ALTER TABLE .. SET COMPRESSION works.

Justin Pryzby, per a complaint from Michael Paquier. Reviewed by
Dilip Kumar and by me.

Discussion: http://postgr.es/m/20210429040132.GF27406@telsasoft.com

4 years agoUpdate replication statistics after every stream/spill.
Amit Kapila [Thu, 6 May 2021 05:51:26 +0000 (11:21 +0530)]
Update replication statistics after every stream/spill.

Currently, replication slot statistics are updated at prepare, commit, and
rollback. Now, if the transaction is interrupted the stats might not get
updated. Fixed this by updating replication statistics after every
stream/spill.

In passing update the docs to change the description of some of the slot
stats.

Author: Vignesh C, Sawada Masahiko
Reviewed-by: Amit Kapila
Discussion: https://postgr.es/m/20210319185247.ldebgpdaxsowiflw@alap3.anarazel.de

4 years agojit: Fix warning reported by gcc-11 caused by dubious function signature.
Andres Freund [Thu, 6 May 2021 05:07:40 +0000 (22:07 -0700)]
jit: Fix warning reported by gcc-11 caused by dubious function signature.

Reported-By: Erik Rijkers <er@xs4all.nl>
Discussion: https://postgr.es/m/833107370.1313189.1619647621213@webmailclassic.xs4all.nl
Backpatch: 13, where b059d2f45685 introduced the issue.

4 years agoDoc: update RELEASE_CHANGES checklist.
Tom Lane [Thu, 6 May 2021 03:10:33 +0000 (23:10 -0400)]
Doc: update RELEASE_CHANGES checklist.

Update checklist to reflect current practice:

* The platform-specific FAQ files are long gone.

* We've never routinely updated the libbind code we borrowed, either,
and there seems no reason to start now.

* Explain current practice of running pgindent twice per cycle.

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

4 years agoTighten the concurrent abort check during decoding.
Amit Kapila [Thu, 6 May 2021 02:56:42 +0000 (08:26 +0530)]
Tighten the concurrent abort check during decoding.

During decoding of an in-progress or prepared transaction, we detect
concurrent abort with an error code ERRCODE_TRANSACTION_ROLLBACK. That is
not sufficient because a callback can decide to throw that error code
at other times as well.

Reported-by: Tom Lane
Author: Amit Kapila
Reviewed-by: Dilip Kumar
Discussion: https://postgr.es/m/CAA4eK1KCjPRS4aZHB48QMM4J8XOC1+TD8jo-4Yu84E+MjwqVhA@mail.gmail.com

4 years agoRemove unused argument of ATAddForeignConstraint
Alvaro Herrera [Wed, 5 May 2021 16:27:39 +0000 (12:27 -0400)]
Remove unused argument of ATAddForeignConstraint

Commit 0325d7a5957b made this unused but forgot to remove it. Do so now.

Author: Amit Langote <amitlangote09@gmail.com>
Discussion: https://postgr.es/m/209c99fe-b9a2-94f4-cd68-a8304186a09e@lab.ntt.co.jp

4 years agoHave ALTER CONSTRAINT recurse on partitioned tables
Alvaro Herrera [Wed, 5 May 2021 16:14:21 +0000 (12:14 -0400)]
Have ALTER CONSTRAINT recurse on partitioned tables

When ALTER TABLE .. ALTER CONSTRAINT changes deferrability properties
changed in a partitioned table, we failed to propagate those changes
correctly to partitions and to triggers.  Repair by adding a recursion
mechanism to affect all derived constraints and all derived triggers.
(In particular, recurse to partitions even if their respective parents
are already in the desired state: it is possible for the partitions to
have been altered individually.)  Because foreign keys involve tables in
two sides, we cannot use the standard ALTER TABLE recursion mechanism,
so we invent our own by following pg_constraint.conparentid down.

When ALTER TABLE .. ALTER CONSTRAINT is invoked on the derived
pg_constraint object that's automaticaly created in a partition as a
result of a constraint added to its parent, raise an error instead of
pretending to work and then failing to modify all the affected triggers.
Before this commit such a command would be allowed but failed to affect
all triggers, so it would silently misbehave.  (Restoring dumps of
existing databases is not affected, because pg_dump does not produce
anything for such a derived constraint anyway.)

Add some tests for the case.

Backpatch to 11, where foreign key support was added to partitioned
tables by commit 3de241dba86f.  (A related change is commit f56f8f8da6af
in pg12 which added support for FKs *referencing* partitioned tables;
this is what forces us to use an ad-hoc recursion mechanism for this.)

Diagnosed by Tom Lane from bug report from Ron L Johnson.  As of this
writing, no reviews were offered.

Discussion: https://postgr.es/m/75fe0761-a291-86a9-c8d8-4906da077469@gmail.com
Discussion: https://postgr.es/m/3144850.1607369633@sss.pgh.pa.us

4 years agoDoc: improve and centralize the documentation for OID alias types.
Tom Lane [Wed, 5 May 2021 15:26:48 +0000 (11:26 -0400)]
Doc: improve and centralize the documentation for OID alias types.

Previously, a lot of information about type regclass existed only
in the discussion of the sequence functions.  Maybe that made sense
in the beginning, because I think originally those were the only
functions taking regclass.  But it doesn't make sense anymore.
Move that material to the "Object Identifier Types" section in
datatype.sgml, generalize it to talk about the other reg* types
as well, and add more examples.

Per bug #16991 from Federico Caselli.

Discussion: https://postgr.es/m/16991-bcaeaafa17e0a723@postgresql.org

4 years agoGUC description improvements for clarity
Peter Eisentraut [Wed, 5 May 2021 06:18:22 +0000 (08:18 +0200)]
GUC description improvements for clarity

4 years agoDisable cache clobber to avoid breaking postgres_fdw termination test.
Tom Lane [Tue, 4 May 2021 17:36:26 +0000 (13:36 -0400)]
Disable cache clobber to avoid breaking postgres_fdw termination test.

Commit 93f414614 improved a pre-existing test case so that it would
show whether or not termination of the "remote" worker process happened.
This soon exposed that, when debug_invalidate_system_caches_always
(nee CLOBBER_CACHE_ALWAYS) is enabled, no such termination occurs.
That's because cache invalidation forces postgres_fdw connections
to be dropped at end of transaction, so that there's no worker to
terminate.  There's a race condition as to whether the worker will
manage to get out of the BackendStatusArray before we look, but at
least on buildfarm member hyrax, it's failed twice in two attempts.

Rather than re-lobotomizing the test, let's fix this by transiently
disabling debug_invalidate_system_caches_always.  (Hooray for that
being just a GUC nowadays, rather than a compile-time option.)
If this proves not to be enough to make the test stable, we can
do the other thing instead.

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

4 years agoFix OID passed to object-alter hook during ALTER CONSTRAINT
Alvaro Herrera [Tue, 4 May 2021 14:09:12 +0000 (10:09 -0400)]
Fix OID passed to object-alter hook during ALTER CONSTRAINT

The OID of the constraint is used instead of the OID of the trigger --
an easy mistake to make.  Apparently the object-alter hooks are not very
well tested :-(

Backpatch to 12, where this typo was introduced by 578b229718e8

Discussion: https://postgr.es/m/20210503231633.GA6994@alvherre.pgsql

4 years agodoc: Fix typos
Peter Eisentraut [Tue, 4 May 2021 13:45:13 +0000 (15:45 +0200)]
doc: Fix typos

4 years agopg_dump: Fix dump of generated columns in partitions
Peter Eisentraut [Tue, 4 May 2021 12:03:54 +0000 (14:03 +0200)]
pg_dump: Fix dump of generated columns in partitions

The previous fix for dumping of inherited generated columns
(0bf83648a52df96f7c8677edbbdf141bfa0cf32b) must not be applied to
partitions, since, unlike normal inherited tables, they are always
dumped separately and reattached.

Reported-by: Santosh Udupi <email@hitha.net>
Discussion: https://www.postgresql.org/message-id/flat/CACLRvHZ4a-%2BSM_159%2BtcrHdEqxFrG%3DW4gwTRnwf7Oj0UNj5R2A%40mail.gmail.com

4 years agoFix ALTER TABLE / INHERIT with generated columns
Peter Eisentraut [Tue, 4 May 2021 09:45:37 +0000 (11:45 +0200)]
Fix ALTER TABLE / INHERIT with generated columns

When running ALTER TABLE t2 INHERIT t1, we must check that columns in
t2 that correspond to a generated column in t1 are also generated and
have the same generation expression.  Otherwise, this would allow
creating setups that a normal CREATE TABLE sequence would not allow.

Discussion: https://www.postgresql.org/message-id/22de27f6-7096-8d96-4619-7b882932ca25@2ndquadrant.com

4 years agoRemove mention of the version number from pg_trgm docs
Alexander Korotkov [Tue, 4 May 2021 00:56:16 +0000 (03:56 +0300)]
Remove mention of the version number from pg_trgm docs

We don't usually mention the version number in similar situations.  So, neither
mention it here.

Reported-by: Bruce Momjian
Discussion: https://postgr.es/m/20210503234914.GO6180%40momjian.us

4 years agoUpdate query_id computation
Bruce Momjian [Mon, 3 May 2021 18:59:30 +0000 (14:59 -0400)]
Update query_id computation

Properly fix:

- the "ONLY" in FROM [ONLY] isn't hashed
- the agglevelsup field in GROUPING isn't hashed
- WITH TIES not being hashed (new in PG 13)
- "DISTINCT" in "GROUP BY [DISTINCT]" isn't hashed (new in PG 14)

Reported-by: Julien Rouhaud
Discussion: https://postgr.es/m/20210425081119.ulyzxqz23ueh3wuj@nol

4 years agodoc: Add index entry for "multirange type"
Peter Eisentraut [Mon, 3 May 2021 18:14:03 +0000 (20:14 +0200)]
doc: Add index entry for "multirange type"

Before now, looking up "multirange" in the index only led to the
multirange() function.  To make this more useful, also add an entry
pointing to the range types section.

4 years agoamcheck: Improve some confusing reports about TOAST problems.
Robert Haas [Mon, 3 May 2021 16:32:05 +0000 (12:32 -0400)]
amcheck: Improve some confusing reports about TOAST problems.

Don't phrase reports in terms of the number of tuples thus-far
returned by the index scan, but rather in terms of the chunk_seq
values found inside the tuples.

Patch by me, reviewed by Mark Dilger.

Discussion: http://postgr.es/m/CA+TgmoZUONCkdcdR778EKuE+f1r5Obieu63db2OgMPHaEvEPTQ@mail.gmail.com

4 years agoFix performance issue in new regex match-all detection code.
Tom Lane [Mon, 3 May 2021 15:42:31 +0000 (11:42 -0400)]
Fix performance issue in new regex match-all detection code.

Commit 824bf7190 introduced a new search of the NFAs generated by
regex compilation.  I failed to think hard about the performance
characteristics of that search, with the predictable outcome
that it's bad: weird regexes can trigger exponential search time.
Worse, there's no check-for-interrupt in that code, so you can't
even cancel the query if this happens.

Fix by introducing memo-ization of the search results, so that any one
NFA state need be examined in detail just once.  This potentially uses
a lot of memory, but we can bound the memory usage by putting a limit
on the number of states for which we'll try to prove match-all-ness.
That is sane because we already have a limit (DUPINF) on the maximum
finite string length that a matchall regex can match; and patterns
that involve much more than DUPINF states would probably exceed that
limit anyway.

Also, rearrange the logic so that we check the basic is-the-graph-
all-RAINBOW-arcs property before we start the recursive search to
determine path lengths.  This will ensure that we fall out quickly
whenever the NFA couldn't possibly be matchall.

Also stick in a check-for-interrupt, just in case these measures
don't completely eliminate the risk of slowness.

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

4 years agoPrevent lwlock dtrace probes from unnecessary work
Peter Eisentraut [Mon, 3 May 2021 10:11:33 +0000 (12:11 +0200)]
Prevent lwlock dtrace probes from unnecessary work

If dtrace is compiled in but disabled, the lwlock dtrace probes still
evaluate their arguments.  Since PostgreSQL 13, T_NAME(lock) does
nontrivial work, so it should be avoided if not needed.  To fix, make
these calls conditional on the *_ENABLED() macro corresponding to each
probe.

Reviewed-by: Craig Ringer <craig.ringer@enterprisedb.com>
Discussion: https://www.postgresql.org/message-id/CAGRY4nwxKUS_RvXFW-ugrZBYxPFFM5kjwKT5O+0+Stuga5b4+Q@mail.gmail.com

4 years agoRemove unused function argument
Peter Eisentraut [Mon, 3 May 2021 07:05:58 +0000 (09:05 +0200)]
Remove unused function argument

became unused by 04942bffd0aa9bd0d143d99b473342eb9ecee88b

4 years agolibpq: Refactor some error messages for easier translation
Peter Eisentraut [Mon, 3 May 2021 06:51:30 +0000 (08:51 +0200)]
libpq: Refactor some error messages for easier translation

4 years agoFactor out system call names from error messages
Peter Eisentraut [Mon, 3 May 2021 05:27:31 +0000 (07:27 +0200)]
Factor out system call names from error messages

One more that ought to have been part of
82c3cd974131d7fa1cfcd07cebfb04fffe26ee35.

4 years agoFix the computation of slot stats for 'total_bytes'.
Amit Kapila [Mon, 3 May 2021 01:52:08 +0000 (07:22 +0530)]
Fix the computation of slot stats for 'total_bytes'.

Previously, we were using the size of all the changes present in
ReorderBuffer to compute total_bytes after decoding a transaction and that
can lead to counting some of the transactions' changes more than once. Fix
it by using the size of the changes decoded for a transaction to compute
'total_bytes'.

Author: Sawada Masahiko
Reviewed-by: Vignesh C, Amit Kapila
Discussion: https://postgr.es/m/20210319185247.ldebgpdaxsowiflw@alap3.anarazel.de

4 years agoMake websearch_to_tsquery() parse text in quotes as a single token
Alexander Korotkov [Mon, 3 May 2021 00:58:03 +0000 (03:58 +0300)]
Make websearch_to_tsquery() parse text in quotes as a single token

websearch_to_tsquery() splits text in quotes into tokens and connects them with
phrase operator on its own.  However, that leads to surprising results when the
token contains no words.

For instance, websearch_to_tsquery('"aaa: bbb"') is 'aaa <2> bbb', because
it is equivalent of to_tsquery(E'aaa <-> \':\' <-> bbb').  But
websearch_to_tsquery('"aaa: bbb"') has to be 'aaa <-> bbb' in order to match
to_tsvector('aaa: bbb').

Since 0c4f355c6a, we anyway connect lexemes of complex tokens with phrase
operators.  Thus, let's just websearch_to_tsquery() parse text in quotes as
a single token.  Therefore, websearch_to_tsquery() should process the quoted
text in the same way phraseto_tsquery() does.  This solution is what we exactly
need and also simplifies the code.

This commit is an incompatible change, so we don't backpatch it.

Reported-by: Valentin Gatien-Baron
Discussion: https://postgr.es/m/CA%2B0DEqiZs7gdOd4ikmg%3D0UWG%2BSwWOLxPsk_JW-sx9WNOyrb0KQ%40mail.gmail.com
Author: Alexander Korotkov
Reviewed-by: Tom Lane, Zhihong Yu
4 years agoRevert use singular for -1 (commits 9ee7d533da and 5da9868ed9
Bruce Momjian [Sat, 1 May 2021 14:42:44 +0000 (10:42 -0400)]
Revert use singular for -1 (commits 9ee7d533da and 5da9868ed9

Turns out you can specify negative values using plurals:

https://english.stackexchange.com/questions/9735/is-1-followed-by-a-singular-or-plural-noun

so the previous code was correct enough, and consistent with other usage
in our code.  Also add comment in the two places where this could be
confused.

Reported-by: Noah Misch
Diagnosed-by: 20210425115726.GA2353095@rfd.leadboat.com
4 years agoDoc: add an example of a self-referential foreign key to ddl.sgml.
Tom Lane [Fri, 30 Apr 2021 19:37:56 +0000 (15:37 -0400)]
Doc: add an example of a self-referential foreign key to ddl.sgml.

While we've always allowed such cases, the documentation didn't
say you could do it.

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

4 years agoDoc: update libpq's documentation for PQfn().
Tom Lane [Fri, 30 Apr 2021 19:10:06 +0000 (15:10 -0400)]
Doc: update libpq's documentation for PQfn().

Mention specifically that you can't call aggregates, window functions,
or procedures this way (the inability to call SRFs was already
mentioned).

Also, the claim that PQfn doesn't support NULL arguments or results
has been a lie since we invented protocol 3.0.  Not sure why this
text was never updated for that, but do it now.

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

4 years agoDisallow calling anything but plain functions via the fastpath API.
Tom Lane [Fri, 30 Apr 2021 18:10:26 +0000 (14:10 -0400)]
Disallow calling anything but plain functions via the fastpath API.

Reject aggregates, window functions, and procedures.  Aggregates
failed anyway, though with a somewhat obscure error message.
Window functions would hit an Assert or null-pointer dereference.
Procedures seemed to work as long as you didn't try to do
transaction control, but (a) transaction control is sort of the
point of a procedure, and (b) it's not entirely clear that no
bugs lurk in that path.  Given the lack of testing of this area,
it seems safest to be conservative in what we support.

Also reject proretset functions, as the fastpath protocol can't
support returning a set.

Also remove an easily-triggered assertion that the given OID
isn't 0; the subsequent lookups can handle that case themselves.

Per report from Theodor-Arsenij Larionov-Trichkin.
Back-patch to all supported branches.  (The procedure angle
only applies in v11+, of course.)

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

4 years agoFix the bugs in selecting the transaction for streaming.
Amit Kapila [Fri, 30 Apr 2021 05:19:52 +0000 (10:49 +0530)]
Fix the bugs in selecting the transaction for streaming.

There were two problems:
a. We were always selecting the next available txn instead of selecting it
when it is larger than the previous transaction.
b. We were selecting the transactions which haven't made any changes to
the database (base snapshot is not set). Later it was hitting an Assert
because we don't decode such transactions and the changes in txn remain as
it is. It is better not to choose such transactions for streaming in the
first place.

Reported-by: Haiying Tang
Author: Dilip Kumar
Reviewed-by: Amit Kapila
Discussion: https://postgr.es/m/OS0PR01MB61133B94E63177040F7ECDA1FB429@OS0PR01MB6113.jpnprd01.prod.outlook.com

4 years agoAdjust EXPLAIN output for parallel Result Cache plans
David Rowley [Fri, 30 Apr 2021 02:46:42 +0000 (14:46 +1200)]
Adjust EXPLAIN output for parallel Result Cache plans

Here we adjust the EXPLAIN ANALYZE output for Result Cache so that we
don't show any Result Cache stats for parallel workers who don't
contribute anything to Result Cache plan nodes.

I originally had ideas that workers who don't help could still have their
Result Cache stats displayed.  The idea with that was so that I could
write some parallel Result Cache regression tests that show the EXPLAIN
ANALYZE output.  However, I realized a little too late that such tests
would just not be possible to have run in a stable way on the buildfarm.

With that knowledge, before 9eacee2e6 went in, I had removed all of the
tests that were showing the EXPLAIN ANALYZE output of a parallel Result
Cache plan, however, I forgot to put back the code that adjusts the
EXPLAIN output to hide the Result Cache stats for parallel workers who
were not fast enough to help out before query execution was over. All
other nodes behave this way and so should Result Cache.

Additionally, with this change, it now seems safe enough to remove the SET
force_parallel_mode = off that I had added to the regression tests.

Also, perform some cleanup in the partition_prune tests. I had adjusted
the explain_parallel_append() function to sanitize the Result Cache
EXPLAIN ANALYZE output.  However, since I didn't actually include any
parallel Result Cache tests that show their EXPLAIN ANALYZE output, that
code does nothing and can be removed.

In passing, move the setting of memPeakKb into the scope where it's used.

Reported-by: Amit Khandekar
Author: David Rowley, Amit Khandekar
Discussion: https://postgr.es/m/CAJ3gD9d8SkfY95GpM1zmsOtX2-Ogx5q-WLsf8f0ykEb0hCRK3w@mail.gmail.com

4 years agoAnother try to fix the test case added by commit f5fc2f5b23.
Amit Kapila [Fri, 30 Apr 2021 02:25:42 +0000 (07:55 +0530)]
Another try to fix the test case added by commit f5fc2f5b23.

As per analysis, it appears that the 'drop slot' message from the previous
test and 'create slot' message of the new test are either missed or not
yet delivered to the stats collector due to which we will still see the
stats from the old slot. This can happen rarely which could be the reason
that we are seeing some failures in the buildfarm randomly. To avoid that
we are using a different slot name for the tests in
test_decoding/sql/stats.sql.

Reported-by: Tom Lane based on buildfarm reports
Author: Sawada Masahiko
Reviewed-by: Amit Kapila, Vignesh C
Discussion: https://postgr.es/m/20210319185247.ldebgpdaxsowiflw@alap3.anarazel.de

4 years agoImprove wording of some pg_upgrade failure reports.
Tom Lane [Thu, 29 Apr 2021 19:40:34 +0000 (15:40 -0400)]
Improve wording of some pg_upgrade failure reports.

Don't advocate dropping a whole table when dropping a column would
serve.  While at it, try to make the layout of these messages a
bit cleaner and more consistent.

Per suggestion from Daniel Gustafsson.  No back-patch, as we generally
don't like to churn translatable messages in released branches.

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

4 years agoFix some more omissions in pg_upgrade's tests for non-upgradable types.
Tom Lane [Thu, 29 Apr 2021 19:24:37 +0000 (15:24 -0400)]
Fix some more omissions in pg_upgrade's tests for non-upgradable types.

Commits 29aeda6e4 et al closed up some oversights involving not checking
for non-upgradable types within container types, such as arrays and
ranges.  However, I only looked at version.c, failing to notice that
there were substantially-equivalent tests in check.c.  (The division
of responsibility between those files is less than clear...)

In addition, because genbki.pl does not guarantee that auto-generated
rowtype OIDs will hold still across versions, we need to consider that
the composite type associated with a system catalog or view is
non-upgradable.  It seems unlikely that someone would have a user
column declared that way, but if they did, trying to read it in another
PG version would likely draw "no such pg_type OID" failures, thanks
to the type OID embedded in composite Datums.

To support the composite and reg*-type cases, extend the recursive
query that does the search to allow any base query that returns
a column of pg_type OIDs, rather than limiting it to exactly one
starting type.

As before, back-patch to all supported branches.

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

4 years agoImprove documentation for default_tablespace on partitioned tables
Alvaro Herrera [Thu, 29 Apr 2021 15:31:24 +0000 (11:31 -0400)]
Improve documentation for default_tablespace on partitioned tables

Backpatch to 12, where 87259588d0ab introduced the current behavior.

Per note from Justin Pryzby.

Co-authored-by: Justin Pryzby <pryzby@telsasoft.com>
Discussion: https://postgr.es/m/20210416143135.GI3315@telsasoft.com

4 years agopsql: Fix line continuation prompts for unbalanced parentheses
Peter Eisentraut [Thu, 29 Apr 2021 07:04:31 +0000 (09:04 +0200)]
psql: Fix line continuation prompts for unbalanced parentheses

This was broken by a silly mistake in
e717a9a18b2e34c9c40e5259ad4d31cd7e420750.

Reported-by: Jeff Janes <jeff.janes@gmail.com>
Author: Justin Pryzby <pryzby@telsasoft.com>
Discussion: https://www.postgresql.org/message-id/CAMkU=1zKGWEJdBbYKw7Tn7cJmYR_UjgdcXTPDqJj=dNwCETBCQ@mail.gmail.com

4 years agopg_hba.conf.sample: Reword connection type section
Peter Eisentraut [Thu, 29 Apr 2021 04:51:42 +0000 (06:51 +0200)]
pg_hba.conf.sample: Reword connection type section

Improve the wording in the connection type section of
pg_hba.conf.sample a bit.  After the hostgssenc part was added on, the
whole thing became a bit wordy, and it's also a bit inaccurate for
example in that the current wording for "host" appears to say that it
does not apply to GSS-encrypted connections.

Discussion: https://www.postgresql.org/message-id/flat/fc06dcc5-513f-e944-cd07-ba51dd7c6916%40enterprisedb.com

4 years agodoc: Fix description of target_session_attrs=prefer-standby
Michael Paquier [Thu, 29 Apr 2021 02:44:24 +0000 (11:44 +0900)]
doc: Fix description of target_session_attrs=prefer-standby

If no standbys can be found in the set of connection points provided,
the fallback behavior is "any", and not "all" that does not exist.

Author: Greg Nancarrow
Reviewed-by: Laurenz Albe
Discussion: https://postgr.es/m/CAJcOf-fDaCv8qCpWH7k5Yh6zFxZeUwZowu4sCWQ2zFx4CdkHpA@mail.gmail.com

4 years agoAdd heuristic incoming-message-size limits in the server.
Tom Lane [Wed, 28 Apr 2021 19:50:42 +0000 (15:50 -0400)]
Add heuristic incoming-message-size limits in the server.

We had a report of confusing server behavior caused by a client bug
that sent junk to the server: the server thought the junk was a
very long message length and waited patiently for data that would
never come.  We can reduce the risk of that by being less trusting
about message lengths.

For a long time, libpq has had a heuristic rule that it wouldn't
believe large message size words, except for a small number of
message types that are expected to be (potentially) long.  This
provides some defense against loss of message-boundary sync and
other corrupted-data cases.  The server does something similar,
except that up to now it only limited the lengths of messages
received during the connection authentication phase.  Let's
do the same as in libpq and put restrictions on the allowed
length of all messages, while distinguishing between message
types that are expected to be long and those that aren't.

I used a limit of 10000 bytes for non-long messages.  (libpq's
corresponding limit is 30000 bytes, but given the asymmetry of
the FE/BE protocol, there's no good reason why the numbers should
be the same.)  Experimentation suggests that this is at least a
factor of 10, maybe a factor of 100, more than we really need;
but plenty of daylight seems desirable to avoid false positives.
In any case we can adjust the limit based on beta-test results.

For long messages, set a limit of MaxAllocSize - 1, which is the
most that we can absorb into the StringInfo buffer that the message
is collected in.  This just serves to make sure that a bogus message
size is reported as such, rather than as a confusing gripe about
not being able to enlarge a string buffer.

While at it, make sure that non-mainline code paths (such as
COPY FROM STDIN) are as paranoid as SocketBackend is, and validate
the message type code before believing the message length.
This provides an additional guard against getting stuck on corrupted
input.

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

4 years agoAllow a partdesc-omitting-partitions to be cached
Alvaro Herrera [Wed, 28 Apr 2021 19:44:35 +0000 (15:44 -0400)]
Allow a partdesc-omitting-partitions to be cached

Makes partition descriptor acquisition faster during the transient
period in which a partition is in the process of being detached.

This also adds the restriction that only one partition can be in
pending-detach state for a partitioned table.

While at it, return find_inheritance_children() API to what it was
before 71f4c8c6f74b, and create a separate
find_inheritance_children_extended() that returns detailed info about
detached partitions.

(This incidentally fixes a bug in 8aba9322511 whereby a memory context
holding a transient partdesc is reparented to a NULL PortalContext,
leading to permanent leak of that memory.  The fix is to no longer rely
on reparenting contexts to PortalContext.   Reported by Amit Langote.)

Per gripe from Amit Langote
Discussion: https://postgr.es/m/CA+HiwqFgpP1LxJZOBYGt9rpvTjXXkg5qG2+Xch2Z1Q7KrqZR1A@mail.gmail.com

4 years agoDoc: fix discussion of how to get real Julian Dates.
Tom Lane [Wed, 28 Apr 2021 14:03:28 +0000 (10:03 -0400)]
Doc: fix discussion of how to get real Julian Dates.

Somehow I'd convinced myself that rotating to UTC-12 was the way
to do this, but upon further review, it's definitely UTC+12.

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

4 years agoFix use-after-release issue with pg_identify_object_as_address()
Michael Paquier [Wed, 28 Apr 2021 02:58:08 +0000 (11:58 +0900)]
Fix use-after-release issue with pg_identify_object_as_address()

Spotted by buildfarm member prion, with -DRELCACHE_FORCE_RELEASE.

Introduced in f7aab36.

Discussion: https://postgr.es/m/2759018.1619577848@sss.pgh.pa.us
Backpatch-through: 9.6

4 years agoFix pg_identify_object_as_address() with event triggers
Michael Paquier [Wed, 28 Apr 2021 02:17:58 +0000 (11:17 +0900)]
Fix pg_identify_object_as_address() with event triggers

Attempting to use this function with event triggers failed, as, since
its introduction in a676201, this code has never associated an object
name with event triggers.  This addresses the failure by adding the
event trigger name to the set defining its object address.

Note that regression tests are added within event_trigger and not
object_address to avoid issues with concurrent connections in parallel
schedules.

Author: Joel Jacobson
Discussion: https://postgr.es/m/3c905e77-a026-46ae-8835-c3f6cd1d24c8@www.fastmail.com
Backpatch-through: 9.6

4 years agoImprove logic in PostgresVersion.pm
Andrew Dunstan [Tue, 27 Apr 2021 12:21:15 +0000 (08:21 -0400)]
Improve logic in PostgresVersion.pm

Handle the situation where perl swaps the order of operands of
the comparison operator. See `perldoc overload` for details:

The third argument is set to TRUE if (and only if) the two
operands have been swapped. Perl may do this to ensure that the
first argument ($self) is an object implementing the overloaded
operation, in line with general object calling conventions.

4 years agodoc: Review for "Allow TRUNCATE command to truncate foreign tables".
Fujii Masao [Tue, 27 Apr 2021 09:39:30 +0000 (18:39 +0900)]
doc: Review for "Allow TRUNCATE command to truncate foreign tables".

Typos, corrections and language improvements in the docs.

Author: Justin Pryzby, Fujii Masao
Reviewed-by: Bharath Rupireddy, Justin Pryzby, Fujii Masao
Discussion: https://postgr.es/m/20210411041658.GB14564@telsasoft.com

4 years agoDon't pass "ONLY" options specified in TRUNCATE to foreign data wrapper.
Fujii Masao [Tue, 27 Apr 2021 05:41:27 +0000 (14:41 +0900)]
Don't pass "ONLY" options specified in TRUNCATE to foreign data wrapper.

Commit 8ff1c94649 allowed TRUNCATE command to truncate foreign tables.
Previously the information about "ONLY" options specified in TRUNCATE
command were passed to the foreign data wrapper. Then postgres_fdw
constructed the TRUNCATE command to issue the remote server and
included "ONLY" options in it based on the passed information.

On the other hand, "ONLY" options specified in SELECT, UPDATE or DELETE
have no effect when accessing or modifying the remote table, i.e.,
are not passed to the foreign data wrapper. So it's inconsistent to
make only TRUNCATE command pass the "ONLY" options to the foreign data
wrapper. Therefore this commit changes the TRUNCATE command so that
it doesn't pass the "ONLY" options to the foreign data wrapper,
for the consistency with other statements. Also this commit changes
postgres_fdw so that it always doesn't include "ONLY" options in
the TRUNCATE command that it constructs.

Author: Fujii Masao
Reviewed-by: Bharath Rupireddy, Kyotaro Horiguchi, Justin Pryzby, Zhihong Yu
Discussion: https://postgr.es/m/551ed8c1-f531-818b-664a-2cecdab99cd8@oss.nttdata.com

4 years agoUse HTAB for replication slot statistics.
Amit Kapila [Tue, 27 Apr 2021 03:39:11 +0000 (09:09 +0530)]
Use HTAB for replication slot statistics.

Previously, we used to use the array of size max_replication_slots to
store stats for replication slots. But that had two problems in the cases
where a message for dropping a slot gets lost: 1) the stats for the new
slot are not recorded if the array is full and 2) writing beyond the end
of the array if the user reduces the max_replication_slots.

This commit uses HTAB for replication slot statistics, resolving both
problems. Now, pgstat_vacuum_stat() search for all the dead replication
slots in stats hashtable and tell the collector to remove them. To avoid
showing the stats for the already-dropped slots, pg_stat_replication_slots
view searches slot stats by the slot name taken from pg_replication_slots.

Also, we send a message for creating a slot at slot creation, initializing
the stats. This reduces the possibility that the stats are accumulated
into the old slot stats when a message for dropping a slot gets lost.

Reported-by: Andres Freund
Author: Sawada Masahiko, test case by Vignesh C
Reviewed-by: Amit Kapila, Vignesh C, Dilip Kumar
Discussion: https://postgr.es/m/20210319185247.ldebgpdaxsowiflw@alap3.anarazel.de

4 years agoFix Logical Replication of Truncate in synchronous commit mode.
Amit Kapila [Tue, 27 Apr 2021 02:58:26 +0000 (08:28 +0530)]
Fix Logical Replication of Truncate in synchronous commit mode.

The Truncate operation acquires an exclusive lock on the target relation
and indexes. It then waits for logical replication of the operation to
finish at commit. Now because we are acquiring the shared lock on the
target index to get index attributes in pgoutput while sending the
changes for the Truncate operation, it leads to a deadlock.

Actually, we don't need to acquire a lock on the target index as we build
the cache entry using a historic snapshot and all the later changes are
absorbed while decoding WAL. So, we wrote a special purpose function for
logical replication to get a bitmap of replica identity attribute numbers
where we get that information without locking the target index.

We decided not to backpatch this as there doesn't seem to be any field
complaint about this issue since it was introduced in commit 5dfd1e5a in
v11.

Reported-by: Haiying Tang
Author: Takamichi Osumi, test case by Li Japin
Reviewed-by: Amit Kapila, Ajin Cherian
Discussion: https://postgr.es/m/OS0PR01MB6113C2499C7DC70EE55ADB82FB759@OS0PR01MB6113.jpnprd01.prod.outlook.com

4 years agopsql: tab-complete ALTER ... DETACH CONCURRENTLY / FINALIZE
Alvaro Herrera [Thu, 22 Apr 2021 20:37:46 +0000 (16:37 -0400)]
psql: tab-complete ALTER ... DETACH CONCURRENTLY / FINALIZE

New keywords per 71f4c8c6f74b.

Discussion: https://postgr.es/m/20210422204035.GA25929@alvherre.pgsql

4 years agoRemove rewriteTargetListIU's expansion of view targetlists in UPDATE.
Tom Lane [Mon, 26 Apr 2021 17:58:00 +0000 (13:58 -0400)]
Remove rewriteTargetListIU's expansion of view targetlists in UPDATE.

Commit 2ec993a7c, which added triggers on views, modified the rewriter
to add dummy entries like "SET x = x" for all columns that weren't
actually being updated by the user in any UPDATE directed at a view.
That was needed at the time to produce a complete "NEW" row to pass
to the trigger.  Later it was found to cause problems for ordinary
updatable views, so commit cab5dc5da restricted it to happen only for
trigger-updatable views.  But in the wake of commit 86dc90056, we
really don't need it at all.  nodeModifyTable.c populates the trigger
"OLD" row from the whole-row variable that is generated for the view,
and then it computes the "NEW" row using that old row and the UPDATE
targetlist.  So there is no need for the UPDATE tlist to have dummy
entries, any more than it needs them for regular tables or other
types of views.

(The comments for rewriteTargetListIU suggest that we must do this
for correct expansion of NEW references in rules, but I now think
that that was just lazy comment editing in 2ec993a7c.  If we didn't
need it for rules on views before there were triggers, we don't need
it after that.)

This essentially propagates 86dc90056's decision that we don't need
dummy column updates into the view case.  Aside from making the
different cases more uniform and hence possibly forestalling future
bugs, it ought to save a little bit of rewriter/planner effort.

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

4 years agoDoc: document EXTRACT(JULIAN ...), improve Julian Date explanation.
Tom Lane [Mon, 26 Apr 2021 15:50:35 +0000 (11:50 -0400)]
Doc: document EXTRACT(JULIAN ...), improve Julian Date explanation.

For some reason, the "julian" option for extract()/date_part() has
never gotten listed in the manual.  Also, while Appendix B mentioned
in passing that we don't conform to the usual astronomical definition
that a Julian date starts at noon UTC, it was kind of vague about what
we do instead.  Clarify that, and add an example showing how to get
the astronomical definition if you want it.

It's been like this for ages, so back-patch to all supported branches.

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

4 years agoFix pg_upgrade test on Cygwin
Peter Eisentraut [Mon, 26 Apr 2021 10:10:46 +0000 (12:10 +0200)]
Fix pg_upgrade test on Cygwin

The verification of permissions doesn't succeed on Cygwin, because the
required feature is not implemented for Cygwin at the moment.  So skip
this part of the test, like MinGW already does.

4 years agoAdd more tests with triggers on partitions for logical replication
Michael Paquier [Mon, 26 Apr 2021 06:22:48 +0000 (15:22 +0900)]
Add more tests with triggers on partitions for logical replication

The tuple routing logic used by a logical replication worker can fire
triggers on relations part of a partition tree, but there was no test
coverage in this area.  The existing script 003_constraints.pl included
something, but nothing when a tuple is applied across partitioned tables
on a subscriber.

Author: Amit Langote
Discussion: https://postgr.es/m/OS0PR01MB611383FA0FE92EB9DE21946AFB769@OS0PR01MB6113.jpnprd01.prod.outlook.com

4 years agoAvoid sending prepare multiple times while decoding.
Amit Kapila [Mon, 26 Apr 2021 05:57:44 +0000 (11:27 +0530)]
Avoid sending prepare multiple times while decoding.

We send the prepare for the concurrently aborted xacts so that later when
rollback prepared is decoded and sent, the downstream should be able to
rollback such a xact. For 'streaming' case (when we send changes for
in-progress transactions), we were sending prepare twice when concurrent
abort was detected.

Author: Peter Smith
Reviewed-by: Amit Kapila
Discussion: https://postgr.es/m/f82133c6-6055-b400-7922-97dae9f2b50b@enterprisedb.com

4 years agoRemove unused function argument
Peter Eisentraut [Mon, 26 Apr 2021 05:05:21 +0000 (07:05 +0200)]
Remove unused function argument

This was already unused in the initial commit
257836a75585934cc05ed7a80bccf8190d41e056.  Apparently, it was used in
an earlier proposed patch version.

4 years agoFix typo in reorderbuffer.c.
Amit Kapila [Mon, 26 Apr 2021 03:12:46 +0000 (08:42 +0530)]
Fix typo in reorderbuffer.c.

Author: Peter Smith
Discussion: https://postgr.es/m/CAHut+PtvzuYY0zu=dVRK_WVz5WGos1+otZWgEWqjha1ncoSRag@mail.gmail.com

4 years agoUpdate comments for rewriteTargetListIU().
Tom Lane [Sun, 25 Apr 2021 22:02:03 +0000 (18:02 -0400)]
Update comments for rewriteTargetListIU().

This function's behavior for UPDATE on a trigger-updatable view was
justified by analogy to what preptlist.c used to do for UPDATE on
regular tables.  Since preptlist.c hasn't done that since 86dc90056,
that argument is no longer sensible, let alone convincing.  I think
we do still need it to act that way, so update the comment to explain
why.

4 years agoMake a test endure log_error_verbosity=verbose.
Noah Misch [Sun, 25 Apr 2021 08:08:05 +0000 (01:08 -0700)]
Make a test endure log_error_verbosity=verbose.

4 years agoProvide pg_amcheck with an --install-missing option
Andrew Dunstan [Sat, 24 Apr 2021 14:13:07 +0000 (10:13 -0400)]
Provide pg_amcheck with an --install-missing option

This will install amcheck in the database if not present. The default
schema is for the extension is pg_catalog, but this can be overridden by
providing a value for the option.

Mark Dilger, slightly editorialized by me.

(rather divergent)
Discussion: https://postgr.es/m/bdc0f7c2-09e3-ee57-8471-569dfb509234@dunslane.net

4 years agoTeach PostgresVersion all the ways to mark non-release code
Andrew Dunstan [Sat, 24 Apr 2021 13:37:20 +0000 (09:37 -0400)]
Teach PostgresVersion all the ways to mark non-release code

As well as 'devel' version_stamp.pl provides for 'alphaN'
'betaN' and 'rcN', so teach PostgresVersion about those.

Also stash the version string instead of trying to reconstruct it during
stringification.

Discussion: https://postgr.es/m/YIHlw5nSgAHs4dK1@paquier.xyz

4 years agoFix come comments in execMain.c
Michael Paquier [Sat, 24 Apr 2021 06:07:04 +0000 (15:07 +0900)]
Fix come comments in execMain.c

1375422 has refactored this area of the executor code, and some comments
went out-of-sync.

Author: Yukun Wang
Reviewed-by: Amul Sul
Discussion: https://postgr.es/m/OS0PR01MB60033394FCAEF79B98F078F5B4459@OS0PR01MB6003.jpnprd01.prod.outlook.com

4 years agoDoc: Remove extraneous whitespaces with some tags
Michael Paquier [Sat, 24 Apr 2021 01:44:13 +0000 (10:44 +0900)]
Doc: Remove extraneous whitespaces with some tags

Author: Justin Pryzby
Discussion: https://postgr.es/m/20210423184338.GL7256@telsasoft.com

4 years agoAdd some forgotten LSN_FORMAT_ARGS() in xlogreader.c
Michael Paquier [Sat, 24 Apr 2021 00:09:02 +0000 (09:09 +0900)]
Add some forgotten LSN_FORMAT_ARGS() in xlogreader.c

6f6f284 has introduced a specific macro to make printf()-ing of LSNs
easier.  This takes care of what looks like the remaining code paths
that did not get the call.

Author: Michael Paquier
Reviewed-by: Kyotaro Horiguchi, Tom Lane
Discussion: https://postgr.es/m/YIJS9x6K8ruizN7j@paquier.xyz

4 years agoamcheck: MAXALIGN() nbtree special area offset.
Peter Geoghegan [Fri, 23 Apr 2021 22:37:03 +0000 (15:37 -0700)]
amcheck:  MAXALIGN() nbtree special area offset.

This isn't strictly necessary, but in theory it might matter if in the
future the width of the nbtree special area changes -- its total size
might not be an even number of MAXALIGN() quantums, even with padding.
PageInit() MAXALIGN()s all special area offsets, but amcheck uses the
offset to perform initial basic validation of line pointers, so we don't
rely on the offset from the page header.

The real reason to do this is to set a good example for new code that
adds amcheck coverage for other index AMs.

Reported-By: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Discussion: https://postgr.es/m/CALj2ACUMqTR9nErh99FbOBmzCXE9=gXNqhBiwYOhejJJS1LXqQ@mail.gmail.com

4 years agoFactor out system call names from error messages
Peter Eisentraut [Fri, 23 Apr 2021 12:18:11 +0000 (14:18 +0200)]
Factor out system call names from error messages

Instead, put them in via a format placeholder.  This reduces the
number of distinct translatable messages and also reduces the chances
of typos during translation.  We already did this for the system call
arguments in a number of cases, so this is just the same thing taken a
bit further.

Discussion: https://www.postgresql.org/message-id/flat/92d6f545-5102-65d8-3c87-489f71ea0a37%40enterprisedb.com

4 years agoUse correct format placeholder for WSAGetLastError()
Peter Eisentraut [Fri, 23 Apr 2021 11:27:01 +0000 (13:27 +0200)]
Use correct format placeholder for WSAGetLastError()

Some code thought this was unsigned, but it's signed int.

4 years agoMark multirange_constructor0() and multirange_constructor2() strict
Alexander Korotkov [Fri, 23 Apr 2021 09:57:33 +0000 (12:57 +0300)]
Mark multirange_constructor0() and multirange_constructor2() strict

These functions shouldn't receive null arguments: multirange_constructor0()
doesn't have any arguments while multirange_constructor2() has a single array
argument, which is never null.

But mark them strict anyway for the sake of uniformity.

Also, make checks for null arguments use elog() instead of ereport() as these
errors should normally be never thrown.  And adjust corresponding comments.

Catversion is bumped.

Reported-by: Peter Eisentraut
Discussion: https://postgr.es/m/0f783a96-8d67-9e71-996b-f34a7352eeef%40enterprisedb.com

4 years agoReorder COMPRESSION option in gram.y and parsenodes.h into alphabetical order.
Fujii Masao [Fri, 23 Apr 2021 10:10:24 +0000 (19:10 +0900)]
Reorder COMPRESSION option in gram.y and parsenodes.h into alphabetical order.

Commit bbe0a81db6 introduced "INCLUDING COMPRESSION" option
in CREATE TABLE command, but previously TableLikeOption in gram.y and
parsenodes.h didn't classify this new option in alphabetical order
with the rest.

Author: Fujii Masao
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/YHerAixOhfR1ryXa@paquier.xyz

4 years agoMention that toplevel is part of pg_stat_statements key.
Magnus Hagander [Fri, 23 Apr 2021 09:41:36 +0000 (11:41 +0200)]
Mention that toplevel is part of pg_stat_statements key.

While at it, also document that toplevel is always true if
pg_stat_statements.track is set to top.

Author: Julien Rouhaud
Reported-By: Fujii Masao
Discussion: https://postgr.es/m/a878d5ea-64a7-485e-5d2f-177618ebc52d@oss.nttdata.com

4 years agopg_amcheck: Use logging functions
Peter Eisentraut [Fri, 23 Apr 2021 07:55:23 +0000 (09:55 +0200)]
pg_amcheck: Use logging functions

This was already mostly done, but some error messages were printed the
long way.

4 years agodoc: Fix typos
Peter Eisentraut [Fri, 23 Apr 2021 07:28:44 +0000 (09:28 +0200)]
doc: Fix typos

Author: Justin Pryzby <pryzby@telsasoft.com>

4 years agodoc: Fix obsolete description about pg_basebackup.
Fujii Masao [Fri, 23 Apr 2021 06:45:46 +0000 (15:45 +0900)]
doc: Fix obsolete description about pg_basebackup.

Previously it was documented that if using "-X none" option there was
no guarantee that all required WAL files were archived at the end of
pg_basebackup when taking a backup from the standby. But this limitation
was removed by commit 52f8a59dd9. Now, even when taking a backup
from the standby, pg_basebackup can wait for all required WAL files
to be archived. Therefore this commit removes such obsolete
description from the docs.

Also this commit adds new description about the limitation when
taking a backup from the standby, into the docs. The limitation is that
pg_basebackup cannot force the standbfy to switch to a new WAL file
at the end of backup, which may cause pg_basebackup to wait a long
time for the last required WAL file to be switched and archived,
especially when write activity on the primary is low.

Back-patch to v10 where the issue was introduced.

Reported-by: Kyotaro Horiguchi
Author: Kyotaro Horiguchi, Fujii Masao
Reviewed-by: Kyotaro Horiguchi, Fujii Masao
Discussion: https://postgr.es/m/20210420.133235.1342729068750553399.horikyota.ntt@gmail.com

4 years agoFix incorrect format placeholder
Peter Eisentraut [Fri, 23 Apr 2021 05:21:13 +0000 (07:21 +0200)]
Fix incorrect format placeholder

4 years agoFix some comments in fmgr.c
Michael Paquier [Fri, 23 Apr 2021 04:34:02 +0000 (13:34 +0900)]
Fix some comments in fmgr.c

Oversight in 2a0faed.

Author: Hou Zhijie
Discussion: https://postgr.es/m/OS0PR01MB5716405E2464D85E6DB6DC0794469@OS0PR01MB5716.jpnprd01.prod.outlook.com

4 years agoRemove use of [U]INT64_FORMAT in some translatable strings
Michael Paquier [Fri, 23 Apr 2021 04:25:49 +0000 (13:25 +0900)]
Remove use of [U]INT64_FORMAT in some translatable strings

%lld with (long long), or %llu with (unsigned long long) are more
adapted.  This is similar to 3286065.

Author: Kyotaro Horiguchi
Discussion: https://postgr.es/m/20210421.200000.1462448394029407895.horikyota.ntt@gmail.com

4 years agoMinor code cleanup in asynchronous execution support.
Etsuro Fujita [Fri, 23 Apr 2021 03:00:00 +0000 (12:00 +0900)]
Minor code cleanup in asynchronous execution support.

This is cleanup for commit 27e1f1456:

* ExecAppendAsyncEventWait(), which was modified a bit further by commit
  a8af856d3, duplicated the same nevents calculation.  Simplify the code
  a little bit to avoid the duplication.  Update comments there.
* Add an assertion to ExecAppendAsyncRequest().
* Update a comment about merging the async_capable options from input
  relations in merge_fdw_options(), per complaint from Kyotaro Horiguchi.
* Add a comment for fetch_more_data_begin().

Author: Etsuro Fujita
Discussion: https://postgr.es/m/CAPmGK1637W30Wx3MnrReewhafn6F_0J76mrJGoFXFnpPq4QfvA%40mail.gmail.com

4 years agoDon't crash on reference to an un-available system column.
Tom Lane [Thu, 22 Apr 2021 21:30:42 +0000 (17:30 -0400)]
Don't crash on reference to an un-available system column.

Adopt a more consistent policy about what slot-type-specific
getsysattr functions should do when system attributes are not
available.  To wit, they should all throw the same user-oriented
error, rather than variously crashing or emitting developer-oriented
messages.

This closes a identifiable problem in commits a71cfc56b and
3fb93103a (in v13 and v12), so back-patch into those branches,
along with a test case to try to ensure we don't break it again.
It is not known that any of the former crash cases are reachable
in HEAD, but this seems like a good safety improvement in any case.

Discussion: https://postgr.es/m/141051591267657@mail.yandex.ru

4 years agoFix some trailing whitespace in documentation files
Peter Eisentraut [Thu, 22 Apr 2021 20:47:57 +0000 (22:47 +0200)]
Fix some trailing whitespace in documentation files

4 years agoFix uninitialized memory bug
Alvaro Herrera [Thu, 22 Apr 2021 20:04:48 +0000 (16:04 -0400)]
Fix uninitialized memory bug

Have interested callers of find_inheritance_children set the
detached_exist value to false prior to calling it, so that that routine
only has to set it true in the rare cases where it is necessary.  Don't
touch it otherwise.

Per buildfarm member thorntail (which reported a UBSan failure here).

4 years agodoc: mention <link> can be inside of <command>, but not <xref>
Bruce Momjian [Thu, 22 Apr 2021 20:01:17 +0000 (16:01 -0400)]
doc:  mention <link> can be inside of <command>, but not <xref>

This was discussed in commit 9081bddbd.

Reported-by: Peter Eisentraut
Discussion: https://postgr.es/m/flat/87o8pco34z.fsf@wibble.ilmari.org

4 years agoMake PostgresVersion code a bit more robust and simple.
Andrew Dunstan [Thu, 22 Apr 2021 19:25:37 +0000 (15:25 -0400)]
Make PostgresVersion code a bit more robust and simple.

per gripe from Alvaro Herrera.

4 years agoFix relcache inconsistency hazard in partition detach
Alvaro Herrera [Thu, 22 Apr 2021 19:13:25 +0000 (15:13 -0400)]
Fix relcache inconsistency hazard in partition detach

During queries coming from ri_triggers.c, we need to omit partitions
that are marked pending detach -- otherwise, the RI query is tricked
into allowing a row into the referencing table whose corresponding row
is in the detached partition.  Which is bogus: once the detach operation
completes, the row becomes an orphan.

However, the code was not doing that in repeatable-read transactions,
because relcache kept a copy of the partition descriptor that included
the partition, and used it in the RI query.  This commit changes the
partdesc cache code to only keep descriptors that aren't dependent on
a snapshot (namely: those where no detached partition exist, and those
where detached partitions are included).  When a partdesc-without-
detached-partitions is requested, we create one afresh each time; also,
those partdescs are stored in PortalContext instead of
CacheMemoryContext.

find_inheritance_children gets a new output *detached_exist boolean,
which indicates whether any partition marked pending-detach is found.
Its "include_detached" input flag is changed to "omit_detached", because
that name captures desired the semantics more naturally.
CreatePartitionDirectory() and RelationGetPartitionDesc() arguments are
identically renamed.

This was noticed because a buildfarm member that runs with relcache
clobbering, which would not keep the improperly cached partdesc, broke
one test, which led us to realize that the expected output of that test
was bogus.  This commit also corrects that expected output.

Author: Amit Langote <amitlangote09@gmail.com>
Author: Álvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://postgr.es/m/3269784.1617215412@sss.pgh.pa.us

4 years agoDoc: document the tie-breaking behavior of the round() function.
Tom Lane [Thu, 22 Apr 2021 18:47:26 +0000 (14:47 -0400)]
Doc: document the tie-breaking behavior of the round() function.

Back-patch to v13; the table layout in older branches is unfriendly
to adding such details.

Laurenz Albe

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

4 years agoMake PostgresNode version aware
Andrew Dunstan [Thu, 22 Apr 2021 14:56:28 +0000 (10:56 -0400)]
Make PostgresNode version aware

A new PostgresVersion object type is created and this is used in
PostgresNode using the output of `pg_config --version` and the result
stored in the PostgresNode object.  This object can be compared to other
PostgresVersion objects, or to a number or string.

PostgresNode is currently believed to be compatible with versions down
to release 12, so PostgresNode will issue a warning if used with a
version prior to that.

No attempt has been made to deal with incompatibilities in older
versions - that remains work to be undertaken in a subsequent
development cycle.

Based on code from Mark Dilger and Jehan-Guillaume de Rorthais.

Discussion: https://postgr.es/m/a80421c0-3d7e-def1-bcfe-24777f15e344@dunslane.net

4 years agoFix relation leak for subscribers firing triggers in logical replication
Michael Paquier [Thu, 22 Apr 2021 03:48:54 +0000 (12:48 +0900)]
Fix relation leak for subscribers firing triggers in logical replication

Creating a trigger on a relation to which an apply operation is
triggered would cause a relation leak once the change gets committed,
as the executor would miss that the relation needs to be closed
beforehand.  This issue got introduced with the refactoring done in
1375422c, where it becomes necessary to track relations within
es_opened_result_relations to make sure that they are closed.

We have discussed using ExecInitResultRelation() coupled with
ExecCloseResultRelations() for the relations in need of tracking by the
apply operations in the subscribers, which would simplify greatly the
opening and closing of indexes, but this requires a larger rework and
reorganization of the worker code, particularly for the tuple routing
part.  And that's not really welcome post feature freeze.  So, for now,
settle down to the same solution as TRUNCATE which is to fill in
es_opened_result_relations with the relation opened, to make sure that
ExecGetTriggerResultRel() finds them and that they get closed.

The code is lightly refactored so as a relation is not registered three
times for each DML code path, making the whole a bit easier to follow.

Reported-by: Tang Haiying, Shi Yu, Hou Zhijie
Author: Amit Langote, Masahiko Sawada, Hou Zhijie
Reviewed-by: Amit Kapila, Michael Paquier
Discussion: https://postgr.es/m/OS0PR01MB611383FA0FE92EB9DE21946AFB769@OS0PR01MB6113.jpnprd01.prod.outlook.com

4 years agodoc: Move parallel_leader_participation to its correct category
Michael Paquier [Thu, 22 Apr 2021 00:47:43 +0000 (09:47 +0900)]
doc: Move parallel_leader_participation to its correct category

parallel_leader_participation got introduced in e5253fd, where it was
listed under RESOURCES_ASYNCHRONOUS in guc.c, but the documentation
did not reflect that and listed it with the other planner-related
options.  This commit fixes this inconsistency as the parameter is
intended to be an asynchronous one.

While on it, reorganize a bit the section dedicated to asynchronous
parameters, backend_flush_after being moved first to do better in terms
of alphabetical order of the options listed.

Reported-by: Yanliang Lei
Author: Bharath Rupireddy
Discussion: https://postgr.es/m/16972-42d4b0c15aa1d5f5@postgresql.org

4 years agoAdd comment about extract_autovac_opts not holding lock
Alvaro Herrera [Wed, 21 Apr 2021 22:36:12 +0000 (18:36 -0400)]
Add comment about extract_autovac_opts not holding lock

Per observation from Tom Lane.

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

4 years agoDon't add a redundant constraint when detaching a partition
Alvaro Herrera [Wed, 21 Apr 2021 22:12:05 +0000 (18:12 -0400)]
Don't add a redundant constraint when detaching a partition

On ALTER TABLE .. DETACH CONCURRENTLY, we add a new table constraint
that duplicates the partition constraint.  But if the partition already
has another constraint that implies that one, then that's unnecessary.
We were already avoiding the addition of a duplicate constraint if there
was an exact 'equal' match -- this just improves the quality of the check.

Author: Justin Pryzby <pryzby@telsasoft.com>
Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://postgr.es/m/20210410184226.GY6592@telsasoft.com

4 years agofix silly perl error in commit d064afc720
Andrew Dunstan [Wed, 21 Apr 2021 15:12:04 +0000 (11:12 -0400)]
fix silly perl error in commit d064afc720

4 years agoUpdate config.guess and config.sub
Peter Eisentraut [Wed, 21 Apr 2021 14:02:03 +0000 (16:02 +0200)]
Update config.guess and config.sub

4 years agoOnly ever test for non-127.0.0.1 addresses on Windows in PostgresNode
Andrew Dunstan [Wed, 21 Apr 2021 14:21:22 +0000 (10:21 -0400)]
Only ever test for non-127.0.0.1 addresses on Windows in PostgresNode

This has been found to cause hangs where tcp usage is forced.

Alexey Kodratov

Discussion: https://postgr.es/m/82e271a9a11928337fcb5b5e57b423c0@postgrespro.ru

Backpatch to all live branches

4 years agoAdd DISTINCT to information schema usage views
Peter Eisentraut [Wed, 21 Apr 2021 09:54:47 +0000 (11:54 +0200)]
Add DISTINCT to information schema usage views

Since pg_depend can contain duplicate entries, we need to eliminate
those in information schema views that build on pg_depend, using
DISTINCT.  Some of the older views already did that correctly, but
some of the more recently added ones didn't.  (In some of these views,
it might not be possible to reproduce the issue because of how the
implementation happens to deduplicate dependencies while recording
them, but it seems better to keep this consistent in all cases.)

4 years agoUse correct format placeholder for timeline IDs
Peter Eisentraut [Wed, 21 Apr 2021 06:26:18 +0000 (08:26 +0200)]
Use correct format placeholder for timeline IDs

Should be %u rather than %d.

4 years agodoc: Improve hyphenation consistency
Peter Eisentraut [Wed, 21 Apr 2021 06:14:43 +0000 (08:14 +0200)]
doc: Improve hyphenation consistency

4 years agoDon't use INT64_FORMAT inside message strings
Peter Eisentraut [Mon, 19 Apr 2021 20:48:13 +0000 (22:48 +0200)]
Don't use INT64_FORMAT inside message strings

Use %lld and cast to long long int instead.

4 years agoFix typo
Peter Eisentraut [Mon, 19 Apr 2021 20:47:43 +0000 (22:47 +0200)]
Fix typo

4 years agodoc: List compute_query_id in required config for pg_stat_statements
Michael Paquier [Wed, 21 Apr 2021 03:02:41 +0000 (12:02 +0900)]
doc: List compute_query_id in required config for pg_stat_statements

Not enabling compute_query_id would disable pg_stat_statements even if
the module is listed in shared_preload_libraries, so add it to the
minimum configuration set as listed in its documentation.

Author: Greg Nancarrow
Reviewed-by: Julien Rouhaud, Bharath Rupireddy
Discussion: https://postgr.es/m/CAJcOf-fXyb2QiDbwftD813UF70w-+BsK-03bFp1GrijXU9GQYQ@mail.gmail.com

4 years agoAdd CURRENT_ROLE to list of roles for tab completion of GRANT in psql
Michael Paquier [Wed, 21 Apr 2021 01:34:43 +0000 (10:34 +0900)]
Add CURRENT_ROLE to list of roles for tab completion of GRANT in psql

This compatibility has been added in 45b9805, but psql forgot the call.

Author: Wei Wang
Reviewed-by: Aleksander Alekseev
Discussion: https://postgr.es/m/OS3PR01MB6275935F62E161BCD393D6559E489@OS3PR01MB6275.jpnprd01.prod.outlook.com

4 years agoImprove WAL record descriptions for SP-GiST records.
Tom Lane [Tue, 20 Apr 2021 21:01:43 +0000 (17:01 -0400)]
Improve WAL record descriptions for SP-GiST records.

While tracking down the bug fixed in the preceding commit, I got quite
annoyed by the low quality of spg_desc's output.  Add missing fields,
try to make the formatting consistent.