]> granicus.if.org Git - postgresql/log
postgresql
8 years agoChange the way that LWLocks for extensions are allocated.
Robert Haas [Thu, 4 Feb 2016 21:43:04 +0000 (16:43 -0500)]
Change the way that LWLocks for extensions are allocated.

The previous RequestAddinLWLocks() method had several disadvantages.
First, the locks would be in the main tranche; we've recently decided
that it's useful for LWLocks used for separate purposes to have
separate tranche IDs.  Second, there wasn't any correlation between
what code called RequestAddinLWLocks() and what code called
LWLockAssign(); when multiple modules are in use, it could become
quite difficult to troubleshoot problems where LWLockAssign() ran out
of locks.  To fix, create a concept of named LWLock tranches which
can be used either by extension or by core code.

Amit Kapila and Robert Haas

8 years agoSimplify syntax diagram for REINDEX.
Tom Lane [Thu, 4 Feb 2016 18:58:40 +0000 (13:58 -0500)]
Simplify syntax diagram for REINDEX.

Since there currently is only one possible parenthesized option, namely
VERBOSE, it's a bit pointless to show it with "{ } [, ... ]".  The curly
braces are useless and therefore confusing, as seen in a recent question
from Karsten Hilbert.  Remove the extra decoration for the time being;
we can put it back when and if REINDEX grows some more options.

8 years agoIn pg_dump, ensure that view triggers are processed after view rules.
Tom Lane [Thu, 4 Feb 2016 05:26:10 +0000 (00:26 -0500)]
In pg_dump, ensure that view triggers are processed after view rules.

If a view is split into CREATE TABLE + CREATE RULE to break a circular
dependency, then any triggers on the view must be dumped/reloaded after
the CREATE RULE; else the backend may reject the CREATE TRIGGER because
it's the wrong type of trigger for a plain table.  This works all right
in plain dump/restore because of pg_dump's sorting heuristic that places
triggers after rules.  However, when using parallel restore, the ordering
must be enforced by a dependency --- and we didn't have one.

Fixing this is a mere matter of adding an addObjectDependency() call,
except that we need to be able to find all the triggers belonging to the
view relation, and there was no easy way to do that.  Add fields to
pg_dump's TableInfo struct to remember where the associated TriggerInfo
struct(s) are.

Per bug report from Dennis Kögel.  The failure can be exhibited at least
as far back as 9.1, so back-patch to all supported branches.

8 years agoExtend sortsupport for text to more opclasses.
Robert Haas [Wed, 3 Feb 2016 19:17:35 +0000 (14:17 -0500)]
Extend sortsupport for text to more opclasses.

Have varlena.c expose an interface that allows the char(n), bytea, and
bpchar types to piggyback on a now-generalized SortSupport for text.
This pushes a little more knowledge of the bpchar/char(n) type into
varlena.c than might be preferred, but that seems like the approach
that creates least friction.  Also speed things up for index builds
that use text_pattern_ops or varchar_pattern_ops.

This patch does quite a bit of renaming, but it seems likely to be
worth it, so as to avoid future confusion about the fact that this code
is now more generally used than the old names might have suggested.

Peter Geoghegan, reviewed by Álvaro Herrera and Andreas Karlsson,
with small tweaks by me.

8 years agoAdd hstore_to_jsonb() and hstore_to_jsonb_loose() to hstore documentation.
Tom Lane [Wed, 3 Feb 2016 17:56:40 +0000 (12:56 -0500)]
Add hstore_to_jsonb() and hstore_to_jsonb_loose() to hstore documentation.

These were never documented anywhere user-visible.  Tut tut.

8 years agoAllow parallel custom and foreign scans.
Robert Haas [Wed, 3 Feb 2016 17:46:18 +0000 (12:46 -0500)]
Allow parallel custom and foreign scans.

This patch doesn't put the new infrastructure to use anywhere, and
indeed it's not clear how it could ever be used for something like
postgres_fdw which has to send an SQL query and wait for a reply,
but there might be FDWs or custom scan providers that are CPU-bound,
so let's give them a way to join club parallel.

KaiGai Kohei, reviewed by me.

8 years agodoc: Fix stand-alone INSTALL file build
Peter Eisentraut [Wed, 3 Feb 2016 17:31:33 +0000 (12:31 -0500)]
doc: Fix stand-alone INSTALL file build

Commit 7d17e683fcc28a1b371c7dd02935728cd2cbf9bf introduced an external
link.

8 years agoMake hstore_to_jsonb_loose match hstore_to_json_loose on what's a number.
Tom Lane [Wed, 3 Feb 2016 17:03:50 +0000 (12:03 -0500)]
Make hstore_to_jsonb_loose match hstore_to_json_loose on what's a number.

Commit e09996ff8dee3f70 removed some ad-hoc code in hstore_to_json_loose
that determined whether an hstore value string looked like a number,
in favor of calling the JSON parser's is-it-a-number code.  However,
it neglected the fact that the exact same code appeared in
hstore_to_jsonb_loose.

This is not a bug, exactly, because the requirements on the two functions
are not the same: hstore_to_json_loose must accept only syntactically legal
JSON numbers as numbers, or it will produce invalid JSON output, as per bug
#12070 which spawned the prior commit.  But hstore_to_jsonb_loose could
accept anything that numeric_in will eat, other than Inf and NaN.

Nonetheless it seems surprising and arbitrary that the two functions don't
use the same rules for what is a number versus what is a string; especially
since they did use the same rules before the aforesaid commit.  For one
thing, that means that doing hstore_to_json_loose and then casting to jsonb
can produce results different from doing just hstore_to_jsonb_loose.

Hence, change hstore_to_jsonb_loose's logic to match hstore_to_json_loose,
ie, hstore values are treated as numbers when they match the JSON syntax
for numbers.

No back-patch, since this is more in the nature of a definitional change
than a bug fix.

8 years agoCode review for commit dc203dc3ac40a4b02b92fb827848a547d2957153.
Robert Haas [Wed, 3 Feb 2016 16:53:46 +0000 (11:53 -0500)]
Code review for commit dc203dc3ac40a4b02b92fb827848a547d2957153.

Remove duplicate assignment.  This part by Ashutosh Bapat.

Remove now-obsolete comment.  This part by me, although the pending
join pushdown patch does something similar, and for the same reason:
there's no reason to keep two lists of the things in the fdw_private
structure that have to be kept in sync with each other.

8 years agoRemove CustomPath's TextOutCustomPath method.
Robert Haas [Wed, 3 Feb 2016 15:38:50 +0000 (10:38 -0500)]
Remove CustomPath's TextOutCustomPath method.

You can't really do anything useful with this in the form it currently
exists; among other problems, there's no way to reread whatever
information might be produced when the path is output.  Work is
underway to replace this with a more useful and more general system of
extensible nodes, but let's start by getting rid of this bit.

Extracted from a larger patch by KaiGai Kohei.

8 years agopostgres_fdw: Allow fetch_size to be set per-table or per-server.
Robert Haas [Wed, 3 Feb 2016 14:01:59 +0000 (09:01 -0500)]
postgres_fdw: Allow fetch_size to be set per-table or per-server.

The default fetch size of 100 rows might not be right in every
environment, so allow users to configure it.

Corey Huinker, reviewed by Kyotaro Horiguchi, Andres Freund, and me.

8 years agoFix IsValidJsonNumber() to notice trailing non-alphanumeric garbage.
Tom Lane [Wed, 3 Feb 2016 06:39:08 +0000 (01:39 -0500)]
Fix IsValidJsonNumber() to notice trailing non-alphanumeric garbage.

Commit e09996ff8dee3f70 was one brick shy of a load: it didn't insist
that the detected JSON number be the whole of the supplied string.
This allowed inputs such as "2016-01-01" to be misdetected as valid JSON
numbers.  Per bug #13906 from Dmitry Ryabov.

In passing, be more wary of zero-length input (I'm not sure this can
happen given current callers, but better safe than sorry), and do some
minor cosmetic cleanup.

8 years agoAdd support for systemd service notifications
Peter Eisentraut [Tue, 17 Nov 2015 11:46:17 +0000 (06:46 -0500)]
Add support for systemd service notifications

Insert sd_notify() calls at server start and stop for integration with
systemd.  This allows the use of systemd service units of type "notify",
which greatly simplifies the systemd configuration.

Reviewed-by: Pavel Stěhule <pavel.stehule@gmail.com>
8 years agoImprove error reporting when location specified by postgres -D does not exist
Peter Eisentraut [Tue, 17 Nov 2015 11:47:18 +0000 (06:47 -0500)]
Improve error reporting when location specified by postgres -D does not exist

Previously, the first error seen would be that postgresql.conf does not
exist.  But for the case where the whole directory does not exist, give
an error message about that, together with a hint for how to create one.

8 years agoRemove printQueryOpt.quote field.
Tom Lane [Tue, 2 Feb 2016 20:26:21 +0000 (15:26 -0500)]
Remove printQueryOpt.quote field.

This field was included in the original definition of the printQueryOpt
struct in commit a45195a191eec367, but it was not used anywhere in that
commit, nor since then.  Spotted by Dickson S. Guedes.

8 years agoDon't test for system columns on join relations
Alvaro Herrera [Tue, 2 Feb 2016 18:20:02 +0000 (19:20 +0100)]
Don't test for system columns on join relations

create_foreignscan_plan needs to know whether any system columns are
requested from a relation (this flag is needed by ForeignNext during
execution).  However, for join relations this is a pointless test,
because it's not possible to request system columns from them, so
remove the check.

Author: Etsuro Fujita
Discussion: http://www.postgresql.org/message-id/56AA0FC5.9000207@lab.ntt.co.jp
Reviewed-by: David Rowley, Robert Haas
8 years agoRemove unnecessary "implementation of FOO operator" DESCR() entries.
Tom Lane [Tue, 2 Feb 2016 16:52:27 +0000 (11:52 -0500)]
Remove unnecessary "implementation of FOO operator" DESCR() entries.

Apparently at least one committer hasn't gotten the word that these do not
need to be maintained by hand, since initdb will create them automatically.
Noted while fixing bug #13905.

No catversion bump since the post-initdb state is exactly the same either
way.  I don't see a need for back-patch, either.

8 years agoFix pg_description entries for jsonb_to_record() and jsonb_to_recordset().
Tom Lane [Tue, 2 Feb 2016 16:39:50 +0000 (11:39 -0500)]
Fix pg_description entries for jsonb_to_record() and jsonb_to_recordset().

All the other jsonb function descriptions refer to the arguments as being
"jsonb", but these two said "json".  Make it consistent.  Per bug #13905
from Petru Florin Mihancea.

No catversion bump --- we can't force one in the back branches, and this
isn't very critical anyway.

8 years agoFix typo in comment
Magnus Hagander [Tue, 2 Feb 2016 12:49:02 +0000 (13:49 +0100)]
Fix typo in comment

8 years agoFix lossy KNN GiST when ordering operator returns non-float8 value.
Teodor Sigaev [Tue, 2 Feb 2016 12:20:33 +0000 (15:20 +0300)]
Fix lossy KNN GiST when ordering operator returns non-float8 value.

KNN GiST with recheck flag should return to executor the same type as ordering
operator, GiST detects this type by looking to return type of function which
implements ordering operator. But occasionally detecting code works after
replacing ordering operator function to distance support function.
Distance support function always returns float8, so, detecting code get float8
instead of actual return type of ordering operator.

Built-in opclasses don't have ordering operator which doesn't return
non-float8 value, so, tests are impossible here, at least now.

Backpatch to 9.5 where lozzy KNN was introduced.

Author: Alexander Korotkov
Report by: Artur Zakirov

8 years agoMake all built-in lwlock tranche IDs fixed.
Robert Haas [Tue, 2 Feb 2016 11:42:14 +0000 (06:42 -0500)]
Make all built-in lwlock tranche IDs fixed.

This makes the values more stable, which seems like a good thing for
anybody who needs to look at at them.

Alexander Korotkov and Amit Kapila

8 years agopgbench: allow per-script statistics
Alvaro Herrera [Mon, 1 Feb 2016 14:55:33 +0000 (15:55 +0100)]
pgbench: allow per-script statistics

Provide per-script statistical info (count of transactions executed
under that script, average latency for the whole script) after a
multi-script run, adding an intermediate level of detail to existing
global stats and per-command stats.

Author: Fabien Coelho
Reviewer: Michaël Paquier, Álvaro Herrera

8 years agopgbench: Install guards against obscure overflow conditions.
Robert Haas [Mon, 1 Feb 2016 13:23:41 +0000 (08:23 -0500)]
pgbench: Install guards against obscure overflow conditions.

Dividing INT_MIN by -1 or taking INT_MIN modulo -1 can sometimes
cause floating-point exceptions or otherwise misbehave.

Fabien Coelho and Michael Paquier

8 years agoVarious fixes to "ALTER ... SET/RESET" tab completions
Fujii Masao [Mon, 1 Feb 2016 13:19:51 +0000 (22:19 +0900)]
Various fixes to "ALTER ... SET/RESET" tab completions

Add
- ALTER SYSTEM SET/RESET ... -> GUC variables
- ALTER TABLE ... SET WITH -> OIDS
- ALTER DATABASE/FUNCTION/ROLE/USER ... SET/RESET -> GUC variables
- ALTER DATABASE/FUNCTION/ROLE/USER ... SET ... -> FROM CURRENT/TO
- ALTER DATABASE/FUNCTION/ROLE/USER ... SET ... TO/= -> possible values

Author: Fujii Masao
Reviewed-by: Michael Paquier, Masahiko Sawada
8 years agoMake sure ecpg header files do not have a comment lasting several lines, one of
Michael Meskes [Mon, 1 Feb 2016 12:10:40 +0000 (13:10 +0100)]
Make sure ecpg header files do not have a comment lasting several lines, one of
which is a preprocessor directive. This leads ecpg to incorrectly parse the comment as nested.

8 years agoFix typos in comments
Magnus Hagander [Mon, 1 Feb 2016 10:43:48 +0000 (11:43 +0100)]
Fix typos in comments

Author: Michael Paquier

8 years agoFix misspelled function name in comment.
Heikki Linnakangas [Mon, 1 Feb 2016 08:10:24 +0000 (10:10 +0200)]
Fix misspelled function name in comment.

8 years agoFix error in documentated use of mingw-w64 compilers
Andrew Dunstan [Sun, 31 Jan 2016 00:28:44 +0000 (19:28 -0500)]
Fix error in documentated use of mingw-w64 compilers

Error reported by Igal Sapir.

8 years agoFix whitespace
Peter Eisentraut [Sat, 30 Jan 2016 20:58:20 +0000 (15:58 -0500)]
Fix whitespace

8 years agopostgres_fdw: More preliminary refactoring for upcoming join pushdown.
Robert Haas [Sat, 30 Jan 2016 15:32:38 +0000 (10:32 -0500)]
postgres_fdw: More preliminary refactoring for upcoming join pushdown.

The code that generates a complete SQL query for a given foreign relation
was repeated in two places, and they didn't quite agree: the EXPLAIN case
left out the locking clause.  Centralize the code so we get the same
behavior everywhere, and adjust calling conventions and which functions
are static vs. extern accordingly .  Centralize the code so we get the same
behavior everywhere, and adjust calling conventions and which functions
are static vs. extern accordingly.

Ashutosh Bapat, reviewed and slightly adjusted by me.

8 years agoMigrate replication slot I/O locks into a separate tranche.
Robert Haas [Fri, 29 Jan 2016 14:44:29 +0000 (09:44 -0500)]
Migrate replication slot I/O locks into a separate tranche.

This is following in a long train of similar changes and for the same
reasons - see b319356f0e94a6482c726cf4af96597c211d8d6e and
fe702a7b3f9f2bc5bf6d173166d7d55226af82c8 inter alia.

Author: Amit Kapila
Reviewed-by: Alexander Korotkov, Robert Haas
8 years agoMigrate PGPROC's backendLock into PGPROC itself, using a new tranche.
Robert Haas [Fri, 29 Jan 2016 13:10:47 +0000 (08:10 -0500)]
Migrate PGPROC's backendLock into PGPROC itself, using a new tranche.

Previously, each PGPROC's backendLock was part of the main tranche,
and the PGPROC just contained a pointer.  Now, the actual LWLock is
part of the PGPROC.

As with previous, similar patches, this makes it significantly easier
to identify these lwlocks in LWLOCK_STATS or Trace_lwlocks output
and improves modularity.

Author: Ildus Kurbangaliev
Reviewed-by: Amit Kapila, Robert Haas
8 years agopgbench: refactor handling of stats tracking
Alvaro Herrera [Fri, 29 Jan 2016 12:05:08 +0000 (13:05 +0100)]
pgbench: refactor handling of stats tracking

This doesn't add any functionality but just shuffles things around so
that it can be reused and improved later.

Author: Fabien Coelho
Reviewed-by: Michael Paquier, Álvaro Herrera
8 years agoFix incorrect pattern-match processing in psql's \det command.
Tom Lane [Fri, 29 Jan 2016 09:28:02 +0000 (10:28 +0100)]
Fix incorrect pattern-match processing in psql's \det command.

listForeignTables' invocation of processSQLNamePattern did not match up
with the other ones that handle potentially-schema-qualified names; it
failed to make use of pg_table_is_visible() and also passed the name
arguments in the wrong order.  Bug seems to have been aboriginal in commit
0d692a0dc9f0e532.  It accidentally sort of worked as long as you didn't
inquire too closely into the behavior, although the silliness was later
exposed by inconsistencies in the test queries added by 59efda3e50ca4de6
(which I probably should have questioned at the time, but didn't).

Per bug #13899 from Reece Hart.  Patch by Reece Hart and Tom Lane.
Back-patch to all affected branches.

8 years agoFix syntax descriptions for replication commands in logicaldecoding.sgml
Fujii Masao [Fri, 29 Jan 2016 03:14:56 +0000 (12:14 +0900)]
Fix syntax descriptions for replication commands in logicaldecoding.sgml

Patch-by: Oleksandr Shulgin
Reviewed-by: Craig Ringer and Fujii Masao
Backpatch-through: 9.4 where logical decoding was introduced

8 years agopostgres_fdw: Refactor deparsing code for locking clauses.
Robert Haas [Thu, 28 Jan 2016 21:44:01 +0000 (16:44 -0500)]
postgres_fdw: Refactor deparsing code for locking clauses.

The upcoming patch to allow join pushdown in postgres_fdw needs to use
this code multiple times, which requires moving it to deparse.c.  That
seems like a good idea anyway, so do that now both on general principle
and to simplify the future patch.

Inspired by a patch by Shigeru Hanada and Ashutosh Bapat, but I did
it a little differently than what that patch did.

8 years agoOnly try to push down foreign joins if the user mapping OIDs match.
Robert Haas [Thu, 28 Jan 2016 19:05:36 +0000 (14:05 -0500)]
Only try to push down foreign joins if the user mapping OIDs match.

Previously, the foreign join pushdown infrastructure left the question
of security entirely up to individual FDWs, but it would be easy for
a foreign data wrapper to inadvertently open up subtle security holes
that way.  So, make it the core code's job to determine which user
mapping OID is relevant, and don't attempt join pushdown unless it's
the same for all relevant relations.

Per a suggestion from Tom Lane.  Shigeru Hanada and Ashutosh Bapat,
reviewed by Etsuro Fujita and KaiGai Kohei, with some further
changes by me.

8 years agoAdd missing quotation mark.
Robert Haas [Thu, 28 Jan 2016 17:21:51 +0000 (12:21 -0500)]
Add missing quotation mark.

This fix accidentally got left out of the previous commit.

8 years agoAvoid multiple foreign server connections when all use same user mapping.
Robert Haas [Thu, 28 Jan 2016 17:05:19 +0000 (12:05 -0500)]
Avoid multiple foreign server connections when all use same user mapping.

Previously, postgres_fdw's connection cache was keyed by user OID and
server OID, but this can lead to multiple connections when it's not
really necessary.  In particular, if all relevant users are mapped to
the public user mapping, then their connection options are certainly
the same, so one connection can be used for all of them.

While we're cleaning things up here, drop the "server" argument to
GetConnection(), which isn't really needed.  This saves a few cycles
because callers no longer have to look this up; the function itself
does, but only when establishing a new connection, not when reusing
an existing one.

Ashutosh Bapat, with a few small changes by me.

8 years agoAdd [NO]BYPASSRLS options to CREATE USER and ALTER USER docs.
Robert Haas [Thu, 28 Jan 2016 14:29:04 +0000 (09:29 -0500)]
Add [NO]BYPASSRLS options to CREATE USER and ALTER USER docs.

Patch-by: Filip Rembiałkowski
Reviewed-by: Robert Haas
Backpatch-through: 9.5

8 years agoFix spi_worker mention in bgworker documentation
Alvaro Herrera [Thu, 28 Jan 2016 13:08:21 +0000 (14:08 +0100)]
Fix spi_worker mention in bgworker documentation

The documentation mentioned contrib/ but the module was moved to
src/test/modules/ by commit 22dfd116a127a of 9.5 era.

Problem pointed out by Dickson Guedes in bug #13896
Backpatch-to: 9.5.
8 years agoFix typos in comments and doc
Fujii Masao [Thu, 28 Jan 2016 07:47:36 +0000 (16:47 +0900)]
Fix typos in comments and doc

overriden -> overridden

The misspelling in create_extension.sgml was introduced in b67aaf2,
so no need to backpatch.

8 years agoAdd gin_clean_pending_list function to clean up GIN pending list
Fujii Masao [Thu, 28 Jan 2016 03:57:52 +0000 (12:57 +0900)]
Add gin_clean_pending_list function to clean up GIN pending list

This function cleans up the pending list of the GIN index by
moving entries in it to the main GIN data structure in bulk.
It returns the number of pages cleaned up from the pending list.

This function is useful, for example, when the pending list
needs to be cleaned up *quickly* to improve the performance of
the search using GIN index. VACUUM can do the same thing, too,
but it may take days to run on a large table.

Jeff Janes,
reviewed by Julien Rouhaud, Jaime Casanova, Alvaro Herrera and me.

Discussion: CAMkU=1x8zFkpfnozXyt40zmR3Ub_kHu58LtRmwHUKRgQss7=iQ@mail.gmail.com

8 years agoAssert that create_unique_path returns non-NULL.
Robert Haas [Thu, 28 Jan 2016 03:03:18 +0000 (22:03 -0500)]
Assert that create_unique_path returns non-NULL.

Per off-list discussion with Tom Lane and Michael Paquier, Coverity
gets unhappy if this is not done.

8 years agoFix cross-version pg_dump for aggregate combine functions.
Robert Haas [Thu, 28 Jan 2016 02:45:07 +0000 (21:45 -0500)]
Fix cross-version pg_dump for aggregate combine functions.

Fixes a defect in commit a7de3dc5c346e07e0439275982569996e645b3c2.

David Rowley, per report from Jeff Janes, who also checked that the
fix works.

8 years agoFix volatility marking of pg_size_pretty function
Fujii Masao [Wed, 27 Jan 2016 02:13:31 +0000 (11:13 +0900)]
Fix volatility marking of pg_size_pretty function

pg_size_pretty function should be marked immutable rather than volatile
because it always returns the same result given the same argument.

Pavel Stehule

8 years agopgbench: improve multi-script support
Alvaro Herrera [Wed, 27 Jan 2016 01:54:22 +0000 (02:54 +0100)]
pgbench: improve multi-script support

Previously, it was possible to specify one or several custom scripts to
run, or only one of the builtin scripts.  With this patch it is also
possible to specify to run the builtin scripts multiple times, using the
new -b option.  Also, unify the code for both cases; this eases future
pgbench improvements.

Author: Fabien Coelho
Review: Michaël Paquier, Álvaro Herrera

8 years agoMostly mechanical cleanup of pgbench
Alvaro Herrera [Wed, 27 Jan 2016 01:11:34 +0000 (02:11 +0100)]
Mostly mechanical cleanup of pgbench

pgindent for recent commits; also change some variables from int to
boolean, which is how they are really used.

Mostly submitted by Fabien Coelho; this is in preparation to commit
further patches to the file.

8 years agoFix startup so that log prefix %h works for the log_connections message.
Tom Lane [Tue, 26 Jan 2016 20:38:33 +0000 (15:38 -0500)]
Fix startup so that log prefix %h works for the log_connections message.

We entirely randomly chose to initialize port->remote_host just after
printing the log_connections message, when we could perfectly well do it
just before, allowing %h and %r to work for that message.  Per gripe from
Artem Tomyuk.

8 years agoImprove ResourceOwners' behavior for large numbers of owned objects.
Tom Lane [Tue, 26 Jan 2016 20:20:22 +0000 (15:20 -0500)]
Improve ResourceOwners' behavior for large numbers of owned objects.

The original coding was quite fast so long as objects were always
released in reverse order of addition; otherwise, it degenerated into
O(N^2) behavior due to searching for the array element to delete.
Improve matters by switching to hashed storage when the number of
objects of a given type exceeds 64.  (The cutover point is open to
discussion, of course, but some simple performance testing suggests
that hashing has enough overhead to be a loser below there.)

Also, refactor resowner.c so that we don't need N copies of the array
management code.  Since all the resource IDs the code currently needs
to deal with are either pointers or integers, it seems sufficient to
create a one-size-fits-all infrastructure in which everything is
converted to a Datum for storage.

Aleksander Alekseev, reviewed by Stas Kelvich, further fixes by me

8 years agoVarious fixes to REFRESH MATERIALIZED VIEW tab completion.
Kevin Grittner [Tue, 26 Jan 2016 14:45:08 +0000 (08:45 -0600)]
Various fixes to REFRESH MATERIALIZED VIEW tab completion.

Masahiko Sawada, Fujii Masao, Kevin Grittner

8 years agoRevert "Fix broken multibyte regression tests."
Tatsuo Ishii [Mon, 25 Jan 2016 23:29:15 +0000 (08:29 +0900)]
Revert "Fix broken multibyte regression tests."

This reverts commit efc1610b64b04e7cf08cc1d6c608ede8b7d5ff07.
The commit was plain wrong as pointed out in:
http://www.postgresql.org/message-id/27771.1448736909@sss.pgh.pa.us

8 years agoCorrect comment in GetConflictingVirtualXIDs()
Simon Riggs [Sun, 24 Jan 2016 18:22:11 +0000 (10:22 -0800)]
Correct comment in GetConflictingVirtualXIDs()

We use Share lock because it is safe to do so.

8 years agoYet further adjust degree-based trig functions for more portability.
Tom Lane [Sun, 24 Jan 2016 17:53:03 +0000 (12:53 -0500)]
Yet further adjust degree-based trig functions for more portability.

Buildfarm member cockatiel is still saying that cosd(60) isn't 0.5.
What seems likely is that the subexpression (1.0 - cos(x)) isn't being
rounded to double width before more arithmetic is done on it, so force
that by storing it into a variable.

8 years agoStill further adjust degree-based trig functions for more portability.
Tom Lane [Sat, 23 Jan 2016 23:12:54 +0000 (18:12 -0500)]
Still further adjust degree-based trig functions for more portability.

Indeed, the non-static declaration foreseen in my previous commit message
is necessary.  Per Noah Misch.

8 years agoFurther adjust degree-based trig functions for more portability.
Tom Lane [Sat, 23 Jan 2016 21:17:31 +0000 (16:17 -0500)]
Further adjust degree-based trig functions for more portability.

The last round didn't do it.  Per Noah Misch, the problem on at least
some machines is that the compiler pre-evaluates trig functions having
constant arguments using code slightly different from what will be used
at runtime.  Therefore, we must prevent the compiler from seeing constant
arguments to any of the libm trig functions used in this code.

The method used here might still fail if init_degree_constants() gets
inlined into the call sites.  That probably won't happen given the large
number of call sites; but if it does, we could probably fix it by making
init_degree_constants() non-static.  I'll avoid that till proven
necessary, though.

8 years agoAdjust degree-based trig functions for more portability.
Tom Lane [Sat, 23 Jan 2016 16:26:07 +0000 (11:26 -0500)]
Adjust degree-based trig functions for more portability.

The buildfarm isn't very happy with the results of commit e1bd684a34c11139.
To try to get the expected exact results everywhere:

* Replace M_PI / 180 subexpressions with a precomputed constant, so that
the compiler can't decide to rearrange that division with an adjacent
operation.  Hopefully this will fix failures to get exactly 0.5 from
sind(30) and cosd(60).

* Add scaling to ensure that tand(45) and cotd(45) give exactly 1; there
was nothing particularly guaranteeing that before.

* Replace minus zero by zero when tand() or cotd() would output that;
many machines did so for tand(180) and cotd(270), but not all.  We could
alternatively deem both results valid, but that doesn't seem likely to
be what users will want.

8 years agopsql: Improve completion of FDW DDL commands
Peter Eisentraut [Sat, 23 Jan 2016 11:57:42 +0000 (06:57 -0500)]
psql: Improve completion of FDW DDL commands

Add
- ALTER FOREIGN DATA WRAPPER -> RENAME TO
- ALTER SERVER -> RENAME TO
- ALTER SERVER ... VERSION ... -> OPTIONS
- CREATE FOREIGN DATA WRAPPER -> OPTIONS
- CREATE SERVER -> OPTIONS
- CREATE|ALTER USER MAPPING -> OPTIONS

From: Andreas Karlsson <andreas@proxel.se>

8 years agopg_dump: Fix quoting of domain constraint names
Alvaro Herrera [Fri, 22 Jan 2016 23:04:35 +0000 (20:04 -0300)]
pg_dump: Fix quoting of domain constraint names

The original code was adding double quotes to an already-quoted
identifier, leading to nonsensical results.  Remove the quoting call.

I introduced the broken code in 7eca575d1c of 9.5 era, so backpatch to
9.5.

Report and patch by Elvis Pranskevichus
Reviewed by Michael Paquier

8 years agoAdd trigonometric functions that work in degrees.
Tom Lane [Fri, 22 Jan 2016 20:46:22 +0000 (15:46 -0500)]
Add trigonometric functions that work in degrees.

The implementations go to some lengths to deliver exact results for values
where an exact result can be expected, such as sind(30) = 0.5 exactly.

Dean Rasheed, reviewed by Michael Paquier

8 years agoImprove cross-platform consistency of Inf/NaN handling in trig functions.
Tom Lane [Fri, 22 Jan 2016 19:50:51 +0000 (14:50 -0500)]
Improve cross-platform consistency of Inf/NaN handling in trig functions.

Ensure that the trig functions return NaN for NaN input regardless of what
the underlying C library functions might do.  Also ensure that an error
is thrown for Inf (or otherwise out-of-range) input, except for atan/atan2
which should accept it.

All these behaviors should now conform to the POSIX spec; previously, all
our popular platforms deviated from that in one case or another.

The main remaining platform dependency here is whether the C library might
choose to throw a domain error for sin/cos/tan inputs that are large but
less than infinity.  (Doing so is not unreasonable, since once a single
unit-in-the-last-place exceeds PI, there can be no significance at all in
the result; however there doesn't seem to be any suggestion in POSIX that
such an error is allowed.)  We will report such errors if they are reported
via "errno", but not if they are reported via "fetestexcept" which is the
other mechanism sanctioned by POSIX.  Some preliminary experiments with
fetestexcept indicated that it might also report errors we could do
without, such as complaining about underflow at an unreasonably large
threshold.  So let's skip that complexity for now.

Dean Rasheed, reviewed by Michael Paquier

8 years agoImprove levenshtein() docs.
Tom Lane [Fri, 22 Jan 2016 17:29:07 +0000 (12:29 -0500)]
Improve levenshtein() docs.

Fix chars-vs-bytes confusion here too.  Improve poor grammar and
markup.

8 years agoRemove new coupling between NAMEDATALEN and MAX_LEVENSHTEIN_STRLEN.
Tom Lane [Fri, 22 Jan 2016 16:53:06 +0000 (11:53 -0500)]
Remove new coupling between NAMEDATALEN and MAX_LEVENSHTEIN_STRLEN.

Commit e529cd4ffa605c6f introduced an Assert requiring NAMEDATALEN to be
less than MAX_LEVENSHTEIN_STRLEN, which has been 255 for a long time.
Since up to that instant we had always allowed NAMEDATALEN to be
substantially more than that, this was ill-advised.

It's debatable whether we need MAX_LEVENSHTEIN_STRLEN at all (versus
putting a CHECK_FOR_INTERRUPTS into the loop), or whether it has to be
so tight; but this patch takes the narrower approach of just not applying
the MAX_LEVENSHTEIN_STRLEN limit to calls from the parser.

Trusting the parser for this seems reasonable, first because the strings
are limited to NAMEDATALEN which is unlikely to be hugely more than 256,
and second because the maximum distance is tightly constrained by
MAX_FUZZY_DISTANCE (though we'd forgotten to make use of that limit in one
place).  That means the cost is not really O(mn) but more like O(max(m,n)).

Relaxing the limit for user-supplied calls is left for future research;
given the lack of complaints to date, it doesn't seem very high priority.

In passing, fix confusion between lengths-in-bytes and lengths-in-chars
in comments and error messages.

Per gripe from Kevin Day; solution suggested by Robert Haas.  Back-patch
to 9.5 where the unwanted restriction was introduced.

8 years agoMake extract() do something more reasonable with infinite datetimes.
Tom Lane [Fri, 22 Jan 2016 03:26:20 +0000 (22:26 -0500)]
Make extract() do something more reasonable with infinite datetimes.

Historically, extract() just returned zero for any case involving an
infinite timestamp[tz] input; even cases in which the unit name was
invalid.  This is not very sensible.  Instead, return infinity or
-infinity as appropriate when the requested field is one that is
monotonically increasing (e.g, year, epoch), or NULL when it is not
(e.g., day, hour).  Also, throw the expected errors for bad unit names.

BACKWARDS INCOMPATIBLE CHANGE

Vitaly Burovoy, reviewed by Vik Fearing

8 years agoSuppress compiler warning.
Tom Lane [Fri, 22 Jan 2016 02:14:07 +0000 (21:14 -0500)]
Suppress compiler warning.

Given the limited range of i, these shifts should not cause any
problem, but that apparently doesn't stop some compilers from
whining about them.

David Rowley

8 years agoImprove index AMs' opclass validation procedures.
Tom Lane [Fri, 22 Jan 2016 00:47:15 +0000 (19:47 -0500)]
Improve index AMs' opclass validation procedures.

The amvalidate functions added in commit 65c5fcd353a859da were on the
crude side.  Improve them in a few ways:

* Perform signature checking for operators and support functions.

* Apply more thorough checks for missing operators and functions,
where possible.

* Instead of reporting problems as ERRORs, report most problems as INFO
messages and make the amvalidate function return FALSE.  This allows
more than one problem to be discovered per run.

* Report object names rather than OIDs, and work a bit harder on making
the messages understandable.

Also, remove a few more opr_sanity regression test queries that are
now superseded by the amvalidate checks.

8 years agoAdd defenses against putting expanded objects into Const nodes.
Tom Lane [Thu, 21 Jan 2016 17:55:59 +0000 (12:55 -0500)]
Add defenses against putting expanded objects into Const nodes.

Putting a reference to an expanded-format value into a Const node would be
a bad idea for a couple of reasons.  It'd be possible for the supposedly
immutable Const to change value, if something modified the referenced
variable ... in fact, if the Const's reference were R/W, any function that
has the Const as argument might itself change it at runtime.  Also, because
datumIsEqual() is pretty simplistic, the Const might fail to compare equal
to other Consts that it should compare equal to, notably including copies
of itself.  This could lead to unexpected planner behavior, such as "could
not find pathkey item to sort" errors or inferior plans.

I have not been able to find any way to get an expanded value into a Const
within the existing core code; but Paul Ramsey was able to trigger the
problem by writing a datatype input function that returns an expanded
value.

The best fix seems to be to establish a rule that varlena values being
placed into Const nodes should be passed through pg_detoast_datum().
That will do nothing (and cost little) in normal cases, but it will flatten
expanded values and thereby avoid the above problems.  Also, it will
convert short-header or compressed values into canonical format, which will
avoid possible unexpected lack-of-equality issues for those cases too.
And it provides a last-ditch defense against putting a toasted value into
a Const, which we already knew was dangerous, cf commit 2b0c86b66563cf2f.
(In the light of this discussion, I'm no longer sure that that commit
provided 100% protection against such cases, but this fix should do it.)

The test added in commit 65c3d05e18e7c530 to catch datatype input functions
with unstable results would fail for functions that returned expanded
values; but it seems a bit uncharitable to deem a result unstable just
because it's expressed in expanded form, so revise the coding so that we
check for bitwise equality only after applying pg_detoast_datum().  That's
a sufficient condition anyway given the new rule about detoasting when
forming a Const.

Back-patch to 9.5 where the expanded-object facility was added.  It's
possible that this should go back further; but in the absence of clear
evidence that there's any live bug in older branches, I'll refrain for now.

8 years agoRemove unused argument from ginInsertCleanup()
Fujii Masao [Thu, 21 Jan 2016 16:22:56 +0000 (01:22 +0900)]
Remove unused argument from ginInsertCleanup()

It's an oversight in commit dc943ad.

8 years agoRefactor headers to split out standby defs
Simon Riggs [Thu, 21 Jan 2016 02:51:34 +0000 (18:51 -0800)]
Refactor headers to split out standby defs

Jeff Janes

8 years agoSpeedup 2PC by skipping two phase state files in normal path
Simon Riggs [Thu, 21 Jan 2016 02:40:44 +0000 (18:40 -0800)]
Speedup 2PC by skipping two phase state files in normal path

2PC state info is written only to WAL at PREPARE, then read back from WAL at
COMMIT PREPARED/ABORT PREPARED. Prepared transactions that live past one bufmgr
checkpoint cycle will be written to disk in the same form as previously. Crash
recovery path is not altered. Measured performance gains of 50-100% for short
2PC transactions by completely avoiding writing files and fsyncing. Other
optimizations still available, further patches in related areas expected.

Stas Kelvich and heavily edited by Simon Riggs

Based upon earlier ideas and patches by Michael Paquier and Heikki Linnakangas,
a concrete example of how Postgres-XC has fed back ideas into PostgreSQL.

Reviewed by Michael Paquier, Jeff Janes and Andres Freund
Performance testing by Jesper Pedersen

8 years agopsql: Add tab completion for COPY with query
Peter Eisentraut [Thu, 21 Jan 2016 02:27:46 +0000 (21:27 -0500)]
psql: Add tab completion for COPY with query

From: Andreas Karlsson <andreas@proxel.se>

8 years agoRefactor to create generic WAL page read callback
Simon Riggs [Thu, 21 Jan 2016 01:18:58 +0000 (17:18 -0800)]
Refactor to create generic WAL page read callback

Previously we didn’t have a generic WAL page read callback function,
surprisingly. Logical decoding has logical_read_local_xlog_page(), which was
actually generic, so move that to xlogfunc.c and rename to
read_local_xlog_page().
Maintain logical_read_local_xlog_page() so existing callers still work.

As requested by Michael Paquier, Alvaro Herrera and Andres Freund

8 years agoSupport parallel joins, and make related improvements.
Robert Haas [Wed, 20 Jan 2016 19:29:22 +0000 (14:29 -0500)]
Support parallel joins, and make related improvements.

The core innovation of this patch is the introduction of the concept
of a partial path; that is, a path which if executed in parallel will
generate a subset of the output rows in each process.  Gathering a
partial path produces an ordinary (complete) path.  This allows us to
generate paths for parallel joins by joining a partial path for one
side (which at the baserel level is currently always a Partial Seq
Scan) to an ordinary path on the other side.  This is subject to
various restrictions at present, especially that this strategy seems
unlikely to be sensible for merge joins, so only nested loops and
hash joins paths are generated.

This also allows an Append node to be pushed below a Gather node in
the case of a partitioned table.

Testing revealed that early versions of this patch made poor decisions
in some cases, which turned out to be caused by the fact that the
original cost model for Parallel Seq Scan wasn't very good.  So this
patch tries to make some modest improvements in that area.

There is much more to be done in the area of generating good parallel
plans in all cases, but this seems like a useful step forward.

Patch by me, reviewed by Dilip Kumar and Amit Kapila.

8 years agoSupport multi-stage aggregation.
Robert Haas [Wed, 20 Jan 2016 18:46:50 +0000 (13:46 -0500)]
Support multi-stage aggregation.

Aggregate nodes now have two new modes: a "partial" mode where they
output the unfinalized transition state, and a "finalize" mode where
they accept unfinalized transition states rather than individual
values as input.

These new modes are not used anywhere yet, but they will be necessary
for parallel aggregation.  The infrastructure also figures to be
useful for cases where we want to aggregate local data and remote
data via the FDW interface, and want to bring back partial aggregates
from the remote side that can then be combined with locally generated
partial aggregates to produce the final value.  It may also be useful
even when neither FDWs nor parallelism are in play, as explained in
the comments in nodeAgg.c.

David Rowley and Simon Riggs, reviewed by KaiGai Kohei, Heikki
Linnakangas, Haribabu Kommi, and me.

8 years agoPostgresNode: Add names to nodes
Alvaro Herrera [Wed, 20 Jan 2016 17:13:11 +0000 (14:13 -0300)]
PostgresNode: Add names to nodes

This makes the log files easier to follow when investigating a test
failure.

Author: Michael Paquier
Review: Noah Misch

8 years agoProperly install dynloader.h on MSVC builds
Bruce Momjian [Wed, 20 Jan 2016 04:30:29 +0000 (23:30 -0500)]
Properly install dynloader.h on MSVC builds

This will enable PL/Java to be cleanly compiled, as dynloader.h is a
requirement.

Report by Chapman Flack

Patch by Michael Paquier

Backpatch through 9.1

8 years agoFix assorted inconsistencies in GIN opclass support function declarations.
Tom Lane [Wed, 20 Jan 2016 03:32:19 +0000 (22:32 -0500)]
Fix assorted inconsistencies in GIN opclass support function declarations.

GIN had some minor issues too, mostly using "internal" where something
else would be more appropriate.  I went with the same approach as in
9ff60273e35cad6e, namely preferring the opclass' indexed datatype for
arguments that receive an operator RHS value, even if that's not
necessarily what they really are.

Again, this is with an eye to having a uniform rule for ginvalidate()
to check support function signatures.

8 years agoAdd two HyperLogLog functions
Alvaro Herrera [Tue, 19 Jan 2016 20:40:15 +0000 (17:40 -0300)]
Add two HyperLogLog functions

New functions initHyperLogLogError() and freeHyperLogLog() simplify
using this module from elsewhere.

Author: Tomáš Vondra
Review: Peter Geoghegan

8 years agoFix assorted inconsistencies in GiST opclass support function declarations.
Tom Lane [Tue, 19 Jan 2016 17:04:32 +0000 (12:04 -0500)]
Fix assorted inconsistencies in GiST opclass support function declarations.

The conventions specified by the GiST SGML documentation were widely
ignored.  For example, the strategy-number argument for "consistent" and
"distance" functions is specified to be a smallint, but most of the
built-in support functions declared it as an integer, and for that matter
the core code passed it using Int32GetDatum not Int16GetDatum.  None of
that makes any real difference at runtime, but it's quite confusing for
newcomers to the code, and it makes it very hard to write an amvalidate()
function that checks support function signatures.  So let's try to instill
some consistency here.

Another similar issue is that the "query" argument is not of a single
well-defined type, but could have different types depending on the strategy
(corresponding to search operators with different righthand-side argument
types).  Some of the functions threw up their hands and declared the query
argument as being of "internal" type, which surely isn't right ("any" would
have been more appropriate); but the majority position seemed to be to
declare it as being of the indexed data type, corresponding to a search
operator with both input types the same.  So I've specified a convention
that that's what to do always.

Also, the result of the "union" support function actually must be of the
index's storage type, but the documentation suggested declaring it to
return "internal", and some of the functions followed that.  Standardize
on telling the truth, instead.

Similarly, standardize on declaring the "same" function's inputs as
being of the storage type, not "internal".

Also, somebody had forgotten to add the "recheck" argument to both
the documentation of the "distance" support function and all of their
SQL declarations, even though the C code was happily using that argument.
Clean that up too.

Fix up some other omissions in the docs too, such as documenting that
union's second input argument is vestigial.

So far as the errors in core function declarations go, we can just fix
pg_proc.h and bump catversion.  Adjusting the erroneous declarations in
contrib modules is more debatable: in principle any change in those
scripts should involve an extension version bump, which is a pain.
However, since these changes are purely cosmetic and make no functional
difference, I think we can get away without doing that.

8 years agoRemove Cygwin-specific code from pg_ctl
Andrew Dunstan [Tue, 19 Jan 2016 12:31:18 +0000 (07:31 -0500)]
Remove Cygwin-specific code from pg_ctl

This code has been there for a long time, but it's never really been
needed. Cygwin has its own utility for registering, unregistering,
stopping and starting Windows services, and that's what's used in the
Cygwin postgres packages. So now pg_ctl for Cygwin looks like it is for
any Unix platform.

Michael Paquier and me

8 years agoFix typo.
Tatsuo Ishii [Mon, 18 Jan 2016 12:26:30 +0000 (21:26 +0900)]
Fix typo.

Reported by KOIZUMI Satoru.

8 years agoAdd explicit cast to amcostestimate call.
Tom Lane [Mon, 18 Jan 2016 03:56:16 +0000 (22:56 -0500)]
Add explicit cast to amcostestimate call.

My compiler doesn't complain here, but David Rowley's does ...

8 years agoRestructure index access method API to hide most of it at the C level.
Tom Lane [Mon, 18 Jan 2016 00:36:59 +0000 (19:36 -0500)]
Restructure index access method API to hide most of it at the C level.

This patch reduces pg_am to just two columns, a name and a handler
function.  All the data formerly obtained from pg_am is now provided
in a C struct returned by the handler function.  This is similar to
the designs we've adopted for FDWs and tablesample methods.  There
are multiple advantages.  For one, the index AM's support functions
are now simple C functions, making them faster to call and much less
error-prone, since the C compiler can now check function signatures.
For another, this will make it far more practical to define index access
methods in installable extensions.

A disadvantage is that SQL-level code can no longer see attributes
of index AMs; in particular, some of the crosschecks in the opr_sanity
regression test are no longer possible from SQL.  We've addressed that
by adding a facility for the index AM to perform such checks instead.
(Much more could be done in that line, but for now we're content if the
amvalidate functions more or less replace what opr_sanity used to do.)
We might also want to expose some sort of reporting functionality, but
this patch doesn't do that.

Alexander Korotkov, reviewed by Petr Jelínek, and rather heavily
editorialized on by me.

8 years agoRe-pgindent a few files.
Tom Lane [Mon, 18 Jan 2016 00:13:18 +0000 (19:13 -0500)]
Re-pgindent a few files.

In preparation for landing index AM interface changes.

8 years agoRemove dead code in pg_dump.
Tom Lane [Sun, 17 Jan 2016 16:38:40 +0000 (11:38 -0500)]
Remove dead code in pg_dump.

Coverity quite reasonably complained that this check for fout==NULL
occurred after we'd already dereferenced fout.  However, the check
is just dead code since there is no code path by which CreateArchive
can return a null pointer.  Errors such as can't-open-that-file are
reported down inside CreateArchive, and control doesn't return.
So let's silence the warning by removing the dead code, rather than
continuing to pretend it does something.

Coverity didn't complain about this before 5b5fea2a1, so back-patch
to 9.5 like that patch.

8 years agopsql: Add completion support for DROP INDEX CONCURRENTLY
Peter Eisentraut [Sun, 17 Jan 2016 01:46:14 +0000 (20:46 -0500)]
psql: Add completion support for DROP INDEX CONCURRENTLY

based on patch by Kyotaro Horiguchi

8 years agoFix minor typo in comment
Magnus Hagander [Fri, 15 Jan 2016 09:24:37 +0000 (10:24 +0100)]
Fix minor typo in comment

Tatsuro Yamada

8 years agoFix spelling mistakes.
Robert Haas [Fri, 15 Jan 2016 04:12:05 +0000 (23:12 -0500)]
Fix spelling mistakes.

Same patch submitted independently by David Rowley and Peter Geoghegan.

8 years agoFix build_grouping_chain() to not clobber its input lists.
Tom Lane [Thu, 14 Jan 2016 16:51:57 +0000 (11:51 -0500)]
Fix build_grouping_chain() to not clobber its input lists.

There's no good reason for stomping on the input data; it makes the logic
in this function no simpler, in fact probably the reverse.  And it makes
it impossible to separate path generation from plan generation, as I'm
working towards doing; that will require more than one traversal of these
lists.

8 years agoProperly close token in sspi authentication
Magnus Hagander [Thu, 14 Jan 2016 12:06:03 +0000 (13:06 +0100)]
Properly close token in sspi authentication

We can never leak more than one token, but we shouldn't do that. We
don't bother closing it in the error paths since the process will
exit shortly anyway.

Christian Ullrich

8 years agoHandle extension members when first setting object dump flags in pg_dump.
Tom Lane [Wed, 13 Jan 2016 23:55:27 +0000 (18:55 -0500)]
Handle extension members when first setting object dump flags in pg_dump.

pg_dump's original approach to handling extension member objects was to
run around and clear (or set) their dump flags rather late in its data
collection process.  Unfortunately, quite a lot of code expects those flags
to be valid before that; which was an entirely reasonable expectation
before we added extensions.  In particular, this explains Karsten Hilbert's
recent report of pg_upgrade failing on a database in which an extension
has been installed into the pg_catalog schema.  Its objects are initially
marked as not-to-be-dumped on the strength of their schema, and later we
change them to must-dump because we're doing a binary upgrade of their
extension; but we've already skipped essential tasks like making associated
DO_SHELL_TYPE objects.

To fix, collect extension membership data first, and incorporate it in the
initial setting of the dump flags, so that those are once again correct
from the get-go.  This has the undesirable side effect of slightly
lengthening the time taken before pg_dump acquires table locks, but testing
suggests that the increase in that window is not very much.

Along the way, get rid of ugly special-case logic for deciding whether
to dump procedural languages, FDWs, and foreign servers; dump decisions
for those are now correct up-front, too.

In 9.3 and up, this also fixes erroneous logic about when to dump event
triggers (basically, they were *always* dumped before).  In 9.5 and up,
transform objects had that problem too.

Since this problem came in with extensions, back-patch to all supported
versions.

8 years agoAccess pg_dump's options structs through Archive struct, not directly.
Tom Lane [Wed, 13 Jan 2016 22:48:33 +0000 (17:48 -0500)]
Access pg_dump's options structs through Archive struct, not directly.

Rather than passing around DumpOptions and RestoreOptions as separate
arguments, add fields to struct Archive to carry pointers to these objects,
and access them through those fields when needed.  There already was a
RestoreOptions pointer in Archive, though for no obvious reason it was part
of the "private" struct rather than out where pg_dump.c could see it.

Doing this allows reversion of quite a lot of parameter-addition changes
made in commit 0eea8047bf, which is a good thing IMO because this will
reduce the code delta between 9.4 and 9.5, probably easing a few future
back-patch efforts.  Moreover, the previous commit only added a DumpOptions
argument to functions that had to have it at the time, which means we could
anticipate still more code churn (and more back-patch hazard) as the
requirement spread further.  I'd hit exactly that problem in my upcoming
patch to fix extension membership marking, which is what motivated me to
do this.

8 years agoRun pgindent on src/bin/pg_dump/*
Tom Lane [Wed, 13 Jan 2016 20:48:54 +0000 (15:48 -0500)]
Run pgindent on src/bin/pg_dump/*

To ease doing indent fixups on a couple of patches I have in progress.

8 years agopsql: Improve CREATE INDEX CONCURRENTLY tab completion
Peter Eisentraut [Wed, 13 Jan 2016 01:31:43 +0000 (20:31 -0500)]
psql: Improve CREATE INDEX CONCURRENTLY tab completion

The completion of CREATE INDEX CONCURRENTLY was lacking in several ways
compared to a plain CREATE INDEX command:

- CREATE INDEX <name> ON completes table names, but didn't with
  CONCURRENTLY.

- CREATE INDEX completes ON and existing index names, but with
  CONCURRENTLY it only completed ON.

- CREATE INDEX <name> completes ON, but didn't with CONCURRENTLY.

These are now all fixed.

8 years agopsql: Fix CREATE INDEX tab completion
Peter Eisentraut [Sun, 10 Jan 2016 16:43:27 +0000 (11:43 -0500)]
psql: Fix CREATE INDEX tab completion

The previous code supported a syntax like CREATE INDEX name
CONCURRENTLY, which never existed.  Mistake introduced in commit
37ec19a15ce452ee94f32ebc3d6a9a45868e82fd.  Remove the addition of
CONCURRENTLY at that point.

8 years agopsql: Update tab completion comment
Peter Eisentraut [Sun, 10 Jan 2016 16:24:51 +0000 (11:24 -0500)]
psql: Update tab completion comment

This just updates a comment to match the code.

from Michael Paquier

8 years agoAdd new user fn pg_current_xlog_flush_location()
Simon Riggs [Tue, 12 Jan 2016 07:54:52 +0000 (07:54 +0000)]
Add new user fn pg_current_xlog_flush_location()

Tomas Vondra, reviewed by Michael Paquier and Amit Kapila
Minor edits by me

8 years agoMaintain local LogwrtResult consistently
Simon Riggs [Tue, 12 Jan 2016 07:33:20 +0000 (07:33 +0000)]
Maintain local LogwrtResult consistently

Teach GetFlushRecPtr() to update LogwrtResult cache as performed by all other
functions in xlog.c

8 years agoRemove no-longer-needed old-style check for incompatible plpythons.
Tom Lane [Tue, 12 Jan 2016 01:13:31 +0000 (20:13 -0500)]
Remove no-longer-needed old-style check for incompatible plpythons.

Commit 866566a690bb9916 introduced a new mechanism for incompatible
plpythons to detect each other.  I left the old mechanism in place,
because it seems possible that a plpython predating that commit might be
used with one postdating it.  (This would require updating plpython3 but
not plpython2 or vice versa, but that seems well within the realm of
possibility.)  However, surely it will not be able to happen in 9.6 or
later, so we can delete the old mechanism in HEAD.

8 years agoUse LOAD not actual code execution to pull in plpython library.
Tom Lane [Tue, 12 Jan 2016 01:06:36 +0000 (20:06 -0500)]
Use LOAD not actual code execution to pull in plpython library.

Commit 866566a690bb9916 is insufficient to prevent dump/reload failures
when using transform modules in a database with both plpython2 and
plpython3 installed.  The reason is that the transform extension scripts
use DO blocks as a mechanism to pull in the libpython library before
creating the transform function.  It's necessary to preload the library
because the dynamic loader won't do it for us on every platform, leading
to "unresolved symbol" failures when the transform library is loaded.
But it's *not* necessary to execute Python code, and doing so will
provoke a multiple-Pythons-are-loaded error even after the preceding
commit.

To fix, use LOAD instead of a DO block.  That requires superuser privilege,
but creation of a C function does anyway.  It also embeds knowledge of
the underlying library name for each PL language; but that's wired into
the initdb-time contents of pg_pltemplate too, so that doesn't seem like
a large problem either.  Note that CREATE TRANSFORM as such doesn't call
the language module at all.

Per a report from Paul Jones.  Back-patch to 9.5 where transform modules
were introduced.