]> granicus.if.org Git - postgresql/log
postgresql
9 years agoMake TAP tests work on Windows.
Heikki Linnakangas [Wed, 29 Jul 2015 16:17:02 +0000 (19:17 +0300)]
Make TAP tests work on Windows.

On Windows, use listen_address=127.0.0.1 to allow TCP connections. We were
already using "pg_regress --config-auth" to set up HBA appropriately. The
standard_initdb helper function now sets up the server's
unix_socket_directories or listen_addresses in the config file, so that
they don't need to be specified in the pg_ctl command line anymore. That
way, the pg_ctl invocations in test programs don't need to differ between
Windows and Unix.

Add another helper function to configure the server's pg_hba.conf to allow
replication connections. The configuration is done similarly to "pg_regress
--config-auth": trust on domain sockets on Unix, and SSPI authentication on
Windows.

Replace calls to "cat" and "touch" programs with built-in perl code, as
those programs don't normally exist on Windows.

Add instructions in the docs on how to install IPC::Run on Windows. Adjust
vcregress.pl to not replace PERL5LIB completely in vcregress.pl, because
otherwise cannot install IPC::Run in a non-standard location easily.

Michael Paquier, reviewed by Noah Misch, some additional tweaking by me.

9 years agoDocument how to build the docs using the website style.
Robert Haas [Wed, 29 Jul 2015 15:16:55 +0000 (11:16 -0400)]
Document how to build the docs using the website style.

Craig Ringer

9 years agoRemove outdated comment in LWLockDequeueSelf's header.
Andres Freund [Wed, 29 Jul 2015 08:13:10 +0000 (10:13 +0200)]
Remove outdated comment in LWLockDequeueSelf's header.

Noticed-By: Robert Haas
Backpatch: 9.5, where the function was added

9 years agoFix typo in comment.
Heikki Linnakangas [Wed, 29 Jul 2015 07:55:43 +0000 (10:55 +0300)]
Fix typo in comment.

Amit Langote

9 years agopg_basebackup: Add --slot option
Peter Eisentraut [Wed, 22 Jul 2015 01:06:45 +0000 (21:06 -0400)]
pg_basebackup: Add --slot option

This option specifies a replication slot for WAL streaming (-X stream),
so that there can be continuous replication slot use between WAL
streaming during the base backup and the start of regular streaming
replication.

Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
9 years agopg_basebackup: Add tests for -X option
Peter Eisentraut [Wed, 1 Jul 2015 01:15:29 +0000 (21:15 -0400)]
pg_basebackup: Add tests for -X option

Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
9 years agopg_basebackup: Add tests for -R option
Peter Eisentraut [Wed, 1 Jul 2015 01:15:05 +0000 (21:15 -0400)]
pg_basebackup: Add tests for -R option

Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
9 years agoPrevent platform-dependent output row ordering in a new test query.
Tom Lane [Wed, 29 Jul 2015 00:00:13 +0000 (20:00 -0400)]
Prevent platform-dependent output row ordering in a new test query.

Buildfarm indicates this is necessary.

9 years agoSuppress "variable may be used uninitialized" warning.
Tom Lane [Tue, 28 Jul 2015 23:55:59 +0000 (19:55 -0400)]
Suppress "variable may be used uninitialized" warning.

Also re-pgindent, just because I'm a neatnik.

9 years agoDisallow converting a table to a view if row security is present.
Joe Conway [Tue, 28 Jul 2015 23:24:01 +0000 (16:24 -0700)]
Disallow converting a table to a view if row security is present.

When DefineQueryRewrite() is about to convert a table to a view, it checks
the table for features unavailable to views.  For example, it rejects tables
having triggers.  It omits to reject tables having relrowsecurity or a
pg_policy record. Fix that. To faciliate the repair, invent
relation_has_policies() which indicates the presence of policies on a
relation even when row security is disabled for that relation.

Reported by Noah Misch. Patch by me, review by Stephen Frost. Back-patch
to 9.5 where RLS was introduced.

9 years agoCreate a pg_shdepend entry for each role in TO clause of policies.
Joe Conway [Tue, 28 Jul 2015 23:01:53 +0000 (16:01 -0700)]
Create a pg_shdepend entry for each role in TO clause of policies.

CreatePolicy() and AlterPolicy() omit to create a pg_shdepend entry for
each role in the TO clause. Fix this by creating a new shared dependency
type called SHARED_DEPENDENCY_POLICY and assigning it to each role.

Reported by Noah Misch. Patch by me, reviewed by Alvaro Herrera.
Back-patch to 9.5 where RLS was introduced.

9 years agoUpdate our documentation concerning where to create data directories.
Tom Lane [Tue, 28 Jul 2015 22:42:59 +0000 (18:42 -0400)]
Update our documentation concerning where to create data directories.

Although initdb has long discouraged use of a filesystem mount-point
directory as a PG data directory, this point was covered nowhere in the
user-facing documentation.  Also, with the popularity of pg_upgrade,
we really need to recommend that the PG user own not only the data
directory but its parent directory too.  (Without a writable parent
directory, operations such as "mv data data.old" fail immediately.
pg_upgrade itself doesn't do that, but wrapper scripts for it often do.)

Hence, adjust the "Creating a Database Cluster" section to address
these points.  I also took the liberty of wordsmithing the discussion
of NFS a bit.

These considerations aren't by any means new, so back-patch to all
supported branches.

9 years agoOnly adjust negative indexes in json_get up to the length of the path.
Andrew Dunstan [Tue, 28 Jul 2015 21:54:13 +0000 (17:54 -0400)]
Only adjust negative indexes in json_get up to the length of the path.

The previous code resulted in memory access beyond the path bounds. The
cure is to move it into a code branch that checks the value of lex_level
is within the correct bounds.

Bug reported and diagnosed by Piotr Stefaniak.

9 years agoReduce chatter from signaling of autovacuum workers.
Tom Lane [Tue, 28 Jul 2015 21:34:00 +0000 (17:34 -0400)]
Reduce chatter from signaling of autovacuum workers.

Don't print a WARNING if we get ESRCH from a kill() that's attempting
to cancel an autovacuum worker.  It's possible (and has been seen in the
buildfarm) that the worker is already gone by the time we are able to
execute the kill, in which case the failure is harmless.  About the only
plausible reason for reporting such cases would be to help debug corrupted
lock table contents, but this is hardly likely to be the most important
symptom if that happens.  Moreover issuing a WARNING might scare users
more than is warranted.

Also, since sending a signal to an autovacuum worker is now entirely a
routine thing, and the worker will log the query cancel on its end anyway,
reduce the message saying we're doing that from LOG to DEBUG1 level.

Very minor cosmetic cleanup as well.

Since the main practical reason for doing this is to avoid unnecessary
buildfarm failures, back-patch to all active branches.

9 years agoBump catversion so that HEAD is beyond 9.5
Joe Conway [Tue, 28 Jul 2015 20:59:23 +0000 (13:59 -0700)]
Bump catversion so that HEAD is beyond 9.5

As pointed out by Tom, since HEAD has progressed beyond 9.5 in terms of
its catalog, we need to be sure catversion of HEAD is advanced beyond
that of 9.5. Corrects my mistake in the pg_stats view commit cfa928ff.

9 years agoPlug RLS related information leak in pg_stats view.
Joe Conway [Tue, 28 Jul 2015 20:21:22 +0000 (13:21 -0700)]
Plug RLS related information leak in pg_stats view.

The pg_stats view is supposed to be restricted to only show rows
about tables the user can read. However, it sometimes can leak
information which could not otherwise be seen when row level security
is enabled. Fix that by not showing pg_stats rows to users that would
be subject to RLS on the table the row is related to. This is done
by creating/using the newly introduced SQL visible function,
row_security_active().

Along the way, clean up three call sites of check_enable_rls(). The second
argument of that function should only be specified as other than
InvalidOid when we are checking as a different user than the current one,
as in when querying through a view. These sites were passing GetUserId()
instead of InvalidOid, which can cause the function to return incorrect
results if the current user has the BYPASSRLS privilege and row_security
has been set to OFF.

Additionally fix a bug causing RI Trigger error messages to unintentionally
leak information when RLS is enabled, and other minor cleanup and
improvements. Also add WITH (security_barrier) to the definition of pg_stats.

Bumped CATVERSION due to new SQL functions and pg_stats view definition.

Back-patch to 9.5 where RLS was introduced. Reported by Yaroslav.
Patch by Joe Conway and Dean Rasheed with review and input by
Michael Paquier and Stephen Frost.

9 years agoRemove ssl renegotiation support.
Andres Freund [Tue, 28 Jul 2015 19:39:32 +0000 (21:39 +0200)]
Remove ssl renegotiation support.

While postgres' use of SSL renegotiation is a good idea in theory, it
turned out to not work well in practice. The specification and openssl's
implementation of it have lead to several security issues. Postgres' use
of renegotiation also had its share of bugs.

Additionally OpenSSL has a bunch of bugs around renegotiation, reported
and open for years, that regularly lead to connections breaking with
obscure error messages. We tried increasingly complex workarounds to get
around these bugs, but we didn't find anything complete.

Since these connection breakages often lead to hard to debug problems,
e.g. spuriously failing base backups and significant latency spikes when
synchronous replication is used, we have decided to change the default
setting for ssl renegotiation to 0 (disabled) in the released
backbranches and remove it entirely in 9.5 and master.

Author: Andres Freund
Discussion: 20150624144148.GQ4797@alap3.anarazel.de
Backpatch: 9.5 and master, 9.0-9.4 get a different patch

9 years agoMake tap tests store postmaster logs and handle vpaths correctly
Andrew Dunstan [Tue, 28 Jul 2015 19:34:35 +0000 (15:34 -0400)]
Make tap tests store postmaster logs and handle vpaths correctly

Given this it is possible that the buildfarm animals running these tests
will be able to capture adequate logging to allow diagnosis of failures.

9 years agoCentralize decision-making about where to get a backend's PGPROC.
Robert Haas [Tue, 28 Jul 2015 18:51:57 +0000 (14:51 -0400)]
Centralize decision-making about where to get a backend's PGPROC.

This code was originally written as part of parallel query effort, but
it seems to have independent value, because if we make one decision
about where to get a PGPROC when we allocate and then put it back on a
different list at backend-exit time, bad things happen.  This isn't
just a theoretical risk; we fixed an actual problem of this type in
commit e280c630a87e1b8325770c6073097d109d79a00f.

9 years agoRemove an unsafe Assert, and explain join_clause_is_movable_into() better.
Tom Lane [Tue, 28 Jul 2015 17:20:39 +0000 (13:20 -0400)]
Remove an unsafe Assert, and explain join_clause_is_movable_into() better.

join_clause_is_movable_into() is approximate, in the sense that it might
sometimes return "false" when actually it would be valid to push the given
join clause down to the specified level.  This is okay ... but there was
an Assert in get_joinrel_parampathinfo() that's only safe if the answers
are always exact.  Comment out the Assert, and add a bunch of commentary
to clarify what's going on.

Per fuzz testing by Andreas Seltenreich.  The added regression test is
a pretty silly query, but it's based on his crasher example.

Back-patch to 9.2 where the faulty logic was introduced.

9 years agoFix bug in collecting total_latencies from all threads in pgbench.
Heikki Linnakangas [Tue, 28 Jul 2015 08:30:23 +0000 (11:30 +0300)]
Fix bug in collecting total_latencies from all threads in pgbench.

This was broken in 1bc90f7a, which removed the thread-emulation. With modest
-j and -c settings the result were usually close enough that you wouldn't
notice it easily, but with a high enough thread count it would access
uninitialized memory and crash.

Per report from Andres Freund offlist.

9 years agoAnother attempt at fixing memory leak in xlogreader.
Heikki Linnakangas [Tue, 28 Jul 2015 06:05:46 +0000 (09:05 +0300)]
Another attempt at fixing memory leak in xlogreader.

max_block_id is also reset between reading records.

Michael Paquier

9 years agoFix pg_dump output of policies.
Joe Conway [Tue, 28 Jul 2015 03:24:18 +0000 (20:24 -0700)]
Fix pg_dump output of policies.

pg_dump neglected to wrap parenthesis around USING and WITH CHECK
expressions -- fixed. Reported by Noah Misch.

9 years agoImprove RLS handling in copy.c
Stephen Frost [Mon, 27 Jul 2015 20:48:26 +0000 (16:48 -0400)]
Improve RLS handling in copy.c

To avoid a race condition where the relation being COPY'd could be
changed into a view or otherwise modified, keep the original lock
on the relation.  Further, fully qualify the relation when building
the query up.

Also remove the poorly thought-out Assert() and check the entire
relationOids list as, post-RLS, there can certainly be multiple
relations involved and the planner does not guarantee their ordering.

Per discussion with Noah and Andres.

Back-patch to 9.5 where RLS was introduced.

9 years agoFurther code review for pg_stat_ssl patch.
Tom Lane [Mon, 27 Jul 2015 20:29:14 +0000 (16:29 -0400)]
Further code review for pg_stat_ssl patch.

Fix additional bogosity in commit 9029f4b37406b21a.  Include the
BackendSslStatusBuffer in the BackendStatusShmemSize calculation,
avoid ugly and error-prone casts to char* and back, put related
code stanzas into a consistent order (and fix a couple of previous
instances of that sin).  All cosmetic except for the size oversight.

9 years agoFix pointer-arithmetic thinko in pg_stat_ssl patch.
Tom Lane [Mon, 27 Jul 2015 19:58:46 +0000 (15:58 -0400)]
Fix pointer-arithmetic thinko in pg_stat_ssl patch.

Nasty memory-stomp bug in commit 9029f4b37406b21a.  It's not apparent how
this survived even cursory testing :-(.  Per report from Peter Holzer.

9 years agoDon't assume that 'char' is signed.
Heikki Linnakangas [Mon, 27 Jul 2015 18:48:51 +0000 (21:48 +0300)]
Don't assume that 'char' is signed.

On some platforms, notably ARM and PowerPC, 'char' is unsigned by
default. This fixes an assertion failure at WAL replay on such platforms.

Reported by Noah Misch. Backpatch to 9.5, where this was broken.

9 years agoFix memory leaks in pg_rewind. Several PQclear() calls were missing.
Heikki Linnakangas [Mon, 27 Jul 2015 17:38:44 +0000 (20:38 +0300)]
Fix memory leaks in pg_rewind. Several PQclear() calls were missing.

Originally reported by Vladimir Borodin in the pg_rewind github project,
patch by Michael Paquier.

9 years agoDon't assume that PageIsEmpty() returns true on an all-zeros page.
Heikki Linnakangas [Mon, 27 Jul 2015 15:54:09 +0000 (18:54 +0300)]
Don't assume that PageIsEmpty() returns true on an all-zeros page.

It does currently, and I don't see us changing that any time soon, but we
don't make that assumption anywhere else.

Per Tom Lane's suggestion. Backpatch to 9.2, like the previous patch that
added this assumption.

9 years agoFix memory leak in xlogreader facility.
Heikki Linnakangas [Mon, 27 Jul 2015 15:27:27 +0000 (18:27 +0300)]
Fix memory leak in xlogreader facility.

XLogReaderFree failed to free the per-block data buffers, when they
happened to not be used by the latest read WAL record.

Michael Paquier. Backpatch to 9.5, where the per-block buffers were added.

9 years agoReuse all-zero pages in GIN.
Heikki Linnakangas [Mon, 27 Jul 2015 09:30:26 +0000 (12:30 +0300)]
Reuse all-zero pages in GIN.

In GIN, an all-zeros page would be leaked forever, and never reused. Just
add them to the FSM in vacuum, and they will be reinitialized when grabbed
from the FSM. On master and 9.5, attempting to access the page's opaque
struct also caused an assertion failure, although that was otherwise
harmless.

Reported by Jeff Janes. Backpatch to all supported versions.

9 years agoFix handling of all-zero pages in SP-GiST vacuum.
Heikki Linnakangas [Mon, 27 Jul 2015 09:28:21 +0000 (12:28 +0300)]
Fix handling of all-zero pages in SP-GiST vacuum.

SP-GiST initialized an all-zeros page at vacuum, but that was not
WAL-logged, which is not safe. You might get a torn page write, when it gets
flushed to disk, and end-up with a half-initialized index page. To fix,
leave it in the all-zeros state, and add it to the FSM. It will be
initialized when reused. Also don't set the page-deleted flag when recycling
an empty page. That was also not WAL-logged, and a torn write of that would
cause the page to have an invalid checksum.

Backpatch to 9.2, where SP-GiST indexes were added.

9 years agoAvoid calling PageGetSpecialPointer() on an all-zeros page.
Heikki Linnakangas [Mon, 27 Jul 2015 09:24:27 +0000 (12:24 +0300)]
Avoid calling PageGetSpecialPointer() on an all-zeros page.

That was otherwise harmless, but tripped the new assertion in
PageGetSpecialPointer().

Reported by Amit Langote. Backpatch to 9.5, where the assertion was added.

9 years agoRemove false comment about speculative insertion.
Heikki Linnakangas [Mon, 27 Jul 2015 08:46:11 +0000 (11:46 +0300)]
Remove false comment about speculative insertion.

There is no full discussion of speculative insertions in the executor
README. There is a high-level explanation in execIndexing.c, but it doesn't
seem necessary to refer it from here.

Peter Geoghegan

9 years agoFix oversight in flattening of subqueries with empty FROM.
Tom Lane [Sun, 26 Jul 2015 21:44:27 +0000 (17:44 -0400)]
Fix oversight in flattening of subqueries with empty FROM.

I missed a restriction that commit f4abd0241de20d5d6a79b84992b9e88603d44134
should have enforced: we can't pull up an empty-FROM subquery if it's under
an outer join, because then we'd need to wrap its output columns in
PlaceHolderVars.  As the code currently stands, the PHVs end up with empty
relid sets, which doesn't work (and is correctly caught by an Assert).

It's possible that this could be fixed by assigning the PHVs the relid
sets of the parent FromExpr/JoinExpr, but getting that to work is more
complication than I care to add right now; indeed it's likely that
we'll never bother, since pulling up empty-FROM subqueries is a rather
marginal optimization anyway.

Per report from Andreas Seltenreich.  Back-patch to 9.5 where the faulty
code was added.

9 years agoMake entirely-dummy appendrels get marked as such in set_append_rel_size.
Tom Lane [Sun, 26 Jul 2015 20:19:08 +0000 (16:19 -0400)]
Make entirely-dummy appendrels get marked as such in set_append_rel_size.

The planner generally expects that the estimated rowcount of any relation
is at least one row, *unless* it has been proven empty by constraint
exclusion or similar mechanisms, which is marked by installing a dummy path
as the rel's cheapest path (cf. IS_DUMMY_REL).  When I split up
allpaths.c's processing of base rels into separate set_base_rel_sizes and
set_base_rel_pathlists steps, the intention was that dummy rels would get
marked as such during the "set size" step; this is what justifies an Assert
in indxpath.c's get_loop_count that other relations should either be dummy
or have positive rowcount.  Unfortunately I didn't get that quite right
for append relations: if all the child rels have been proven empty then
set_append_rel_size would come up with a rowcount of zero, which is
correct, but it didn't then do set_dummy_rel_pathlist.  (We would have
ended up with the right state after set_append_rel_pathlist, but that's
too late, if we generate indexpaths for some other rel first.)

In addition to fixing the actual bug, I installed an Assert enforcing this
convention in set_rel_size; that then allows simplification of a couple
of now-redundant tests for zero rowcount in set_append_rel_size.

Also, to cover the possibility that third-party FDWs have been careless
about not returning a zero rowcount estimate, apply clamp_row_est to
whatever an FDW comes up with as the rows estimate.

Per report from Andreas Seltenreich.  Back-patch to 9.2.  Earlier branches
did not have the separation between set_base_rel_sizes and
set_base_rel_pathlists steps, so there was no intermediate state where an
appendrel would have had inconsistent rowcount and pathlist.  It's possible
that adding the Assert to set_rel_size would be a good idea in older
branches too; but since they're not under development any more, it's likely
not worth the trouble.

9 years agoCheck the relevant index element in ON CONFLICT unique index inference.
Andres Freund [Sun, 26 Jul 2015 16:20:41 +0000 (18:20 +0200)]
Check the relevant index element in ON CONFLICT unique index inference.

ON CONFLICT unique index inference had a thinko that could affect cases
where the user-supplied inference clause required that an attribute
match a particular (user specified) collation and/or opclass.

infer_collation_opclass_match() has to check for opclass and/or
collation matches and that the attribute is in the list of attributes or
expressions known to be in the definition of the index under
consideration. The bug was that these two conditions weren't necessarily
evaluated for the same index attribute.

Author: Peter Geoghegan
Discussion: CAM3SWZR4uug=WvmGk7UgsqHn2MkEzy9YU-+8jKGO4JPhesyeWg@mail.gmail.com
Backpatch: 9.5, where ON CONFLICT was introduced

9 years agoFix flattening of nested grouping sets.
Andres Freund [Sun, 26 Jul 2015 14:37:49 +0000 (16:37 +0200)]
Fix flattening of nested grouping sets.

Previously nested grouping set specifications accidentally weren't
flattened, but instead contained the nested specification as a element
in the outer list.

Fix this by, as actually documented in comments, concatenating the
nested set specification into the outer one. Also add tests to prevent
this from breaking again.

Author: Andrew Gierth, with tests from Jeevan Chalke
Reported-By: Jeevan Chalke
Discussion: CAM2+6=V5YvuxB+EyN4iH=GbD-XTA435TCNvnDFSD--YvXs+pww@mail.gmail.com
Backpatch: 9.5, where grouping sets were introduced

9 years agoAllow to push down clauses from HAVING to WHERE when grouping sets are used.
Andres Freund [Sun, 26 Jul 2015 13:56:26 +0000 (15:56 +0200)]
Allow to push down clauses from HAVING to WHERE when grouping sets are used.

Previously we disallowed pushing down quals to WHERE in the presence of
grouping sets. That's overly restrictive.

We now instead copy quals to WHERE if applicable, leaving the
one in HAVING in place. That's because, at that stage of the planning
process, it's nontrivial to determine if it's safe to remove the one in
HAVING.

Author: Andrew Gierth
Discussion: 874mkt3l59.fsf@news-spur.riddles.org.uk
Backpatch: 9.5, where grouping sets were introduced. This isn't exactly
    a bugfix, but it seems better to keep the branches in sync at this point.

9 years agoRecognize GROUPING() as a aggregate expression.
Andres Freund [Sun, 26 Jul 2015 13:34:29 +0000 (15:34 +0200)]
Recognize GROUPING() as a aggregate expression.

Previously GROUPING() was not recognized as a aggregate expression,
erroneously allowing the planner to move it from HAVING to WHERE.

Author: Jeevan Chalke
Reviewed-By: Andrew Gierth
Discussion: CAM2+6=WG9omG5rFOMAYBweJxmpTaapvVp5pCeMrE6BfpCwr4Og@mail.gmail.com
Backpatch: 9.5, where grouping sets were introduced

9 years agoBuild column mapping for grouping sets in all required cases.
Andres Freund [Sun, 26 Jul 2015 13:17:44 +0000 (15:17 +0200)]
Build column mapping for grouping sets in all required cases.

The previous coding frequently failed to fail because for one it's
unusual to have rollup clauses with one column, and for another
sometimes the wrong mapping didn't cause obvious problems.

Author: Jeevan Chalke
Reviewed-By: Andrew Gierth
Discussion: CAM2+6=W=9=hQOipH0HAPbkun3Z3TFWij_EiHue0_6UX=oR=1kw@mail.gmail.com
Backpatch: 9.5, where grouping sets were introduced

9 years agoImprove markup for row_security.
Joe Conway [Sun, 26 Jul 2015 00:46:04 +0000 (17:46 -0700)]
Improve markup for row_security.

Wrap the literals on, off, force, and BYPASSRLS with appropriate
markup. Per Kevin Grittner.

9 years agoDodge portability issue (apparent compiler bug) in new tablesample code.
Tom Lane [Sat, 25 Jul 2015 23:42:32 +0000 (19:42 -0400)]
Dodge portability issue (apparent compiler bug) in new tablesample code.

Some of the older OS X critters in the buildfarm are failing regression,
with symptoms showing that a request for 100% sampling in BERNOULLI or
SYSTEM methods actually gets only around 50% of the table.  gdb revealed
that the computation of the "cutoff" number was producing 0x7FFFFFFF
rather than the expected 0x100000000.  Inspecting the assembly code,
it looks like gcc is trying to use lrint() instead of rint() and then
fumbling the conversion from long double to uint64.  This seems like a
clear compiler bug, but assigning the intermediate result into a plain
double variable works around it, so let's just do that.  (Another idea
would be to give up one bit of hash width so that we don't need to use
a uint64 cutoff, but let's see if this is enough.)

9 years agoRestore use of zlib default compression in pg_dump directory mode.
Andrew Dunstan [Sat, 25 Jul 2015 21:14:36 +0000 (17:14 -0400)]
Restore use of zlib default compression in pg_dump directory mode.

This was broken by commit 0e7e355f27302b62af3e1add93853ccd45678443 and
friends, which ignored the fact that gzopen() will treat "-1" in the
mode argument as an invalid character, which it ignores, and a flag for
compression level 1. Now, when this value is encountered no compression
level flag is passed  to gzopen, leaving it to use the zlib default.

Also, enforce the documented allowed range for pg_dump's -Z option,
namely 0 .. 9, and remove some consequently dead code from
pg_backup_tar.c.

Problem reported by Marc Mamin.

Backpatch to 9.1, like the patch that introduced the bug.

9 years agoSome platforms now need contrib/tsm_system_time to be linked with libm.
Tom Lane [Sat, 25 Jul 2015 20:37:12 +0000 (16:37 -0400)]
Some platforms now need contrib/tsm_system_time to be linked with libm.

Buildfarm member hornet, at least, seems to want -lm in the link command.
Probably this is due to the just-added use of isnan().

9 years agoIn pg_ctl, report unexpected failure to stat() the postmaster.pid file.
Tom Lane [Sat, 25 Jul 2015 19:58:14 +0000 (15:58 -0400)]
In pg_ctl, report unexpected failure to stat() the postmaster.pid file.

Any error other than ENOENT is a bit suspicious here, and perhaps should
not be grounds for assuming the postmaster has failed.  For the moment
though, just report it, and don't change the behavior otherwise.  The
intent is mainly to try to determine why we are seeing intermittent
failures in this area on some buildfarm members.

Back-patch to 9.5 where some of these failures have happened.

9 years agoUpdate oidjoins regression test for 9.5.
Tom Lane [Sat, 25 Jul 2015 19:46:26 +0000 (15:46 -0400)]
Update oidjoins regression test for 9.5.

New FK relationships for pg_transform.  Also findoidjoins now detects a few
relationships it didn't before for pre-existing catalogs, as a result of
new regression tests leaving entries in those catalogs that weren't there
before.

9 years agoRedesign tablesample method API, and do extensive code review.
Tom Lane [Sat, 25 Jul 2015 18:39:00 +0000 (14:39 -0400)]
Redesign tablesample method API, and do extensive code review.

The original implementation of TABLESAMPLE modeled the tablesample method
API on index access methods, which wasn't a good choice because, without
specialized DDL commands, there's no way to build an extension that can
implement a TSM.  (Raw inserts into system catalogs are not an acceptable
thing to do, because we can't undo them during DROP EXTENSION, nor will
pg_upgrade behave sanely.)  Instead adopt an API more like procedural
language handlers or foreign data wrappers, wherein the only SQL-level
support object needed is a single handler function identified by having
a special return type.  This lets us get rid of the supporting catalog
altogether, so that no custom DDL support is needed for the feature.

Adjust the API so that it can support non-constant tablesample arguments
(the original coding assumed we could evaluate the argument expressions at
ExecInitSampleScan time, which is undesirable even if it weren't outright
unsafe), and discourage sampling methods from looking at invisible tuples.
Make sure that the BERNOULLI and SYSTEM methods are genuinely repeatable
within and across queries, as required by the SQL standard, and deal more
honestly with methods that can't support that requirement.

Make a full code-review pass over the tablesample additions, and fix
assorted bugs, omissions, infelicities, and cosmetic issues (such as
failure to put the added code stanzas in a consistent ordering).
Improve EXPLAIN's output of tablesample plans, too.

Back-patch to 9.5 so that we don't have to support the original API
in production.

9 years agoMake RLS work with UPDATE ... WHERE CURRENT OF
Joe Conway [Fri, 24 Jul 2015 19:55:30 +0000 (12:55 -0700)]
Make RLS work with UPDATE ... WHERE CURRENT OF

UPDATE ... WHERE CURRENT OF would not work in conjunction with
RLS. Arrange to allow the CURRENT OF expression to be pushed down.
Issue noted by Peter Geoghegan. Patch by Dean Rasheed. Back patch
to 9.5 where RLS was introduced.

9 years agoFix treatment of nulls in jsonb_agg and jsonb_object_agg
Andrew Dunstan [Fri, 24 Jul 2015 13:40:46 +0000 (09:40 -0400)]
Fix treatment of nulls in jsonb_agg and jsonb_object_agg

The wrong is_null flag was being passed to datum_to_json. Also, null
object key values are not permitted, and this was not being checked
for. Add regression tests covering these cases, and also add those tests
to the json set, even though it was doing the right thing.

Fixes bug #13514, initially diagnosed by Tom Lane.

9 years agoFix bug around assignment expressions containing indirections.
Andres Freund [Fri, 24 Jul 2015 09:48:53 +0000 (11:48 +0200)]
Fix bug around assignment expressions containing indirections.

Handling of assigned-to expressions with indirection (e.g. set f1[1] =
3) was broken for ON CONFLICT DO UPDATE.  The problem was that
ParseState was consulted to determine if an INSERT-appropriate or
UPDATE-appropriate behavior should be used when transforming expressions
with indirections. When the wrong path was taken the old row was
substituted with NULL, leading to wrong results..

To fix remove p_is_update and only use p_is_insert to decide how to
transform the assignment expression, and uset p_is_insert while parsing
the on conflict statement. This isn't particularly pretty, but it's not
any worse than before.

Author: Peter Geoghegan, slightly edited by me
Discussion: CAM3SWZS8RPvA=KFxADZWw3wAHnnbxMxDzkEC6fNaFc7zSm411w@mail.gmail.com
Backpatch: 9.5, where the feature was introduced

9 years agoRedirect install output of make check into a log file
Andrew Dunstan [Thu, 23 Jul 2015 13:44:20 +0000 (09:44 -0400)]
Redirect install output of make check into a log file

dbf2ec1a changed make check so that the installation logs get directed
to stdout and stderr. Per discussion on -hackers, this patch restores
saving it to a file. It is now saved in /tmp_install/log, which is
created once per invocation of any make target doing regression tests.

Along the way, add a missing /log/ entry to test_ddl_deparse's
.gitignore.

Michael Paquier.

9 years agoFix off-by-one error in calculating subtrans/multixact truncation point.
Heikki Linnakangas [Wed, 22 Jul 2015 22:29:59 +0000 (01:29 +0300)]
Fix off-by-one error in calculating subtrans/multixact truncation point.

If there were no subtransactions (or multixacts) active, we would calculate
the oldestxid == next xid. That's correct, but if next XID happens to be
on the next pg_subtrans (pg_multixact) page, the page does not exist yet,
and SimpleLruTruncate will produce an "apparent wraparound" warning. The
warning is harmless in this case, but looks very alarming to users.

Backpatch to all supported versions. Patch and analysis by Thomas Munro.

9 years agoFix add_rte_to_flat_rtable() for recent feature additions.
Tom Lane [Wed, 22 Jul 2015 00:03:58 +0000 (20:03 -0400)]
Fix add_rte_to_flat_rtable() for recent feature additions.

The TABLESAMPLE and row security patches each overlooked this function,
though their errors of omission were opposite: RLS failed to zero out the
securityQuals field, leading to wasteful copying of useless expression
trees in finished plans, while TABLESAMPLE neglected to add a comment
saying that it intentionally *isn't* deleting the tablesample subtree.
There probably should be a similar comment about ctename, too.

Back-patch as appropriate.

9 years agoAdd selectivity estimation functions for intarray operators.
Heikki Linnakangas [Tue, 21 Jul 2015 17:54:18 +0000 (20:54 +0300)]
Add selectivity estimation functions for intarray operators.

Uriy Zhuravlev and Alexander Korotkov, reviewed by Jeff Janes, some cleanup
by me.

9 years agoFix some oversights in BRIN patch.
Tom Lane [Tue, 21 Jul 2015 17:38:24 +0000 (13:38 -0400)]
Fix some oversights in BRIN patch.

Remove HeapScanDescData.rs_initblock, which wasn't being used for anything
in the final version of the patch.

Fix IndexBuildHeapScan so that it supports syncscan again; the patch
broke synchronous scanning for index builds by forcing rs_startblk
to zero even when the caller did not care about that and had asked
for syncscan.

Add some commentary and usage defenses to heap_setscanlimits().

Fix heapam so that asking for rs_numblocks == 0 does what you would
reasonably expect.  As coded it amounted to requesting a whole-table
scan, because those "--x <= 0" tests on an unsigned variable would
behave surprisingly.

9 years agoFix location of output logs of pg_regress
Andrew Dunstan [Tue, 21 Jul 2015 13:53:16 +0000 (09:53 -0400)]
Fix location of output logs of pg_regress

initdb.log and postmaster.log were moved to within the temporary instance
path by commit dcae5fa. This directory now gets removed at the end
of the run of pg_regress when there are no failures found, which makes
analysis of after-run issues difficult in some cases, and reduces the
output verbosity of the buildfarm after a run.

Fix by Michael Paquier

Backpatch to 9.5

9 years agoFix omission of OCLASS_TRANSFORM in object_classes[]
Alvaro Herrera [Tue, 21 Jul 2015 11:20:53 +0000 (13:20 +0200)]
Fix omission of OCLASS_TRANSFORM in object_classes[]

This was forgotten in cac76582053e (and its fixup ad89a5d115).  Since it
seems way too easy to miss this, this commit also introduces a mechanism
to enforce that the array is consistent with the enum.

Problem reported independently by Robert Haas and Jaimin Pan.
Patches proposed by Jaimin Pan, Jim Nasby, Michael Paquier and myself,
though I didn't use any of these and instead went with a cleaner
approach suggested by Tom Lane.

Backpatch to 9.5.

Discussion:
https://www.postgresql.org/message-id/CA+Tgmoa6SgDaxW_n_7SEhwBAc=mniYga+obUj5fmw4rU9_mLvA@mail.gmail.com
https://www.postgresql.org/message-id/29788.1437411581@sss.pgh.pa.us

9 years agoSanity-check that a page zeroed by redo routine is marked with WILL_INIT.
Heikki Linnakangas [Mon, 20 Jul 2015 13:02:28 +0000 (16:02 +0300)]
Sanity-check that a page zeroed by redo routine is marked with WILL_INIT.

There was already a sanity-check in the other direction: if a page was
marked with WILL_INIT, it had to be initialized by the redo routine. It's
not strictly necessary for correctness that a page is marked with WILL_INIT
if it's going to be initialized at redo, but it's a missed optimization if
nothing else.

Fix a few instances of this issue in SP-GiST, where a block in WAL record
was not marked with WILL_INIT, but was in fact always initialized at redo.
We were creating a full-page image of the page unnecessarily in those
cases.

Backpatch to 9.5, where the new WILL_INIT flag was added.

9 years agoDon't handle PUBLIC/NONE separately
Alvaro Herrera [Mon, 20 Jul 2015 16:47:15 +0000 (18:47 +0200)]
Don't handle PUBLIC/NONE separately

Since those role specifiers are checked in the grammar, there's no need
for the old checks to remain in place after 31eae6028ec.  Remove them.

Backpatch to 9.5.

Noted and patch by Jeevan Chalke

9 years agoThis supports the triconsistent function for pg_trgm GIN opclass
Teodor Sigaev [Mon, 20 Jul 2015 15:18:48 +0000 (18:18 +0300)]
This supports the triconsistent function for pg_trgm GIN opclass
to make it faster to implement indexed queries where some keys are
common and some are rare.

Patch by Jeff Janes

9 years agoImprove tab-completion for DROP POLICY
Alvaro Herrera [Mon, 20 Jul 2015 13:37:17 +0000 (15:37 +0200)]
Improve tab-completion for DROP POLICY

Backpatch to 9.5.

Author: Pavel Stěhule

9 years agoFix (some of) pltcl memory usage
Alvaro Herrera [Sun, 19 Jul 2015 10:26:14 +0000 (12:26 +0200)]
Fix (some of) pltcl memory usage

As reported by Bill Parker, PL/Tcl did not validate some malloc() calls
against NULL return.  Fix by using palloc() in a new long-lived memory
context instead.  This allows us to simplify error handling too, by
simply deleting the memory context instead of doing retail frees.

There's still a lot that could be done to improve PL/Tcl's memory
handling ...

This is pretty ancient, so backpatch all the way back.

Author: Michael Paquier and Álvaro Herrera
Discussion: https://www.postgresql.org/message-id/CAFrbyQwyLDYXfBOhPfoBGqnvuZO_Y90YgqFM11T2jvnxjLFmqw@mail.gmail.com

9 years agoImprove BRIN documentation somewhat
Alvaro Herrera [Mon, 20 Jul 2015 10:16:40 +0000 (12:16 +0200)]
Improve BRIN documentation somewhat

This removes some info about support procedures being used, which was
obsoleted by commit db5f98ab4f, as well as add some more documentation
on how to create new opclasses using the Minmax infrastructure.
(Hopefully we can get something similar for Inclusion as well.)

In passing, fix some obsolete mentions of "mmtuples" in source code
comments.

Backpatch to 9.5, where BRIN was introduced.

9 years agoFix mis-merge in previous commit
Alvaro Herrera [Mon, 20 Jul 2015 09:59:31 +0000 (11:59 +0200)]
Fix mis-merge in previous commit

9 years agoAdd some comments to test_ddl_deparse and a README
Alvaro Herrera [Mon, 20 Jul 2015 09:20:40 +0000 (11:20 +0200)]
Add some comments to test_ddl_deparse and a README

Per comments from Heikki Linnakangas.

Backpatch to 9.5, where this module was introduced.

9 years agoHandle AT_ReAddComment in test_ddl_deparse, and add a catch-all default.
Heikki Linnakangas [Mon, 20 Jul 2015 07:19:22 +0000 (10:19 +0300)]
Handle AT_ReAddComment in test_ddl_deparse, and add a catch-all default.

In the passing, also move AT_ReAddComment to more logical position in the
enum, after all the Constraint-related subcommands.

This fixes a compiler warning, added by commit e42375fc. Backpatch to 9.5,
like that patch.

9 years agoRemove dead code.
Andrew Dunstan [Sun, 19 Jul 2015 17:19:38 +0000 (13:19 -0400)]
Remove dead code.

Defect noticed by Coverity.

9 years agoMake WaitLatchOrSocket's timeout detection more robust.
Tom Lane [Sat, 18 Jul 2015 15:47:13 +0000 (11:47 -0400)]
Make WaitLatchOrSocket's timeout detection more robust.

In the previous coding, timeout would be noticed and reported only when
poll() or socket() returned zero (or the equivalent behavior on Windows).
Ordinarily that should work well enough, but it seems conceivable that we
could get into a state where poll() always returns a nonzero value --- for
example, if it is noticing a condition on one of the file descriptors that
we do not think is reason to exit the loop.  If that happened, we'd be in a
busy-wait loop that would fail to terminate even when the timeout expires.

We can make this more robust at essentially no cost, by deciding to exit
of our own accord if we compute a zero or negative time-remaining-to-wait.
Previously the code noted this but just clamped the time-remaining to zero,
expecting that we'd detect timeout on the next loop iteration.

Back-patch to 9.2.  While 9.1 had a version of WaitLatchOrSocket, it was
primitive compared to later versions, and did not guarantee reliable
detection of timeouts anyway.  (Essentially, this is a refinement of
commit 3e7fdcffd6f77187, which was back-patched only as far as 9.2.)

9 years agoEnable transforms modules to build and test on Cygwin.
Andrew Dunstan [Sat, 18 Jul 2015 14:09:04 +0000 (10:09 -0400)]
Enable transforms modules to build and test on Cygwin.

This still doesn't work correctly with Python 3, but I am committing
this so we can get Cygwin buildfarm members building with Python 2.

9 years agoRelease note compatibility item
Andrew Dunstan [Sat, 18 Jul 2015 01:08:03 +0000 (21:08 -0400)]
Release note compatibility item

Note that json and jsonb extraction operators no longer consider a
negative subscript to be invalid.

9 years agoSupport JSON negative array subscripts everywhere
Andrew Dunstan [Sat, 18 Jul 2015 00:56:13 +0000 (20:56 -0400)]
Support JSON negative array subscripts everywhere

Previously, there was an inconsistency across json/jsonb operators that
operate on datums containing JSON arrays -- only some operators
supported negative array count-from-the-end subscripting.  Specifically,
only a new-to-9.5 jsonb deletion operator had support (the new "jsonb -
integer" operator).  This inconsistency seemed likely to be
counter-intuitive to users.  To fix, allow all places where the user can
supply an integer subscript to accept a negative subscript value,
including path-orientated operators and functions, as well as other
extraction operators.  This will need to be called out as an
incompatibility in the 9.5 release notes, since it's possible that users
are relying on certain established extraction operators changed here
yielding NULL in the event of a negative subscript.

For the json type, this requires adding a way of cheaply getting the
total JSON array element count ahead of time when parsing arrays with a
negative subscript involved, necessitating an ad-hoc lex and parse.
This is followed by a "conversion" from a negative subscript to its
equivalent positive-wise value using the count.  From there on, it's as
if a positive-wise value was originally provided.

Note that there is still a minor inconsistency here across jsonb
deletion operators.  Unlike the aforementioned new "-" deletion operator
that accepts an integer on its right hand side, the new "#-" path
orientated deletion variant does not throw an error when it appears like
an array subscript (input that could be recognized by as an integer
literal) is being used on an object, which is wrong-headed.  The reason
for not being stricter is that it could be the case that an object pair
happens to have a key value that looks like an integer; in general,
these two possibilities are impossible to differentiate with rhs path
text[] argument elements.  However, we still don't allow the "#-"
path-orientated deletion operator to perform array-style subscripting.
Rather, we just return the original left operand value in the event of a
negative subscript (which seems analogous to how the established
"jsonb/json #> text[]" path-orientated operator may yield NULL in the
event of an invalid subscript).

In passing, make SetArrayPath() stricter about not accepting cases where
there is trailing non-numeric garbage bytes rather than a clean NUL
byte.  This means, for example, that strings like "10e10" are now not
accepted as an array subscript of 10 by some new-to-9.5 path-orientated
jsonb operators (e.g. the new #- operator).  Finally, remove dead code
for jsonb subscript deletion; arguably, this should have been done in
commit b81c7b409.

Peter Geoghegan and Andrew Dunstan

9 years agoRepair mishandling of cached cast-expression trees in plpgsql.
Tom Lane [Fri, 17 Jul 2015 19:53:09 +0000 (15:53 -0400)]
Repair mishandling of cached cast-expression trees in plpgsql.

In commit 1345cc67bbb014209714af32b5681b1e11eaf964, I introduced caching
of expressions representing type-cast operations into plpgsql.  However,
I supposed that I could cache both the expression trees and the evaluation
state trees derived from them for the life of the session.  This doesn't
work, because we execute the expressions in plpgsql's simple_eval_estate,
which has an ecxt_per_query_memory that is only transaction-lifespan.
Therefore we can end up putting pointers into the evaluation state tree
that point to transaction-lifespan memory; in particular this happens if
the cast expression calls a SQL-language function, as reported by Geoff
Winkless.

The minimum-risk fix seems to be to treat the state trees the same way
we do for "simple expression" trees in plpgsql, ie create them in the
simple_eval_estate's ecxt_per_query_memory, which means recreating them
once per transaction.

Since I had to introduce bookkeeping overhead for that anyway, I bought
back some of the added cost by sharing the read-only expression trees
across all functions in the session, instead of using a per-function
table as originally.  The simple-expression bookkeeping takes care of
the recursive-usage risk that I was concerned about avoiding before.

At some point we should take a harder look at how all this works,
and see if we can't reduce the amount of tree reinitialization needed.
But that won't happen for 9.5.

9 years agoFix entirely broken permissions test in new alter_operator regression test.
Tom Lane [Fri, 17 Jul 2015 18:10:52 +0000 (14:10 -0400)]
Fix entirely broken permissions test in new alter_operator regression test.

Not only did this test fail to test what it was supposed to test, but it
left a user definition lying around, which caused subsequent runs of the
regression tests to fail.

9 years agoAdd new function pg_notification_queue_usage.
Robert Haas [Fri, 17 Jul 2015 13:12:03 +0000 (09:12 -0400)]
Add new function pg_notification_queue_usage.

This tells you what fraction of NOTIFY's queue is currently filled.

Brendan Jurd, reviewed by Merlin Moncure and Gurjeet Singh.  A few
further tweaks by me.

9 years agoAIX: Test the -qlonglong option before use.
Noah Misch [Fri, 17 Jul 2015 07:01:14 +0000 (03:01 -0400)]
AIX: Test the -qlonglong option before use.

xlc provides "long long" unconditionally at C99-compatible language
levels, and this option provokes a warning.  The warning interferes with
"configure" tests that fail in response to any warning.  Notably, before
commit 85a2a8903f7e9151793308d0638621003aded5ae, it interfered with the
test for -qnoansialias.  Back-patch to 9.0 (all supported versions).

9 years agoFix a low-probability crash in our qsort implementation.
Tom Lane [Fri, 17 Jul 2015 02:57:46 +0000 (22:57 -0400)]
Fix a low-probability crash in our qsort implementation.

It's standard for quicksort implementations, after having partitioned the
input into two subgroups, to recurse to process the smaller partition and
then handle the larger partition by iterating.  This method guarantees
that no more than log2(N) levels of recursion can be needed.  However,
Bentley and McIlroy argued that checking to see which partition is smaller
isn't worth the cycles, and so their code doesn't do that but just always
recurses on the left partition.  In most cases that's fine; but with
worst-case input we might need O(N) levels of recursion, and that means
that qsort could be driven to stack overflow.  Such an overflow seems to
be the only explanation for today's report from Yiqing Jin of a SIGSEGV
in med3_tuple while creating an index of a couple billion entries with a
very large maintenance_work_mem setting.  Therefore, let's spend the few
additional cycles and lines of code needed to choose the smaller partition
for recursion.

Also, fix up the qsort code so that it properly uses size_t not int for
some intermediate values representing numbers of items.  This would only
be a live risk when sorting more than INT_MAX bytes (in qsort/qsort_arg)
or tuples (in qsort_tuple), which I believe would never happen with any
caller in the current core code --- but perhaps it could happen with
call sites in third-party modules?  In any case, this is trouble waiting
to happen, and the corrected code is probably if anything shorter and
faster than before, since it removes sign-extension steps that had to
happen when converting between int and size_t.

In passing, move a couple of CHECK_FOR_INTERRUPTS() calls so that it's
not necessary to preserve the value of "r" across them, and prettify
the output of gen_qsort_tuple.pl a little.

Back-patch to all supported branches.  The odds of hitting this issue
are probably higher in 9.4 and up than before, due to the new ability
to allocate sort workspaces exceeding 1GB, but there's no good reason
to believe that it's impossible to crash older branches this way.

9 years agoFix spelling error
Magnus Hagander [Thu, 16 Jul 2015 07:31:58 +0000 (10:31 +0300)]
Fix spelling error

David Rowley

9 years agoFix copy/past error in comment
Magnus Hagander [Thu, 16 Jul 2015 07:28:44 +0000 (10:28 +0300)]
Fix copy/past error in comment

David Christensen

9 years agoAIX: Link TRANSFORM modules with their dependencies.
Noah Misch [Thu, 16 Jul 2015 01:00:26 +0000 (21:00 -0400)]
AIX: Link TRANSFORM modules with their dependencies.

The result closely resembles linking of these modules for the "win32"
port.  Augment the $(exports_file) header so the file is also usable as
an import file.  Unfortunately, relocating an AIX installation will now
require adding $(pkglibdir) to LD_LIBRARY_PATH.  Back-patch to 9.5,
where the modules were introduced.

9 years agoAIX: Link the postgres executable with -Wl,-brtllib.
Noah Misch [Thu, 16 Jul 2015 01:00:26 +0000 (21:00 -0400)]
AIX: Link the postgres executable with -Wl,-brtllib.

This allows PostgreSQL modules and their dependencies to have undefined
symbols, resolved at runtime.  Perl module shared objects rely on that
in Perl 5.8.0 and later.  This fixes the crash when PL/PerlU loads such
modules, as the hstore_plperl test suite does.  Module authors can link
using -Wl,-G to permit undefined symbols; by default, linking will fail
as it has.  Back-patch to 9.0 (all supported versions).

9 years agoMinGW: Link ltree_plpython with plpython.
Noah Misch [Thu, 16 Jul 2015 01:00:26 +0000 (21:00 -0400)]
MinGW: Link ltree_plpython with plpython.

The MSVC build system already did this, and building against Python 3
requires it.  Back-patch to 9.5, where the module was introduced.

9 years agoMention table_rewrite as valid event trigger tag
Alvaro Herrera [Wed, 15 Jul 2015 14:08:46 +0000 (17:08 +0300)]
Mention table_rewrite as valid event trigger tag

This was forgotten in 618c9430a8.

9 years agoRemove regression test added on auto-pilot.
Robert Haas [Tue, 14 Jul 2015 20:19:44 +0000 (16:19 -0400)]
Remove regression test added on auto-pilot.

Test does not match the comment which precedes it.

Peter Geoghegan

9 years agoFix event trigger support for the new ALTER OPERATOR command.
Heikki Linnakangas [Tue, 14 Jul 2015 16:50:18 +0000 (19:50 +0300)]
Fix event trigger support for the new ALTER OPERATOR command.

Also, the lock on pg_operator should not be released until end of
transaction.

9 years agoAdd ALTER OPERATOR command, for changing selectivity estimator functions.
Heikki Linnakangas [Tue, 14 Jul 2015 15:17:55 +0000 (18:17 +0300)]
Add ALTER OPERATOR command, for changing selectivity estimator functions.

Other options cannot be changed, as it's not totally clear if cached plans
would need to be invalidated if one of the other options change. Selectivity
estimator functions only change plan costs, not correctness of plans, so
those should be safe.

Original patch by Uriy Zhuravlev, heavily edited by me.

9 years agoPrevent pgstattuple() from reporting BRIN as unknown index.
Fujii Masao [Tue, 14 Jul 2015 13:36:51 +0000 (22:36 +0900)]
Prevent pgstattuple() from reporting BRIN as unknown index.

Also this patch removes obsolete comment.

Back-patch to 9.5 where BRIN index was added.

9 years agoMake regression test output stable.
Heikki Linnakangas [Tue, 14 Jul 2015 13:16:23 +0000 (16:16 +0300)]
Make regression test output stable.

In the test query I added for ALTER TABLE retaining comments, the order of
the result rows was not stable, and varied across systems. Add an ORDER BY
to make the order predictable. This should fix the buildfarm failures.

9 years agoRetain comments on indexes and constraints at ALTER TABLE ... TYPE ...
Heikki Linnakangas [Tue, 14 Jul 2015 08:40:22 +0000 (11:40 +0300)]
Retain comments on indexes and constraints at ALTER TABLE ... TYPE ...

When a column's datatype is changed, ATExecAlterColumnType() rebuilds all
the affected indexes and constraints, and the comments from the old
indexes/constraints were not carried over.

To fix, create a synthetic COMMENT ON command in the work queue, to re-add
any comments on constraints. For indexes, there's a comment field in
IndexStmt that is used.

This fixes bug #13126, reported by Kirill Simonov. Original patch by
Michael Paquier, reviewed by Petr Jelinek and me. This bug is present in
all versions, but only backpatch to 9.5. Given how minor the issue is, it
doesn't seem worth the work and risk to backpatch further than that.

9 years agoReformat code in ATPostAlterTypeParse.
Heikki Linnakangas [Tue, 14 Jul 2015 08:38:08 +0000 (11:38 +0300)]
Reformat code in ATPostAlterTypeParse.

The code in ATPostAlterTypeParse was very deeply indented, mostly because
there were two nested switch-case statements, which add a lot of
indentation. Use if-else blocks instead, to make the code less indented
and more readable.

This is in preparation for next patch that makes some actualy changes to
the function. These cosmetic parts have been separated to make it easier
to see the real changes in the other patch.

9 years agorelease notes: markup: vacuumdb is an application, not command
Bruce Momjian [Sun, 12 Jul 2015 21:41:57 +0000 (17:41 -0400)]
release notes:  markup:  vacuumdb is an application, not command

9 years agoFix assorted memory leaks.
Tom Lane [Sun, 12 Jul 2015 20:25:51 +0000 (16:25 -0400)]
Fix assorted memory leaks.

Per Coverity (not that any of these are so non-obvious that they should not
have been caught before commit).  The extent of leakage is probably minor
to unnoticeable, but a leak is a leak.  Back-patch as necessary.

Michael Paquier

9 years agoFor consistency add a pfree to ON CONFLICT set_plan_refs code.
Andres Freund [Sun, 12 Jul 2015 20:18:57 +0000 (22:18 +0200)]
For consistency add a pfree to ON CONFLICT set_plan_refs code.

Backpatch to 9.5 where ON CONFLICT was introduced.

Author: Peter Geoghegan

9 years agoOptionally don't error out due to preexisting slots in commandline utilities.
Andres Freund [Sun, 12 Jul 2015 20:06:27 +0000 (22:06 +0200)]
Optionally don't error out due to preexisting slots in commandline utilities.

pg_receivexlog and pg_recvlogical error out when --create-slot is
specified and a slot with the same name already exists. In some cases,
especially with pg_receivexlog, that's rather annoying and requires
additional scripting.

Backpatch to 9.5 as slot control functions have newly been added to
pg_receivexlog, and there doesn't seem much point leaving it in a less
useful state.

Discussion: 20150619144755.GG29350@alap3.anarazel.de

9 years agoAdd now-required #include.
Tom Lane [Sun, 12 Jul 2015 03:34:41 +0000 (23:34 -0400)]
Add now-required #include.

Fixes compiler warning induced by 808ea8fc7bb259ddd810353719cac66e85a608c8.

9 years agodoc: fix typo in CREATE POLICY manual page
Bruce Momjian [Sun, 12 Jul 2015 02:46:28 +0000 (22:46 -0400)]
doc:  fix typo in CREATE POLICY manual page

Backpatch through 9.5

9 years agoAdd assign_expr_collations() to CreatePolicy() and AlterPolicy().
Joe Conway [Sat, 11 Jul 2015 21:19:31 +0000 (14:19 -0700)]
Add assign_expr_collations() to CreatePolicy() and AlterPolicy().

As noted by Noah Misch, CreatePolicy() and AlterPolicy() omit to call
assign_expr_collations() on the node trees. Fix the omission and add
his test case to the rowsecurity regression test.

9 years agoCopy-edit the docs changes of OWNER TO CURRENT/SESSION_USER additions.
Heikki Linnakangas [Fri, 10 Jul 2015 11:28:34 +0000 (14:28 +0300)]
Copy-edit the docs changes of OWNER TO CURRENT/SESSION_USER additions.

Commit 31eae602 added new syntax to many DDL commands to use CURRENT_USER
or SESSION_USER instead of role name in ALTER ... OWNER TO, but because
of a misplaced '{', the syntax in the docs implied that the syntax was
"ALTER ... CURRENT_USER", instead of "ALTER ... OWNER TO CURRENT_USER".
Fix that, and also the funny indentation in some of the modified syntax
blurps.

9 years agoImprove documentation about array concat operator vs. underlying functions.
Tom Lane [Thu, 9 Jul 2015 22:50:31 +0000 (18:50 -0400)]
Improve documentation about array concat operator vs. underlying functions.

The documentation implied that there was seldom any reason to use the
array_append, array_prepend, and array_cat functions directly.  But that's
not really true, because they can help make it clear which case is meant,
which the || operator can't do since it's overloaded to represent all three
cases.  Add some discussion and examples illustrating the potentially
confusing behavior that can ensue if the parser misinterprets what was
meant.

Per a complaint from Michael Herold.  Back-patch to 9.2, which is where ||
started to behave this way.

9 years agoFix postmaster's handling of a startup-process crash.
Tom Lane [Thu, 9 Jul 2015 17:22:22 +0000 (13:22 -0400)]
Fix postmaster's handling of a startup-process crash.

Ordinarily, a failure (unexpected exit status) of the startup subprocess
should be considered fatal, so the postmaster should just close up shop
and quit.  However, if we sent the startup process a SIGQUIT or SIGKILL
signal, the failure is hardly "unexpected", and we should attempt restart;
this is necessary for recovery from ordinary backend crashes in hot-standby
scenarios.  I attempted to implement the latter rule with a two-line patch
in commit 442231d7f71764b8c628044e7ce2225f9aa43b67, but it now emerges that
that patch was a few bricks shy of a load: it failed to distinguish the
case of a signaled startup process from the case where the new startup
process crashes before reaching database consistency.  That resulted in
infinitely respawning a new startup process only to have it crash again.

To handle this properly, we really must track whether we have sent the
*current* startup process a kill signal.  Rather than add yet another
ad-hoc boolean to the postmaster's state, I chose to unify this with the
existing RecoveryError flag into an enum tracking the startup process's
state.  That seems more consistent with the postmaster's general state
machine design.

Back-patch to 9.0, like the previous patch.