]> granicus.if.org Git - postgresql/log
postgresql
4 years agoAlways skip recovery SysV shared memory tests on Windows
Andrew Dunstan [Fri, 6 Sep 2019 19:47:23 +0000 (15:47 -0400)]
Always skip recovery SysV shared memory tests on Windows

The test for SysV support currently involves looking for the perl
modules IPC::SharedMem and IPC::SysV. However, the perl on msys2 has
these modules but the tests fail. Therefore, force skipping the tests on
Windows platforms unconditionally.

Discussion: https://postgr.es/m/176e86ba-1a46-9d8c-5ae4-9865a463b411@2ndQuadrant.com

4 years agoDoc: tweak installation doc edits made by commit 76c2af926.
Tom Lane [Fri, 6 Sep 2019 15:24:36 +0000 (11:24 -0400)]
Doc: tweak installation doc edits made by commit 76c2af926.

We don't consider that building with MinGW is deprecated,
so adjust some places that gave that impression.
Per discussion with Peter Eisentraut.

Discussion: https://postgr.es/m/4a023388-8652-fea0-a0b4-35ad5e734e9a@2ndquadrant.com

4 years agoCreate an API for inserting and deleting rows in TOAST tables.
Robert Haas [Fri, 6 Sep 2019 14:38:51 +0000 (10:38 -0400)]
Create an API for inserting and deleting rows in TOAST tables.

This moves much of the non-heap-specific logic from toast_delete and
toast_insert_or_update into a helper functions accessible via a new
header, toast_helper.h.  Using the functions in this module, a table
AM can implement creation and deletion of TOAST table rows with
much less code duplication than was possible heretofore.  Some
table AMs won't want to use the TOAST logic at all, but for those
that do this will make that easier.

Patch by me, reviewed and tested by Prabhat Sabu, Thomas Munro,
Andres Freund, and Álvaro Herrera.

Discussion: http://postgr.es/m/CA+TgmoZv-=2iWM4jcw5ZhJeL18HF96+W1yJeYrnGMYdkFFnEpQ@mail.gmail.com

4 years agoWhen performing a base backup, check for read errors.
Robert Haas [Fri, 6 Sep 2019 12:22:32 +0000 (08:22 -0400)]
When performing a base backup, check for read errors.

The old code didn't differentiate between a read error and a
concurrent truncation. fread reports both of these by returning 0;
you have to use feof() or ferror() to distinguish between them,
which this code did not do.

It might be a better idea to use read() rather than fread() here,
so that we can display a less-generic error message, but I'm not
sure that would qualify as a back-patchable bug fix, so just do
this much for now.

Jeevan Chalke, reviewed by Jeevan Ladhe and by me.

Discussion: http://postgr.es/m/CA+TgmobG4ywMzL5oQq2a8YKp8x2p3p1LOMMcGqpS7aekT9+ETA@mail.gmail.com

4 years agolibpq: ccache -> credential cache
Peter Eisentraut [Fri, 6 Sep 2019 07:15:35 +0000 (09:15 +0200)]
libpq: ccache -> credential cache

The term "ccache" is overloaded.  Let's be more clear, in case someone
other than a Kerberos wizard has to read this code.

4 years agoMake pg_promote() detect postmaster death while waiting for promotion to end.
Fujii Masao [Fri, 6 Sep 2019 05:27:25 +0000 (14:27 +0900)]
Make pg_promote() detect postmaster death while waiting for promotion to end.

Previously even if postmaster died and WaitLatch() woke up with that event
while pg_promote() was waiting for the standby promotion to finish,
pg_promote() did nothing special and kept waiting until timeout occurred.
This could cause a busy loop.

This patch make pg_promote() return false immediately when postmaster
dies, to avoid such a busy loop.

Back-patch to v12 where pg_promote() was added.

Author: Fujii Masao
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/CAHGQGwEs9ROgSp+QF+YdDU+xP8W=CY1k-_Ov-d_Z3JY+to3eXA@mail.gmail.com

4 years agoMake use of generic logging in vacuumlo and oid2name
Michael Paquier [Fri, 6 Sep 2019 05:00:13 +0000 (14:00 +0900)]
Make use of generic logging in vacuumlo and oid2name

Doing the switch reduces the footprint of "progname" in both utilities
for the messages produced.  This also cleans up a couple of
inconsistencies in the message formats.

Author: Michael Paquier
Reviewed-by: Álvaro Herrera, Peter Eisentraut
Discussion: https://postgr.es/m/20190820012819.GA8326@paquier.xyz

4 years agoUse data directory inode number, not port, to select SysV resource keys.
Tom Lane [Thu, 5 Sep 2019 17:31:41 +0000 (13:31 -0400)]
Use data directory inode number, not port, to select SysV resource keys.

This approach provides a much tighter binding between a data directory
and the associated SysV shared memory block (and SysV or named-POSIX
semaphores, if we're using those).  Key collisions are still possible,
but only between data directories stored on different filesystems,
so the situation should be negligible in practice.  More importantly,
restarting the postmaster with a different port number no longer
risks failing to identify a relevant shared memory block, even when
postmaster.pid has been removed.  A standalone backend is likewise
much more certain to detect conflicting leftover backends.

(In the longer term, we might now think about deprecating the port as
a cluster-wide value, so that one postmaster could support sockets
with varying port numbers.  But that's for another day.)

The hazards fixed here apply only on Unix systems; our Windows code
paths already use identifiers derived from the data directory path
name rather than the port.

src/test/recovery/t/017_shm.pl, which intends to test key-collision
cases, has been substantially rewritten since it can no longer use
two postmasters with identical port numbers to trigger the case.
Instead, use Perl's IPC::SharedMem module to create a conflicting
shmem segment directly.  The test script will be skipped if that
module is not available.  (This means that some older buildfarm
members won't run it, but I don't think that that results in any
meaningful coverage loss.)

Patch by me; thanks to Noah Misch and Peter Eisentraut for discussion
and review.

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

4 years agoSplit tuptoaster.c into three separate files.
Robert Haas [Mon, 8 Jul 2019 15:58:05 +0000 (11:58 -0400)]
Split tuptoaster.c into three separate files.

detoast.c/h contain functions required to detoast a datum, partially
or completely, plus a few other utility functions for examining the
size of toasted datums.

toast_internals.c/h contain functions that are used internally to the
TOAST subsystem but which (mostly) do not need to be accessed from
outside.

heaptoast.c/h contains code that is intrinsically specific to the
heap AM, either because it operates on HeapTuples or is based on the
layout of a heap page.

detoast.c and toast_internals.c are placed in
src/backend/access/common rather than src/backend/access/heap.  At
present, both files still have dependencies on the heap, but that will
be improved in a future commit.

Patch by me, reviewed and tested by Prabhat Sabu, Thomas Munro,
Andres Freund, and Álvaro Herrera.

Discussion: http://postgr.es/m/CA+TgmoZv-=2iWM4jcw5ZhJeL18HF96+W1yJeYrnGMYdkFFnEpQ@mail.gmail.com

4 years agoUse explicit_bzero
Peter Eisentraut [Thu, 5 Sep 2019 06:15:58 +0000 (08:15 +0200)]
Use explicit_bzero

Use the explicit_bzero() function in places where it is important that
security information such as passwords is cleared from memory.  There
might be other places where it could be useful; this is just an
initial collection.

For platforms that don't have explicit_bzero(), provide various
fallback implementations.  (explicit_bzero() itself isn't standard,
but as Linux/glibc, FreeBSD, and OpenBSD have it, it's the most common
spelling, so it makes sense to make that the invocation point.)

Discussion: https://www.postgresql.org/message-id/flat/42d26bde-5d5b-c90d-87ae-6cab875f73be%402ndquadrant.com

4 years agoFix thinko when ending progress report for a backend
Michael Paquier [Wed, 4 Sep 2019 06:46:37 +0000 (15:46 +0900)]
Fix thinko when ending progress report for a backend

The logic ending progress reporting for a backend entry introduced by
b6fb647 causes callers of pgstat_progress_end_command() to do some extra
work when track_activities is enabled as the process fields are reset in
the backend entry even if no command were started for reporting.

This resets the fields only if a command is registered for progress
reporting, and only if track_activities is enabled.

Author: Masahiho Sawada
Discussion: https://postgr.es/m/CAD21AoCry_vJ0E-m5oxJXGL3pnos-xYGCzF95rK5Bbi3Uf-rpA@mail.gmail.com
Backpatch-through: 9.6

4 years agoDelay fsyncs of pg_basebackup until the end of backup
Michael Paquier [Wed, 4 Sep 2019 04:21:11 +0000 (13:21 +0900)]
Delay fsyncs of pg_basebackup until the end of backup

Since the addition of fsync requests in bc34223 to make base backup data
consistent on disk once pg_basebackup finishes, each tablespace tar file
is individually flushed once completed, with an additional flush of the
parent directory when the base backup finishes.  While holding a
connection to the server, a fsync request taking a long time may cause a
failure of the base backup, which is annoying for any integration.  A
recent example of breakage can involve tcp_user_timeout, but
wal_sender_timeout can cause similar problems.

While reviewing the code, there was a second issue causing too many
fsync requests to be done for the same WAL data.  As recursive fsyncs
are done at the end of the backup for both the plain and tar formats
from the base target directory where everything is written, it is fine
to disable fsyncs when fetching or streaming WAL.

Reported-by: Ryohei Takahashi
Author: Michael Paquier
Reviewed-by: Ryohei Takahashi
Discussion: https://postgr.es/m/OSBPR01MB4550DAE2F8C9502894A45AAB82BE0@OSBPR01MB4550.jpnprd01.prod.outlook.com
Backpatch-through: 10

4 years agoMake XLogReaderInvalReadState static
Alvaro Herrera [Tue, 3 Sep 2019 21:41:43 +0000 (17:41 -0400)]
Make XLogReaderInvalReadState static

This function is only used by xlogreader.c itself, so there's no need to
export it.  It was introduced by commit 3b02ea4f0780 with the apparent
intention that it could be used externally, but I couldn't find any
external code calling it.

I (Álvaro) couldn't resist the urge to sort nearby function prototypes
properly while at it.

Author: Antonin Houska
Discussion: https://postgr.es/m/14984.1554998742@spoje.net

4 years agoRemove 'msg' parameter from convert_tuples_by_name
Alvaro Herrera [Tue, 3 Sep 2019 18:47:29 +0000 (14:47 -0400)]
Remove 'msg' parameter from convert_tuples_by_name

The message was included as a parameter when this function was added in
dcb2bda9b704, but I don't think it has ever served any useful purpose.
Let's stop spreading it pointlessly.

Reviewed by Amit Langote and Peter Eisentraut.

Discussion: https://postgr.es/m/20190806224728.GA17233@alvherre.pgsql

4 years agoClarify pg_dump documentation
Peter Eisentraut [Tue, 3 Sep 2019 12:25:26 +0000 (14:25 +0200)]
Clarify pg_dump documentation

Clarify in the help output and documentation that -n, -t etc. take a
"pattern" rather than a "schema" or "table" etc.  This was especially
confusing now that the new pg_dumpall --exclude-database option was
documented with "pattern" and the others not, even though they all
behave the same.

Discussion: https://www.postgresql.org/message-id/flat/b85f3fa1-b350-38d1-1893-4f7911bd7310%402ndquadrant.com

4 years agoImprove base backup protocol documentation
Peter Eisentraut [Tue, 3 Sep 2019 09:59:36 +0000 (11:59 +0200)]
Improve base backup protocol documentation

Document that the tablespace sizes are in units of kilobytes.  Make
the pg_basebackup source code a bit clearer about this, too.

Reviewed-by: Magnus Hagander <magnus@hagander.net>
4 years agopg_checksums: Handle read and write returns correctly
Peter Eisentraut [Tue, 3 Sep 2019 06:26:55 +0000 (08:26 +0200)]
pg_checksums: Handle read and write returns correctly

The read() return was not checking for errors, the write() return was
not checking for short writes.

Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://www.postgresql.org/message-id/flat/5de61b6b-8be9-7771-0048-860328efe027%402ndquadrant.com

4 years agoBetter error messages for short reads/writes in SLRU
Peter Eisentraut [Tue, 3 Sep 2019 06:26:55 +0000 (08:26 +0200)]
Better error messages for short reads/writes in SLRU

This avoids getting a

    Could not read from file ...: Success.

for a short read or write (since errno is not set in that case).
Instead, report a more specific error messages.

Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://www.postgresql.org/message-id/flat/5de61b6b-8be9-7771-0048-860328efe027%402ndquadrant.com

4 years agoDoc: Replace mention to "K bytes" by "kilobytes" in textsearch.sgml
Michael Paquier [Tue, 3 Sep 2019 04:03:29 +0000 (13:03 +0900)]
Doc: Replace mention to "K bytes" by "kilobytes" in textsearch.sgml

"kB" or "kilobyte" is used in the documentation.

Author: Daniel Gustafsson
Discussion: https://postgr.es/m/32BA3AF7-37E9-4334-A226-98B844ADCC4E@yesql.se

4 years agoFix memory leak with lower, upper and initcap with ICU-provided collations
Michael Paquier [Tue, 3 Sep 2019 03:30:53 +0000 (12:30 +0900)]
Fix memory leak with lower, upper and initcap with ICU-provided collations

The leak happens in str_tolower, str_toupper and str_initcap, which are
used in several places including their equivalent SQL-level functions,
and can only be triggered when using an ICU-provided collation when
converting the input string.

b615920 fixed a similar leak.  Backpatch down 10 where ICU collations
have been introduced.

Author: Konstantin Knizhnik
Discussion: https://postgr.es/m/94c0ad0a-cbc2-e4a3-7829-2bdeaf9146db@postgrespro.ru
Backpatch-through: 10

4 years agoAvoid touching replica identity index in ExtractReplicaIdentity().
Tom Lane [Mon, 2 Sep 2019 20:10:37 +0000 (16:10 -0400)]
Avoid touching replica identity index in ExtractReplicaIdentity().

In what seems like a fit of misplaced optimization,
ExtractReplicaIdentity() accessed the relation's replica-identity
index without taking any lock on it.  Usually, the surrounding query
already holds some lock so this is safe enough ... but in the case
of a previously-planned delete, there might be no existing lock.
Given a suitable test case, this is exposed in v12 and HEAD by an
assertion added by commit b04aeb0a0.

The whole thing's rather poorly thought out anyway; rather than
looking directly at the index, we should use the index-attributes
bitmap that's held by the parent table's relcache entry, as the
caller functions do.  This is more consistent and likely a bit
faster, since it avoids a cache lookup.  Hence, change to doing it
that way.

While at it, rather than blithely assuming that the identity
columns are non-null (with catastrophic results if that's wrong),
add assertion checks that they aren't null.  Possibly those should
be actual test-and-elog, but I'll leave it like this for now.

In principle, this is a bug that's been there since this code was
introduced (in 9.4).  In practice, the risk seems quite low, since
we do have a lock on the index's parent table, so concurrent
changes to the index's catalog entries seem unlikely.  Given the
precedent that commit 9c703c169 wasn't back-patched, I won't risk
back-patching this further than v12.

Per report from Hadi Moshayedi.

Discussion: https://postgr.es/m/CAK=1=Wrek44Ese1V7LjKiQS-Nd-5LgLi_5_CskGbpggKEf3tKQ@mail.gmail.com

4 years agoHandle corner cases correctly in psql's reconnection logic.
Tom Lane [Mon, 2 Sep 2019 18:02:45 +0000 (14:02 -0400)]
Handle corner cases correctly in psql's reconnection logic.

After an unexpected connection loss and successful reconnection,
psql neglected to resynchronize its internal state about the server,
such as server version.  Ordinarily we'd be reconnecting to the same
server and so this isn't really necessary, but there are scenarios
where we do need to update --- one example is where we have a list
of possible connection targets and they're not all alike.

Define "resynchronize" as including connection_warnings(), so that
this case acts the same as \connect.  This seems useful; for example,
if the server version did change, the user might wish to know that.
An attuned user might also notice that the new connection isn't
SSL-encrypted, for example, though this approach isn't especially
in-your-face about such changes.  Although this part is a behavioral
change, it only affects interactive sessions, so it should not break
any applications.

Also, in do_connect, make sure that we desynchronize correctly when
abandoning an old connection in non-interactive mode.

These problems evidently are the result of people patching only one
of the two places where psql deals with connection changes, so insert
some cross-referencing comments in hopes of forestalling future bugs
of the same ilk.

Lastly, in Windows builds, issue codepage mismatch warnings only at
startup, not during reconnections.  psql's codepage can't change
during a reconnect, so complaining about it again seems like useless
noise.

Peter Billen and Tom Lane.  Back-patch to all supported branches.

Discussion: https://postgr.es/m/CAMTXbE8e6U=EBQfNSe01Ej17CBStGiudMAGSOPaw-ALxM-5jXg@mail.gmail.com

4 years agoAdd POD documentation to TestLib.pm
Alvaro Herrera [Mon, 2 Sep 2019 17:37:57 +0000 (13:37 -0400)]
Add POD documentation to TestLib.pm

This module was pretty much undocumented.  Fix that.

Inspired by a preliminary patch sent by Ramanarayana, heavily updated by
Andrew Dunstan, and reviewed by Michael Paquier.

Discussion: https://postgr.es/m/CAF6A77G_WJTwBV9SBxCnQfZB09hm1p1O3stZ6eE5QiYd=X84Jg@mail.gmail.com

4 years agoAdd overflow-safe math inline functions for unsigned integers
Michael Paquier [Mon, 2 Sep 2019 00:38:23 +0000 (09:38 +0900)]
Add overflow-safe math inline functions for unsigned integers

Similarly to the signed versions added in 4d6ad31, this adds a set of
inline functions for overflow checks with unsigned integers, including
uint16, uint32 and uint64.  This relies on compiler built-in overflow
checks by default if available.  The behavior of unsigned integers is
well-defined so the fallback implementations checks are simple for
additions and subtractions.  Multiplications avoid division-based checks
which are expensive if possible, still this can happen for uint64 if
128-bit integers are not available.

While on it, the code in common/int.h is reorganized to avoid too many
duplicated comments.  The new macros will be used in a follow-up patch.

All thanks to Andres Freund for the input provided.

Author: Fabien Coelho, Michael Paquier
Discussion: https://postgr.es/m/20190830073423.GB2354@paquier.xyz

4 years agoFix compiler warning
Peter Eisentraut [Sun, 1 Sep 2019 21:19:51 +0000 (23:19 +0200)]
Fix compiler warning

Fix a warning about unused variable on Windows when using OpenSSL.

4 years agoDoc: describe the "options" allowed in an ECPG connection target string.
Tom Lane [Sat, 31 Aug 2019 18:05:32 +0000 (14:05 -0400)]
Doc: describe the "options" allowed in an ECPG connection target string.

These have been there a long time, but their format was never explained
in the docs.  Per complaint from Yusuke Egashira.

Discussion: https://postgr.es/m/848B1649C8A6274AA527C4472CA11EDD5FC70CBE@G01JPEXMBYT02

4 years agoCosmetic improvements for options-handling code in ECPGconnect().
Tom Lane [Sat, 31 Aug 2019 17:37:10 +0000 (13:37 -0400)]
Cosmetic improvements for options-handling code in ECPGconnect().

The comment describing the string format was a lie.  Make it agree with
reality, add/improve some other comments, fix coding style for loops with
empty bodies.  Also add an Assert that we counted parameters correctly,
because the spread-out logic for that looks pretty fragile.

No actual bugs fixed here, so no need to back-patch.

Discussion: https://postgr.es/m/848B1649C8A6274AA527C4472CA11EDD5FC70CBE@G01JPEXMBYT02

4 years agoDoc: restructure documentation of the configure script's options.
Tom Lane [Fri, 30 Aug 2019 19:44:00 +0000 (15:44 -0400)]
Doc: restructure documentation of the configure script's options.

The list of configure options has grown long, and there was next
to no organization to it, never mind any indication of which options
were interesting to most people.  Break it into several sub-sections
to provide a bit of structure, and add some introductory text where
it seems helpful to point people to particular options.

I failed to resist the temptation to do a small amount of
word-smithing on some of the option descriptions, too.
But mostly this is reorganization and addition of intro text.

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

4 years agoDoc: remove some long-obsolete information from installation.sgml.
Tom Lane [Fri, 30 Aug 2019 17:02:35 +0000 (13:02 -0400)]
Doc: remove some long-obsolete information from installation.sgml.

Section 16.2 pointed to platform-specific FAQ files that we removed
way back in 8.4.  Section 16.7 contained a bunch of information about
AIX and HPUX bugs that were squashed decades ago, plus discussions of
old compiler versions that are certainly moot now that we require C99
support.  Since we're obviously not maintaining this stuff carefully,
just remove it.  The HPUX sub-section seems like it can go away
entirely, since everything it said that was still applicable was
redundant with material elsewhere in the chapter.

In passing, I couldn't resist the temptation to do a small amount
of copy-editing on nearby text.

Back-patch to v12, since this stuff is surely obsolete in any
branch that requires C99.

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

4 years agoError out on too many command-line arguments
Peter Eisentraut [Thu, 29 Aug 2019 14:19:35 +0000 (16:19 +0200)]
Error out on too many command-line arguments

Fix up oid2name, pg_upgrade, and pgbench to error out on too many
command-line arguments.  This makes it match the behavior of other
PostgreSQL programs.

Author: Peter Eisentraut, Ibrar Ahmed
Discussion: https://www.postgresql.org/message-id/flat/f2554627-04e7-383a-ef01-ab99bb6a291c%402ndquadrant.com

4 years agoFix typos in regression test comments.
Etsuro Fujita [Thu, 29 Aug 2019 09:45:00 +0000 (18:45 +0900)]
Fix typos in regression test comments.

4 years agoAdd .gitignore file forgotten in commit bde7493d1.
Tom Lane [Wed, 28 Aug 2019 16:59:47 +0000 (12:59 -0400)]
Add .gitignore file forgotten in commit bde7493d1.

4 years agoFix overflow check and comment in GIN posting list encoding.
Heikki Linnakangas [Wed, 28 Aug 2019 09:55:33 +0000 (12:55 +0300)]
Fix overflow check and comment in GIN posting list encoding.

The comment did not match what the code actually did for integers with
the 43rd bit set. You get an integer like that, if you have a posting
list with two adjacent TIDs that are more than 2^31 blocks apart.
According to the comment, we would store that in 6 bytes, with no
continuation bit on the 6th byte, but in reality, the code encodes it
using 7 bytes, with a continuation bit on the 6th byte as normal.

The decoding routine also handled these 7-byte integers correctly, except
for an overflow check that assumed that one integer needs at most 6 bytes.
Fix the overflow check, and fix the comment to match what the code
actually does. Also fix the comment that claimed that there are 17 unused
bits in the 64-bit representation of an item pointer. In reality, there
are 64-32-11=21.

Fitting any item pointer into max 6 bytes was an important property when
this was written, because in the old pre-9.4 format, item pointers were
stored as plain arrays, with 6 bytes for every item pointer. The maximum
of 6 bytes per integer in the new format guaranteed that we could convert
any page from the old format to the new format after upgrade, so that the
new format was never larger than the old format. But we hardly need to
worry about that anymore, and running into that problem during upgrade,
where an item pointer is expanded from 6 to 7 bytes such that the data
doesn't fit on a page anymore, is implausible in practice anyway.

Backpatch to all supported versions.

This also includes a little test module to test these large distances
between item pointers, without requiring a 16 TB table. It is not
backpatched, I'm including it more for the benefit of future development
of new posting list formats.

Discussion: https://www.postgresql.org/message-id/33bfc20a-5c86-f50c-f5a5-58e9925d05ff%40iki.fi
Reviewed-by: Masahiko Sawada, Alexander Korotkov
4 years agoAvoid catalog lookups in RelationAllowsEarlyPruning().
Thomas Munro [Wed, 28 Aug 2019 01:37:03 +0000 (13:37 +1200)]
Avoid catalog lookups in RelationAllowsEarlyPruning().

RelationAllowsEarlyPruning() performed a catalog scan, but is used
in two contexts where that was a bad idea:

1.  In heap_page_prune_opt(), which runs very frequently in some large
    scans.  This caused major performance problems in a field report
    that was easy to reproduce.

2.  In TestForOldSnapshot(), which runs while we hold a buffer content
    lock.  It's not clear if this was guaranteed to be free of buffer
    deadlock risk.

The check was introduced in commit 2cc41acd8 and defended against a
real problem: 9.6's hash indexes have no page LSN and so we can't
allow early pruning (ie the snapshot-too-old feature).  We can remove
the check from all later releases though: hash indexes are now logged,
and there is no way to create UNLOGGED indexes on regular logged
tables.

If a future release allows such a combination, it might need to put
a similar check in place, but it'll need some more thought.

Back-patch to 10.

Author: Thomas Munro
Reviewed-by: Tom Lane, who spotted the second problem
Discussion: https://postgr.es/m/CA%2BhUKGKT8oTkp5jw_U4p0S-7UG9zsvtw_M47Y285bER6a2gD%2Bg%40mail.gmail.com
Discussion: https://postgr.es/m/CAA4eK1%2BWy%2BN4eE5zPm765h68LrkWc3Biu_8rzzi%2BOYX4j%2BiHRw%40mail.gmail.com

4 years agoImprove coverage of utils/float.h
Michael Paquier [Wed, 28 Aug 2019 03:28:16 +0000 (12:28 +0900)]
Improve coverage of utils/float.h

check_float4_val() checks after underflow and overflow of values
converted from float8 to float4, but there has never been any regression
tests for that.  This brings the coverage of float.h to 100%.

Author: Movead Li
Discussion: https://postgr.es/m/20190822174636998766188@highgo.ca

4 years agoDisable timeouts when running pg_rewind with online source cluster
Michael Paquier [Wed, 28 Aug 2019 02:47:35 +0000 (11:47 +0900)]
Disable timeouts when running pg_rewind with online source cluster

In this case, the transfer uses a libpq connection, which is subject to
the timeout parameters set at system level, and this can make the rewind
operation suddenly canceled which is not good for automation.  One
workaround to such issues would be to use PGOPTIONS to enforce the
wanted timeout parameters, but that's annoying, and for example pg_dump,
which can run potentially long-running queries disables all types of
timeouts.

lock_timeout and statement_timeout are the ones which can cause problems
now.  Note that pg_rewind does not use transactions, so disabling
idle_in_transaction_session_timeout is optional, but it feels safer to
do so for the future.

This is back-patched down to 9.5.  idle_in_transaction_session_timeout
is only present since 9.6.

Author: Alexander Kukushkin
Discussion: https://postgr.es/m/CAFh8B=krcVXksxiwVQh1SoY+ziJ-JC=6FcuoBL3yce_40Es5_g@mail.gmail.com
Backpatch-through: 9.5

4 years agoSet application_name per-test in isolation and ecpg tests.
Tom Lane [Tue, 27 Aug 2019 23:49:09 +0000 (19:49 -0400)]
Set application_name per-test in isolation and ecpg tests.

Commit a4327296d taught pg_regress proper to do this, but
missed the opportunity to do likewise in the isolationtester
and ecpg variants of pg_regress.  Seems like this might be
helpful for tracking down issues exposed by those tests.

4 years agoDoc: improve documentation of pg_signal_backend default role.
Tom Lane [Tue, 27 Aug 2019 22:03:09 +0000 (18:03 -0400)]
Doc: improve documentation of pg_signal_backend default role.

Give it an explanatory para like the other default roles have.
Don't imply that it can send any signal whatever.

In passing, reorder the table entries and explanatory paras
for the default roles into some semblance of consistency.

Ian Barwick, tweaked a bit by me.

Discussion: https://postgr.es/m/89907e32-76f3-7282-a89c-ea19c722fe5d@2ndquadrant.com

4 years agoImprove what pg_strsignal prints if we haven't got strsignal(3).
Tom Lane [Tue, 27 Aug 2019 21:24:13 +0000 (17:24 -0400)]
Improve what pg_strsignal prints if we haven't got strsignal(3).

Turns out that returning "unrecognized signal" is confusing.
Make it explicit that the platform lacks any support for signal names.
(At least of the machines in the buildfarm, only HPUX lacks it.)

Back-patch to v12 where we invented this function.

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

4 years agoRemove obsolete nbtree page deletion comment.
Peter Geoghegan [Tue, 27 Aug 2019 21:01:43 +0000 (14:01 -0700)]
Remove obsolete nbtree page deletion comment.

Commit efada2b8e92, which made the nbtree page deletion algorithm more
robust, removed the concept of a half-dead internal page.  Remove a
comment about half dead parent pages that was overlooked.

4 years agoDoc: clarify behavior of standard aggregates for null inputs.
Tom Lane [Tue, 27 Aug 2019 20:37:21 +0000 (16:37 -0400)]
Doc: clarify behavior of standard aggregates for null inputs.

Section 4.2.7 says that unless otherwise specified, built-in
aggregates ignore rows in which any input is null.  This is
not true of the JSON aggregates, but it wasn't documented.
Fix that.

Of the other entries in table 9.55, some were explicit about
ignoring nulls, and some weren't; for consistency and
self-contained-ness, make them all say it explicitly.

Per bug #15884 from Tim Möhlmann.  Back-patch to all supported
branches.

Discussion: https://postgr.es/m/15884-c32d848f787fcae3@postgresql.org

4 years agoAdd missing newline in help output.
Tom Lane [Tue, 27 Aug 2019 19:14:55 +0000 (15:14 -0400)]
Add missing newline in help output.

Daniel Gustafsson

Discussion: https://postgr.es/m/F2FB03F2-B112-4E51-842E-12C50DCA2F4A@yesql.se

4 years agoReject empty names and recursion in config-file include directives.
Tom Lane [Tue, 27 Aug 2019 18:44:26 +0000 (14:44 -0400)]
Reject empty names and recursion in config-file include directives.

An empty file name or subdirectory name leads join_path_components() to
just produce the parent directory name, which leads to weird failures or
recursive inclusions.  Let's throw a specific error for that.  It takes
only slightly more code to detect all-blank names, so do so.

Also, detect direct recursion, ie a file calling itself.  As coded
this will also detect recursion via "include_dir '.'", which is
perhaps more likely than explicitly including the file itself.

Detecting indirect recursion would require API changes for guc-file.l
functions, which seems not worth it since extensions might call them.
The nesting depth limit will catch such cases eventually, just not
with such an on-point error message.

In passing, adjust the example usages in postgresql.conf.sample
to perhaps eliminate the problem at the source: there's no reason
for the examples to suggest that an empty value is valid.

Per a trouble report from Brent Bates.  Back-patch to 9.5; the
issue is old, but the code in 9.4 is enough different that the
patch doesn't apply easily, and it doesn't seem worth the trouble
to fix there.

Ian Barwick and Tom Lane

Discussion: https://postgr.es/m/8c8bcbca-3bd9-dc6e-8986-04a5abdef142@2ndquadrant.com

4 years agoFix failure of --jobs with reindexdb and vacuumdb on Windows
Michael Paquier [Tue, 27 Aug 2019 00:11:31 +0000 (09:11 +0900)]
Fix failure of --jobs with reindexdb and vacuumdb on Windows

FD_SETSIZE needs to be declared before winsock2.h, or it is possible to
run into buffer overflow issues when using --jobs.  This is similar to
pgbench's solution done in a23c641.

This has been introduced by 71d84ef, and older versions have been using
the default value of FD_SETSIZE, defined at 64.

Per buildfarm member jacana, but this impacts all Windows animals
running the TAP tests.  I have reproduced the failure locally to check
the patch.

Author: Michael Paquier
Reviewed-by: Andrew Dunstan
Discussion: https://postgr.es/m/20190826054000.GE7005@paquier.xyz
Backpatch-through: 9.5

4 years agoFix 007_sync_rep.pl to notice failures in ALTER SYSTEM SET.
Tom Lane [Mon, 26 Aug 2019 21:02:52 +0000 (17:02 -0400)]
Fix 007_sync_rep.pl to notice failures in ALTER SYSTEM SET.

If a test case tried to set an invalid value of synchronous_standby_names,
the test script didn't detect that, which seems like a bad idea.
Noticed while testing a proposed patch that broke some of these
test cases.

4 years agoFix postmaster state machine to handle dead_end child crashes better.
Tom Lane [Mon, 26 Aug 2019 19:59:44 +0000 (15:59 -0400)]
Fix postmaster state machine to handle dead_end child crashes better.

A report from Alvaro Herrera shows that if we're in PM_STARTUP
state, and we spawn a dead_end child to reject some incoming
connection request, and that child dies with an unexpected exit
code, the postmaster does not respond well.  We correctly send
SIGQUIT to the startup process, but then:

* if the startup process exits with nonzero exit code, as expected,
we thought that that indicated a crash and aborted startup.

* if the startup process exits with zero exit code, which is possible
due to the inherent race condition, we'd advance to PM_RUN state
which is fine --- but the code forgot that AbortStartTime would be
nonzero in this situation.  We'd either die on the Asserts saying
that it was zero, or perhaps misbehave later on.  (A quick look
suggests that the only misbehavior might be busy-waiting due to
DetermineSleepTime doing the wrong thing.)

To fix the first point, adjust the state-machine logic to recognize
that a nonzero exit code is expected after sending SIGQUIT, and have
it transition to a state where we can restart the startup process.
To fix the second point, change the Asserts to clear the variable
rather than just claiming it should be clear already.

Perhaps we could improve this further by not treating a crash of
a dead_end child as a reason for panic'ing the database.  However,
since those child processes are connected to shared memory, that
seems a bit risky.  There are few good reasons for a dead_end child
to report failure anyway (the cause of this in Alvaro's report is
quite unclear).  On balance, therefore, a minimal fix seems best.

This is an oversight in commit 45811be94.  While that was back-patched,
I'm hesitant to back-patch this change.  The lack of reasons for a
dead_end child to fail suggests that the case should be very rare in
the field, which squares with the lack of reports; so it seems like
this might not be worth the risk of introducing new issues.  In any
case we can let it bake awhile in HEAD before considering a back-patch.

Discussion: https://postgr.es/m/20190615160950.GA31378@alvherre.pgsql

4 years agoMake comment in fmgr.h match the one in fmgr.c.
Tom Lane [Mon, 26 Aug 2019 18:32:40 +0000 (14:32 -0400)]
Make comment in fmgr.h match the one in fmgr.c.

Incompletely quoting an API spec does nobody any good.  Noted by
Paul Jungwirth.  Looks like the discrepancy was my fault originally :-(

Discussion: https://postgr.es/m/CA+renyU_J8TU_d3Kr0PkuOgFbpypextendu7a+_d5NOfVdvDeA@mail.gmail.com

4 years agoFix gettext triggers specification
Peter Eisentraut [Mon, 26 Aug 2019 17:04:35 +0000 (19:04 +0200)]
Fix gettext triggers specification

In cc8d41511721d25d557fc02a46c053c0a602fed0, the arguments of
warn_or_exit_horribly() were changed but this was not updated.

4 years agoAdjust to latest Msys2 kernel release number
Andrew Dunstan [Mon, 26 Aug 2019 12:11:27 +0000 (08:11 -0400)]
Adjust to latest Msys2 kernel release number

Previously 'uname -r' on Msys2 reported a kernele release starting with
2. The latest version starts with 3. In commit 1638623f we specifically
looked for one starting with 2. This is now changed to look for any
digit between 2 and 9.

backpatch to release 10.

4 years agoTreat MINGW and MSYS the same in pg_upgrade test script
Andrew Dunstan [Mon, 26 Aug 2019 11:44:34 +0000 (07:44 -0400)]
Treat MINGW and MSYS the same in pg_upgrade test script

On msys2, 'uname -s' reports a string starting MSYS instead on MINGW
as happens on msys1. Treat these both the same way. This reverts
608a710195a4b in favor of a more general solution.

Backpatch to all live branches.

4 years agoFix error handling of vacuumdb and reindexdb when running out of fds
Michael Paquier [Mon, 26 Aug 2019 02:14:18 +0000 (11:14 +0900)]
Fix error handling of vacuumdb and reindexdb when running out of fds

When trying to use a high number of jobs, vacuumdb (and more recently
reindexdb) has only checked for a maximum number of jobs used, causing
confusing failures when running out of file descriptors when the jobs
open connections to Postgres.  This commit changes the error handling so
as we do not check anymore for a maximum number of allowed jobs when
parsing the option value with FD_SETSIZE, but check instead if a file
descriptor is within the supported range when opening the connections
for the jobs so as this is detected at the earliest time possible.

Also, improve the error message to give a hint about the number of jobs
recommended, using a wording given by the reviewers of the patch.

Reported-by: Andres Freund
Author: Michael Paquier
Reviewed-by: Andres Freund, Álvaro Herrera, Tom Lane
Discussion: https://postgr.es/m/20190818001858.ho3ev4z57fqhs7a5@alap3.anarazel.de
Backpatch-through: 9.5

4 years agoAvoid platform-specific null pointer dereference in psql.
Tom Lane [Sun, 25 Aug 2019 19:04:04 +0000 (15:04 -0400)]
Avoid platform-specific null pointer dereference in psql.

POSIX permits getopt() to advance optind beyond argc when the last
argv entry is an option that requires an argument and hasn't got one.
It seems that no major platforms actually do that, but musl does,
so that something like "psql -f" would crash with that libc.
Add a check that optind is in range before trying to look at the
possibly-bogus option.

Report and fix by Quentin Rameau.  Back-patch to all supported
branches.

Discussion: https://postgr.es/m/20190825100617.GA6087@fifth.space

4 years agoBack off output precision in circle.sql regression test.
Tom Lane [Sun, 25 Aug 2019 16:14:50 +0000 (12:14 -0400)]
Back off output precision in circle.sql regression test.

We were setting extra_float_digits = 0 to avoid platform-dependent
output in this test, but that's still able to expose platform-specific
roundoff behavior in some new test cases added by commit a3d284485,
as reported by Peter Eisentraut.  Reduce it to -1 to hide that.

(Over in geometry.sql, we're using -3, which is an ancient decision
dating to 337f73b1b.  I wonder whether that's overkill now.  But
there's probably little value in trying to change it.)

Back-patch to v12 where a3d284485 came in; there's no evidence that
we have any platform-dependent issues here before that.

Discussion: https://postgr.es/m/15551268-e224-aa46-084a-124b64095ee3@2ndquadrant.com

4 years agoDon't rely on llvm::make_unique.
Thomas Munro [Sun, 25 Aug 2019 01:54:48 +0000 (13:54 +1200)]
Don't rely on llvm::make_unique.

Bleeding-edge LLVM has stopped supplying replacements for various
C++14 library features, for people on older C++ versions.  Since we're
not ready to require C++14 yet, just use plain old new instead of
make_unique.  As revealed by buildfarm animal seawasp.

Back-patch to 11.

Reviewed-by: Andres Freund
Discussion: https://postgr.es/m/CA%2BhUKGJWG7unNqmkxg7nC5o3o-0p2XP6co4r%3D9epqYMm8UY4Mw%40mail.gmail.com

4 years agoDo more cleanup of isolation tests for test_decoding
Michael Paquier [Sat, 24 Aug 2019 03:34:37 +0000 (12:34 +0900)]
Do more cleanup of isolation tests for test_decoding

989d23b has caused its tests to be broken as the module defines unused
steps, turning the buildfarm red.

4 years agoExplain subtlety in nbtree locking protocol.
Peter Geoghegan [Sat, 24 Aug 2019 03:24:49 +0000 (20:24 -0700)]
Explain subtlety in nbtree locking protocol.

The Postgres approach to coupling locks during an ascent of the tree is
slightly different to the approach taken by Lehman and Yao.  Add a new
paragraph to the "Differences to the Lehman & Yao algorithm" section of
the nbtree README that explains the similarities and differences.

4 years agoDetect unused steps in isolation specs and do some cleanup
Michael Paquier [Sat, 24 Aug 2019 02:45:05 +0000 (11:45 +0900)]
Detect unused steps in isolation specs and do some cleanup

This is useful for developers to find out if an isolation spec is
over-engineered or if it needs more work by warning at the end of a
test run if a step is not used, generating a failure with extra diffs.

While on it, clean up all the specs which include steps not used in any
permutations to simplify them.

Author: Michael Paquier
Reviewed-by: Asim Praveen, Melanie Plageman
Discussion: https://postgr.es/m/20190819080820.GG18166@paquier.xyz

4 years agoRemove dry-run mode from isolationtester
Michael Paquier [Sat, 24 Aug 2019 02:35:43 +0000 (11:35 +0900)]
Remove dry-run mode from isolationtester

The original purpose of the dry-run mode is to be able to print all the
possible permutations from a spec file, but it has become less useful
since isolation tests has improved regarding deadlock detection as one
step not wanted by the author could block indefinitely now (originally
the step blocked would have been detected rather quickly).  Per
discussion, let's remove it.

Author: Michael Paquier
Reviewed-by: Asim Praveen, Melanie Plageman
Discussion: https://postgr.es/m/20190819080820.GG18166@paquier.xyz

4 years agoImprove documentation of pageinspect
Michael Paquier [Fri, 23 Aug 2019 11:41:06 +0000 (20:41 +0900)]
Improve documentation of pageinspect

This adds a section for heap-related functions.  These were previously
mixed with functions having a more general purpose, leading to
confusion.  While on it, add a query example for fsm_page_contents.

Backpatch down to 10, where b5e3942 introduced the subsections for
function types in pageinspect documentation.

Author: Masahiko Sawada
Discussion: https://postgr.es/m/CAD21AoDyM7E1+cK3-aWejxKTGC-wVVP2B+RnJhN6inXyeRmqzw@mail.gmail.com
Backpatch-through: 10

4 years agoUpdate SQL conformance information
Peter Eisentraut [Thu, 22 Aug 2019 13:36:30 +0000 (15:36 +0200)]
Update SQL conformance information

T612 has been fully supported since the major window function
enhancements in PostgreSQL 11, but it wasn't updated at the time.

4 years agoMake SQL/JSON error code names match SQL standard
Peter Eisentraut [Thu, 22 Aug 2019 08:17:30 +0000 (10:17 +0200)]
Make SQL/JSON error code names match SQL standard

There were some minor differences that didn't seem necessary.

Discussion: https://www.postgresql.org/message-id/flat/86b67eef-bb26-c97d-3e35-64f1fbd4f9fe%402ndquadrant.com

4 years agoDoc: Remove mention to "Visual Studio Express 2019"
Michael Paquier [Thu, 22 Aug 2019 00:58:45 +0000 (09:58 +0900)]
Doc: Remove mention to "Visual Studio Express 2019"

The "Express" flavor of Visual Studio exists up to 2017, and the
documentation referred to "Express" for Visual Studio 2019.

Author: Takuma Hoshiai
Discussion: https://postgr.es/m/20190820120231.f905542e685140258ca73d82@sraoss.co.jp
Backpatch-through: 9.4

4 years agoUpdate comments on nbtree stack struct.
Peter Geoghegan [Wed, 21 Aug 2019 20:50:27 +0000 (13:50 -0700)]
Update comments on nbtree stack struct.

Adjust the struct comment that describes how page splits use their
descent stack to cascade up the tree from the leaf level.

In passing, fix up some unrelated nbtree comments that had typos or were
obsolete.

4 years agoRemove configure detection of crypt()
Peter Eisentraut [Wed, 21 Aug 2019 19:33:05 +0000 (21:33 +0200)]
Remove configure detection of crypt()

crypt() hasn't been needed since crypt detection was removed from
PostgreSQL, so these configure checks are not necessary.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/21f88934-f00c-27f6-a9d8-7ea06d317781%402ndquadrant.com

4 years agoFix typo
Alvaro Herrera [Wed, 21 Aug 2019 15:12:44 +0000 (11:12 -0400)]
Fix typo

In early development patches, "replication origins" were called "identifiers";
almost everything was renamed, but these references to the old terminology
went unnoticed.

Reported-by: Craig Ringer
4 years agoRemove unnecessary test dependency on the contents of pg_pltemplate.
Tom Lane [Wed, 21 Aug 2019 14:43:23 +0000 (10:43 -0400)]
Remove unnecessary test dependency on the contents of pg_pltemplate.

Using pg_pltemplate as test data was probably not very forward-looking,
considering we've had many discussions around removing that catalog
altogether.  Use a nearby temp table instead, to make these two test
scripts more self-contained.  This is a better test case anyway, since
it exercises the scenario where the entries in the anyarray column
actually vary in type intra-query.

4 years agoRemove master/slave usage from plpgsql tests
Peter Eisentraut [Wed, 21 Aug 2019 09:46:37 +0000 (11:46 +0200)]
Remove master/slave usage from plpgsql tests

Author: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/E393EC88-377F-4C59-A67A-69F2A38D17C7@yesql.se

4 years agoClean up some SCRAM attribute processing
Peter Eisentraut [Tue, 20 Aug 2019 20:25:58 +0000 (22:25 +0200)]
Clean up some SCRAM attribute processing

Correct the comment for read_any_attr().  Give a clearer error message
when parsing at the end of the string, when the client-final-message
does not contain a "p" attribute (for some reason).

Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://www.postgresql.org/message-id/flat/2fb8a15b-de35-682d-a77b-edcc9c52fa12%402ndquadrant.com

4 years agoFix bogus comment
Alvaro Herrera [Tue, 20 Aug 2019 20:04:09 +0000 (16:04 -0400)]
Fix bogus comment

Author: Alexander Lakhin
Discussion: https://postgr.es/m/20190819072244.GE18166@paquier.xyz

4 years agoFix compilation failure of vacuumdb and reindexdb with OpenBSD
Michael Paquier [Tue, 20 Aug 2019 07:10:20 +0000 (16:10 +0900)]
Fix compilation failure of vacuumdb and reindexdb with OpenBSD

FD_SETSIZE is included in sys/select.h per POSIX, and this header
inclusion has been moved to scripts_parallel.c as of 5f38403 without
moving the variable, causing a compilation failure on recent versions of
OpenBSD (6.6 was the version used in the report).

In order to take care of the failure, move FD_SETSIZE directly to
scripts_parallel.c with a wrapper controlling the maximum number of
parallel slots supported, based on a suggestion by Andres Freund.

While on it, reduce the maximum number to be less than FD_SETSIZE,
leaving some room for stdin, stdout and such as they consume some file
descriptors.

The buildfarm did not complain about that, as it happens to only be
an issue on recent versions of OpenBSD and there is no coverage in this
area.  51c3e9f fixed a similar set of issues.

Bug: #15964
Reported-by: Sean Farrell
Discussion: https://postgr.es/m/15964-c1753bdfed722e04@postgresql.org

4 years agoDoc: Improve wording of multiple places in documentation
Michael Paquier [Tue, 20 Aug 2019 03:36:31 +0000 (12:36 +0900)]
Doc: Improve wording of multiple places in documentation

This has been found during its translation.

Author: Liudmila Mantrova
Discussion: https://postgr.es/m/CAEkD-mDJHV3bhgezu3MUafJLoAKsOOT86+wHukKU8_NeiJYhLQ@mail.gmail.com
Backpatch-through: 12

4 years agoRestore json{b}_populate_record{set}'s ability to take type info from AS.
Tom Lane [Mon, 19 Aug 2019 22:00:57 +0000 (18:00 -0400)]
Restore json{b}_populate_record{set}'s ability to take type info from AS.

If the record argument is NULL and has no declared type more concrete
than RECORD, we can't extract useful information about the desired
rowtype from it.  In this case, see if we're in FROM with an AS clause,
and if so extract the needed rowtype info from AS.

It worked like this before v11, but commit 37a795a60 removed the
behavior, reasoning that it was undocumented, inefficient, and utterly
not self-consistent.  If you want to take type info from an AS clause,
you should be using the json_to_record() family of functions not the
json_populate_record() family.  Also, it was already the case that
the "populate" functions would fail for a null-valued RECORD input
(with an unfriendly "record type has not been registered" error)
when there wasn't an AS clause at hand, and it wasn't obvious that
that behavior wasn't OK when there was one.  However, it emerges
that some people were depending on this to work, and indeed the
rather off-point error message you got if you left off AS encouraged
slapping on AS without switching to the json_to_record() family.

Hence, put back the fallback behavior of looking for AS.  While at it,
improve the run-time error you get when there's no place to obtain type
info; we can do a lot better than "record type has not been registered".
(We can't, unfortunately, easily improve the parse-time error message
that leads people down this path in the first place.)

While at it, I refactored the code a bit to avoid duplicating the
same logic in several different places.

Per bug #15940 from Jaroslav Sivy.  Back-patch to v11 where the
current coding came in.  (The pre-v11 deficiencies in this area
aren't regressions, so we'll leave those branches alone.)

Patch by me, based on preliminary analysis by Dmitry Dolgov.

Discussion: https://postgr.es/m/15940-2ab76dc58ffb85b6@postgresql.org

4 years agoAdd fmgr.h include to selfuncs.h.
Andres Freund [Mon, 19 Aug 2019 19:51:38 +0000 (12:51 -0700)]
Add fmgr.h include to selfuncs.h.

Necessary after fb3b098f. That previously escaped notice, because all
including sites already include fmgr.h some other way.

Reported-By: Tom Lane
Author: Andres Freund
Discussion: https://postgr.es/m/17463.1566153454@sss.pgh.pa.us

4 years agoAdd "headerscheck" script to test header-file compilability under C.
Tom Lane [Mon, 19 Aug 2019 18:22:56 +0000 (14:22 -0400)]
Add "headerscheck" script to test header-file compilability under C.

We already had "cpluspluscheck", which served the dual purposes of
verifying that headers compile standalone and that they compile as C++.
However, C++ compilers don't have the exact same set of error conditions
as C compilers, so this doesn't really prove that a header will compile
standalone as C.

Hence, add a second script that's largely similar but runs the C
compiler not C++.

Also add a bit more documentation than the none-at-all we had before.

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

4 years agoUse zic's new "-b slim" option to generate smaller timezone files.
Tom Lane [Mon, 19 Aug 2019 17:17:02 +0000 (13:17 -0400)]
Use zic's new "-b slim" option to generate smaller timezone files.

IANA tzcode release 2019b adds an option that tells zic not to emit
the old 32-bit section of the timezone files, and to skip some other
space-wasting hacks needed for compatibility with old timezone client
libraries.  Since we only expect our own code to use the timezone data
we install, and our code is up-to-date with 2019b, there's no apparent
reason not to generate the smallest possible files.

Unfortunately, while the individual zone files do get significantly
smaller in many cases, they were not that big to begin with; which
means that no real space savings ensues on filesystems that don't
optimize small files.  (For instance, on ext4 with 4K block size,
"du" says the installed timezone tree is the same size as before.)
Still, it seems worth making the change, if only because this is
presumably the wave of the future.  At the very least, we'll save
some cycles while reading a zone file.

But given the marginal value and the fact that this is a new code
path, it doesn't seem worth the risk of back-patching this change
into stable branches.  Hence, unlike most of our timezone-related
changes, apply to HEAD only.

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

4 years agoReplace genetic algorithm ASCII-art with a real figure
Alvaro Herrera [Mon, 19 Aug 2019 16:05:38 +0000 (12:05 -0400)]
Replace genetic algorithm ASCII-art with a real figure

Author: Jürgen Purtz
Discussion: https://postgr.es/m/c6027f7a-78ea-8453-0837-09903ba5fd9b@purtz.de

4 years agodoc: Fix image use in PDF build with vpath
Peter Eisentraut [Mon, 19 Aug 2019 08:30:47 +0000 (10:30 +0200)]
doc: Fix image use in PDF build with vpath

In a vpath build, we need to point to the source directory to allow
FOP to find the images.

4 years agoFix tab completion for CREATE TYPE in psql
Michael Paquier [Mon, 19 Aug 2019 07:33:24 +0000 (16:33 +0900)]
Fix tab completion for CREATE TYPE in psql

Oversight in 7bdc655.

Author: Alexander Lakhin
Discussion: https://postgr.es/m/5da8e325-c665-da95-21e0-c8a99ea61fbf@gmail.com

4 years agoFix inconsistencies and typos in the tree, take 11
Michael Paquier [Mon, 19 Aug 2019 07:21:39 +0000 (16:21 +0900)]
Fix inconsistencies and typos in the tree, take 11

This fixes various typos in docs and comments, and removes some orphaned
definitions.

Author: Alexander Lakhin
Discussion: https://postgr.es/m/5da8e325-c665-da95-21e0-c8a99ea61fbf@gmail.com

4 years agoAvoid conflicts with library versions of inet_net_ntop() and friends.
Tom Lane [Sun, 18 Aug 2019 23:27:23 +0000 (19:27 -0400)]
Avoid conflicts with library versions of inet_net_ntop() and friends.

Prefix inet_net_ntop and sibling routines with "pg_" to ensure that
they aren't mistaken for C-library functions.  This fixes warnings
from cpluspluscheck on some platforms, and should help reduce reader
confusion everywhere, since our functions aren't exactly interchangeable
with the library versions (they may have different ideas about address
family codes).

This shouldn't be fixing any actual bugs, unless somebody's linker
is misbehaving, so no need to back-patch.

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

4 years agoFix incidental warnings from cpluspluscheck.
Tom Lane [Sun, 18 Aug 2019 23:01:40 +0000 (19:01 -0400)]
Fix incidental warnings from cpluspluscheck.

Remove use of "register" keyword in hashfn.c.  It's obsolescent
according to recent C++ compilers, and no modern C compiler pays
much attention to it either.

Also fix one cosmetic warning about signed vs unsigned comparison.

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

4 years agoFix failure-to-compile-standalone in scripts_parallel.h.
Tom Lane [Sun, 18 Aug 2019 22:01:01 +0000 (18:01 -0400)]
Fix failure-to-compile-standalone in scripts_parallel.h.

Needs libpq-fe.h for references to PGConn.

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

4 years agoFix failure-to-compile-standalone in ecpg's dt.h.
Tom Lane [Sun, 18 Aug 2019 21:51:35 +0000 (17:51 -0400)]
Fix failure-to-compile-standalone in ecpg's dt.h.

This has to have <time.h>, or the references to "struct tm" don't
mean what they should.

We have some other recently-introduced issues of the same ilk,
but this one seems old.  No backpatch though, as it's only a
latent problem for most purposes.

4 years agoDisallow changing an inherited column's type if not all parents changed.
Tom Lane [Sun, 18 Aug 2019 21:11:57 +0000 (17:11 -0400)]
Disallow changing an inherited column's type if not all parents changed.

If a table inherits from multiple unrelated parents, we must disallow
changing the type of a column inherited from multiple such parents, else
it would be out of step with the other parents.  However, it's possible
for the column to ultimately be inherited from just one common ancestor,
in which case a change starting from that ancestor should still be
allowed.  (I would not be excited about preserving that option, were
it not that we have regression test cases exercising it already ...)

It's slightly annoying that this patch looks different from the logic
with the same end goal in renameatt(), and more annoying that it
requires an extra syscache lookup to make the test.  However, the
recursion logic is quite different in the two functions, and a
back-patched bug fix is no place to be trying to unify them.

Per report from Manuel Rigger.  Back-patch to 9.5.  The bug exists in
9.4 too (and doubtless much further back); but the way the recursion
is done in 9.4 is a good bit different, so that substantial refactoring
would be needed to fix it in 9.4.  I'm disinclined to do that, or risk
introducing new bugs, for a bug that has escaped notice for this long.

Discussion: https://postgr.es/m/CA+u7OA4qogDv9rz1HAb-ADxttXYPqQdUdPY_yd4kCzywNxRQXA@mail.gmail.com

4 years agoRemove obsolete reference to Irix
Peter Eisentraut [Sun, 18 Aug 2019 04:53:28 +0000 (06:53 +0200)]
Remove obsolete reference to Irix

4 years agoMake deadlock-parallel isolation test more robust.
Tom Lane [Sat, 17 Aug 2019 22:15:38 +0000 (18:15 -0400)]
Make deadlock-parallel isolation test more robust.

This test failed fairly reproducibly on some CLOBBER_CACHE_ALWAYS
buildfarm animals.  The cause seems to be that if a parallel worker
is slow enough to reach its lock wait, it may not be released by
the first deadlock check run, and then later deadlock checks might
decide to unblock the d2 session instead of the d1 session, leaving
us in an undetected deadlock state (since the isolationtester client
is waiting for d1 to complete first).

Fix by introducing an additional lock wait at the end of the d2a1
step, ensuring that the deadlock checker will recognize that d1
has to be unblocked before d2a1 completes.

Also reduce max_parallel_workers_per_gather to 3 in this test.  With the
default max_worker_processes value, we were only getting one parallel
worker for the d2a1 step, which is not the case I hoped to test.  We
should get 3 for d1a2 and 2 for d2a1, as the code stands; and maybe 3
for d2a1 if somebody figures out why the last parallel worker slot isn't
free already.

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

4 years agoImprove Assert output
Peter Eisentraut [Sat, 17 Aug 2019 10:36:30 +0000 (12:36 +0200)]
Improve Assert output

If an assertion expression contained a macro, the failed assertion
message would print the expanded macro, which is usually unhelpful and
confusing.  Restructure the Assert macros to not expand any macros
when constructing the failure message.

This also fixes that the existing output for Assert et al. shows
the *inverted* condition, which is also confusing and not how
assertions usually work.

Discussion: https://www.postgresql.org/message-id/flat/6c68efe3-117a-dcc1-73d4-18ba1ec532e2%402ndquadrant.com

4 years agoAdd default_table_access_method to postgresql.conf.sample.
Andres Freund [Fri, 16 Aug 2019 22:24:22 +0000 (15:24 -0700)]
Add default_table_access_method to postgresql.conf.sample.

Reported-By: Heikki Linnakangas
Author: Michael Paquier
Discussion: https://postgr.es/m/d6ffbebb-a0d2-181c-811d-b029b2225ed7@iki.fi
Backpatch: 12-, where pluggable table access methods were introduced

4 years agoAdd missing fmgr.h include.
Andres Freund [Fri, 16 Aug 2019 22:19:50 +0000 (15:19 -0700)]
Add missing fmgr.h include.

4 years agoRemove fmgr.h includes from headers that don't really need it.
Andres Freund [Fri, 16 Aug 2019 17:35:31 +0000 (10:35 -0700)]
Remove fmgr.h includes from headers that don't really need it.

Most of the fmgr.h includes were obsoleted by 352a24a1f9d6f7d4abb1. A
few others can be obsoleted using the underlying struct type in an
implementation detail.

Author: Andres Freund
Discussion: https://postgr.es/m/20190803193733.g3l3x3o42uv4qj7l@alap3.anarazel.de

4 years agoDon't include utils/array.h from acl.h.
Andres Freund [Fri, 16 Aug 2019 17:33:30 +0000 (10:33 -0700)]
Don't include utils/array.h from acl.h.

For most uses of acl.h the details of how "Acl" internally looks like
are irrelevant. It might make sense to move a lot of the
implementation details into a separate header at a later point.

The main motivation of this change is to avoid including fmgr.h (via
array.h, which needs it for exposed structs) in a lot of files that
otherwise don't need it. A subsequent commit will remove the fmgr.h
include from a lot of files.

Directly include utils/array.h and utils/expandeddatum.h from the
files that need them, but previously included them indirectly, via
acl.h.

Author: Andres Freund
Discussion: https://postgr.es/m/20190803193733.g3l3x3o42uv4qj7l@alap3.anarazel.de

4 years agoRemove redundant prototypes for SQL callable functions.
Andres Freund [Fri, 16 Aug 2019 17:16:42 +0000 (10:16 -0700)]
Remove redundant prototypes for SQL callable functions.

These aren't needed after 352a24a1f9d6. The remaining prototypes are
not defined on the SQL level.

Author: Andres Freund
Discussion: https://postgr.es/m/20190803193733.g3l3x3o42uv4qj7l@alap3.anarazel.de

4 years agoRemove useless bms_free() calls in build_child_join_rel().
Etsuro Fujita [Fri, 16 Aug 2019 05:35:55 +0000 (14:35 +0900)]
Remove useless bms_free() calls in build_child_join_rel().

These seem to be leftovers from the original partitionwise-join patch,
perhaps.

Discussion: https://postgr.es/m/CAPmGK145YiMTPRnvev1dLz8na_-0aZ=Xyqn8f2QsJFBUTObNow@mail.gmail.com

4 years agoPrevent possible double-free when update trigger returns old tuple.
Tom Lane [Fri, 16 Aug 2019 00:04:19 +0000 (20:04 -0400)]
Prevent possible double-free when update trigger returns old tuple.

This is a variant of the problem fixed in commit 25b692568, which
unfortunately we failed to detect at the time.  If an update trigger
returns the "old" tuple, as it's entitled to do, then a subsequent
iteration of the loop in ExecBRUpdateTriggers would have "oldtuple"
equal to "trigtuple" and would fail to notice that it shouldn't
free that.

In addition to fixing the code, extend the test case added by
25b692568 so that it covers multiple-trigger-iterations cases.

This problem does not manifest in v12/HEAD, as a result of the
relevant code having been largely rewritten for slotification.
However, include the test case into v12/HEAD anyway, since this
is clearly an area that someone could break again in future.

Per report from Piotr Gabriel Kosinski.  Back-patch into all
supported branches, since the bug seems quite old.

Diagnosis and code fix by Thomas Munro, test case by me.

Discussion: https://postgr.es/m/CAFMLSdP0rd7LqC3j-H6Fh51FYSt5A10DDh-3=W4PPc4LLUQ8YQ@mail.gmail.com

4 years agoFix plpgsql to re-look-up composite type names at need.
Tom Lane [Thu, 15 Aug 2019 19:21:47 +0000 (15:21 -0400)]
Fix plpgsql to re-look-up composite type names at need.

Commit 4b93f5799 rearranged things in plpgsql to make it cope better with
composite types changing underneath it intra-session.  However, I failed to
consider the case of a composite type being dropped and recreated entirely.
In my defense, the previous coding didn't consider that possibility at all
either --- but it would accidentally work so long as you didn't change the
type's field list, because the built-at-compile-time list of component
variables would then still match the type's new definition.  The new
coding, however, occasionally tries to re-look-up the type by OID, and
then fails to find the dropped type.

To fix this, we need to save the TypeName struct, and then redo the type
OID lookup from that.  Of course that's expensive, so we don't want to do
it every time we need the type OID.  This can be fixed in the same way that
4b93f5799 dealt with changes to composite types' definitions: keep an eye
on the type's typcache entry to see if its tupledesc has been invalidated.
(Perhaps, at some point, this mechanism should be generalized so it can
work for non-composite types too; but for now, plpgsql only tries to
cope with intra-session redefinitions of composites.)

I'm slightly hesitant to back-patch this into v11, because it changes
the contents of struct PLpgSQL_type as well as the signature of
plpgsql_build_datatype(), so in principle it could break code that is
poking into the innards of plpgsql.  However, the only popular extension
of that ilk is pldebugger, and it doesn't seem to be affected.  Since
this is a regression for people who were relying on the old behavior,
it seems worth taking the small risk of causing compatibility issues.

Per bug #15913 from Daniel Fiori.  Back-patch to v11 where 4b93f5799
came in.

Discussion: https://postgr.es/m/15913-a7e112e16dedcffc@postgresql.org

4 years agoUse a hash table to de-duplicate NOTIFY events faster.
Tom Lane [Thu, 15 Aug 2019 16:22:12 +0000 (12:22 -0400)]
Use a hash table to de-duplicate NOTIFY events faster.

Previously, async.c got rid of duplicate notifications by scanning
the list of pending events to compare each one to the proposed new
event.  This works okay for very small numbers of distinct events,
but degrades as O(N^2) for many events.  We can improve matters by
using a hash table to probe for duplicates.  So as not to add a
lot of overhead for the simple cases that the code did handle well
before, create the hash table only once a (sub)transaction has
queued more than 16 distinct notify events.

A downside is that we now have to do per-event work to propagate
a successful subtransaction's notify events up to its parent.
(But this isn't significant unless the subtransaction had many
events, in which case the O(N^2) behavior would have been in
play already, so we still come out ahead.)

We can make some lemonade out of this lemon, though: since we must
examine each event anyway, it's now possible to de-duplicate events
fully, rather than skipping that for events merged up from
subtransactions.  Hence, remove the old weasel wording in notify.sgml
about whether de-duplication happens or not, and adjust the test
case in async-notify.spec that exhibited the old behavior.

While at it, rearrange the definition of struct Notification to make
it more compact and require just one palloc per event, rather than
two or three.  This saves space when there are a lot of events,
in fact more than enough to buy back the space needed for the hash
table.

Patch by me, based on discussions around a different patch
submitted by Filip Rembiałkowski.

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

4 years agoDoc: improve documentation about postgresql.auto.conf.
Tom Lane [Thu, 15 Aug 2019 15:14:26 +0000 (11:14 -0400)]
Doc: improve documentation about postgresql.auto.conf.

Clarify what external tools can do to this file, and add a bit
of detail about what ALTER SYSTEM itself does.

Discussion: https://postgr.es/m/aed6cc9f-98f3-2693-ac81-52bb0052307e@2ndquadrant.com

4 years agoFix ALTER SYSTEM to cope with duplicate entries in postgresql.auto.conf.
Tom Lane [Wed, 14 Aug 2019 19:09:19 +0000 (15:09 -0400)]
Fix ALTER SYSTEM to cope with duplicate entries in postgresql.auto.conf.

ALTER SYSTEM itself normally won't make duplicate entries (although
up till this patch, it was possible to confuse it by writing case
variants of a GUC's name).  However, if some external tool has appended
entries to the file, that could result in duplicate entries for a single
GUC name.  In such a situation, ALTER SYSTEM did exactly the wrong thing,
because it replaced or removed only the first matching entry, leaving
the later one(s) still there and hence still determining the active value.

This patch fixes that by making ALTER SYSTEM sweep through the file and
remove all matching entries, then (if not ALTER SYSTEM RESET) append the
new setting to the end.  This means entries will be in order of last
setting rather than first setting, but that shouldn't hurt anything.

Also, make the comparisons case-insensitive so that the right things
happen if you do, say, ALTER SYSTEM SET "TimeZone" = 'whatever'.

This has been broken since ALTER SYSTEM was invented, so back-patch
to all supported branches.

Ian Barwick, with minor mods by me

Discussion: https://postgr.es/m/aed6cc9f-98f3-2693-ac81-52bb0052307e@2ndquadrant.com

4 years agoRemove block number field from nbtree stack.
Peter Geoghegan [Wed, 14 Aug 2019 18:32:35 +0000 (11:32 -0700)]
Remove block number field from nbtree stack.

The initial value of the nbtree stack downlink block number field
recorded during an initial descent of the tree wasn't actually used.
Both _bt_getstackbuf() callers overwrote the value with their own value.

Remove the block number field from the stack struct, and add a child
block number argument to _bt_getstackbuf() in its place.  This makes the
overall design of _bt_getstackbuf() clearer.

Author: Peter Geoghegan
Reviewed-By: Anastasia Lubennikova
Discussion: https://postgr.es/m/CAH2-Wzmx+UbXt2YNOUCZ-a04VdXU=S=OHuAuD7Z8uQq-PXTYUg@mail.gmail.com

4 years agoinitdb: Remove obsolete locale handling
Peter Eisentraut [Wed, 14 Aug 2019 04:50:47 +0000 (06:50 +0200)]
initdb: Remove obsolete locale handling

The method of passing LC_COLLATE and LC_CTYPE to the backend during
initdb is obsolete as of 61d967498802ab86d8897cb3c61740d7e9d712f6.
This can all be removed.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/eeaf2f99-a1a6-8aca-3f43-9ab0b2fb112a%402ndquadrant.com