]> granicus.if.org Git - postgresql/log
postgresql
10 years agoTranslation updates
Peter Eisentraut [Mon, 21 Jul 2014 05:07:36 +0000 (01:07 -0400)]
Translation updates

10 years agoUpdate SQL features list
Peter Eisentraut [Mon, 21 Jul 2014 04:42:32 +0000 (00:42 -0400)]
Update SQL features list

10 years agoFix xreflabel for hot_standby_feedback.
Tom Lane [Sun, 20 Jul 2014 02:20:38 +0000 (22:20 -0400)]
Fix xreflabel for hot_standby_feedback.

Rather remarkable that this has been wrong since 9.1 and nobody noticed.

10 years agoUpdate time zone data files to tzdata release 2014e.
Tom Lane [Sat, 19 Jul 2014 19:00:50 +0000 (15:00 -0400)]
Update time zone data files to tzdata release 2014e.

DST law changes in Crimea, Egypt, Morocco.  New zone Antarctica/Troll
for Norwegian base in Queen Maud Land.

10 years agoPartial fix for dropped columns in functions returning composite.
Tom Lane [Sat, 19 Jul 2014 18:28:25 +0000 (14:28 -0400)]
Partial fix for dropped columns in functions returning composite.

When a view has a function-returning-composite in FROM, and there are
some dropped columns in the underlying composite type, ruleutils.c
printed junk in the column alias list for the reconstructed FROM entry.
Before 9.3, this was prevented by doing get_rte_attribute_is_dropped
tests while printing the column alias list; but that solution is not
currently available to us for reasons I'll explain below.  Instead,
check for empty-string entries in the alias list, which can only exist
if that column position had been dropped at the time the view was made.
(The parser fills in empty strings to preserve the invariant that the
aliases correspond to physical column positions.)

While this is sufficient to handle the case of columns dropped before
the view was made, we have still got issues with columns dropped after
the view was made.  In particular, the view could contain Vars that
explicitly reference such columns!  The dependency machinery really
ought to refuse the column drop attempt in such cases, as it would do
when trying to drop a table column that's explicitly referenced in
views.  However, we currently neglect to store dependencies on columns
of composite types, and fixing that is likely to be too big to be
back-patchable (not to mention that existing views in existing databases
would not have the needed pg_depend entries anyway).  So I'll leave that
for a separate patch.

Pre-9.3, ruleutils would print such Vars normally (with their original
column names) even though it suppressed their entries in the RTE's
column alias list.  This is certainly bogus, since the printed view
definition would fail to reload, but at least it didn't crash.  However,
as of 9.3 the printed column alias list is tightly tied to the names
printed for Vars; so we can't treat columns as dropped for one purpose
and not dropped for the other.  This is why we can't just put back the
get_rte_attribute_is_dropped test: it results in an assertion failure
if the view in fact contains any Vars referencing the dropped column.
Once we've got dependencies preventing such cases, we'll probably want
to do it that way instead of relying on the empty-string test used here.

This fix turned up a very ancient bug in outfuncs/readfuncs, namely
that T_String nodes containing empty strings were not dumped/reloaded
correctly: the node was printed as "<>" which is read as a string
value of <>.  Since (per SQL) we disallow empty-string identifiers,
such nodes don't occur normally, which is why we'd not noticed.
(Such nodes aren't used for literal constants, just identifiers.)

Per report from Marc Schablewski.  Back-patch to 9.3 which is where
the rule printing behavior changed.  The dangling-variable case is
broken all the way back, but that's not what his complaint is about.

10 years agoLimit pg_upgrade authentication advice to always-secure techniques.
Noah Misch [Fri, 18 Jul 2014 20:05:17 +0000 (16:05 -0400)]
Limit pg_upgrade authentication advice to always-secure techniques.

~/.pgpass is a sound choice everywhere, and "peer" authentication is
safe on every platform it supports.  Cease to recommend "trust"
authentication, the safety of which is deeply configuration-specific.
Back-patch to 9.0, where pg_upgrade was introduced.

10 years agoFix two low-probability memory leaks in regular expression parsing.
Tom Lane [Fri, 18 Jul 2014 17:00:27 +0000 (13:00 -0400)]
Fix two low-probability memory leaks in regular expression parsing.

If pg_regcomp failed after having invoked markst/cleanst, it would leak any
"struct subre" nodes it had created.  (We've already detected all regex
syntax errors at that point, so the only likely causes of later failure
would be query cancel or out-of-memory.)  To fix, make sure freesrnode
knows the difference between the pre-cleanst and post-cleanst cleanup
procedures.  Add some documentation of this less-than-obvious point.

Also, newlacon did the wrong thing with an out-of-memory failure from
realloc(), so that the previously allocated array would be leaked.

Both of these are pretty low-probability scenarios, but a bug is a bug,
so patch all the way back.

Per bug #10976 from Arthur O'Dwyer.

10 years agodoc: Spell checking
Peter Eisentraut [Thu, 17 Jul 2014 02:20:15 +0000 (22:20 -0400)]
doc: Spell checking

10 years agoFix bugs in SP-GiST search with range type's -|- (adjacent) operator.
Heikki Linnakangas [Wed, 16 Jul 2014 06:10:54 +0000 (09:10 +0300)]
Fix bugs in SP-GiST search with range type's -|- (adjacent) operator.

The consistent function contained several bugs:

* The "if (which2) { ... }"  block was broken. It compared the  argument's
lower bound against centroid's upper bound, while it was supposed to compare
the argument's upper bound against the centroid's lower bound (the comment
was correct, code was wrong). Also, it cleared bits in the "which1"
variable, while it was supposed to clear bits in "which2".

* If the argument's upper bound was equal to the centroid's lower bound, we
descended to both halves (= all quadrants). That's unnecessary, searching
the right quadrants is sufficient. This didn't lead to incorrect query
results, but was clearly wrong, and slowed down queries unnecessarily.

* In the case that argument's lower bound is adjacent to the centroid's
upper bound, we also don't need to visit all quadrants. Per similar
reasoning as previous point.

* The code where we compare the previous centroid with the current centroid
should match the code where we compare the current centroid with the
argument. The point of that code is to redo the calculation done in the
previous level, to see if we were supposed to traverse left or right (or up
or down), and if we actually did. If we moved in the different direction,
then we know there are no matches for bound.

Refactor the code and adds comments to make it more readable and easier to
reason about.

Backpatch to 9.3 where SP-GiST support for range types was introduced.

10 years agoMove check for SSL_get_current_compression to run on mingw
Magnus Hagander [Tue, 15 Jul 2014 20:00:56 +0000 (22:00 +0200)]
Move check for SSL_get_current_compression to run on mingw

Mingw uses a different header file than msvc, so we don't get the
hardcoded value, so we need the configure test to run.

10 years agodoc: Put new options in right order on reference pages
Peter Eisentraut [Tue, 15 Jul 2014 18:34:33 +0000 (14:34 -0400)]
doc: Put new options in right order on reference pages

10 years agopg_upgrade: Fix spacing in help output
Peter Eisentraut [Tue, 15 Jul 2014 18:33:59 +0000 (14:33 -0400)]
pg_upgrade: Fix spacing in help output

10 years agopg_basebackup: Add more information about --max-rate option to help output
Peter Eisentraut [Tue, 15 Jul 2014 18:32:55 +0000 (14:32 -0400)]
pg_basebackup: Add more information about --max-rate option to help output

It was previously not clear what unit the option argument should have.

10 years agojson_build_object and json_build_array are stable, not immutable.
Andrew Dunstan [Tue, 15 Jul 2014 18:24:47 +0000 (14:24 -0400)]
json_build_object and json_build_array are stable, not immutable.

These functions indirectly invoke output functions, so they can't be
immutable.

Backpatch to 9.4 where they were introduced.

Catalog version bumped.

10 years agoFix REASSIGN OWNED for text search objects
Alvaro Herrera [Tue, 15 Jul 2014 17:24:07 +0000 (13:24 -0400)]
Fix REASSIGN OWNED for text search objects

Trying to reassign objects owned by a user that had text search
dictionaries or configurations used to fail with:
ERROR:  unexpected classid 3600
or
ERROR:  unexpected classid 3602

Fix by adding cases for those object types in a switch in pg_shdepend.c.

Both REASSIGN OWNED and text search objects go back all the way to 8.1,
so backpatch to all supported branches.  In 9.3 the alter-owner code was
made generic, so the required change in recent branches is pretty
simple; however, for 9.2 and older ones we need some additional
reshuffling to enable specifying objects by OID rather than name.

Text search templates and parsers are not owned objects, so there's no
change required for them.

Per bug #9749 reported by Michal Novotný

10 years agoDetect presence of SSL_get_current_compression
Magnus Hagander [Tue, 15 Jul 2014 16:04:43 +0000 (18:04 +0200)]
Detect presence of SSL_get_current_compression

Apparently we still build against OpenSSL so old that it doesn't
have this function, so add an autoconf check for it to make the
buildfarm happy. If the function doesn't exist, always return
that compression is disabled, since presumably the actual
compression functionality is always missing.

For now, hardcode the function as present on MSVC, since we should
hopefully be well beyond those old versions on that platform.

10 years agoAdd missing source files to nls.mk
Peter Eisentraut [Tue, 15 Jul 2014 14:00:53 +0000 (10:00 -0400)]
Add missing source files to nls.mk

These are files under common/ that have been moved around.  Updating
these manually is not satisfactory, but it's the only solution at the
moment.

10 years agoInclude SSL compression status in psql banner and connection logging
Magnus Hagander [Tue, 15 Jul 2014 13:07:38 +0000 (15:07 +0200)]
Include SSL compression status in psql banner and connection logging

Both the psql banner and the connection logging already included
SSL status, cipher and bitlength, this adds the information about
compression being on or off.

10 years agoAdd missing serial commas
Peter Eisentraut [Tue, 15 Jul 2014 12:25:27 +0000 (08:25 -0400)]
Add missing serial commas

Also update one place where the wal_level "logical" was not added to an
error message.

10 years agodoc: small fixes for REINDEX reference page
Peter Eisentraut [Tue, 15 Jul 2014 00:37:00 +0000 (20:37 -0400)]
doc: small fixes for REINDEX reference page

From: Josh Kupershmidt <schmiddy@gmail.com>

10 years agoMove view reloptions into their own varlena struct
Alvaro Herrera [Mon, 14 Jul 2014 21:24:40 +0000 (17:24 -0400)]
Move view reloptions into their own varlena struct

Per discussion after a gripe from me in
http://www.postgresql.org/message-id/20140611194633.GH18688@eldon.alvh.no-ip.org

Jaime Casanova

10 years agoPrevent bitmap heap scans from showing unnecessary block info in EXPLAIN ANALYZE.
Fujii Masao [Mon, 14 Jul 2014 11:40:14 +0000 (20:40 +0900)]
Prevent bitmap heap scans from showing unnecessary block info in EXPLAIN ANALYZE.

EXPLAIN ANALYZE shows the information of the numbers of exact/lossy blocks which
bitmap heap scan processes. But, previously, when those numbers were both zero,
it displayed only the prefix "Heap Blocks:" in TEXT output format. This is strange
and would confuse the users. So this commit suppresses such unnecessary information.

Backpatch to 9.4 where EXPLAIN ANALYZE was changed so that such information was
displayed.

Etsuro Fujita

10 years agoFix decoding of consecutive MULTI_INSERTs emitted by one heap_multi_insert().
Andres Freund [Sat, 12 Jul 2014 12:28:19 +0000 (14:28 +0200)]
Fix decoding of consecutive MULTI_INSERTs emitted by one heap_multi_insert().

Commit 1b86c81d2d fixed the decoding of toasted columns for the rows
contained in one xl_heap_multi_insert record. But that's not actually
enough, because heap_multi_insert() will actually first toast all
passed in rows and then emit several *_multi_insert records; one for
each page it fills with tuples.

Add a XLOG_HEAP_LAST_MULTI_INSERT flag which is set in
xl_heap_multi_insert->flag denoting that this multi_insert record is
the last emitted by one heap_multi_insert() call. Then use that flag
in decode.c to only set clear_toast_afterwards in the right situation.

Expand the number of rows inserted via COPY in the corresponding
regression test to make sure that more than one heap page is filled
with tuples by one heap_multi_insert() call.

Backpatch to 9.4 like the previous commit.

10 years agoAdd autocompletion of locale keywords for CREATE DATABASE
Magnus Hagander [Sat, 12 Jul 2014 12:19:57 +0000 (14:19 +0200)]
Add autocompletion of locale keywords for CREATE DATABASE

Adds support for autocomplete of LC_COLLATE and LC_CTYPE to
the CREATE DATABASE command in psql.

10 years agoFix bug with whole-row references to append subplans.
Tom Lane [Fri, 11 Jul 2014 23:12:38 +0000 (19:12 -0400)]
Fix bug with whole-row references to append subplans.

ExecEvalWholeRowVar incorrectly supposed that it could "bless" the source
TupleTableSlot just once per query.  But if the input is coming from an
Append (or, perhaps, other cases?) more than one slot might be returned
over the query run.  This led to "record type has not been registered"
errors when a composite datum was extracted from a non-blessed slot.

This bug has been there a long time; I guess it escaped notice because when
dealing with subqueries the planner tends to expand whole-row Vars into
RowExprs, which don't have the same problem.  It is possible to trigger
the problem in all active branches, though, as illustrated by the added
regression test.

10 years agoRename logical decoding's pg_llog directory to pg_logical.
Andres Freund [Wed, 2 Jul 2014 19:07:47 +0000 (21:07 +0200)]
Rename logical decoding's pg_llog directory to pg_logical.

The old name wasn't very descriptive as of actual contents of the
directory, which are historical snapshots in the snapshots/
subdirectory and mappingdata for rewritten tuples in
mappings/. There's been a fair amount of discussion what would be a
good name. I'm settling for pg_logical because it's likely that
further data around logical decoding and replication will need saving
in the future.

Also add the missing entry for the directory into storage.sgml's list
of PGDATA contents.

Bumps catversion as the data directories won't be compatible.

Backpatch to 9.4, which I missed to do as Michael Paquier luckily
noticed. As there already has been a catversion bump after 9.4beta1,
there's no reasons for having 9.4 diverge from master.

10 years agoFix whitespace
Peter Eisentraut [Wed, 9 Jul 2014 03:29:09 +0000 (23:29 -0400)]
Fix whitespace

10 years agoUpdate key words table for 9.4
Peter Eisentraut [Tue, 8 Jul 2014 18:54:32 +0000 (14:54 -0400)]
Update key words table for 9.4

10 years agodoc: Link text to table by id
Peter Eisentraut [Tue, 8 Jul 2014 18:14:37 +0000 (14:14 -0400)]
doc: Link text to table by id

10 years agoDon't assume a subquery's output is unique if there's a SRF in its tlist.
Tom Lane [Tue, 8 Jul 2014 18:03:16 +0000 (14:03 -0400)]
Don't assume a subquery's output is unique if there's a SRF in its tlist.

While the x output of "select x from t group by x" can be presumed unique,
this does not hold for "select x, generate_series(1,10) from t group by x",
because we may expand the set-returning function after the grouping step.
(Perhaps that should be re-thought; but considering all the other oddities
involved with SRFs in targetlists, it seems unlikely we'll change it.)
Put a check in query_is_distinct_for() so it's not fooled by such cases.

Back-patch to all supported branches.

David Rowley

10 years agodoc: Fix spacing in verbatim environments
Peter Eisentraut [Tue, 8 Jul 2014 15:39:07 +0000 (11:39 -0400)]
doc: Fix spacing in verbatim environments

10 years agopg_upgrade: allow upgrades for new-only TOAST tables
Bruce Momjian [Mon, 7 Jul 2014 17:24:08 +0000 (13:24 -0400)]
pg_upgrade: allow upgrades for new-only TOAST tables

Previously, when calculations on the need for toast tables changed,
pg_upgrade could not handle cases where the new cluster needed a TOAST
table and the old cluster did not.  (It already handled the opposite
case.)  This fixes the "OID mismatch" error typically generated in this
case.

Backpatch through 9.2

10 years agoFix decoding of MULTI_INSERTs when rows other than the last are toasted.
Andres Freund [Sun, 6 Jul 2014 13:58:01 +0000 (15:58 +0200)]
Fix decoding of MULTI_INSERTs when rows other than the last are toasted.

When decoding the results of a HEAP2_MULTI_INSERT (currently only
generated by COPY FROM) toast columns for all but the last tuple
weren't replaced by their actual contents before being handed to the
output plugin. The reassembled toast datums where disregarded after
every REORDER_BUFFER_CHANGE_(INSERT|UPDATE|DELETE) which is correct
for plain inserts, updates, deletes, but not multi inserts - there we
generate several REORDER_BUFFER_CHANGE_INSERTs for a single
xl_heap_multi_insert record.

To solve the problem add a clear_toast_afterwards boolean to
ReorderBufferChange's union member that's used by modifications. All
row changes but multi_inserts always set that to true, but
multi_insert sets it only for the last change generated.

Add a regression test covering decoding of multi_inserts - there was
none at all before.

Backpatch to 9.4 where logical decoding was introduced.

Bug found by Petr Jelinek.

10 years agoConsistently pass an "unsigned char" to ctype.h functions.
Noah Misch [Sun, 6 Jul 2014 04:29:51 +0000 (00:29 -0400)]
Consistently pass an "unsigned char" to ctype.h functions.

The isxdigit() calls relied on undefined behavior.  The isascii() call
was well-defined, but our prevailing style is to include the cast.
Back-patch to 9.4, where the isxdigit() calls were introduced.

10 years agoDon't cache per-group context across the whole query in orderedsetaggs.c.
Tom Lane [Thu, 3 Jul 2014 22:47:09 +0000 (18:47 -0400)]
Don't cache per-group context across the whole query in orderedsetaggs.c.

Although nodeAgg.c currently uses the same per-group memory context for
all groups of a query, that might change in future.  Avoid assuming it.
This costs us an extra AggCheckCallContext() call per group, but that's
pretty cheap and is probably good from a safety standpoint anyway.

Back-patch to 9.4 in case any third-party code copies this logic.

Andrew Gierth

10 years agoRedesign API presented by nodeAgg.c for ordered-set and similar aggregates.
Tom Lane [Thu, 3 Jul 2014 22:25:37 +0000 (18:25 -0400)]
Redesign API presented by nodeAgg.c for ordered-set and similar aggregates.

The previous design exposed the input and output ExprContexts of the
Agg plan node, but work on grouping sets has suggested that we'll regret
doing that.  Instead provide more narrowly-defined APIs that can be
implemented in multiple ways, namely a way to get a short-term memory
context and a way to register an aggregate shutdown callback.

Back-patch to 9.4 where the bad APIs were introduced, since we don't
want third-party code using these APIs and then having to change in 9.5.

Andrew Gierth

10 years agoUse a separate temporary directory for the Unix-domain socket
Peter Eisentraut [Thu, 3 Jul 2014 01:44:02 +0000 (21:44 -0400)]
Use a separate temporary directory for the Unix-domain socket

Creating the Unix-domain socket in the build directory can run into
name-length limitations.  Therefore, create the socket file in the
default temporary directory of the operating system.  Keep the temporary
data directory etc. in the build tree.

10 years agoSupport vpath builds in TAP tests
Peter Eisentraut [Thu, 3 Jul 2014 01:47:07 +0000 (21:47 -0400)]
Support vpath builds in TAP tests

10 years agoSmooth reporting of commit/rollback statistics.
Kevin Grittner [Wed, 2 Jul 2014 20:03:57 +0000 (15:03 -0500)]
Smooth reporting of commit/rollback statistics.

If a connection committed or rolled back any transactions within a
PGSTAT_STAT_INTERVAL pacing interval without accessing any tables,
the reporting of those statistics would be held up until the
connection closed or until it ended a PGSTAT_STAT_INTERVAL interval
in which it had accessed a table.  This could result in under-
reporting of transactions for an extended period, followed by a
spike in reported transactions.

While this is arguably a bug, the impact is minimal, primarily
affecting, and being affected by, monitoring software.  It might
cause more confusion than benefit to change the existing behavior
in released stable branches, so apply only to master and the 9.4
beta.

Gurjeet Singh, with review and editing by Kevin Grittner,
incorporating suggested changes from Abhijit Menon-Sen and Tom
Lane.

10 years agopg_upgrade: preserve database and relation minmxid values
Bruce Momjian [Wed, 2 Jul 2014 19:29:38 +0000 (15:29 -0400)]
pg_upgrade:  preserve database and relation minmxid values

Also set these values for pre-9.3 old clusters that don't have values to
preserve.

Analysis by Alvaro

Backpatch through 9.3

10 years agopg_upgrade: no need to remove "members" files for pre-9.3 upgrades
Bruce Momjian [Wed, 2 Jul 2014 17:11:05 +0000 (13:11 -0400)]
pg_upgrade:  no need to remove "members" files for pre-9.3 upgrades

Per analysis by Alvaro

Backpatch through 9.3

10 years agoAdd some errdetail to checkRuleResultList().
Tom Lane [Wed, 2 Jul 2014 16:31:27 +0000 (12:31 -0400)]
Add some errdetail to checkRuleResultList().

This function wasn't originally thought to be really user-facing,
because converting a table to a view isn't something we expect people
to do manually.  So not all that much effort was spent on the error
messages; in particular, while the code will complain that you got
the column types wrong it won't say exactly what they are.  But since
we repurposed the code to also check compatibility of rule RETURNING
lists, it's definitely user-facing.  It now seems worthwhile to add
errdetail messages showing exactly what the conflict is when there's
a mismatch of column names or types.  This is prompted by bug #10836
from Matthias Raffelsieper, which might have been forestalled if the
error message had reported the wrong column type as being "record".

Back-patch to 9.4, but not into older branches where the set of
translatable error strings is supposed to be stable.

10 years agoPrevent psql from issuing BEGIN before ALTER SYSTEM when AUTOCOMMIT is off.
Fujii Masao [Wed, 2 Jul 2014 03:42:20 +0000 (12:42 +0900)]
Prevent psql from issuing BEGIN before ALTER SYSTEM when AUTOCOMMIT is off.

The autocommit-off mode works by issuing an implicit BEGIN just before
any command that is not already in a transaction block and is not itself
a BEGIN or other transaction-control command, nor a command that
cannot be executed inside a transaction block. This commit prevents psql
from issuing such an implicit BEGIN before ALTER SYSTEM because it's
not allowed inside a transaction block.

Backpatch to 9.4 where ALTER SYSTEM was added.

Report by Feike Steenbergen

10 years agoFix inadequately-sized output buffer in contrib/unaccent.
Tom Lane [Tue, 1 Jul 2014 15:22:46 +0000 (11:22 -0400)]
Fix inadequately-sized output buffer in contrib/unaccent.

The output buffer size in unaccent_lexize() was calculated as input string
length times pg_database_encoding_max_length(), which effectively assumes
that replacement strings aren't more than one character.  While that was
all that we previously documented it to support, the code actually has
always allowed replacement strings of arbitrary length; so if you tried
to make use of longer strings, you were at risk of buffer overrun.  To fix,
use an expansible StringInfo buffer instead of trying to determine the
maximum space needed a-priori.

This would be a security issue if unaccent rules files could be installed
by unprivileged users; but fortunately they can't, so in the back branches
the problem can be labeled as improper configuration by a superuser.
Nonetheless, a memory stomp isn't a nice way of reacting to improper
configuration, so let's back-patch the fix.

10 years agopg_upgrade: update C comments about pg_dumpall
Bruce Momjian [Mon, 30 Jun 2014 23:57:47 +0000 (19:57 -0400)]
pg_upgrade:  update C comments about pg_dumpall

There were some C comments that hadn't been updated from the switch of
using only pg_dumpall to using pg_dump and pg_dumpall, so update them.
Also, don't bother using --schema-only for pg_dumpall --globals-only.

Backpatch through 9.4

10 years agoDon't prematurely free the BufferAccessStrategy in pgstat_heap().
Noah Misch [Mon, 30 Jun 2014 20:59:19 +0000 (16:59 -0400)]
Don't prematurely free the BufferAccessStrategy in pgstat_heap().

This function continued to use it after heap_endscan() freed it.  In
passing, don't explicit create a strategy here.  Instead, use the one
created by heap_beginscan_strat(), if any.  Back-patch to 9.2, where use
of a BufferAccessStrategy here was introduced.

10 years agoCheck interrupts during logical decoding more frequently.
Andres Freund [Sun, 29 Jun 2014 15:08:04 +0000 (17:08 +0200)]
Check interrupts during logical decoding more frequently.

When reading large amounts of preexisting WAL during logical decoding
using the SQL interface we possibly could fail to check interrupts in
due time. Similarly the same could happen on systems with a very high
WAL volume while creating a new logical replication slot, independent
of the used interface.

Previously these checks where only performed in xlogreader's read_page
callbacks, while waiting for new WAL to be produced. That's not
sufficient though, if there's never a need to wait.  Walsender's send
loop already contains a interrupt check.

Backpatch to 9.4 where the logical decoding feature was introduced.

10 years agoRevert the assertion of no palloc's in critical section.
Heikki Linnakangas [Mon, 30 Jun 2014 07:23:18 +0000 (10:23 +0300)]
Revert the assertion of no palloc's in critical section.

Per discussion, it still fires too often to be safe to enable in
production. Keep it in master, so that we find the issues, but disable it
in the stable branch.

10 years agoRemove use_json_as_text options from json_to_record/json_populate_record.
Tom Lane [Sun, 29 Jun 2014 17:51:02 +0000 (13:51 -0400)]
Remove use_json_as_text options from json_to_record/json_populate_record.

The "false" case was really quite useless since all it did was to throw
an error; a definition not helped in the least by making it the default.
Instead let's just have the "true" case, which emits nested objects and
arrays in JSON syntax.  We might later want to provide the ability to
emit sub-objects in Postgres record or array syntax, but we'd be best off
to drive that off a check of the target field datatype, not a separate
argument.

For the functions newly added in 9.4, we can just remove the flag arguments
outright.  We can't do that for json_populate_record[set], which already
existed in 9.3, but we can ignore the argument and always behave as if it
were "true".  It helps that the flag arguments were optional and not
documented in any useful fashion anyway.

10 years agoHave multixact be truncated by checkpoint, not vacuum
Alvaro Herrera [Fri, 27 Jun 2014 18:43:52 +0000 (14:43 -0400)]
Have multixact be truncated by checkpoint, not vacuum

Instead of truncating pg_multixact at vacuum time, do it only at
checkpoint time.  The reason for doing it this way is twofold: first, we
want it to delete only segments that we're certain will not be required
if there's a crash immediately after the removal; and second, we want to
do it relatively often so that older files are not left behind if
there's an untimely crash.

Per my proposal in
http://www.postgresql.org/message-id/20140626044519.GJ7340@eldon.alvh.no-ip.org
we now execute the truncation in the checkpointer process rather than as
part of vacuum.  Vacuum is in only charge of maintaining in shared
memory the value to which it's possible to truncate the files; that
value is stored as part of checkpoints also, and so upon recovery we can
reuse the same value to re-execute truncate and reset the
oldest-value-still-safe-to-use to one known to remain after truncation.

Per bug reported by Jeff Janes in the course of his tests involving
bug #8673.

While at it, update some comments that hadn't been updated since
multixacts were changed.

Backpatch to 9.3, where persistency of pg_multixact files was
introduced by commit 0ac5ad5134f2.

10 years agoDon't allow relminmxid to go backwards during VACUUM FULL
Alvaro Herrera [Fri, 27 Jun 2014 18:43:46 +0000 (14:43 -0400)]
Don't allow relminmxid to go backwards during VACUUM FULL

We were allowing a table's pg_class.relminmxid value to move backwards
when heaps were swapped by VACUUM FULL or CLUSTER.  There is a
similar protection against relfrozenxid going backwards, which we
neglected to clone when the multixact stuff was rejiggered by commit
0ac5ad5134f276.

Backpatch to 9.3, where relminmxid was introduced.

As reported by Heikki in
http://www.postgresql.org/message-id/52401AEA.9000608@vmware.com

10 years agoFix broken Assert() introduced by 8e9a16ab8f7f0e58
Alvaro Herrera [Fri, 27 Jun 2014 18:43:39 +0000 (14:43 -0400)]
Fix broken Assert() introduced by 8e9a16ab8f7f0e58

Don't assert MultiXactIdIsRunning if the multi came from a tuple that
had been share-locked and later copied over to the new cluster by
pg_upgrade.  Doing that causes an error to be raised unnecessarily:
MultiXactIdIsRunning is not open to the possibility that its argument
came from a pg_upgraded tuple, and all its other callers are already
checking; but such multis cannot, obviously, have transactions still
running, so the assert is pointless.

Noticed while investigating the bogus pg_multixact/offsets/0000 file
left over by pg_upgrade, as reported by Andres Freund in
http://www.postgresql.org/message-id/20140530121631.GE25431@alap3.anarazel.de

Backpatch to 9.3, as the commit that introduced the buglet.

10 years agoDisallow pushing volatile qual expressions down into DISTINCT subqueries.
Tom Lane [Fri, 27 Jun 2014 18:08:51 +0000 (11:08 -0700)]
Disallow pushing volatile qual expressions down into DISTINCT subqueries.

A WHERE clause applied to the output of a subquery with DISTINCT should
theoretically be applied only once per distinct row; but if we push it
into the subquery then it will be evaluated at each row before duplicate
elimination occurs.  If the qual is volatile this can give rise to
observably wrong results, so don't do that.

While at it, refactor a little bit to allow subquery_is_pushdown_safe
to report more than one kind of restrictive condition without indefinitely
expanding its argument list.

Although this is a bug fix, it seems unwise to back-patch it into released
branches, since it might de-optimize plans for queries that aren't giving
any trouble in practice.  So apply to 9.4 but not further back.

10 years agoGet rid of bogus separate pg_proc entries for json_extract_path operators.
Tom Lane [Thu, 26 Jun 2014 23:22:18 +0000 (16:22 -0700)]
Get rid of bogus separate pg_proc entries for json_extract_path operators.

These should not have existed to begin with, but there was apparently some
misunderstanding of the purpose of the opr_sanity regression test item
that checks for operator implementation functions with their own comments.
The idea there is to check for unintentional violations of the rule that
operator implementation functions shouldn't be documented separately
.... but for these functions, that is in fact what we want, since the
variadic option is useful and not accessible via the operator syntax.
Get rid of the extra pg_proc entries and fix the regression test and
documentation to be explicit about what we're doing here.

10 years agoForward-patch regression test for "could not find pathkey item to sort".
Tom Lane [Thu, 26 Jun 2014 17:40:55 +0000 (10:40 -0700)]
Forward-patch regression test for "could not find pathkey item to sort".

Commit a87c729153e372f3731689a7be007bc2b53f1410 already fixed the bug this
is checking for, but the regression test case it added didn't cover this
scenario.  Since we managed to miss the fact that there was a bug at all,
it seems like a good idea to propagate the extra test case forward to HEAD.

10 years agoRemove obsolete example of CSV log file name from log_filename document.
Fujii Masao [Thu, 26 Jun 2014 05:27:27 +0000 (14:27 +0900)]
Remove obsolete example of CSV log file name from log_filename document.

7380b63 changed log_filename so that epoch was not appended to it
when no format specifier is given. But the example of CSV log file name
with epoch still left in log_filename document. This commit removes
such obsolete example.

This commit also documents the defaults of log_directory and
log_filename.

Backpatch to all supported versions.

Christoph Berg

10 years agoRationalize error messages within jsonfuncs.c.
Tom Lane [Wed, 25 Jun 2014 22:25:26 +0000 (15:25 -0700)]
Rationalize error messages within jsonfuncs.c.

I noticed that the functions in jsonfuncs.c sometimes printed error
messages that claimed I'd called some other function.  Investigation showed
that this was from repurposing code into "worker" functions without taking
much care as to whether it would mention the right SQL-level function if it
threw an error.  Moreover, there was a weird mismash of messages that
contained a fixed function name, messages that used %s for a function name,
and messages that constructed a function name out of spare parts, like
"json%s_populate_record" (which, quite aside from being ugly as sin, wasn't
even sufficient to cover all the cases).  This would put an undue burden on
our long-suffering translators.  Standardize on inserting the SQL function
name with %s so as to reduce the number of translatable strings, and pass
function names around as needed to make sure we can report the right one.
Fix up some gratuitous variations in wording, too.

10 years agoCosmetic improvements in jsonfuncs.c.
Tom Lane [Wed, 25 Jun 2014 18:22:21 +0000 (11:22 -0700)]
Cosmetic improvements in jsonfuncs.c.

Re-pgindent, remove a lot of random vertical whitespace, remove useless
(if not counterproductive) inline markings, get rid of unnecessary
zero-padding of strings for hashtable searches.  No functional changes.

10 years agoFix handling of nested JSON objects in json_populate_recordset and friends.
Tom Lane [Wed, 25 Jun 2014 04:22:43 +0000 (21:22 -0700)]
Fix handling of nested JSON objects in json_populate_recordset and friends.

populate_recordset_object_start() improperly created a new hash table
(overwriting the link to the existing one) if called at nest levels
greater than one.  This resulted in previous fields not appearing in
the final output, as reported by Matti Hameister in bug #10728.
In 9.4 the problem also affects json_to_recordset.

This perhaps missed detection earlier because the default behavior is to
throw an error for nested objects: you have to pass use_json_as_text = true
to see the problem.

In addition, fix query-lifespan leakage of the hashtable created by
json_populate_record().  This is pretty much the same problem recently
fixed in dblink: creating an intended-to-be-temporary context underneath
the executor's per-tuple context isn't enough to make it go away at the
end of the tuple cycle, because MemoryContextReset is not
MemoryContextResetAndDeleteChildren.

Michael Paquier and Tom Lane

10 years agopg_upgrade: remove pg_multixact files left by initdb
Bruce Momjian [Tue, 24 Jun 2014 20:11:06 +0000 (16:11 -0400)]
pg_upgrade:  remove pg_multixact files left by initdb

This fixes a bug that caused vacuum to fail when the '0000' files left
by initdb were accessed as part of vacuum's cleanup of old pg_multixact
files.

Backpatch through 9.3

10 years agoDon't allow foreign tables with OIDs.
Heikki Linnakangas [Tue, 24 Jun 2014 09:31:36 +0000 (12:31 +0300)]
Don't allow foreign tables with OIDs.

The syntax doesn't let you specify "WITH OIDS" for foreign tables, but it
was still possible with default_with_oids=true. But the rest of the system,
including pg_dump, isn't prepared to handle foreign tables with OIDs
properly.

Backpatch down to 9.1, where foreign tables were introduced. It's possible
that there are databases out there that already have foreign tables with
OIDs. There isn't much we can do about that, but at least we can prevent
them from being created in the future.

Patch by Etsuro Fujita, reviewed by Hadi Moshayedi.

10 years agoFix typo in replication slot function doc.
Fujii Masao [Mon, 23 Jun 2014 18:51:51 +0000 (03:51 +0900)]
Fix typo in replication slot function doc.

10 years agoAdd missing closing parenthesis into max_replication_slots doc.
Fujii Masao [Mon, 23 Jun 2014 18:25:01 +0000 (03:25 +0900)]
Add missing closing parenthesis into max_replication_slots doc.

10 years agodoc: adjust JSONB GIN index description
Bruce Momjian [Sat, 21 Jun 2014 19:33:22 +0000 (15:33 -0400)]
doc:  adjust JSONB GIN index description

Backpatch through 9.4

10 years ago9.4 release notes: adjust some entry wording
Bruce Momjian [Sat, 21 Jun 2014 14:56:37 +0000 (10:56 -0400)]
9.4 release notes:  adjust some entry wording

Backpatch to 9.4

10 years agoFix documentation template for CREATE TRIGGER.
Kevin Grittner [Sat, 21 Jun 2014 14:17:14 +0000 (09:17 -0500)]
Fix documentation template for CREATE TRIGGER.

By using curly braces, the template had specified that one of
"NOT DEFERRABLE", "INITIALLY IMMEDIATE", or "INITIALLY DEFERRED"
was required on any CREATE TRIGGER statement, which is not
accurate.  Change to square brackets makes that optional.

Backpatch to 9.1, where the error was introduced.

10 years agoClean up data conversion short-lived memory context.
Joe Conway [Fri, 20 Jun 2014 19:22:34 +0000 (12:22 -0700)]
Clean up data conversion short-lived memory context.

dblink uses a short-lived data conversion memory context. However it
was not deleted when no longer needed, leading to a noticeable memory
leak under some circumstances. Plug the hole, along with minor
refactoring. Backpatch to 9.2 where the leak was introduced.

Report and initial patch by MauMau. Reviewed/modified slightly by
Tom Lane and me.

10 years agoDo all-visible handling in lazy_vacuum_page() outside its critical section.
Andres Freund [Fri, 20 Jun 2014 09:06:48 +0000 (11:06 +0200)]
Do all-visible handling in lazy_vacuum_page() outside its critical section.

Since fdf9e21196a lazy_vacuum_page() rechecks the all-visible status
of pages in the second pass over the heap. It does so inside a
critical section, but both visibilitymap_test() and
heap_page_is_all_visible() perform operations that should not happen
inside one. The former potentially performs IO and both potentially do
memory allocations.

To fix, simply move all the all-visible handling outside the critical
section. Doing so means that the PD_ALL_VISIBLE on the page won't be
included in the full page image of the HEAP2_CLEAN record anymore. But
that's fine, the flag will be set by the HEAP2_VISIBLE logged later.

Backpatch to 9.3 where the problem was introduced. The bug only came
to light due to the assertion added in 4a170ee9 and isn't likely to
cause problems in production scenarios. The worst outcome is a
avoidable PANIC restart.

This also gets rid of the difference in the order of operations
between master and standby mentioned in 2a8e1ac5.

Per reports from David Leverton and Keith Fiske in bug #10533.

10 years agoAvoid leaking memory while evaluating arguments for a table function.
Tom Lane [Fri, 20 Jun 2014 02:13:44 +0000 (22:13 -0400)]
Avoid leaking memory while evaluating arguments for a table function.

ExecMakeTableFunctionResult evaluated the arguments for a function-in-FROM
in the query-lifespan memory context.  This is insignificant in simple
cases where the function relation is scanned only once; but if the function
is in a sub-SELECT or is on the inside of a nested loop, any memory
consumed during argument evaluation can add up quickly.  (The potential for
trouble here had been foreseen long ago, per existing comments; but we'd
not previously seen a complaint from the field about it.)  To fix, create
an additional temporary context just for this purpose.

Per an example from MauMau.  Back-patch to all active branches.

10 years agoDocument SQL functions' behavior of parsing the whole function at once.
Tom Lane [Thu, 19 Jun 2014 16:33:56 +0000 (12:33 -0400)]
Document SQL functions' behavior of parsing the whole function at once.

Haribabu Kommi, somewhat rewritten by me

10 years agoFix calculation of PREDICATELOCK_MANAGER_LWLOCK_OFFSET.
Kevin Grittner [Thu, 19 Jun 2014 13:51:54 +0000 (08:51 -0500)]
Fix calculation of PREDICATELOCK_MANAGER_LWLOCK_OFFSET.

Commit ea9df812d8502fff74e7bc37d61bdc7d66d77a7f failed to include
NUM_BUFFER_PARTITIONS in this offset, resulting in a bad offset.
Ultimately this threw off NUM_FIXED_LWLOCKS which is based on
earlier offsets, leading to memory allocation problems.  It seems
likely to have also caused increased LWLOCK contention when
serializable transactions were used, because lightweight locks used
for that overlapped others.

Reported by Amit Kapila with analysis and fix.
Backpatch to 9.4, where the bug was introduced.

10 years agoDon't allow data_directory to be set in postgresql.auto.conf by ALTER SYSTEM.
Fujii Masao [Thu, 19 Jun 2014 11:31:20 +0000 (20:31 +0900)]
Don't allow data_directory to be set in postgresql.auto.conf by ALTER SYSTEM.

data_directory could be set both in postgresql.conf and postgresql.auto.conf so far.
This could cause some problematic situations like circular definition. To avoid such
situations, this commit forbids a user to set data_directory in postgresql.auto.conf.

Backpatch this to 9.4 where ALTER SYSTEM command was introduced.

Amit Kapila, reviewed by Abhijit Menon-Sen, with minor adjustments by me.

10 years agoRemove unnecessary check for jbvBinary in convertJsonbValue.
Andrew Dunstan [Wed, 18 Jun 2014 23:28:20 +0000 (19:28 -0400)]
Remove unnecessary check for jbvBinary in convertJsonbValue.

The check was confusing and is a condition that should never in fact
happen.

Per gripe from Dmitry Dolgov.

10 years agoFix weird spacing in error message.
Tom Lane [Wed, 18 Jun 2014 19:44:15 +0000 (15:44 -0400)]
Fix weird spacing in error message.

Seems to have been introduced in 1a3458b6d8d202715a83c88474a1b63726d0929e.

10 years agoDocument that jsonb has all the standard comparison operators.
Andrew Dunstan [Wed, 18 Jun 2014 19:16:48 +0000 (15:16 -0400)]
Document that jsonb has all the standard comparison operators.

10 years agoFix the MSVC build process for uuid-ossp.
Noah Misch [Wed, 18 Jun 2014 13:21:50 +0000 (09:21 -0400)]
Fix the MSVC build process for uuid-ossp.

Catch up with commit b8cc8f94730610c0189aa82dfec4ae6ce9b13e34's
introduction of the HAVE_UUID_OSSP symbol to the principal build
process.  Back-patch to 9.4, where that commit appeared.

10 years ago9.4 release notes: improve valgrind mention
Bruce Momjian [Tue, 17 Jun 2014 15:28:34 +0000 (11:28 -0400)]
9.4 release notes: improve valgrind mention

Report by Peter Geoghegan

10 years agoUse type pgsocket for Windows pipe emulation socket calls
Bruce Momjian [Mon, 16 Jun 2014 19:33:19 +0000 (15:33 -0400)]
Use type pgsocket for Windows pipe emulation socket calls

This prevents several compiler warnings on Windows.

10 years agoSecure Unix-domain sockets of "make check" temporary clusters.
Noah Misch [Sat, 14 Jun 2014 13:41:13 +0000 (09:41 -0400)]
Secure Unix-domain sockets of "make check" temporary clusters.

Any OS user able to access the socket can connect as the bootstrap
superuser and proceed to execute arbitrary code as the OS user running
the test.  Protect against that by placing the socket in a temporary,
mode-0700 subdirectory of /tmp.  The pg_regress-based test suites and
the pg_upgrade test suite were vulnerable; the $(prove_check)-based test
suites were already secure.  Back-patch to 8.4 (all supported versions).
The hazard remains wherever the temporary cluster accepts TCP
connections, notably on Windows.

As a convenient side effect, this lets testing proceed smoothly in
builds that override DEFAULT_PGSOCKET_DIR.  Popular non-default values
like /var/run/postgresql are often unwritable to the build user.

Security: CVE-2014-0067

10 years agoAdd mkdtemp() to libpgport.
Noah Misch [Sat, 14 Jun 2014 13:41:13 +0000 (09:41 -0400)]
Add mkdtemp() to libpgport.

This function is pervasive on free software operating systems; import
NetBSD's implementation.  Back-patch to 8.4, like the commit that will
harness it.

10 years agoHarden pg_filenode_relation test against concurrent DROP TABLE.
Noah Misch [Fri, 13 Jun 2014 23:57:59 +0000 (19:57 -0400)]
Harden pg_filenode_relation test against concurrent DROP TABLE.

Per buildfarm member prairiedog.  Back-patch to 9.4, where the test was
introduced.

Reviewed by Tom Lane.

10 years agoAdjust 9.4 release notes.
Noah Misch [Fri, 13 Jun 2014 23:57:41 +0000 (19:57 -0400)]
Adjust 9.4 release notes.

Back-patch to 9.4.

10 years agoemacs.samples: Reliably override ".dir-locals.el".
Noah Misch [Fri, 13 Jun 2014 23:57:18 +0000 (19:57 -0400)]
emacs.samples: Reliably override ".dir-locals.el".

Back-patch to 9.4, where .dir-locals.el was introduced.

10 years agoFix pg_restore's processing of old-style BLOB COMMENTS data.
Tom Lane [Fri, 13 Jun 2014 00:14:36 +0000 (20:14 -0400)]
Fix pg_restore's processing of old-style BLOB COMMENTS data.

Prior to 9.0, pg_dump handled comments on large objects by dumping a bunch
of COMMENT commands into a single BLOB COMMENTS archive object.  With
sufficiently many such comments, some of the commands would likely get
split across bufferloads when restoring, causing failures in
direct-to-database restores (though no problem would be evident in text
output).  This is the same type of issue we have with table data dumped as
INSERT commands, and it can be fixed in the same way, by using a mini SQL
lexer to figure out where the command boundaries are.  Fortunately, the
COMMENT commands are no more complex to lex than INSERTs, so we can just
re-use the existing lexer for INSERTs.

Per bug #10611 from Jacek Zalewski.  Back-patch to all active branches.

10 years agoImprove tuplestore's error messages for I/O failures.
Tom Lane [Thu, 12 Jun 2014 22:59:06 +0000 (18:59 -0400)]
Improve tuplestore's error messages for I/O failures.

We should report the errno when we get a failure from functions like
BufFileWrite.  "ERROR: write failed" is unreasonably taciturn for a
case that's well within the realm of possibility; I've seen it a
couple times in the buildfarm recently, in situations that were
probably out-of-disk-space, but it'd be good to see the errno
to confirm it.

I think this code was originally written without assuming that
the buffile.c functions would return useful errno; but most other
callers *are* assuming that, and a quick look at the buffile code
gives no reason to suppose otherwise.

Also, a couple of the old messages were phrased on the assumption
that a short read might indicate a logic bug in tuplestore itself;
but that code's pretty well tested by now, so a filesystem-level
problem seems much more likely.

10 years agoAdjust largeobject regression test to leave a couple of LOs behind.
Tom Lane [Thu, 12 Jun 2014 21:51:47 +0000 (17:51 -0400)]
Adjust largeobject regression test to leave a couple of LOs behind.

Since we commonly test pg_dump/pg_restore by seeing whether they can dump
and restore the regression test database, it behooves us to include some
large objects in that test scenario.

I tried to include a comment on one of these large objects to improve
the test scenario further ... but it turns out that pg_upgrade fails to
preserve comments on large objects, and its regression test notices
the discrepancy.  So uncommenting that COMMENT is a TODO for later.

10 years agoRemove inadvertent copyright violation in largeobject regression test.
Tom Lane [Thu, 12 Jun 2014 20:51:05 +0000 (16:51 -0400)]
Remove inadvertent copyright violation in largeobject regression test.

Robert Frost is no longer with us, but his copyrights still are, so
let's stop using "Stopping by Woods on a Snowy Evening" as test data
before somebody decides to sue us.  Wordsworth is more safely dead.

10 years agoAdd regression test to prevent future breakage of legacy query in libpq.
Tom Lane [Thu, 12 Jun 2014 19:54:13 +0000 (15:54 -0400)]
Add regression test to prevent future breakage of legacy query in libpq.

Memorialize the expected output of the query that libpq has been using for
many years to get the OIDs of large-object support functions.  Although
we really ought to change the way libpq does this, we must expect that
this query will remain in use in the field for the foreseeable future,
so until we're ready to break compatibility with old libpq versions
we'd better check the results stay the same.  See the recent lo_create()
fiasco.

10 years agoRename lo_create(oid, bytea) to lo_from_bytea().
Tom Lane [Thu, 12 Jun 2014 19:39:09 +0000 (15:39 -0400)]
Rename lo_create(oid, bytea) to lo_from_bytea().

The previous naming broke the query that libpq's lo_initialize() uses
to collect the OIDs of the server-side functions it requires, because
that query effectively assumes that there is only one function named
lo_create in the pg_catalog schema (and likewise only one lo_open, etc).

While we should certainly make libpq more robust about this, the naive
query will remain in use in the field for the foreseeable future, so it
seems the only workable choice is to use a different name for the new
function.  lo_from_bytea() won a small straw poll.

Back-patch into 9.4 where the new function was introduced.

10 years agoConsistency improvements for slot and decoding code.
Andres Freund [Thu, 12 Jun 2014 11:23:46 +0000 (13:23 +0200)]
Consistency improvements for slot and decoding code.

Change the order of checks in similar functions to be the same; remove
a parameter that's not needed anymore; rename a memory context and
expand a couple of comments.

Per review comments from Amit Kapila

10 years agoFix ancient encoding error in hungarian.stop.
Tom Lane [Wed, 11 Jun 2014 02:48:16 +0000 (22:48 -0400)]
Fix ancient encoding error in hungarian.stop.

When we grabbed this file off the Snowball project's website, we mistakenly
supposed that it was in LATIN1 encoding, but evidently it was actually in
LATIN2.  This resulted in ő (o-double-acute, U+0151, which is code 0xF5 in
LATIN2) being misconverted into õ (o-tilde, U+00F5), as complained of in
bug #10589 from Zoltán Sörös.  We'd have messed up u-double-acute too,
but there aren't any of those in the file.  Other characters used in the
file have the same codes in LATIN1 and LATIN2, which no doubt helped hide
the problem for so long.

The error is not only ours: the Snowball project also was confused about
which encoding is required for Hungarian.  But dealing with that will
require source-code changes that I'm not at all sure we'll wish to
back-patch.  Fixing the stopword file seems reasonably safe to back-patch
however.

10 years agoForward-port regression test for bug #10587 into 9.3 and HEAD.
Tom Lane [Tue, 10 Jun 2014 01:37:18 +0000 (21:37 -0400)]
Forward-port regression test for bug #10587 into 9.3 and HEAD.

Although this bug is already fixed in post-9.2 branches, the case
triggering it is quite different from what was under consideration
at the time.  It seems worth memorializing this example in HEAD
just to make sure it doesn't get broken again in future.

Extracted from commit 187ae17300776f48b2bd9d0737923b1bf70f606e.

10 years agoFix infinite loop when splitting inner tuples in SPGiST text indexes.
Tom Lane [Mon, 9 Jun 2014 20:30:40 +0000 (16:30 -0400)]
Fix infinite loop when splitting inner tuples in SPGiST text indexes.

Previously, the code used a node label of zero both for strings that
contain no bytes beyond the inner tuple's prefix, and for cases where an
"allTheSame" inner tuple has to be split to allow a string with a different
next byte to be inserted into it.  Failing to distinguish these cases meant
that if a string ending with the current prefix needed to be inserted into
an allTheSame tuple, we got into an infinite loop, because after splitting
the tuple we'd descend into the child allTheSame tuple and then find we
need to split again.

To fix, instead use -1 and -2 as the node labels for these two cases.
This requires widening the node label type from "char" to int2, but
fortunately SPGiST stores all pass-by-value node label types in their
Datum representation, which means that this change is transparently upward
compatible so far as the on-disk representation goes.  We continue to
recognize zero as a dummy node label for reading purposes, but will not
attempt to push new index entries down into such a label, so that the loop
won't occur even when dealing with an existing index.

Per report from Teodor Sigaev.  Back-patch to 9.2 where the faulty
code was introduced.

10 years agoWrap multixact/members correctly during extension, take 2
Alvaro Herrera [Mon, 9 Jun 2014 19:17:23 +0000 (15:17 -0400)]
Wrap multixact/members correctly during extension, take 2

In a50d97625497b7 I already changed this, but got it wrong for the case
where the number of members is larger than the number of entries that
fit in the last page of the last segment.

As reported by Serge Negodyuck in a followup to bug #8673.

10 years agoFix off-by-one in decoding causing one-record events to be skipped.
Andres Freund [Thu, 5 Jun 2014 16:27:11 +0000 (18:27 +0200)]
Fix off-by-one in decoding causing one-record events to be skipped.

A ReorderBufferTransaction's end_lsn, the sentPtr advocated by
walsender keepalive messages, and the end location remembered by the
decoding get_*changes* SQL functions all use the location of the last
read record + 1. I.e. the LSN points to the beginning of the next
record. That cannot realistically be changed without changing the
replication protocol because that's how keepalive messages have worked
since 9.0.
The bug is that the logic inside the snapshot builder, which decides
whether a transaction's contents should be decoded, assumed the start
location would point towards the last byte of the last record. The
reason this didn't actually cause visible problems is that currently
that decision is only made for commit records. Since interesting
transactions always have at least one additional record - containing
actual data - we'd never skip a transaction.
But if there ever were transactions, or other events, with just one
record containing important information, we'd skip them after stopping
and restarting logical decoding.

10 years agoAdd defenses against running with a wrong selection of LOBLKSIZE.
Tom Lane [Thu, 5 Jun 2014 15:31:06 +0000 (11:31 -0400)]
Add defenses against running with a wrong selection of LOBLKSIZE.

It's critical that the backend's idea of LOBLKSIZE match the way data has
actually been divided up in pg_largeobject.  While we don't provide any
direct way to adjust that value, doing so is a one-line source code change
and various people have expressed interest recently in changing it.  So,
just as with TOAST_MAX_CHUNK_SIZE, it seems prudent to record the value in
pg_control and cross-check that the backend's compiled-in setting matches
the on-disk data.

Also tweak the code in inv_api.c so that fetches from pg_largeobject
explicitly verify that the length of the data field is not more than
LOBLKSIZE.  Formerly we just had Asserts() for that, which is no protection
at all in production builds.  In some of the call sites an overlength data
value would translate directly to a security-relevant stack clobber, so it
seems worth one extra runtime comparison to be sure.

In the back branches, we can't change the contents of pg_control; but we
can still make the extra checks in inv_api.c, which will offer some amount
of protection against running with the wrong value of LOBLKSIZE.

10 years agoConsistently spell a replication slot's name as slot_name.
Andres Freund [Thu, 5 Jun 2014 14:29:20 +0000 (16:29 +0200)]
Consistently spell a replication slot's name as slot_name.

Previously there's been a mix between 'slotname' and 'slot_name'. It's
not nice to be unneccessarily inconsistent in a new feature. As a post
beta1 initdb now is required in the wake of eeca4cd35e, fix the
inconsistencies.
Most the changes won't affect usage of replication slots because the
majority of changes is around function parameter names. The prominent
exception to that is that the recovery.conf parameter
'primary_slotname' is now named 'primary_slot_name'.

10 years agoMove regression test listing of builtin leakproof functions to opr_sanity.sql.
Andres Freund [Thu, 5 Jun 2014 11:54:16 +0000 (13:54 +0200)]
Move regression test listing of builtin leakproof functions to opr_sanity.sql.

The original location in create_function_3.sql didn't invite the close
structinity warranted for adding new leakproof functions. Add comments
to the test explaining that functions should only be added after
careful consideration and understanding what a leakproof function is.

Per complaint from Tom Lane after 5eebb8d954ad.

10 years agoAdjust SP-GiST WAL record formats to reduce alignment padding.
Heikki Linnakangas [Thu, 5 Jun 2014 09:55:35 +0000 (12:55 +0300)]
Adjust SP-GiST WAL record formats to reduce alignment padding.

The way the code was written, the padding was copied from uninitialized
memory areas.. Because the structs are local variables in the code where
the WAL records are constructed, making them larger and zeroing the padding
bytes would not make the code very pretty, so rather than fixing this
directly by zeroing out the padding bytes, it seems more clear to not try to
align the tuples in the WAL records. The redo functions are taught to copy
the tuple header to a local variable to avoid unaligned access.

Stable-branches have the same problem, but we can't change the WAL format
there, so fix in master only. Reading a few random extra bytes at the stack
is harmless in practice, so it's not worth crafting a different
back-patchable fix.

Per reports from Kevin Grittner and Andres Freund, using clang static
analyzer and Valgrind, respectively.

10 years agoTweak new regression test case for better portability.
Tom Lane [Thu, 5 Jun 2014 01:31:41 +0000 (21:31 -0400)]
Tweak new regression test case for better portability.

Buildfarm says we get different plans on 32-bit and 64-bit platforms,
probably because of MAXALIGN-related differences in memory-consumption
calculations.  Add some dummy WHERE clauses so that the planner estimates
different sizes for the three generate_series() relations; that should
stabilize the choice of join order.