]> granicus.if.org Git - postgresql/log
postgresql
4 years agoClarify some comments about ntstatus.h in win32_port.h
Michael Paquier [Tue, 8 Oct 2019 04:59:53 +0000 (13:59 +0900)]
Clarify some comments about ntstatus.h in win32_port.h

Some comments in this file referred to outdated links.  This simplifies
the outdated comment blocks and refreshes the links.

Reported-by: Vignesh C
Author: Juan José Santamaría Flecha
Discussion: https://postgr.es/m/46C03E17-16F7-4C38-B148-029AC7448E96@gmail.com

4 years agoImprove test coverage of pg_rewind
Michael Paquier [Tue, 8 Oct 2019 02:46:30 +0000 (11:46 +0900)]
Improve test coverage of pg_rewind

This includes new TAP tests for a couple of areas not covered yet and
some improvements:
- More coverage for --no-ensure-shutdown, the enforced recovery step and
--dry-run.
- Failures with option combinations and basic option checks.
- Removal of a duplicated comment.

Author: Alexey Kondratov, Michael Paquier
Discussion: https://postgr.es/m/20191007010651.GD14532@paquier.xyz

4 years agodocs: Improve A?synchronous Multimaster Replication descr.
Bruce Momjian [Mon, 7 Oct 2019 22:06:08 +0000 (18:06 -0400)]
docs:  Improve A?synchronous Multimaster Replication descr.

The docs for sync and async multimaster replication were unclear about
when to use it, and when it has benefits;  this change clarifies that.

Reported-by: juha-pekka.eloranta@reaktor.fi
Discussion: https://postgr.es/m/156856543824.1274.12180817186798859836@wrigleys.postgresql.org

Backpatch-through: 9.4

4 years agodocs: clarify that today/tomorrow/yesterday is at 00:00
Bruce Momjian [Mon, 7 Oct 2019 21:26:46 +0000 (17:26 -0400)]
docs:  clarify that today/tomorrow/yesterday is at 00:00

This should help people clearly know that these days start at midnight.

Reported-by: David Harper
Discussion: https://postgr.es/m/156258047907.1181.11324468080514061996@wrigleys.postgresql.org

Backpatch-through: 9.4

4 years agodoc: move mention of log_min_error_statement in a better spot
Bruce Momjian [Mon, 7 Oct 2019 18:33:31 +0000 (14:33 -0400)]
doc:  move mention of log_min_error_statement in a better spot

Previously it was mentioned in the lock_timeout docs in a confusing
location.

Reported-by: ivaylo.zlatanov@gmail.com
Discussion: https://postgr.es/m/157019615723.25307.15449102262106437404@wrigleys.postgresql.org

Backpatch-through: 9.4

4 years agoCheck for too many postmaster children before spawning a bgworker.
Tom Lane [Mon, 7 Oct 2019 16:39:09 +0000 (12:39 -0400)]
Check for too many postmaster children before spawning a bgworker.

The postmaster's code path for spawning a bgworker neglected to check
whether we already have the max number of live child processes.  That's
a bit hard to hit, since it would necessarily be a transient condition;
but if we do, AssignPostmasterChildSlot() fails causing a postmaster
crash, as seen in a report from Bhargav Kamineni.

To fix, invoke canAcceptConnections() in the bgworker code path, as we
do in the other code paths that spawn children.  Since we don't want
the same pmState tests in this case, add a child-process-type parameter
to canAcceptConnections() so that it can know what to do.

Back-patch to 9.5.  In principle the same hazard exists in 9.4, but the
code is enough different that this patch wouldn't quite fix it there.
Given the tiny usage of bgworkers in that branch it doesn't seem worth
creating a variant patch for it.

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

4 years agoSimplify PGAC_STRUCT_TIMEZONE Autoconf macro
Peter Eisentraut [Mon, 7 Oct 2019 14:28:56 +0000 (16:28 +0200)]
Simplify PGAC_STRUCT_TIMEZONE Autoconf macro

Since 63bd0db12199c5df043e1dea0f2b574f622b3a4c we don't use tzname
anymore, so we don't need to check for it.  Instead, just keep the
part of PGAC_STRUCT_TIMEZONE that we need, which is the check for
struct tm.tm_zone.

Discussion: https://www.postgresql.org/message-id/flat/5eb11a37-f3ca-5fb7-308f-4485dec25a2e%402ndquadrant.com

4 years agoRemove use of deprecated Autoconf define
Peter Eisentraut [Mon, 7 Oct 2019 14:27:31 +0000 (16:27 +0200)]
Remove use of deprecated Autoconf define

Change from HAVE_TM_ZONE to HAVE_STRUCT_TM_TM_ZONE.

4 years agoHack pg_ctl to report postmaster's exit status.
Tom Lane [Mon, 7 Oct 2019 14:39:07 +0000 (10:39 -0400)]
Hack pg_ctl to report postmaster's exit status.

Temporarily change pg_ctl so that the postmaster's exit status will
be printed (to the postmaster's stdout).  This is to help identify
the cause of intermittent "postmaster exited during a parallel
transaction" failures seen on a couple of buildfarm members.  This
change degrades pg_ctl's functionality in a couple of minor ways,
so we'll revert it once we've obtained the desired info.

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

4 years agoFix incorrect use of term HEAD for Git
Peter Eisentraut [Mon, 7 Oct 2019 07:44:17 +0000 (09:44 +0200)]
Fix incorrect use of term HEAD for Git

HEAD as used here was CVS terminology.  Now we mean master.

4 years agoImprove handling and coverage of --no-ensure-shutdown in pg_rewind
Michael Paquier [Mon, 7 Oct 2019 00:07:22 +0000 (09:07 +0900)]
Improve handling and coverage of --no-ensure-shutdown in pg_rewind

This includes a couple of changes around the new behavior of pg_rewind
which enforces recovery to happen once on a cluster not shut down
cleanly:
- Some comments and documentation improvements.
- Shutdown the cluster to rewind with immediate mode in all the tests,
this allows to check after the forced recovery behavior which is wanted
as new default.
- Use -F for the forced recovery step, so as postgres does not use
fsync.  This was useless as a final sync is done once the tool is done.

Author: Michael Paquier
Reviewed-by: Alexey Kondratov
Discussion: https://postgr.es/m/20191004083721.GA1829@paquier.xyz

4 years agoDoc: improve docs about pg_statistic_ext_data.
Tom Lane [Sun, 6 Oct 2019 18:14:45 +0000 (14:14 -0400)]
Doc: improve docs about pg_statistic_ext_data.

Commit aa087ec64 was a bit over-hasty about the doc changes needed
while splitting pg_statistic_ext_data off from pg_statistic_ext.
It duplicated one para and inserted another in what seems to me
to be the wrong section.  Fix that up, and in passing do some minor
copy-editing.

Per report from noborusai.

Discussion: https://postgr.es/m/CAAM3qnLXLUz4mOBkqa8jxigpKhKNxzSuvwpjvCRPvO5EqWjxSg@mail.gmail.com

4 years agoAvoid trying to release a List's initial allocation via repalloc().
Tom Lane [Sun, 6 Oct 2019 16:06:30 +0000 (12:06 -0400)]
Avoid trying to release a List's initial allocation via repalloc().

Commit 1cff1b95a included some code that supposed it could repalloc()
a memory chunk to a smaller size without risk of the chunk moving.
That was not a great idea, because it depended on undocumented behavior
of AllocSetRealloc, which commit c477f3e44 changed thereby breaking it.
(Not to mention that this code ought to work with other memory context
types, which might not work the same...)  So get rid of the repalloc
calls, and instead just wipe the now-unused ListCell array and/or tell
Valgrind it's NOACCESS, as if we'd freed it.

In cases where the initial list allocation had been quite large, this
could represent an annoying waste of space.  In principle we could
ameliorate that by allocating the initial cell array separately when
it exceeds some threshold.  But that would complicate new_list() which
is hot code, and the returns would materialize only in narrow cases.
On balance I don't think it'd be worth it.

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

4 years agoChange MemoryContextMemAllocated to return Size
Tomas Vondra [Sat, 5 Oct 2019 18:49:39 +0000 (20:49 +0200)]
Change MemoryContextMemAllocated to return Size

Commit f2369bc610 switched most of the memory accounting from int64 to
Size, but it forgot to change the MemoryContextMemAllocated return type.
So this fixes that omission.

Discussion: https://www.postgresql.org/message-id/11238.1570200198%40sss.pgh.pa.us

4 years agoReport test_atomic_ops() failures consistently, via macros.
Noah Misch [Sat, 5 Oct 2019 17:05:05 +0000 (10:05 -0700)]
Report test_atomic_ops() failures consistently, via macros.

This prints the unexpected value in more failure cases, and it removes
forty-eight hand-maintained error messages.  Back-patch to 9.5, which
introduced these tests.

Reviewed (in an earlier version) by Andres Freund.

Discussion: https://postgr.es/m/20190915160021.GA24376@alvherre.pgsql

4 years agoAvoid use of wildcard in pg_waldump's .gitignore.
Tom Lane [Sat, 5 Oct 2019 16:26:55 +0000 (12:26 -0400)]
Avoid use of wildcard in pg_waldump's .gitignore.

This would be all right, maybe, if it didn't also match a file that
definitely should not be ignored.  We don't add rmgrs so often that
manual maintenance of this file list is impractical, so just write
out the list.

(I find the equivalent wildcard use in the Makefile pretty lazy and
unsafe as well, but will leave that alone until it actually causes a
problem.)

Per bug #16042 from Denis Stuchalin.

Discussion: https://postgr.es/m/16042-c174ee692ac21cbd@postgresql.org

4 years agoDisable one more set of tests from c8841199509.
Andres Freund [Sat, 5 Oct 2019 15:05:11 +0000 (08:05 -0700)]
Disable one more set of tests from c8841199509.

Discussion: https://postgr.es/m/20191004222437.45qmglpto43pd3jb@alap3.anarazel.de
Backpatch: 9.6-, just like c8841199509 and 6e61d75f525

4 years agoDisable one set of tests from c8841199509.
Andres Freund [Sat, 5 Oct 2019 04:11:23 +0000 (21:11 -0700)]
Disable one set of tests from c8841199509.

One of the upsert related tests is unstable (sometimes even hanging
until isolationtester's step timeout is reached). Based on preliminary
analysis that might be a problem outside of just that test, but not
really related to EPQ and triggers.  Disable for now, to get the
buildfarm greener again.

Discussion: https://postgr.es/m/20191004222437.45qmglpto43pd3jb@alap3.anarazel.de
Backpatch: 9.6-, just like c8841199509.

4 years agoAdd isolation tests for the combination of EPQ and triggers.
Andres Freund [Fri, 4 Oct 2019 20:56:04 +0000 (13:56 -0700)]
Add isolation tests for the combination of EPQ and triggers.

As evidenced by bug #16036 this area is woefully under-tested. Add
fairly extensive tests for the combination.

Backpatch back to 9.6 - before that isolationtester was not capable
enough. While we don't backpatch tests all the time, future fixes to
trigger.c would potentially look different enough in 12+ from the
earlier branches that introducing bugs during backpatching is more
likely than normal. Also, it's just a crucial and undertested area of
the code.

Author: Andres Freund
Discussion: https://postgr.es/m/16036-28184c90d952fb7f@postgresql.org
Backpatch: 9.6-, the earliest these tests work

4 years agoFix crash caused by EPQ happening with a before update trigger present.
Andres Freund [Fri, 4 Oct 2019 18:59:34 +0000 (11:59 -0700)]
Fix crash caused by EPQ happening with a before update trigger present.

When ExecBRUpdateTriggers()'s GetTupleForTrigger() follows an EPQ
chain the former needs to run the result tuple through the junkfilter
again, and update the slot containing the new version of the tuple to
contain that new version. The input tuple may already be in the
junkfilter's output slot, which used to be OK - we don't need the
previous version anymore. Unfortunately ff11e7f4b9ae started to use
ExecCopySlot() to update newslot, and ExecCopySlot() doesn't support
copying a slot into itself, leading to a slot in a corrupt
state, which then can cause crashes or other symptoms.

Fix this by skipping the ExecCopySlot() when copying into itself.

While we could have easily made ExecCopySlot() handle that case, it
seems better to add an assert forbidding doing so instead. As the goal
of copying might be to make the contents of one slot independent from
another, it seems failure prone to handle doing so silently.

A follow-up commit will add tests for the obviously under-covered
combination of EPQ and triggers. Done as a separate commit as it might
make sense to backpatch them further than this bug.

Also remove confusion with confusing variable names for slots in
ExecBRDeleteTriggers() and ExecBRUpdateTriggers().

Bug: #16036
Reported-By: Антон Власов
Author: Andres Freund
Discussion: https://postgr.es/m/16036-28184c90d952fb7f@postgresql.org
Backpatch: 12-, where ff11e7f4b9ae was merged

4 years agoUse a fd opened for read/write when syncing slots during startup, take 2.
Andres Freund [Fri, 4 Oct 2019 20:08:51 +0000 (13:08 -0700)]
Use a fd opened for read/write when syncing slots during startup, take 2.

Cribbing from dfbaed45975:
    Some operating systems, including the reporter's windows, return EBADFD
    or similar when fsync() is invoked on a O_RDONLY file descriptor.
    Unfortunately RestoreSlotFromDisk() does exactly that; which causes
    failures after restarts in at least some scenarios.

    If you hit the bug the error message will be something like
    ERROR: could not fsync file "pg_replslot/$name/state": Bad file descriptor

    Simply use O_RDWR instead of O_RDONLY when opening the relevant file
    descriptor to fix the bug.

Unfortunately this fix was undone in 82a5649fb9db. Re-apply, and add a
comment.

Bug: 16039
Reported-By: Hans Buschmann
Author: Andres Freund
Discussion: https://postgr.es/m/16039-196fc97cc05e141c@postgresql.org
Backpatch: 12-, as 82a5649fb9db

4 years agoHandle spaces in OpenSSL install location for MSVC
Andrew Dunstan [Fri, 4 Oct 2019 19:34:40 +0000 (15:34 -0400)]
Handle spaces in OpenSSL install location for MSVC

First, make sure that the .exe name is quoted when trying to get the
version number. Also, don't quote the lib name for using in the project
files if it's already been quoted. This second change applies to all
libraries, not just OpenSSL.

This has clearly been broken forever, so backpatch to all live branches.

4 years agoRename some toasting functions based on whether they are heap-specific.
Robert Haas [Fri, 4 Oct 2019 18:24:46 +0000 (14:24 -0400)]
Rename some toasting functions based on whether they are heap-specific.

The old names for the attribute-detoasting functions names included
the word "heap," which seems outdated now that the heap is only one of
potentially many table access methods.

On the other hand, toast_insert_or_update and toast_delete are
heap-specific, so rename them by adding "heap_" as a prefix.

Not all of the work of making the TOAST system fully accessible to AMs
other than the heap is done yet, but there seems to be little harm in
getting this renaming out of the way now. Commit
8b94dab06617ef80a0901ab103ebd8754427ef5a already divided up the
functions among various files partially according to whether it was
intended that they should be heap-specific or AM-agnostic, so this is
just clarifying the division contemplated by that 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 agoFix bitshiftright()'s zero-padding some more.
Tom Lane [Fri, 4 Oct 2019 14:34:21 +0000 (10:34 -0400)]
Fix bitshiftright()'s zero-padding some more.

Commit 5ac0d9360 failed to entirely fix bitshiftright's habit of
leaving one-bits in the pad space that should be all zeroes,
because in a moment of sheer brain fade I'd concluded that only
the code path used for not-a-multiple-of-8 shift distances needed
to be fixed.  Of course, a multiple-of-8 shift distance can also
cause the problem, so we need to forcibly zero the extra bits
in both cases.

Per bug #16037 from Alexander Lakhin.  As before, back-patch to all
supported branches.

Discussion: https://postgr.es/m/16037-1d1ebca564db54f4@postgresql.org

4 years agoUse Size instead of int64 to track allocated memory
Tomas Vondra [Fri, 4 Oct 2019 14:10:56 +0000 (16:10 +0200)]
Use Size instead of int64 to track allocated memory

Commit 5dd7fc1519 added block-level memory accounting, but used int64 variable to
track the amount of allocated memory. That is incorrect, because we have Size for
exactly these purposes, but it was mostly harmless until c477f3e449 which changed
how we handle with repalloc() when downsizing the chunk. Previously we've ignored
these cases and just kept using the original chunk, but now we need to update the
accounting, and the code was doing this:

    context->mem_allocated += blksize - oldblksize;

Both blksize and oldblksize are Size (so unsigned) which means the subtraction
underflows, producing a very high positive value. On 64-bit platforms (where Size
has the same size as mem_alllocated) this happens to work because the result wraps
to the right value, but on (some) 32-bit platforms this fails.

This fixes two things - it changes mem_allocated (and related variables) to Size,
and it splits the update to two separate steps, to prevent any underflows.

Discussion: https://www.postgresql.org/message-id/15151.1570163761%40sss.pgh.pa.us

4 years agoRemove AtSubStart_Notify.
Robert Haas [Fri, 4 Oct 2019 12:19:25 +0000 (08:19 -0400)]
Remove AtSubStart_Notify.

Allocate notify-related state lazily instead. This makes trivial
subtransactions noticeably faster.

Patch by me, reviewed and tested by Dilip Kumar, Kyotaro Horiguchi,
and Jeevan Ladhe.

Discussion: https://postgr.es/m/CA+TgmobE1J22S1eC-6N-je9LgrcwZypkwp+zH6JXo9mc=4Nk3A@mail.gmail.com

4 years agoFix issues in pg_rewind with --no-ensure-shutdown/--write-recovery-conf
Michael Paquier [Fri, 4 Oct 2019 07:18:29 +0000 (16:18 +0900)]
Fix issues in pg_rewind with --no-ensure-shutdown/--write-recovery-conf

This fixes two issues with recent features added in pg_rewind:
- --dry-run should do nothing on the target directory, but 927474c
forgot to consider that for --write-recovery-conf.
- --no-ensure-shutdown was not actually working.  There is no test
coverage for this option yet, but a subsequent patch will add that.

Author: Alexey Kondratov
Discussion: https://postgr.es/m/7ca88204-3e0b-2f4c-c8af-acadc4b266e5@postgrespro.ru

4 years agoFix --dry-run mode of pg_rewind
Michael Paquier [Fri, 4 Oct 2019 00:14:51 +0000 (09:14 +0900)]
Fix --dry-run mode of pg_rewind

Even if --dry-run mode was specified, the control file was getting
updated, preventing follow-up runs of pg_rewind to work properly on the
target data folder.  The origin of the problem came from the refactoring
done by ce6afc6.

Author: Alexey Kondratov
Discussion: https://postgr.es/m/7ca88204-3e0b-2f4c-c8af-acadc4b266e5@postgrespro.ru
Backpatch-through: 12

4 years agoAvoid unnecessary out-of-memory errors during encoding conversion.
Tom Lane [Thu, 3 Oct 2019 21:34:25 +0000 (17:34 -0400)]
Avoid unnecessary out-of-memory errors during encoding conversion.

Encoding conversion uses the very simplistic rule that the output
can't be more than 4X longer than the input, and palloc's a buffer
of that size.  This results in failure to convert any string longer
than 1/4 GB, which is becoming an annoying limitation.

As a band-aid to improve matters, allow the allocated output buffer
size to exceed 1GB.  We still insist that the final result fit into
MaxAllocSize (1GB), though.  Perhaps it'd be safe to relax that
restriction, but it'd require close analysis of all callers, which
is daunting (not least because external modules might call these
functions).  For the moment, this should allow a 2X to 4X improvement
in the longest string we can convert, which is a useful gain in
return for quite a simple patch.

Also, once we have successfully converted a long string, repalloc
the output down to the actual string length, returning the excess
to the malloc pool.  This seems worth doing since we can usually
expect to give back several MB if we take this path at all.

This still leaves much to be desired, most notably that the assumption
that MAX_CONVERSION_GROWTH == 4 is very fragile, and yet we have no
guard code verifying that the output buffer isn't overrun.  Fixing
that would require significant changes in the encoding conversion
APIs, so it'll have to wait for some other day.

The present patch seems safely back-patchable, so patch all supported
branches.

Alvaro Herrera and Tom Lane

Discussion: https://postgr.es/m/20190816181418.GA898@alvherre.pgsql
Discussion: https://postgr.es/m/3614.1569359690@sss.pgh.pa.us

4 years agoAllow repalloc() to give back space when a large chunk is downsized.
Tom Lane [Thu, 3 Oct 2019 17:56:26 +0000 (13:56 -0400)]
Allow repalloc() to give back space when a large chunk is downsized.

Up to now, if you resized a large (>8K) palloc chunk down to a smaller
size, aset.c made no attempt to return any space to the malloc pool.
That's unpleasant if a really large allocation is resized to a
significantly smaller size.  I think no such cases existed when this
code was designed, and I'm not sure whether they're common even yet,
but an upcoming fix to encoding conversion will certainly create such
cases.  Therefore, fix AllocSetRealloc so that it gives realloc()
a chance to do something with the block.  This doesn't noticeably
increase complexity, we mostly just have to change the order in which
the cases are considered.

Back-patch to all supported branches.

Discussion: https://postgr.es/m/20190816181418.GA898@alvherre.pgsql
Discussion: https://postgr.es/m/3614.1569359690@sss.pgh.pa.us

4 years agoSelectively include window frames in expression walks/mutates.
Andrew Gierth [Thu, 3 Oct 2019 09:54:52 +0000 (10:54 +0100)]
Selectively include window frames in expression walks/mutates.

query_tree_walker and query_tree_mutator were skipping the
windowClause of the query, without regard for the fact that the
startOffset and endOffset in a WindowClause node are expression trees
that need to be processed. This was an oversight in commit ec4be2ee6
from 2010 which added the expression fields; the main symptom is that
function parameters in window frame clauses don't work in inlined
functions.

Fix (as conservatively as possible since this needs to not break
existing out-of-tree callers) and add tests.

Backpatch all the way, since this has been broken since 9.0.

Per report from Alastair McKinley; fix by me with kibitzing and review
from Tom Lane.

Discussion: https://postgr.es/m/DB6PR0202MB2904E7FDDA9D81504D1E8C68E3800@DB6PR0202MB2904.eurprd02.prod.outlook.com

4 years agopgbench: add --partitions and --partition-method options.
Amit Kapila [Tue, 1 Oct 2019 04:20:26 +0000 (09:50 +0530)]
pgbench: add --partitions and --partition-method options.

These new options allow users to partition the pgbench_accounts table by
specifying the number of partitions and partitioning method.  The values
allowed for partitioning method are range and hash.

This feature allows users to measure the overhead of partitioning if any.

Author: Fabien COELHO
Reviewed-by: Amit Kapila, Amit Langote, Dilip Kumar, Asif Rehman, and
Alvaro Herrera
Discussion: https://postgr.es/m/alpine.DEB.2.21.1907230826190.7008@lancre

4 years agoRemove temporary WAL and history files at the end of archive recovery
Michael Paquier [Wed, 2 Oct 2019 06:53:07 +0000 (15:53 +0900)]
Remove temporary WAL and history files at the end of archive recovery

cbc55da has reworked the order of some actions at the end of archive
recovery.  Unfortunately this overlooked the fact that the startup
process needs to remove RECOVERYXLOG (for temporary WAL segment newly
recovered from archives) and RECOVERYHISTORY (for temporary history
file) at this step, leaving the files around even after recovery ended.

Backpatch to 9.5, like the previous commit.

Author: Sawada Masahiko
Reviewed-by: Fujii Masao, Michael Paquier
Discussion: https://postgr.es/m/CAD21AoBO_eDQub6zojFnWtnmutRBWvYf7=cW4Hsqj+U_R26w3Q@mail.gmail.com
Backpatch-through: 9.5

4 years agoRevert hooks for session start and end, take two
Michael Paquier [Wed, 2 Oct 2019 00:55:27 +0000 (09:55 +0900)]
Revert hooks for session start and end, take two

The location of the session end hook has been chosen so as it is
possible to allow modules to do their own transactions, however any
trying to any any subsystem which went through before_shmem_exit()
would cause issues, limiting the pluggability of the hook.

Per discussion with Tom Lane and Andres Freund.

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

4 years agoBlind attempt to fix pglz_maximum_compressed_size
Tomas Vondra [Tue, 1 Oct 2019 14:53:04 +0000 (16:53 +0200)]
Blind attempt to fix pglz_maximum_compressed_size

Commit 11a078cf87 triggered failures on big-endian machines, and the
only plausible place for an issue seems to be that TOAST_COMPRESS_SIZE
calls VARSIZE instead of VARSIZE_ANY. So try fixing that blindly.

Discussion: https://www.postgresql.org/message-id/20191001131803.j6uin7nho7t6vxzy%40development

4 years agoMark two variables in in aset.c with PG_USED_FOR_ASSERTS_ONLY
Tomas Vondra [Tue, 1 Oct 2019 12:39:06 +0000 (14:39 +0200)]
Mark two variables in in aset.c with PG_USED_FOR_ASSERTS_ONLY

This fixes two compiler warnings about unused variables in non-assert builds,
introduced by 5dd7fc1519461548eebf26c33eac6878ea3e8788.

4 years agoOptimize partial TOAST decompression
Tomas Vondra [Tue, 1 Oct 2019 12:13:44 +0000 (14:13 +0200)]
Optimize partial TOAST decompression

Commit 4d0e994eed added support for partial TOAST decompression, so the
decompression is interrupted after producing the requested prefix. For
prefix and slices near the beginning of the entry, this may saves a lot
of decompression work.

That however only deals with decompression - the whole compressed entry
was still fetched and re-assembled, even though the compression used
only a small fraction of it. This commit improves that by computing how
much compressed data may be needed to decompress the requested prefix,
and then fetches only the necessary part.

We always need to fetch a bit more compressed data than the requested
(uncompressed) prefix, because the prefix may not be compressible at all
and pglz itself adds a bit of overhead. That means this optimization is
most effective when the requested prefix is much smaller than the whole
compressed entry.

Author: Binguo Bao
Reviewed-by: Andrey Borodin, Tomas Vondra, Paul Ramsey
Discussion: https://www.postgresql.org/message-id/flat/CAL-OGkthU9Gs7TZchf5OWaL-Gsi=hXqufTxKv9qpNG73d5na_g@mail.gmail.com

4 years agoFix test_session_hooks with parallel workers
Michael Paquier [Tue, 1 Oct 2019 06:19:32 +0000 (15:19 +0900)]
Fix test_session_hooks with parallel workers

Several buildfarm machines have been complaining about the new module
test_session_hooks to be unstable, like crake and thorntail.  The issue
was that the module was trying to log some start and end session
activity for parallel workers, which makes little sense as they don't
support DML, so just prevent this pattern to happen in the module.

This could be reproduced by enforcing force_parallel_mode=regress, which
is the value used by some of the buildfarm members.

Discussion: https://postgr.es/m/20191001045246.GF2781@paquier.xyz

4 years agoAdd hooks for session start and session end, take two
Michael Paquier [Tue, 1 Oct 2019 03:15:25 +0000 (12:15 +0900)]
Add hooks for session start and session end, take two

These hooks can be used in loadable modules.  A simple test module is
included.

The first attempt was done with cd8ce3a but we lacked handling for
NO_INSTALLCHECK in the MSVC scripts (problem solved afterwards by
431f1599) so the buildfarm got angry.  This also fixes a couple of
issues noticed upon review compared to the first attempt, so the code
has slightly changed, resulting in a more simple test module.

Author: Fabrízio de Royes Mello, Yugo Nagata
Reviewed-by: Andrew Dunstan, Michael Paquier, Aleksandr Parfenov
Discussion: https://postgr.es/m/20170720204733.40f2b7eb.nagata@sraoss.co.jp
Discussion: https://postgr.es/m/20190823042602.GB5275@paquier.xyz

4 years agoFix confusing error caused by connection parameter channel_binding
Michael Paquier [Tue, 1 Oct 2019 01:56:27 +0000 (10:56 +0900)]
Fix confusing error caused by connection parameter channel_binding

When using a client compiled without channel binding support (linking to
OpenSSL 1.0.1 or older) to connect to a server which supports channel
binding (linking to OpenSSL 1.0.2 or newer), libpq would generate a
confusing error message with channel_binding=require for an SSL
connection, where the server sends back SCRAM-SHA-256-PLUS:
"channel binding is required, but server did not offer an authentication
method that supports channel binding."

This is confusing because the server did send a SASL mechanism able to
support channel binding, but libpq was not able to detect that
properly.

The situation can be summarized as followed for the case described in
the previous paragraph for the SASL mechanisms used with the various
modes of channel_binding:
1) Client supports channel binding.
1-1) channel_binding = disable => OK, with SCRAM-SHA-256.
1-2) channel_binding = prefer => OK, with SCRAM-SHA-256-PLUS.
1-3) channel_binding = require => OK, with SCRAM-SHA-256-PLUS.
2) Client does not support channel binding.
2-1) channel_binding = disable => OK, with SCRAM-SHA-256.
2-2) channel_binding = prefer => OK, with SCRAM-SHA-256.
2-3) channel_binding = require => failure with new error message,
instead of the confusing one.
This commit updates case 2-3 to generate a better error message.  Note
that the SSL TAP tests are not impacted as it is not possible to test
with mixed versions of OpenSSL for the backend and libpq.

Reported-by: Tom Lane
Author: Michael Paquier
Reviewed-by: Jeff Davis, Tom Lane
Discussion: https://postgr.es/m/24857.1569775891@sss.pgh.pa.us

4 years agoAdd transparent block-level memory accounting
Tomas Vondra [Tue, 1 Oct 2019 01:13:39 +0000 (03:13 +0200)]
Add transparent block-level memory accounting

Adds accounting of memory allocated in a memory context. Compared to
various ad hoc solutions, the main advantage is that the accounting is
transparent and does not require direct control over allocations (this
matters for use cases where the allocations happen in user code, like
for example aggregate states allocated in a transition functions).

To reduce overhead, the accounting happens at the block level (not for
individual chunks) and only the context immediately owning the block is
updated. When inquiring about amount of memory allocated in a context,
we have to recursively walk all children contexts.

This "lazy" accounting works well for cases with relatively small number
of contexts in the relevant subtree and/or with infrequent inquiries.

Author: Jeff Davis
Reivewed-by: Tomas Vondra, Melanie Plageman, Soumyadeep Chakraborty
Discussion: https://www.postgresql.org/message-id/flat/027a129b8525601c6a680d27ce3a7172dab61aab.camel@j-davis.com

4 years agoDon't generate EEOP_*_FETCHSOME operations for slots know to be virtual.
Andres Freund [Mon, 30 Sep 2019 23:06:16 +0000 (16:06 -0700)]
Don't generate EEOP_*_FETCHSOME operations for slots know to be virtual.

That avoids unnecessary work during both interpreted execution, and
JIT compiled expression evaluation. Both benefit from fewer expression
steps needing be processed, and for interpreted execution there now is
a fastpath dedicated to just fetching a value from a virtual
slot. That's e.g. beneficial for hashjoins over nodes that perform
projections, as the hashed columns are currently fetched individually.

Author: Soumyadeep Chakraborty, Andres Freund
Discussion: https://postgr.es/m/CAE-ML+9OKSN71+mHtfMD-L24oDp8dGTfaVjDU6U+j+FNAW5kRQ@mail.gmail.com

4 years agoReduce code duplication for ExecJust*Var operations.
Andres Freund [Mon, 30 Sep 2019 22:00:21 +0000 (15:00 -0700)]
Reduce code duplication for ExecJust*Var operations.

This is mainly in preparation for adding further fastpath evaluation
routines.

Also reorder ExecJust*Var functions to be consistent with the order in
which they're used.

Author: Andres Freund
Discussion: https://postgr.es/m/CAE-ML+9OKSN71+mHtfMD-L24oDp8dGTfaVjDU6U+j+FNAW5kRQ@mail.gmail.com

4 years agoRely on plan_cache_mode to force generic plans in partition_prune test.
Tom Lane [Mon, 30 Sep 2019 21:14:00 +0000 (17:14 -0400)]
Rely on plan_cache_mode to force generic plans in partition_prune test.

This file had a very weird mix of tests that did "set plan_cache_mode =
force_generic_plan" to get a generic plan, and tests that relied on
using five dummy executions of a prepared statement.  Converting them
all to rely on plan_cache_mode is more consistent and shaves off a
noticeable fraction of the test script's runtime.

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

4 years agoSuppress another CR in program output
Andrew Dunstan [Mon, 30 Sep 2019 19:48:54 +0000 (15:48 -0400)]
Suppress another CR in program output

This one was exposed by a12c75a10.

Backpatch to release 11 where check_pg_config was introduced.

4 years agoFix pg_rewind link order issue introduced in 927474ce1a2.
Andres Freund [Mon, 30 Sep 2019 19:43:09 +0000 (12:43 -0700)]
Fix pg_rewind link order issue introduced in 927474ce1a2.

The aforementioned commit orders the link to pgfeutils after libpq,
which can fail because pgfeutils uses symbols from libpq.

Per buildfarm animal jacana.

Author: Andres Freund
Discussion: https://postgr.es/m/20190930192013.r3wievljua2n3tbb@alap3.anarazel.de

4 years agoDoc: improve PREPARE documentation, cross-referencing to plan_cache_mode.
Tom Lane [Mon, 30 Sep 2019 18:31:12 +0000 (14:31 -0400)]
Doc: improve PREPARE documentation, cross-referencing to plan_cache_mode.

The behavior described in the PREPARE man page applies only for the
default plan_cache_mode setting, so explain that properly.  Rewrite
some of the text while I'm here.  Per suggestion from Bruce.

Discussion: https://postgr.es/m/20190930155505.GA21095@momjian.us

4 years agodocs: adjust multi-column most-common-value statistics
Bruce Momjian [Mon, 30 Sep 2019 17:44:22 +0000 (13:44 -0400)]
docs:  adjust multi-column most-common-value statistics

This commit adds a mention that the order of columns specified during
multi-column most-common-value statistics is insignificant, and tries to
simplify examples.

Discussion: https://postgr.es/m/20190828162238.GA8360@momjian.us

Backpatch-through: 12

4 years agopg_rewind: test new --write-recovery-conf functionality
Alvaro Herrera [Mon, 30 Sep 2019 17:04:00 +0000 (14:04 -0300)]
pg_rewind: test new --write-recovery-conf functionality

Author: Alexey Kondratov
Reviewed-by: Paul Guo
Discussion: https://postgr.es/m/2f726102-3f1e-bf16-061e-501919473ace@postgrespro.ru

4 years agopg_rewind: Allow writing recovery configuration
Alvaro Herrera [Mon, 30 Sep 2019 15:57:35 +0000 (12:57 -0300)]
pg_rewind: Allow writing recovery configuration

This is provided with a new switch --write-recovery-conf and reuses the
pg_basebackup code.

Author: Paul Guo, Jimmy Yih, Ashwin Agrawal
Reviewed-by: Alexey Kondratov, Michaël Paquier, Álvaro Herrera
Discussion: https://postgr.es/m/CAEET0ZEffUkXc48pg2iqARQgGRYDiiVxDu+yYek_bTwJF+q=Uw@mail.gmail.com

4 years agoFix SSL test for libpq connection parameter channel_binding
Michael Paquier [Mon, 30 Sep 2019 04:11:31 +0000 (13:11 +0900)]
Fix SSL test for libpq connection parameter channel_binding

When compiling Postgres with OpenSSL 1.0.1 or older versions, SCRAM's
channel binding cannot be supported as X509_get_signature_nid() is
needed, which causes a regression test with channel_binding='require' to
fail as the server cannot publish SCRAM-SHA-256-PLUS as SASL mechanism
over an SSL connection.

Fix the issue by using a method similar to c3d41cc, making the test
result conditional.  The test passes if X509_get_signature_nid() is
present, and when missing we test for a connection failure.  Testing a
connection failure is more useful than skipping the test as we should
fail the connection if channel binding is required by the client but the
server does not support it.

Reported-by: Tom Lane, Michael Paquier
Author: Michael Paquier
Discussion: https://postgr.es/m/20190927024457.GA8485@paquier.xyz
Discussion: https://postgr.es/m/24857.1569775891@sss.pgh.pa.us

4 years agoMake crash recovery ignore recovery target settings.
Fujii Masao [Mon, 30 Sep 2019 01:18:15 +0000 (10:18 +0900)]
Make crash recovery ignore recovery target settings.

In v11 or before, recovery target settings could not take effect in
crash recovery because they are specified in recovery.conf and
crash recovery always starts without recovery.conf. But commit
2dedf4d9a8 integrated recovery.conf into postgresql.conf and
which unexpectedly allowed recovery target settings to take effect
even in crash recovery. This is definitely not good behavior.

To fix the issue, this commit makes crash recovery always ignore
recovery target settings.

Back-patch to v12.

Author: Peter Eisentraut
Reviewed-by: Fujii Masao
Discussion: https://postgr.es/m/e445616d-023e-a268-8aa1-67b8b335340c@pgmasters.net

4 years agojit: Re-allow JIT compilation of execGrouping.c hashtable comparisons.
Andres Freund [Sun, 29 Sep 2019 23:24:32 +0000 (16:24 -0700)]
jit: Re-allow JIT compilation of execGrouping.c hashtable comparisons.

In the course of 5567d12ce03356687bd8 and 317ffdfeaac, I changed
BuildTupleHashTable[Ext]'s call to ExecBuildGroupingEqual to not pass
in the parent node, but NULL. Which in turn prevents the tuple
equality comparator from being JIT compiled.  While that fixes
bug #15486, it is not actually necessary after all of the above commits,
as we don't re-build the comparator when using the new
BuildTupleHashTableExt() interface (as the content of the hashtable
are reset, but the TupleHashTable itself is not).

Therefore re-allow jit compilation for callers that use
BuildTupleHashTableExt with a separate context for "metadata" and
content.

As in the previous commit, there's ongoing work to make this easier to
test to prevent such regressions in the future, but that
infrastructure is not going to be backpatchable.

The performance impact of not JIT compiling hashtable equality
comparators can be substantial e.g. for aggregation queries that
aggregate a lot of input rows to few output rows (when there are a lot
of output groups, there will be fewer comparisons).

Author: Andres Freund
Discussion: https://postgr.es/m/20190927072053.njf6prdl3vb7y7qb@alap3.anarazel.de
Backpatch: 11, just as 5567d12ce03

4 years agoFix determination when slot types for upper executor nodes are fixed.
Andres Freund [Sun, 29 Sep 2019 22:24:54 +0000 (15:24 -0700)]
Fix determination when slot types for upper executor nodes are fixed.

For many queries the fact that the tuple descriptor from the lower
node was not taken into account when determining whether the type of a
slot is fixed, lead to tuple deforming for such upper nodes not to be
JIT accelerated.

I broke this in 675af5c01e297.

There is ongoing work to enable writing regression tests for related
behavior (including a patch that would have detected this
regression), by optionally showing such details in EXPLAIN. But as it
seems unlikely that that will be suitable for stable branches, just
merge the fix for now.

While it's fairly close to the 12 release window, the fact that 11
continues to perform JITed tuple deforming in these cases, that
there's still cases where we do so in 12, and the fact that the
performance regression can be sizable, weigh in favor of fixing it
now.

Author: Andres Freund
Discussion: https://postgr.es/m/20190927072053.njf6prdl3vb7y7qb@alap3.anarazel.de
Backpatch: 12-, where 675af5c01e297 was merged.

4 years agoAllow SSL TAP tests to run on Windows
Andrew Dunstan [Sun, 29 Sep 2019 21:32:46 +0000 (17:32 -0400)]
Allow SSL TAP tests to run on Windows

Windows does not enforce key file permissions checks in libpq, and psql
can produce CRLF line endings on Windows.

Backpatch to Release 12 (CRLF) and Release 11 (permissions check)

4 years agodoc: Further clarify how recovery target parameters are applied
Peter Eisentraut [Sun, 29 Sep 2019 21:07:22 +0000 (23:07 +0200)]
doc: Further clarify how recovery target parameters are applied

Recovery target parameters are all applied even in standby mode.  The
previous documentation mostly wished they were not but this was never
the case.

Discussion: https://www.postgresql.org/message-id/flat/e445616d-023e-a268-8aa1-67b8b335340c%40pgmasters.net

4 years agoFix bogus order of error checks in new channel_binding code.
Tom Lane [Sun, 29 Sep 2019 16:35:53 +0000 (12:35 -0400)]
Fix bogus order of error checks in new channel_binding code.

Coverity pointed out that it's pretty silly to check for a null pointer
after we've already dereferenced the pointer.  To fix, just swap the
order of the two error checks.  Oversight in commit d6e612f83.

4 years agodoc: Add a link target
Peter Eisentraut [Sun, 29 Sep 2019 07:50:36 +0000 (09:50 +0200)]
doc: Add a link target

Forward-patched from PostgreSQL 12 release notes patch, for
consistency.

4 years agoFix compilation with older OpenSSL versions
Peter Eisentraut [Sat, 28 Sep 2019 13:54:02 +0000 (15:54 +0200)]
Fix compilation with older OpenSSL versions

Some older OpenSSL versions (0.9.8 branch) define TLS*_VERSION macros
but not the corresponding SSL_OP_NO_* macro, which causes the code for
handling ssl_min_protocol_version/ssl_max_protocol_version to fail to
compile.  To fix, add more #ifdefs and error handling.

Reported-by: Victor Wagner <vitus@wagner.pp.ru>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://www.postgresql.org/message-id/flat/20190924101859.09383b4f%40fafnir.local.vm

4 years agoImprove stability of partition_prune regression test.
Tom Lane [Sat, 28 Sep 2019 17:33:34 +0000 (13:33 -0400)]
Improve stability of partition_prune regression test.

This test already knew that, to get stable test output, it had to hide
"loops" counts in EXPLAIN ANALYZE results.  But that's not nearly enough:
if we get a smaller number of workers than we planned for, then the
"Workers Launched" number will change, and so will all the rows and loops
counts up to the Gather node.  This has resulted in repeated failures in
the buildfarm, so adjust the test to filter out all these counts.

(Really, we wouldn't bother with EXPLAIN ANALYZE at all here, except
that currently the only way to verify that executor-time pruning has
happened is to look for '(never executed)' annotations.  Those are
stable and needn't be filtered out.)

Back-patch to v11 where the test was introduced.

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

4 years agoRemove code relevant to OpenSSL 0.9.6 in be/fe-secure-openssl.c
Michael Paquier [Sat, 28 Sep 2019 06:22:49 +0000 (15:22 +0900)]
Remove code relevant to OpenSSL 0.9.6 in be/fe-secure-openssl.c

HEAD supports OpenSSL 0.9.8 and newer versions, and this code likely got
forgotten as its surrounding comments mention an incorrect version
number.

Author: Michael Paquier
Reviewed-by: Peter Eisentraut
Discussion: https://postgr.es/m/20190927032311.GB8485@paquier.xyz

4 years agoMake pg_regress.c unset PGDATABASE during make installcheck.
Tom Lane [Fri, 27 Sep 2019 22:19:37 +0000 (18:19 -0400)]
Make pg_regress.c unset PGDATABASE during make installcheck.

For the most part, we leave libpq-controlling environment variables
alone during "make installcheck", reasoning that connecting to the
server the user expects us to connect to may depend on those variables.
But that argument doesn't apply to PGDATABASE, since we always want
to connect to a specific database name within the server.  And failing
to unset it causes certain ECPG tests to fail, as various people have
complained of in the past.  So let's unset it.

Possibly this should be back-patched, but I'm disinclined to do that
right before 12.0 release.  Maybe later.

Discussion: https://postgr.es/m/20180318205548.2akxjqvo7hrk5wbc@alap3.anarazel.de
Discussion: https://postgr.es/m/E1bOum4-0002EA-2y@gemulon.postgresql.org

4 years agoSilence -Wmaybe-uninitialized compiler warnings in dbcommands.c.
Andres Freund [Fri, 27 Sep 2019 21:10:16 +0000 (14:10 -0700)]
Silence -Wmaybe-uninitialized compiler warnings in dbcommands.c.

When compiling postgres using gcc -O3, there are false-positive
warnings about the now initialized variables. Silence them.

Author: Peter Eisentraut, Andres Freund
Discussion: https://postgr.es/m/15fb2350-b8b8-e188-278f-0b34fdee5210@2ndquadrant.com

4 years agoHave pg_rewind run crash recovery before rewinding
Alvaro Herrera [Fri, 27 Sep 2019 19:40:01 +0000 (16:40 -0300)]
Have pg_rewind run crash recovery before rewinding

If we don't do this, the rewind fails if the server wasn't cleanly shut
down, which seems unhelpful serving no purpose.

Also provide a new option --no-ensure-shutdown to suppress this
behavior, for alleged advanced usage that prefers to avoid the crash
recovery.

Authors: Paul Guo, Jimmy Yih, Ashwin Agrawal
Reviewed-by: Álvaro Herrera
Discussion: https://postgr.es/m/CAEET0ZEffUkXc48pg2iqARQgGRYDiiVxDu+yYek_bTwJF+q=Uw@mail.gmail.com

4 years agoFix implicit-fallthrough compiler warning introduced in 6dda292d4df82.
Andres Freund [Fri, 27 Sep 2019 17:25:08 +0000 (10:25 -0700)]
Fix implicit-fallthrough compiler warning introduced in 6dda292d4df82.

For some reason at least gcc-9 warns about the fallthrough, even
though it otherwise recognizes that elog(ERROR, ...) doesn't return.

Author: Andres Freund

4 years agoANALYZE a_star and its children to avoid plan instability in tests.
Tom Lane [Fri, 27 Sep 2019 15:28:24 +0000 (11:28 -0400)]
ANALYZE a_star and its children to avoid plan instability in tests.

We've noted certain EXPLAIN queries on these tables occasionally showing
unexpected plan choices.  This seems to happen because VACUUM sometimes
fails to update relpages/reltuples for one of these single-page tables,
due to bgwriter or checkpointer holding a pin on the lone page at just
the wrong time.  To ensure those values get set, insert explicit ANALYZE
operations on these tables after we finish populating them.  This
doesn't seem to affect any other test cases, so it's a usable fix.

Back-patch to v12.  In principle the issue exists further back, but
we have not seen it before v12, so I won't risk back-patching further.

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

4 years agoFinish reverting "Insert temporary debugging output in regression tests."
Tom Lane [Fri, 27 Sep 2019 15:20:09 +0000 (11:20 -0400)]
Finish reverting "Insert temporary debugging output in regression tests."

This removes the last of the temporary debugging queries added to the
regression tests by commit f03a9ca43.  We've pretty much convinced
ourselves that the plan instability we were seeing is due to VACUUM
sometimes failing to update relpages/reltuples for a single-page table,
due to bgwriter or checkpointer holding a pin on that page at just the
wrong time.  I'll push a workaround for that separately.

Discussion: https://postgr.es/m/CA+hUKG+0CxrKRWRMf5ymN3gm+BECHna2B-q1w8onKBep4HasUw@mail.gmail.com

4 years agoDoc: clean up markup for jsonb_set and related functions.
Tom Lane [Fri, 27 Sep 2019 15:01:36 +0000 (11:01 -0400)]
Doc: clean up markup for jsonb_set and related functions.

The markup for optional parameters was neither correct nor consistent.
In passing, fix a spelling mistake.

Per report from Alex Macy.  Some of these mistakes are old, so
back-patch as appropriate.

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

4 years agodoc: Add timeline as valid recovery target in standby.signal documentation
Peter Eisentraut [Fri, 27 Sep 2019 14:21:47 +0000 (16:21 +0200)]
doc: Add timeline as valid recovery target in standby.signal documentation

The documentation states that no target settings will be used when
standby.signal is present, but this is not quite the case since
recovery_target_timeline is a valid recovery target for a standby.

Update the documentation with this exception.

Author: David Steele <david@pgmasters.net>
Discussion: https://www.postgresql.org/message-id/flat/e445616d-023e-a268-8aa1-67b8b335340c%40pgmasters.net

4 years agoAdd tab completion for EXPLAIN (SETTINGS) in psql
Michael Paquier [Fri, 27 Sep 2019 03:53:43 +0000 (12:53 +0900)]
Add tab completion for EXPLAIN (SETTINGS) in psql

Author: Justin Pryzby
Reviewed-by: Tatsuro Yamada
Discussion: https://postgr.es/m/20190927022051.GC24334@telsasoft.com
Backpatch-through: 12

4 years agoFix oversight in commit 4429f6a9e3e12bb4af6e3677fbc78cd80f160252.
Amit Kapila [Wed, 18 Sep 2019 03:44:26 +0000 (09:14 +0530)]
Fix oversight in commit 4429f6a9e3e12bb4af6e3677fbc78cd80f160252.

The test name and the following test cases suggest the index created
should be hash index, but it forgot to add 'using hash' in the test case.
This in itself won't improve code coverage as there were some other tests
which were covering the corresponding code.  However, it is better if the
added tests serve their actual purpose.

Reported-by: Paul A Jungwirth
Author: Paul A Jungwirth
Reviewed-by: Mahendra Singh
Backpatch-through: 9.4
Discussion: https://postgr.es/m/CA+renyV=Us-5XfMC25bNp-uWSj39XgHHmGE9Rh2cQKMegSj52g@mail.gmail.com

4 years agoFix lockmode initialization for custom relation options
Michael Paquier [Fri, 27 Sep 2019 00:31:20 +0000 (09:31 +0900)]
Fix lockmode initialization for custom relation options

The code was enforcing AccessExclusiveLock for all custom relation
options, which is incorrect as the APIs allow a custom lock level to be
set.

While on it, fix a couple of inconsistencies in the tests and the README
of dummy_index_am.

Oversights in commit 773df88.

Discussion: https://postgr.es/m/20190925234152.GA2115@paquier.xyz

4 years agodoc: Fix whitespace in markup
Peter Eisentraut [Thu, 26 Sep 2019 19:29:14 +0000 (21:29 +0200)]
doc: Fix whitespace in markup

4 years agodoc: Format example JSON data better
Peter Eisentraut [Thu, 26 Sep 2019 19:27:34 +0000 (21:27 +0200)]
doc: Format example JSON data better

4 years agodoc: Update a confusing sentence about SQL/JSON
Peter Eisentraut [Thu, 26 Sep 2019 14:35:10 +0000 (16:35 +0200)]
doc: Update a confusing sentence about SQL/JSON

Author: Liudmila Mantrova <l.mantrova@postgrespro.ru>
Reported-by: Jeff Janes <jeff.janes@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/CAMkU%3D1wP-SO4KpiLxHJuPezTJCmK%3DJqefLXrr3eXFO7Qku%2BtMg%40mail.gmail.com

4 years agodoc: Update note about source code formatting
Peter Eisentraut [Thu, 26 Sep 2019 08:51:39 +0000 (10:51 +0200)]
doc: Update note about source code formatting

Update the note about why not to use // comments, even though it's now
technically supported.

The note about variable declarations was dropped here because it's
addressed more properly later in the chapter.

Discussion: https://www.postgresql.org/message-id/flat/156924954640.1117.6309209869705522549%40wrigleys.postgresql.org

4 years agodoc: Reorder JSON functions documentation
Peter Eisentraut [Thu, 26 Sep 2019 07:44:22 +0000 (09:44 +0200)]
doc: Reorder JSON functions documentation

Put the description of the SQL/JSON path language after the
description of the general JSON functions and operators, instead of
before.

Discussion: https://www.postgresql.org/message-id/16968.1569189812@sss.pgh.pa.us

4 years agoFix comment in xlogreader.c
Michael Paquier [Thu, 26 Sep 2019 02:53:37 +0000 (11:53 +0900)]
Fix comment in xlogreader.c

This has been introduced by 709d003, that has moved readSegNo, readOff
and readPageTLI into a new structure called WALOpenSegment initialized
separately.

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

4 years agoCorrectly cast types to Datum and back in compareDatetime()
Alexander Korotkov [Wed, 25 Sep 2019 23:06:45 +0000 (02:06 +0300)]
Correctly cast types to Datum and back in compareDatetime()

Discussion: https://postgr.es/m/CAPpHfdteFKW6MLpXM4md99m55YAuXs0n9_P2wiTq_EmG09doUA%40mail.gmail.com

4 years agoFix handling of GENERATED columns in CREATE TABLE LIKE INCLUDING DEFAULTS.
Tom Lane [Wed, 25 Sep 2019 21:30:42 +0000 (17:30 -0400)]
Fix handling of GENERATED columns in CREATE TABLE LIKE INCLUDING DEFAULTS.

LIKE INCLUDING DEFAULTS tried to copy the attrdef expression without
copying the state of the attgenerated column.  This is in fact wrong,
because GENERATED and DEFAULT expressions are not the same kind of animal;
one can contain Vars and the other not.  We *must* copy attgenerated
when we're copying the attrdef expression.  Rearrange the if-tests
so that the expression is copied only when the correct one of
INCLUDING DEFAULTS and INCLUDING GENERATED has been specified.

Per private report from Manuel Rigger.

Tom Lane and Peter Eisentraut

4 years agoImplement jsonpath .datetime() method
Alexander Korotkov [Wed, 25 Sep 2019 18:54:14 +0000 (21:54 +0300)]
Implement jsonpath .datetime() method

This commit implements jsonpath .datetime() method as it's specified in
SQL/JSON standard.  There are no-argument and single-argument versions of
this method.  No-argument version selects first of ISO datetime formats
matching input string.  Single-argument version accepts template string as
its argument.

Additionally to .datetime() method itself this commit also implements
comparison ability of resulting date and time values.  There is some difficulty
because exising jsonb_path_*() functions are immutable, while comparison of
timezoned and non-timezoned types involves current timezone.  At first, current
timezone could be changes in session.  Moreover, timezones themselves are not
immutable and could be updated.  This is why we let existing immutable functions
throw errors on such non-immutable comparison.  In the same time this commit
provides jsonb_path_*_tz() functions which are stable and support operations
involving timezones.  As new functions are added to the system catalog,
catversion is bumped.

Support of .datetime() method was the only blocker prevents T832 from being
marked as supported.  sql_features.txt is updated correspondingly.

Extracted from original patch by Nikita Glukhov, Teodor Sigaev, Oleg Bartunov.
Heavily revised by me.  Comments were adjusted by Liudmila Mantrova.

Discussion: https://postgr.es/m/fcc6fc6a-b497-f39a-923d-aa34d0c588e8%402ndQuadrant.com
Discussion: https://postgr.es/m/CAPpHfdsZgYEra_PeCLGNoXOWYx6iU-S3wF8aX0ObQUcZU%2B4XTw%40mail.gmail.com
Author: Alexander Korotkov, Nikita Glukhov, Teodor Sigaev, Oleg Bartunov, Liudmila Mantrova
Reviewed-by: Anastasia Lubennikova, Peter Eisentraut
4 years agoAllow datetime values in JsonbValue
Alexander Korotkov [Wed, 25 Sep 2019 18:53:41 +0000 (21:53 +0300)]
Allow datetime values in JsonbValue

SQL/JSON standard allows manipulation with datetime values.  So, it appears to
be convinient to allow datetime values to be represented in JsonbValue struct.
These datetime values are allowed for temporary representation only.  During
serialization datetime values are converted into strings.

SQL/JSON requires writing timestamps with timezone in the same timezone offset
as they were parsed.  This is why we allow storage of timezone offset in
JsonbValue struct.  For the same reason timezone offset argument is added to
JsonEncodeDateTime() function.

Extracted from original patch by Nikita Glukhov, Teodor Sigaev, Oleg Bartunov.
Revised by me.  Comments were adjusted by Liudmila Mantrova.

Discussion: https://postgr.es/m/fcc6fc6a-b497-f39a-923d-aa34d0c588e8%402ndQuadrant.com
Discussion: https://postgr.es/m/CAPpHfdsZgYEra_PeCLGNoXOWYx6iU-S3wF8aX0ObQUcZU%2B4XTw%40mail.gmail.com
Author: Nikita Glukhov, Teodor Sigaev, Oleg Bartunov, Alexander Korotkov, Liudmila Mantrova
Reviewed-by: Anastasia Lubennikova, Peter Eisentraut
4 years agoError suppression support for upcoming jsonpath .datetime() method
Alexander Korotkov [Wed, 25 Sep 2019 18:51:47 +0000 (21:51 +0300)]
Error suppression support for upcoming jsonpath .datetime() method

Add support of error suppression in some date and time manipulation functions
as it's required for jsonpath .datetime() method support.  This commit doesn't
use PG_TRY()/PG_CATCH() in order to implement that.  Instead, it provides
internal versions of date and time functions used, which support error
suppression.

Discussion: https://postgr.es/m/CAPpHfdsZgYEra_PeCLGNoXOWYx6iU-S3wF8aX0ObQUcZU%2B4XTw%40mail.gmail.com
Author: Alexander Korotkov, Nikita Glukhov
Reviewed-by: Anastasia Lubennikova, Peter Eisentraut
4 years agoImplement parse_datetime() function
Alexander Korotkov [Wed, 25 Sep 2019 18:50:55 +0000 (21:50 +0300)]
Implement parse_datetime() function

This commit adds parse_datetime() function, which implements datetime
parsing with extended features demanded by upcoming jsonpath .datetime()
method:

 * Dynamic type identification based on template string,
 * Support for standard-conforming 'strict' mode,
 * Timezone offset is returned as separate value.

Extracted from original patch by Nikita Glukhov, Teodor Sigaev, Oleg Bartunov.
Revised by me.

Discussion: https://postgr.es/m/fcc6fc6a-b497-f39a-923d-aa34d0c588e8%402ndQuadrant.com
Discussion: https://postgr.es/m/CAPpHfdsZgYEra_PeCLGNoXOWYx6iU-S3wF8aX0ObQUcZU%2B4XTw%40mail.gmail.com
Author: Nikita Glukhov, Teodor Sigaev, Oleg Bartunov, Alexander Korotkov
Reviewed-by: Anastasia Lubennikova, Peter Eisentraut
4 years agoImplement standard datetime parsing mode
Alexander Korotkov [Wed, 25 Sep 2019 18:44:48 +0000 (21:44 +0300)]
Implement standard datetime parsing mode

SQL Standard 2016 defines rules for handling separators in datetime template
strings, which are different to to_date()/to_timestamp() rules.  Standard
allows only small set of separators and requires strict matching for them.

Standard applies to jsonpath .datetime() method and CAST (... FORMAT ...) SQL
clause.  We're not going to change handling of separators in existing
to_date()/to_timestamp() functions, because their current behavior is familiar
for users.  Standard behavior now available by special flag, which will be used
in upcoming .datetime() jsonpath method.

Discussion: https://postgr.es/m/CAPpHfdsZgYEra_PeCLGNoXOWYx6iU-S3wF8aX0ObQUcZU%2B4XTw%40mail.gmail.com
Author: Alexander Korotkov

4 years agoUpdate expected output for dummy_index_am
Alvaro Herrera [Wed, 25 Sep 2019 19:17:19 +0000 (16:17 -0300)]
Update expected output for dummy_index_am

Forgot to add the file in the previous commit.

4 years agoSupport reloptions of enum type
Alvaro Herrera [Wed, 25 Sep 2019 18:56:52 +0000 (15:56 -0300)]
Support reloptions of enum type

All our current in core relation options of type string (not many,
admittedly) behave in reality like enums.  But after seeing an
implementation for enum reloptions, it's clear that strings are messier,
so introduce the new reloption type.  Switch all string options to be
enums instead.

Fortunately we have a recently introduced test module for reloptions, so
we don't lose coverage of string reloptions, which may still be used by
third-party modules.

Authors: Nikolay Shaplov, Álvaro Herrera
Reviewed-by: Nikita Glukhov, Aleksandr Parfenov
Discussion: https://postgr.es/m/43332102.S2V5pIjXRx@x200m

4 years agoSplit out recovery confing-writing code from pg_basebackup
Alvaro Herrera [Wed, 25 Sep 2019 17:35:24 +0000 (14:35 -0300)]
Split out recovery confing-writing code from pg_basebackup

... into a new file, fe_utils/recovery_gen.c.

This can later be used by pg_rewind.

Authors: Paul Guo, Jimmy Yih, Ashwin Agrawal.  A few tweaks by Álvaro Herrera
Reviewed-by: Michaël Paquier
Discussion: https://postgr.es/m/CAEET0ZEffUkXc48pg2iqARQgGRYDiiVxDu+yYek_bTwJF+q=Uw@mail.gmail.com

4 years agoDoc: Fix example related to partition pruning
Michael Paquier [Wed, 25 Sep 2019 04:44:30 +0000 (13:44 +0900)]
Doc: Fix example related to partition pruning

Append node has been removed in v12 when there would be only one subnode
under it.

Author: Amit Langote
Discussion: https://postgr.es/m/CA+HiwqHhS62w8zUFXF4NBjvMboCXYnD-jWoWp-tfo2aHvP3Gxg@mail.gmail.com
Backpatch-through: 12

4 years agoMake more stable regression tests of dummy_index_am for string validations
Michael Paquier [Wed, 25 Sep 2019 03:48:26 +0000 (12:48 +0900)]
Make more stable regression tests of dummy_index_am for string validations

Several buildfarm members (crake, loach and spurfowl) are complaining
about two queries looking up at pg_class.reloptions which trigger the
validation routines for string reloptions with default values.  This
commit limits the routines to be triggered only when building an index
with all custom options set in CREATE INDEX, which is sufficient for the
coverage.

Introduced by 640c198.

4 years agoAdd dummy_index_am to src/test/modules/
Michael Paquier [Wed, 25 Sep 2019 03:11:12 +0000 (12:11 +0900)]
Add dummy_index_am to src/test/modules/

This includes more tests dedicated to relation options, bringing the
coverage of this code close to 100%, and the module can be used for
other purposes, like a base template for an index AM implementation.

Author: Nikolay Sharplov, Michael Paquier
Reviewed-by: Álvaro Herrera, Dent John
Discussion: https://postgr.es/m/17071942.m9zZutALE6@x200m

4 years agoAllow definition of lock mode for custom reloptions
Michael Paquier [Wed, 25 Sep 2019 01:13:52 +0000 (10:13 +0900)]
Allow definition of lock mode for custom reloptions

Relation options can define a lock mode other than AccessExclusiveMode
since 47167b7, but modules defining custom relation options did not
really have a way to enforce that.  Correct that by extending the
current API set so as modules can define a custom lock mode.

Author: Michael Paquier
Reviewed-by: Kuntal Ghosh
Discussion: https://postgr.es/m/20190920013831.GD1844@paquier.xyz

4 years agoFix failure with lock mode used for custom relation options
Michael Paquier [Wed, 25 Sep 2019 01:07:23 +0000 (10:07 +0900)]
Fix failure with lock mode used for custom relation options

In-core relation options can use a custom lock mode since 47167b7, that
has lowered the lock available for some autovacuum parameters.  However
it forgot to consider custom relation options.  This causes failures
with ALTER TABLE SET when changing a custom relation option, as its lock
is not defined.  The existing APIs to define a custom reloption does not
allow to define a custom lock mode, so enforce its initialization to
AccessExclusiveMode which should be safe enough in all cases.  An
upcoming patch will extend the existing APIs to allow a custom lock mode
to be defined.

The problem can be reproduced with bloom indexes, so add a test there.

Reported-by: Nikolay Sharplov
Analyzed-by: Thomas Munro, Michael Paquier
Author: Michael Paquier
Reviewed-by: Kuntal Ghosh
Discussion: https://postgr.es/m/20190920013831.GD1844@paquier.xyz
Backpatch-through: 9.6

4 years agoFix bug in pairingheap_SpGistSearchItem_cmp()
Alexander Korotkov [Tue, 24 Sep 2019 22:47:36 +0000 (01:47 +0300)]
Fix bug in pairingheap_SpGistSearchItem_cmp()

Our item contains only so->numberOfNonNullOrderBys of distances.  Reflect that
in the loop upper bound.

Discussion: https://postgr.es/m/53536807-784c-e029-6e92-6da802ab8d60%40postgrespro.ru
Author: Nikita Glukhov
Backpatch-through: 12

4 years agoRework WAL-reading supporting structs
Alvaro Herrera [Tue, 24 Sep 2019 19:08:31 +0000 (16:08 -0300)]
Rework WAL-reading supporting structs

The state-tracking of WAL reading in various places was pretty messy,
mostly because the ancient physical-replication WAL reading code wasn't
using the XLogReader abstraction.  This led to some untidy code.  Make
it prettier by creating two additional supporting structs,
WALSegmentContext and WALOpenSegment which keep track of WAL-reading
state.  This makes code cleaner, as well as supports more future
cleanup.

Author: Antonin Houska
Reviewed-by: Álvaro Herrera and (older versions) Robert Haas
Discussion: https://postgr.es/m/14984.1554998742@spoje.net

4 years agoPrevent bogus pullup of constant-valued functions returning composite.
Tom Lane [Tue, 24 Sep 2019 16:11:32 +0000 (12:11 -0400)]
Prevent bogus pullup of constant-valued functions returning composite.

Fix an oversight in commit 7266d0997: as it stood, the code failed
when a function-in-FROM returns composite and can be simplified
to a composite constant.

For the moment, just test for composite result and abandon pullup
if we see one.  To make it actually work, we'd have to decompose
the composite constant into per-column constants; which is surely
do-able, but I'm not convinced it's worth the code space.

Per report from Raúl Marín Rodríguez.

Discussion: https://postgr.es/m/CAM6_UM4isP+buRA5sWodO_MUEgutms-KDfnkwGmryc5DGj9XuQ@mail.gmail.com

4 years agoSpeedup truncations of relation forks.
Fujii Masao [Tue, 24 Sep 2019 08:31:26 +0000 (17:31 +0900)]
Speedup truncations of relation forks.

When a relation is truncated, shared_buffers needs to be scanned
so that any buffers for the relation forks are invalidated in it.
Previously, shared_buffers was scanned for each relation forks, i.e.,
MAIN, FSM and VM, when VACUUM truncated off any empty pages
at the end of relation or TRUNCATE truncated the relation in place.
Since shared_buffers needed to be scanned multiple times,
it could take a long time to finish those commands especially
when shared_buffers was large.

This commit changes the logic so that shared_buffers is scanned only
one time for those three relation forks.

Author: Kirk Jamison
Reviewed-by: Masahiko Sawada, Thomas Munro, Alvaro Herrera, Takayuki Tsunakawa and Fujii Masao
Discussion: https://postgr.es/m/D09B13F772D2274BB348A310EE3027C64E2067@g01jpexmbkw24

4 years agoDon't disable ccache when building with coverage support
Peter Eisentraut [Tue, 24 Sep 2019 08:00:56 +0000 (10:00 +0200)]
Don't disable ccache when building with coverage support

This was working around a bug in ccache that was fixed in ccache
3.2.2 (released 2015-05-10).  (Users of older ccache versions can
continue to set CCACHE_DISABLE themselves.)

Discussion: https://www.postgresql.org/message-id/20190530191130.GA24528@alvherre.pgsql

4 years agoFix ExprState's tag to be of type NodeTag rather than Node.
Andres Freund [Mon, 23 Sep 2019 22:28:13 +0000 (15:28 -0700)]
Fix ExprState's tag to be of type NodeTag rather than Node.

This appears to have been an oversight in b8d7f053c5c2. As it's
effectively harmless, though confusing, only fix in master.

Author: Andres Freund

4 years agoAdd libpq parameter 'channel_binding'.
Jeff Davis [Mon, 23 Sep 2019 20:45:23 +0000 (13:45 -0700)]
Add libpq parameter 'channel_binding'.

Allow clients to require channel binding to enhance security against
untrusted servers.

Author: Jeff Davis
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/227015d8417f2b4fef03f8966dbfa5cbcc4f44da.camel%40j-davis.com