]> granicus.if.org Git - postgresql/log
postgresql
8 years agoForce synchronous_commit=on in test_decoding's concurrent_ddl_dml.spec.
Andres Freund [Fri, 4 Mar 2016 01:09:08 +0000 (17:09 -0800)]
Force synchronous_commit=on in test_decoding's concurrent_ddl_dml.spec.

Otherwise running installcheck-force on a server with
synchronous_commit=off will result in the tests failing. All the other
tests already do so...

Backpatch: 9.4, where logical decoding was added

8 years agopgbench: accept unambiguous builtin prefixes for -b
Alvaro Herrera [Thu, 3 Mar 2016 22:37:13 +0000 (19:37 -0300)]
pgbench: accept unambiguous builtin prefixes for -b

This makes it easier to use "-b se" instead of typing the full "-b
select-only".

Author: Fabien Coelho
Reviewed-by: Michaël Paquier
8 years agoRework PostgresNode's psql method
Alvaro Herrera [Thu, 3 Mar 2016 20:58:30 +0000 (17:58 -0300)]
Rework PostgresNode's psql method

This makes the psql() method much more capable: it captures both stdout
and stderr; it now returns the psql exit code rather than stdout; a
timeout can now be specified, as can ON_ERROR_STOP behavior; it gained a
new "on_error_die" (defaulting to off) parameter to raise an exception
if there's any problem.  Finally, additional parameters to psql can be
passed if there's need for further tweaking.

For convenience, a new safe_psql() method retains much of the old
behavior of psql(), except that it uses on_error_die on, so that
problems like syntax errors in SQL commands can be detected more easily.

Many existing TAP test files now use safe_psql, which is what is really
wanted.  A couple of ->psql() calls are now added in the commit_ts
tests, which verify that the right thing is happening on certain errors.
Some ->command_fails() calls in recovery tests that were verifying that
psql failed also became ->psql() calls now.

Author: Craig Ringer. Some tweaks by Álvaro Herrera
Reviewed-By: Michaël Paquier
8 years agoperltidy PostgresNode and SimpleTee
Alvaro Herrera [Thu, 3 Mar 2016 16:20:46 +0000 (13:20 -0300)]
perltidy PostgresNode and SimpleTee

Also, mention in README that Perl files should be perltidy'ed.  This
isn't really the best place (since we have Perl files elsewhere in the
tree) and this is already in pgindent's README, but this subdir is
likely to get hacked a whole lot more than the other Perl files, so it
seems okay to spend two lines on this.

Author: Craig Ringer

8 years agoFix mistakes in recovery tests
Alvaro Herrera [Thu, 3 Mar 2016 15:49:02 +0000 (12:49 -0300)]
Fix mistakes in recovery tests

One test was relying on method remove_tree that isn't implemented in the
oldest Perl we support; fix it by using the older rmtree instead.

Another test had a typo in a SQL command, which isn't noticed because
the PostgresNode->psql() method doesn't check that queries return
correctly.  That's undesirable and will also be fixed later on, but for
now let's make the test actually work.

Author: Craig Ringer

8 years agoRevert buggy optimization of index scans
Simon Riggs [Thu, 3 Mar 2016 09:53:43 +0000 (09:53 +0000)]
Revert buggy optimization of index scans

606c0123d627 attempted to reduce cost of index scans using > and <
strategies, though got that completely wrong in a few complex cases.

Revert whole patch until we find a safe optimization.

8 years agoAdd prefix to pl/pgsql global variables and functions
Magnus Hagander [Thu, 3 Mar 2016 09:45:59 +0000 (10:45 +0100)]
Add prefix to pl/pgsql global variables and functions

Rename pl/pgsql global variables to always have a plpgsql_ prefix,
so they don't conflict with other shared libraries loaded.

8 years agological decoding: fix decoding of a commit's commit time.
Andres Freund [Thu, 3 Mar 2016 07:42:21 +0000 (23:42 -0800)]
logical decoding: fix decoding of a commit's commit time.

When adding replication origins in 5aa235042, I somehow managed to set
the timestamp of decoded transactions to InvalidXLogRecptr when decoding
one made without a replication origin. Fix that, and the wrong type of
the new commit_time variable.

This didn't trigger a regression test failure because we explicitly
don't show commit timestamps in the regression tests, as they obviously
are variable. Add a test that checks that a decoded commit's timestamp
is within minutes of NOW() from before the commit.

Reported-By: Weiping Qu
Diagnosed-By: Artur Zakirov
Discussion: 56D4197E.9050706@informatik.uni-kl.de,
    56D42918.1010108@postgrespro.ru
Backpatch: 9.5, where 5aa235042 originates.

8 years agoFix json_to_record() bug with nested objects.
Tom Lane [Thu, 3 Mar 2016 04:31:39 +0000 (23:31 -0500)]
Fix json_to_record() bug with nested objects.

A thinko concerning nesting depth caused json_to_record() to produce bogus
output if a field of its input object contained a sub-object with a field
name matching one of the requested output column names.  Per bug #13996
from Johann Visagie.

I added a regression test case based on his example, plus parallel tests
for json_to_recordset, jsonb_to_record, jsonb_to_recordset.  The latter
three do not exhibit the same bug (which suggests that we may be missing
some opportunities to share code...) but testing seems like a good idea
in any case.

Back-patch to 9.4 where these functions were introduced.

8 years agoCreate stub functions to support pg_upgrade of old contrib/tsearch2.
Tom Lane [Wed, 2 Mar 2016 22:37:54 +0000 (17:37 -0500)]
Create stub functions to support pg_upgrade of old contrib/tsearch2.

Commits 9ff60273e35cad6e and dbe2328959e12701 adjusted the declarations
of some core functions referenced by contrib/tsearch2's install script,
forgetting that in a pg_upgrade situation, we'll be trying to restore
operator class definitions that reference the old signatures.  We've
hit this problem before; solve it in the same way as before, namely by
installing stub functions that have the expected signature and just
invoke the correct function.  Per report from Jeff Janes.

(Someday we ought to stop supporting contrib/tsearch2, but I'm not
sure today is that day.)

8 years agoPrefix temp data dirs with the node name
Alvaro Herrera [Wed, 2 Mar 2016 20:02:36 +0000 (17:02 -0300)]
Prefix temp data dirs with the node name

This makes it easier to relate the temporary data dirs to each node in
a test script.

Author: Kyotaro Horiguchi
Reviewed-By: Craig Ringer, Alvaro Herrera
8 years agoFix PL/Tcl's encoding conversion logic.
Tom Lane [Wed, 2 Mar 2016 18:30:14 +0000 (13:30 -0500)]
Fix PL/Tcl's encoding conversion logic.

PL/Tcl appears to contain logic to convert strings between the database
encoding and UTF8, which is the only encoding modern Tcl will deal with.
However, that code has been disabled since commit 034895125d648b86, which
made it "#if defined(UNICODE_CONVERSION)" and neglected to provide any way
for that symbol to become defined.  That might have been all right back
in 2001, but these days we take a dim view of allowing strings with
incorrect encoding into the database.

Remove the conditional compilation, fix warnings about signed/unsigned char
conversions, clean up assorted places that didn't bother with conversions.
(Notably, there were lots of assumptions that database table and field
names didn't need conversion...)

Add a regression test based on plpython_unicode.  It's not terribly
thorough, but better than no test at all.

8 years agoMake PL/Tcl require Tcl 8.4 or later.
Tom Lane [Wed, 2 Mar 2016 17:24:30 +0000 (12:24 -0500)]
Make PL/Tcl require Tcl 8.4 or later.

As of commit 287822068246a6ae30bb2c7191de727672ae6328, PL/Tcl will not
compile against pre-8.0 Tcl, whereas it used to work (more or less anyway)
with quite prehistoric versions.  As long as we're moving these goalposts,
let's reinstall them at someplace that has some thought behind it.  This
commit sets the minimum allowed Tcl version at 8.4, and rips out some bits
of compatibility cruft that are in consequence no longer needed.  Reasons
for requiring 8.4 include:

* 8.4 was released in 2002; there seems little reason to believe that
anyone would want to use older versions with Postgres 9.6+.

* We have no buildfarm members testing anything older than 8.4, and
thus no way to know if it's broken.

* We need at least 8.1 to allow enforcement of database encoding
security (8.1 standardized Tcl on using UTF8 internally, before that
it was pretty unpredictable).

* Some versions between 8.1 and 8.4 allowed the backend to become
multithreaded, which is disastrous.  We need at least 8.4 to be able
to disable the Tcl notifier subsystem to prevent that.

A small side benefit is that we can make the code more readable by
doing s/CONST84/const/g.

8 years agoConvert PL/Tcl to use Tcl's "object" interfaces.
Tom Lane [Wed, 2 Mar 2016 17:07:31 +0000 (12:07 -0500)]
Convert PL/Tcl to use Tcl's "object" interfaces.

The original implementation of Tcl was all strings, but they improved
performance significantly by introducing typed "objects" (integers,
lists, code, etc).  It's past time we made use of that; that happened
in Tcl 8.0 which was released in 1997.

This patch also modernizes some of the error-reporting code, which may
cause small changes in the spelling of complaints about bad calls to
PL/Tcl-provided commands.

Jim Nasby and Karl Lehenbauer, reviewed by Victor Wagner

8 years agoFix TAP tests for older Perls.
Tom Lane [Wed, 2 Mar 2016 06:06:31 +0000 (01:06 -0500)]
Fix TAP tests for older Perls.

Commit 7132810c (Retain tempdirs for failed tests) used Test::More's
is_passing method, but that was added in Test::More 0.89_01 which is
sometime later than Perl 5.10.1.  Popular platforms such as RHEL6 don't
have that, nevermind some of our older dinosaurs.  Do it the hard way.

Michael Paquier, based on research by Craig Ringer

8 years agoChange the format of the VM fork to add a second bit per page.
Robert Haas [Wed, 2 Mar 2016 02:49:41 +0000 (21:49 -0500)]
Change the format of the VM fork to add a second bit per page.

The new bit indicates whether every tuple on the page is already frozen.
It is cleared only when the all-visible bit is cleared, and it can be
set only when we vacuum a page and find that every tuple on that page is
both visible to every transaction and in no need of any future
vacuuming.

A future commit will use this new bit to optimize away full-table scans
that would otherwise be triggered by XID wraparound considerations.  A
page which is merely all-visible must still be scanned in that case, but
a page which is all-frozen need not be.  This commit does not attempt
that optimization, although that optimization is the goal here.  It
seems better to get the basic infrastructure in place first.

Per discussion, it's very desirable for pg_upgrade to automatically
migrate existing VM forks from the old format to the new format.  That,
too, will be handled in a follow-on patch.

Masahiko Sawada, reviewed by Kyotaro Horiguchi, Fujii Masao, Amit
Kapila, Simon Riggs, Andres Freund, and others, and substantially
revised by me.

8 years agoImprove coverage of pltcl regression tests.
Tom Lane [Wed, 2 Mar 2016 01:01:07 +0000 (20:01 -0500)]
Improve coverage of pltcl regression tests.

Test composite-type arguments and the argisnull and spi_lastoid Tcl
commmands.  This stuff was not covered before, but needs to be exercised
since the upcoming Tcl object-conversion patch changes these code paths
(and broke at least one of them).

8 years agoAdd more tests for commit_timestamp feature
Alvaro Herrera [Tue, 1 Mar 2016 22:53:18 +0000 (19:53 -0300)]
Add more tests for commit_timestamp feature

These tests verify that 1) WAL replay preserves the stored value,
2) a streaming standby server replays the value obtained from the
master, and 3) the behavior is sensible in the face of repeated
configuration changes.

One annoyance is that tmp_check/ subdir from the TAP tests is clobbered
when the pg_regress test runs in the same subdirectory.  This is
bothersome but not too terrible a problem, since the pg_regress test is
not run anyway if the TAP tests fail (unless "make -k" is used).

I had these tests around since commit 69e7235c93e2; add them now that we
have the recovery test framework in place.

8 years agoTAP tests: retain temp dirs on test failure
Alvaro Herrera [Tue, 1 Mar 2016 22:50:13 +0000 (19:50 -0300)]
TAP tests: retain temp dirs on test failure

This makes it easier to study the reason for the failure.

Author: Kyotaro Horiguchi
Reviewed-By: Craig Ringer
8 years agoFix incorrect comment.
Robert Haas [Tue, 1 Mar 2016 18:31:44 +0000 (13:31 -0500)]
Fix incorrect comment.

PQmblen and PQdsplen return information about characters, not words.

Kyotaro Horiguchi

8 years agoFix mistake in extensible node code.
Robert Haas [Tue, 1 Mar 2016 18:17:09 +0000 (13:17 -0500)]
Fix mistake in extensible node code.

I believe that I (rhaas) introduced this bug while editing the patch
that became bcac23de73b89b001fbc628d84471a392e928d1c.

Report and patch from KaiGai Kohei.

8 years agoExtend pgbench's expression syntax to support a few built-in functions.
Robert Haas [Tue, 1 Mar 2016 18:04:09 +0000 (13:04 -0500)]
Extend pgbench's expression syntax to support a few built-in functions.

Fabien Coelho, reviewed mostly by Michael Paquier and me, but also by
Heikki Linnakangas, BeomYong Lee, Kyotaro Horiguchi, Oleksander
Shulgin, and Álvaro Herrera.

8 years agoAdd Unicode map generation scripts as rule prerequisites
Peter Eisentraut [Tue, 1 Mar 2016 01:08:16 +0000 (20:08 -0500)]
Add Unicode map generation scripts as rule prerequisites

That way, the rules will trigger when the scripts change.

8 years agoFix comments
Peter Eisentraut [Tue, 1 Mar 2016 01:08:16 +0000 (20:08 -0500)]
Fix comments

Some of these comments were copied and pasted without updating them,
some of them were duplicates.

8 years agoUCS_to_most.pl: Make executable, for consistency with other scripts
Peter Eisentraut [Tue, 1 Mar 2016 01:08:16 +0000 (20:08 -0500)]
UCS_to_most.pl: Make executable, for consistency with other scripts

8 years agoSuppress scary-looking log messages from async-notify isolation test.
Tom Lane [Tue, 1 Mar 2016 00:29:19 +0000 (19:29 -0500)]
Suppress scary-looking log messages from async-notify isolation test.

I noticed that the async-notify test results in log messages like these:

LOG:  could not send data to client: Broken pipe
FATAL:  connection to client lost

This is because it unceremoniously disconnects a client session that is
about to have some NOTIFY messages delivered to it.  Such log messages
during a regression test might well cause people to go looking for a
problem that doesn't really exist (it did cause me to waste some time that
way).  We can shut it up by adding an UNLISTEN command to session teardown.

Patch HEAD only; this doesn't seem significant enough to back-patch.

8 years agoImprove error message for rejecting RETURNING clauses with dropped columns.
Tom Lane [Tue, 1 Mar 2016 00:11:38 +0000 (19:11 -0500)]
Improve error message for rejecting RETURNING clauses with dropped columns.

This error message was written with only ON SELECT rules in mind, but since
then we also made RETURNING-clause targetlists go through the same logic.
This means that you got a rather off-topic error message if you tried to
add a rule with RETURNING to a table having dropped columns.  Ideally we'd
just support that, but some preliminary investigation says that it might be
a significant amount of work.  Seeing that Nicklas Avén's complaint is the
first one we've gotten about this in the ten years or so that the code's
been like that, I'm unwilling to put much time into it.  Instead, improve
the error report by issuing a different message for RETURNING cases, and
revise the associated comment based on this investigation.

Discussion: 1456176604.17219.9.camel@jordogskog.no

8 years agoMinor tweaks for new src/test/recovery
Alvaro Herrera [Mon, 29 Feb 2016 21:16:59 +0000 (18:16 -0300)]
Minor tweaks for new src/test/recovery

Author: Michael Paquier

8 years agoFix typos
Alvaro Herrera [Mon, 29 Feb 2016 21:11:58 +0000 (18:11 -0300)]
Fix typos

Author: Amit Langote

8 years agodoc: document MANPATH as /usr/local/pgsql/share/man
Alvaro Herrera [Mon, 29 Feb 2016 20:53:55 +0000 (17:53 -0300)]
doc: document MANPATH as /usr/local/pgsql/share/man

The docs were advising to use /usr/local/pgsql/man instead, but that's
wrong.

Reported-By: Slawomir Sudnik
Backpatch-To: 9.1
Bug: #13894

8 years agoMake new isolationtester test more stable
Alvaro Herrera [Mon, 29 Feb 2016 19:28:54 +0000 (16:28 -0300)]
Make new isolationtester test more stable

The original coding of the test was relying too much on the ordering in
which backends are awakened once an advisory lock which they wait for is
released.  Change the code so that each backend uses its own advisory
lock instead, so that the output becomes stable.  Also add a few seconds
of sleep between lock releases, so that the test isn't broken in
overloaded buildfarm animals, as suggested by Tom Lane.

Per buildfarm members spoonbill and guaibasaurus.

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

8 years agoRemove useless unary plus.
Tom Lane [Mon, 29 Feb 2016 15:48:40 +0000 (10:48 -0500)]
Remove useless unary plus.

It's harmless, but might confuse readers.  Seems to have been introduced
in 6bc8ef0b7f1f1df3.  Back-patch, just to avoid cosmetic cross-branch
differences.

Amit Langote

8 years agoFix build under OPTIMIZER_DEBUG.
Tom Lane [Mon, 29 Feb 2016 15:14:12 +0000 (10:14 -0500)]
Fix build under OPTIMIZER_DEBUG.

In commit 19a541143a09c067 I replaced RelOptInfo.width with
RelOptInfo.reltarget.width, but I missed updating debug_print_rel()
for that because it's not compiled by default.
Reported by Salvador Fandino, patch by Michael Paquier.

8 years agoFix incorrect varlevelsup in security_barrier_replace_vars().
Dean Rasheed [Mon, 29 Feb 2016 12:28:06 +0000 (12:28 +0000)]
Fix incorrect varlevelsup in security_barrier_replace_vars().

When converting an RTE with securityQuals into a security barrier
subquery RTE, ensure that the Vars in the new subquery's targetlist
all have varlevelsup = 0 so that they correctly refer to the
underlying base relation being wrapped.

The original code was creating new Vars by copying them from existing
Vars referencing the base relation found elsewhere in the query, but
failed to account for the fact that such Vars could come from sublink
subqueries, and hence have varlevelsup > 0. In practice it looks like
this could only happen with nested security barrier views, where the
outer view has a WHERE clause containing a correlated subquery, due to
the order in which the Vars are processed.

Bug: #13988
Reported-by: Adam Guthrie
Backpatch-to: 9.4, where updatable SB views were introduced
8 years agoAvoid multiple free_struct_lconv() calls on same data.
Tom Lane [Mon, 29 Feb 2016 04:39:20 +0000 (23:39 -0500)]
Avoid multiple free_struct_lconv() calls on same data.

A failure partway through PGLC_localeconv() led to a situation where
the next call would call free_struct_lconv() a second time, leading
to free() on already-freed strings, typically leading to a core dump.
Add a flag to remember whether we need to do that.

Per report from Thom Brown.  His example case only provokes the failure
as far back as 9.4, but nonetheless this code is obviously broken, so
back-patch to all supported branches.

8 years agoAllow multiple --temp-config arguments to pg_regress
Andrew Dunstan [Sun, 28 Feb 2016 14:38:43 +0000 (09:38 -0500)]
Allow multiple --temp-config arguments to pg_regress

This means that if, for example, TEMP_CONFIG is set and a Makefile
explicitly sets a temp-config file, both will now be used.

Patch from John Gorman.

8 years agoRespect TEMP_CONFIG when pg_regress_check and friends are called
Andrew Dunstan [Sat, 27 Feb 2016 17:28:21 +0000 (12:28 -0500)]
Respect TEMP_CONFIG when pg_regress_check and friends are called

This reverts commit 9117985b6ba9beda4f280f596035649fc23b6233 in favor of
a more general solution.

8 years agoAdd isolationtester spec for old heapam.c bug
Alvaro Herrera [Fri, 26 Feb 2016 20:11:15 +0000 (17:11 -0300)]
Add isolationtester spec for old heapam.c bug

In 0e5680f4737a, I fixed a bug in heapam that caused spurious deadlocks
when multiple updates concurrently attempted to modify the old version
of an updated tuple whose new version was key-share locked.  I proposed
an isolationtester spec file that reproduced the bug, but back then
isolationtester wasn't mature enough to be able to run it.  Now that
38f8bdcac498 is in the tree, we can have this spec file too.

Discussion: https://www.postgresql.org/message-id/20141212205254.GC1768%40alvh.no-ip.org

8 years agoApply last revision of recovery patch
Alvaro Herrera [Fri, 26 Feb 2016 19:22:53 +0000 (16:22 -0300)]
Apply last revision of recovery patch

I applied the previous-to-last revision of Michaël's submitted patch
instead of the last; these two tweaks pointed out by Craig were left out
of the previous commit by accident.

8 years agoAdd a test framework for recovery
Alvaro Herrera [Fri, 26 Feb 2016 19:13:30 +0000 (16:13 -0300)]
Add a test framework for recovery

This long-awaited framework is an expansion of the existing PostgresNode
stuff to support additional features for recovery testing; the recovery
tests included in this commit are a starting point that cover some of
the recovery features we have.  More scripts are expected to be added
later.

Author: Michaël Paquier, a bit of help from Amir Rohan
Reviewed by: Amir Rohan, Stas Kelvich, Kyotaro Horiguchi, Victor Wagner,
Craig Ringer, Álvaro Herrera
Discussion: http://www.postgresql.org/message-id/CAB7nPqTf7V6rswrFa=q_rrWeETUWagP=h8LX8XAov2Jcxw0DRg@mail.gmail.com
Discussion: http://www.postgresql.org/message-id/trinity-b4a8035d-59af-4c42-a37e-258f0f28e44a-1443795007012@3capp-mailcom-lxa08

8 years agoMove some code from RewindTest into PostgresNode
Alvaro Herrera [Fri, 26 Feb 2016 16:24:22 +0000 (13:24 -0300)]
Move some code from RewindTest into PostgresNode

Some code in the RewindTest test suite is more generally useful than
just for that suite, so put it where other test suites can reach it.

Some postgresql.conf parameters change their default values when a
cluster is initialized with 'allows_streaming' than the previous
behavior; most notably, autovacuum is no longer turned off.

(Also, we no longer call pg_ctl promote with -w, but that flag doesn't
actually do anything in promote so there's no behavior change.)

Author: Michael Paquier

8 years agoOn second thought, disable parallelism for prepared statements.
Robert Haas [Fri, 26 Feb 2016 11:03:37 +0000 (16:33 +0530)]
On second thought, disable parallelism for prepared statements.

CREATE TABLE .. AS EXECUTE can turn an apparently read-only query into
a write operation, which parallel query can't handle.  It's a bit of a
shame that requires us to avoid parallel query for queries prepared via
PREPARE in all cases, but for right now it does.

8 years agoAdd new FDW API to test for parallel-safety.
Robert Haas [Fri, 26 Feb 2016 10:44:46 +0000 (16:14 +0530)]
Add new FDW API to test for parallel-safety.

This is basically a bug fix; the old code assumes that a ForeignScan
is always parallel-safe, but for postgres_fdw, for example, this is
definitely false.  It should be true for file_fdw, though, since a
worker can read a file from the filesystem just as well as any other
backend process.

Original patch by Thomas Munro.  Documentation, and changes to the
comments, by me.

8 years agoRespect TEMP_CONFIG when running contrib regression tests.
Robert Haas [Fri, 26 Feb 2016 07:08:21 +0000 (12:38 +0530)]
Respect TEMP_CONFIG when running contrib regression tests.

Thomas Munro

8 years agoAdd POD docs to PostgresNode
Alvaro Herrera [Fri, 26 Feb 2016 00:31:52 +0000 (21:31 -0300)]
Add POD docs to PostgresNode

Also, the dump_info method got split into another method that returns
the stuff as a string instead of just printing it to stdout.

Add a new README in src/test/perl too.

Author: Craig Ringer
Reviewed by: Michaël Paquier

8 years agoAdd README in src/test and src/test/modules
Alvaro Herrera [Fri, 26 Feb 2016 00:08:32 +0000 (21:08 -0300)]
Add README in src/test and src/test/modules

Author: Craig Ringer
Reviewed by: Michaël Paquier

8 years agoFix typos
Alvaro Herrera [Thu, 25 Feb 2016 23:50:20 +0000 (20:50 -0300)]
Fix typos

Backpatch to: 9.4

8 years agoEnable parallelism for prepared statements and extended query protocol.
Robert Haas [Thu, 25 Feb 2016 07:32:18 +0000 (13:02 +0530)]
Enable parallelism for prepared statements and extended query protocol.

Parallel query can't handle running a query only partially rather than
to completion.  However, there seems to be no way to run a statement
prepared via SQL PREPARE other than to completion, so we can enable it
there without a problem.

The situation is more complicated for the extend query protocol.
libpq seems to provide no way to send an Execute message with a
non-zero rowcount, but some other client might.  If that happens, and
a parallel plan was chosen, we'll execute the parallel plan without
using any workers, which may be somewhat inefficient but should still
work.  Hopefully this won't be a problem; users can always set
max_parallel_degree=0 to avoid choosing parallel plans in the first
place.

Amit Kapila, reviewed by me.

8 years agoClean the last few TAP suite tmp_check directories.
Noah Misch [Thu, 25 Feb 2016 04:41:54 +0000 (23:41 -0500)]
Clean the last few TAP suite tmp_check directories.

Back-patch to 9.5, where the suites were introduced.

8 years agoMSVC: Clean tmp_check directory of pg_controldata test suite.
Noah Misch [Thu, 25 Feb 2016 04:41:33 +0000 (23:41 -0500)]
MSVC: Clean tmp_check directory of pg_controldata test suite.

Back-patch to 9.4, where the suite was introduced.

8 years agoCreate a function to reliably identify which sessions block which others.
Tom Lane [Mon, 22 Feb 2016 19:31:43 +0000 (14:31 -0500)]
Create a function to reliably identify which sessions block which others.

This patch introduces "pg_blocking_pids(int) returns int[]", which returns
the PIDs of any sessions that are blocking the session with the given PID.
Historically people have obtained such information using a self-join on
the pg_locks view, but it's unreasonably tedious to do it that way with any
modicum of correctness, and the addition of parallel queries has pretty
much broken that approach altogether.  (Given some more columns in the view
than there are today, you could imagine handling parallel-query cases with
a 4-way join; but ugh.)

The new function has the following behaviors that are painful or impossible
to get right via pg_locks:

1. Correctly understands which lock modes block which other ones.

2. In soft-block situations (two processes both waiting for conflicting lock
modes), only the one that's in front in the wait queue is reported to
block the other.

3. In parallel-query cases, reports all sessions blocking any member of
the given PID's lock group, and reports a session by naming its leader
process's PID, which will be the pg_backend_pid() value visible to
clients.

The motivation for doing this right now is mostly to fix the isolation
tests.  Commit 38f8bdcac4982215beb9f65a19debecaf22fd470 lobotomized
isolationtester's is-it-waiting query by removing its ability to recognize
nonconflicting lock modes, as a crude workaround for the inability to
handle soft-block situations properly.  But even without the lock mode
tests, the old query was excessively slow, particularly in
CLOBBER_CACHE_ALWAYS builds; some of our buildfarm animals fail the new
deadlock-hard test because the deadlock timeout elapses before they can
probe the waiting status of all eight sessions.  Replacing the pg_locks
self-join with use of pg_blocking_pids() is not only much more correct, but
a lot faster: I measure it at about 9X faster in a typical dev build with
Asserts, and 3X faster in CLOBBER_CACHE_ALWAYS builds.  That should provide
enough headroom for the slower CLOBBER_CACHE_ALWAYS animals to pass the
test, without having to lengthen deadlock_timeout yet more and thus slow
down the test for everyone else.

8 years agoRemove redundant PGPROC.lockGroupLeaderIdentifier field.
Tom Lane [Mon, 22 Feb 2016 16:20:35 +0000 (11:20 -0500)]
Remove redundant PGPROC.lockGroupLeaderIdentifier field.

We don't really need this field, because it's either zero or redundant with
PGPROC.pid.  The use of zero to mark "not a group leader" is not necessary
since we can just as well test whether lockGroupLeader is NULL.  This does
not save very much, either as to code or data, but the simplification seems
worthwhile anyway.

8 years agoFix wrong keysize in PrivateRefCountHash creation.
Andres Freund [Mon, 22 Feb 2016 06:48:44 +0000 (22:48 -0800)]
Fix wrong keysize in PrivateRefCountHash creation.

In 4b4b680c3 I accidentally used sizeof(PrivateRefCountArray) instead of
sizeof(PrivateRefCountEntry) when creating the refcount overflow
hashtable. As the former is bigger than the latter, this luckily only
resulted in a slightly increased memory usage when many buffers are
pinned in a backend.

Reported-By: Takashi Horikawa
Discussion: 73FA3881462C614096F815F75628AFCD035A48C3@BPXM01GP.gisp.nec.co.jp
Backpatch: 9.5, where thew new ref count infrastructure was introduced

8 years agoDocs: make prose discussion match the ordering of Table 9-58.
Tom Lane [Sun, 21 Feb 2016 20:23:17 +0000 (15:23 -0500)]
Docs: make prose discussion match the ordering of Table 9-58.

The "Session Information Functions" table seems to be sorted mostly
alphabetically (although it's not perfect), which would be all right
if it didn't lead to some related functions being described in a
pretty nonintuitive order.  Also, the prose discussions after the table
were in an order that hardly matched the table at all.  Rearrange to
make things a bit easier to follow.

8 years agoCosmetic improvements in new config_info code.
Tom Lane [Sun, 21 Feb 2016 16:38:24 +0000 (11:38 -0500)]
Cosmetic improvements in new config_info code.

Coverity griped about use of unchecked strcpy() into a local variable.
There's unlikely to be any actual bug there, since no caller would be
passing a path longer than MAXPGPATH, but nonetheless use of strlcpy()
seems preferable.

While at it, get rid of unmaintainable separation between list of
field names and list of field values in favor of initializing them
in parallel.  And we might as well declare get_configdata()'s path
argument as const char *, even though no current caller needs that.

8 years agoFix two-argument jsonb_object when called with empty arrays
Andrew Dunstan [Sun, 21 Feb 2016 15:30:49 +0000 (10:30 -0500)]
Fix two-argument jsonb_object when called with empty arrays

Some over-eager copy-and-pasting on my part resulted in a nonsense
result being returned in this case. I have adopted the same pattern for
handling this case as is used in the one argument form of the function,
i.e. we just skip over the code that adds values to the object.

Diagnosis and patch from Michael Paquier, although not quite his
solution.

Fixes bug #13936.

Backpatch to 9.5 where jsonb_object was introduced.

8 years agoFix incorrect decision about which lock to take.
Robert Haas [Sun, 21 Feb 2016 11:36:41 +0000 (17:06 +0530)]
Fix incorrect decision about which lock to take.

Spotted by Tom Lane.

8 years agoCosmetic improvements to group locking.
Robert Haas [Sun, 21 Feb 2016 10:12:02 +0000 (15:42 +0530)]
Cosmetic improvements to group locking.

Reflow text in lock manager README so that it fits within 80 columns.
Correct some mistakes.  Expand the README to explain not only why group
locking exists but also the data structures that support it.  Improve
comments related to group locking several files.  Change the name of a
macro argument for improved clarity.

Most of these problems were reported by Tom Lane, but I found a few
of them myself.

Robert Haas and Tom Lane

8 years agopostgres_fdw: Avoid sharing list substructure.
Robert Haas [Sun, 21 Feb 2016 08:47:50 +0000 (14:17 +0530)]
postgres_fdw: Avoid sharing list substructure.

list_concat(list_concat(a, b), c) destructively changes both a and b;
to avoid such perils, copy lists of remote_conds before incorporating
them into larger lists via list_concat().

Ashutosh Bapat, per a report from Etsuro Fujita

8 years agoFix wording in the Tutorial document.
Tatsuo Ishii [Sun, 21 Feb 2016 00:04:59 +0000 (09:04 +0900)]
Fix wording in the Tutorial document.

With suggentions from Tom Lane.

8 years agoFurther fixing to make pg_size_bytes() portable.
Dean Rasheed [Sat, 20 Feb 2016 15:49:26 +0000 (15:49 +0000)]
Further fixing to make pg_size_bytes() portable.

Not all compilers support "long long" and the "LL" integer literal
suffix, so use a cast to int64 instead.

8 years agoFix pg_size_bytes() to be more portable.
Dean Rasheed [Sat, 20 Feb 2016 11:03:04 +0000 (11:03 +0000)]
Fix pg_size_bytes() to be more portable.

Commit 53874c5228fe16589a4d01b3e1fab3678e0fd8e3 broke various 32-bit
buildfarm machines because it incorrectly used an 'L' suffix for what
needed to be a 64-bit literal. Thanks to Michael Paquier for helping
to diagnose this.

8 years agoAdd pg_size_bytes() to parse human-readable size strings.
Dean Rasheed [Sat, 20 Feb 2016 09:57:27 +0000 (09:57 +0000)]
Add pg_size_bytes() to parse human-readable size strings.

This will parse strings in the format produced by pg_size_pretty() and
return sizes in bytes. This allows queries to be written with clauses
like "pg_total_relation_size(oid) > pg_size_bytes('10 GB')".

Author: Pavel Stehule with various improvements by Vitaly Burovoy
Discussion: http://www.postgresql.org/message-id/CAFj8pRD-tGoDKnxdYgECzA4On01_uRqPrwF-8LdkSE-6bDHp0w@mail.gmail.com
Reviewed-by: Vitaly Burovoy, Oleksandr Shulgin, Kyotaro Horiguchi,
    Michael Paquier and Robert Haas

8 years agodoc: Improve CSS style of option element
Peter Eisentraut [Sat, 20 Feb 2016 04:00:22 +0000 (23:00 -0500)]
doc: Improve CSS style of option element

Prevent wrapping of the element content to avoid confusing line breaks
between hyphens.

8 years agoCall xlc __isync() after, not before, associated compare-and-swap.
Noah Misch [Sat, 20 Feb 2016 03:47:50 +0000 (22:47 -0500)]
Call xlc __isync() after, not before, associated compare-and-swap.

Architecture reference material specifies this order, and s_lock.h
inline assembly agrees.  The former order failed to provide mutual
exclusion to lwlock.c and perhaps to other clients.  The two xlc
buildfarm members, hornet and mandrill, have failed sixteen times with
duplicate key errors involving pg_class_oid_index or pg_type_oid_index.
Back-patch to 9.5, where commit b64d92f1a5602c55ee8b27a7ac474f03b7aee340
introduced atomics.

Reviewed by Andres Freund and Tom Lane.

8 years agoCorrect StartupSUBTRANS for page wraparound
Simon Riggs [Fri, 19 Feb 2016 08:31:12 +0000 (08:31 +0000)]
Correct StartupSUBTRANS for page wraparound

StartupSUBTRANS() incorrectly handled cases near the max pageid in the subtrans
data structure, which in some cases could lead to errors in startup for Hot
Standby.
This patch wraps the pageids correctly, avoiding any such errors.
Identified by exhaustive crash testing by Jeff Janes.

Jeff Janes

8 years agopg_dump: Fix inconsistent sscanf() conversions
Peter Eisentraut [Fri, 19 Feb 2016 01:12:38 +0000 (20:12 -0500)]
pg_dump: Fix inconsistent sscanf() conversions

It was using %u to read a string that was earlier produced by snprintf with %d
into a signed integer variable.  This seems to work in practice but is
incorrect.

found by cppcheck

8 years agoAdd an explicit representation of the output targetlist to Paths.
Tom Lane [Fri, 19 Feb 2016 01:01:49 +0000 (20:01 -0500)]
Add an explicit representation of the output targetlist to Paths.

Up to now, there's been an assumption that all Paths for a given relation
compute the same output column set (targetlist).  However, there are good
reasons to remove that assumption.  For example, an indexscan on an
expression index might be able to return the value of an expensive function
"for free".  While we have the ability to generate such a plan today in
simple cases, we don't have a way to model that it's cheaper than a plan
that computes the function from scratch, nor a way to create such a plan
in join cases (where the function computation would normally happen at
the topmost join node).  Also, we need this so that we can have Paths
representing post-scan/join steps, where the targetlist may well change
from one step to the next.  Therefore, invent a "struct PathTarget"
representing the columns we expect a plan step to emit.  It's convenient
to include the output tuple width and tlist evaluation cost in this struct,
and there will likely be additional fields in future.

While Path nodes that actually do have custom outputs will need their own
PathTargets, it will still be true that most Paths for a given relation
will compute the same tlist.  To reduce the overhead added by this patch,
keep a "default PathTarget" in RelOptInfo, and allow Paths that compute
that column set to just point to their parent RelOptInfo's reltarget.
(In the patch as committed, actually every Path is like that, since we
do not yet have any cases of custom PathTargets.)

I took this opportunity to provide some more-honest costing of
PlaceHolderVar evaluation.  Up to now, the assumption that "scan/join
reltargetlists have cost zero" was applied not only to Vars, where it's
reasonable, but also PlaceHolderVars where it isn't.  Now, we add the eval
cost of a PlaceHolderVar's expression to the first plan level where it can
be computed, by including it in the PathTarget cost field and adding that
to the cost estimates for Paths.  This isn't perfect yet but it's much
better than before, and there is a way forward to improve it more.  This
costing change affects the join order chosen for a couple of the regression
tests, changing expected row ordering.

8 years agopg_upgrade: suppress creation of delete script
Bruce Momjian [Thu, 18 Feb 2016 23:32:27 +0000 (18:32 -0500)]
pg_upgrade:  suppress creation of delete script

Suppress creation of the pg_upgrade delete script when the new data
directory is inside the old data directory.

Reported-by: IRC
Backpatch-through: 9.3, where delete script tests were added

8 years agoFix multiple bugs in contrib/pgstattuple's pgstatindex() function.
Tom Lane [Thu, 18 Feb 2016 20:40:35 +0000 (15:40 -0500)]
Fix multiple bugs in contrib/pgstattuple's pgstatindex() function.

Dead or half-dead index leaf pages were incorrectly reported as live, as a
consequence of a code rearrangement I made (during a moment of severe brain
fade, evidently) in commit d287818eb514d431.

The index metapage was not counted in index_size, causing that result to
not agree with the actual index size on-disk.

Index root pages were not counted in internal_pages, which is inconsistent
compared to the case of a root that's also a leaf (one-page index), where
the root would be counted in leaf_pages.  Aside from that inconsistency,
this could lead to additional transient discrepancies between the reported
page counts and index_size, since it's possible for pgstatindex's scan to
see zero or multiple pages marked as BTP_ROOT, if the root moves due to
a split during the scan.  With these fixes, index_size will always be
exactly one page more than the sum of the displayed page counts.

Also, the index_size result was incorrectly documented as being measured in
pages; it's always been measured in bytes.  (While fixing that, I couldn't
resist doing some small additional wordsmithing on the pgstattuple docs.)

Including the metapage causes the reported index_size to not be zero for
an empty index.  To preserve the desired property that the pgstattuple
regression test results are platform-independent (ie, BLCKSZ configuration
independent), scale the index_size result in the regression tests.

The documentation issue was reported by Otsuka Kenji, and the inconsistent
root page counting by Peter Geoghegan; the other problems noted by me.
Back-patch to all supported branches, because this has been broken for
a long time.

8 years agoImprove error message about active replication slot
Peter Eisentraut [Thu, 18 Feb 2016 02:22:13 +0000 (21:22 -0500)]
Improve error message about active replication slot

The old phrasing was awkward if a replication slot is activated and
deactivated repeatedly.

8 years agoRevert inadvertant change in pg_config behavior
Joe Conway [Wed, 17 Feb 2016 18:00:34 +0000 (10:00 -0800)]
Revert inadvertant change in pg_config behavior

In commit a5c43b88 the behavior of command line pg_config was
inadvertantly changed to include the config name when specific
configs are requested, similar to when none are requested and
all are emitted. This breaks scripts that expect to use
pg_config for e.g. PGXS. Revert the behavior to the previous.

8 years agoAdd new system view, pg_config
Joe Conway [Wed, 17 Feb 2016 17:12:06 +0000 (09:12 -0800)]
Add new system view, pg_config

Move and refactor the underlying code for the pg_config client
application to src/common in support of sharing it with a new
system information SRF called pg_config() which makes the same
information available via SQL. Additionally wrap the SRF with a
new system view, as called pg_config.

Patch by me with extensive input and review by Michael Paquier
and additional review by Alvaro Herrera.

8 years agoReuse abbreviated keys in ordered [set] aggregates.
Robert Haas [Wed, 17 Feb 2016 10:10:00 +0000 (15:40 +0530)]
Reuse abbreviated keys in ordered [set] aggregates.

When processing ordered aggregates following a sort that could make use
of the abbreviated key optimization, only call the equality operator to
compare successive pairs of tuples when their abbreviated keys were not
equal.

Peter Geoghegan, reviewd by Andreas Karlsson and by me.

8 years agoMake plpython cope with funny characters in function names.
Tom Lane [Wed, 17 Feb 2016 02:08:15 +0000 (21:08 -0500)]
Make plpython cope with funny characters in function names.

A function name that's double-quoted in SQL can contain almost any
characters, but we were using that name directly as part of the name
generated for the Python-level function, and Python doesn't like
anything that isn't pretty much a standard identifier.  To fix,
replace anything that isn't an ASCII letter or digit with an underscore
in the generated name.  This doesn't create any risk of duplicate Python
function names because we were already appending the function OID to
the generated name to ensure uniqueness.  Per bug #13960 from Jim Nasby.

Patch by Jim Nasby, modified a bit by me.  Back-patch to all
supported branches.

8 years agoImprove documentation about CREATE INDEX CONCURRENTLY.
Tom Lane [Tue, 16 Feb 2016 18:43:03 +0000 (13:43 -0500)]
Improve documentation about CREATE INDEX CONCURRENTLY.

Clarify the description of which transactions will block a CREATE INDEX
CONCURRENTLY command from proceeding, and mention that the index might
still not be usable after CREATE INDEX completes.  (This happens if the
index build detected broken HOT chains, so that pg_index.indcheckxmin gets
set, and there are open old transactions preventing the xmin horizon from
advancing past the index's initial creation.  I didn't want to explain what
broken HOT chains are, though, so I omitted an explanation of exactly when
old transactions prevent the index from being used.)

Per discussion with Chris Travers.  Back-patch to all supported branches,
since the same text appears in all of them.

8 years agorelease notes: fix 9.5 SGML comment about commit
Bruce Momjian [Tue, 16 Feb 2016 17:42:35 +0000 (12:42 -0500)]
release notes:  fix 9.5 SGML comment about commit

Reported-by: Tatsuo Ishii
Backpatch-through: 9.5

8 years agoChanged expected result to list IPv6 local interface too.
Michael Meskes [Tue, 16 Feb 2016 13:34:10 +0000 (14:34 +0100)]
Changed expected result to list IPv6 local interface too.

8 years agoChange ecpg lexer to accept comments with line breaks in CPP lines.
Michael Meskes [Tue, 16 Feb 2016 13:23:50 +0000 (14:23 +0100)]
Change ecpg lexer to accept comments with line breaks in CPP lines.

8 years agoImprove wording in the planner doc
Tatsuo Ishii [Tue, 16 Feb 2016 06:36:52 +0000 (15:36 +0900)]
Improve wording in the planner doc

Change "In this case" to "In the example above" to clarify what it
actually refers to.

8 years agoCorrect the formulas for System V IPC parameters SEMMNI and SEMMNS in docs.
Fujii Masao [Tue, 16 Feb 2016 05:49:47 +0000 (14:49 +0900)]
Correct the formulas for System V IPC parameters SEMMNI and SEMMNS in docs.

In runtime.sgml, the old formulas for calculating the reasonable
values of SEMMNI and SEMMNS were incorrect. They have forgotten to
count the number of semaphores which both the checkpointer process
(introduced in 9.2) and the background worker processes (introduced
in 9.3) need.

This commit fixes those formulas so that they count the number of
semaphores which the checkpointer process and the background worker
processes need.

Report and patch by Kyotaro Horiguchi. Only the patch for 9.3 was
modified by me. Back-patch to 9.2 where the checkpointer process was
added and the number of needed semaphores was increased.

Author: Kyotaro Horiguchi
Reviewed-by: Fujii Masao
Backpatch: 9.2
Discussion: http://www.postgresql.org/message-id/20160203.125119.66820697.horiguchi.kyotaro@lab.ntt.co.jp

8 years agoMove DATA entry to correct position
Joe Conway [Tue, 16 Feb 2016 00:37:03 +0000 (16:37 -0800)]
Move DATA entry to correct position

In commit 7b4bfc87 the DATA and DESCR entries for the new
row_security_active() function were inadvertantly put after
the PROVOLATILE defines, rather than before as they should
have been placed. Move them up where they belong.

Backpatch to 9.5 where the new entries were introduced.

8 years agoAllow the WAL writer to flush WAL at a reduced rate.
Andres Freund [Mon, 15 Feb 2016 22:52:38 +0000 (23:52 +0100)]
Allow the WAL writer to flush WAL at a reduced rate.

Commit 4de82f7d7 increased the WAL flush rate, mainly to increase the
likelihood that hint bits can be set quickly. More quickly set hint bits
can reduce contention around the clog et al.  But unfortunately the
increased flush rate can have a significant negative performance impact,
I have measured up to a factor of ~4.  The reason for this slowdown is
that if there are independent writes to the underlying devices, for
example because shared buffers is a lot smaller than the hot data set,
or because a checkpoint is ongoing, the fdatasync() calls force cache
flushes to be emitted to the storage.

This is achieved by flushing WAL only if the last flush was longer than
wal_writer_delay ago, or if more than wal_writer_flush_after (new GUC)
unflushed blocks are pending. Based on some tests the default for
wal_writer_delay is 1MB, which seems to work well both on SSD and
rotational media.

To avoid negative performance impact due to 4de82f7d7 an earlier
commit (db76b1e) made SetHintBits() more likely to succeed; preventing
performance regressions in the pgbench tests I performed.

Discussion: 20160118163908.GW10941@awork2.anarazel.de

8 years agopgbench: avoid FD_ISSET on an invalid file descriptor
Alvaro Herrera [Mon, 15 Feb 2016 23:33:43 +0000 (20:33 -0300)]
pgbench: avoid FD_ISSET on an invalid file descriptor

The original code wasn't careful to test the file descriptor returned by
PQsocket() for an invalid socket.  If an invalid socket did turn up,
that would amount to calling FD_ISSET with fd = -1, whereby undefined
behavior can be invoked.

To fix, test file descriptor for validity and stop further processing if
that fails.

Problem noticed by Coverity.

There is an existing FD_ISSET callsite that does check for invalid
sockets beforehand, but the error message reported by it was
strerror(errno); in testing the aforementioned change, that turns out to
result in "bad socket: Success" which isn't terribly helpful.  Instead
use PQerrorMessage() in both places which is more likely to contain an
useful error message.

Backpatch-through: 9.1.

8 years agoSuppress compiler warnings about useless comparison of unsigned to zero.
Tom Lane [Mon, 15 Feb 2016 22:11:51 +0000 (17:11 -0500)]
Suppress compiler warnings about useless comparison of unsigned to zero.

Reportedly, some compilers warn about tests like "c < 0" if c is unsigned,
and hence complain about the character range checks I added in commit
3bb3f42f3749d40b8d4de65871e8d828b18d4a45.  This is a bit of a pain since
the regex library doesn't really want to assume that chr is unsigned.
However, since any such reconfiguration would involve manual edits of
regcustom.h anyway, we can put it on the shoulders of whoever wants to
do that to adjust this new range-checking macro correctly.

Per gripes from Coverity and Andres.

8 years agoAllow SetHintBits() to succeed if the buffer's LSN is new enough.
Andres Freund [Mon, 15 Feb 2016 21:15:35 +0000 (22:15 +0100)]
Allow SetHintBits() to succeed if the buffer's LSN is new enough.

Previously we only allowed SetHintBits() to succeed if the commit LSN of
the last transaction touching the page has already been flushed to
disk. We can't generally change the LSN of the page, because we don't
necessarily have the required locks on the page. But the required LSN
interlock does not mean the commit record has to be flushed immediately,
it just requires that the commit record will be flushed before the page is
written out. Therefore if the buffer LSN is newer than the commit LSN,
the hint bit can be safely set.

In a number of scenarios (e.g. pgbench) this noticeably increases the
number of hint bits are set. But more importantly it also keeps the
success rate up when flushing WAL less frequently. That was the original
reason for commit 4de82f7d7, which has negative performance consequences
in a number of scenarios. This will allow a followup commit to reduce
the flush rate.

Discussion: 20160118163908.GW10941@awork2.anarazel.de

8 years agoCorrect Copyright year from 2015 to 2016
Joe Conway [Mon, 15 Feb 2016 21:19:35 +0000 (13:19 -0800)]
Correct Copyright year from 2015 to 2016

Looks like this patch went in after Copyright messages
were updated for 2016 and it missed the boat. Fixed.

8 years agoMake concurrent refresh check early that there is a unique index on matview.
Fujii Masao [Mon, 15 Feb 2016 17:15:44 +0000 (02:15 +0900)]
Make concurrent refresh check early that there is a unique index on matview.

In REFRESH MATERIALIZED VIEW command, CONCURRENTLY option is only
allowed if there is at least one unique index with no WHERE clause on
one or more columns of the matview. Previously, concurrent refresh
checked the existence of a unique index on the matview after filling
the data to new snapshot, i.e., after calling refresh_matview_datafill().
So, when there was no unique index, we could need to wait a long time
before we detected that and got the error. It was a waste of time.

To eliminate such wasting time, this commit changes concurrent refresh
so that it checks the existence of a unique index at the beginning of
the refresh operation, i.e., before starting any time-consuming jobs.
If CONCURRENTLY option is not allowed due to lack of a unique index,
concurrent refresh can immediately detect it and emit an error.

Author: Masahiko Sawada
Reviewed-by: Michael Paquier, Fujii Masao
8 years agoFix typo
Magnus Hagander [Mon, 15 Feb 2016 10:41:34 +0000 (11:41 +0100)]
Fix typo

8 years agoReplace broken link in comment.
Noah Misch [Mon, 15 Feb 2016 07:35:52 +0000 (02:35 -0500)]
Replace broken link in comment.

8 years agoMake GetLockStatusData's header comment resemble reality.
Tom Lane [Sat, 13 Feb 2016 20:42:31 +0000 (15:42 -0500)]
Make GetLockStatusData's header comment resemble reality.

The API spec for this function was changed completely (and for the better)
by commit 3cba8999b343648c4c528432ab3d51400194e93b, but it didn't bother
with anything as mundane as updating the comments.

8 years agopg_upgrade: Add C comment about NextXID delimiter
Bruce Momjian [Fri, 12 Feb 2016 22:53:36 +0000 (17:53 -0500)]
pg_upgrade: Add C comment about NextXID delimiter

We don't test the catversion for the NextXID delimiter change, we just
test the string contents;  explain why.

Reported-by: Michael Paquier
8 years agoChange delimiter used for display of NextXID
Joe Conway [Fri, 12 Feb 2016 22:23:59 +0000 (14:23 -0800)]
Change delimiter used for display of NextXID

NextXID has been rendered in the form of a pg_lsn even though it
really is not. This can cause confusion, so change the format from
%u/%u to %u:%u, per discussion on hackers.

Complaint by me, patch by me and Bruce, reviewed by Michael Paquier
and Alvaro. Applied to HEAD only.

Author: Joe Conway, Bruce Momjian
Reviewed-by: Michael Paquier, Alvaro Herrera
Backpatch-through: master

8 years agoIncrease deadlock_timeout some more in the deadlock-hard isolation test.
Tom Lane [Fri, 12 Feb 2016 22:22:42 +0000 (17:22 -0500)]
Increase deadlock_timeout some more in the deadlock-hard isolation test.

The previous value of 5s is inadequate for the buildfarm's
CLOBBER_CACHE_ALWAYS animals: they take long enough to do the is-it-waiting
queries that the timeout expires, allowing the database state to change,
before isolationtester is done looking.  Perhaps 10s will be enough.
(If it isn't, I'm inclined to reduce the number of sessions involved.)

8 years agoRevert "isolationtester: don't repeat the is-it-waiting query when retrying a step."
Tom Lane [Fri, 12 Feb 2016 22:12:23 +0000 (17:12 -0500)]
Revert "isolationtester: don't repeat the is-it-waiting query when retrying a step."

This mostly reverts commit 9c9782f066e0ce5424b8706df2cce147cb78170f.
I left in the parts that rearranged removal of completed waiting steps;
but the idea of not rechecking a step's blocked-ness isn't working.

8 years agoRevert "Still further tweaking of deadlock isolation tests."
Tom Lane [Fri, 12 Feb 2016 22:02:59 +0000 (17:02 -0500)]
Revert "Still further tweaking of deadlock isolation tests."

This reverts commit d03130d378b5fb071d231a7822784ad87268583a.
That was dependent on an isolationtester.c change that now proves
to be broken; we will need to find another solution.

8 years agopgbench: cleanup use of a "logfile" parameter
Alvaro Herrera [Fri, 12 Feb 2016 20:30:46 +0000 (17:30 -0300)]
pgbench: cleanup use of a "logfile" parameter

There is no reason to have the per-thread logfile file pointer as a
separate parameter in various functions: it's much simpler to put it in
the per-thread state struct instead, which is already being passed to
all functions that need the log file anyway.  Change the callsites in
which it was used as a boolean to test whether logging is active, so
that they use the use_log global variable instead.

No backpatch, even though this exists since commit a887c486d5df of March
2010, because this is just for cleanliness' sake and the surrounding
code has been modified a lot recently anyway.

8 years agopgbench: fix segfault with empty sql file
Alvaro Herrera [Fri, 12 Feb 2016 20:14:45 +0000 (17:14 -0300)]
pgbench: fix segfault with empty sql file

Commit 1d0c3b3f8a introduced a bug that causes pgbench to crash if an
empty script file is specified.  Fix it by rejecting such files at
startup, which is the historical and intended behavior.

Reported-By: Jeff Janes
Discussion: https://www.postgresql.org/message-id/CAMkU=1zxKUbLPOt9hQWFp14pTc=V0cGo2GQBbn2GsK2Pu+8ZfA@mail.gmail.com

8 years agoStill further tweaking of deadlock isolation tests.
Tom Lane [Fri, 12 Feb 2016 19:19:57 +0000 (14:19 -0500)]
Still further tweaking of deadlock isolation tests.

It turns out that there is a second race condition in the new deadlock-hard
test: once the deadlock detector fires, it's uncertain whether step s7a8 or
step s8a1 will report first, because killing s8's transaction unblocks s7.
So far, s7 has only been seen to report first in CLOBBER_CACHE_ALWAYS
builds, but it's pretty reproducible there, and in theory it should
sometimes occur in normal builds too.  If s7 were a bit slower than usual,
that could also break the test, since the existing expected-file assumes
that we'll see s7a8 report the first time we check it after s8a1 completes.
To fix, add a post-lock delay to s7a8.

8 years agoisolationtester: don't repeat the is-it-waiting query when retrying a step.
Tom Lane [Fri, 12 Feb 2016 19:10:36 +0000 (14:10 -0500)]
isolationtester: don't repeat the is-it-waiting query when retrying a step.

If we're retrying a step, then we already decided it was blocked on a lock,
and there's no need to recheck that.  The original coding of commit
38f8bdcac4982215beb9f65a19debecaf22fd470 resulted in a large number of
is-it-waiting queries when dealing with multiple concurrently-blocked
sessions, which is fairly pointless and also results in test failures in
CLOBBER_CACHE_ALWAYS builds, where the is-it-waiting query is quite slow.

This definition also permits appending pg_sleep() calls to steps where it's
needed to control the order of finish of concurrent steps.  Before, that
did not work nicely because we'd decide that a step performing a sleep was
not blocked and hang up waiting for it to finish, rather than noticing the
completion of the concurrent step we're supposed to notice first.

In passing, revise handling of removal of completed waiting steps
to make it a bit less messy.