]> granicus.if.org Git - postgresql/log
postgresql
7 years agoAvoid searching for callback functions in CallSyscacheCallbacks().
Tom Lane [Fri, 12 May 2017 23:05:13 +0000 (19:05 -0400)]
Avoid searching for callback functions in CallSyscacheCallbacks().

We have now grown enough registerable syscache-invalidation callback
functions that the original assumption that there would be few of them
is causing performance problems.  In particular, let's fix things so that
CallSyscacheCallbacks doesn't have to search the whole array to find
which callback(s) to invoke for a given cache ID.  Preserve the original
behavior that callbacks are called in order of registration, just in
case there's someplace that depends on that (which I doubt).

In support of this, export the number of syscaches from syscache.h.
People could have found that out anyway from the enum, but adding a
#define makes that much safer.

This provides a useful additional speedup in Mathieu Fenniak's
logical-decoding test case, although we're reaching the point of
diminishing returns there.  I think any further improvement will have
to come from reducing the number of cache invalidations that are
triggered in the first place.  Still, we can hope that this change
gives some incremental benefit for all invalidation scenarios.

Back-patch to 9.4 where logical decoding was introduced.

Discussion: https://postgr.es/m/CAHoiPjzea6N0zuCi=+f9v_j94nfsy6y8SU7-=bp4=7qw6_i=Rg@mail.gmail.com

7 years agodoc: update markup for release note "release date" block
Bruce Momjian [Fri, 12 May 2017 22:31:55 +0000 (18:31 -0400)]
doc:  update markup for release note "release date" block

This has to be backpatched to all supported releases so release markup
added to HEAD and copied to back branches matches the existing markup.

Reported-by: Peter Eisentraut
Discussion: 2b8a2552-fffa-f7c8-97c5-14db47a87731@2ndquadrant.com

Author: initial patch and sample markup by Peter Eisentraut

Backpatch-through: 9.2

7 years agoReduce initial size of RelfilenodeMapHash.
Tom Lane [Fri, 12 May 2017 22:30:02 +0000 (18:30 -0400)]
Reduce initial size of RelfilenodeMapHash.

A test case provided by Mathieu Fenniak shows that hash_seq_search'ing
this hashtable can consume a very significant amount of overhead during
logical decoding, which triggers frequent cache invalidation.  Testing
suggests that the actual population of the hashtable is often no more
than a few dozen entries, so we can cut the overhead just by dropping
the initial number of buckets down from 1024 --- I chose to cut it to 64.
(In situations where we do have a significant number of entries, we
shouldn't get any real penalty from doing this, as the dynahash.c code
will resize the hashtable automatically.)

This gives a further factor-of-two savings in Mathieu's test case.
That may be overly optimistic for real-world benefit, as real cases
may have larger average table populations, but it's hard to see it
turning into a net negative for any workload.

Back-patch to 9.4 where relfilenodemap.c was introduced.

Discussion: https://postgr.es/m/CAHoiPjzea6N0zuCi=+f9v_j94nfsy6y8SU7-=bp4=7qw6_i=Rg@mail.gmail.com

7 years agogetObjectDescription: support extended statistics
Alvaro Herrera [Fri, 12 May 2017 22:22:03 +0000 (19:22 -0300)]
getObjectDescription: support extended statistics

This was missed in 7b504eb282ca.

Remove the "default:" clause in the switch, to avoid this problem in the
future.  Other switches involving the same enum should probably be
changed in the same way, but are not touched by this patch.

Discussion: https://postgr.es/m/20170512204800.iqt2uwyx3c32j45r@alvherre.pgsql

7 years agoAvoid searching for the target catcache in CatalogCacheIdInvalidate.
Tom Lane [Fri, 12 May 2017 22:17:29 +0000 (18:17 -0400)]
Avoid searching for the target catcache in CatalogCacheIdInvalidate.

A test case provided by Mathieu Fenniak shows that the initial search for
the target catcache in CatalogCacheIdInvalidate consumes a very significant
amount of overhead in cases where cache invalidation is triggered but has
little useful work to do.  There is no good reason for that search to exist
at all, as the index array maintained by syscache.c allows direct lookup of
the catcache from its ID.  We just need a frontend function in syscache.c,
matching the division of labor for most other cache-accessing operations.

While there's more that can be done in this area, this patch alone reduces
the runtime of Mathieu's example by 2X.  We can hope that it offers some
useful benefit in other cases too, although usually cache invalidation
overhead is not such a striking fraction of the total runtime.

Back-patch to 9.4 where logical decoding was introduced.  It might be
worth going further back, but presently the only case we know of where
cache invalidation is really a significant burden is in logical decoding.
Also, older branches have fewer catcaches, reducing the possible benefit.

(Note: although this nominally changes catcache's API, we have always
documented CatalogCacheIdInvalidate as a private function, so I would
have little sympathy for an external module calling it directly.  So
backpatching should be fine.)

Discussion: https://postgr.es/m/CAHoiPjzea6N0zuCi=+f9v_j94nfsy6y8SU7-=bp4=7qw6_i=Rg@mail.gmail.com

7 years agoFix dependencies for extended statistics objects.
Tom Lane [Fri, 12 May 2017 20:26:31 +0000 (16:26 -0400)]
Fix dependencies for extended statistics objects.

A stats object ought to have a dependency on each individual column
it reads, not the entire table.  Doing this honestly lets us get rid
of the hard-wired logic in RemoveStatisticsExt, which seems to have
been misguidedly modeled on RemoveStatistics; and it will be far easier
to extend to multiple tables later.

Also, add overlooked dependency on owner, and make the dependency on
schema be NORMAL like every other such dependency.

There remains some unfinished work here, which is to allow statistics
objects to be extension members.  That takes more effort than just
adding the dependency call, though, so I left it out for now.

initdb forced because this changes the set of pg_depend records that
should exist for a statistics object.

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

7 years agoChange CREATE STATISTICS syntax
Alvaro Herrera [Fri, 12 May 2017 17:59:23 +0000 (14:59 -0300)]
Change CREATE STATISTICS syntax

Previously, we had the WITH clause in the middle of the command, where
you'd specify both generic options as well as statistic types.  Few
people liked this, so this commit changes it to remove the WITH keyword
from that clause and makes it accept statistic types only.  (We
currently don't have any generic options, but if we invent in the
future, we will gain a new WITH clause, probably at the end of the
command).

Also, the column list is now specified without parens, which makes the
whole command look more similar to a SELECT command.  This change will
let us expand the command to supporting expressions (not just columns
names) as well as multiple tables and their join conditions.

Tom added lots of code comments and fixed some parts of the CREATE
STATISTICS reference page, too; more changes in this area are
forthcoming.  He also fixed a potential problem in the alter_generic
regression test, reducing verbosity on a cascaded drop to avoid
dependency on message ordering, as we do in other tests.

Tom also closed a security bug: we documented that table ownership was
required in order to create a statistics object on it, but didn't
actually implement it.

Implement tab-completion for statistics objects.  This can stand some
more improvement.

Authors: Alvaro Herrera, with lots of cleanup by Tom Lane
Discussion: https://postgr.es/m/20170420212426.ltvgyhnefvhixm6i@alvherre.pgsql

7 years agoReplace another "transaction log" with "write-ahead log"
Peter Eisentraut [Fri, 12 May 2017 17:53:24 +0000 (13:53 -0400)]
Replace another "transaction log" with "write-ahead log"

Reported-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
7 years agoStandardize "WAL location" terminology
Peter Eisentraut [Fri, 12 May 2017 17:51:27 +0000 (13:51 -0400)]
Standardize "WAL location" terminology

Other previously used terms were "WAL position" or "log position".

7 years agoReplace "transaction log" with "write-ahead log"
Peter Eisentraut [Fri, 12 May 2017 15:49:56 +0000 (11:49 -0400)]
Replace "transaction log" with "write-ahead log"

This makes documentation and error messages match the renaming of "xlog"
to "wal" in APIs and file naming.

7 years agoHonor PROVE_FLAGS environment setting
Andrew Dunstan [Fri, 12 May 2017 15:11:49 +0000 (11:11 -0400)]
Honor PROVE_FLAGS environment setting

On MSVC builds and on back branches that means removing the hardcoded
--verbose setting. On master for Unix that means removing the empty
setting in the global Makefile so that the value can be acquired from
the environment as well as from the make arguments.

Backpatch to 9.4 where we introduced TAP tests

7 years agoAdd libxml2 include path for MSVC builds
Andrew Dunstan [Fri, 12 May 2017 14:17:54 +0000 (10:17 -0400)]
Add libxml2 include path for MSVC builds

On Unix this path is detected via the use of xml2-config, but that's not
available on Windows. This means that users building with libxml2 will
no longer need to move things around from the standard libxml2
installation for MSVC builds.

Backpatch to all live branches.

7 years agopg_dump: Add --no-publications option
Peter Eisentraut [Fri, 12 May 2017 13:15:40 +0000 (09:15 -0400)]
pg_dump: Add --no-publications option

Author: Michael Paquier <michael.paquier@gmail.com>

7 years agoRework the options syntax for logical replication commands
Peter Eisentraut [Fri, 12 May 2017 12:57:01 +0000 (08:57 -0400)]
Rework the options syntax for logical replication commands

For CREATE/ALTER PUBLICATION/SUBSCRIPTION, use similar option style as
other statements that use a WITH clause for options.

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

7 years agoAvoid tests which crash the calling process on Windows
Andrew Dunstan [Fri, 12 May 2017 10:41:23 +0000 (06:41 -0400)]
Avoid tests which crash the calling process on Windows

Certain recovery tests use the Perl IPC::Run module's start/kill_kill
method of processing. On at least some versions of perl this causes the
whole process and its caller to crash. If we ever find a better way of
doing these tests they can be re-enabled on this platform. This does not
affect Mingw or Cygwin builds, which use a different perl and a
different shell and so are not affected.

7 years agoLag tracking for logical replication
Simon Riggs [Fri, 12 May 2017 09:50:56 +0000 (10:50 +0100)]
Lag tracking for logical replication

Lag tracking is called for each commit, but we introduce
a pacing delay to ensure we don't swamp the lag tracker.

Author: Petr Jelinek, with minor pacing delay code from me

7 years agoDoc fix: scale(numeric) returns integer, not numeric.
Tom Lane [Thu, 11 May 2017 22:09:22 +0000 (18:09 -0400)]
Doc fix: scale(numeric) returns integer, not numeric.

Thinko in commit abb173392, which introduced this function.

Report: https://postgr.es/m/20170511215234.1795.54347@wrigleys.postgresql.org

7 years agoIncrease MAX_SYSCACHE_CALLBACKS to provide more room for extensions.
Tom Lane [Thu, 11 May 2017 18:51:21 +0000 (14:51 -0400)]
Increase MAX_SYSCACHE_CALLBACKS to provide more room for extensions.

Increase from the historical value of 32 to 64.  We are up to 31 callers
of CacheRegisterSyscacheCallback() in HEAD, so if they were all to be
exercised in one process that would leave only one slot for add-on modules.
It's probably not possible for that to happen, but still we clearly need
more daylight here.  (At some point it might be worth making the array
dynamically resizable; but since we've never heard a complaint of "out of
syscache_callback_list slots" happening in the field, I doubt it's worth
it yet.)

Back-patch as far as 9.4, which is where we increased the companion limit
MAX_RELCACHE_CALLBACKS (cf commit f01d1ae3a).  It's not as urgent in
released branches, which have only a couple dozen call sites in core, but
it still seems that somebody might hit the limit before these branches die.

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

7 years agoRename WAL-related functions and views to use "lsn" not "location".
Tom Lane [Thu, 11 May 2017 15:49:59 +0000 (11:49 -0400)]
Rename WAL-related functions and views to use "lsn" not "location".

Per discussion, "location" is a rather vague term that could refer to
multiple concepts.  "LSN" is an unambiguous term for WAL locations and
should be preferred.  Some function names, view column names, and function
output argument names used "lsn" already, but others used "location",
as well as yet other terms such as "wal_position".  Since we've already
renamed a lot of things in this area from "xlog" to "wal" for v10,
we may as well incur a bit more compatibility pain and make these names
all consistent.

David Rowley, minor additional docs hacking by me

Discussion: https://postgr.es/m/CAKJS1f8O0njDKe8ePFQ-LK5-EjwThsDws6ohJ-+c6nWK+oUxtg@mail.gmail.com

7 years agoRevert "Permit dump/reload of not-too-large >1GB tuples"
Alvaro Herrera [Wed, 10 May 2017 21:41:27 +0000 (18:41 -0300)]
Revert "Permit dump/reload of not-too-large >1GB tuples"

This reverts commits fa2fa9955280 and 42f50cb8fa98.

While the functionality that was intended to be provided by these
commits is desired, the patch didn't actually solve as many of the
problematic situations as we hoped, and it created a bunch of its own
problems.  Since we're going to require more extensive changes soon for
other reasons and users have been working around these problems for a
long time already, there is no point in spending effort in fixing this
halfway measure.

Per complaint from Tom Lane.
Discussion: https://postgr.es/m/21407.1484606922@sss.pgh.pa.us

(Commit fa2fa9955280 had already been reverted in branches 9.5 as
f858524ee4f and 9.6 as e9e44a0953, so this touches master only.
Commit 42f50cb8fa98 was not present in the older branches.)

7 years agopsql: Add missing translation markers
Peter Eisentraut [Wed, 10 May 2017 14:14:49 +0000 (10:14 -0400)]
psql: Add missing translation markers

7 years agoFix typo.
Robert Haas [Wed, 10 May 2017 03:57:52 +0000 (23:57 -0400)]
Fix typo.

Thomas Munro

Discussion: http://postgr.es/m/CAEepm=3vV1YKxDfLMqq-nYM2fN+STMYLwPKFCoah4M0gxqqNNg@mail.gmail.com

7 years agoAvoid theoretical infinite loop loading relcache partition key.
Robert Haas [Wed, 10 May 2017 03:51:54 +0000 (23:51 -0400)]
Avoid theoretical infinite loop loading relcache partition key.

Amit Langote, per report from 甄明洋

Discussion: http://postgr.es/m/57bd1e1.1886.15bd7b79cee.Coremail.18612389267@yeah.net

7 years agoDocument trigger-firing behavior for inheritance/partitioning.
Robert Haas [Wed, 10 May 2017 03:49:20 +0000 (23:49 -0400)]
Document trigger-firing behavior for inheritance/partitioning.

Amit Langote, reviewed Thomas Munro and by me.

Discussion: http://postgr.es/m/CA+Tgmoadpcs3=mMgdyqVX7L7L_PwO_Dn5j-98a6Tj7ByBuimUQ@mail.gmail.com

7 years agoRemove no-longer-needed compatibility code for hash indexes.
Robert Haas [Wed, 10 May 2017 03:44:21 +0000 (23:44 -0400)]
Remove no-longer-needed compatibility code for hash indexes.

Because commit ea69a0dead5128c421140dc53fac165ba4af8520 bumped the
HASH_VERSION, we don't need to worry about PostgreSQL 10 seeing
bucket pages from earlier versions.

Amit Kapila

Discussion: http://postgr.es/m/CAA4eK1LAo4DGwh+mi-G3U8Pj1WkBBeFL38xdCnUHJv1z4bZFkQ@mail.gmail.com

7 years agoFix typos in comments.
Robert Haas [Wed, 10 May 2017 03:40:08 +0000 (23:40 -0400)]
Fix typos in comments.

Etsuro Fujita

Discussion: http://postgr.es/m/968d99bf-0fa8-085b-f0a1-a379f8d661ff@lab.ntt.co.jp

7 years agoProhibit transition tables on views and foreign tables.
Robert Haas [Wed, 10 May 2017 03:34:02 +0000 (23:34 -0400)]
Prohibit transition tables on views and foreign tables.

Thomas Munro, per off-list report from Prabhat Sabu.  Changes
to the message wording for consistency with the existing
relkind check for partitioned tables by me.

Discussion: http://postgr.es/m/CAEepm=2xJFFpGM+N=gpWx-9Nft2q1oaFZX07_y23AHCrJQLt0g@mail.gmail.com

7 years agoDon't permit transition tables with TRUNCATE triggers.
Robert Haas [Wed, 10 May 2017 03:22:39 +0000 (23:22 -0400)]
Don't permit transition tables with TRUNCATE triggers.

Prior to this prohibition, such a trigger caused a crash.

Thomas Munro, per a report from Neha Sharma.  I added a
regression test.

Discussion: http://postgr.es/m/CAEepm=0VR5W-N38eTkO_FqJbGqQ_ykbBRmzmvHyxDhy1p=0Csw@mail.gmail.com

7 years agoPass EXEC_FLAG_REWIND when initializing a tuplestore scan.
Robert Haas [Wed, 10 May 2017 03:13:21 +0000 (23:13 -0400)]
Pass EXEC_FLAG_REWIND when initializing a tuplestore scan.

Since a rescan is possible, we must be able to rewind.

Thomas Munro, per a report from Prabhat Sabu

Discussion: http://postgr.es/m/CAEepm=2=Uv5fm=exqL+ygBxaO+-tgmC=o+63H4zYAXi9HtXf1w@mail.gmail.com

7 years agoDisallow finite partition bound following earlier UNBOUNDED column.
Robert Haas [Wed, 10 May 2017 02:41:12 +0000 (22:41 -0400)]
Disallow finite partition bound following earlier UNBOUNDED column.

Amit Langote, per an observation by me.

Discussion: http://postgr.es/m/CA+TgmoYWnV2GMnYLG-Czsix-E1WGAbo4D+0tx7t9NdfYBDMFsA@mail.gmail.com

7 years agoImprove memory use in logical replication apply
Peter Eisentraut [Tue, 9 May 2017 18:40:42 +0000 (14:40 -0400)]
Improve memory use in logical replication apply

Previously, the memory used by the logical replication apply worker for
processing messages would never be freed, so that could end up using a
lot of memory.  To improve that, change the existing ApplyContext memory
context to ApplyMessageContext and reset that after every
message (similar to MessageContext used elsewhere).  For consistency of
naming, rename the ApplyCacheContext to ApplyContext.

Author: Stas Kelvich <s.kelvich@postgrespro.ru>

7 years agoIgnore PQcancel errors properly
Alvaro Herrera [Tue, 9 May 2017 17:58:51 +0000 (14:58 -0300)]
Ignore PQcancel errors properly

Add a (void) cast to all PQcancel() calls that purposefully don't check
the return value, to keep compilers and static checkers happy.

Per Coverity.

7 years agopg_dump: Add --no-subscriptions option
Peter Eisentraut [Tue, 9 May 2017 14:58:06 +0000 (10:58 -0400)]
pg_dump: Add --no-subscriptions option

Author: Michael Paquier <michael.paquier@gmail.com>
Reviewed-by: Petr Jelinek <petr.jelinek@2ndquadrant.com>
7 years agodoc: Add info about replication slot management
Peter Eisentraut [Tue, 9 May 2017 14:25:26 +0000 (10:25 -0400)]
doc: Add info about replication slot management

Add some more information about managing replication slots associated
with logical replication subscriptions.

7 years agoRemove the NODROP SLOT option from DROP SUBSCRIPTION
Peter Eisentraut [Tue, 9 May 2017 14:20:42 +0000 (10:20 -0400)]
Remove the NODROP SLOT option from DROP SUBSCRIPTION

It turned out this approach had problems, because a DROP command should
not have any options other than CASCADE and RESTRICT.  Instead, always
attempt to drop the slot if there is one configured, but also add an
ALTER SUBSCRIPTION action to set the slot to NONE.

Author: Petr Jelinek <petr.jelinek@2ndquadrant.com>
Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/29431.1493730652@sss.pgh.pa.us

7 years agopgindent: use HTTP instead of FTP to retrieve pg_bsd_indent src
Bruce Momjian [Tue, 9 May 2017 13:28:44 +0000 (09:28 -0400)]
pgindent:  use HTTP instead of FTP to retrieve pg_bsd_indent src

FTP support will be removed from ftp.postgresql.org in months, but http
still works.  Typedefs already used http.

7 years agoFurther patch rangetypes_selfuncs.c's statistics slot management.
Tom Lane [Mon, 8 May 2017 19:02:57 +0000 (15:02 -0400)]
Further patch rangetypes_selfuncs.c's statistics slot management.

Values in a STATISTIC_KIND_RANGE_LENGTH_HISTOGRAM slot are float8,
not of the type of the column the statistics are for.

This bug is at least partly the fault of sloppy specification comments
for get_attstatsslot()/free_attstatsslot(): the type OID they want is that
of the stavalues entries, not of the underlying column.  (I double-checked
other callers and they seem to get this right.)  Adjust the comments to be
more correct.

Per buildfarm.

Security: CVE-2017-7484

7 years agoCheck connection info string in ALTER SUBSCRIPTION
Peter Eisentraut [Mon, 8 May 2017 18:01:00 +0000 (14:01 -0400)]
Check connection info string in ALTER SUBSCRIPTION

Previously it would allow an invalid connection string to be set.

Author: Petr Jelinek <petr.jelinek@2ndquadrant.com>
Reported-by: tushar <tushar.ahuja@enterprisedb.com>
7 years agoLast-minute updates for release notes.
Tom Lane [Mon, 8 May 2017 16:57:27 +0000 (12:57 -0400)]
Last-minute updates for release notes.

Security: CVE-2017-7484, CVE-2017-7485, CVE-2017-7486

7 years agoFix statistics reporting in logical replication workers
Peter Eisentraut [Mon, 8 May 2017 16:07:59 +0000 (12:07 -0400)]
Fix statistics reporting in logical replication workers

This new arrangement ensures that statistics are reported right after
commit of transactions.  The previous arrangement didn't get this quite
right and could lead to assertion failures.

Author: Petr Jelinek <petr.jelinek@2ndquadrant.com>
Reported-by: Erik Rijkers <er@xs4all.nl>
7 years agoFix possibly-uninitialized variable.
Tom Lane [Mon, 8 May 2017 15:18:40 +0000 (11:18 -0400)]
Fix possibly-uninitialized variable.

Oversight in e2d4ef8de et al (my fault not Peter's).  Per buildfarm.

Security: CVE-2017-7484

7 years agoMatch pg_user_mappings limits to information_schema.user_mapping_options.
Noah Misch [Mon, 8 May 2017 14:24:24 +0000 (07:24 -0700)]
Match pg_user_mappings limits to information_schema.user_mapping_options.

Both views replace the umoptions field with NULL when the user does not
meet qualifications to see it.  They used different qualifications, and
pg_user_mappings documented qualifications did not match its implemented
qualifications.  Make its documentation and implementation match those
of user_mapping_options.  One might argue for stronger qualifications,
but these have long, documented tenure.  pg_user_mappings has always
exhibited this problem, so back-patch to 9.2 (all supported versions).

Michael Paquier and Feike Steenbergen.  Reviewed by Jeff Janes.
Reported by Andrew Wheelwright.

Security: CVE-2017-7486

7 years agoRestore PGREQUIRESSL recognition in libpq.
Noah Misch [Mon, 8 May 2017 14:24:24 +0000 (07:24 -0700)]
Restore PGREQUIRESSL recognition in libpq.

Commit 65c3bf19fd3e1f6a591618e92eb4c54d0b217564 moved handling of the,
already then, deprecated requiressl parameter into conninfo_storeval().
The default PGREQUIRESSL environment variable was however lost in the
change resulting in a potentially silent accept of a non-SSL connection
even when set.  Its documentation remained.  Restore its implementation.
Also amend the documentation to mark PGREQUIRESSL as deprecated for
those not following the link to requiressl.  Back-patch to 9.3, where
commit 65c3bf1 first appeared.

Behavior has been more complex when the user provides both deprecated
and non-deprecated settings.  Before commit 65c3bf1, libpq operated
according to the first of these found:

  requiressl=1
  PGREQUIRESSL=1
  sslmode=*
  PGSSLMODE=*

(Note requiressl=0 didn't override sslmode=*; it would only suppress
PGREQUIRESSL=1 or a previous requiressl=1.  PGREQUIRESSL=0 had no effect
whatsoever.)  Starting with commit 65c3bf1, libpq ignored PGREQUIRESSL,
and order of precedence changed to this:

  last of requiressl=* or sslmode=*
  PGSSLMODE=*

Starting now, adopt the following order of precedence:

  last of requiressl=* or sslmode=*
  PGSSLMODE=*
  PGREQUIRESSL=1

This retains the 65c3bf1 behavior for connection strings that contain
both requiressl=* and sslmode=*.  It retains the 65c3bf1 change that
either connection string option overrides both environment variables.
For the first time, PGSSLMODE has precedence over PGREQUIRESSL; this
avoids reducing security of "PGREQUIRESSL=1 PGSSLMODE=verify-full"
configurations originating under v9.3 and later.

Daniel Gustafsson

Security: CVE-2017-7485

7 years agodoc: add Simon Riggs to VACUUM VERBOSE PG 10 release note item
Bruce Momjian [Mon, 8 May 2017 13:50:07 +0000 (09:50 -0400)]
doc:  add Simon Riggs to VACUUM VERBOSE PG 10 release note item

Reported-by: Masahiko Sawada
7 years agoAdd security checks to selectivity estimation functions
Peter Eisentraut [Fri, 5 May 2017 16:18:48 +0000 (12:18 -0400)]
Add security checks to selectivity estimation functions

Some selectivity estimation functions run user-supplied operators over
data obtained from pg_statistic without security checks, which allows
those operators to leak pg_statistic data without having privileges on
the underlying tables.  Fix by checking that one of the following is
satisfied: (1) the user has table or column privileges on the table
underlying the pg_statistic data, or (2) the function implementing the
user-supplied operator is leak-proof.  If neither is satisfied, planning
will proceed as if there are no statistics available.

At least one of these is satisfied in most cases in practice.  The only
situations that are negatively impacted are user-defined or
not-leak-proof operators on a security-barrier view.

Reported-by: Robert Haas <robertmhaas@gmail.com>
Author: Peter Eisentraut <peter_e@gmx.net>
Author: Tom Lane <tgl@sss.pgh.pa.us>

Security: CVE-2017-7484

7 years agoRemove support for password_encryption='off' / 'plain'.
Heikki Linnakangas [Mon, 8 May 2017 08:26:07 +0000 (11:26 +0300)]
Remove support for password_encryption='off' / 'plain'.

Storing passwords in plaintext hasn't been a good idea for a very long
time, if ever. Now seems like a good time to finally forbid it, since we're
messing with this in PostgreSQL 10 anyway.

Remove the CREATE/ALTER USER UNENCRYPTED PASSSWORD 'foo' syntax, since
storing passwords unencrypted is no longer supported. ENCRYPTED PASSWORD
'foo' is still accepted, but ENCRYPTED is now just a noise-word, it does
the same as just PASSWORD 'foo'.

Likewise, remove the --unencrypted option from createuser, but accept
--encrypted as a no-op for backward compatibility. AFAICS, --encrypted was
a no-op even before this patch, because createuser encrypted the password
before sending it to the server even if --encrypted was not specified. It
added the ENCRYPTED keyword to the SQL command, but since the password was
already in encrypted form, it didn't make any difference. The documentation
was not clear on whether that was intended or not, but it's moot now.

Also, while password_encryption='on' is still accepted as an alias for
'md5', it is now marked as hidden, so that it is not listed as an accepted
value in error hints, for example. That's not directly related to removing
'plain', but it seems better this way.

Reviewed by Michael Paquier

Discussion: https://www.postgresql.org/message-id/16e9b768-fd78-0b12-cfc1-7b6b7f238fde@iki.fi

7 years agoRemove poorly worded and duplicated comment
Simon Riggs [Mon, 8 May 2017 07:49:28 +0000 (08:49 +0100)]
Remove poorly worded and duplicated comment

Move line of code to avoid need for duplicated comment

Brought to attention by Masahiko Sawada

7 years agoRelease notes for 9.6.3, 9.5.7, 9.4.12, 9.3.17, 9.2.21.
Tom Lane [Sun, 7 May 2017 20:56:02 +0000 (16:56 -0400)]
Release notes for 9.6.3, 9.5.7, 9.4.12, 9.3.17, 9.2.21.

7 years agoThird pass on 9.6.3 release notes.
Tom Lane [Sun, 7 May 2017 18:43:04 +0000 (14:43 -0400)]
Third pass on 9.6.3 release notes.

Add updates for recent commits.

In passing, credit Etsuro Fujita for his work on the postgres_fdw
query cancel feature in 9.6; I seem to have missed that in the
original drafting of the 9.6 notes.

7 years agoFix memory leaks if random salt generation fails.
Heikki Linnakangas [Sun, 7 May 2017 16:58:21 +0000 (19:58 +0300)]
Fix memory leaks if random salt generation fails.

In the backend, this is just to silence coverity warnings, but in the
frontend, it's a genuine leak, even if extremely rare.

Spotted by Coverity, patch by Michael Paquier.

7 years agoGuard against null t->tm_zone in strftime.c.
Tom Lane [Sun, 7 May 2017 16:33:12 +0000 (12:33 -0400)]
Guard against null t->tm_zone in strftime.c.

The upstream IANA code does not guard against null TM_ZONE pointers in this
function, but in our code there is such a check in the other pre-existing
use of t->tm_zone.  We do have some places that set pg_tm.tm_zone to NULL.
I'm not entirely sure it's possible to reach strftime with such a value,
but I'm not sure it isn't either, so be safe.

Per Coverity complaint.

7 years agoInstall the "posixrules" timezone link in MSVC builds.
Tom Lane [Sun, 7 May 2017 15:57:41 +0000 (11:57 -0400)]
Install the "posixrules" timezone link in MSVC builds.

Somehow, we'd missed ever doing this.  The consequences aren't too
severe: basically, the timezone library would fall back on its hardwired
notion of the DST transition dates to use for a POSIX-style zone name,
rather than obeying US/Eastern which is the intended behavior.  The net
effect would only be to obey current US DST law further back than it
ought to apply; so it's not real surprising that nobody noticed.

David Rowley, per report from Amit Kapila

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

7 years agoRestore fullname[] contents before falling through in pg_open_tzfile().
Tom Lane [Sun, 7 May 2017 15:34:31 +0000 (11:34 -0400)]
Restore fullname[] contents before falling through in pg_open_tzfile().

Fix oversight in commit af2c5aa88: if the shortcut open() doesn't work,
we need to reset fullname[] to be just the name of the toplevel tzdata
directory before we fall through into the pre-existing code.  This failed
to be exposed in my (tgl's) testing because the fall-through path is
actually never taken under normal circumstances.

David Rowley, per report from Amit Kapila

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

7 years agodoc PG 10: adjustments to BRIN, WAL, JSON, XML items, syntax
Bruce Momjian [Sun, 7 May 2017 03:31:54 +0000 (23:31 -0400)]
doc PG 10:  adjustments to BRIN, WAL, JSON, XML items, syntax

Reported-by: Alvaro Herrera
7 years agopg_dump: Don't leak memory in buildDefaultACLCommands()
Stephen Frost [Sun, 7 May 2017 02:58:12 +0000 (22:58 -0400)]
pg_dump: Don't leak memory in buildDefaultACLCommands()

buildDefaultACLCommands() didn't destroy the string buffer created in
certain cases, leading to a memory leak.  Fix by destroying the buffer
before returning from the function.

Spotted by Coverity.

Author: Michael Paquier

Back-patch to 9.6 where buildDefaultACLCommands() was added.

7 years agoRLS: Fix ALL vs. SELECT+UPDATE policy usage
Stephen Frost [Sun, 7 May 2017 01:46:35 +0000 (21:46 -0400)]
RLS: Fix ALL vs. SELECT+UPDATE policy usage

When we add the SELECT-privilege based policies to the RLS with check
options (such as for an UPDATE statement, or when we have INSERT ...
RETURNING), we need to be sure and use the 'USING' case if the policy is
actually an 'ALL' policy (which could have both a USING clause and an
independent WITH CHECK clause).

This could result in policies acting differently when built using ALL
(when the ALL had both USING and WITH CHECK clauses) and when building
the policies independently as SELECT and UPDATE policies.

Fix this by adding an explicit boolean to add_with_check_options() to
indicate when the USING policy should be used, even if the policy has
both USING and WITH CHECK policies on it.

Reported by: Rod Taylor

Back-patch to 9.5 where RLS was introduced.

7 years agoFix duplicated words in comment.
Andres Freund [Sun, 7 May 2017 00:03:04 +0000 (17:03 -0700)]
Fix duplicated words in comment.

Reported-By: Peter Geoghegan
Discussion: https://postgr.es/m/CAH2-Wzn3rY2N0gTWndaApD113T+O8L6oz8cm7_F3P8y4awdoOg@mail.gmail.com
Backpatch: no, only present in master

7 years agoFix off-by-one possibly leading to skipped XLOG_RUNNING_XACTS records.
Andres Freund [Sat, 6 May 2017 23:47:40 +0000 (16:47 -0700)]
Fix off-by-one possibly leading to skipped XLOG_RUNNING_XACTS records.

Since 6ef2eba3f57f1 ("Skip checkpoints, archiving on idle systems."),
GetLastImportantRecPtr() is used to avoid performing superfluous
checkpoints, xlog switches, running-xact records when the system is
idle.  Unfortunately the check concerning running-xact records had a
off-by-one error, leading to such records being potentially skipped
when only a single record has been inserted since the last
running-xact record.

An alternative approach would have been to change
GetLastImportantRecPtr()'s definition to point to the end of records,
but that would make the checkpoint code more complicated.

Author: Andres Freund
Discussion: https://postgr.es/m/20170505012447.wsrympaxnfis6ojt@alap3.anarazel.de
Backpatch: no, code only present in master

7 years agoSecond pass on 9.6.3 release notes.
Tom Lane [Sat, 6 May 2017 20:28:20 +0000 (16:28 -0400)]
Second pass on 9.6.3 release notes.

Improve description of logical decoding snapshot issues, per suggestion
from Petr Jelinek.  Mention possible need to re-sync logical replicas
as a post-upgrade task.  Minor copy-editing for some other items.

7 years agoDocument current_role.
Tom Lane [Sat, 6 May 2017 18:19:47 +0000 (14:19 -0400)]
Document current_role.

This system function has been there a very long time, but somehow escaped
being listed in func.sgml.

Fabien Coelho and Tom Lane

Discussion: https://postgr.es/m/alpine.DEB.2.20.1705061027580.3896@lancre

7 years agoFirst-draft release notes for 9.6.3.
Tom Lane [Fri, 5 May 2017 23:33:34 +0000 (19:33 -0400)]
First-draft release notes for 9.6.3.

As usual, the release notes for other branches will be made by cutting
these down, but put them up for community review first.  Note there
are some entries that really only apply to pre-9.6 branches.

7 years agoSuppress compiler warning about unportable pointer value.
Tom Lane [Fri, 5 May 2017 16:46:04 +0000 (12:46 -0400)]
Suppress compiler warning about unportable pointer value.

Setting a pointer value to "0xdeadbeef" draws a warning from some
compilers, and for good reason.  Be less cute and just set it to NULL.

In passing make some other cosmetic adjustments nearby.

Discussion: https://postgr.es/m/CAJrrPGdW3EkU-CRobvVKYf3fJuBdgWyuGeAbNzAQ4yBh+bfb_Q@mail.gmail.com

7 years agoAllow MSVC to build with Tcl 8.6.
Alvaro Herrera [Fri, 5 May 2017 15:05:34 +0000 (12:05 -0300)]
Allow MSVC to build with Tcl 8.6.

Commit eaba54c20c5 added support for Tcl 8.6 for configure-supported
platforms after verifying that pltcl works without further changes, but
the MSVC tooling wasn't updated accordingly.  Update MSVC to match,
restructuring the code to avoid duplicating the logic for every Tcl
version supported.

Backpatch to all live branches, like eaba54c20c5.  In 9.4 and previous,
change the patch to use backslashes rather than forward, as in the rest
of the file.

Reported by Paresh More, who also tested the patch I provided.
Discussion: https://postgr.es/m/CAAgiCNGVw3ssBtSi3ZNstrz5k00ax=UV+_ZEHUeW_LMSGL2sew@mail.gmail.com

7 years agoPrevent panic during shutdown checkpoint
Peter Eisentraut [Mon, 1 May 2017 19:09:06 +0000 (15:09 -0400)]
Prevent panic during shutdown checkpoint

When the checkpointer writes the shutdown checkpoint, it checks
afterwards whether any WAL has been written since it started and throws
a PANIC if so.  At that point, only walsenders are still active, so one
might think this could not happen, but walsenders can also generate WAL,
for instance in BASE_BACKUP and certain variants of
CREATE_REPLICATION_SLOT.  So they can trigger this panic if such a
command is run while the shutdown checkpoint is being written.

To fix this, divide the walsender shutdown into two phases.  First, the
postmaster sends a SIGUSR2 signal to all walsenders.  The walsenders
then put themselves into the "stopping" state.  In this state, they
reject any new commands.  (For simplicity, we reject all new commands,
so that in the future we do not have to track meticulously which
commands might generate WAL.)  The checkpointer waits for all walsenders
to reach this state before proceeding with the shutdown checkpoint.
After the shutdown checkpoint is done, the postmaster sends
SIGINT (previously unused) to the walsenders.  This triggers the
existing shutdown behavior of sending out the shutdown checkpoint record
and then terminating.

Author: Michael Paquier <michael.paquier@gmail.com>
Reported-by: Fujii Masao <masao.fujii@gmail.com>
7 years agoFix wording in pg_upgrade docs
Magnus Hagander [Fri, 5 May 2017 10:42:21 +0000 (12:42 +0200)]
Fix wording in pg_upgrade docs

Author: Daniel Gustafsson

7 years agoBuild pgoutput.dll in MSVC build
Magnus Hagander [Fri, 5 May 2017 10:08:48 +0000 (12:08 +0200)]
Build pgoutput.dll in MSVC build

Without this, logical replication obviously does not work on Windows

MauMau, with clean.bet additions from me per note from Michael Paquier

7 years agoMake SCRAM salts and nonces longer.
Heikki Linnakangas [Fri, 5 May 2017 07:02:13 +0000 (10:02 +0300)]
Make SCRAM salts and nonces longer.

The salt is stored base64-encoded. With the old 10 bytes raw length, it was
always padded to 16 bytes after encoding. We might as well use 12 raw bytes
for the salt, and it's still encoded into 16 bytes.

Similarly for the random nonces, use a raw length that's divisible by 3, so
that there's no padding after base64 encoding. Make the nonces longer while
we're at it. 10 bytes was probably enough to prevent replay attacks, but
there's no reason to be skimpy here.

Per suggestion from Álvaro Hernández Tortosa.

Discussion: https://www.postgresql.org/message-id/df8c6e27-4d8e-5281-96e5-131a4e638fc8@8kdata.com

7 years agoMisc cleanup of SCRAM code.
Heikki Linnakangas [Fri, 5 May 2017 07:01:44 +0000 (10:01 +0300)]
Misc cleanup of SCRAM code.

* Remove is_scram_verifier() function. It was unused.
* Fix sanitize_char() function, used in error messages on protocol
  violations, to print bytes >= 0x7F correctly.
* Change spelling of scram_MockSalt() function to be more consistent with
  the surroundings.
* Change a few more references to "server proof" to "server signature" that
  I missed in commit d981074c24.

7 years agoDon't use SCRAM-specific "e=invalid-proof" on invalid password.
Heikki Linnakangas [Fri, 5 May 2017 07:01:41 +0000 (10:01 +0300)]
Don't use SCRAM-specific "e=invalid-proof" on invalid password.

Instead, send the same FATAL message as with other password-based
authentication mechanisms. This gives a more user-friendly message:

psql: FATAL:  password authentication failed for user "test"

instead of:

psql: error received from server in SASL exchange: invalid-proof

Even before this patch, the server sent that FATAL message, after the
SCRAM-specific "e=invalid-proof" message. But libpq would stop at the
SCRAM error message, and not process the ErrorResponse that would come
after that. We could've taught libpq to check for an ErrorResponse after
failed authentication, but it's simpler to modify the server to send only
the ErrorResponse. The SCRAM specification allows for aborting the
authentication at any point, using an application-defined error mechanism,
like PostgreSQL's ErrorResponse. Using the e=invalid-proof message is
optional.

Reported by Jeff Janes.

Discussion: https://www.postgresql.org/message-id/CAMkU%3D1w3jQ53M1OeNfN8Cxd9O%2BA_9VONJivTbYoYRRdRsLT6vA@mail.gmail.com

7 years agoChange the way pg_dump retrieves partitioning info
Stephen Frost [Fri, 5 May 2017 02:17:52 +0000 (22:17 -0400)]
Change the way pg_dump retrieves partitioning info

This gets rid of the code that issued separate queries to retrieve the
partitioning parent-child relationship, parent partition key, and child
partition bound information.  With this patch, the information is
retrieved instead using the queries issued from getTables() and
getInherits(), which is both more efficient than the previous approach
and doesn't require any new code.

Since the partitioning parent-child relationship is now retrieved with
the same old code that handles inheritance, partition attributes receive
a proper flagInhAttrs() treatment (that it didn't receive before), which
is needed so that the inherited NOT NULL constraints are not emitted if
we already emitted it for the parent.

Also, fix a bug in pg_dump's --binary-upgrade code, which caused pg_dump
to emit invalid command to attach a partition to its parent.

Author: Amit Langote, with some additional changes by me.

7 years agodoc: update PG 10 release notes
Bruce Momjian [Fri, 5 May 2017 00:33:06 +0000 (20:33 -0400)]
doc:  update PG 10 release notes

Mention vacuum verbose includes oldest xmin, BRIN index usage
estimation, and multi-column statistics.

Reported-by: Masahiko Sawada, Alvaro Herrera
7 years agodoc: PG 10 release note updates for psql, GiST, and markup
Bruce Momjian [Thu, 4 May 2017 23:33:41 +0000 (19:33 -0400)]
doc: PG 10 release note updates for psql, GiST, and markup

Reported-by: Andrew Borodin, Fabien COELHO, Dagfinn Ilmari Mannsaker
7 years agoCredit Claudio as main author of feature
Alvaro Herrera [Thu, 4 May 2017 20:50:54 +0000 (17:50 -0300)]
Credit Claudio as main author of feature

7 years agoFix pfree-of-already-freed-tuple when rescanning a GiST index-only scan.
Tom Lane [Thu, 4 May 2017 17:59:13 +0000 (13:59 -0400)]
Fix pfree-of-already-freed-tuple when rescanning a GiST index-only scan.

GiST's getNextNearest() function attempts to pfree the previously-returned
tuple if any (that is, scan->xs_hitup in HEAD, or scan->xs_itup in older
branches).  However, if we are rescanning a plan node after ending a
previous scan early, those tuple pointers could be pointing to garbage,
because they would be pointing into the scan's pageDataCxt or queueCxt
which has been reset.  In a debug build this reliably results in a crash,
although I think it might sometimes accidentally fail to fail in
production builds.

To fix, clear the pointer field anyplace we reset a context it might
be pointing into.  This may be overkill --- I think probably only the
queueCxt case is involved in this bug, so that resetting in gistrescan()
would be sufficient --- but dangling pointers are generally bad news,
so let's avoid them.

Another plausible answer might be to just not bother with the pfree in
getNextNearest().  The reconstructed tuples would go away anyway in the
context resets, and I'm far from convinced that freeing them a bit earlier
really saves anything meaningful.  I'll stick with the original logic in
this patch, but if we find more problems in the same area we should
consider that approach.

Per bug #14641 from Denis Smirnov.  Back-patch to 9.5 where this
logic was introduced.

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

7 years agoFix PQencryptPasswordConn to work with older server versions.
Heikki Linnakangas [Thu, 4 May 2017 09:28:25 +0000 (12:28 +0300)]
Fix PQencryptPasswordConn to work with older server versions.

password_encryption was a boolean before version 10, so cope with "on" and
"off".

Also, change the behavior with "plain", to treat it the same as "md5".
We're discussing removing the password_encryption='plain' option from the
server altogether, which will make this the only reasonable choice, but
even if we kept it, it seems best to never send the password in cleartext.

7 years agoFix cursor_to_xml in tableforest false mode
Peter Eisentraut [Thu, 4 May 2017 01:25:01 +0000 (21:25 -0400)]
Fix cursor_to_xml in tableforest false mode

It only produced <row> elements but no wrapping <table> element.

By contrast, cursor_to_xmlschema produced a schema that is now correct
but did not previously match the XML data produced by cursor_to_xml.

In passing, also fix a minor misunderstanding about moving cursors in
the tests related to this.

Reported-by: filip@jirsak.org
Based-on-patch-by: Thomas Munro <thomas.munro@enterprisedb.com>
7 years agoRemove useless and rather expensive stanza in matview regression test.
Tom Lane [Wed, 3 May 2017 23:37:01 +0000 (19:37 -0400)]
Remove useless and rather expensive stanza in matview regression test.

This removes a test case added by commit b69ec7cc9, which was intended
to exercise a corner case involving the rule used at that time that
materialized views were unpopulated iff they had physical size zero.
We got rid of that rule very shortly later, in commit 1d6c72a55, but
kept the test case.  However, because the case now asks what VACUUM
will do to a zero-sized physical file, it would be pretty surprising
if the answer were ever anything but "nothing" ... and if things were
indeed that broken, surely we'd find it out from other tests.  Since
the test involves a table that's fairly large by regression-test
standards (100K rows), it's quite slow to run.  Dropping it should
save some buildfarm cycles, so let's do that.

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

7 years agoAdd pg_dump tests for CREATE STATISTICS
Alvaro Herrera [Wed, 3 May 2017 18:52:00 +0000 (15:52 -0300)]
Add pg_dump tests for CREATE STATISTICS

CREATE STATISTICS pg_dump support code was not covered at all by
previous tests.

Discussion: https://postgr.es/m/20170503172746.rwftidszir67sgk7@alvherre.pgsql

7 years agopg_dump/t/002: append terminating semicolon to SQL commands
Alvaro Herrera [Wed, 3 May 2017 18:12:09 +0000 (15:12 -0300)]
pg_dump/t/002: append terminating semicolon to SQL commands

It's easy to overlook the need for one, and its lack is annoying for the
next developer wanting to create a new test.  Rather than expect every
individual command to add the semicolon, just append one automatically.

Discussion: http://postgr.es/m/20170503172746.rwftidszir67sgk7@alvherre.pgsql

7 years agoAdd PQencryptPasswordConn function to libpq, use it in psql and createuser.
Heikki Linnakangas [Wed, 3 May 2017 08:19:07 +0000 (11:19 +0300)]
Add PQencryptPasswordConn function to libpq, use it in psql and createuser.

The new function supports creating SCRAM verifiers, in addition to md5
hashes. The algorithm is chosen based on password_encryption, by default.

This fixes the issue reported by Jeff Janes, that there was previously
no way to create a SCRAM verifier with "\password".

Michael Paquier and me

Discussion: https://www.postgresql.org/message-id/CAMkU%3D1wfBgFPbfAMYZQE78p%3DVhZX7nN86aWkp0QcCp%3D%2BKxZ%3Dbg%40mail.gmail.com

7 years agoImprove performance of timezone loading, especially pg_timezone_names view.
Tom Lane [Wed, 3 May 2017 01:50:35 +0000 (21:50 -0400)]
Improve performance of timezone loading, especially pg_timezone_names view.

tzparse() would attempt to load the "posixrules" timezone database file on
each call.  That might seem like it would only be an issue when selecting a
POSIX-style zone name rather than a zone defined in the timezone database,
but it turns out that each zone definition file contains a POSIX-style zone
string and tzload() will call tzparse() to parse that.  Thus, when scanning
the whole timezone file tree as we do in the pg_timezone_names view,
"posixrules" was read repetitively for each zone definition file.  Fix
that by caching the file on first use within any given process.  (We cache
other zone definitions for the life of the process, so there seems little
reason not to cache this one as well.)  This probably won't help much in
processes that never run pg_timezone_names, but even one additional SET
of the timezone GUC would come out ahead.

An even worse problem for pg_timezone_names is that pg_open_tzfile()
has an inefficient way of identifying the canonical case of a zone name:
it basically re-descends the directory tree to the zone file.  That's not
awful for an individual "SET timezone" operation, but it's pretty horrid
when we're inspecting every zone in the database.  And it's pointless too
because we already know the canonical spelling, having just read it from
the filesystem.  Fix by teaching pg_open_tzfile() to avoid the directory
search if it's not asked for the canonical name, and backfilling the
proper result in pg_tzenumerate_next().

In combination these changes seem to make the pg_timezone_names view
about 3x faster to read, for me.  Since a scan of pg_timezone_names
has up to now been one of the slowest queries in the regression tests,
this should help some little bit for buildfarm cycle times.

Back-patch to all supported branches, not so much because it's likely
that users will care much about the view's performance as because
tracking changes in the upstream IANA timezone code is really painful
if we don't keep all the branches in sync.

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

7 years agoRemove create_singleton_array(), hard-coding the case in its sole caller.
Tom Lane [Wed, 3 May 2017 00:41:37 +0000 (20:41 -0400)]
Remove create_singleton_array(), hard-coding the case in its sole caller.

create_singleton_array() was not really as useful as we perhaps thought
when we added it.  It had never accreted more than one call site, and is
only saving a dozen lines of code at that one, which is considerably less
bulk than the function itself.  Moreover, because of its insistence on
using the caller's fn_extra cache space, it's arguably a coding hazard.
text_to_array_internal() does not currently use fn_extra in any other way,
but if it did it would be subtly broken, since the conflicting fn_extra
uses could be needed within a single query, in the seldom-tested case that
the field separator varies during the query.  The same objection seems
likely to apply to any other potential caller.

The replacement code is a bit uglier, because it hardwires knowledge of
the storage parameters of type TEXT, but it's not like we haven't got
dozens or hundreds of other places that do the same.  Uglier seems like
a good tradeoff for smaller, faster, and safer.

Per discussion with Neha Khatri.

Discussion: https://postgr.es/m/CAFO0U+_fS5SRhzq6uPG+4fbERhoA9N2+nPrtvaC9mmeWivxbsA@mail.gmail.com

7 years agoEnsure commands in extension scripts see the results of preceding DDL.
Tom Lane [Tue, 2 May 2017 22:05:53 +0000 (18:05 -0400)]
Ensure commands in extension scripts see the results of preceding DDL.

Due to a missing CommandCounterIncrement() call, parsing of a non-utility
command in an extension script would not see the effects of the immediately
preceding DDL command, unless that command's execution ends with
CommandCounterIncrement() internally ... which some do but many don't.
Report by Philippe Beaudoin, diagnosis by Julien Rouhaud.

Rather remarkably, this bug has evaded detection since extensions were
invented, so back-patch to all supported branches.

Discussion: https://postgr.es/m/2cf7941e-4e41-7714-3de8-37b1a8f74dff@free.fr

7 years agoextstats: change output functions to emit valid JSON
Alvaro Herrera [Tue, 2 May 2017 21:49:32 +0000 (18:49 -0300)]
extstats: change output functions to emit valid JSON

Manipulating extended statistics is more convenient as JSON than the
current ad-hoc format, so let's change before it's too late.

Discussion: https://postgr.es/m/20170420193828.k3fliiock5hdnehn@alvherre.pgsql

7 years agodoc: Improve order in ALTER PUBLICATION/SUBSCRIPTION ref pages
Peter Eisentraut [Tue, 2 May 2017 19:29:30 +0000 (15:29 -0400)]
doc: Improve order in ALTER PUBLICATION/SUBSCRIPTION ref pages

Move the OWNER and RENAME clauses to the end, so the interesting
functionality is listed first.  This is more typical on nearby reference
pages, whereas the previous order was the order in which the clauses
were added.

7 years agoFix typos in comments.
Robert Haas [Tue, 2 May 2017 18:47:46 +0000 (14:47 -0400)]
Fix typos in comments.

Etsuro Fujita

Discussion: http://postgr.es/m/00e88999-684d-d79a-70e4-908c937a0126@lab.ntt.co.jp

7 years agodoc: Add missing markup
Peter Eisentraut [Tue, 2 May 2017 18:33:19 +0000 (14:33 -0400)]
doc: Add missing markup

7 years agoAvoid unnecessary catalog updates in ALTER SEQUENCE
Peter Eisentraut [Tue, 2 May 2017 14:41:48 +0000 (10:41 -0400)]
Avoid unnecessary catalog updates in ALTER SEQUENCE

ALTER SEQUENCE can do nontransactional changes to the sequence (RESTART
clause) and transactional updates to the pg_sequence catalog (most other
clauses).  When just calling RESTART, the code would still needlessly do
a catalog update without any changes.  This would entangle that
operation in the concurrency issues of a catalog update (causing either
locking or concurrency errors, depending on how that issue is to be
resolved).

Fix by keeping track during options parsing whether a catalog update is
needed, and skip it if not.

Reported-by: Jason Petersen <jason@citusdata.com>
7 years agodoc: Update ALTER SEQUENCE claims about changes being nontransactional
Peter Eisentraut [Tue, 2 May 2017 14:34:49 +0000 (10:34 -0400)]
doc: Update ALTER SEQUENCE claims about changes being nontransactional

Clarify that all changes except RESTART are transactional (since
1753b1b027035029c2a2a1649065762fafbf63f3).

Reported-by: Michael Paquier <michael.paquier@gmail.com>
7 years agoFix perl thinko in commit fed6df486dca
Andrew Dunstan [Tue, 2 May 2017 12:20:11 +0000 (08:20 -0400)]
Fix perl thinko in commit fed6df486dca

Report and fix from Vaishnavi Prabakaran

Backpatch to 9.4 like original.

7 years agoChange hot_standby default value to 'on'
Magnus Hagander [Tue, 2 May 2017 09:12:30 +0000 (11:12 +0200)]
Change hot_standby default value to 'on'

This goes together with the changes made to enable replication on the
sending side by default (wal_level, max_wal_senders etc) by making the
receiving stadby node also enable it by default.

Huong Dangminh

7 years agoDon't wake up logical replication launcher unnecessarily
Peter Eisentraut [Tue, 2 May 2017 02:50:32 +0000 (22:50 -0400)]
Don't wake up logical replication launcher unnecessarily

In CREATE SUBSCRIPTION, only wake up the launcher when the subscription
is enabled.

Author: Fujii Masao <masao.fujii@gmail.com>

7 years agoImprove function header comment for create_singleton_array().
Tom Lane [Mon, 1 May 2017 19:31:41 +0000 (15:31 -0400)]
Improve function header comment for create_singleton_array().

Mentioning the caller is neither future-proof nor an adequate substitute
for giving an API specification.  Per gripe from Neha Khatri, though
I changed the patch around some.

Discussion: https://postgr.es/m/CAFO0U+_fS5SRhzq6uPG+4fbERhoA9N2+nPrtvaC9mmeWivxbsA@mail.gmail.com

7 years agoReduce semijoins with unique inner relations to plain inner joins.
Tom Lane [Mon, 1 May 2017 18:53:42 +0000 (14:53 -0400)]
Reduce semijoins with unique inner relations to plain inner joins.

If the inner relation can be proven unique, that is it can have no more
than one matching row for any row of the outer query, then we might as
well implement the semijoin as a plain inner join, allowing substantially
more freedom to the planner.  This is a form of outer join strength
reduction, but it can't be implemented in reduce_outer_joins() because
we don't have enough info about the individual relations at that stage.
Instead do it much like remove_useless_joins(): once we've built base
relations, we can make another pass over the SpecialJoinInfo list and
get rid of any entries representing reducible semijoins.

This is essentially a followon to the inner-unique patch (commit 9c7f5229a)
and makes use of the proof machinery that that patch created.  We need only
minor refactoring of innerrel_is_unique's API to support this usage.

Per performance complaint from Teodor Sigaev.

Discussion: https://postgr.es/m/f994fc98-389f-4a46-d1bc-c42e05cb43ed@sigaev.ru

7 years agoFix mis-optimization of semijoins with more than one LHS relation.
Tom Lane [Mon, 1 May 2017 18:39:11 +0000 (14:39 -0400)]
Fix mis-optimization of semijoins with more than one LHS relation.

The inner-unique patch (commit 9c7f5229a) supposed that if we're
considering a JOIN_UNIQUE_INNER join path, we can always set inner_unique
for the join, because the inner path produced by create_unique_path should
be unique relative to the outer relation.  However, that's true only if
we're considering joining to the whole outer relation --- otherwise we may
be applying only some of the join quals, and so the inner path might be
non-unique from the perspective of this join.  Adjust the test to only
believe that we can set inner_unique if we have the whole semijoin LHS on
the outer side.

There is more that can be done in this area, but this commit is only
intended to provide the minimal fix needed to get correct plans.

Per report from Teodor Sigaev.  Thanks to David Rowley for preliminary
investigation.

Discussion: https://postgr.es/m/f994fc98-389f-4a46-d1bc-c42e05cb43ed@sigaev.ru

7 years agoUpdate time zone data files to tzdata release 2017b.
Tom Lane [Mon, 1 May 2017 15:52:59 +0000 (11:52 -0400)]
Update time zone data files to tzdata release 2017b.

DST law changes in Chile, Haiti, and Mongolia.  Historical corrections for
Ecuador, Kazakhstan, Liberia, and Spain.

The IANA crew continue their campaign to replace invented time zone
abbrevations with numeric GMT offsets.  This update changes numerous zones
in South America, the Pacific and Indian oceans, and some Asian and Middle
Eastern zones.  I kept these abbreviations in the tznames/ data files,
however, so that we will still accept them for input.  (We may want to
start trimming those files someday, but I think we should wait for the
upstream dust to settle before deciding what to do.)

In passing, add MESZ (Mitteleuropaeische Sommerzeit) to the tznames lists;
since we accept MEZ (Mitteleuropaeische Zeit) it seems rather strange not
to take the other one.  And fix some incorrect, or at least obsolete,
comments that certain abbreviations are not traceable to the IANA data.

7 years agolibpq: Fix inadvertent change in .pgpass lookup behavior.
Robert Haas [Mon, 1 May 2017 15:27:09 +0000 (11:27 -0400)]
libpq: Fix inadvertent change in .pgpass lookup behavior.

Commit 274bb2b3857cc987cfa21d14775cae9b0dababa5 caused password file
lookups to use the hostaddr in preference to the host, but that was
not intended and the documented behavior is the opposite.

Report and patch by Kyotaro Horiguchi.

Discussion: http://postgr.es/m/20170428.165432.60857995.horiguchi.kyotaro@lab.ntt.co.jp

7 years agoAllow vcregress.pl to run an arbitrary TAP test set
Andrew Dunstan [Mon, 1 May 2017 14:12:02 +0000 (10:12 -0400)]
Allow vcregress.pl to run an arbitrary TAP test set

Currently only provision for running the bin checks in a single step is
provided for. Now these tests can be run individually, as well as tests
in other locations (e.g. src.test/recover).

Also provide for suppressing unnecessary temp installs by setting the
NO_TEMP_INSTALL environment variable just as the Makefiles do.

Backpatch to 9.4.

7 years agoFix logical replication launcher wake up and reset
Peter Eisentraut [Mon, 1 May 2017 14:18:09 +0000 (10:18 -0400)]
Fix logical replication launcher wake up and reset

After the logical replication launcher was told to wake up at
commit (for example, by a CREATE SUBSCRIPTION command), the flag to wake
up was not reset, so it would be woken up at every following commit as
well.  So fix that by resetting the flag.

Also, we don't need to wake up anything if the transaction was rolled
back.  Just reset the flag in that case.

Author: Masahiko Sawada <sawada.mshk@gmail.com>
Reported-by: Fujii Masao <masao.fujii@gmail.com>
7 years agoFire per-statement triggers on partitioned tables.
Robert Haas [Mon, 1 May 2017 12:23:01 +0000 (08:23 -0400)]
Fire per-statement triggers on partitioned tables.

Even though no actual tuples are ever inserted into a partitioned
table (the actual tuples are in the partitions, not the partitioned
table itself), we still need to have a ResultRelInfo for the
partitioned table, or per-statement triggers won't get fired.

Amit Langote, per a report from Rajkumar Raghuwanshi.  Reviewed by me.

Discussion: http://postgr.es/m/CAKcux6%3DwYospCRY2J4XEFuVy0L41S%3Dfic7rmkbsU-GXhhSbmBg%40mail.gmail.com