users/rhaas/postgres.git
5 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

5 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

5 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.

5 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

5 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/[email protected]
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 <[email protected]>
Co-authored-by: Álvaro Herrera <[email protected]>
Discussion: https://postgr.es/m/20200408.141956.891237856186513376[email protected]

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 <[email protected]>
Reviewed-by: Álvaro Herrera <[email protected]>
Discussion: https://postgr.es/m/20200408.093710.447591748588426656[email protected]

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[email protected]

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[email protected]

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[email protected]

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[email protected]

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[email protected]

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

5 years agoRemove some unstable parts from new TAP test for archive status check
Michael Paquier [Fri, 24 Apr 2020 02:33:41 +0000 (11:33 +0900)]
Remove some unstable parts from new TAP test for archive status check

The test is proving to have timing issues when looking at archive status
files on standbys after crash recovery, while other parts of the test
rely on pg_stat_archiver as a wait point to make sure that a given state
of the archiving is reached.  The coverage is not heavily impacted by
the removal those extra tests.

Per reports from several buildfarm animals, like crake, piculet,
culicidae and francolin.

Discussion: https://postgr.es/m/20200424005929[email protected]
Backpatch-through: 9.5

5 years agoFix handling of WAL segments ready to be archived during crash recovery
Michael Paquier [Thu, 23 Apr 2020 23:48:28 +0000 (08:48 +0900)]
Fix handling of WAL segments ready to be archived during crash recovery

78ea8b5 has fixed an issue related to the recycling of WAL segments on
standbys depending on archive_mode.  However, it has introduced a
regression with the handling of WAL segments ready to be archived during
crash recovery, causing those files to be recycled without getting
archived.

This commit fixes the regression by tracking in shared memory if a live
cluster is either in crash recovery or archive recovery as the handling
of WAL segments ready to be archived is different in both cases (those
WAL segments should not be removed during crash recovery), and by using
this new shared memory state to decide if a segment can be recycled or
not.  Previously, it was not possible to know if a cluster was in crash
recovery or archive recovery as the shared state was able to track only
if recovery was happening or not, leading to the problem.

A set of TAP tests is added to close the gap here, making sure that WAL
segments ready to be archived are correctly handled when a cluster is in
archive or crash recovery with archive_mode set to "on" or "always", for
both standby and primary.

Reported-by: Benoît Lobréau
Author: Jehan-Guillaume de Rorthais
Reviewed-by: Kyotaro Horiguchi, Fujii Masao, Michael Paquier
Discussion: https://postgr.es/m/20200331172229.40ee00dc@firost
Backpatch-through: 9.5

5 years agoRemove ACLDEBUG #define and associated code.
Tom Lane [Thu, 23 Apr 2020 19:38:04 +0000 (15:38 -0400)]
Remove ACLDEBUG #define and associated code.

In the footsteps of aaf069aa3, remove ACLDEBUG, which was the only
other remaining undocumented symbol in pg_config_manual.h.  The fact
that nobody had bothered to document it in seventeen years is a good
clue to its usefulness.  In practice, none of the tracing logic it
enabled would be of any value without additional effort.

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

5 years agoRemove useless (and broken) logging logic in memory context functions.
Tom Lane [Thu, 23 Apr 2020 19:27:37 +0000 (15:27 -0400)]
Remove useless (and broken) logging logic in memory context functions.

Nobody really uses this stuff, especially not since we created
valgrind-based infrastructure that does the same thing better.
It is thus unsurprising that the generation.c and slab.c versions
were actually broken.  Rather than fix 'em, let's just remove 'em.

Alexander Lakhin

Discussion: https://postgr.es/m/8936216c-3492-3f6e-634b-d638fddc5f91@gmail.com

5 years agoDoc: update section 9.12 for new function table layout.
Tom Lane [Thu, 23 Apr 2020 19:12:42 +0000 (15:12 -0400)]
Doc: update section 9.12 for new function table layout.

Also rearrange that page a bit for more consistency and less
duplication.

In passing, fix erroneous examples of the results of abbrev(cidr)
in datatype.sgml, and do a bit of copy-editing there.

5 years agoAlso rename 'struct manifest_info'.
Robert Haas [Thu, 23 Apr 2020 13:47:50 +0000 (09:47 -0400)]
Also rename 'struct manifest_info'.

The previous commit renamed the struct's typedef, but not the struct
name itself.

5 years agoRename exposed identifiers to say "backup manifest".
Robert Haas [Thu, 23 Apr 2020 12:44:06 +0000 (08:44 -0400)]
Rename exposed identifiers to say "backup manifest".

Function names declared "extern" now use BackupManifest in the name
rather than just Manifest, and data types use backup_manifest
rather than just manifest.

Per note from Michael Paquier.

Discussion: http://postgr.es/m/20200418125713[email protected]

5 years agoFix transient memory leak for SRFs in FROM.
Andres Freund [Thu, 23 Apr 2020 02:52:07 +0000 (19:52 -0700)]
Fix transient memory leak for SRFs in FROM.

In a9c35cf85ca I changed ExecMakeTableFunctionResult() to dynamically
allocate the FunctionCallInfo used to call the SRF. Unfortunately I
did not account for the fact that the surrounding memory context has
query lifetime, leading to a leak till the end of the query.

In most cases the leak is fairly inconsequential, but if the
FunctionScan is done many times in the query, the leak can add
up. This happens e.g. if the function scan is on the inner side of a
nested loop, due to a lateral join.
EXPLAIN SELECT sum(f) FROM generate_series(1, 100000000) g(i), generate_series(i, i+1) f;
quickly shows the leak.

Instead of explicitly freeing the FunctionCallInfo it seems better to
make sure all the per-set temporary state in
ExecMakeTableFunctionResult() is cleaned up wholesale. Currently
that's probably just the FunctionCallInfo allocation, but since
there's some initialization work, and since there's already an
appropriate context, this seems like a more robust approach.

Bug: #16112
Reported-By: Ben Cornett
Author: Andres Freund
Reviewed-By: Tom Lane
Discussion: https://postgr.es/m/16112-4448bbf55a404189%40postgresql.org
Backpatch: 12, a9c35cf85ca

5 years agoFix option related issues in pg_verifybackup.
Fujii Masao [Thu, 23 Apr 2020 02:32:17 +0000 (11:32 +0900)]
Fix option related issues in pg_verifybackup.

This commit does:

- get rid of the garbage code for unused --print-parse-wal option.
- add help message for --quiet option into usage().
- fix typo of option name in help message.

Author: Fujii Masao
Reviewed-by: Robert Haas
Discussion: https://postgr.es/m/ff4710f7-2331-4f6b-012e-d76da3275e91@oss.nttdata.com

5 years agoDoc: improve description of geometric multiplication/division.
Tom Lane [Thu, 23 Apr 2020 01:32:38 +0000 (21:32 -0400)]
Doc: improve description of geometric multiplication/division.

David Johnston reminded me that the per-point calculations being done
by these operators are equivalent to complex multiplication/division.
(Once I would've recognized that immediately, but it's been too long
since I did any of that sort of math.)

Also put in a footnote mentioning that "rotation" of a box doesn't do
what you might expect, as I'd griped about in the referenced thread.

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

5 years agonbtree: Rename BT_RESERVED_OFFSET_MASK.
Peter Geoghegan [Wed, 22 Apr 2020 23:09:55 +0000 (16:09 -0700)]
nbtree: Rename BT_RESERVED_OFFSET_MASK.

The mask was added by commit 8224de4f, which introduced INCLUDE nbtree
indexes.  The status bits really were reserved initially.  We now use 2
out of 4 of the bits for additional tuple metadata, though.  Rename the
mask to BT_STATUS_OFFSET_MASK.

Also consolidate related nbtree.h code comments about the format of
pivot tuples and posting list tuples.

5 years agoFix cost_incremental_sort for expressions with varno 0
Tomas Vondra [Wed, 22 Apr 2020 22:15:24 +0000 (00:15 +0200)]
Fix cost_incremental_sort for expressions with varno 0

When estimating the number of pre-sorted groups in cost_incremental_sort
we must not pass Vars with varno 0 to estimate_num_groups, which would
cause failues in find_base_rel. This may happen when sorting output of
set operations, thanks to generate_append_tlist.

Unlike recurse_set_operations we can't easily access the original target
list, so if we find any Vars with varno 0, we fall back to the default
estimate DEFAULT_NUM_DISTINCT.

Reported-by: Justin Pryzby
Discussion: https://postgr.es/m/20200411214639.GK2228%40telsasoft.com

5 years agodocs: land height is "elevation", not "altitude"
Bruce Momjian [Wed, 22 Apr 2020 20:23:19 +0000 (16:23 -0400)]
docs:  land height is "elevation", not "altitude"

See https://mapscaping.com/blogs/geo-candy/what-is-the-difference-between-elevation-relief-and-altitude
No patching of regression tests.

Reported-by: [email protected]
Discussion: https://postgr.es/m/158506544539.679.2278386310645558048@wrigleys.postgresql.org

Backpatch-through: 9.5

5 years agoSync up some inconsistent comments in config/c-compiler.m4.
Tom Lane [Wed, 22 Apr 2020 19:27:43 +0000 (15:27 -0400)]
Sync up some inconsistent comments in config/c-compiler.m4.

Make header/trailer comments agree with the actual names of some macros.
These seem like legit names in earlier iterations of respective patches
(commit b779168ff "Detect PG_PRINTF_ATTRIBUTE automatically." and
commit 6869b4f25 "Add C++ support to configure.") but the macro had
been renamed out of sync with the header / trailer comment in the final
committed patch.

Even more nitpickily, make the dashed underlines agree with the lengths
of the macro names everyplace.  There doesn't seem to have been any
meeting of the minds previously on whether those should match or not,
but at least some people have been trying to make 'em match.

Jesse Zhang, Tom Lane

Discussion: https://postgr.es/m/CAGf+fX7DDyq6WfCy6X_KtD28MkbNBE6NkRi26fSf25dfUwX0zw@mail.gmail.com

5 years agoDoc: update section 9.11 for new function table layout.
Tom Lane [Wed, 22 Apr 2020 18:43:26 +0000 (14:43 -0400)]
Doc: update section 9.11 for new function table layout.

This also makes an attempt to flesh out the docs for some of the more
severely underdocumented geometric operators and functions.

This effort exposed that the point <^ point (point_below) and
point >^ point (point_above) operators are misnamed; they should be
<<| and |>>, because they act like the other operators named that
way and not like the other operators named <^ and >^.  But I just
documented them that way; fixing it is matter for another patch.

The haphazard datatype coverage of many of the operators is also
now depressingly obvious.

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

5 years agoRemove bogus Assert in foreign key cloning code
David Rowley [Wed, 22 Apr 2020 10:12:19 +0000 (22:12 +1200)]
Remove bogus Assert in foreign key cloning code

This Assert was trying to ensure that the number of columns in the foreign
key being cloned was the same number of attributes in the parentRel.  Of
course, it's perfectly valid to have columns in the table which are not
part of the foreign key constraint. It appears that this Assert was
misunderstanding that.

Reported-by: Rajkumar Raghuwanshi
Reviewed-by: amul sul
Discussion: https://postgr.es/m/CAKcux6=z1dtiWw5BOpqDx-U6KTiq+zD0Y2m810zUtWL+giVXWA@mail.gmail.com

5 years agoRemove HEAPDEBUGALL
Peter Eisentraut [Tue, 21 Apr 2020 17:57:33 +0000 (19:57 +0200)]
Remove HEAPDEBUGALL

This has been broken since PostgreSQL 12 and was probably never really
used.  PostgreSQL 12 added an analogous HEAPAMSLOTDEBUGALL, which
still works right now, but it's also not very useful, so remove that
as well.

Discussion: https://www.postgresql.org/message-id/flat/645c0646-4218-d4c3-409a-a7003a0c108d%402ndquadrant.com

5 years agoFix single-record reads to use restore_command if available in pg_rewind
Michael Paquier [Tue, 21 Apr 2020 23:08:28 +0000 (08:08 +0900)]
Fix single-record reads to use restore_command if available in pg_rewind

readOneRecord() is used now when looking for a checkpoint record to
check if the target server is an ancestor of the source across multiple
timelines, and using a restore_command if available improves the
stability of the operation.  This part was missed in a7e8ece.

Reported-by: Kyotaro Horiguchi
Discussion: https://postgr.es/m/20200421.150830.1410714948345179794[email protected]

5 years agopsql \d: Display table where trigger is defined, if inherited
Alvaro Herrera [Tue, 21 Apr 2020 22:37:26 +0000 (18:37 -0400)]
psql \d: Display table where trigger is defined, if inherited

It's important to know that a trigger is cloned from a parent table,
because of the behavior that the trigger is dropped on detach.  Make
psql's \d display it.

We'd like to backpatch, but lack of the pg_trigger.tgparentid column
makes it more difficult.  Punt for now.  If somebody wants to volunteer
an implementation that reads pg_depend on older versions, that can
probably be backpatched.

Authors: Justin Pryzby, Amit Langote, Álvaro Herrera
Discussion: https://postgr.es/m/20200419002206[email protected]

5 years agoFix memory leak in libpq when using sslmode=verify-full
Michael Paquier [Tue, 21 Apr 2020 22:27:03 +0000 (07:27 +0900)]
Fix memory leak in libpq when using sslmode=verify-full

Checking if Subject Alternative Names (SANs) from a certificate match
with the hostname connected to leaked memory after each lookup done.

This is broken since acd08d7 that added support for SANs in SSL
certificates, so backpatch down to 9.5.

Author: Roman Peshkurov
Reviewed-by: Hamid Akhtar, Michael Paquier, David Steele
Discussion: https://postgr.es/m/CALLDf-pZ-E3mjxd5=bnHsDu9zHEOnpgPgdnO84E2RuwMCjjyPw@mail.gmail.com
Backpatch-through: 9.5

5 years agoDocument partitiong tables ancillary object handling some more
Alvaro Herrera [Tue, 21 Apr 2020 21:14:18 +0000 (17:14 -0400)]
Document partitiong tables ancillary object handling some more

Add a couple of lines to make it explicit that indexes, constraints,
triggers are added, removed, or left alone.

Backpatch to pg11.

Author: Álvaro Herrera <[email protected]>
Reviewed-by: Justin Pryzby <[email protected]>
Discussion: https://postgr.es/m/20200421162038[email protected]

5 years agoFix possible crash during FATAL exit from reindexing.
Tom Lane [Tue, 21 Apr 2020 19:58:42 +0000 (15:58 -0400)]
Fix possible crash during FATAL exit from reindexing.

index.c supposed that it could just use a PG_TRY block to clean up the
state associated with an active REINDEX operation.  However, that code
doesn't run if we do a FATAL exit --- for example, due to a SIGTERM
shutdown signal --- while the REINDEX is happening.  And that state does
get consulted during catalog accesses, which makes it problematic if we
do any catalog accesses during shutdown --- for example, to clean up any
temp tables created in the session.

If this combination of circumstances occurred, we could find ourselves
trying to access already-freed memory.  In debug builds that'd fairly
reliably cause an assertion failure.  In production we might often
get away with it, but with some bad luck it could cause a core dump.

Another possible bad outcome is an erroneous conclusion that an
index-to-be-accessed is being reindexed; but it looks like that would
be unlikely to have any consequences worse than failing to drop temp
tables right away.  (They'd still get dropped by the next session that
uses that temp schema.)

To fix, get rid of the use of PG_TRY here, and instead hook into
the transaction abort mechanisms to clean up reindex state.

Per bug #16378 from Alexander Lakhin.  This has been wrong for a
very long time, so back-patch to all supported branches.

Discussion: https://postgr.es/m/16378-7a70ca41b3ec2009@postgresql.org

5 years agoFix minor violations of FunctionCallInvoke usage protocol.
Tom Lane [Tue, 21 Apr 2020 18:23:42 +0000 (14:23 -0400)]
Fix minor violations of FunctionCallInvoke usage protocol.

Working on commit 1c455078b led me to check through FunctionCallInvoke
call sites to see if every one was being honest about (a) making sure
that fcinfo.isnull is initially false, and (b) checking its state after
the call.  Sure enough, I found some violations.

The main one is that finalize_partialaggregate re-used serialfn_fcinfo
without resetting isnull, even though it clearly intends to cater for
serialfns that return NULL.  There would only be an issue with a
non-strict serialfn, since it's unlikely that a serialfn would return
NULL for non-null input.  We have no non-strict serialfns in core, and
there may be none in the wild either, which would account for the lack
of complaints.  Still, it's clearly wrong, so back-patch that fix to
9.6 where finalize_partialaggregate was introduced.

Also, arrayfuncs.c and rowtypes.c contained various callers that were
not bothering to check for result nulls.  While what's being called is
a comparison or hash function that probably *shouldn't* return null,
that's a lousy excuse for not having any check at all.  There are
existing places that just Assert(!fcinfo->isnull) in comparable
situations, so I added that to the places that were calling btree
comparison or hash support functions.  In the places calling
boolean-returning equality functions, it's quite cheap to have them
treat isnull as FALSE, so make those places do that.  Also remove some
"locfcinfo->isnull = false" assignments that are unnecessary given the
assumption that no previous call returned null.  These changes seem like
mostly neatnik-ism or debugging support, so I didn't back-patch.

5 years agoFix detaching partitions with cloned row triggers
Alvaro Herrera [Tue, 21 Apr 2020 17:57:00 +0000 (13:57 -0400)]
Fix detaching partitions with cloned row triggers

When a partition is detached, any triggers that had been cloned from its
parent were not properly disentangled from its parent triggers.
This resulted in triggers that could not be dropped because they
depended on the trigger in the trigger in the no-longer-parent table:
  ALTER TABLE t DETACH PARTITION t1;
  DROP TRIGGER trig ON t1;
    ERROR:  cannot drop trigger trig on table t1 because trigger trig on table t requires it
    HINT:  You can drop trigger trig on table t instead.

Moreover the table can no longer be re-attached to its parent, because
the trigger name is already taken:
  ALTER TABLE t ATTACH PARTITION t1 FOR VALUES FROM (1)TO(2);
    ERROR:  trigger "trig" for relation "t1" already exists

The former is a bug introduced in commit 86f575948c77.  (The latter is
not necessarily a bug, but it makes the bug more uncomfortable.)

To avoid the complexity that would be needed to tell whether the trigger
has a local definition that has to be merged with the one coming from
the parent table, establish the behavior that the trigger is removed
when the table is detached.

Backpatch to pg11.

Author: Justin Pryzby <[email protected]>
Reviewed-by: Amit Langote <[email protected]>
Reviewed-by: Álvaro Herrera <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/20200408152412[email protected]

5 years agoConsider outliers in split interval calculation.
Peter Geoghegan [Tue, 21 Apr 2020 16:59:24 +0000 (09:59 -0700)]
Consider outliers in split interval calculation.

Commit 0d861bbb, which introduced deduplication to nbtree, added some
logic to take large posting list tuples into account when choosing a
split point.  We subtract firstright posting list overhead from the
projected new high key size when calculating leftfree/rightfree values
for an affected candidate split point.  Posting list tuples aren't
special to nbtsplitloc.c, but taking them into account like this makes a
huge difference in practice.  Posting list tuples are frequently tuple
size outliers.

However, commit 0d861bbb missed a closely related issue: split interval
itself is calculated based on the assumption that tuples on the page
being split are roughly equisized.  That assumption was acceptable back
when commit fab25024 taught the logic for choosing a split point about
suffix truncation, but it's pretty questionable now that very large
tuple sizes are common.  This oversight led to unbalanced page splits in
low cardinality multi-column indexes when deduplication was used: page
splits that don't give sufficient weight to how unbalanced the split is
when the interval happens to include some large posting list tuples (and
when most other tuples on the page are not so large).

Nail this down by calculating an initial split interval in a way that's
attuned to the actual cost that we want to keep under control (not a
fuzzy proxy for the cost): apply a leftfree + rightfree evenness test to
each candidate split point that actually gets included in the split
interval (for the default strategy).  This replaces logic that used a
percentage of all legal split points for the page as the basis of the
initial split interval.

Discussion: https://postgr.es/m/CAH2-WznJt5aT2uUB2Bs+JBLdwe0XTX67+xeLFcaNvCKxO=QBVQ@mail.gmail.com

5 years agoAllow matchingsel() to be used with operators that might return NULL.
Tom Lane [Tue, 21 Apr 2020 16:56:55 +0000 (12:56 -0400)]
Allow matchingsel() to be used with operators that might return NULL.

Although selfuncs.c will never call a target operator with null inputs,
some functions might return null anyway.  The existing coding will fail
if that happens (since FunctionCall2Coll will punt), which seems
undesirable given that matchingsel() has such a broad range of potential
applicability --- in fact, we already have a problem because we apply it
to jsonb_path_exists_opr, which can return null.  Hence, rejigger the
underlying functions mcv_selectivity and histogram_selectivity to cope,
treating a null result as false.

While we are at it, we can move the InitFunctionCallInfoData overhead
out of the inner loops, which isn't a huge number of cycles but might
save something considering we are likely calling functions as cheap
as int4eq().  Plus, the number of loop cycles to be expected is much
more than it was when this code was written, since typical settings
of default_statistics_target are higher.

In view of that consideration, let's apply the same change to
var_eq_const, eqjoinsel_inner, and eqjoinsel_semi.  We do not expect
equality functions to ever return null for non-null inputs (and
certainly that code has been that way a long time without complaints),
but the cycle savings seem attractive, especially in the eqjoinsel loops
where there's potentially an O(N^2) savings.

Similar code exists in ineq_histogram_selectivity and
get_variable_range, but I forebore from changing those for now.
The performance argument for changing ineq_histogram_selectivity
is really weak anyway, since that will only iterate log2(N) times.

Nikita Glukhov and Tom Lane

Discussion: https://postgr.es/m/9d3b0959-95d6-c37e-2c0b-287bcfe5c705@postgrespro.ru

5 years agoClean up cpluspluscheck violation.
Tom Lane [Tue, 21 Apr 2020 15:21:15 +0000 (11:21 -0400)]
Clean up cpluspluscheck violation.

"operator" is a reserved word in C++, so per project conventions,
don't use it as an identifier in header files.

My oversight in commit a80818605.

5 years agoFix duplicate typedef from commit 0d8c9c121.
Tom Lane [Tue, 21 Apr 2020 15:13:05 +0000 (11:13 -0400)]
Fix duplicate typedef from commit 0d8c9c121.

Older gcc versions don't like duplicate typedefs, so get rid of
that in favor of doing it like we do it elsewhere, ie just use
a "struct" declaration when trying to avoid importing a whole
header file.

Also, there seems no reason to include stringinfo.h here at all,
so get rid of that addition too.

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

5 years agoMention pg_promote() as a method to trigger promotion in documentation.
Fujii Masao [Tue, 21 Apr 2020 05:05:43 +0000 (14:05 +0900)]
Mention pg_promote() as a method to trigger promotion in documentation.

Previously in the "Standby Server Operation" section, pg_ctl promote and
protmote_trigger_file were documented as a method to trigger standby
promotion, but pg_promote() function not.

This commit also adds parentheses into <function>pg_promote</function>
in some docs to make it clearer that a function is being referred to.

Author: Masahiro Ikeda
Reviewed-by: Michael Paquier, Laurenz Albe, Tom Lane, Fujii Masao
Discussion: https://postgr.es/m/de0068417a9f4046bac693cbcc00bdc9@oss.nttdata.com

5 years agodoc: change SGML markup "figure" to "example"
Bruce Momjian [Tue, 21 Apr 2020 01:41:13 +0000 (21:41 -0400)]
doc:  change SGML markup "figure" to "example"

Reported-by: Jürgen Purtz
Discussion: https://postgr.es/m/709d7809-d7f4-8175-47f3-4d131341bba8@purtz.de

Author: Jürgen Purtz

Backpatch-through: 9.5

5 years agoDoc: update sections 9.7 and 9.8 for new function table layout.
Tom Lane [Mon, 20 Apr 2020 22:44:12 +0000 (18:44 -0400)]
Doc: update sections 9.7 and 9.8 for new function table layout.

Also some mop-up in section 9.9.

5 years agoMove the server's backup manifest code to a separate file.
Robert Haas [Mon, 20 Apr 2020 18:37:38 +0000 (14:37 -0400)]
Move the server's backup manifest code to a separate file.

basebackup.c is already a pretty big and complicated file, so it
makes more sense to keep the backup manifest support routines
in a separate file, for clarity and ease of maintenance.

Discussion: http://postgr.es/m/CA+TgmoavRak5OdP76P8eJExDYhPEKWjMb0sxW7dF01dWFgE=uA@mail.gmail.com

5 years agoAdd tab-completion for ALTER INDEX .. [NO] DEPENDS ON
Alvaro Herrera [Mon, 20 Apr 2020 17:42:41 +0000 (13:42 -0400)]
Add tab-completion for ALTER INDEX .. [NO] DEPENDS ON

... as added in the prior commit.

(We'd like to have tab-completion for the other object types too, but
they don't have sub-command completion yet.)

Author: Ibrar Ahmed <[email protected]>
Reviewed-by: Álvaro Herrera <[email protected]>
Discussion: https://postgr.es/m/CALtqXTcogrFEVP9uou5vFtnGsn+vHZUu9+9a0inarfYVOHScYQ@mail.gmail.com

5 years agoAdd ALTER .. NO DEPENDS ON
Alvaro Herrera [Mon, 20 Apr 2020 17:42:12 +0000 (13:42 -0400)]
Add ALTER .. NO DEPENDS ON

Commit f2fcad27d59c (9.6 era) added the ability to mark objects as
dependent an extension, but forgot to add a way for such dependencies to
be removed.  This commit fixes that oversight.

Strictly speaking this should be backpatched to 9.6, but due to lack of
demand we're not doing so at this time.

Discussion: https://postgr.es/m/20200217225333[email protected]
Reviewed-by: ahsan hadi <[email protected]>
Reviewed-by: Ibrar Ahmed <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
5 years agoDoc: update sections 9.5 and 9.6 for new function table layout.
Tom Lane [Mon, 20 Apr 2020 16:29:28 +0000 (12:29 -0400)]
Doc: update sections 9.5 and 9.6 for new function table layout.

Along the way, update the older examples for bytea to use "hex"
output format.  That lets us get rid of the lame disclaimer about
how the examples assume bytea_output = escape, which was only half
true anyway because none of the more-recently-added examples had
paid any attention to that.