postgresql.git
4 years agoSimplify show_incremental_sort_info a bit
Tomas Vondra [Sat, 9 May 2020 17:41:42 +0000 (19:41 +0200)]
Simplify show_incremental_sort_info a bit

Incremental sort always processes at least one full group group before
switching to prefix groups, so it's enough to check just the number of
full groups. There was no risk of division by zero due to the extra
condition, but it made the code harder to understand.

Reported-by: Ranier Vilela
Discussion: https://postgr.es/m/CAEudQAp+7qoS92-4V1vLChpdY3vEkLCbf+gye6P-4cirE-0z0A@mail.gmail.com

4 years agoDo no reset bounded before incremental sort rescan
Tomas Vondra [Sat, 9 May 2020 17:41:36 +0000 (19:41 +0200)]
Do no reset bounded before incremental sort rescan

ExecReScanIncrementalSort was resetting bounded=false, which means the
optimization would be disabled on all rescans. This happens because
ExecSetTupleBound is called before the rescan, not after it.

Author: James Coleman
Reviewed-by: Tomas Vondra
Discussion: https://postgr.es/m/20200414065336.GI1492@paquier.xyz

4 years agoFix handling of REWIND/MARK/BACKWARD in incremental sort
Tomas Vondra [Sat, 9 May 2020 17:41:18 +0000 (19:41 +0200)]
Fix handling of REWIND/MARK/BACKWARD in incremental sort

The executor flags were not handled entirely correctly, although the
bugs were mostly harmless and it was mostly comment inaccuracy. We don't
need to strip any of the flags for child nodes.

Incremental sort does not support backward scans of mark/restore, so
MARK/BACKWARDS flags should not be possible. So we simply ensure this
using an assert, and we don't bother removing them when initializing
the child node.

With REWIND it's a bit less clear - incremental sort does not support
REWIND, but there is no way to signal this - it's legal to just ignore
the flag. We however continue passing the flag to child nodes, because
they might be useful to leverage that.

Reported-by: Michael Paquier
Author: James Coleman
Reviewed-by: Tomas Vondra
Discussion: https://postgr.es/m/20200414065336.GI1492@paquier.xyz

4 years agoUpdate oidjoins regression test for v13.
Tom Lane [Sat, 9 May 2020 17:05:08 +0000 (13:05 -0400)]
Update oidjoins regression test for v13.

We seem to have forgotten to do this in the v12 cycle, so add it as
a task in the RELEASE_CHANGES list, in hopes we won't forget again.

While here, fix findoidjoins.c so that it actually works in the
new dispensation where OID is a regular column, and change it to only
consider system relations (this avoids being fooled by the OID column
in the brintest test table).

Also tweak the largeobject test so that the somewhat-recently-added
manual creation of a LO with an OID in the system range doesn't
fool findoidjoins.c.  For the moment I just made that use an unused
OID, but we might have to find a more robust solution someday.

4 years agopg_restore: Provide file name with one failure message
Alvaro Herrera [Fri, 8 May 2020 23:38:46 +0000 (19:38 -0400)]
pg_restore: Provide file name with one failure message

Almost all error messages already include file name where relevant, but
this one had been overlooked.  Repair.

Backpatch to 9.5.

Author: Euler Taveira <euler.taveira@2ndquadrant.com>
Discussion: https://postgr.es/m/CAH503wA_VOrcKL_43p9atRejCDYmOZ8MzfK9S6TJrQqBqNeAXA@mail.gmail.com
Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org>
4 years agoRework XLogReader callback system
Alvaro Herrera [Fri, 8 May 2020 19:30:34 +0000 (15:30 -0400)]
Rework XLogReader callback system

Code review for 0dc8ead46363, prompted by a bug closed by 91c40548d5f7.

XLogReader's system for opening and closing segments had gotten too
complicated, with callbacks being passed at both the XLogReaderAllocate
level (read_page) as well as at the WALRead level (segment_open).  This
was confusing and hard to follow, so restructure things so that these
callbacks are passed together at XLogReaderAllocate time, and add
another callback to the set (segment_close) to make it a coherent whole.
Also, ensure XLogReaderState is an argument to all the callbacks, so
that they can grab at the ->private data if necessary.

Document the whole arrangement more clearly.

Author: Álvaro Herrera <alvherre@alvh.no-ip.org>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Discussion: https://postgr.es/m/20200422175754.GA19858@alvherre.pgsql

4 years agoImprove use of prepositions in messages
Peter Eisentraut [Fri, 8 May 2020 18:35:03 +0000 (20:35 +0200)]
Improve use of prepositions in messages

*in* database, *in* cluster, *on* server; and some related fixes

4 years agoUnify find_other_exec() error messages
Peter Eisentraut [Fri, 8 May 2020 11:33:00 +0000 (13:33 +0200)]
Unify find_other_exec() error messages

There were a few different ways to line-wrap the error messages.  Make
them all the same, and use placeholders for the actual program names,
to save translation work.

4 years agoFix several DDL issues of generated columns versus inheritance
Peter Eisentraut [Wed, 6 May 2020 14:25:54 +0000 (16:25 +0200)]
Fix several DDL issues of generated columns versus inheritance

Several combinations of generated columns and inheritance in CREATE
TABLE were not handled correctly.  Specifically:

- Disallow a child column specifying a generation expression if the
  parent column is a generated column.  The child column definition
  must be unadorned and the parent column's generation expression will
  be copied.

- Prohibit a child column of a generated parent column specifying
  default values or identity.

- Allow a child column of a not-generated parent column specifying
  itself as a generated column.  This previously did not work, but it
  was possible to arrive at the state via other means (involving ALTER
  TABLE), so it seems sensible to support it.

Add tests for each case.  Also add documentation about the rules
involving generated columns and inheritance.

Discussion:
    https://www.postgresql.org/message-id/flat/15830.1575468847%40sss.pgh.pa.us
    https://www.postgresql.org/message-id/flat/2678bad1-048f-519a-ef24-b12962f41807%40enterprisedb.com
    https://www.postgresql.org/message-id/flat/CAJvUf_u4h0DxkCMCeEKAWCuzGUTnDP-G5iVmSwxLQSXn0_FWNQ%40mail.gmail.com

4 years agoPropagate ALTER TABLE ... SET STORAGE to indexes
Peter Eisentraut [Thu, 9 Apr 2020 12:10:01 +0000 (14:10 +0200)]
Propagate ALTER TABLE ... SET STORAGE to indexes

When creating a new index, the attstorage setting of the table column
is copied to regular (non-expression) index columns.  But a later
ALTER TABLE ... SET STORAGE is not propagated to indexes, thus
creating an inconsistent and undumpable state.

Discussion: https://www.postgresql.org/message-id/flat/9765d72b-37c0-06f5-e349-2a580aafd989%402ndquadrant.com

4 years agoFix inconsistency in pg_buffercache docs.
Amit Kapila [Fri, 8 May 2020 03:03:05 +0000 (08:33 +0530)]
Fix inconsistency in pg_buffercache docs.

Commit 6e654546fb avoids locking bufmgr partitions to make pg_buffercache
less disruptive on production systems but forgot to update the docs.

Reported-by: Sawada Masahiko
Author: Sawada Masahiko
Reviewed-by: Amit Kapila
Backpatch-through: 10
Discussion: https://postgr.es/m/CA+fd4k6sD8oeP1qJbFAor=rCpYckU9DsywHiYx3x5Hz5Z8Ua_w@mail.gmail.com

4 years agoReport missing wait event for timeline history file.
Fujii Masao [Fri, 8 May 2020 01:36:40 +0000 (10:36 +0900)]
Report missing wait event for timeline history file.

TimelineHistoryRead and TimelineHistoryWrite wait events are reported
during waiting for a read and write of a timeline history file, respectively.
However, previously, TimelineHistoryRead wait event was not reported
while readTimeLineHistory() was reading a timeline history file. Also
TimelineHistoryWrite was not reported while writeTimeLineHistory() was
writing one line with the details of the timeline split, at the end.
This commit fixes these issues.

Back-patch to v10 where wait events for a timeline history file was added.

Author: Masahiro Ikeda
Reviewed-by: Michael Paquier, Fujii Masao
Discussion: https://postgr.es/m/d11b0c910b63684424e06772eb844ab5@oss.nttdata.com

4 years agoRefactor nbtree deletion INCOMPLETE_SPLIT check.
Peter Geoghegan [Thu, 7 May 2020 23:08:54 +0000 (16:08 -0700)]
Refactor nbtree deletion INCOMPLETE_SPLIT check.

Factor out code common to _bt_lock_branch_parent() and _bt_pagedel()
into a new utility function.  This new function is used to check that
the left sibling of a deletion target page does not have the
INCOMPLETE_SPLIT page flag set.  If it is set then deletion is unsafe;
there won't be a usable pivot tuple (with a downlink) in the parent page
that points to the deletion target page.  The page deletion algorithm is
not prepared to deal with that.  Also restructure an existing, related
utility function that checks if the right sibling of the target page has
the ISHALFDEAD page flag set.

This organization highlights the symmetry between the two cases.  The
goal is to make the design of page deletion clearer.  Both functions
involve a sibling page with a flag that indicates that there was an
interrupted operation (a page split or a page deletion) that resulted in
a page pointed to by sibling pages, but not pointed to in the parent.
And, both functions indicate if page deletion is unsafe due to the
absence of a particular downlink in the parent page.

4 years agoFix YA text phrase search bug.
Tom Lane [Thu, 7 May 2020 19:59:51 +0000 (15:59 -0400)]
Fix YA text phrase search bug.

checkcondition_str() failed to report multiple matches for a prefix
pattern correctly: it would dutifully merge the match positions, but
then after exiting that loop, if the last prefix-matching word had
had no suitable positions, it would report there were no matches.
The upshot would be failing to recognize a match that the query
should match.

It looks like you need all of these conditions to see the bug:
* a phrase search (else we don't ask for match position details)
* a prefix search item (else we don't get to this code)
* a weight restriction (else checkclass_str won't fail)

Noted while investigating a problem report from Pavel Borisov,
though this is distinct from the issue he was on about.

Back-patch to 9.6 where phrase search was added.

4 years agoDoc: update remaining tables of functions/operators for new layout.
Tom Lane [Thu, 7 May 2020 18:25:18 +0000 (14:25 -0400)]
Doc: update remaining tables of functions/operators for new layout.

This converts the contrib documentation to the new style, and mops up
a couple of function tables that were outside chapter 9 in the main
docs.

A few contrib modules choose not to present their functions in the
standard tabular format.  There might be room to rethink those decisions
now that the standard format is more friendly to verbose descriptions.
But I have not undertaken to do that here; I just converted existing
tables.

4 years agodoc: PG 13 relnotes: adjust partitioning items
Bruce Momjian [Thu, 7 May 2020 17:06:31 +0000 (13:06 -0400)]
doc: PG 13 relnotes: adjust partitioning items

Reported-by: Amit Langote
4 years agodoc: PG 13 relnotes: adjust wording and Unicode item
Bruce Momjian [Thu, 7 May 2020 14:01:22 +0000 (10:01 -0400)]
doc: PG 13 relnotes:  adjust wording and Unicode item

4 years agodoc: PG 13 relnotes: adjust partition items and attributions
Bruce Momjian [Thu, 7 May 2020 13:00:24 +0000 (09:00 -0400)]
doc:  PG 13 relnotes:  adjust partition items and attributions

This merges three partition publication items into two.

4 years agodoc: PG 13 relnotes, update TOAST item to mention decompression
Bruce Momjian [Wed, 6 May 2020 23:34:22 +0000 (19:34 -0400)]
doc:  PG 13 relnotes, update TOAST item to mention decompression

Reported-by: Andrey M. Borodin
Discussion: https://postgr.es/m/D49B37B1-E2B9-4F67-8C6C-5CFD4015E8C5@yandex-team.ru

4 years agopgbench: document that the default data loading is client-side
Bruce Momjian [Wed, 6 May 2020 23:07:29 +0000 (19:07 -0400)]
pgbench:  document that the default data loading is client-side

Reported-by: Fabien COELHO
Discussion: https://postgr.es/m/alpine.DEB.2.22.394.2005051811320.2183756@pseudo

4 years agoDoc: remove now-redundant align specifications in colspecs.
Tom Lane [Wed, 6 May 2020 19:58:23 +0000 (15:58 -0400)]
Doc: remove now-redundant align specifications in colspecs.

In the wake of commit f21599311, we don't need to set table columns'
align specs retail.  Undo a few such settings I'd added in commit
5545b69ae.  (The column width adjustments stay, though.)

4 years agoHeed lock protocol in DROP OWNED BY
Alvaro Herrera [Wed, 6 May 2020 16:29:41 +0000 (12:29 -0400)]
Heed lock protocol in DROP OWNED BY

We were acquiring object locks then deleting objects one by one, instead
of acquiring all object locks first, ignoring those that did not exist,
and then deleting all objects together.   The latter is the correct
protocol to use, and what this commits changes to code to do.  Failing
to follow that leads to "cache lookup failed for relation XYZ" error
reports when DROP OWNED runs concurrently with other DDL -- for example,
a session termination that removes some temp tables.

Author: Álvaro Herrera
Reported-by: Mithun Chicklore Yogendra (Mithun CY)
Reviewed-by: Ahsan Hadi, Tom Lane
Discussion: https://postgr.es/m/CADq3xVZTbzK4ZLKq+dn_vB4QafXXbmMgDP3trY-GuLnib2Ai1w@mail.gmail.com

4 years agoDoc: further fooling-about with rendering of tables in PDF output.
Tom Lane [Wed, 6 May 2020 16:23:43 +0000 (12:23 -0400)]
Doc: further fooling-about with rendering of tables in PDF output.

I concluded that we really just ought to force all tables in PDF output
to default to "left" alignment (instead of "justify"); that is what the
HTML toolchain does and that's what most people have been designing the
tables to look good with.  There are few if any places where "justify"
produces better-looking output, and there are many where it looks
horrible.  So change stylesheet-fo.xsl to make that true.

Also tweak column widths in a few more tables to make them look better
and avoid "exceed the available area" warnings.  This commit fixes
basically everything that can be fixed through that approach.  The
remaining tables that give warnings either are scheduled for redesign
as per recent discussions, or need a fundamental rethink because they
Just Don't Work in a narrow view.

4 years agoHandle spaces for Python install location in MSVC scripts
Michael Paquier [Wed, 6 May 2020 12:08:15 +0000 (21:08 +0900)]
Handle spaces for Python install location in MSVC scripts

Attempting to use an installation path of Python that includes spaces
caused the MSVC builds to fail.  This fixes the issue by using the same
quoting method as ad7595b for OpenSSL.

Author: Victor Wagner
Discussion: https://postgr.es/m/20200430150608.6dc6b8c4@antares.wagner.home
Backpatch-through: 9.5

4 years agodoc: PG 13 relnotes, fix markup
Bruce Momjian [Tue, 5 May 2020 21:45:34 +0000 (17:45 -0400)]
doc:  PG 13 relnotes, fix markup

4 years agodoc: PG 13 renotes: adjust attribution and pgbench item
Bruce Momjian [Tue, 5 May 2020 21:43:27 +0000 (17:43 -0400)]
doc:  PG 13 renotes:  adjust attribution and pgbench item

4 years agoNormalize _bt_findsplitloc() argument names.
Peter Geoghegan [Tue, 5 May 2020 21:42:10 +0000 (14:42 -0700)]
Normalize _bt_findsplitloc() argument names.

Oversight in commit bc3087b626d.

4 years agoRemove obsolete amcheck comment.
Peter Geoghegan [Tue, 5 May 2020 21:36:54 +0000 (14:36 -0700)]
Remove obsolete amcheck comment.

Oversight in commit d114cc53.

4 years agodoc: PG 13 relnotes, add pgbench script item
Bruce Momjian [Tue, 5 May 2020 21:21:57 +0000 (17:21 -0400)]
doc:  PG 13 relnotes, add pgbench script item

4 years agodoc: PG 13 relnotes, add attributions and wording changes
Bruce Momjian [Tue, 5 May 2020 20:31:44 +0000 (16:31 -0400)]
doc: PG 13 relnotes, add attributions and wording changes

4 years agoDoc: warn that timezone abbreviations don't work in recovery_target_time.
Tom Lane [Tue, 5 May 2020 20:06:49 +0000 (16:06 -0400)]
Doc: warn that timezone abbreviations don't work in recovery_target_time.

Moving this setting into the main configuration file was ill-considered,
perhaps, because that typically causes it to be set before
timezone_abbreviations has been set.  Which in turn means that zone
abbreviations don't work, only full zone names.

We could imagine hacking things so that such cases do work, but the
stability of the hack would be questionable, and the value isn't really
that high.  Instead just document that you should use a numeric zone
offset or a full zone name.

Per bug #16404 from Reijo Suhonen.
Back-patch to v12 where this was changed.

Discussion: https://postgr.es/m/16404-4603a99603fbd04c@postgresql.org

4 years agodoc: PG 13 release note adjustments, Justin Pryzby v2
Bruce Momjian [Tue, 5 May 2020 18:40:27 +0000 (14:40 -0400)]
doc:  PG 13 release note adjustments, Justin Pryzby v2

Reported-by: Justin Pryzby
4 years agodoc: PG 13 retnote adjustments
Bruce Momjian [Tue, 5 May 2020 17:18:05 +0000 (13:18 -0400)]
doc: PG 13 retnote adjustments

Reported-by: Justin Pryzby
4 years agoFix severe memory leaks in GSSAPI encryption support.
Tom Lane [Tue, 5 May 2020 17:10:09 +0000 (13:10 -0400)]
Fix severe memory leaks in GSSAPI encryption support.

Both the backend and libpq leaked buffers containing encrypted data
to be transmitted, so that the process size would grow roughly as
the total amount of data sent.

There were also far-less-critical leaks of the same sort in GSSAPI
session establishment.

Oversight in commit b0b39f72b, which I failed to notice while
reviewing the code in 2c0cdc818.

Per complaint from pmc@citylink.
Back-patch to v12 where this code was introduced.

Discussion: https://postgr.es/m/20200504115649.GA77072@gate.oper.dinoex.org

4 years agodoc: normalize contributor names in PG 13 release notes
Bruce Momjian [Tue, 5 May 2020 16:42:55 +0000 (12:42 -0400)]
doc:  normalize contributor names in PG 13 release notes

4 years agodoc: update PG 13 release notes for glossary and NO DEPENDS
Bruce Momjian [Tue, 5 May 2020 15:42:28 +0000 (11:42 -0400)]
doc:  update PG 13 release notes for glossary and NO DEPENDS

4 years agodoc: Fix PG 13 release note markup
Bruce Momjian [Tue, 5 May 2020 14:33:50 +0000 (10:33 -0400)]
doc:  Fix PG 13 release note markup

4 years agodoc: update PG 13 release notes after first draft
Bruce Momjian [Tue, 5 May 2020 14:32:50 +0000 (10:32 -0400)]
doc:  update PG 13 release notes after first draft

Minor corrections from individuals.

4 years agoFix capitalization of messages, per style guide
Peter Eisentraut [Tue, 5 May 2020 06:49:52 +0000 (08:49 +0200)]
Fix capitalization of messages, per style guide

4 years agoDoc: Outline REPLICATION before SUPERUSER privilege
Michael Paquier [Tue, 5 May 2020 05:16:01 +0000 (14:16 +0900)]
Doc: Outline REPLICATION before SUPERUSER privilege

The following docs are updated:
- High-availaility section
- pg_basebackup
- pg_receivewal

Per the principle of least privilege, we want to encourage users to
interact with those areas using roles that have replication rights, but
superusers were mentioned first.

Author: Daniel Gustafsson
Reviewed-by: Fujii Masao, Michael Paquier
Discussion: https://postgr.es/m/ECEBD212-7101-41EB-84F3-2F356E4B6401@yesql.se

5 years agodoc: first draft of PG 13 release notes
Bruce Momjian [Tue, 5 May 2020 03:09:45 +0000 (23:09 -0400)]
doc:  first draft of PG 13 release notes

This still needs markup, indenting, and word wrap.

5 years agoChange the display of WAL usage statistics in Explain.
Amit Kapila [Tue, 5 May 2020 02:30:53 +0000 (08:00 +0530)]
Change the display of WAL usage statistics in Explain.

In commit 33e05f89c5, we have added the option to display WAL usage
statistics in Explain and auto_explain.  The display format used two spaces
between each field which is inconsistent with Buffer usage statistics which
is using one space between each field.  Change the format to make WAL usage
statistics consistent with Buffer usage statistics.

This commit also changed the usage of "full page writes" to
"full page images" for WAL usage statistics to make it consistent with
other parts of code and docs.

Author: Julien Rouhaud, Amit Kapila
Reviewed-by: Justin Pryzby, Kyotaro Horiguchi and Amit Kapila
Discussion: https://postgr.es/m/CAB-hujrP8ZfUkvL5OYETipQwA=e3n7oqHFU=4ZLxWS_Cza3kQQ@mail.gmail.com

5 years agoDoc: improve PDF presentation of some tables by adjusting column widths.
Tom Lane [Mon, 4 May 2020 20:16:42 +0000 (16:16 -0400)]
Doc: improve PDF presentation of some tables by adjusting column widths.

The PDF toolchain defaults to laying out all columns of a table with
equal widths, in contrast to the HTML rendering which automatically
varies the column widths to fit the data.  In many places, this
results in very badly laid-out tables, with lots of useless whitespace
in some places and text that overruns its cell in other places.

For tables that have reasonably static content, we can improve
matters by adding <colspec> entries to hand-assign the column widths.
This commit does that for a few of the tables that were worst off;
it eliminates close to 200 "contents ... exceed the available area"
warnings in an A4 PDF build.

I also forced align="left" in these tables, overriding the PDF
toolchain's default which is evidently "justify".  (The HTML toolchain
seems to default to that already.)  Anyplace where things are tight
enough that we need to worry about this, forced justification tends to
look truly awful.

5 years agoAdd posting list tuple amcheck test case.
Peter Geoghegan [Mon, 4 May 2020 18:23:44 +0000 (11:23 -0700)]
Add posting list tuple amcheck test case.

Add a test case to contrib/amcheck that creates coverage of code paths
that are used to verify posting list tuples (tuples created when
deduplication merges together existing tuples to avoid a leaf page
split).

5 years agoDoc: standardize markup a bit more.
Tom Lane [Mon, 4 May 2020 17:48:30 +0000 (13:48 -0400)]
Doc: standardize markup a bit more.

We had a mishmash of <replaceable>, <replaceable class="parameter">,
and <parameter> markup for operator/function arguments.  Use <parameter>
consistently for things that are in fact names of parameters (including
OUT parameters), reserving <replaceable> for things that aren't.  The
latter class includes some made-up-by-the-docs type class names, like
"numeric_type", as well as placeholders for arguments that don't have
well-defined types.  Possibly we could do better with those categories
as well, but for the moment I'm content not to have parameter names
marked up in different ways in different places.

(This commit aligns the earlier sections of chapter 9 with a policy
that I'd arrived at while working on commit 1ad23335f, which is why
the last few sections need no changes.)

5 years agoDoc: update sections 9.22 - 9.30 for new function table layout.
Tom Lane [Mon, 4 May 2020 16:18:06 +0000 (12:18 -0400)]
Doc: update sections 9.22 - 9.30 for new function table layout.

With the usual quota of minor and less-minor editorial changes.

5 years agoFix typo in comment
Alexander Korotkov [Sun, 3 May 2020 09:19:31 +0000 (12:19 +0300)]
Fix typo in comment

Reported-by: Oleg Bartunov
5 years agoAdd missing newlines in error messages
Peter Eisentraut [Sun, 3 May 2020 08:45:52 +0000 (10:45 +0200)]
Add missing newlines in error messages

5 years agoRefactor btvacuumpage().
Peter Geoghegan [Sat, 2 May 2020 21:04:33 +0000 (14:04 -0700)]
Refactor btvacuumpage().

Remove one of the arguments to btvacuumpage(), and give up on the idea
that it's a recursive function.  We now use the term "backtracking" to
refer to the case where an earlier block must be visited to make sure no
tuples that need to be removed were missed.

Advertising btvacuumpage() as a recursive function was unhelpful.  In
reality the function always simulates recursion with a loop (it doesn't
actually call itself).  This wasn't just necessary as a precaution (per
the comments mentioning tail recursion), though.  There is no reliable
natural limit on the number of times we can backtrack.

There are important behavioral difference when "recursing"/backtracking,
mostly related to page deletion.  We don't perform page deletion when
backtracking due to the extra complexity.  And when we recurse, we're
not performing a physical order scan anymore, so we expect fairly
different conditions to hold for the page.  Structuring the code like
this makes it clearer how _bt_pagedel() cooperates with btvacuumpage()
and btvacuumscan() (as established in commit b0229f26 and commit
73a076b0).

Author: Peter Geoghegan
Reviewed-By: Masahiko Sawada
Discussion: https://postgr.es/m/CAH2-WzmRGMDWiLMcb+zagG9652PboNN4Gfcq1Gc_wJL6A716MA@mail.gmail.com

5 years agoFix GSS client to non-GSS server connection
Stephen Frost [Sat, 2 May 2020 15:39:26 +0000 (11:39 -0400)]
Fix GSS client to non-GSS server connection

If the client is compiled with GSSAPI support and tries to start up GSS
with the server, but the server is not compiled with GSSAPI support, we
would mistakenly end up falling through to call ProcessStartupPacket
with secure_done = true, but the client might then try to perform SSL,
which the backend wouldn't understand and we'd end up failing the
connection with:

FATAL:  unsupported frontend protocol 1234.5679: server supports 2.0 to 3.0

Fix by arranging to track ssl_done independently from gss_done, instead
of trying to use the same boolean for both.

Author: Andrew Gierth
Discussion: https://postgr.es/m/87h82kzwqn.fsf@news-spur.riddles.org.uk
Backpatch: 12-, where GSSAPI encryption was added.

5 years agoRemove superfluous memset from pgstat_recv_resetslrucounter
Tomas Vondra [Sat, 2 May 2020 13:30:10 +0000 (15:30 +0200)]
Remove superfluous memset from pgstat_recv_resetslrucounter

The extra memset meant pg_stat_reset_slru() always reset all the entries
even when reset of a single entry was requested, but the timestamp was
left uninitialized.

Reported-by: Atsushi Torikoshi
Discussion: https://postgr.es/m/CACZ0uYFe16pjZxQYaTn53mspyM7dgMPYL3DJLjjPw69GMCC2Ow%40mail.gmail.com

5 years agoRemove pg_xact from pg_stat_reset_slru docs
Tomas Vondra [Sat, 2 May 2020 13:26:47 +0000 (15:26 +0200)]
Remove pg_xact from pg_stat_reset_slru docs

This should have been included in 2e08d314ed.

Reported-by: Fujii Masao
Discussion: https://postgr.es/m/20200119143707.gyinppnigokesjok@development

5 years agoAdd NLS to pg_verifybackup
Peter Eisentraut [Sat, 2 May 2020 08:33:10 +0000 (10:33 +0200)]
Add NLS to pg_verifybackup

5 years agoSimplify cost_incremental_sort a bit
Tomas Vondra [Fri, 1 May 2020 23:25:00 +0000 (01:25 +0200)]
Simplify cost_incremental_sort a bit

Commit de0dc1a847 added code to cost_incremental_sort to handle varno 0.
Explicitly removing the RelabelType is not really necessary, because the
pull_varnos handles that just fine, which simplifies the code a bit.

Author: Richard Guo
Discussion: https://postgr.es/m/CAMbWs4_3_D2J5XxOuw68hvn0-gJsw9FXNSGcZka9aTymn9UJ8A%40mail.gmail.com
Discussion: https://postgr.es/m/20200411214639.GK2228%40telsasoft.com

5 years agoRemove pg_xact entry from SLRU stats
Tomas Vondra [Fri, 1 May 2020 22:36:25 +0000 (00:36 +0200)]
Remove pg_xact entry from SLRU stats

The "pg_xact" entry was duplicate with "clog" and was added by mistake.

Reported-by: Fujii Masao
Discussion: https://postgr.es/m/20200119143707.gyinppnigokesjok@development

5 years agoGet rid of trailing semicolons in C macro definitions.
Tom Lane [Fri, 1 May 2020 21:28:00 +0000 (17:28 -0400)]
Get rid of trailing semicolons in C macro definitions.

Writing a trailing semicolon in a macro is almost never the right thing,
because you almost always want to write a semicolon after each macro
call instead.  (Even if there was some reason to prefer not to, pgindent
would probably make a hash of code formatted that way; so within PG the
rule should basically be "don't do it".)  Thus, if we have a semi inside
the macro, the compiler sees "something;;".  Much of the time the extra
empty statement is harmless, but it could lead to mysterious syntax
errors at call sites.  In perhaps an overabundance of neatnik-ism, let's
run around and get rid of the excess semicolons whereever possible.

The only thing worse than a mysterious syntax error is a mysterious
syntax error that only happens in the back branches; therefore,
backpatch these changes where relevant, which is most of them because
most of these mistakes are old.  (The lack of reported problems shows
that this is largely a hypothetical issue, but still, it could bite
us in some future patch.)

John Naylor and Tom Lane

Discussion: https://postgr.es/m/CACPNZCs0qWTqJ2QUSGJ07B7uvAvzMb-KbG2q+oo+J3tsWN5cqw@mail.gmail.com

5 years agoDoc: update sections 9.17 - 9.21 for new function table layout.
Tom Lane [Fri, 1 May 2020 20:16:28 +0000 (16:16 -0400)]
Doc: update sections 9.17 - 9.21 for new function table layout.

With the usual quota of minor editorial changes.

5 years agoClear up issue with FSM and oldest bpto.xact.
Peter Geoghegan [Fri, 1 May 2020 19:19:44 +0000 (12:19 -0700)]
Clear up issue with FSM and oldest bpto.xact.

On further reflection, code comments added by commit b0229f26 slightly
misrepresented how we determine the oldest bpto.xact for the index.
btvacuumpage() does not treat the bpto.xact of a page that it put in the
FSM as a candidate to be the oldest deleted page (the delete-marked page
that has the oldest bpto.xact XID among all pages encountered).

The definition of a deleted page for the purposes of the bpto.xact
calculation is different from the definition used by the bulk delete
statistics.  The bulk delete statistics don't distinguish between pages
that were deleted by the current VACUUM, pages deleted by a previous
VACUUM operation but not yet recyclable/reusable, and pages that are
reusable (though reusable pages are counted separately).

Backpatch: 11-, just like commit b0229f26.

5 years agoReorder function prototypes for consistency.
Peter Geoghegan [Fri, 1 May 2020 17:03:38 +0000 (10:03 -0700)]
Reorder function prototypes for consistency.

5 years agoFix undercounting in VACUUM VERBOSE output.
Peter Geoghegan [Fri, 1 May 2020 16:51:09 +0000 (09:51 -0700)]
Fix undercounting in VACUUM VERBOSE output.

The logic for determining how many nbtree pages in an index are deleted
pages sometimes undercounted pages.  Pages that were deleted by the
current VACUUM operation (as opposed to some previous VACUUM operation
whose deleted pages have yet to be reused) were sometimes overlooked.
The final count is exposed to users through VACUUM VERBOSE's "%u index
pages have been deleted" output.

btvacuumpage() avoided double-counting when _bt_pagedel() deleted more
than one page by assuming that only one page was deleted, and that the
additional deleted pages would get picked up during a future call to
btvacuumpage() by the same VACUUM operation.  _bt_pagedel() can
legitimately delete pages that the btvacuumscan() scan will not visit
again, though, so that assumption was slightly faulty.

Fix the accounting by teaching _bt_pagedel() about its caller's
requirements.  It now only reports on pages that it knows btvacuumscan()
won't visit again (including the current btvacuumpage() page), so
everything works out in the end.

This bug has been around forever.  Only backpatch to v11, though, to
keep _bt_pagedel() is sync on the branches that have today's bugfix
commit b0229f26da.  Note that this commit changes the signature of
_bt_pagedel(), just like commit b0229f26da.

Author: Peter Geoghegan
Reviewed-By: Masahiko Sawada
Discussion: https://postgr.es/m/CAH2-WzkrXBcMQWAYUJMFTTvzx_r4q=pYSjDe07JnUXhe+OZnJA@mail.gmail.com
Backpatch: 11-

5 years agoFix bug in nbtree VACUUM "skip full scan" feature.
Peter Geoghegan [Fri, 1 May 2020 15:39:52 +0000 (08:39 -0700)]
Fix bug in nbtree VACUUM "skip full scan" feature.

Commit 857f9c36cda (which taught nbtree VACUUM to skip a scan of the
index from btcleanup in situations where it doesn't seem worth it) made
VACUUM maintain the oldest btpo.xact among all deleted pages for the
index as a whole.  It failed to handle all the details surrounding pages
that are deleted by the current VACUUM operation correctly (though pages
deleted by some previous VACUUM operation were processed correctly).

The most immediate problem was that the special area of the page was
examined without a buffer pin at one point.  More fundamentally, the
handling failed to account for the full range of _bt_pagedel()
behaviors.  For example, _bt_pagedel() sometimes deletes internal pages
in passing, as part of deleting an entire subtree with btvacuumpage()
caller's page as the leaf level page.  The original leaf page passed to
_bt_pagedel() might not be the page that it deletes first in cases where
deletion can take place.

It's unclear how disruptive this bug may have been, or what symptoms
users might want to look out for.  The issue was spotted during
unrelated code review.

To fix, push down the logic for maintaining the oldest btpo.xact to
_bt_pagedel().  btvacuumpage() is now responsible for pages that were
fully deleted by a previous VACUUM operation, while _bt_pagedel() is now
responsible for pages that were deleted by the current VACUUM operation
(this includes half-dead pages from a previous interrupted VACUUM
operation that become fully deleted in _bt_pagedel()).  Note that
_bt_pagedel() should never encounter an existing deleted page.

This commit theoretically breaks the ABI of a stable release by changing
the signature of _bt_pagedel().  However, if any third party extension
is actually affected by this, then it must already be completely broken
(since there are numerous assumptions made in _bt_pagedel() that cannot
be met outside of VACUUM).  It seems highly unlikely that such an
extension actually exists, in any case.

Author: Peter Geoghegan
Reviewed-By: Masahiko Sawada
Discussion: https://postgr.es/m/CAH2-WzkrXBcMQWAYUJMFTTvzx_r4q=pYSjDe07JnUXhe+OZnJA@mail.gmail.com
Backpatch: 11-, where the "skip full scan" feature was introduced.

5 years agoPut new command-line options into alphabetical order in help output
Peter Eisentraut [Fri, 1 May 2020 09:49:52 +0000 (11:49 +0200)]
Put new command-line options into alphabetical order in help output

5 years agoImprove various aspects of pg_rewind documentation
Michael Paquier [Fri, 1 May 2020 08:40:41 +0000 (17:40 +0900)]
Improve various aspects of pg_rewind documentation

The pg_rewind docs currently assert that the state of the target's
data directory after rewind is equivalent to the source's data
directory.  This clarifies the documentation to describe that the base
state is further back in time and that the target's data directory will
include the current state from the source of any copied blocks since the
point of divergence.

This commit also improves the section "How It Works":
- Describe the update of the pg_control file.
- Reorganize the list of files and directories ignored during the
rewind.

Author: James Coleman
Discussion: https://postgr.es/m/CAAaqYe-sgqCos7MXF4XiY8rUPy3CEmaCY9EvfhX-DhPhPBF5_A@mail.gmail.com

5 years agoAdd nbtree ScalarArrayOpExpr tests.
Peter Geoghegan [Thu, 30 Apr 2020 21:33:13 +0000 (14:33 -0700)]
Add nbtree ScalarArrayOpExpr tests.

Add test coverage for the nbtutils.c routines concerned with IndexScans
that have native ScalarArrayOpExpr quals.  The ScalarArrayOpExpr
specialized mark and restore routines, and the "find extreme element"
routine now have some test coverage.

These functions are probably infrequently exercised by real world
queries, so having some coverage seems like a good idea.  The mark and
restore routines were originally added by a bugfix that came several
weeks after the first stable release of Postgres 9.2 (see commit
70bc5833195).

5 years agoFix AddressSanitizer use-after-scope complaint.
Peter Geoghegan [Thu, 30 Apr 2020 19:31:56 +0000 (12:31 -0700)]
Fix AddressSanitizer use-after-scope complaint.

XLogRegisterBufData() does not copy data pointed to by caller's pointer
argument.

Oversight in commit 0d861bbb702.

Author: Peter Eisentraut
Reported-By: Peter Eisentraut
Discussion: https://postgr.es/m/21800dbe-a13e-22f7-d423-b81db9d249f5@2ndquadrant.com

5 years agoDoc: update sections 9.14 - 9.16 for new function table layout.
Tom Lane [Thu, 30 Apr 2020 16:53:44 +0000 (12:53 -0400)]
Doc: update sections 9.14 - 9.16 for new function table layout.

Minor editorial changes in the first two sections; larger ones
in the JSON section.

5 years agoMake SQL/JSON error code names match SQL standard
Peter Eisentraut [Thu, 30 Apr 2020 07:34:54 +0000 (09:34 +0200)]
Make SQL/JSON error code names match SQL standard

see also a00c53b0cb

5 years agoUpdate config.guess and config.sub
Peter Eisentraut [Thu, 30 Apr 2020 07:06:49 +0000 (09:06 +0200)]
Update config.guess and config.sub

5 years agoRename connection parameters to control min/max SSL protocol version in libpq
Michael Paquier [Thu, 30 Apr 2020 04:39:10 +0000 (13:39 +0900)]
Rename connection parameters to control min/max SSL protocol version in libpq

The libpq parameters ssl{max|min}protocolversion are renamed to use
underscores, to become ssl_{max|min}_protocol_version.  The related
environment variables still use the names introduced in commit ff8ca5f
that added the feature.

Per complaint from Peter Eisentraut (this was also mentioned by me in
the original patch review but the issue got discarded).

Author: Daniel Gustafsson
Reviewed-by: Peter Eisentraut, Michael Paquier
Discussion: https://postgr.es/m/b319e449-318d-e691-4997-1327e166fcc4@2ndquadrant.com

5 years agoDoc: re-re-revise markup for tables of functions.
Tom Lane [Thu, 30 Apr 2020 04:34:05 +0000 (00:34 -0400)]
Doc: re-re-revise markup for tables of functions.

Make the markup a bit less ad-hoc.  A function-table cell now contains
several <para> units, and we label the ones that contain function
signatures with role="func_signature".  The CSS or FO stylesheets then
key off of that to decide how to set the indentation.  A very useful
win from this approach is that we can have more than one signature
entry per table cell, simplifying the documentation of closely-related
operators and functions.

This patch mostly just replaces the markup in the tables I converted so
far.  But I did alter a couple of places where multiple signatures were
helpful.

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

5 years agoRemove redundant _bt_killitems() buffer check.
Peter Geoghegan [Thu, 30 Apr 2020 01:17:49 +0000 (18:17 -0700)]
Remove redundant _bt_killitems() buffer check.

_bt_getbuf() cannot return an invalid buffer.

Oversight in commit 2ed5b87f96d.

5 years agoFix check for conflicting SSL min/max protocol settings
Michael Paquier [Wed, 29 Apr 2020 23:14:02 +0000 (08:14 +0900)]
Fix check for conflicting SSL min/max protocol settings

Commit 79dfa8a has introduced a check to catch when the minimum protocol
version was set higher than the maximum version, however an error was
getting generated when both bounds are set even if they are able to
work, causing a backend to not use a new SSL context but keep the old
one.

Author: Daniel Gustafsson
Discussion: https://postgr.es/m/14BFD060-8C9D-43B4-897D-D5D9AA6FC92B@yesql.se

5 years agoFix checkpoint signalling
Alvaro Herrera [Wed, 29 Apr 2020 22:46:42 +0000 (18:46 -0400)]
Fix checkpoint signalling

Checkpointer uses its MyLatch to wake up when a checkpoint request is
received.  But before commit c6550776394e the latch was not used for
anything else, so the code could just go to sleep after each loop
without rechecking the sleeping condition.  That commit added a separate
ResetLatch in its code path[1], which can cause a checkpoint to go
unnoticed for potentially a long time.

Fix by skipping sleep if any checkpoint flags are set.  Also add a test
to verify this; authored by Kyotaro Horiguchi.

[1] CreateCheckPoint -> InvalidateObsoleteReplicationSlots ->
ConditionVariableTimeSleep

Report and diagnosis by Kyotaro Horiguchi.
Co-authored-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Co-authored-by: Álvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://postgr.es/m/20200408.141956.891237856186513376.horikyota.ntt@gmail.com

5 years agoFix typo
Peter Eisentraut [Wed, 29 Apr 2020 08:13:25 +0000 (10:13 +0200)]
Fix typo

from 927474ce1a2

5 years agoCheck slot->restart_lsn validity in a few more places
Alvaro Herrera [Wed, 29 Apr 2020 00:39:04 +0000 (20:39 -0400)]
Check slot->restart_lsn validity in a few more places

Lack of these checks could cause visible misbehavior, including
assertion failures.  This was missed in commit c6550776394e, whereby
restart_lsn becomes invalid when the size limit is exceeded.

Also reword some existing error messages, and add errdetail(), so that
the reported errors all match in spirit.

Author: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://postgr.es/m/20200408.093710.447591748588426656.horikyota.ntt@gmail.com

5 years agoAdd LP_DEAD deletion of a posting list tuple test.
Peter Geoghegan [Tue, 28 Apr 2020 23:12:56 +0000 (16:12 -0700)]
Add LP_DEAD deletion of a posting list tuple test.

Make sure that we have test coverage of the posting list tuple path
within _bt_xid_horizon().

Per off-list complaint from Andres Freund.

5 years agoAdd missing gettext triggers
Peter Eisentraut [Tue, 28 Apr 2020 11:35:40 +0000 (13:35 +0200)]
Add missing gettext triggers

Some translatable strings have been moved to scanner_yyerror(), so we
need to add that, too.

5 years agoFix definition of pg_statio_all_tables view
Alexander Korotkov [Tue, 28 Apr 2020 08:07:56 +0000 (11:07 +0300)]
Fix definition of pg_statio_all_tables view

pg_statio_all_tables view appears to have a wrong grouping.  As the result
numbers of toast index blocks read and hit were multiplied to the number of
table indexes.  This commit fixes the view definition.

Backpatching this appears difficult.  We don't have a mechanism to patch a
system catalog of existing instances in minor upgrade.  We can write a
release notes instruction to do this manually.  But per discussion this is
probably not so critical bug for doing such an intrusive fix.

Reported-by: Andrei Zubkov
Discussion: https://postgr.es/m/CAPpHfdtMYkkNudLMG9G0dxX_B%3Dn5sfKzOyxxrvWYtSicaGW0Lw%40mail.gmail.com

5 years agoAdd more TAP coverage for archive status with crash recovery of standbys
Michael Paquier [Mon, 27 Apr 2020 22:55:51 +0000 (07:55 +0900)]
Add more TAP coverage for archive status with crash recovery of standbys

This part of the test was included originally in 4e87c48, but got
reverted as of f9c1b8d because of timing issues in the test, where,
after more analysis, we found that the standbys may not have recovered
from the archives all the segments needed by the test.  This stabilizes
the test by making sure that standbys replay up to the position returned
by pg_switch_wal(), meaning that all segments are recovered before the
manual checkpoint that tests WAL segment recycling and its interactions
with archive status files.

Author: Jehan-Guillaume de Rorthais
Reviewed-by: Kyotaro Horiguchi, Michael Paquier
Discussion: https://postgr.es/m/20200424034248.GL33034@paquier.xyz

5 years agoFix bogus tar-file padding logic for standby.signal.
Robert Haas [Mon, 27 Apr 2020 17:04:35 +0000 (13:04 -0400)]
Fix bogus tar-file padding logic for standby.signal.

When pg_basebackup -R is used, we inject standby.signal into the
tar file for the main tablespace. The proper thing to do is to pad
each file injected into the tar file out to a 512-byte boundary
by appending nulls, but here the file is of length 0 and we add
511 zero bytes.  Since 0 is already a multiple of 512, we should
not add any zero bytes. Do that instead.

Patch by me, reviewed by Tom Lane.

Discussion: http://postgr.es/m/CA+TgmobWbfReO9-XFk8urR1K4wTNwqoHx_v56t7=T8KaiEoKNw@mail.gmail.com

5 years agoFix full text search to handle NOT above a phrase search correctly.
Tom Lane [Mon, 27 Apr 2020 16:21:04 +0000 (12:21 -0400)]
Fix full text search to handle NOT above a phrase search correctly.

Queries such as '!(foo<->bar)' failed to find matching rows when
implemented as a GiST or GIN index search.  That's because of
failing to handle phrase searches as tri-valued when considering
a query without any position information for the target tsvector.
We can only say that the phrase operator might match, not that it
does match; and therefore its NOT also might match.  The previous
coding incorrectly inverted the approximate phrase result to
decide that there was certainly no match.

To fix, we need to make TS_phrase_execute return a real ternary result,
and then bubble that up accurately in TS_execute.  As long as we have
to do that anyway, we can simplify the baroque things TS_phrase_execute
was doing internally to manage tri-valued searching with only a bool
as explicit result.

For now, I left the externally-visible result of TS_execute as a plain
bool.  There do not appear to be any outside callers that need to
distinguish a three-way result, given that they passed in a flag
saying what to do in the absence of position data.  This might need
to change someday, but we wouldn't want to back-patch such a change.

Although tsginidx.c has its own TS_execute_ternary implementation for
use at upper index levels, that sadly managed to get this case wrong
as well :-(.  Fixing it is a lot easier fortunately.

Per bug #16388 from Charles Offenbacher.  Back-patch to 9.6 where
phrase search was introduced.

Discussion: https://postgr.es/m/16388-98cffba38d0b7e6e@postgresql.org

5 years agoDoc: render &pi; more nicely in PDF output.
Tom Lane [Mon, 27 Apr 2020 15:00:28 +0000 (11:00 -0400)]
Doc: render &pi; more nicely in PDF output.

We need to select symbol font explicitly, or it comes out misaligned.

Alexander Lakhin, Tom Lane

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

5 years agopg_dump: Replace can't-happen error with assertion
Peter Eisentraut [Mon, 27 Apr 2020 12:24:20 +0000 (14:24 +0200)]
pg_dump: Replace can't-happen error with assertion

5 years agoFix some typos
Michael Paquier [Mon, 27 Apr 2020 05:59:36 +0000 (14:59 +0900)]
Fix some typos

Author: Justin Pryzby
Discussion: https://postgr.es/m/20200408165653.GF2228@telsasoft.com

5 years agoDoc: improve documentation of websearch_to_tqsuery().
Tom Lane [Sun, 26 Apr 2020 15:45:54 +0000 (11:45 -0400)]
Doc: improve documentation of websearch_to_tqsuery().

It wasn't totally clear about punctuation other than what's
specified being ignored.

Pavel Borisov and Tom Lane

Discussion: https://postgr.es/m/CALT9ZEFsBdsogVjG40Z4KfM1Um=wj1FE9hJ00GK3oVfzz0sFNg@mail.gmail.com

5 years agoFix typo
Peter Eisentraut [Sun, 26 Apr 2020 11:48:33 +0000 (13:48 +0200)]
Fix typo

from 303640199d0

5 years agoRaise a timeout to 180s, in test 003_recovery_targets.pl.
Noah Misch [Sun, 26 Apr 2020 01:45:27 +0000 (18:45 -0700)]
Raise a timeout to 180s, in test 003_recovery_targets.pl.

Buildfarm member chipmunk has failed twice due to taking >30s, and
twenty-four runs of other members have used >5s.  The test is new in
v13, so no back-patch.

5 years agoFix another minor page deletion buffer lock issue.
Peter Geoghegan [Sat, 25 Apr 2020 23:45:20 +0000 (16:45 -0700)]
Fix another minor page deletion buffer lock issue.

Avoid accessing the leaf page's top parent tuple without a buffer lock
held during the second phase of nbtree page deletion.  The old approach
was safe, though only because VACUUM never drops its buffer pin (and
because only VACUUM itself can modify a half-dead page).  Even still, it
seems like a good idea to be strict here.  Tighten things up by copying
the top parent page's block number to a local variable before releasing
the buffer lock on the leaf page -- not after.

This is a follow-up to commit fa7ff642, which fixed a similar issue in
the first phase of nbtree page deletion.

Update some related comments in passing.

Discussion: https://postgr.es/m/CAH2-WzkLgyN3zBvRZ1pkNJThC=xi_0gpWRUb_45eexLH1+k2_Q@mail.gmail.com

5 years agoFix minor nbtree page deletion buffer lock issue.
Peter Geoghegan [Sat, 25 Apr 2020 21:17:02 +0000 (14:17 -0700)]
Fix minor nbtree page deletion buffer lock issue.

Avoid accessing the deletion target page's special area during nbtree
page deletion at a point where there is no buffer lock held.  This issue
was detected by a patch that extends Valgrind's memcheck tool to mark
nbtree pages that are unsafe to access (due to not having a buffer lock
or buffer pin) as NOACCESS.

We do hold a buffer pin at this point, and only access the special area,
so the old approach was safe.  Even still, it seems like a good idea to
tighten up the rules in this area.  There is no reason to not simply
insist on always holding a buffer lock (not just a pin) when accessing
nbtree pages.

Update some related comments in passing.

Discussion: https://postgr.es/m/CAH2-WzkLgyN3zBvRZ1pkNJThC=xi_0gpWRUb_45eexLH1+k2_Q@mail.gmail.com

5 years agoIn caught-up logical walsender, sleep only in WalSndWaitForWal().
Noah Misch [Sat, 25 Apr 2020 17:18:12 +0000 (10:18 -0700)]
In caught-up logical walsender, sleep only in WalSndWaitForWal().

Before sleeping, WalSndWaitForWal() sends a keepalive if MyWalSnd->write
< sentPtr.  When the latest physical LSN yields no logical replication
messages (a common case), that keepalive elicits a reply.  Processing
the reply updates pg_stat_replication.replay_lsn.  WalSndLoop() lacks
that; when WalSndLoop() slept, replay_lsn advancement could stall until
wal_receiver_status_interval elapsed.  This sometimes stalled
src/test/subscription/t/001_rep_changes.pl for up to 10s.

Reviewed by Fujii Masao and Michael Paquier.

Discussion: https://postgr.es/m/20200418070142.GA1075445@rfd.leadboat.com

5 years agoRevert "When WalSndCaughtUp, sleep only in WalSndWaitForWal()."
Noah Misch [Sat, 25 Apr 2020 17:17:26 +0000 (10:17 -0700)]
Revert "When WalSndCaughtUp, sleep only in WalSndWaitForWal()."

This reverts commit 421685812290406daea58b78dfab0346eb683bbb.  It caused
idle physical walsenders to busy-wait, as reported by Fujii Masao.

Discussion: https://postgr.es/m/20200417054146.GA1061007@rfd.leadboat.com

5 years agoFix error case for CREATE ROLE ... IN ROLE.
Andrew Gierth [Sat, 25 Apr 2020 04:09:30 +0000 (05:09 +0100)]
Fix error case for CREATE ROLE ... IN ROLE.

CreateRole() was passing a Value node, not a RoleSpec node, for the
newly-created role name when adding the role as a member of existing
roles for the IN ROLE syntax.

This mistake went unnoticed because the node in question is used only
for error messages and is not accessed on non-error paths.

In older pg versions (such as 9.5 where this was found), this results
in an "unexpected node type" error in place of the real error. That
node type check was removed at some point, after which the code would
accidentally fail to fail on 64-bit platforms (on which accessing the
Value node as if it were a RoleSpec would be mostly harmless) or give
an "unexpected role type" error on 32-bit platforms.

Fix the code to pass the correct node type, and add an lfirst_node
assertion just in case.

Per report on irc from user m1chelangelo.

Backpatch all the way, because this error has been around for a long
time.

5 years agoUpdate Windows timezone name list to include currently-known zones.
Tom Lane [Fri, 24 Apr 2020 21:53:23 +0000 (17:53 -0400)]
Update Windows timezone name list to include currently-known zones.

Thanks to Juan José Santamaría Flecha.

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

5 years agoImprove placement of "display name" comment in win32_tzmap[] entries.
Tom Lane [Fri, 24 Apr 2020 21:21:44 +0000 (17:21 -0400)]
Improve placement of "display name" comment in win32_tzmap[] entries.

Sticking this comment at the end of the last line was a bad idea: it's
not particularly readable, and it tempts pgindent to mess with line
breaks within the comment, which in turn reveals that win32tzlist.pl's
clean_displayname() does the wrong thing to clean up such line breaks.
While that's not hard to fix, there's basically no excuse for this
arrangement to begin with, especially since it makes the table layout
needlessly vary across back branches with different pgindent rules.
Let's just put the comment inside the braces, instead.

This commit just moves and reformats the comments, and updates
win32tzlist.pl to match; there's no actual data change.

Per odd-looking results from Juan José Santamaría Flecha.
Back-patch, since the point is to make win32_tzmap[] look the
same in all supported branches again.

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

5 years agoDoc: update section 9.13 for new function table layout.
Tom Lane [Fri, 24 Apr 2020 19:51:35 +0000 (15:51 -0400)]
Doc: update section 9.13 for new function table layout.

This includes the usual amount of editorial cleanup, such as
correcting wrong or less-helpful-than-they-could-be examples.

I moved the two tsvector-updating triggers into "9.28 Trigger
Functions", which seems like a better home for them.  (I believe
that section didn't exist when this text was originally written.)

5 years agogit_changelog: use modern format for rel branch names in example
Bruce Momjian [Fri, 24 Apr 2020 19:16:04 +0000 (15:16 -0400)]
git_changelog: use modern format for rel branch names in example

e.g., REL_12_STABLE

5 years agoTry to avoid compiler warnings in optimized builds.
Robert Haas [Fri, 24 Apr 2020 18:08:29 +0000 (14:08 -0400)]
Try to avoid compiler warnings in optimized builds.

Per report from Andres Freund, who also says that this fix
works for him.

Discussion: http://postgr.es/m/20200405193118.alprgmozhxcfabkw@alap3.anarazel.de

5 years agoRepair performance regression in information_schema.triggers view.
Tom Lane [Fri, 24 Apr 2020 16:02:36 +0000 (12:02 -0400)]
Repair performance regression in information_schema.triggers view.

Commit 32ff26911 introduced use of rank() into the triggers view to
calculate the spec-mandated action_order column.  As written, this
prevents query constraints on the table-name column from being pushed
below the window aggregate step.  That's bad for performance of this
typical usage pattern, since the view now has to be evaluated for all
tables not just the one(s) the user wants to see.  It's also the cause
of some recent buildfarm failures, in which trying to evaluate the view
rows for triggers in process of being dropped resulted in "cache lookup
failed for function NNN" errors.  Those rows aren't of interest to the
test script doing the query, but the filter that would eliminate them
is being applied too late.  None of this happened before the rank()
call was there, so it's a regression compared to v10 and before.

We can improve matters by changing the rank() call so that instead of
partitioning by OIDs, it partitions by nspname and relname, casting
those to sql_identifier so that they match the respective view output
columns exactly.  The planner has enough intelligence to know that
constraints on partitioning columns are safe to push down, so this
eliminates the performance problem and the regression test failure
risk.  We could make the other partitioning columns match view outputs
as well, but it'd be more complicated and the performance benefits
are questionable.

Side note: as this stands, the planner will push down constraints on
event_object_table and trigger_schema, but not on event_object_schema,
because it checks for ressortgroupref matches not expression
equivalence.  That might be worth improving someday, but it's not
necessary to fix the immediate concern.

Back-patch to v11 where the rank() call was added.  Ordinarily we'd not
change information_schema in released branches, but the test failure has
been seen in v12 and presumably could happen in v11 as well, so we need
to do this to keep the buildfarm happy.  The change is harmless so far
as users are concerned.  Some might wish to apply it to existing
installations if performance of this type of query is of concern,
but those who don't are no worse off.

I bumped catversion in HEAD as a pro forma matter (there's no
catalog incompatibility that would really require a re-initdb).
Obviously that can't be done in the back branches.

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

5 years agoUpdate time zone data files to tzdata release 2020a.
Tom Lane [Fri, 24 Apr 2020 14:54:47 +0000 (10:54 -0400)]
Update time zone data files to tzdata release 2020a.

DST law changes in Morocco and the Canadian Yukon.
Historical corrections for Shanghai.

The America/Godthab zone is renamed to America/Nuuk to reflect
current English usage; however, the old name remains available as a
compatibility link.

5 years agoUpdate Unicode data to Unicode 13.0.0 and CLDR 37
Peter Eisentraut [Fri, 24 Apr 2020 07:33:22 +0000 (09:33 +0200)]
Update Unicode data to Unicode 13.0.0 and CLDR 37