]> granicus.if.org Git - postgresql/log
postgresql
8 years agoUpdate more comments for 96198d94cb7adc664bda341842dc8db671d8be72.
Robert Haas [Mon, 14 Mar 2016 18:27:11 +0000 (14:27 -0400)]
Update more comments for 96198d94cb7adc664bda341842dc8db671d8be72.

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

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

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

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

Dagfinn Ilmari Mannsåker

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

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

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

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

I didn't bother with a catversion bump.

Report and patch by Thomas Munro

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

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

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

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

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

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

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

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

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

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

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

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

Per suggestion from Tomas Vondra

Author: Julien Rouhaud

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

Noted by Tomas Vondra

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Konstantin Knizhnik, heavily rewritten by me

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

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

Author: Stas Kelvich

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

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

Author: Artur Zakirov

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

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

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

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

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

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

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

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

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

Author: Craig Ringer and Julien Rouhaud
Review: Petr Jelinek

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

Andreas Karlsson and Robert Haas

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

Per Amit Kapila.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Patch by me, reviewed by Masahiko Sawada.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Author: Christian Ullrich

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

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

Pavan Deolasee, reviewed by Petr Jelinek

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

Fabrízio de Royes Mello and Simon Riggs

8 years agoCode review for b6fb6471f6afaf649e52f38269fd8c5c60647669.
Robert Haas [Thu, 10 Mar 2016 11:07:57 +0000 (06:07 -0500)]
Code review for b6fb6471f6afaf649e52f38269fd8c5c60647669.

Reports by Tomas Vondra, Vinayak Pokale, and Aleksander Alekseev.
Patch by Amit Langote.

8 years agoRemove a couple of useless pstrdup() calls.
Tom Lane [Thu, 10 Mar 2016 04:29:05 +0000 (23:29 -0500)]
Remove a couple of useless pstrdup() calls.

There's no point in pstrdup'ing the result of TextDatumGetCString,
since that's necessarily already a freshly-palloc'd C string.

These particular calls are unlikely to be of any consequence
performance-wise, but still they're a bad precedent that can confuse
future patch authors.

Noted by Chapman Flack.

8 years agoAvoid unlikely data-loss scenarios due to rename() without fsync.
Andres Freund [Thu, 10 Mar 2016 02:53:53 +0000 (18:53 -0800)]
Avoid unlikely data-loss scenarios due to rename() without fsync.

Renaming a file using rename(2) is not guaranteed to be durable in face
of crashes. Use the previously added durable_rename()/durable_link_or_rename()
in various places where we previously just renamed files.

Most of the changed call sites are arguably not critical, but it seems
better to err on the side of too much durability.  The most prominent
known case where the previously missing fsyncs could cause data loss is
crashes at the end of a checkpoint. After the actual checkpoint has been
performed, old WAL files are recycled. When they're filled, their
contents are fdatasynced, but we did not fsync the containing
directory. An OS/hardware crash in an unfortunate moment could then end
up leaving that file with its old name, but new content; WAL replay
would thus not replay it.

Reported-By: Tomas Vondra
Author: Michael Paquier, Tomas Vondra, Andres Freund
Discussion: 56583BDD.9060302@2ndquadrant.com
Backpatch: All supported branches

8 years agoIntroduce durable_rename() and durable_link_or_rename().
Andres Freund [Thu, 10 Mar 2016 02:53:53 +0000 (18:53 -0800)]
Introduce durable_rename() and durable_link_or_rename().

Renaming a file using rename(2) is not guaranteed to be durable in face
of crashes; especially on filesystems like xfs and ext4 when mounted
with data=writeback. To be certain that a rename() atomically replaces
the previous file contents in the face of crashes and different
filesystems, one has to fsync the old filename, rename the file, fsync
the new filename, fsync the containing directory.  This sequence is not
generally adhered to currently; which exposes us to data loss risks. To
avoid having to repeat this arduous sequence, introduce
durable_rename(), which wraps all that.

Also add durable_link_or_rename(). Several places use link() (with a
fallback to rename()) to rename a file, trying to avoid replacing the
target file out of paranoia. Some of those rename sequences need to be
durable as well. There seems little reason extend several copies of the
same logic, so centralize the link() callers.

This commit does not yet make use of the new functions; they're used in
a followup commit.

Author: Michael Paquier, Andres Freund
Discussion: 56583BDD.9060302@2ndquadrant.com
Backpatch: All supported branches

8 years agodoc: Reorganize pg_resetxlog reference page
Peter Eisentraut [Mon, 29 Feb 2016 23:48:34 +0000 (18:48 -0500)]
doc: Reorganize pg_resetxlog reference page

The pg_resetxlog reference page didn't have a proper options list, only
running text listing the options and some explanations of them.  This
might have worked when there were only a few options, but the list has
grown over the releases, and now it's hard to find an option and its
associated explanation.  So write out the options list as on other
reference pages.

8 years agoPostgresNode: add backup_fs_hot and backup_fs_cold
Alvaro Herrera [Wed, 9 Mar 2016 22:54:03 +0000 (19:54 -0300)]
PostgresNode: add backup_fs_hot and backup_fs_cold

These simple methods rely on RecursiveCopy to create a filesystem-level
backup of a server.  They aren't currently used anywhere yet,but will be
useful for future tests.

Author: Craig Ringer
Reviewed-By: Michael Paquier, Salvador Fandino, Álvaro Herrera
Commitfest-URL: https://commitfest.postgresql.org/9/569/

8 years agoAdd filter capability to RecursiveCopy::copypath
Alvaro Herrera [Wed, 9 Mar 2016 21:00:31 +0000 (18:00 -0300)]
Add filter capability to RecursiveCopy::copypath

This allows skipping copying certain files and subdirectories in tests.
This is useful in some circumstances such as copying a data directory;
future tests want this feature.

Also POD-ify the module.

Authors: Craig Ringer, Pallavi Sontakke
Reviewed-By: Álvaro Herrera
8 years agoFix incorrect handling of NULL index entries in indexed ROW() comparisons.
Tom Lane [Wed, 9 Mar 2016 19:51:01 +0000 (14:51 -0500)]
Fix incorrect handling of NULL index entries in indexed ROW() comparisons.

An index search using a row comparison such as ROW(a, b) > ROW('x', 'y')
would stop upon reaching a NULL entry in the "b" column, ignoring the
fact that there might be non-NULL "b" values associated with later values
of "a".  This happens because _bt_mark_scankey_required() marks the
subsidiary scankey for "b" as required, which is just wrong: it's for
a column after the one with the first inequality key (namely "a"), and
thus can't be considered a required match.

This bit of brain fade dates back to the very beginnings of our support
for indexed ROW() comparisons, in 2006.  Kind of astonishing that no one
came across it before Glen Takahashi, in bug #14010.

Back-patch to all supported versions.

Note: the given test case doesn't actually fail in unpatched 9.1, evidently
because the fix for bug #6278 (i.e., stopping at nulls in either scan
direction) is required to make it fail.  I'm sure I could devise a case
that fails in 9.1 as well, perhaps with something involving making a cursor
back up; but it doesn't seem worth the trouble.

8 years agoRe-pgindent vacuumlazy.c.
Robert Haas [Wed, 9 Mar 2016 18:50:31 +0000 (13:50 -0500)]
Re-pgindent vacuumlazy.c.

8 years agopgbench: When -T is used, don't wait for transactions beyond end of run.
Robert Haas [Wed, 9 Mar 2016 18:09:12 +0000 (13:09 -0500)]
pgbench: When -T is used, don't wait for transactions beyond end of run.

At low rates, this can lead to pgbench taking significantly longer to
terminate than the user might expect.  Repair.

Fabien Coelho, reviewed by Aleksander Alekseev, Álvaro Herrera, and me.

8 years agopgcrypto: support changing S2K iteration count
Alvaro Herrera [Wed, 9 Mar 2016 17:31:07 +0000 (14:31 -0300)]
pgcrypto: support changing S2K iteration count

pgcrypto already supports key-stretching during symmetric encryption,
including the salted-and-iterated method; but the number of iterations
was not configurable.  This commit implements a new s2k-count parameter
to pgp_sym_encrypt() which permits selecting a larger number of
iterations.

Author: Jeff Janes

8 years agoAdd a generic command progress reporting facility.
Robert Haas [Wed, 9 Mar 2016 17:08:58 +0000 (12:08 -0500)]
Add a generic command progress reporting facility.

Using this facility, any utility command can report the target relation
upon which it is operating, if there is one, and up to 10 64-bit
counters; the intent of this is that users should be able to figure out
what a utility command is doing without having to resort to ugly hacks
like attaching strace to a backend.

As a demonstration, this adds very crude reporting to lazy vacuum; we
just report the target relation and nothing else.  A forthcoming patch
will make VACUUM report a bunch of additional data that will make this
much more interesting.  But this gets the basic framework in place.

Vinayak Pokale, Rahila Syed, Amit Langote, Robert Haas, reviewed by
Kyotaro Horiguchi, Jim Nasby, Thom Brown, Masahiko Sawada, Fujii Masao,
and Masanori Oyama.

8 years agoFix incorrect tlist generation in create_gather_plan().
Tom Lane [Wed, 9 Mar 2016 15:56:36 +0000 (10:56 -0500)]
Fix incorrect tlist generation in create_gather_plan().

This function is written as though Gather doesn't project; but it does.
Even if it did not project, though, we must use build_path_tlist to ensure
that the output columns receive correct sortgroupref labeling.

Per report from Amit Kapila.

8 years agopostgres_fdw: Consider foreign joining and foreign sorting together.
Robert Haas [Wed, 9 Mar 2016 15:51:49 +0000 (10:51 -0500)]
postgres_fdw: Consider foreign joining and foreign sorting together.

Commit ccd8f97922944566d26c7d90eb67ab7848ee9905 gave us the ability to
request that the remote side sort the data, and, later, commit
e4106b2528727c4b48639c0e12bf2f70a766b910 gave us the ability to
request that the remote side perform the join for us rather than doing
it locally.  But we could not do both things at the same time: a
remote SQL query that had an ORDER BY clause would never be a join.
This commit adds that capability.

Ashutosh Bapat, reviewed by me.

8 years agoFix copy-and-pasteo in comment.
Tom Lane [Wed, 9 Mar 2016 15:29:14 +0000 (10:29 -0500)]
Fix copy-and-pasteo in comment.

Wensheng Zhang

8 years agoImprove handling of pathtargets in planner.c.
Tom Lane [Wed, 9 Mar 2016 06:12:16 +0000 (01:12 -0500)]
Improve handling of pathtargets in planner.c.

Refactor so that the internal APIs in planner.c deal in PathTargets not
targetlists, and establish a more regular structure for deriving the
targets needed for successive steps.

There is more that could be done here; calculating the eval costs of each
successive target independently is both inefficient and wrong in detail,
since we won't actually recompute values available from the input node's
tlist.  But it's no worse than what happened before the pathification
rewrite.  In any case this seems like a good starting point for considering
how to handle Konstantin Knizhnik's function-evaluation-postponement patch.

8 years agoAdd valgrind suppressions for python code.
Andres Freund [Wed, 9 Mar 2016 01:34:09 +0000 (17:34 -0800)]
Add valgrind suppressions for python code.

Python's allocator does some low-level tricks for efficiency;
unfortunately they trigger valgrind errors. Those tricks can be disabled
making instrumentation easier; but few people testing postgres will have
such a build of python. So add broad suppressions of the resulting
errors.

See also https://svn.python.org/projects/python/trunk/Misc/README.valgrind

This possibly will suppress valid errors, but without it it's basically
impossible to use valgrind with plpython code.

Author: Andres Freund
Backpatch: 9.4, where we started to maintain valgrind suppressions

8 years agoAdd valgrind suppressions for bootstrap related code.
Andres Freund [Wed, 9 Mar 2016 03:21:28 +0000 (19:21 -0800)]
Add valgrind suppressions for bootstrap related code.

Author: Andres Freund
Backpatch: 9.4, where we started to maintain valgrind suppressions

8 years agoImprove handling of group-column indexes in GroupingSetsPath.
Tom Lane [Wed, 9 Mar 2016 03:32:03 +0000 (22:32 -0500)]
Improve handling of group-column indexes in GroupingSetsPath.

Instead of having planner.c compute a groupColIdx array and store it in
GroupingSetsPaths, make create_groupingsets_plan() find the grouping
columns by searching in the child plan node's tlist.  Although that's
probably a bit slower for create_groupingsets_plan(), it's more like
the way every other plan node type does this, and it provides positive
confirmation that we know which child output columns we're supposed to be
grouping on.  (Indeed, looking at this now, I'm not at all sure that it
wasn't broken before, because create_groupingsets_plan() isn't demanding
an exact tlist match from its child node.)  Also, this allows substantial
simplification in planner.c, because it no longer needs to compute the
groupColIdx array at all; no other cases were using it.

I'd intended to put off this refactoring until later (like 9.7), but
in view of the likely bug fix and the need to rationalize planner.c's
tlist handling so we can do something sane with Konstantin Knizhnik's
function-evaluation-postponement patch, I think it can't wait.

8 years agoHandle invalid libpq sockets in more places
Peter Eisentraut [Wed, 9 Mar 2016 02:10:33 +0000 (21:10 -0500)]
Handle invalid libpq sockets in more places

Also, make error messages consistent.

From: Michael Paquier <michael.paquier@gmail.com>

8 years agoSuppress GCC 6 warning about self-comparison
Peter Eisentraut [Sat, 20 Feb 2016 04:07:46 +0000 (23:07 -0500)]
Suppress GCC 6 warning about self-comparison

Reviewed-by: Thomas Munro <thomas.munro@enterprisedb.com>
8 years agopsql: Fix some strange code in SQL help creation
Peter Eisentraut [Sat, 20 Feb 2016 04:07:46 +0000 (23:07 -0500)]
psql: Fix some strange code in SQL help creation

Struct QL_HELP used to be defined as static in the sql_help.h header
file, which is included in sql_help.c and help.c, thus creating two
separate instances of the struct.  This causes a warning from GCC 6,
because the struct is not used in sql_help.c.

Instead, declare the struct as extern in the header file and define it
in sql_help.c.  This also allows making a bunch of functions static
because they are no longer needed outside of sql_help.c.

Reviewed-by: Thomas Munro <thomas.munro@enterprisedb.com>
8 years agoecpg: Fix typo
Peter Eisentraut [Sat, 20 Feb 2016 04:07:46 +0000 (23:07 -0500)]
ecpg: Fix typo

GCC 6 points out the redundant conditions, which were apparently typos.

Reviewed-by: Thomas Munro <thomas.munro@enterprisedb.com>
8 years agoltree: Zero padding bytes when allocating memory for externally visible data.
Andres Freund [Tue, 8 Mar 2016 22:59:29 +0000 (14:59 -0800)]
ltree: Zero padding bytes when allocating memory for externally visible data.

ltree/ltree_gist/ltxtquery's headers stores data at MAXALIGN alignment,
requiring some padding bytes. So far we left these uninitialized. Zero
those by using palloc0.

Author: Andres Freund
Reported-By: Andres Freund / valgrind / buildarm animal skink
Backpatch: 9.1-

8 years agoFix minor thinko in pathification code.
Tom Lane [Tue, 8 Mar 2016 21:50:32 +0000 (16:50 -0500)]
Fix minor thinko in pathification code.

I passed the wrong "root" struct to create_pathtarget in build_minmax_path.
Since the subroot is a clone of the outer root, this would not cause any
serious problems, but it would waste some cycles because
set_pathtarget_cost_width would not have access to Var width estimates
set up while running query_planner on the subroot.

8 years agoplperl: Correctly handle empty arrays in plperl_ref_from_pg_array.
Andres Freund [Tue, 8 Mar 2016 21:33:24 +0000 (13:33 -0800)]
plperl: Correctly handle empty arrays in plperl_ref_from_pg_array.

plperl_ref_from_pg_array() didn't consider the case that postgrs arrays
can have 0 dimensions (when they're empty) and accessed the first
dimension without a check. Fix that by special casing the empty array
case.

Author: Alex Hunsaker
Reported-By: Andres Freund / valgrind / buildfarm animal skink
Discussion: 20160308063240.usnzg6bsbjrne667@alap3.anarazel.de
Backpatch: 9.1-

8 years agoFinish refactoring make_foo() functions in createplan.c.
Tom Lane [Tue, 8 Mar 2016 21:28:27 +0000 (16:28 -0500)]
Finish refactoring make_foo() functions in createplan.c.

This patch removes some redundant cost calculations that I left for later
cleanup in commit 3fc6e2d7f5b652b4.  There's now a uniform policy that the
make_foo() convenience functions don't do any cost calculations.  Most of
their callers copy costs from the source Path node, and for those that
don't, the calculation in the make_foo() function wasn't necessarily right
anyhow.  (make_result() was particularly a mess, as it was serving multiple
callers using cost calcs designed for only the first one or two that had
ever existed.)  Aside from saving a few cycles, this ensures that what
EXPLAIN prints matches the costs we used for planning purposes.  It does
not change any planner decisions, since the decisions are already made.

8 years agoComment update for fdw_recheck_quals.
Robert Haas [Tue, 8 Mar 2016 19:40:55 +0000 (14:40 -0500)]
Comment update for fdw_recheck_quals.

Commit 5fc4c26db5120bd90348b6ee3101fcddfdf54800 could've done a better
job updating these comments.

Etsuro Fujita

8 years agoUpdate GetForeignPlan documentation.
Robert Haas [Tue, 8 Mar 2016 19:30:12 +0000 (14:30 -0500)]
Update GetForeignPlan documentation.

Commit 385f337c9f39b21dca96ca4770552a10a6d5af24 added a new argument
to the FDW GetForeignPlan method, but failed to update the documentation
to match.

Etsuro Fujita

8 years agoFix reversed argument to bms_is_subset.
Robert Haas [Tue, 8 Mar 2016 18:59:11 +0000 (13:59 -0500)]
Fix reversed argument to bms_is_subset.

Ashutosh Bapat

8 years agoAdd new flags argument for xl_heap_visible to heap2_desc.
Robert Haas [Tue, 8 Mar 2016 18:28:22 +0000 (13:28 -0500)]
Add new flags argument for xl_heap_visible to heap2_desc.

Masahiko Sawada

8 years agoFix typo.
Robert Haas [Tue, 8 Mar 2016 18:28:00 +0000 (13:28 -0500)]
Fix typo.

Masahiko Sawada

8 years agoFix parallel query on standby servers.
Robert Haas [Tue, 8 Mar 2016 15:27:03 +0000 (10:27 -0500)]
Fix parallel query on standby servers.

Without this fix, it inevitably bombs out with "ERROR:  failed to
initialize transaction_read_only to 0".  Repair.

Ashutosh Sharma; comments adjusted by me.

8 years agoAdd some functions to fd.c for the convenience of extensions.
Robert Haas [Tue, 8 Mar 2016 15:09:50 +0000 (10:09 -0500)]
Add some functions to fd.c for the convenience of extensions.

For example, if you want to perform an ioctl() on a file descriptor
opened through the fd.c routines, there's no way to do that without
being able to get at the underlying fd.

KaiGai Kohei

8 years agoDepartment of second thoughts: remove PD_ALL_FROZEN.
Robert Haas [Tue, 8 Mar 2016 13:46:48 +0000 (08:46 -0500)]
Department of second thoughts: remove PD_ALL_FROZEN.

Commit a892234f830e832110f63fc0a2afce2fb21d1584 added a second bit per
page to the visibility map, which still seems like a good idea, but it
also added a second page-level bit alongside PD_ALL_VISIBLE to track
whether the visibility map bit was set.  That no longer seems like a
clever plan, because we don't really need that bit for anything.  We
always clear both bits when the page is modified anyway.

Patch by me, reviewed by Kyotaro Horiguchi and Masahiko Sawada.

8 years agoAdd pg_visibility contrib module.
Robert Haas [Tue, 8 Mar 2016 13:38:50 +0000 (08:38 -0500)]
Add pg_visibility contrib module.

This lets you examine the visibility map as well as page-level
visibility information.  I initially wrote it as a debugging aid,
but was encouraged to polish it for commit.

Patch by me, reviewed by Masahiko Sawada.

Discussion: 56D77803.6080503@BlueTreble.com

8 years agopg_upgrade: Remove converter plugin facility.
Robert Haas [Tue, 8 Mar 2016 13:13:02 +0000 (08:13 -0500)]
pg_upgrade: Remove converter plugin facility.

We've not found a use for this so far, and the current need, which
is to convert the visibility map to a new format, does not suit the
existing design anyway.  So just rip it out.

Author: Masahiko Sawada, slightly revised by me.
Discussion: 20160215211313.GB31273@momjian.us

8 years agoFix minor typo in logical-decoding docs.
Tom Lane [Tue, 8 Mar 2016 02:52:30 +0000 (21:52 -0500)]
Fix minor typo in logical-decoding docs.

David Rowley

8 years agoSpell "parallel" correctly.
Tom Lane [Tue, 8 Mar 2016 02:48:17 +0000 (21:48 -0500)]
Spell "parallel" correctly.

Per David Rowley.

8 years agoFix uninstall target in tsearch Makefile
Peter Eisentraut [Tue, 8 Mar 2016 01:36:59 +0000 (20:36 -0500)]
Fix uninstall target in tsearch Makefile

Artur Zakirov

8 years agoMake get_controlfile() error logging consistent with src/common
Joe Conway [Mon, 7 Mar 2016 23:14:20 +0000 (15:14 -0800)]
Make get_controlfile() error logging consistent with src/common

As originally committed, get_controlfile() used a non-standard approach
to error logging. Make it consistent with the majority of error logging
done in src/common.

Applies to master only.

8 years agoFurther improvements to c8f621c43.
Andres Freund [Mon, 7 Mar 2016 22:24:03 +0000 (14:24 -0800)]
Further improvements to c8f621c43.

Coverity and inspection for the issue addressed in fd45d16f found some
questionable code.

Specifically coverity noticed that the wrong length was added in
ReorderBufferSerializeChange() - without immediate negative consequences
as the variable isn't used afterwards.  During code-review and testing I
noticed that a bit of space was wasted when allocating tuple bufs in
several places.  Thirdly, the debug memset()s in
ReorderBufferGetTupleBuf() reduce the error checking valgrind can do.

Backpatch: 9.4, like c8f621c43.

8 years agoMake the upper part of the planner work by generating and comparing Paths.
Tom Lane [Mon, 7 Mar 2016 20:58:22 +0000 (15:58 -0500)]
Make the upper part of the planner work by generating and comparing Paths.

I've been saying we needed to do this for more than five years, and here it
finally is.  This patch removes the ever-growing tangle of spaghetti logic
that grouping_planner() used to use to try to identify the best plan for
post-scan/join query steps.  Now, there is (nearly) independent
consideration of each execution step, and entirely separate construction of
Paths to represent each of the possible ways to do that step.  We choose
the best Path or set of Paths using the same add_path() logic that's been
used inside query_planner() for years.

In addition, this patch removes the old restriction that subquery_planner()
could return only a single Plan.  It now returns a RelOptInfo containing a
set of Paths, just as query_planner() does, and the parent query level can
use each of those Paths as the basis of a SubqueryScanPath at its level.
This allows finding some optimizations that we missed before, wherein a
subquery was capable of returning presorted data and thereby avoiding a
sort in the parent level, making the overall cost cheaper even though
delivering sorted output was not the cheapest plan for the subquery in
isolation.  (A couple of regression test outputs change in consequence of
that.  However, there is very little change in visible planner behavior
overall, because the point of this patch is not to get immediate planning
benefits but to create the infrastructure for future improvements.)

There is a great deal left to do here.  This patch unblocks a lot of
planner work that was basically impractical in the old code structure,
such as allowing FDWs to implement remote aggregation, or rewriting
plan_set_operations() to allow consideration of multiple implementation
orders for set operations.  (The latter will likely require a full
rewrite of plan_set_operations(); what I've done here is only to fix it
to return Paths not Plans.)  I have also left unfinished some localized
refactoring in createplan.c and planner.c, because it was not necessary
to get this patch to a working state.

Thanks to Robert Haas, David Rowley, and Amit Kapila for review.

8 years agoFix backwards test for Windows service-ness in pg_ctl.
Tom Lane [Mon, 7 Mar 2016 15:40:44 +0000 (10:40 -0500)]
Fix backwards test for Windows service-ness in pg_ctl.

A thinko in a96761391 caused pg_ctl to get it exactly backwards when
deciding whether to report problems to the Windows eventlog or to stderr.
Per bug #14001 from Manuel Mathar, who also identified the fix.
Like the previous patch, back-patch to all supported branches.

8 years agoRe-fix broken definition for function name in pgbench's exprscan.l.
Tom Lane [Mon, 7 Mar 2016 02:45:34 +0000 (21:45 -0500)]
Re-fix broken definition for function name in pgbench's exprscan.l.

Wups, my first try wasn't quite right either.  Too focused on fixing
the existing bug, not enough on not introducing new ones.

8 years agoFix broken definition for function name in pgbench's exprscan.l.
Tom Lane [Mon, 7 Mar 2016 02:04:25 +0000 (21:04 -0500)]
Fix broken definition for function name in pgbench's exprscan.l.

As written, this would accept e.g. 123e9 as a function name.  Aside
from being mildly astonishing, that would come back to haunt us if
we ever try to add float constants to the expression syntax.  Insist
that function names start with letters (or at least non-digits).

In passing reset yyline as well as yycol when starting a new expression.
This variable is useless since it's used nowhere, but if we're going
to have it we should have it act sanely.

8 years agoFix wrong allocation size in c8f621c43.
Andres Freund [Mon, 7 Mar 2016 00:27:20 +0000 (16:27 -0800)]
Fix wrong allocation size in c8f621c43.

In c8f621c43 I forgot to account for MAXALIGN when allocating a new
tuplebuf in ReorderBufferGetTupleBuf(). That happens to currently not
cause active problems on a number of platforms because the affected
pointer is already aligned, but others, like ppc and hppa, trigger this
in the regression test, due to a debug memset clearing memory.

Fix that.

Backpatch: 9.4, like the previous commit.

8 years agoFix not-terribly-safe coding in NIImportOOAffixes() and NIImportAffixes().
Tom Lane [Mon, 7 Mar 2016 00:20:55 +0000 (19:20 -0500)]
Fix not-terribly-safe coding in NIImportOOAffixes() and NIImportAffixes().

There were two places in spell.c that supposed that they could search
for a location in a string produced by lowerstr() and then transpose
the offset into the original string.  But this fails completely if
lowerstr() transforms any characters into characters of different byte
length, as can happen in Turkish UTF8 for instance.

We'd added some comments about this coding in commit 51e78ab4ff328296,
but failed to realize that it was not merely confusing but wrong.

Coverity complained about this code years ago, but in such an opaque
fashion that nobody understood what it was on about.  I'm not entirely
sure that this issue *is* what it's on about, actually, but perhaps
this patch will shut it up -- and in any case the problem is clear.

Back-patch to all supported branches.

8 years agoFix unportable usage of <ctype.h> functions.
Tom Lane [Sun, 6 Mar 2016 23:23:53 +0000 (18:23 -0500)]
Fix unportable usage of <ctype.h> functions.

isdigit(), isspace(), etc are likely to give surprising results if passed a
signed char.  We should always cast the argument to unsigned char to avoid
that.  Error in commit d78a7d9c7fa3e9cd, found by buildfarm member gaur.

8 years agoFix typos
Magnus Hagander [Sun, 6 Mar 2016 11:25:47 +0000 (12:25 +0100)]
Fix typos

Author: Guillaume Lelarge

8 years agological decoding: Fix handling of large old tuples with replica identity full.
Andres Freund [Sun, 6 Mar 2016 02:02:20 +0000 (18:02 -0800)]
logical decoding: Fix handling of large old tuples with replica identity full.

When decoding the old version of an UPDATE or DELETE change, and if that
tuple was bigger than MaxHeapTupleSize, we either Assert'ed out, or
failed in more subtle ways in non-assert builds.  Normally individual
tuples aren't bigger than MaxHeapTupleSize, with big datums toasted.
But that's not the case for the old version of a tuple for logical
decoding; the replica identity is logged as one piece. With the default
replica identity btree limits that to small tuples, but that's not the
case for FULL.

Change the tuple buffer infrastructure to separate allocate over-large
tuples, instead of always going through the slab cache.

This unfortunately requires changing the ReorderBufferTupleBuf
definition, we need to store the allocated size someplace. To avoid
requiring output plugins to recompile, don't store HeapTupleHeaderData
directly after HeapTupleData, but point to it via t_data; that leaves
rooms for the allocated size.  As there's no reason for an output plugin
to look at ReorderBufferTupleBuf->t_data.header, remove the field. It
was just a minor convenience having it directly accessible.

Reported-By: Adam Dratwiński
Discussion: CAKg6ypLd7773AOX4DiOGRwQk1TVOQKhNwjYiVjJnpq8Wo+i62Q@mail.gmail.com

8 years agological decoding: old/newtuple in spooled UPDATE changes was switched around.
Andres Freund [Sun, 6 Mar 2016 02:02:20 +0000 (18:02 -0800)]
logical decoding: old/newtuple in spooled UPDATE changes was switched around.

Somehow I managed to flip the order of restoring old & new tuples when
de-spooling a change in a large transaction from disk. This happens to
only take effect when a change is spooled to disk which has old/new
versions of the tuple. That only is the case for UPDATEs where he
primary key changed or where replica identity is changed to FULL.

The tests didn't catch this because either spooled updates, or updates
that changed primary keys, were tested; not both at the same time.

Found while adding tests for the following commit.

Backpatch: 9.4, where logical decoding was added

8 years agological decoding: Tell reorderbuffer about all xids.
Andres Freund [Sun, 6 Mar 2016 02:02:20 +0000 (18:02 -0800)]
logical decoding: Tell reorderbuffer about all xids.

Logical decoding's reorderbuffer keeps transactions in an LSN ordered
list for efficiency. To make that's efficiently possible upper-level
xids are forced to be logged before nested subtransaction xids.  That
only works though if these records are all looked at: Unfortunately we
didn't do so for e.g. row level locks, which are otherwise uninteresting
for logical decoding.

This could lead to errors like:
"ERROR: subxact logged without previous toplevel record".

It's not sufficient to just look at row locking records, the xid could
appear first due to a lot of other types of records (which will trigger
the transaction to be marked logged with MarkCurrentTransactionIdLoggedIfAny).
So invent infrastructure to tell reorderbuffer about xids seen, when
they'd otherwise not pass through reorderbuffer.c.

Reported-By: Jarred Ward
Bug: #13844
Discussion: 20160105033249.1087.66040@wrigleys.postgresql.org
Backpatch: 9.4, where logical decoding was added

8 years agoExpose control file data via SQL accessible functions.
Joe Conway [Sat, 5 Mar 2016 19:10:19 +0000 (11:10 -0800)]
Expose control file data via SQL accessible functions.

Add four new SQL accessible functions: pg_control_system(),
pg_control_checkpoint(), pg_control_recovery(), and pg_control_init()
which expose a subset of the control file data.

Along the way move the code to read and validate the control file to
src/common, where it can be shared by the new backend functions
and the original pg_controldata frontend program.

Patch by me, significant input, testing, and review by Michael Paquier.

8 years agoIgnore recovery_min_apply_delay until recovery has reached consistent state
Fujii Masao [Sat, 5 Mar 2016 17:29:04 +0000 (02:29 +0900)]
Ignore recovery_min_apply_delay until recovery has reached consistent state

Previously recovery_min_apply_delay was applied even before recovery
had reached consistency. This could cause us to wait a long time
unexpectedly for read-only connections to be allowed. It's problematic
because the standby was useless during that wait time.

This patch changes recovery_min_apply_delay so that it's applied once
the database has reached the consistent state. That is, even if the delay
is set, the standby tries to replay WAL records as fast as possible until
it has reached consistency.

Author: Michael Paquier
Reviewed-By: Julien Rouhaud
Reported-By: Greg Clough
Backpatch: 9.4, where recovery_min_apply_delay was added
Bug: #13770
Discussion: http://www.postgresql.org/message-id/20151111155006.2644.84564@wrigleys.postgresql.org

8 years agoMake stats regression test robust in the face of parallel query.
Tom Lane [Fri, 4 Mar 2016 21:20:44 +0000 (16:20 -0500)]
Make stats regression test robust in the face of parallel query.

Historically, the wait_for_stats() function in this test has simply checked
for a report of an indexscan on tenk2, corresponding to the last command
issued before we expect stats updates to appear.  However, with parallel
query that indexscan could be done by a parallel worker that will emit
its stats counters to the collector before the session's main backend does
(a full second before, in fact, thanks to the "pg_sleep(1.0)" added by
commit 957d08c81f9cc277).  That leaves a sizable window in which an
autovacuum-triggered write of the stats files would present a state in
which the indexscan on tenk2 appears to have been done, but none of the
write updates performed by the test have been.  This is evidently the
explanation for intermittent failures seen by me and on buildfarm member
mandrill.

To fix, we should check separately for both the tenk2 seqscan and indexscan
counts, since those might be reported by different processes that could be
delayed arbitrarily on an overloaded test machine.  And we need to check
for at least one update-related count.  If we ever allow parallel workers
to do writes, this will get even more complicated ... but in view of all
the other hard problems that will entail, I don't feel a need to solve this
one today.

Per research by Rahila Syed and myself; part of this patch is Rahila's.

8 years agoFix typo in comment.
Robert Haas [Fri, 4 Mar 2016 20:46:30 +0000 (15:46 -0500)]
Fix typo in comment.

Thomas Munro

8 years agoMinor improvements to transaction manager README.
Robert Haas [Fri, 4 Mar 2016 19:12:28 +0000 (14:12 -0500)]
Minor improvements to transaction manager README.

A simple SELECT is handled by PortalRunSelect, not ProcessQuery.  Also,
the previous indentation was unclear: change it so that a deeper level
of indentation indicates that the outer function calls the inner one.

Stas Kelvich

8 years agoFix SerializeSnapshot not to overrun the allocated space.
Robert Haas [Fri, 4 Mar 2016 18:47:05 +0000 (13:47 -0500)]
Fix SerializeSnapshot not to overrun the allocated space.

Rushabh Lathia