]> granicus.if.org Git - postgresql/log
postgresql
7 years agoFix outdated comment
Peter Eisentraut [Wed, 23 Aug 2017 18:19:35 +0000 (14:19 -0400)]
Fix outdated comment

Author: Thomas Munro <thomas.munro@enterprisedb.com>

7 years agoImprove plural handling in error message
Peter Eisentraut [Wed, 23 Aug 2017 17:56:59 +0000 (13:56 -0400)]
Improve plural handling in error message

This does not use the normal plural handling, because no numbers appear
in the actual message.

7 years agoTweak some SCRAM error messages and code comments
Peter Eisentraut [Wed, 23 Aug 2017 16:01:43 +0000 (12:01 -0400)]
Tweak some SCRAM error messages and code comments

Clarify/correct some error messages, fix up some code comments that
confused SASL and SCRAM, and other minor fixes.  No changes in
functionality.

7 years agoFix translation marker
Peter Eisentraut [Wed, 23 Aug 2017 13:56:38 +0000 (09:56 -0400)]
Fix translation marker

This was erroneously removed in
55a70a023c3daefca9bbd68bfbe6862af10ab479.

7 years agoHash tables backed by DSA shared memory.
Andres Freund [Wed, 23 Aug 2017 05:41:32 +0000 (22:41 -0700)]
Hash tables backed by DSA shared memory.

Add general purpose chaining hash tables for DSA memory.  Unlike
DynaHash in shared memory mode, these hash tables can grow as
required, and cope with being mapped into different addresses in
different backends.

There is a wide range of potential users for such a hash table, though
it's very likely the interface will need to evolve as we come to
understand the needs of different kinds of users.  E.g support for
iterators and incremental resizing is planned for later commits and
the details of the callback signatures are likely to change.

Author: Thomas Munro
Reviewed-By: John Gorman, Andres Freund, Dilip Kumar, Robert Haas
Discussion:
https://postgr.es/m/CAEepm=3d8o8XdVwYT6O=bHKsKAM2pu2D6sV1S_=4d+jStVCE7w@mail.gmail.com
https://postgr.es/m/CAEepm=0ZtQ-SpsgCyzzYpsXS6e=kZWqk3g5Ygn3MDV7A8dabUA@mail.gmail.com

7 years agopg_upgrade: Message translatability and style fixes
Peter Eisentraut [Wed, 23 Aug 2017 00:32:17 +0000 (20:32 -0400)]
pg_upgrade: Message translatability and style fixes

7 years agodoc: Mention identity column feature in section on serial
Peter Eisentraut [Tue, 22 Aug 2017 23:55:21 +0000 (19:55 -0400)]
doc: Mention identity column feature in section on serial

Reported-by: Basil Bourque <basil.bourque@pobox.com>
7 years agoRefactor typcache.c's record typmod hash table.
Andres Freund [Tue, 22 Aug 2017 23:05:48 +0000 (16:05 -0700)]
Refactor typcache.c's record typmod hash table.

Previously, tuple descriptors were stored in chains keyed by a fixed size
array of OIDs.  That meant there were effectively two levels of collision
chain -- one inside and one outside the hash table.  Instead, let dynahash.c
look after conflicts for us by supplying a proper hash and equal function
pair.

This is a nice cleanup on its own, but also simplifies followup
changes allowing blessed TupleDescs to be shared between backends
participating in parallel query.

Author: Thomas Munro
Reviewed-By: Andres Freund
Discussion: https://postgr.es/m/CAEepm%3D34GVhOL%2BarUx56yx7OPk7%3DqpGsv3CpO54feqjAwQKm5g%40mail.gmail.com

7 years agoAdd a hash_combine function for mixing hash values.
Andres Freund [Tue, 22 Aug 2017 22:36:49 +0000 (15:36 -0700)]
Add a hash_combine function for mixing hash values.

This hash function is derived from Boost's function of the same name.

Author: Andres Freund, Thomas Munro
Discussion: https://postgr.es/m/CAEepm%3D3rdgjfxW4cKvJ0OEmya2-34B0qHNG1xV0vK7TGPJGMUQ%40mail.gmail.com
Discussion: https://postgr.es/m/20170731210844.3cwrkmsmbbpt4rjc%40alap3.anarazel.de

7 years agoDon't install ICU collation keyword variants
Peter Eisentraut [Mon, 21 Aug 2017 15:22:00 +0000 (11:22 -0400)]
Don't install ICU collation keyword variants

Users can still create them themselves.  Instead, document Unicode TR 35
collation options for ICU, so users can create all this themselves.

Reviewed-by: Peter Geoghegan <pg@bowt.ie>
7 years agoExpand set of predefined ICU locales
Peter Eisentraut [Mon, 21 Aug 2017 13:17:06 +0000 (09:17 -0400)]
Expand set of predefined ICU locales

Install language+region combinations even if they are not distinct from
the language's base locale.  This gives better long-term stability of
the set of predefined locales and makes the predefined locales less
implementation-dependent and more practical for users.

Reviewed-by: Peter Geoghegan <pg@bowt.ie>
7 years agoPush limit through subqueries to underlying sort, where possible.
Robert Haas [Mon, 21 Aug 2017 18:43:01 +0000 (14:43 -0400)]
Push limit through subqueries to underlying sort, where possible.

Douglas Doole, reviewed by Ashutosh Bapat and by me.  Minor formatting
change by me.

Discussion: http://postgr.es/m/CADE5jYLuugnEEUsyW6Q_4mZFYTxHxaVCQmGAsF0yiY8ZDggi-w@mail.gmail.com

7 years agopg_prewarm: Add automatic prewarm feature.
Robert Haas [Mon, 21 Aug 2017 18:43:00 +0000 (14:43 -0400)]
pg_prewarm: Add automatic prewarm feature.

Periodically while the server is running, and at shutdown, write out a
list of blocks in shared buffers.  When the server reaches consistency
-- unfortunatey, we can't do it before that point without breaking
things -- reload those blocks into any still-unused shared buffers.

Mithun Cy and Robert Haas, reviewed and tested by Beena Emerson,
Amit Kapila, Jim Nasby, and Rafia Sabih.

Discussion: http://postgr.es/m/CAD__OugubOs1Vy7kgF6xTjmEqTR4CrGAv8w+ZbaY_+MZeitukw@mail.gmail.com

7 years agoInject $(ICU_LIBS) regardless of platform.
Noah Misch [Mon, 21 Aug 2017 04:22:18 +0000 (21:22 -0700)]
Inject $(ICU_LIBS) regardless of platform.

It appeared in a conditional that excludes AIX, Cygwin and MinGW.  Give
ICU support a chance to work on those platforms.  Back-patch to v10,
where ICU support was introduced.

7 years agoPartially flatten struct tupleDesc so that it can be used in DSM.
Andres Freund [Sun, 20 Aug 2017 18:19:12 +0000 (11:19 -0700)]
Partially flatten struct tupleDesc so that it can be used in DSM.

TupleDesc's attributes were already stored in contiguous memory after the
struct.  Go one step further and get rid of the array of pointers to
attributes so that they can be stored in shared memory mapped at different
addresses in each backend.  This won't work for TupleDescs with contraints
and defaults, since those point to other objects, but for many purposes
only attributes are needed.

Author: Thomas Munro
Reviewed-By: Andres Freund
Discussion: https://postgr.es/m/CAEepm=0ZtQ-SpsgCyzzYpsXS6e=kZWqk3g5Ygn3MDV7A8dabUA@mail.gmail.com

7 years agoChange tupledesc->attrs[n] to TupleDescAttr(tupledesc, n).
Andres Freund [Sun, 20 Aug 2017 18:19:07 +0000 (11:19 -0700)]
Change tupledesc->attrs[n] to TupleDescAttr(tupledesc, n).

This is a mechanical change in preparation for a later commit that
will change the layout of TupleDesc.  Introducing a macro to abstract
the details of where attributes are stored will allow us to change
that in separate step and revise it in future.

Author: Thomas Munro, editorialized by Andres Freund
Reviewed-By: Andres Freund
Discussion: https://postgr.es/m/CAEepm=0ZtQ-SpsgCyzzYpsXS6e=kZWqk3g5Ygn3MDV7A8dabUA@mail.gmail.com

7 years agoFix possible core dump in parallel restore when using a TOC list.
Tom Lane [Sat, 19 Aug 2017 17:39:37 +0000 (13:39 -0400)]
Fix possible core dump in parallel restore when using a TOC list.

Commit 3eb9a5e7c unintentionally introduced an ordering dependency
into restore_toc_entries_prefork().  The existing coding of
reduce_dependencies() contains a check to skip moving a TOC entry
to the ready_list if it wasn't initially in the pending_list.
This used to suffice to prevent reduce_dependencies() from trying to
move anything into the ready_list during restore_toc_entries_prefork(),
because the pending_list stayed empty throughout that phase; but it no
longer does.  The problem doesn't manifest unless the TOC has been
reordered by SortTocFromFile, which is how I missed it in testing.

To fix, just add a test for ready_list == NULL, converting the call
with NULL from a poor man's sanity check into an explicit command
not to touch TOC items' list membership.  Clarify some of the comments
around this; in particular, note the primary purpose of the check for
pending_list membership, which is to ensure that we can't try to restore
the same item twice, in case a TOC list forces it to be restored before
its dependency count goes to zero.

Per report from Fabrízio de Royes Mello.  Back-patch to 9.3, like the
previous commit.

Discussion: https://postgr.es/m/CAFcNs+pjuv0JL_x4+=71TPUPjdLHOXA4YfT32myj_OrrZb4ohA@mail.gmail.com

7 years agoFix creation of ICU comments for keyword variants
Peter Eisentraut [Sat, 19 Aug 2017 03:02:28 +0000 (23:02 -0400)]
Fix creation of ICU comments for keyword variants

It would create the comment referring to the keyword-less parent
locale.  This was broken in ddb5fdc068635d003a0d1c303cb109d1cb3ebeb1.

7 years agoFix interaction of triggers, partitioning, and EXPLAIN ANALYZE.
Robert Haas [Fri, 18 Aug 2017 17:01:05 +0000 (13:01 -0400)]
Fix interaction of triggers, partitioning, and EXPLAIN ANALYZE.

Add a new EState member es_leaf_result_relations, so that the trigger
code knows about ResultRelInfos created by tuple routing.  Also make
sure ExplainPrintTriggers knows about partition-related
ResultRelInfos.

Etsuro Fujita, reviewed by Amit Langote

Discussion: http://postgr.es/m/57163e18-8e56-da83-337a-22f2c0008051@lab.ntt.co.jp

7 years agoTemporarily revert test case from a2b70c89ca1a5fcf6181d3c777d82e7b83d2de1b.
Tom Lane [Thu, 17 Aug 2017 22:35:14 +0000 (18:35 -0400)]
Temporarily revert test case from a2b70c89ca1a5fcf6181d3c777d82e7b83d2de1b.

That code patch was good as far as it went, but the associated test case
has exposed fundamental brain damage in the parallel scan mechanism,
which is going to take nontrivial work to correct.  In the interests of
getting the buildfarm back to green so that unrelated work can proceed,
let's temporarily remove the test case.

7 years agoDon't lock tables in RelationGetPartitionDispatchInfo.
Robert Haas [Thu, 17 Aug 2017 19:39:17 +0000 (15:39 -0400)]
Don't lock tables in RelationGetPartitionDispatchInfo.

Instead, lock them in the caller using find_all_inheritors so that
they get locked in the standard order, minimizing deadlock risks.

Also in RelationGetPartitionDispatchInfo, avoid opening tables which
are not partitioned; there's no need.

Amit Langote, reviewed by Ashutosh Bapat and Amit Khandekar

Discussion: http://postgr.es/m/91b36fa1-c197-b72f-ca6e-56c593bae68c@lab.ntt.co.jp

7 years agoRefactor validation of new partitions a little bit.
Robert Haas [Thu, 17 Aug 2017 18:49:45 +0000 (14:49 -0400)]
Refactor validation of new partitions a little bit.

Move some logic that is currently in ATExecAttachPartition to
separate functions to facilitate future code reuse.

Ashutosh Bapat and Jeevan Ladhe

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

7 years agoAttempt to clarify comments related to force_parallel_mode.
Robert Haas [Thu, 17 Aug 2017 18:04:15 +0000 (14:04 -0400)]
Attempt to clarify comments related to force_parallel_mode.

Per discussion with Tom Lane.

Discussion: http://postgr.es/m/28589.1502902172@sss.pgh.pa.us

7 years agoFix ExecReScanGatherMerge.
Tom Lane [Thu, 17 Aug 2017 17:49:22 +0000 (13:49 -0400)]
Fix ExecReScanGatherMerge.

Not surprisingly, since it'd never ever been tested, ExecReScanGatherMerge
didn't work.  Fix it, and add a regression test case to exercise it.

Amit Kapila

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

7 years agoFurther tweaks to compiler flags for PL/Perl on Windows.
Tom Lane [Thu, 17 Aug 2017 17:13:47 +0000 (13:13 -0400)]
Further tweaks to compiler flags for PL/Perl on Windows.

It now emerges that we can only rely on Perl to tell us we must use
-D_USE_32BIT_TIME_T if it's Perl 5.13.4 or later.  For older versions,
revert to our previous practice of assuming we need that symbol in
all 32-bit Windows builds.  This is not ideal, but inquiring into
which compiler version Perl was built with seems far too fragile.
In any case, we had not previously had complaints about these old
Perl versions, so let's assume this is Good Enough.  (It's still
better than the situation ante commit 5a5c2feca, in that at least
the effects are confined to PL/Perl rather than the whole PG build.)

Back-patch to all supported versions, like 5a5c2feca and predecessors.

Discussion: https://postgr.es/m/CANFyU97OVQ3+Mzfmt3MhuUm5NwPU=-FtbNH5Eb7nZL9ua8=rcA@mail.gmail.com

7 years agodoc: Update RFC URLs
Peter Eisentraut [Thu, 17 Aug 2017 15:39:00 +0000 (11:39 -0400)]
doc: Update RFC URLs

Consistently use the IETF HTML links instead of a random mix of
different sites and formats.  Correct one RFC number and fix one broken
link.

7 years agoRemove bogus line from comment.
Robert Haas [Thu, 17 Aug 2017 15:19:07 +0000 (11:19 -0400)]
Remove bogus line from comment.

Spotted by Tom Lane

Discussion: http://postgr.es/m/27897.1502901074@sss.pgh.pa.us

7 years agoAdd missing "static" marker.
Tom Lane [Thu, 17 Aug 2017 15:17:39 +0000 (11:17 -0400)]
Add missing "static" marker.

Per pademelon.

7 years agodoc: Fix table column count
Peter Eisentraut [Thu, 17 Aug 2017 14:37:12 +0000 (10:37 -0400)]
doc: Fix table column count

Author: Erik Rijkers <er@xs4all.nl>

7 years agopg_dump: Support using synchronized snapshots on standbys
Peter Eisentraut [Wed, 16 Aug 2017 23:46:50 +0000 (19:46 -0400)]
pg_dump: Support using synchronized snapshots on standbys

This became possible by commit
6c2003f8a1bbc7c192a2e83ec51581c018aa162f.  This just makes pg_dump aware
of it and updates the documentation.

Author: Petr Jelinek <petr.jelinek@2ndquadrant.com>

7 years agoFix pg_atomic_u64 initialization.
Heikki Linnakangas [Wed, 16 Aug 2017 21:48:44 +0000 (00:48 +0300)]
Fix pg_atomic_u64 initialization.

As Andres pointed out, pg_atomic_init_u64 must be used to initialize an
atomic variable, before it can be accessed with the actual atomic ops.
Trying to use pg_atomic_write_u64 on an uninitialized variable leads to a
failure with the fallback implementation that uses a spinlock.

Discussion: https://www.postgresql.org/message-id/20170816191346.d3ke5tpshhco4bnd%40alap3.anarazel.de

7 years agoExtend the default rules file for contrib/unaccent with Vietnamese letters.
Tom Lane [Wed, 16 Aug 2017 20:51:56 +0000 (16:51 -0400)]
Extend the default rules file for contrib/unaccent with Vietnamese letters.

Improve generate_unaccent_rules.py to handle composed characters whose base
is another composed character rather than a plain letter.  The net effect
of this is to add a bunch of multi-accented Vietnamese characters to
unaccent.rules.

Original complaint from Kha Nguyen, diagnosis of the script's shortcoming
by Thomas Munro.

Dang Minh Huong and Michael Paquier

Discussion: https://postgr.es/m/CALo3sF6EC8cy1F2JUz=GRf5h4LMUJTaG3qpdoiLrNbWEXL-tRg@mail.gmail.com

7 years agoMake the planner assume that the entries in a VALUES list are distinct.
Tom Lane [Wed, 16 Aug 2017 19:37:14 +0000 (15:37 -0400)]
Make the planner assume that the entries in a VALUES list are distinct.

Previously, if we had to estimate the number of distinct values in a
VALUES column, we fell back on the default behavior used whenever we lack
statistics, which effectively is that there are Min(# of entries, 200)
distinct values.  This can be very badly off with a large VALUES list,
as noted by Jeff Janes.

We could consider actually running an ANALYZE-like scan on the VALUES,
but that seems unduly expensive, and anyway it could not deliver reliable
info if the entries are not all constants.  What seems like a better choice
is to assume that the values are all distinct.  This will sometimes be just
as wrong as the old code, but it seems more likely to be more nearly right
in many common cases.  Also, it is more consistent with what happens in
some related cases, for example WHERE x = ANY(ARRAY[1,2,3,...,n]) and
WHERE x = ANY(VALUES (1),(2),(3),...,(n)) now are estimated similarly.

This was discussed some time ago, but consensus was it'd be better
to slip it in at the start of a development cycle not near the end.
(It should've gone into v10, really, but I forgot about it.)

Discussion: https://postgr.es/m/CAMkU=1xHkyPa8VQgGcCNg3RMFFvVxUdOpus1gKcFuvVi0w6Acg@mail.gmail.com

7 years agoFix shm_toc.c to always return buffer-aligned memory.
Heikki Linnakangas [Wed, 16 Aug 2017 18:52:38 +0000 (21:52 +0300)]
Fix shm_toc.c to always return buffer-aligned memory.

Previously, if you passed a non-aligned size to shm_toc_create(), the
memory returned by shm_toc_allocate() would be similarly non-aligned.
This was exposed by commit 3cda10f41b, which allocated structs containing
a pg_atomic_uint64 field with shm_toc_allocate(). On systems with
MAXIMUM_ALIGNOF = 4, such structs still need to be 8-bytes aligned, but
the memory returned by shm_toc_allocate() was only 4-bytes aligned.

It's quite bogus that we abuse BUFFERALIGN to align the structs for
pg_atomic_uint64. It doesn't really have anything to do with buffers. But
that's a separate issue.

This ought to fix the buildfarm failures on 32-bit x86 systems.

Discussion: https://www.postgresql.org/message-id/7e0a73a5-0df9-1859-b8ae-9acf122dc38d@iki.fi

7 years agodoc: Update URL of DocBook XSL stylesheets
Peter Eisentraut [Wed, 16 Aug 2017 18:44:26 +0000 (14:44 -0400)]
doc: Update URL of DocBook XSL stylesheets

Author: Masahiko Sawada <sawada.mshk@gmail.com>

7 years agodoc: Add logical replication to comparison matrix
Peter Eisentraut [Wed, 16 Aug 2017 17:59:40 +0000 (13:59 -0400)]
doc: Add logical replication to comparison matrix

Author: Steve Singer <steve@ssinger.info>

7 years agoCorrect representation of foreign tables in information schema
Peter Eisentraut [Wed, 16 Aug 2017 15:03:33 +0000 (11:03 -0400)]
Correct representation of foreign tables in information schema

tables.table_type is supposed to be 'FOREIGN' rather than 'FOREIGN
TABLE' according to the SQL standard.

7 years agoUse atomic ops to hand out pages to scan in parallel scan.
Heikki Linnakangas [Wed, 16 Aug 2017 13:18:41 +0000 (16:18 +0300)]
Use atomic ops to hand out pages to scan in parallel scan.

With a lot of CPUs, the spinlock that protects the current scan location
in a parallel scan can become a bottleneck. Use an atomic fetch-and-add
instruction instead.

David Rowley

Discussion: https://www.postgresql.org/message-id/CAKJS1f9tgsPhqBcoPjv9_KUPZvTLCZ4jy%3DB%3DbhqgaKn7cYzm-w@mail.gmail.com

7 years agoRemove dedicated B-tree root-split record types.
Heikki Linnakangas [Wed, 16 Aug 2017 09:16:18 +0000 (12:16 +0300)]
Remove dedicated B-tree root-split record types.

Since commit 40dae7ec53, which changed the way b-tree page splitting
works, there has been no difference in the handling of root, and non-root
split WAL records. We don't need to distinguish them anymore

If you're worried about the loss of debugging information, note that
usually a root split record will normally be followed by a WAL record to
create the new root page. The root page will also have the BTP_ROOT flag
set on the page itself, and there is a pointer to it from the metapage.

Author: Aleksander Alekseev
Discussion: https://www.postgresql.org/message-id/20170406122116.GA11081@e733.localdomain

7 years agoFix up some misusage of appendStringInfo() and friends
Peter Eisentraut [Wed, 16 Aug 2017 03:34:39 +0000 (23:34 -0400)]
Fix up some misusage of appendStringInfo() and friends

Change to appendStringInfoChar() or appendStringInfoString() where those
can be used.

Author: David Rowley <david.rowley@2ndquadrant.com>
Reviewed-by: Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>
7 years agoInitialize replication_slot_catalog_xmin in procarray
Peter Eisentraut [Wed, 16 Aug 2017 01:05:21 +0000 (21:05 -0400)]
Initialize replication_slot_catalog_xmin in procarray

Although not confirmed and probably rare, if the newly allocated memory
is not already zero, this could possibly have caused some problems.

Also reorder the initializations slightly so they match the order of the
struct definition.

Author: Wong, Yi Wen <yiwong@amazon.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
7 years agodoc: Document pg_receivewal exit behavior and status
Peter Eisentraut [Wed, 16 Aug 2017 00:26:58 +0000 (20:26 -0400)]
doc: Document pg_receivewal exit behavior and status

7 years agopg_receivewal: Improve verbose mode
Peter Eisentraut [Wed, 16 Aug 2017 00:25:37 +0000 (20:25 -0400)]
pg_receivewal: Improve verbose mode

Some informational messages showed up even if verbose mode was not
used.  Move them to verbose mode.

Author: Michael Paquier <michael.paquier@gmail.com>
Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
7 years agoInclude foreign tables in information_schema.table_privileges
Peter Eisentraut [Tue, 15 Aug 2017 23:27:22 +0000 (19:27 -0400)]
Include foreign tables in information_schema.table_privileges

This appears to have been an omission in the original commit
0d692a0dc9f.  All related information_schema views already include
foreign tables.

Reported-by: Nicolas Thauvin <nicolas.thauvin@dalibo.com>
7 years agopsql: Add tab completion for \pset pager
Peter Eisentraut [Tue, 15 Aug 2017 23:10:38 +0000 (19:10 -0400)]
psql: Add tab completion for \pset pager

Author: Pavel Stehule <pavel.stehule@gmail.com>

7 years agoSimplify autovacuum work-item implementation
Alvaro Herrera [Tue, 15 Aug 2017 21:14:07 +0000 (18:14 -0300)]
Simplify autovacuum work-item implementation

The initial implementation of autovacuum work-items used a dynamic
shared memory area (DSA).  However, it's argued that dynamic shared
memory is not portable enough, so we cannot rely on it being supported
everywhere; at the same time, autovacuum work-items are now a critical
part of the server, so it's not acceptable that they don't work in the
cases where dynamic shared memory is disabled.  Therefore, let's fall
back to a simpler implementation of work-items that just uses
autovacuum's main shared memory segment for storage.

Discussion: https://postgr.es/m/CA+TgmobQVbz4K_+RSmiM9HeRKpy3vS5xnbkL95gSEnWijzprKQ@mail.gmail.com

7 years agoMake simpler-simple-expressions code cope with a Gather plan.
Tom Lane [Tue, 15 Aug 2017 20:49:47 +0000 (16:49 -0400)]
Make simpler-simple-expressions code cope with a Gather plan.

Commit 00418c612 expected that the plan generated for a simple-expression
query would always be a plain Result node.  However, if force_parallel_mode
is on, the planner might stick a Gather atop that.  Cope by looking through
the Gather.  For safety, assert that the Gather's tlist is trivial.

Per buildfarm.

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

7 years agoFix logical replication protocol comparison logic
Peter Eisentraut [Tue, 15 Aug 2017 20:20:20 +0000 (16:20 -0400)]
Fix logical replication protocol comparison logic

Since we currently only have one protocol, this doesn't make much of a
difference other than the error message.

Author: Yugo Nagata <nagata@sraoss.co.jp>

7 years agodoc: Add missing logical replication protocol message
Peter Eisentraut [Tue, 15 Aug 2017 19:36:18 +0000 (15:36 -0400)]
doc: Add missing logical replication protocol message

Author: Masahiko Sawada <sawada.mshk@gmail.com>

7 years agoSimplify some code in logical replication launcher
Peter Eisentraut [Tue, 15 Aug 2017 19:13:06 +0000 (15:13 -0400)]
Simplify some code in logical replication launcher

Avoid unnecessary locking calls when a subscription is disabled.

Author: Yugo Nagata <nagata@sraoss.co.jp>

7 years agodoc: Improve PDF bookmarks
Peter Eisentraut [Tue, 15 Aug 2017 18:37:44 +0000 (14:37 -0400)]
doc: Improve PDF bookmarks

Also create PDF bookmarks/ToC entries for subsections of reference
pages.  This was a regression from the previous jadetex-based build.

Reported-by: Erik Rijkers <er@xs4all.nl>
7 years agoAvoid out-of-memory in a hash join with many duplicate inner keys.
Tom Lane [Tue, 15 Aug 2017 18:05:46 +0000 (14:05 -0400)]
Avoid out-of-memory in a hash join with many duplicate inner keys.

The executor is capable of splitting buckets during a hash join if
too much memory is being used by a small number of buckets.  However,
this only helps if a bucket's population is actually divisible; if
all the hash keys are alike, the tuples still end up in the same
new bucket.  This can result in an OOM failure if there are enough
inner keys with identical hash values.  The planner's cost estimates
will bias it against choosing a hash join in such situations, but not
by so much that it will never do so.  To mitigate the OOM hazard,
explicitly estimate the hash bucket space needed by just the inner
side's most common value, and if that would exceed work_mem then
add disable_cost to the hash cost estimate.

This approach doesn't account for the possibility that two or more
common values would share the same hash value.  On the other hand,
work_mem is normally a fairly conservative bound, so that eating
two or more times that much space is probably not going to kill us.

If we have no stats about the inner side, ignore this consideration.
There was some discussion of making a conservative assumption, but that
would effectively result in disabling hash join whenever we lack stats,
which seems like an overreaction given how seldom the problem manifests
in the field.

Per a complaint from David Hinkle.  Although this could be viewed
as a bug fix, the lack of similar complaints weighs against back-
patching; indeed we waited for v11 because it seemed already rather
late in the v10 cycle to be making plan choice changes like this one.

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

7 years agoFix error handling path in autovacuum launcher
Alvaro Herrera [Tue, 15 Aug 2017 16:35:12 +0000 (13:35 -0300)]
Fix error handling path in autovacuum launcher

The original code (since 00e6a16d01) was assuming aborting the
transaction in autovacuum launcher was sufficient to release all
resources, but in reality the launcher runs quite a lot of code out of
any transactions.  Re-introduce individual cleanup calls to make abort
more robust.

Reported-by: Robert Haas
Discussion: https://postgr.es/m/CA+TgmobQVbz4K_+RSmiM9HeRKpy3vS5xnbkL95gSEnWijzprKQ@mail.gmail.com

7 years agoAssorted preparatory refactoring for partition-wise join.
Robert Haas [Tue, 15 Aug 2017 16:30:38 +0000 (12:30 -0400)]
Assorted preparatory refactoring for partition-wise join.

Instead of duplicating the logic to search for a matching
ParamPathInfo in multiple places, factor it out into a separate
function.

Pass only the relevant bits of the PartitionKey to
partition_bounds_equal instead of the whole thing, because
partition-wise join will want to call this without having a
PartitionKey available.

Adjust allow_star_schema_join and calc_nestloop_required_outer
to take relevant Relids rather than the entire Path, because
partition-wise join will want to call it with the top-parent
relids to determine whether a child join is allowable.

Ashutosh Bapat.  Review and testing of the larger patch set of which
this is a part by Amit Langote, Rajkumar Raghuwanshi, Rafia Sabih,
Thomas Munro, Dilip Kumar, and me.

Discussion: http://postgr.es/m/CA+TgmobQK80vtXjAsPZWWXd7c8u13G86gmuLupN+uUJjA+i4nA@mail.gmail.com

7 years agoSimplify plpgsql's check for simple expressions.
Tom Lane [Tue, 15 Aug 2017 16:28:39 +0000 (12:28 -0400)]
Simplify plpgsql's check for simple expressions.

plpgsql wants to recognize expressions that it can execute directly
via ExecEvalExpr() instead of going through the full SPI machinery.
Originally the test for this consisted of recursively groveling through
the post-planning expression tree to see if it contained only nodes that
plpgsql recognized as safe.  That was a major maintenance headache, since
it required updating plpgsql every time we added any kind of expression
node.  It was also kind of expensive, so over time we added various
pre-planning checks to try to short-circuit having to do that.
Robert Haas pointed out that as of the SRF-processing changes in v10,
particularly the addition of Query.hasTargetSRFs, there really isn't
any reason to make the recursive scan at all: the initial checks cover
everything we really care about.  We do have to make sure that those
checks agree with what inline_function() considers, so that inlining
of a function that formerly wasn't inlined can't cause an expression
considered simple to become non-simple.

Hence, delete the recursive function exec_simple_check_node(), and tweak
those other tests to more exactly agree with inline_function().  Adjust
some comments and function naming to match.

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

7 years agoAllow continuation lines in ecpg cppline parsing.
Michael Meskes [Tue, 15 Aug 2017 14:06:56 +0000 (16:06 +0200)]
Allow continuation lines in ecpg cppline parsing.

7 years agoDistinguish wait-for-connection from wait-for-write-ready on Windows.
Tom Lane [Tue, 15 Aug 2017 15:07:52 +0000 (11:07 -0400)]
Distinguish wait-for-connection from wait-for-write-ready on Windows.

The API for WaitLatch and friends followed the Unix convention in which
waiting for a socket connection to complete is identical to waiting for
the socket to accept a write.  While Windows provides a select(2)
emulation that agrees with that, the native WaitForMultipleObjects API
treats them as quite different --- and for some bizarre reason, it will
report a not-yet-connected socket as write-ready.  libpq itself has so
far escaped dealing with this because it waits with select(), but in
libpqwalreceiver.c we want to wait using WaitLatchOrSocket.  The semantics
mismatch resulted in replication connection failures on Windows, but only
for remote connections (apparently, localhost connections complete
immediately, or at least too fast for anyone to have noticed the problem
in single-machine testing).

To fix, introduce an additional WL_SOCKET_CONNECTED wait flag for
WaitLatchOrSocket, which is identical to WL_SOCKET_WRITEABLE on
non-Windows, but results in waiting for FD_CONNECT events on Windows.

Ideally, we would also distinguish the two conditions in the API for
PQconnectPoll(), but changing that API at this point seems infeasible.
Instead, cheat by checking for PQstatus() == CONNECTION_STARTED to
determine that we're still waiting for the connection to complete.
(This is a cheat mainly because CONNECTION_STARTED is documented as an
internal state rather than something callers should rely on.  Perhaps
we ought to change the documentation ... but this patch doesn't.)

Per reports from Jobin Augustine and Igor Neyman.  Back-patch to v10
where commit 1e8a85009 exposed this longstanding shortcoming.

Andres Freund, minor fix and some code review/beautification by me

Discussion: https://postgr.es/m/CAHBggj8g2T+ZDcACZ2FmzX9CTxkWjKBsHd6NkYB4i9Ojf6K1Fw@mail.gmail.com

7 years agoTeach adjust_appendrel_attrs(_multilevel) to do multiple translations.
Robert Haas [Tue, 15 Aug 2017 14:49:06 +0000 (10:49 -0400)]
Teach adjust_appendrel_attrs(_multilevel) to do multiple translations.

Currently, child relations are always base relations, so when we
translate parent relids to child relids, we only need to translate
a singler relid.  However, the proposed partition-wise join feature
will create child joins, which will mean we need to translate a set
of parent relids to the corresponding child relids.  This is
preliminary refactoring to make that possible.

Ashutosh Bapat.  Review and testing of the larger patch set of which
this is a part by Amit Langote, Rajkumar Raghuwanshi, Rafia Sabih,
Thomas Munro, Dilip Kumar, and me.  Some adjustments, mostly
cosmetic, by me.

Discussion: http://postgr.es/m/CA+TgmobQK80vtXjAsPZWWXd7c8u13G86gmuLupN+uUJjA+i4nA@mail.gmail.com

7 years agoAvoid unnecessary single-child Append nodes.
Robert Haas [Tue, 15 Aug 2017 13:16:33 +0000 (09:16 -0400)]
Avoid unnecessary single-child Append nodes.

Before commit d3cc37f1d801a6b5cad9bf179274a8, an inheritance parent
whose only children were temp tables of other sessions would end up
as a simple scan of the parent; but with that commit, we end up with
an Append node, per a report from Ashutosh Bapat.  Tweak the logic
so that we go back to the old way, and update the function header
comment for partitioning while we're at it.

Ashutosh Bapat, reviewed by Amit Langote and adjusted by me.

Discussion: http://postgr.es/m/CAFjFpReWJr1yTkHU=OqiMBmcYCMoSW3VPR39RBuQ_ovwDFBT5Q@mail.gmail.com

7 years agoAdd missing call to ExecReScanGatherMerge.
Robert Haas [Tue, 15 Aug 2017 12:06:36 +0000 (08:06 -0400)]
Add missing call to ExecReScanGatherMerge.

Amit Kapila

Discussion: http://postgr.es/m/CAA4eK1KeQWZOoDmDmGMwuqzPW9JhRS+ditQVFdAfGjNmMZzqMQ@mail.gmail.com

7 years agopg_dump: Add a --load-via-partition-root option.
Robert Haas [Tue, 15 Aug 2017 02:54:41 +0000 (22:54 -0400)]
pg_dump: Add a --load-via-partition-root option.

Rushabh Lathia, reviewed and somewhat revised by me.  Testing by
Rajkumar Raghuwanshi.

Discussion: http://postgr.es/m/CAGPqQf0C1he087bz9xRBOGZBuESYz9X=Fp8Ca_g+TfHgAff75g@mail.gmail.com

7 years agoExpand coverage of parallel gather merge a bit.
Andres Freund [Mon, 14 Aug 2017 22:21:26 +0000 (15:21 -0700)]
Expand coverage of parallel gather merge a bit.

Previously paths reaching heap_compare_slots weren't covered.

Author: Rushabh Lathia
Reviewed-By: Andres Freund
Discussion:
https://postgr.es/m/CAGPqQf3C+3PBujb+7m=ceWeii4-vBY=XS99LjzrpkpefvzJbFg@mail.gmail.com
https://postgr.es/m/27200.1502482851@sss.pgh.pa.us
Backpatch: 10, where gather merge was introduced

7 years agoStamp HEAD as 11devel.
Tom Lane [Mon, 14 Aug 2017 22:08:30 +0000 (18:08 -0400)]
Stamp HEAD as 11devel.

Note that we no longer require any manual adjustments to shared-library
minor version numbers, cf commit a3bce17ef.  So this should be everything.

7 years agoFinal pgindent + perltidy run for v10.
Tom Lane [Mon, 14 Aug 2017 21:29:33 +0000 (17:29 -0400)]
Final pgindent + perltidy run for v10.

7 years agoHandle elog(FATAL) during ROLLBACK more robustly.
Tom Lane [Mon, 14 Aug 2017 19:43:20 +0000 (15:43 -0400)]
Handle elog(FATAL) during ROLLBACK more robustly.

Stress testing by Andreas Seltenreich disclosed longstanding problems that
occur if a FATAL exit (e.g. due to receipt of SIGTERM) occurs while we are
trying to execute a ROLLBACK of an already-failed transaction.  In such a
case, xact.c is in TBLOCK_ABORT state, so that AbortOutOfAnyTransaction
would skip AbortTransaction and go straight to CleanupTransaction.  This
led to an assert failure in an assert-enabled build (due to the ROLLBACK's
portal still having a cleanup hook) or without assertions, to a FATAL exit
complaining about "cannot drop active portal".  The latter's not
disastrous, perhaps, but it's messy enough to want to improve it.

We don't really want to run all of AbortTransaction in this code path.
The minimum required to clean up the open portal safely is to do
AtAbort_Memory and AtAbort_Portals.  It seems like a good idea to
do AtAbort_Memory unconditionally, to be entirely sure that we are
starting with a safe CurrentMemoryContext.  That means that if the
main loop in AbortOutOfAnyTransaction does nothing, we need an extra
step at the bottom to restore CurrentMemoryContext = TopMemoryContext,
which I chose to do by invoking AtCleanup_Memory.  This'll result in
calling AtCleanup_Memory twice in many of the paths through this function,
but that seems harmless and reasonably inexpensive.

The original motivation for the assertion in AtCleanup_Portals was that
we wanted to be sure that any user-defined code executed as a consequence
of the cleanup hook runs during AbortTransaction not CleanupTransaction.
That still seems like a valid concern, and now that we've seen one case
of the assertion firing --- which means that exactly that would have
happened in a production build --- let's replace the Assert with a runtime
check.  If we see the cleanup hook still set, we'll emit a WARNING and
just drop the hook unexecuted.

This has been like this a long time, so back-patch to all supported
branches.

Discussion: https://postgr.es/m/877ey7bmun.fsf@ansel.ydns.eu

7 years agoFix typo
Peter Eisentraut [Mon, 14 Aug 2017 17:53:05 +0000 (13:53 -0400)]
Fix typo

Author: Masahiko Sawada <sawada.mshk@gmail.com>

7 years agodoc: Fix logical replication protocol doc detail
Peter Eisentraut [Mon, 14 Aug 2017 17:42:03 +0000 (13:42 -0400)]
doc: Fix logical replication protocol doc detail

Author: Masahiko Sawada <sawada.mshk@gmail.com>
Reported-by: Kyle Conroy <kyle@kyleconroy.com>
Bug: #14775

7 years agoAbsorb -D_USE_32BIT_TIME_T switch from Perl, if relevant.
Tom Lane [Mon, 14 Aug 2017 15:48:59 +0000 (11:48 -0400)]
Absorb -D_USE_32BIT_TIME_T switch from Perl, if relevant.

Commit 3c163a7fc's original choice to ignore all #define symbols whose
names begin with underscore turns out to be too simplistic.  On Windows,
some Perl installations are built with -D_USE_32BIT_TIME_T, and we must
absorb that or we get the wrong result for sizeof(PerlInterpreter).

This effectively re-reverts commit ef58b87df, which injected that symbol
in a hacky way, making it apply to all of Postgres not just PL/Perl.
More significantly, it did so on *all* 32-bit Windows builds, even when
the Perl build to be used did not select this option; so that it fails
to work properly with some newer Perl builds.

By making this change, we would be introducing an ABI break in 32-bit
Windows builds; but fortunately we have not used type time_t in any
exported Postgres APIs in a long time.  So it should be OK, both for
PL/Perl itself and for third-party extensions, if an extension library
is built with a different _USE_32BIT_TIME_T setting than the core code.

Patch by me, based on research by Ashutosh Sharma and Robert Haas.
Back-patch to all supported branches, as commit 3c163a7fc was.

Discussion: https://postgr.es/m/CANFyU97OVQ3+Mzfmt3MhuUm5NwPU=-FtbNH5Eb7nZL9ua8=rcA@mail.gmail.com

7 years agoChanged ecpg parser to allow RETURNING clauses without attached C variables.
Michael Meskes [Mon, 14 Aug 2017 09:29:34 +0000 (11:29 +0200)]
Changed ecpg parser to allow RETURNING clauses without attached C variables.

7 years agoRemove AtEOXact_CatCache().
Tom Lane [Sun, 13 Aug 2017 20:15:14 +0000 (16:15 -0400)]
Remove AtEOXact_CatCache().

The sole useful effect of this function, to check that no catcache
entries have positive refcounts at transaction end, has really been
obsolete since we introduced ResourceOwners in PG 8.1.  We reduced the
checks to assertions years ago, so that the function was a complete
no-op in production builds.  There have been previous discussions about
removing it entirely, but consensus up to now was that it had some small
value as a cross-check for bugs in the ResourceOwner logic.

However, it now emerges that it's possible to trigger these assertions
if you hit an assert-enabled backend with SIGTERM during a call to
SearchCatCacheList, because that function temporarily increases the
refcounts of entries it's intending to add to a catcache list construct.
In a normal ERROR scenario, the extra refcounts are cleaned up by
SearchCatCacheList's PG_CATCH block; but in a FATAL exit we do a
transaction abort and exit without ever executing PG_CATCH handlers.

There's a case to be made that this is a generic hazard and we should
consider restructuring elog(FATAL) handling so that pending PG_CATCH
handlers do get run.  That's pretty scary though: it could easily create
more problems than it solves.  Preliminary stress testing by Andreas
Seltenreich suggests that there are not many live problems of this ilk,
so we rejected that idea.

There are more-localized ways to fix the problem; the most principled
one would be to use PG_ENSURE_ERROR_CLEANUP instead of plain PG_TRY.
But adding cycles to SearchCatCacheList isn't very appealing.  We could
also weaken the assertions in AtEOXact_CatCache in some more or less
ad-hoc way, but that just makes its raison d'etre even less compelling.
In the end, the most reasonable solution seems to be to just remove
AtEOXact_CatCache altogether, on the grounds that it's not worth trying
to fix it.  It hasn't found any bugs for us in many years.

Per report from Jeevan Chalke.  Back-patch to all supported branches.

Discussion: https://postgr.es/m/CAM2+6=VEE30YtRQCZX7_sCFsEpoUkFBV1gZazL70fqLn8rcvBA@mail.gmail.com

7 years agoReword comment for clarity
Alvaro Herrera [Sun, 13 Aug 2017 01:36:07 +0000 (21:36 -0400)]
Reword comment for clarity

Reported by Masahiko Sawada
Discussion: https://postgr.es/m/CAD21AoB+ycZ2z-4Ye=6MfQ_r0aV5r6cvVPw4kOyPdp6bHqQoBQ@mail.gmail.com

7 years agoFix vertical spanning in table "wait_event Description".
Noah Misch [Sun, 13 Aug 2017 01:19:49 +0000 (18:19 -0700)]
Fix vertical spanning in table "wait_event Description".

Michael Paquier

Discussion: https://postgr.es/m/CAB7nPqQr3KEQvXeuUNYcm7tDK2Fb9oLUQ8DU0+y0RZEoN_1_gg@mail.gmail.com

7 years agoSimplify fetch-slot-xmins logic in recovery TAP tests.
Tom Lane [Sat, 12 Aug 2017 16:08:54 +0000 (12:08 -0400)]
Simplify fetch-slot-xmins logic in recovery TAP tests.

Merge wait_slot_xmins() into get_slot_xmins().  At this point the only
place that wasn't doing a wait was the initial-state test, and a wait
there seems pretty harmless.

Michael Paquier

Discussion: https://postgr.es/m/CAB7nPqSp_SLQb2uU7am+sn4V3g1UKv8j3yZU385oAG1cG_BN9Q@mail.gmail.com

7 years agoBe more thorough about cleaning out gcov litter.
Tom Lane [Fri, 11 Aug 2017 21:39:27 +0000 (17:39 -0400)]
Be more thorough about cleaning out gcov litter.

At least on my machine, a run with code coverage enabled produces some
".gcov" files whose names begin with ".".  "rm -f *.gcov" fails to match
those, so they don't get cleaned up by "make clean".  Fix it.

7 years agoAdd regression tests exercising more code paths in nodeLimit.c.
Tom Lane [Fri, 11 Aug 2017 21:27:54 +0000 (17:27 -0400)]
Add regression tests exercising more code paths in nodeLimit.c.

Perusal of the code coverage report shows that the existing regression
test cases for LIMIT/OFFSET don't exercise the nodeLimit code paths
involving backwards scan, empty results, or null values of LIMIT/OFFSET.
Improve the coverage.

7 years agoAdd regression tests exercising the non-hashed code paths in nodeSetop.c.
Tom Lane [Fri, 11 Aug 2017 20:52:12 +0000 (16:52 -0400)]
Add regression tests exercising the non-hashed code paths in nodeSetop.c.

Perusal of the code coverage report shows that the existing regression
test cases for INTERSECT and EXCEPT seemingly all prefer the SETOP_HASHED
implementation.  Add some test cases in which we force use of the
SETOP_SORTED mode.

7 years agodoc: Add example for inet vs cidr difference
Peter Eisentraut [Fri, 11 Aug 2017 20:40:56 +0000 (16:40 -0400)]
doc: Add example for inet vs cidr difference

Reported-by: kes-kes@yandex.ru
7 years agodoc: Update description of rolreplication column
Peter Eisentraut [Fri, 11 Aug 2017 20:14:55 +0000 (16:14 -0400)]
doc: Update description of rolreplication column

Since PostgreSQL 9.6, rolreplication no longer determines whether a role
can run pg_start_backup() and pg_stop_backup(), so remove that.

Add that this attribute determines whether a role can create and drop
replication slots.

Reported-by: Fujii Masao <masao.fujii@gmail.com>
7 years agodoc: Small wording improvement
Peter Eisentraut [Fri, 11 Aug 2017 19:52:39 +0000 (15:52 -0400)]
doc: Small wording improvement

Author: Jeff Janes <jeff.janes@gmail.com>

7 years agopg_upgrade: Clarify one message
Peter Eisentraut [Fri, 11 Aug 2017 19:44:10 +0000 (15:44 -0400)]
pg_upgrade: Clarify one message

Reported-by: Dennis Björklund <db@zigo.dhs.org>
7 years agoRemove pgbench's restriction on placement of -M switch.
Tom Lane [Fri, 11 Aug 2017 19:19:40 +0000 (15:19 -0400)]
Remove pgbench's restriction on placement of -M switch.

Previously the -M switch had to appear before any switch that directly
or indirectly specified a benchmarking script.  This was both confusing
and inadequately documented, as per gripe from Tatsuo Ishii.  We can
remove the restriction at the cost of making an extra pass over the
lists of SQL commands, which seems like a cheap price (the string scans
themselves likely cost much more).  The change is just to not extract
parameters from the SQL commands until we have finished parsing the
switches and know the final value of -M.

Per discussion, we'll treat this as a low-grade bug fix and sneak it
into v10, rather than holding it for v11.

Tom Lane, reviewed by Tatsuo Ishii and Fabien Coelho

Discussion: https://postgr.es/m/20170802.110328.1963639094551443169.t-ishii@sraoss.co.jp
Discussion: https://postgr.es/m/10208.1502465077@sss.pgh.pa.us

7 years agoRemove uses of "slave" in replication contexts
Peter Eisentraut [Mon, 7 Aug 2017 21:42:47 +0000 (17:42 -0400)]
Remove uses of "slave" in replication contexts

This affects mostly code comments, some documentation, and tests.
Official APIs already used "standby".

7 years agoReject use of ucol_strcollUTF8() before ICU 53
Peter Eisentraut [Thu, 10 Aug 2017 00:34:51 +0000 (20:34 -0400)]
Reject use of ucol_strcollUTF8() before ICU 53

Various bugs can cause crashes, so don't use that function before ICU
53.  It will fall back to the code path used for other encodings.

Since we now tie the function availability to an ICU version, we don't
need the configure test anymore.  That also resolves the issue that the
test result was previously hardcoded for Windows.

researched by Daniel Verite <daniel@manitou-mail.org>, Peter Geoghegan
<pg@bowt.ie>, Tom Lane <tgl@sss.pgh.pa.us>

Discussion: https://www.postgresql.org/message-id/flat/f1438ec6-22aa-4029-9a3b-26f79d330e72%40manitou-mail.org

7 years agoFix order of ICU_CFLAGS
Peter Eisentraut [Thu, 10 Aug 2017 00:28:49 +0000 (20:28 -0400)]
Fix order of ICU_CFLAGS

It must be before CPPFLAGS so that an ICU installation in a nonstandard
path can take precedence over one in the system path.

7 years agoImprove the error message when creating an empty range partition.
Robert Haas [Thu, 10 Aug 2017 17:44:30 +0000 (13:44 -0400)]
Improve the error message when creating an empty range partition.

The previous message didn't mention the name of the table or the
bounds.  Put the table name in the primary error message and the
bounds in the detail message.

Amit Langote, changed slightly by me.  Suggestions on the exac
phrasing from Tom Lane, David G. Johnston, and Dean Rasheed.

Discussion: http://postgr.es/m/CA+Tgmoae6bpwVa-1BMaVcwvCCeOoJ5B9Q9-RHWo-1gJxfPBZ5Q@mail.gmail.com

7 years agoMake some more improvements to parallel query documentation.
Robert Haas [Thu, 10 Aug 2017 17:22:31 +0000 (13:22 -0400)]
Make some more improvements to parallel query documentation.

Many places that mentioned only Gather should also mention Gather
Merge, or should be phrased in a more neutral way.  Be more clear
about the fact that max_parallel_workers_per_gather affects the number
of workers the planner may want to use.  Fix a typo.  Explain how
Gather Merge works.  Adjust wording around parallel scans to be a bit
more clear.  Adjust wording around parallel-restricted operations for
the fact that uncorrelated subplans are no longer restricted.

Patch by me, reviewed by Erik Rijkers

Discussion: http://postgr.es/m/CA+TgmoZsTjgVGn=ei5ht-1qGFKy_m1VgB3d8+Rg304hz91N5ww@mail.gmail.com

7 years agoFix typo in comment.
Robert Haas [Thu, 10 Aug 2017 17:14:47 +0000 (13:14 -0400)]
Fix typo in comment.

Etsuro Fujita

Discussion: http://postgr.es/m/5f794b91-67df-1ac6-8a4f-069f8e8e169d@lab.ntt.co.jp

7 years agopgstatindex: Insert some casts to prevent overflow.
Robert Haas [Thu, 10 Aug 2017 15:48:42 +0000 (11:48 -0400)]
pgstatindex: Insert some casts to prevent overflow.

This could cause hash indexes to report greater than 100% free space.

Ashutosh Sharma, reviewed by Amit Kapila

Discussion: http://postgr.es/m/CAE9k0PnCKfg-ZK1CwGZJPF1yKcG2A=GUgC3BMdNMzLAXVOo4Eg@mail.gmail.com

7 years agoRemove incorrect assertion in clog.c
Robert Haas [Thu, 10 Aug 2017 15:20:57 +0000 (11:20 -0400)]
Remove incorrect assertion in clog.c

We must advance the oldest XID that can be safely looked up in clog
*before* truncating CLOG, and the oldest XID that can't be reused
*after* truncating CLOG.  This assertion, and the accompanying
comment, are confused; remove them.

Reported by Neha Sharma.

Discussion: http://postgr.es/m/CANiYTQumC3T=UMBMd1Hor=5XWZYuCEQBioL3ug0YtNQCMMT5wQ@mail.gmail.com

7 years agoFix handling of container types in find_composite_type_dependencies.
Tom Lane [Wed, 9 Aug 2017 21:03:09 +0000 (17:03 -0400)]
Fix handling of container types in find_composite_type_dependencies.

find_composite_type_dependencies correctly found columns that are of
the specified type, and columns that are of arrays of that type, but
not columns that are domains or ranges over the given type, its array
type, etc.  The most general way to handle this seems to be to assume
that any type that is directly dependent on the specified type can be
treated as a container type, and processed recursively (allowing us
to handle nested cases such as ranges over domains over arrays ...).
Since a type's array type already has such a dependency, we can drop
the existing special case for the array type.

The very similar logic in get_rels_with_domain was likewise a few
bricks shy of a load, as it supposed that a directly dependent type
could *only* be a sub-domain.  This is already wrong for ranges over
domains, and it'll someday be wrong for arrays over domains.

Add test cases illustrating the problems, and back-patch to all
supported branches.

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

7 years agoPrevent passing down MAKELEVEL/MAKEFLAGS from non-GNU make to GNU make.
Tom Lane [Wed, 9 Aug 2017 16:05:53 +0000 (12:05 -0400)]
Prevent passing down MAKELEVEL/MAKEFLAGS from non-GNU make to GNU make.

FreeBSD's make, for one, sets the MAKELEVEL environment variable when
invoking commands.  In the special Makefile we provide to hand off control
from a non-GNU make to GNU make, this causes GNU make to think it is a
child make invocation rather than top-level.  That interferes with the hack
added in commit dcae5facc to cause the temp-install tree to be made only by
the top-level invocation of gmake.  Unset the variable to prevent that.

Likewise unset MAKEFLAGS, which FreeBSD's make also sets, and which could
easily confuse gmake.  There are no reports of actual trouble from that,
but it seems better to be proactive.

Back-patch to 9.5 where dcae5facc came in.

Thomas Munro, hacked a bit more by me

Discussion: https://postgr.es/m/CAEepm=1ueww35AXTkt1A3gyzZUqv5XCzh8RUNvJZAQAW=eOhVw@mail.gmail.com

7 years agodoc: Add missing pieces to logical replication protocol doc
Peter Eisentraut [Tue, 8 Aug 2017 23:18:16 +0000 (19:18 -0400)]
doc: Add missing pieces to logical replication protocol doc

Reported-by: Kyle Conroy <kyle@kyleconroy.com>
7 years agoFix datumSerialize infrastructure to not crash on non-varlena data.
Tom Lane [Tue, 8 Aug 2017 23:18:11 +0000 (19:18 -0400)]
Fix datumSerialize infrastructure to not crash on non-varlena data.

Commit 1efc7e538 did a poor job of emulating existing logic for touching
Datums that might be expanded-object pointers.  It didn't check for typlen
being -1 first, which meant it could crash on fixed-length pass-by-ref
values, and probably on cstring values as well.  It also didn't use
DatumGetPointer before VARATT_IS_EXTERNAL_EXPANDED, which while currently
harmless is not according to documentation nor prevailing style.

I also think the lack of any explanation as to why datumSerialize makes
these particular nonobvious choices is pretty awful, so fix that.

Per report from Jarred Ward.  Back-patch to 9.6 where this code came in.

Discussion: https://postgr.es/m/6F61E6D2-2F5E-4794-9479-A429BE1CEA4B@simple.com

7 years agoReword some unclear comments
Alvaro Herrera [Tue, 8 Aug 2017 22:46:16 +0000 (18:46 -0400)]
Reword some unclear comments

7 years agoFix typo in comment
Alvaro Herrera [Tue, 8 Aug 2017 22:31:39 +0000 (18:31 -0400)]
Fix typo in comment

7 years agoFix yet another race condition in recovery/t/001_stream_rep.pl.
Tom Lane [Tue, 8 Aug 2017 22:03:30 +0000 (18:03 -0400)]
Fix yet another race condition in recovery/t/001_stream_rep.pl.

In commit 5c77690f6, we added polling in front of most of the
get_slot_xmins calls in 001_stream_rep.pl, but today's results from
buildfarm member nightjar show that at least one more poll loop
is needed.

Proactively add a poll loop before the next-to-last get_slot_xmins call
as well.  It may be that there is no race condition there because the
standby_2 server is shut down at that point, but I'm quite tired of
fighting with this test script.  The empirical evidence that it's safe,
from the buildfarm, is no stronger than the evidence for the other
call that nightjar just proved unsafe.

The only remaining get_slot_xmins calls without wait_slot_xmins
protection are the first two, which should be OK since nothing has
happened at that point.  It's tempting to ignore that special case
and merge get_slot_xmins and wait_slot_xmins into a single function.
I didn't go that far though.

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

7 years agoFix replication origin-related race conditions
Alvaro Herrera [Tue, 8 Aug 2017 20:07:46 +0000 (16:07 -0400)]
Fix replication origin-related race conditions

Similar to what was fixed in commit 9915de6c1cb2 for replication slots,
but this time it's related to replication origins: DROP SUBSCRIPTION
attempts to drop the replication origin, but that fails if the
replication worker process hasn't yet marked it unused.  This causes
failures in the buildfarm:
ERROR:  could not drop replication origin with OID 1, in use by PID 34069

Like the aforementioned commit, fix by having the process running DROP
SUBSCRIPTION sleep until the worker marks the the replication origin
struct as free.  This uses a condition variable on each replication
origin shmem state struct, so that the session trying to drop can sleep
and expect to be awakened by the process keeping the origin open.

Also fix a SGML markup in the previous commit.

Discussion: https://postgr.es/m/20170808001433.rozlseaf4m2wkw3n@alvherre.pgsql

7 years agoFix inadequacies in recently added wait events
Alvaro Herrera [Tue, 8 Aug 2017 19:37:44 +0000 (15:37 -0400)]
Fix inadequacies in recently added wait events

In commit 9915de6c1cb2, we introduced a new wait point for replication
slots and incorrectly labelled it as wait event PG_WAIT_LOCK.  That's
wrong, so invent an appropriate new wait event instead, and document it
properly.

While at it, fix numerous other problems in the vicinity:
- two different walreceiver wait events were being mixed up in a single
  wait event (which wasn't documented either); split it out so that they
  can be distinguished, and document the new events properly.

- ParallelBitmapPopulate was documented but didn't exist.

- ParallelBitmapScan was not documented (I think this should be called
  "ParallelBitmapScanInit" instead.)

- Logical replication wait events weren't documented

- various symbols had been added in dartboard order in various places.
  Put them in alphabetical order instead, as was originally intended.

Discussion: https://postgr.es/m/20170808181131.mu4fjepuh5m75cyq@alvherre.pgsql

7 years agoDisclaim xmltable() support for non-UTF8 databases.
Noah Misch [Tue, 8 Aug 2017 00:16:21 +0000 (17:16 -0700)]
Disclaim xmltable() support for non-UTF8 databases.

The xmltable() implementation mirrors xpath(), including its lack of
character encoding awareness.

7 years agoStamp 10beta3. REL_10_BETA3
Tom Lane [Mon, 7 Aug 2017 21:08:19 +0000 (17:08 -0400)]
Stamp 10beta3.