]> granicus.if.org Git - postgresql/log
postgresql
8 years agoAllow SSL server key file to have group read access if owned by root
Peter Eisentraut [Sat, 19 Mar 2016 10:03:22 +0000 (11:03 +0100)]
Allow SSL server key file to have group read access if owned by root

We used to require the server key file to have permissions 0600 or less
for best security.  But some systems (such as Debian) have certificate
and key files managed by the operating system that can be shared with
other services.  In those cases, the "postgres" user is made a member of
a special group that has access to those files, and the server key file
has permissions 0640.  To accommodate that kind of setup, also allow the
key file to have permissions 0640 but only if owned by root.

From: Christoph Berg <myon@debian.org>
Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org>
8 years agoFix stupid omission in c4901a1e.
Andres Freund [Sat, 19 Mar 2016 05:35:43 +0000 (22:35 -0700)]
Fix stupid omission in c4901a1e.

Reported-By: Jeff Janes
Discussion: CAMkU=1zGxREwoyaCrp_CHadEB+dPgpVyKBysCJ+6xP9gCOvAuw@mail.gmail.com

8 years agoFix missed update in _readForeignScan().
Tom Lane [Sat, 19 Mar 2016 05:20:34 +0000 (01:20 -0400)]
Fix missed update in _readForeignScan().

Blatant fail in 0bf3ae88af330496517722e391e7c975e6bad219.
Caught by buildfarm member mandrill.

8 years agoUse yylex_init not yylex_init_extra().
Tom Lane [Sat, 19 Mar 2016 05:02:18 +0000 (01:02 -0400)]
Use yylex_init not yylex_init_extra().

Older versions of flex don't have the latter.  Per buildfarm.

8 years agoSuppress FLEX_NO_BACKUP check for psqlscanslash.l.
Tom Lane [Sat, 19 Mar 2016 04:43:46 +0000 (00:43 -0400)]
Suppress FLEX_NO_BACKUP check for psqlscanslash.l.

The existing infrastructure for FLEX_NO_BACKUP doesn't work reliably
when two lexers are built in parallel in the same directory.  We can
probably fix that, but as a short-term workaround, just don't make
the check for psqlscanslash.l.

Per buildfarm.

8 years agoSplit psql's lexer into two separate .l files for SQL and backslash cases.
Tom Lane [Sat, 19 Mar 2016 04:24:55 +0000 (00:24 -0400)]
Split psql's lexer into two separate .l files for SQL and backslash cases.

This gets us to a point where psqlscan.l can be used by other frontend
programs for the same purpose psql uses it for, ie to detect when it's
collected a complete SQL command from input that is divided across
line boundaries.  Moreover, other programs can supply their own lexers
for backslash commands of their own choosing.  A follow-on patch will
use this in pgbench.

The end result here is roughly the same as in Kyotaro Horiguchi's
0001-Make-SQL-parser-part-of-psqlscan-independent-from-ps.patch, although
the details of the method for switching between lexers are quite different.
Basically, in this patch we share the entire PsqlScanState, YY_BUFFER_STATE
stack, *and* yyscan_t between different lexers.  The only thing we need
to do to switch to a different lexer is to make sure the start_state is
valid for the new lexer.  This works because flex doesn't keep any other
persistent state that depends on the specific lexing tables generated for
a particular .l file.  (We are assuming that both lexers are built with
the same flex version, or at least versions that are compatible with
respect to the contents of yyscan_t; but that doesn't seem likely to
be a big problem in practice, considering how slowly flex changes.)

Aside from being more efficient than Horiguchi-san's original solution,
this avoids possible corner-case changes in semantics: the original code
was capable of popping the input buffer stack while still staying in
backslash-related parsing states.  I'm not sure that that equates to any
useful user-visible behaviors, but I'm not sure it doesn't either, so
I'm loath to assume that we only need to consider the topmost buffer when
parsing a backslash command.

I've attempted to update the MSVC build scripts for the added .l file,
but will rely on the buildfarm to see if I missed anything.

Kyotaro Horiguchi and Tom Lane

8 years agoConvert psql's flex lexer to be re-entrant, and make it compile standalone.
Tom Lane [Sat, 19 Mar 2016 01:21:52 +0000 (21:21 -0400)]
Convert psql's flex lexer to be re-entrant, and make it compile standalone.

Change psqlscan.l to specify '%option reentrant', adjust internal APIs
to match, and get rid of its internal static variables.  While this is
good cleanup in an abstract sense, the reason to do it right now is that
it seems the only practical way to support use of separate flex lexers
with common PsqlScanState infrastructure.  If we build two non-reentrant
lexers then we are going to have problems with dangling buffer pointers
in whichever lexer isn't active when we transition from one buffer to
another, as well as curious side-effects if we try to share any code
between the files.  (Horiguchi-san had a different solution to that in his
pending patch, but I find it ugly and probably broken for corner cases.)

Depending on which version of flex you're using, this may result in getting
a "warning: unused variable 'yyg'" warning from psqlscan, similar to the
one you'd have seen for a long time in backend/parser/scan.l.  I put a
local -Wno-error into CFLAGS for the file, for the convenience of those
who compile with -Werror.

Also, stop compiling psqlscan as part of mainloop.c, and make it a
standalone build target instead.  This is a lot cleaner than before, though
it doesn't really change much in practice as of this commit.  (I'm not sure
whether the MSVC build scripts will need some help with this part, but the
buildfarm will soon tell us.)

8 years agoMerge wal_level "archive" and "hot_standby" into new name "replica"
Peter Eisentraut [Tue, 1 Mar 2016 01:01:54 +0000 (20:01 -0500)]
Merge wal_level "archive" and "hot_standby" into new name "replica"

The distinction between "archive" and "hot_standby" existed only because
at the time "hot_standby" was added, there was some uncertainty about
stability.  This is now a long time ago.  We would like to move forward
with simplifying the replication configuration, but this distinction is
in the way, because a primary server cannot tell (without asking a
standby or predicting the future) which one of these would be the
appropriate level.

Pick a new name for the combined setting to make it clearer that it
covers all (non-logical) backup and replication uses.  The old values
are still accepted but are converted internally.

Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
Reviewed-by: David Steele <david@pgmasters.net>
8 years agoDecouple psqlscan.l from surrounding program.
Tom Lane [Fri, 18 Mar 2016 19:05:49 +0000 (15:05 -0400)]
Decouple psqlscan.l from surrounding program.

Remove assorted external references from psqlscan.l in preparation for
making it usable by other frontend programs.  This mostly involves
getting rid of direct calls to psql_error() and GetVariable() in favor
of introducing a callback-functions struct to encapsulate variable
fetching and error printing.  In addition, pass the current encoding
and standard-strings status as additional parameters to psql_scan_setup
instead of looking directly at "pset" or calling additional functions.

I did not bother to change some references to psql_error that are in
functions that will soon migrate to a psql-specific backslash-command
lexer.  Other than that, this version of psqlscan.l is capable of
compiling standalone.  It still depends on assorted src/common functions
as well as some encoding-related libpq functions, but we expect that
all programs using it will be happy with those dependencies.

Kyotaro Horiguchi, somewhat editorialized on by me

8 years agoUse INT64_FORMAT instead of %ld for int64.
Robert Haas [Fri, 18 Mar 2016 18:53:06 +0000 (14:53 -0400)]
Use INT64_FORMAT instead of %ld for int64.

Commit 0011c0091e886b874e485a46ff2c94222ffbf550 introduced this
mistake.

Patch by me.  Reported by Andres Freund, who also reviewed the
patch.

8 years agoOnly clear latch self-pipe/event if there is a pending notification.
Andres Freund [Fri, 18 Mar 2016 18:43:59 +0000 (11:43 -0700)]
Only clear latch self-pipe/event if there is a pending notification.

This avoids a good number of, individually quite fast, system calls in
scenarios with many quick queries. Besides the aesthetic benefit of
seing fewer superflous system calls with strace, it also improves
performance by ~2% measured by pgbench -M prepared -c 96 -j 8 -S (scale
100).

Without having benchmarked it, this patch also adjust the windows code,
as that makes it easier to unify the unix/windows codepaths in a later
patch. There's little reason to diverge in behaviour between the
platforms.

Discussion: CA+TgmoYc1Zm+Szoc_Qbzi92z2c1vRHZmjhfPn5uC=w8bXv6Avg@mail.gmail.com
Reviewed-By: Robert Haas
8 years agoMake it easier to choose the used waiting primitive in unix_latch.c.
Andres Freund [Fri, 18 Mar 2016 18:43:59 +0000 (11:43 -0700)]
Make it easier to choose the used waiting primitive in unix_latch.c.

This allows for easier testing of the different primitives; in
preparation for adding a new primitive.

Discussion: 20160114143931.GG10941@awork2.anarazel.de
Reviewed-By: Robert Haas
8 years agoError out if waiting on socket readiness without a specified socket.
Andres Freund [Fri, 18 Mar 2016 18:43:59 +0000 (11:43 -0700)]
Error out if waiting on socket readiness without a specified socket.

Previously we just ignored such an attempt, but that seems to serve no
purpose but making things harder to debug.

Discussion: 20160114143931.GG10941@awork2.anarazel.de
    20151230173734.hx7jj2fnwyljfqek@alap3.anarazel.de
Reviewed-By: Robert Haas
8 years agoRemove unused, and dangerous, TestLatch() macro.
Andres Freund [Fri, 18 Mar 2016 18:43:59 +0000 (11:43 -0700)]
Remove unused, and dangerous, TestLatch() macro.

The macro has not seen any in-tree use since latches had been introduced
in 2746e5f, in 2010.

8 years agoDirectly modify foreign tables.
Robert Haas [Fri, 18 Mar 2016 17:48:58 +0000 (13:48 -0400)]
Directly modify foreign tables.

postgres_fdw can now sent an UPDATE or DELETE statement directly to
the foreign server in simple cases, rather than sending a SELECT FOR
UPDATE statement and then updating or deleting rows one-by-one.

Etsuro Fujita, reviewed by Rushabh Lathia, Shigeru Hanada, Kyotaro
Horiguchi, Albe Laurenz, Thom Brown, and me.

8 years agoClean up some misplaced #includes.
Tom Lane [Fri, 18 Mar 2016 17:43:13 +0000 (13:43 -0400)]
Clean up some misplaced #includes.

Random .h files have no business including postgres-fe.h (or postgres.h).
If that wasn't the first #include done by the calling .c file, it's the
.c file that's broken.  Noted while prepping Kyotaro Horiguchi's psql
lexer refactoring patch.

8 years agoFix a typo
Teodor Sigaev [Fri, 18 Mar 2016 15:49:24 +0000 (18:49 +0300)]
Fix a typo

Erik Rijkers

8 years agoIntroduce parse_ident()
Teodor Sigaev [Fri, 18 Mar 2016 15:16:14 +0000 (18:16 +0300)]
Introduce parse_ident()

SQL-layer function to split qualified identifier into array parts.

Author: Pavel Stehule with minor editorization by me and Jim Nasby

8 years agoPush scan/join target list beneath Gather when possible.
Robert Haas [Fri, 18 Mar 2016 13:46:40 +0000 (09:46 -0400)]
Push scan/join target list beneath Gather when possible.

This means that, for example, "SELECT expensive_func(a) FROM bigtab
WHERE something" can compute expensive_func(a) in the workers rather
than the leader if it happens to be parallel-safe, which figures to be
a big win in some practical cases.

Currently, we can only do this if the entire target list is
parallel-safe.  If we worked harder, we might be able to evaluate
parallel-safe targets in the worker and any parallel-restricted
targets in the leader, but that would be more complicated, and there
aren't that many parallel-restricted functions that people are likely
to use in queries anyway.  I think.  So just do the simple thing for
the moment.

Robert Haas, Amit Kapila, and Tom Lane

8 years agoVarious minor corrections of and improvements to comments.
Robert Haas [Fri, 18 Mar 2016 13:38:59 +0000 (09:38 -0400)]
Various minor corrections of and improvements to comments.

Aleksander Alekseev

8 years agopg_trgm's set_limit() now uses SetConfigOption()
Teodor Sigaev [Fri, 18 Mar 2016 09:26:27 +0000 (12:26 +0300)]
pg_trgm's set_limit() now uses SetConfigOption()

Deprecated set_limit() is modified to use SetConfigOption() to set
similarity_threshold which is actually an instance of
pg_trgm.similarity_threshold GUC variable. Previous coding directly sets
similarity_threshold what could cause an inconsistency between states of
actual variable and GUC representation.

Per gripe from Tom Lane

8 years agodocs: Fix typo'd brin_summarize_new_values
Alvaro Herrera [Thu, 17 Mar 2016 23:17:04 +0000 (20:17 -0300)]
docs: Fix typo'd brin_summarize_new_values

I wrote "brin_summarize_new_pages" instead, in docs as well as in the
commit message of commit ac443d1034d9.

Bug: #14030
Reported-By: Chris Pacejo
8 years agoRemove useless double calls of make_parsestate().
Tom Lane [Thu, 17 Mar 2016 20:46:23 +0000 (16:46 -0400)]
Remove useless double calls of make_parsestate().

Aleksander Alekseev

8 years agoUpdate tuplesort.c comments for memory mangement improvements.
Robert Haas [Thu, 17 Mar 2016 20:11:14 +0000 (16:11 -0400)]
Update tuplesort.c comments for memory mangement improvements.

I'm committing these changes separately so that it's clear what is
Peter's original work versus what I changed.  This is a followup to
commit 0011c0091e886b874e485a46ff2c94222ffbf550, and these changes
are all by me.

8 years agoImprove memory management for external sorts.
Robert Haas [Thu, 17 Mar 2016 20:05:05 +0000 (16:05 -0400)]
Improve memory management for external sorts.

Introduce a new memory context which stores tuple data, and reset it
at the end of each merge pass; this helps avoid memory fragmentation
and, consequently, overallocation.  Also, for the final merge patch,
eliminate memory context chunk header overhead entirely by allocating
all of the memory used for buffering tuples during the merge in a
single chunk.  Since this modestly increases the number of tuples we
can store, grow the memtuples array a bit so that we're less likely to
run short of slots there.

Peter Geoghegan.  Review and testing of patches in this series by
Jeff Janes, Greg Stark, Mithun Cy, and me.

8 years agoFix assorted breakage in to_char()'s OF format option.
Tom Lane [Thu, 17 Mar 2016 19:50:33 +0000 (15:50 -0400)]
Fix assorted breakage in to_char()'s OF format option.

In HEAD, fix incorrect field width for hours part of OF when tm_gmtoff is
negative.  This was introduced by commit 2d87eedc1d4468d3 as a result of
falsely applying a pattern that's correct when + signs are omitted, which
is not the case for OF.

In 9.4, fix missing abs() call that allowed a sign to be attached to the
minutes part of OF.  This was fixed in 9.5 by 9b43d73b3f9bef27, but for
inscrutable reasons not back-patched.

In all three versions, ensure that the sign of tm_gmtoff is correctly
reported even when the GMT offset is less than 1 hour.

Add regression tests, which evidently we desperately need here.

Thomas Munro and Tom Lane, per report from David Fetter

8 years agoImprove support of Hunspell
Teodor Sigaev [Thu, 17 Mar 2016 14:23:38 +0000 (17:23 +0300)]
Improve support of Hunspell

- allow to use non-ascii characters as affix flag. Non-numeric affix flags now
  are stored as string instead of numeric value of character.
- allow to use 0 as affix flag in numeric encoded affixes

That adds support for arabian, hungarian, turkish and
brazilian portuguese languages.

Author: Artur Zakirov with heavy editorization by me

8 years agoFix typos.
Robert Haas [Thu, 17 Mar 2016 11:26:20 +0000 (07:26 -0400)]
Fix typos.

Jim Nasby

8 years agoAdd syslog_split_messages parameter
Peter Eisentraut [Wed, 16 Mar 2016 02:48:53 +0000 (22:48 -0400)]
Add syslog_split_messages parameter

Reviewed-by: Andreas Karlsson <andreas@proxel.se>
8 years agoAdd syslog_sequence_numbers parameter
Peter Eisentraut [Sat, 27 Feb 2016 03:34:30 +0000 (22:34 -0500)]
Add syslog_sequence_numbers parameter

Reviewed-by: Andreas Karlsson <andreas@proxel.se>
8 years agoFix "pg_bench -C -M prepared".
Tom Lane [Thu, 17 Mar 2016 03:18:07 +0000 (23:18 -0400)]
Fix "pg_bench -C -M prepared".

This didn't work because when we dropped and re-established a database
connection, we did not bother to reset session-specific state such as
the statements-are-prepared flags.

The st->prepared[] array certainly needs to be flushed, and I cleared a
couple of other fields as well that couldn't possibly retain meaningful
state for a new connection.

In passing, fix some bogus comments and strange field order choices.

Per report from Robins Tharakan.

8 years agoFix j2day() to behave sanely for negative Julian dates.
Tom Lane [Thu, 17 Mar 2016 00:57:45 +0000 (20:57 -0400)]
Fix j2day() to behave sanely for negative Julian dates.

Somebody had apparently once figured that casting to unsigned int would
produce the right output for negative inputs, but that would only be
true if 2^32 were a multiple of 7, which of course it ain't.  We need
to use a signed division and then correct the sign of the remainder.

AFAICT, the only case where this would arise currently is when doing
ISO-week calculations for dates in 4714BC, where we'd compute a
negative Julian date representing 4714-01-04BC and then do some
arithmetic with it.  Since we don't even really document support for
such dates, this is not of much consequence.  But we may as well
get it right.

Per report from Vitaly Burovoy.

8 years agoBe more careful about out-of-range dates and timestamps.
Tom Lane [Wed, 16 Mar 2016 23:09:04 +0000 (19:09 -0400)]
Be more careful about out-of-range dates and timestamps.

Tighten the semantics of boundary-case timestamptz so that we allow
timestamps >= '4714-11-24 00:00+00 BC' and < 'ENDYEAR-01-01 00:00+00 AD'
exactly, no more and no less, but it is allowed to enter timestamps
within that range using non-GMT timezone offsets (which could make the
nominal date 4714-11-23 BC or ENDYEAR-01-01 AD).  This eliminates
dump/reload failure conditions for timestamps near the endpoints.
To do this, separate checking of the inputs for date2j() from the
final range check, and allow the Julian date code to handle a range
slightly wider than the nominal range of the datatypes.

Also add a bunch of checks to detect out-of-range dates and timestamps
that formerly could be returned by operations such as date-plus-integer.
All C-level functions that return date, timestamp, or timestamptz should
now be proof against returning a value that doesn't pass IS_VALID_DATE()
or IS_VALID_TIMESTAMP().

Vitaly Burovoy, reviewed by Anastasia Lubennikova, and substantially
whacked around by me

8 years agoAnother comment update.
Robert Haas [Wed, 16 Mar 2016 18:28:25 +0000 (14:28 -0400)]
Another comment update.

I thought this was in my last commit, but I goofed.

8 years agoFix problems in commit c16dc1aca5e01e6acaadfcf38f5fc964a381dc62.
Robert Haas [Wed, 16 Mar 2016 17:54:04 +0000 (13:54 -0400)]
Fix problems in commit c16dc1aca5e01e6acaadfcf38f5fc964a381dc62.

Vinayak Pokale provided a patch for a copy-and-paste error in a
comment.  I noticed that I'd use the word "automatically" nearby where
I meant to talk about things being "atomic".  Rahila Syed spotted a
misplaced counter update.  Fix all that stuff.

8 years agoAdd files forgotten in f576b17cd6ba653bdace1f0da9a3b57f4984e460
Teodor Sigaev [Wed, 16 Mar 2016 16:23:41 +0000 (19:23 +0300)]
Add files forgotten in f576b17cd6ba653bdace1f0da9a3b57f4984e460

8 years agoAdd word_similarity to pg_trgm contrib module.
Teodor Sigaev [Wed, 16 Mar 2016 15:59:21 +0000 (18:59 +0300)]
Add word_similarity to pg_trgm contrib module.

Patch introduces a concept of similarity over string and just a word from
another string.

Version of extension is not changed because 1.2 was already introduced in 9.6
release cycle, so, there wasn't a public version.

Author: Alexander Korotkov, Artur Zakirov

8 years agoFix typo.
Robert Haas [Wed, 16 Mar 2016 15:38:30 +0000 (11:38 -0400)]
Fix typo.

Amit Langote

8 years agoAdd idle_in_transaction_session_timeout.
Robert Haas [Wed, 16 Mar 2016 15:30:45 +0000 (11:30 -0400)]
Add idle_in_transaction_session_timeout.

Vik Fearing, reviewed by Stéphane Schildknecht and me, and revised
slightly by me.

8 years agoGUC variable pg_trgm.similarity_threshold insead of set_limit()
Teodor Sigaev [Wed, 16 Mar 2016 14:44:58 +0000 (17:44 +0300)]
GUC variable pg_trgm.similarity_threshold insead of set_limit()

Use GUC variable pg_trgm.similarity_threshold insead of
set_limit()/show_limit() which was introduced when defining GUC varuables
by modules was absent.

Author: Artur Zakirov

8 years agoUCS_to_EUC_JIS_2004.pl: Turn off "test" mode by default
Peter Eisentraut [Tue, 1 Mar 2016 01:08:16 +0000 (20:08 -0500)]
UCS_to_EUC_JIS_2004.pl: Turn off "test" mode by default

It produces debugging output files that are of no further use, so we
don't need that by default.

8 years agoMake spacing and punctuation consistent
Peter Eisentraut [Tue, 1 Mar 2016 01:08:16 +0000 (20:08 -0500)]
Make spacing and punctuation consistent

8 years agofix typo in comment
Teodor Sigaev [Wed, 16 Mar 2016 14:18:14 +0000 (17:18 +0300)]
fix typo in comment

8 years agoImprove script generating unaccent rules
Teodor Sigaev [Wed, 16 Mar 2016 13:47:03 +0000 (16:47 +0300)]
Improve script generating unaccent rules

Script now use the standard Unicode transliterator Latin-ASCII.

Author: Leonard Benedetti

8 years agoFix typos.
Robert Haas [Tue, 15 Mar 2016 22:06:11 +0000 (18:06 -0400)]
Fix typos.

Oskari Saarenmaa

8 years agoAvoid incorrectly indicating exclusion constraint wait
Stephen Frost [Tue, 15 Mar 2016 22:04:39 +0000 (18:04 -0400)]
Avoid incorrectly indicating exclusion constraint wait

INSERT ... ON CONFLICT's precheck may have to wait on the outcome of
another insertion, which may or may not itself be a speculative
insertion.  This wait is not necessarily associated with an exclusion
constraint, but was always reported that way in log messages if the wait
happened to involve a tuple that had no speculative token.

Initially discovered through use of ON CONFLICT DO NOTHING, where
spurious references to exclusion constraints in log messages were more
likely.

Patch by Peter Geoghegan.
Reviewed by Julien Rouhaud.

Back-patch to 9.5 where INSERT ... ON CONFLICT was added.

8 years agoFix typos in comments
Alvaro Herrera [Tue, 15 Mar 2016 20:57:17 +0000 (17:57 -0300)]
Fix typos in comments

8 years agopostgres_fdw: make_tuple_from_result_row should set cur_attno for ctid.
Robert Haas [Tue, 15 Mar 2016 20:51:56 +0000 (16:51 -0400)]
postgres_fdw: make_tuple_from_result_row should set cur_attno for ctid.

There's no reason for this function to do this for every other
attribute number and omit it for CTID, especially since
conversion_error_callback has code to handle that case.  This seems
to be an oversight in commit e690b9515072fd7767fdeca5c54166f6a77733bc.

Etsuro Fujita

8 years agoFix typos.
Robert Haas [Tue, 15 Mar 2016 20:28:17 +0000 (16:28 -0400)]
Fix typos.

Thomas Reiss

8 years agoAdd simple VACUUM progress reporting.
Robert Haas [Tue, 15 Mar 2016 17:31:18 +0000 (13:31 -0400)]
Add simple VACUUM progress reporting.

There's a lot more that could be done here yet - in particular, this
reports only very coarse-grained information about the index vacuuming
phase - but even as it stands, the new pg_stat_progress_vacuum can
tell you quite a bit about what a long-running vacuum is actually
doing.

Amit Langote and Robert Haas, based on earlier work by Vinayak Pokale
and Rahila Syed.

8 years agoCope if platform declares mbstowcs_l(), but not locale_t, in <xlocale.h>.
Tom Lane [Tue, 15 Mar 2016 17:19:57 +0000 (13:19 -0400)]
Cope if platform declares mbstowcs_l(), but not locale_t, in <xlocale.h>.

Previously, we included <xlocale.h> only if necessary to get the definition
of type locale_t.  According to notes in PGAC_TYPE_LOCALE_T, this is
important because on some versions of glibc that file supplies an
incompatible declaration of locale_t.  (This info may be obsolete, because
on my RHEL6 box that seems to be the *only* definition of locale_t; but
there may still be glibc's in the wild for which it's a live concern.)

It turns out though that on FreeBSD and maybe other BSDen, you can get
locale_t from stdlib.h or locale.h but mbstowcs_l() and friends only from
<xlocale.h>.  This was leaving us compiling calls to mbstowcs_l() and
friends with no visible prototype, which causes a warning and could
possibly cause actual trouble, since it's not declared to return int.

Hence, adjust the configure checks so that we'll include <xlocale.h>
either if it's necessary to get type locale_t or if it's necessary to
get a declaration of mbstowcs_l().

Report and patch by Aleksander Alekseev, somewhat whacked around by me.
Back-patch to all supported branches, since we have been using
mbstowcs_l() since 9.1.

8 years agoAdd a GetForeignUpperPaths callback function for FDWs.
Tom Lane [Tue, 15 Mar 2016 00:04:44 +0000 (20:04 -0400)]
Add a GetForeignUpperPaths callback function for FDWs.

This is basically like the just-added create_upper_paths_hook, but
control is funneled only to the FDW responsible for all the baserels
of the current query; so providing such a callback is much less likely
to add useless overhead than using the hook function is.

The documentation is a bit sketchy.  We'll likely want to improve it,
and/or adjust the call conventions, when we get some experience with
actually using this callback.  Hopefully somebody will find time to
experiment with it before 9.6 feature freeze.

8 years agoAdd missing include for self-containment
Peter Eisentraut [Mon, 14 Mar 2016 23:56:33 +0000 (19:56 -0400)]
Add missing include for self-containment

8 years agoFix EXPLAIN ANALYZE SELECT INTO not to choose a parallel plan.
Robert Haas [Mon, 14 Mar 2016 23:48:46 +0000 (19:48 -0400)]
Fix EXPLAIN ANALYZE SELECT INTO not to choose a parallel plan.

We don't support any parallel write operations at present, so choosing
a parallel plan causes us to error out.  Also, add a new regression
test that uses EXPLAIN ANALYZE SELECT INTO; if we'd had this previously,
force_parallel_mode testing would have caught this issue.

Mithun Cy and Robert Haas

8 years agoProvide a planner hook at a suitable place for creating upper-rel Paths.
Tom Lane [Mon, 14 Mar 2016 23:23:29 +0000 (19:23 -0400)]
Provide a planner hook at a suitable place for creating upper-rel Paths.

In the initial revision of the upper-planner pathification work, the only
available way for an FDW or custom-scan provider to inject Paths
representing post-scan-join processing was to insert them during scan-level
GetForeignPaths or similar processing.  While that's not impossible, it'd
require quite a lot of duplicative processing to look forward and see if
the extension would be capable of implementing the whole query.  To improve
matters for custom-scan providers, provide a hook function at the point
where the core code is about to start filling in upperrel Paths.  At this
point Paths are available for the whole scan/join tree, which should reduce
the amount of redundant effort considerably.

(An alternative design that was suggested was to provide a separate hook
for each post-scan-join processing step, but that seems messy and not
clearly more useful.)

Following our time-honored tradition, there's no documentation for this
hook outside the source code.

As-is, this hook is only meant for custom scan providers, which we can't
assume very much about.  A followon patch will implement an FDW callback
to let FDWs do the same thing in a somewhat more structured fashion.

8 years agoAllow callers of create_foreignscan_path to specify nondefault PathTarget.
Tom Lane [Mon, 14 Mar 2016 21:31:28 +0000 (17:31 -0400)]
Allow callers of create_foreignscan_path to specify nondefault PathTarget.

Although the default choice of rel->reltarget should typically be
sufficient for scan or join paths, it's not at all sufficient for the
purposes PathTargets were invented for; in particular not for
upper-relation Paths.  So break API compatibility by adding a PathTarget
argument to create_foreignscan_path().  To ease updating of existing
code, accept a NULL value of the argument as selecting rel->reltarget.

8 years agoRethink representation of PathTargets.
Tom Lane [Mon, 14 Mar 2016 20:59:59 +0000 (16:59 -0400)]
Rethink representation of PathTargets.

In commit 19a541143a09c067 I did not make PathTarget a subtype of Node,
and embedded a RelOptInfo's reltarget directly into it rather than having
a separately-allocated Node.  In hindsight that was misguided
micro-optimization, enabled by the fact that at that point we didn't have
any Paths with custom PathTargets.  Now that PathTarget processing has
been fleshed out some more, it's easier to see that it's better to have
PathTarget as an indepedent Node type, even if it does cost us one more
palloc to create a RelOptInfo.  So change it while we still can.

This commit just changes the representation, without doing anything more
interesting than that.

8 years agoUpdate PL/Perl's comment about hv_store().
Tom Lane [Mon, 14 Mar 2016 18:45:45 +0000 (14:45 -0400)]
Update PL/Perl's comment about hv_store().

Negative klen is documented since Perl 5.16, and 5.6 is no longer
supported so no need to comment about it.

Dagfinn Ilmari Mannsåker

8 years agoImprove conversions from uint64 to Perl types.
Tom Lane [Mon, 14 Mar 2016 18:38:36 +0000 (14:38 -0400)]
Improve conversions from uint64 to Perl types.

Perl's integers are pointer-sized, so can hold more than INT_MAX on LP64
platforms, and come in both signed (IV) and unsigned (UV).  Floating
point values (NV) may also be larger than double.

Since Perl 5.19.4 array indices are SSize_t instead of I32, so allow up
to SSize_t_max on those versions.  The limit is not imposed just by
av_extend's argument type, but all the array handling code, so remove
the speculative comment.

Dagfinn Ilmari Mannsåker

8 years agoUpdate more comments for 96198d94cb7adc664bda341842dc8db671d8be72.
Robert Haas [Mon, 14 Mar 2016 18:27:11 +0000 (14:27 -0400)]
Update more comments for 96198d94cb7adc664bda341842dc8db671d8be72.

Etsuro Fujita, reviewed (though not completely endorsed) by Ashutosh
Bapat, and slightly expanded by me.

8 years agoUse repalloc_huge() to enlarge a SPITupleTable's tuple pointer array.
Tom Lane [Mon, 14 Mar 2016 18:22:16 +0000 (14:22 -0400)]
Use repalloc_huge() to enlarge a SPITupleTable's tuple pointer array.

Commit 23a27b039d94ba35 widened the rows-stored counters to uint64, but
that's academic unless we allow the tuple pointer array to exceed 1GB.

(It might be a good idea to provide some other limit on how much storage
a SPITupleTable can eat.  On the other hand, there are plenty of other
ways to drive a backend into swap hell.)

Dagfinn Ilmari Mannsåker

8 years agoImprove check for overly-long extensible node name.
Robert Haas [Mon, 14 Mar 2016 17:48:35 +0000 (13:48 -0400)]
Improve check for overly-long extensible node name.

The old code is bad for two reasons.  First, it has an off-by-one
error.  Second, it won't help if you aren't running with assertions
enabled.  Per discussion, we want a check here in that case too.

Author: KaiGai Kohei, adjusted by me.
Reviewed-by: Petr Jelinek
Discussion: 56E0D547.1030101@2ndquadrant.com

8 years agopg_stat_get_progress_info() should be marked STRICT.
Tom Lane [Mon, 14 Mar 2016 16:51:55 +0000 (12:51 -0400)]
pg_stat_get_progress_info() should be marked STRICT.

I didn't bother with a catversion bump.

Report and patch by Thomas Munro

8 years agoTeach the configure script to validate its --with-pgport argument.
Tom Lane [Mon, 14 Mar 2016 14:41:29 +0000 (10:41 -0400)]
Teach the configure script to validate its --with-pgport argument.

Previously, configure would take any string, including an empty string,
leading to obscure compile failures in guc.c.  It seems worth expending
a few lines of code to ensure that the argument is a decimal number
between 1 and 65535.

Report and patch by Jim Nasby; reviews by Alex Shulgin, Peter Eisentraut,
Ivan Kartyshov

8 years agoMop-up for setting minimum Tcl version to 8.4.
Tom Lane [Sun, 13 Mar 2016 21:14:49 +0000 (17:14 -0400)]
Mop-up for setting minimum Tcl version to 8.4.

Commit e2609323e set the minimum Tcl version we support to 8.4, but
I forgot to adjust the documentation to say the same.  Some nosing
around for other consequences found that the configure script could
be simplified slightly as well.

8 years agoFix memory leak in repeated GIN index searches.
Tom Lane [Sun, 13 Mar 2016 20:44:10 +0000 (16:44 -0400)]
Fix memory leak in repeated GIN index searches.

Commit d88976cfa1302e8d removed this code from ginFreeScanKeys():
- if (entry->list)
- pfree(entry->list);
evidently in the belief that that ItemPointer array is allocated in the
keyCtx and so would be reclaimed by the following MemoryContextReset.
Unfortunately, it isn't and it won't.  It'd likely be a good idea for
that to become so, but as a simple and back-patchable fix in the
meantime, restore this code to ginFreeScanKeys().

Also, add a similar pfree to where startScanEntry() is about to zero out
entry->list.  I am not sure if there are any code paths where this
change prevents a leak today, but it seems like cheap future-proofing.

In passing, make the initial allocation of so->entries[] use palloc
not palloc0.  The code doesn't depend on unused entries being zero;
if it did, the array-enlargement code in ginFillScanEntry() would be
wrong.  So using palloc0 initially can only serve to confuse readers
about what the invariant is.

Per report from Felipe de Jesús Molina Bravo, via Jaime Casanova in
<CAJGNTeMR1ndMU2Thpr8GPDUfiHTV7idELJRFusA5UXUGY1y-eA@mail.gmail.com>

8 years agoFix whitespace and remove obsolete gitattributes entry
Peter Eisentraut [Sun, 13 Mar 2016 20:03:13 +0000 (16:03 -0400)]
Fix whitespace and remove obsolete gitattributes entry

8 years agoRename auto_explain.sample_ratio to sample_rate
Magnus Hagander [Sun, 13 Mar 2016 12:18:03 +0000 (13:18 +0100)]
Rename auto_explain.sample_ratio to sample_rate

Per suggestion from Tomas Vondra

Author: Julien Rouhaud

8 years agoFix order of MemSet arguments
Magnus Hagander [Sun, 13 Mar 2016 12:11:06 +0000 (13:11 +0100)]
Fix order of MemSet arguments

Noted by Tomas Vondra

8 years agoReport memory context stats upon out-of-memory in repalloc[_huge].
Tom Lane [Sun, 13 Mar 2016 05:21:07 +0000 (00:21 -0500)]
Report memory context stats upon out-of-memory in repalloc[_huge].

This longstanding functionality evidently got lost in commit
3d6d1b585524aab6.  Noted while studying an OOM report from Jaime
Casanova.  Backpatch to 9.5 where the bug was introduced.

8 years agoFix Windows portability issue in 23a27b039d94ba35.
Tom Lane [Sun, 13 Mar 2016 03:34:47 +0000 (22:34 -0500)]
Fix Windows portability issue in 23a27b039d94ba35.

_strtoui64() is available in MSVC builds, but apparently not with
other Windows toolchains.  Thanks to Petr Jelinek for the diagnosis.

8 years agoGet rid of scribbling on a const variable in psql's print.c.
Tom Lane [Sat, 12 Mar 2016 23:16:24 +0000 (18:16 -0500)]
Get rid of scribbling on a const variable in psql's print.c.

Commit a2dabf0e1dda93c8 had the bright idea that it could modify a "const"
global variable if it merely casted away const from a pointer.  This does
not work on platforms where the compiler puts "const" variables into
read-only storage.  Depressingly, we evidently have no such platforms in
our buildfarm ... an oversight I have now remedied.  (The one platform
that is known to catch this is recent OS X with -fno-common.)

Per report from Chris Ruprecht.  Back-patch to 9.5 where the bogus
code was introduced.

8 years agoWiden query numbers-of-tuples-processed counters to uint64.
Tom Lane [Sat, 12 Mar 2016 21:05:10 +0000 (16:05 -0500)]
Widen query numbers-of-tuples-processed counters to uint64.

This patch widens SPI_processed, EState's es_processed field, PortalData's
portalPos field, FuncCallContext's call_cntr and max_calls fields,
ExecutorRun's count argument, PortalRunFetch's result, and the max number
of rows in a SPITupleTable to uint64, and deals with (I hope) all the
ensuing fallout.  Some of these values were declared uint32 before, and
others "long".

I also removed PortalData's posOverflow field, since that logic seems
pretty useless given that portalPos is now always 64 bits.

The user-visible results are that command tags for SELECT etc will
correctly report tuple counts larger than 4G, as will plpgsql's GET
GET DIAGNOSTICS ... ROW_COUNT command.  Queries processing more tuples
than that are still not exactly the norm, but they're becoming more
common.

Most values associated with FETCH/MOVE distances, such as PortalRun's count
argument and the count argument of most SPI functions that have one, remain
declared as "long".  It's not clear whether it would be worth promoting
those to int64; but it would definitely be a large dollop of additional
API churn on top of this, and it would only help 32-bit platforms which
seem relatively less likely to see any benefit.

Andreas Scherbaum, reviewed by Christian Ullrich, additional hacking by me

8 years agoInclude portability/mem.h into fd.c for MAP_FAILED.
Andres Freund [Sat, 12 Mar 2016 20:16:48 +0000 (12:16 -0800)]
Include portability/mem.h into fd.c for MAP_FAILED.

Buildfarm members gaur and pademelon are old enough not to know about
MAP_FAILED; which is used in 428b1d6. Include portability/mem.h to fix;
as already done in a bunch of other places.

8 years agoRe-export a few of createplan.c's make_xxx() functions.
Tom Lane [Sat, 12 Mar 2016 17:12:59 +0000 (12:12 -0500)]
Re-export a few of createplan.c's make_xxx() functions.

CitusDB is using these and don't wish to redesign their code right now.
I am not on board with this being a good idea, or a good precedent,
but I lack the energy to fight about it.

8 years agopg_upgrade: Convert old visibility map format to new format.
Robert Haas [Fri, 11 Mar 2016 17:28:22 +0000 (12:28 -0500)]
pg_upgrade: Convert old visibility map format to new format.

Commit a892234f830e832110f63fc0a2afce2fb21d1584 added a second bit per
page to the visibility map, but pg_upgrade has been unaware of it up
until now.  Therefore, a pg_upgrade from an earlier major release of
PostgreSQL to any commit preceding this one and following the one
mentioned above would result in invalid visibility map contents on the
new cluster, very possibly leading to data corruption.  This plugs
that hole.

Masahiko Sawada, reviewed by Jeff Janes, Bruce Momjian, Simon Riggs,
Michael Paquier, Andres Freund, me, and others.

8 years agoWhen appropriate, postpone SELECT output expressions till after ORDER BY.
Tom Lane [Fri, 11 Mar 2016 17:27:41 +0000 (12:27 -0500)]
When appropriate, postpone SELECT output expressions till after ORDER BY.

It is frequently useful for volatile, set-returning, or expensive functions
in a SELECT's targetlist to be postponed till after ORDER BY and LIMIT are
done.  Otherwise, the functions might be executed for every row of the
table despite the presence of LIMIT, and/or be executed in an unexpected
order.  For example, in
SELECT x, nextval('seq') FROM tab ORDER BY x LIMIT 10;
it's probably desirable that the nextval() values are ordered the same
as x, and that nextval() is not run more than 10 times.

In the past, Postgres was inconsistent in this area: you would get the
desirable behavior if the ordering were performed via an indexscan, but
not if it had to be done by an explicit sort step.  Getting the desired
behavior reliably required contortions like
SELECT x, nextval('seq')
  FROM (SELECT x FROM tab ORDER BY x) ss LIMIT 10;

This patch conditionally postpones evaluation of pure-output target
expressions (that is, those that are not used as DISTINCT, ORDER BY, or
GROUP BY columns) so that they effectively occur after sorting, even if an
explicit sort step is necessary.  Volatile expressions and set-returning
expressions are always postponed, so as to provide consistent semantics.
Expensive expressions (costing more than 10 times typical operator cost,
which by default would include any user-defined function) are postponed
if there is a LIMIT or if there are expressions that must be postponed.

We could be more aggressive and postpone any nontrivial expression, but
there are costs associated with doing so: it requires an extra Result plan
node which adds some overhead, and postponement changes the volume of data
going through the sort step, perhaps for the worse.  Since we tend not to
have very good estimates of the output width of nontrivial expressions,
it's hard to have much confidence in our ability to predict whether
postponement would increase or decrease the cost of the sort; therefore
this patch doesn't attempt to make decisions conditionally on that.
Between these factors and a general desire not to change query behavior
when there's not a demonstrable benefit, it seems best to be conservative
about applying postponement.  We might tweak the decision rules in the
future, though.

Konstantin Knizhnik, heavily rewritten by me

8 years agoFix Windows build broken in 6943a946c7e5eb72d53c0ce71f08a81a133503bd
Teodor Sigaev [Fri, 11 Mar 2016 17:10:20 +0000 (20:10 +0300)]
Fix Windows build broken in 6943a946c7e5eb72d53c0ce71f08a81a133503bd

Also it fixes dynamic array allocation disallowed by ANSI-C.

Author: Stas Kelvich

8 years agoFix merge affixes for numeric ones
Teodor Sigaev [Fri, 11 Mar 2016 16:47:50 +0000 (19:47 +0300)]
Fix merge affixes for numeric ones

Some dictionaries have duplicated base words with different affix set, we
just merge that sets into one set. But previously merging of sets of affixes
was actually a concatenation of strings but it's wrong for numeric
representation of affixes because such representation uses comma to
separate affixes.

Author: Artur Zakirov

8 years agoBump catalog version missed in 6943a946c7e5eb72d53c0ce71f08a81a133503bd
Teodor Sigaev [Fri, 11 Mar 2016 16:31:04 +0000 (19:31 +0300)]
Bump catalog version missed in 6943a946c7e5eb72d53c0ce71f08a81a133503bd

8 years agoTsvector editing functions
Teodor Sigaev [Fri, 11 Mar 2016 16:22:36 +0000 (19:22 +0300)]
Tsvector editing functions

Adds several tsvector editting function: convert tsvector to/from text array,
set weight for given lexemes, delete lexeme(s), unnest, filter lexemes
with given weights

Author: Stas Kelvich with some editorization by me
Reviewers: Tomas Vondram, Teodor Sigaev

8 years agoMinor additional refactoring of planner.c's PathTarget handling.
Tom Lane [Fri, 11 Mar 2016 15:24:33 +0000 (10:24 -0500)]
Minor additional refactoring of planner.c's PathTarget handling.

Teach make_group_input_target() and make_window_input_target() to work
entirely with the PathTarget representation of tlists, rather than
constructing a tlist and immediately deconstructing it into PathTarget
format.  In itself this only saves a few palloc's; the bigger picture is
that it opens the door for sharing cost_qual_eval work across all of
planner.c's constructions of PathTargets.  I'll come back to that later.

In support of this, flesh out tlist.c's infrastructure for PathTargets
a bit more.

8 years agoAllow setting sample ratio for auto_explain
Magnus Hagander [Fri, 11 Mar 2016 14:08:34 +0000 (15:08 +0100)]
Allow setting sample ratio for auto_explain

New configuration parameter auto_explain.sample_ratio makes it
possible to log just a fraction of the queries meeting the configured
threshold, to reduce the amount of logging.

Author: Craig Ringer and Julien Rouhaud
Review: Petr Jelinek

8 years agopsql: Don't automatically use expanded format when there's 1 column.
Robert Haas [Fri, 11 Mar 2016 13:04:01 +0000 (08:04 -0500)]
psql: Don't automatically use expanded format when there's 1 column.

Andreas Karlsson and Robert Haas

8 years agoFix a typo, and remove unnecessary pgstat_report_wait_end().
Robert Haas [Fri, 11 Mar 2016 12:32:59 +0000 (07:32 -0500)]
Fix a typo, and remove unnecessary pgstat_report_wait_end().

Per Amit Kapila.

8 years agoRefactor receivelog.c parameters
Magnus Hagander [Fri, 11 Mar 2016 10:08:01 +0000 (11:08 +0100)]
Refactor receivelog.c parameters

Much cruft had accumulated over time with a large number of parameters
passed down between functions very deep. With this refactoring, instead
introduce a StreamCtl structure that holds the parameters, and pass around
a pointer to this structure instead. This makes it much easier to add or
remove fields that are needed deeper down in the implementation without
having to modify every function header in the file.

Patch by me after much nagging from Andres
Reviewed by Craig Ringer and Daniel Gustafsson

8 years agoAllow emit_log_hook to see original message text
Simon Riggs [Fri, 11 Mar 2016 09:53:06 +0000 (09:53 +0000)]
Allow emit_log_hook to see original message text

emit_log_hook could only see the translated text, making it harder to identify
which message was being sent. Pass original text to allow the exact message to
be identified, whichever language is used for logging.

Discussion: 20160216.184755.59721141.horiguchi.kyotaro@lab.ntt.co.jp
Author: Kyotaro Horiguchi

8 years agoSimplify GetLockNameFromTagType.
Robert Haas [Fri, 11 Mar 2016 02:37:22 +0000 (21:37 -0500)]
Simplify GetLockNameFromTagType.

The old code is wrong, because it returns a pointer to an automatic
variable.  And it's also more clever than we really need to be
considering that the case it's worrying about should never happen.

8 years agoBlindly try to fix dtrace enabled builds, broken in 9cd00c45.
Andres Freund [Fri, 11 Mar 2016 01:49:43 +0000 (17:49 -0800)]
Blindly try to fix dtrace enabled builds, broken in 9cd00c45.

Reported-By: Peter Eisentraut
Discussion: 56E2239E.1050607@gmx.net

8 years agoCheckpoint sorting and balancing.
Andres Freund [Fri, 19 Feb 2016 20:17:51 +0000 (12:17 -0800)]
Checkpoint sorting and balancing.

Up to now checkpoints were written in the order they're in the
BufferDescriptors. That's nearly random in a lot of cases, which
performs badly on rotating media, but even on SSDs it causes slowdowns.

To avoid that, sort checkpoints before writing them out. We currently
sort by tablespace, relfilenode, fork and block number.

One of the major reasons that previously wasn't done, was fear of
imbalance between tablespaces. To address that balance writes between
tablespaces.

The other prime concern was that the relatively large allocation to sort
the buffers in might fail, preventing checkpoints from happening. Thus
pre-allocate the required memory in shared memory, at server startup.

This particularly makes it more efficient to have checkpoint flushing
enabled, because that'll often result in a lot of writes that can be
coalesced into one flush.

Discussion: alpine.DEB.2.10.1506011320000.28433@sto
Author: Fabien Coelho and Andres Freund

8 years agoAllow to trigger kernel writeback after a configurable number of writes.
Andres Freund [Fri, 19 Feb 2016 20:13:05 +0000 (12:13 -0800)]
Allow to trigger kernel writeback after a configurable number of writes.

Currently writes to the main data files of postgres all go through the
OS page cache. This means that some operating systems can end up
collecting a large number of dirty buffers in their respective page
caches.  When these dirty buffers are flushed to storage rapidly, be it
because of fsync(), timeouts, or dirty ratios, latency for other reads
and writes can increase massively.  This is the primary reason for
regular massive stalls observed in real world scenarios and artificial
benchmarks; on rotating disks stalls on the order of hundreds of seconds
have been observed.

On linux it is possible to control this by reducing the global dirty
limits significantly, reducing the above problem. But global
configuration is rather problematic because it'll affect other
applications; also PostgreSQL itself doesn't always generally want this
behavior, e.g. for temporary files it's undesirable.

Several operating systems allow some control over the kernel page
cache. Linux has sync_file_range(2), several posix systems have msync(2)
and posix_fadvise(2). sync_file_range(2) is preferable because it
requires no special setup, whereas msync() requires the to-be-flushed
range to be mmap'ed. For the purpose of flushing dirty data
posix_fadvise(2) is the worst alternative, as flushing dirty data is
just a side-effect of POSIX_FADV_DONTNEED, which also removes the pages
from the page cache.  Thus the feature is enabled by default only on
linux, but can be enabled on all systems that have any of the above
APIs.

While desirable and likely possible this patch does not contain an
implementation for windows.

With the infrastructure added, writes made via checkpointer, bgwriter
and normal user backends can be flushed after a configurable number of
writes. Each of these sources of writes controlled by a separate GUC,
checkpointer_flush_after, bgwriter_flush_after and backend_flush_after
respectively; they're separate because the number of flushes that are
good are separate, and because the performance considerations of
controlled flushing for each of these are different.

A later patch will add checkpoint sorting - after that flushes from the
ckeckpoint will almost always be desirable. Bgwriter flushes are most of
the time going to be random, which are slow on lots of storage hardware.
Flushing in backends works well if the storage and bgwriter can keep up,
but if not it can have negative consequences.  This patch is likely to
have negative performance consequences without checkpoint sorting, but
unfortunately so has sorting without flush control.

Discussion: alpine.DEB.2.10.1506011320000.28433@sto
Author: Fabien Coelho and Andres Freund

8 years agoGive pull_var_clause() reject/recurse/return behavior for WindowFuncs too.
Tom Lane [Thu, 10 Mar 2016 21:23:40 +0000 (16:23 -0500)]
Give pull_var_clause() reject/recurse/return behavior for WindowFuncs too.

All along, this function should have treated WindowFuncs in a manner
similar to Aggrefs, ie with an option whether or not to recurse into them.
By not considering the case, it was always recursing, which is OK for most
callers (although I suspect that the case in prepare_sort_from_pathkeys
might represent a bug).  But now we need return-without-recursing behavior
as well.  There are also more than a few callers that should never see a
WindowFunc, and now we'll get some error checking on that.

8 years agoDon't vacuum all-frozen pages.
Robert Haas [Thu, 10 Mar 2016 21:12:10 +0000 (16:12 -0500)]
Don't vacuum all-frozen pages.

Commit a892234f830e832110f63fc0a2afce2fb21d1584 gave us enough
infrastructure to avoid vacuuming pages where every tuple on the
page is already frozen.  So, replace the notion of a scan_all or
whole-table vacuum with the less onerous notion of an "aggressive"
vacuum, which will pages that are all-visible, but still skip those
that are all-frozen.

This should greatly reduce the cost of anti-wraparound vacuuming
on large clusters where the majority of data is never touched
between one cycle and the next, because we'll no longer have to
read all of those pages only to find out that we don't need to
do anything with them.

Patch by me, reviewed by Masahiko Sawada.

8 years agoRefactor pull_var_clause's API to make it less tedious to extend.
Tom Lane [Thu, 10 Mar 2016 20:52:58 +0000 (15:52 -0500)]
Refactor pull_var_clause's API to make it less tedious to extend.

In commit 1d97c19a0f748e94 and later c1d9579dd8bf3c92, we extended
pull_var_clause's API by adding enum-type arguments.  That's sort of a pain
to maintain, though, because it means every time we add a new behavior we
must touch every last one of the call sites, even if there's a reasonable
default behavior that most of them could use.  Let's switch over to using a
bitmask of flags, instead; that seems more maintainable and might save a
nanosecond or two as well.  This commit changes no behavior in itself,
though I'm going to follow it up with one that does add a new behavior.

In passing, remove flatten_tlist(), which has not been used since 9.1
and would otherwise need the same API changes.

Removing these enums means that optimizer/tlist.h no longer needs to
depend on optimizer/var.h.  Changing that caused a number of C files to
need addition of #include "optimizer/var.h" (probably we can thank old
runs of pgrminclude for that); but on balance it seems like a good change
anyway.

8 years agoRework wait for AccessExclusiveLocks on Hot Standby
Simon Riggs [Thu, 10 Mar 2016 19:26:24 +0000 (19:26 +0000)]
Rework wait for AccessExclusiveLocks on Hot Standby

Earlier version committed in 9.0 caused spurious waits in some cases.
New infrastructure for lock waits in 9.3 used to correct and improve this.

Jeff Janes based upon a proposal by Simon Riggs, who also reviewed
Additional review comments from Amit Kapila

8 years agoProvide much better wait information in pg_stat_activity.
Robert Haas [Thu, 10 Mar 2016 17:44:09 +0000 (12:44 -0500)]
Provide much better wait information in pg_stat_activity.

When a process is waiting for a heavyweight lock, we will now indicate
the type of heavyweight lock for which it is waiting.  Also, you can
now see when a process is waiting for a lightweight lock - in which
case we will indicate the individual lock name or the tranche, as
appropriate - or for a buffer pin.

Amit Kapila, Ildus Kurbangaliev, reviewed by me.  Lots of helpful
discussion and suggestions by many others, including Alexander
Korotkov, Vladimir Borodin, and many others.

8 years agoDocument BRIN a bit more thoroughly
Alvaro Herrera [Thu, 10 Mar 2016 16:15:08 +0000 (13:15 -0300)]
Document BRIN a bit more thoroughly

The chapter "Interfacing Extensions To Indexes" and CREATE OPERATOR
CLASS reference page were missed when BRIN was added.  We document
all our other index access methods there, so make sure BRIN complies.

Author: Álvaro Herrera
Reported-By: Julien Rouhaud, Tom Lane
Reviewed-By: Emre Hasegeli
Discussion: https://www.postgresql.org/message-id/56CF604E.9000303%40dalibo.com
Backpatch: 9.5, where BRIN was introduced

8 years agoAvoid crash on old Windows with AVX2-capable CPU for VS2013 builds
Magnus Hagander [Thu, 10 Mar 2016 12:48:58 +0000 (13:48 +0100)]
Avoid crash on old Windows with AVX2-capable CPU for VS2013 builds

The Visual Studio 2013 CRT generates invalid code when it makes a 64-bit
build that is later used on a CPU that supports AVX2 instructions using a
version of Windows before 7SP1/2008R2SP1.

Detect this combination, and in those cases turn off the generation of
FMA3, per recommendation from the Visual Studio team.

The bug is actually in the CRT shipping with Visual Studio 2013, but
Microsoft have stated they're only fixing it in newer major versions.
The fix is therefor conditioned specifically on being built with this
version of Visual Studio, and not previous or later versions.

Author: Christian Ullrich

8 years agoReduce size of two phase file header
Simon Riggs [Thu, 10 Mar 2016 12:51:46 +0000 (12:51 +0000)]
Reduce size of two phase file header

Previously 2PC header was fixed at 200 bytes, which in most cases wasted
WAL space for a workload using 2PC heavily.

Pavan Deolasee, reviewed by Petr Jelinek

8 years agoReduce lock level for altering fillfactor
Simon Riggs [Thu, 10 Mar 2016 12:07:33 +0000 (12:07 +0000)]
Reduce lock level for altering fillfactor

Fabrízio de Royes Mello and Simon Riggs