]> granicus.if.org Git - postgresql/log
postgresql
10 years agoDocumentation for logical decoding.
Robert Haas [Tue, 18 Mar 2014 17:20:01 +0000 (13:20 -0400)]
Documentation for logical decoding.

Craig Ringer, Andres Freund, Christian Kruse, with edits by me.

10 years agoAdd pg_recvlogical, a tool to receive data logical decoding data.
Robert Haas [Tue, 18 Mar 2014 16:19:57 +0000 (12:19 -0400)]
Add pg_recvlogical, a tool to receive data logical decoding data.

This is fairly basic at the moment, but it's at least useful for
testing and debugging, and possibly more.

Andres Freund

10 years agoRewrite comment for shm_mq_receive_bytes.
Robert Haas [Tue, 18 Mar 2014 15:51:51 +0000 (11:51 -0400)]
Rewrite comment for shm_mq_receive_bytes.

The comment and the code diverged at some point before the initial
commit of this feature, and I failed to notice.

Noted by Tom Lane.

10 years agoFix relcache reference leak in refresh_by_match_merge().
Tom Lane [Tue, 18 Mar 2014 15:36:45 +0000 (11:36 -0400)]
Fix relcache reference leak in refresh_by_match_merge().

One path through the loop over indexes forgot to do index_close().  Rather
than adding a fourth call, restructure slightly so that there's only one.

In passing, get rid of an unnecessary syscache lookup: the pg_index struct
for the index is already available from its relcache entry.

Per report from YAMAMOTO Takashi, though this is a bit different from his
suggested patch.  This is new code in HEAD, so no need for back-patch.

10 years agoImprove shm_mq portability around MAXIMUM_ALIGNOF and sizeof(Size).
Robert Haas [Tue, 18 Mar 2014 15:19:13 +0000 (11:19 -0400)]
Improve shm_mq portability around MAXIMUM_ALIGNOF and sizeof(Size).

Revise the original decision to expose a uint64-based interface and
use Size everywhere possible.  Avoid assuming that MAXIMUM_ALIGNOF is
8, or making any assumption about the relationship between that value
and sizeof(Size).  If MAXIMUM_ALIGNOF is bigger, we'll now insert
padding after the length word; if it's smaller, we are now prepared
to read and write the length word in chunks.

Per discussion with Tom Lane.

10 years agoFix pg_dumpall option parsing: -i doesn't take an argument.
Tom Lane [Tue, 18 Mar 2014 14:38:25 +0000 (10:38 -0400)]
Fix pg_dumpall option parsing: -i doesn't take an argument.

This used to work properly, but got fat-fingered in commit
3dee636e0404885d07885d41c0d70e50c784f324.  Per bug #9620 from
Nicolas Payart.

10 years agoFix help message and document in pg_receivexlog.
Fujii Masao [Tue, 18 Mar 2014 12:15:45 +0000 (21:15 +0900)]
Fix help message and document in pg_receivexlog.

Add SLOTNAME placeholder to --slot option in help message and
document.

10 years agoMake it easy to detach completely from shared memory.
Robert Haas [Tue, 18 Mar 2014 11:58:53 +0000 (07:58 -0400)]
Make it easy to detach completely from shared memory.

The new function dsm_detach_all() can be used either by postmaster
children that don't wish to take any risk of accidentally corrupting
shared memory; or by forked children of regular backends with
the same need.  This patch also updates the postmaster children that
already do PGSharedMemoryDetach() to do dsm_detach_all() as well.

Per discussion with Tom Lane.

10 years agoRelease notes for 9.3.4, 9.2.8, 9.1.13, 9.0.17, 8.4.21.
Tom Lane [Mon, 17 Mar 2014 19:28:22 +0000 (15:28 -0400)]
Release notes for 9.3.4, 9.2.8, 9.1.13, 9.0.17, 8.4.21.

10 years agoDuring index build, check and elog (not just Assert) for broken HOT chain.
Tom Lane [Mon, 17 Mar 2014 16:36:11 +0000 (12:36 -0400)]
During index build, check and elog (not just Assert) for broken HOT chain.

The recently-fixed bug in WAL replay could result in not finding a parent
tuple for a heap-only tuple.  The existing code would either Assert or
generate an invalid index entry, neither of which is desirable.  Throw a
regular error instead.

10 years agoFix thinko: have trueTriConsistentFn return GIN_TRUE.
Heikki Linnakangas [Mon, 17 Mar 2014 15:18:40 +0000 (17:18 +0200)]
Fix thinko: have trueTriConsistentFn return GIN_TRUE.

While we're at it, also improve comments in ginlogic.c.

10 years agoFix typos in comments.
Fujii Masao [Mon, 17 Mar 2014 11:47:28 +0000 (20:47 +0900)]
Fix typos in comments.

Thom Brown

10 years agoFix bug in clean shutdown of walsender that pg_receiving is connecting to.
Fujii Masao [Mon, 17 Mar 2014 11:37:50 +0000 (20:37 +0900)]
Fix bug in clean shutdown of walsender that pg_receiving is connecting to.

On clean shutdown, walsender waits for all WAL to be replicated to a standby,
and exits. It determined whether that replication had been completed by
checking whether its sent location had been equal to a standby's flush
location. Unfortunately this condition never becomes true when the standby
such as pg_receivexlog which always returns an invalid flush location is
connecting to walsender, and then walsender waits forever.

This commit changes walsender so that it just checks a standby's write
location if a flush location is invalid.

Back-patch to 9.1 where enough infrastructure for this exists.

10 years agoFix small typo in comment
Magnus Hagander [Mon, 17 Mar 2014 08:09:21 +0000 (09:09 +0100)]
Fix small typo in comment

Michael Paquier

10 years agoplperl: Fix memory leak in hek2cstr
Alvaro Herrera [Mon, 17 Mar 2014 02:22:21 +0000 (23:22 -0300)]
plperl: Fix memory leak in hek2cstr

Backpatch all the way back to 9.1, where it was introduced by commit
50d89d42.

Reported by Sergey Burladyan in #9223
Author: Alex Hunsaker

10 years agoFix unportable shell-script syntax in pg_upgrade's test.sh.
Tom Lane [Mon, 17 Mar 2014 01:55:02 +0000 (21:55 -0400)]
Fix unportable shell-script syntax in pg_upgrade's test.sh.

I discovered the hard way that on some old shells, the locution
    FOO=""   unset FOO
does not behave the same as
    FOO="";  unset FOO
and in fact leaves FOO set to an empty string.  test.sh was inconsistently
spelling it different ways on adjacent lines.

This got broken relatively recently, in commit c737a2e56, so the lack of
field reports to date doesn't represent a lot of evidence that the problem
is rare.

10 years agoMake punctuation consistent
Peter Eisentraut [Mon, 17 Mar 2014 01:44:58 +0000 (21:44 -0400)]
Make punctuation consistent

10 years agoFix whitespace
Peter Eisentraut [Mon, 17 Mar 2014 01:43:59 +0000 (21:43 -0400)]
Fix whitespace

10 years agoFix advertised dispsize for libpq's sslmode connection parameter.
Tom Lane [Mon, 17 Mar 2014 01:43:40 +0000 (21:43 -0400)]
Fix advertised dispsize for libpq's sslmode connection parameter.

"8" was correct back when "disable" was the longest allowed value, but
since "verify-full" was added, it should be "12".  Given the lack of
complaints, I wouldn't be surprised if nobody is actually using these
values ... but still, if they're in the API, they should be right.

Noticed while pursuing a different problem.  It's been wrong for quite
a long time, so back-patch to all supported branches.

10 years agoCleanups from the remove-native-krb5 patch
Magnus Hagander [Sun, 16 Mar 2014 14:18:52 +0000 (15:18 +0100)]
Cleanups from the remove-native-krb5 patch

krb_srvname is actually not available anymore as a parameter server-side, since
with gssapi we accept all principals in our keytab. It's still used in libpq for
client side specification.

In passing remove declaration of krb_server_hostname, where all the functionality
was already removed.

Noted by Stephen Frost, though a different solution than his suggestion

10 years agoFirst-draft release notes for 9.3.4.
Tom Lane [Sat, 15 Mar 2014 19:58:59 +0000 (15:58 -0400)]
First-draft release notes for 9.3.4.

As usual, the release notes for older branches will be made by cutting
these down, but put them up for community review first.

10 years agoUpdate time zone data files to tzdata release 2014a.
Tom Lane [Sat, 15 Mar 2014 17:36:07 +0000 (13:36 -0400)]
Update time zone data files to tzdata release 2014a.

DST law changes in Fiji, Turkey; historical changes in Israel, Ukraine.

10 years agoFix race condition in B-tree page deletion.
Heikki Linnakangas [Fri, 14 Mar 2014 13:43:58 +0000 (15:43 +0200)]
Fix race condition in B-tree page deletion.

In short, we don't allow a page to be deleted if it's the rightmost child
of its parent, but that situation can change after we check for it.

Problem
-------

We check that the page to be deleted is not the rightmost child of its
parent, and then lock its left sibling, the page itself, its right sibling,
and the parent, in that order. However, if the parent page is split after
the check but before acquiring the locks, the target page might become the
rightmost child, if the split happens at the right place. That leads to an
error in vacuum (I reproduced this by setting a breakpoint in debugger):

ERROR:  failed to delete rightmost child 41 of block 3 in index "foo_pkey"

We currently re-check that the page is still the rightmost child, and throw
the above error if it's not. We could easily just give up rather than throw
an error, but that approach doesn't scale to half-dead pages. To recap,
although we don't normally allow deleting the rightmost child, if the page
is the *only* child of its parent, we delete the child page and mark the
parent page as half-dead in one atomic operation. But before we do that, we
check that the parent can later be deleted, by checking that it in turn is
not the rightmost child of the grandparent (potentially recursing all the
way up to the root). But the same situation can arise there - the
grandparent can be split while we're not holding the locks. We end up with
a half-dead page that we cannot delete.

To make things worse, the keyspace of the deleted page has already been
transferred to its right sibling. As the README points out, the keyspace at
the grandparent level is "out-of-whack" until the half-dead page is deleted,
and if enough tuples with keys in the transferred keyspace are inserted, the
page might get split and a downlink might be inserted into the grandparent
that is out-of-order. That might not cause any serious problem if it's
transient (as the README ponders), but is surely bad if it stays that way.

Solution
--------

This patch changes the page deletion algorithm to avoid that problem. After
checking that the topmost page in the chain of to-be-deleted pages is not
the rightmost child of its parent, and then deleting the pages from bottom
up, unlink the pages from top to bottom. This way, the intermediate stages
are similar to the intermediate stages in page splitting, and there is no
transient stage where the keyspace is "out-of-whack". The topmost page in
the to-be-deleted chain doesn't have a downlink pointing to it, like a page
split before the downlink has been inserted.

This also allows us to get rid of the cleanup step after WAL recovery, if we
crash during page deletion. The deletion will be continued at next VACUUM,
but the tree is consistent for searches and insertions at every step.

This bug is old, all supported versions are affected, but this patch is too
big to back-patch (and changes the WAL record formats of related records).
We have not heard any reports of the bug from users, so clearly it's not
easy to bump into. Maybe backpatch later, after this has had some field
testing.

Reviewed by Kevin Grittner and Peter Geoghegan.

10 years agoPrevent interrupts while reporting non-ERROR elog messages.
Tom Lane [Fri, 14 Mar 2014 00:59:42 +0000 (20:59 -0400)]
Prevent interrupts while reporting non-ERROR elog messages.

This should eliminate the risk of recursive entry to syslog(3), which
appears to be the cause of the hang reported in bug #9551 from James
Morton.

Arguably, the real problem here is auth.c's willingness to turn on
ImmediateInterruptOK while executing fairly wide swaths of backend code.
We may well need to work at narrowing the code ranges in which the
authentication_timeout interrupt is enabled.  For the moment, though,
this is a cheap and reasonably noninvasive fix for a field-reported
failure; the other approach would be complex and not necessarily
bug-free itself.

Back-patch to all supported branches.

10 years agoAllow psql to print COPY command status in more cases.
Tom Lane [Thu, 13 Mar 2014 17:49:03 +0000 (13:49 -0400)]
Allow psql to print COPY command status in more cases.

Previously, psql would print the "COPY nnn" command status only for COPY
commands executed server-side.  Now it will print that for frontend copies
too (including \copy).  However, we continue to suppress the command status
for COPY TO STDOUT, since in that case the copy data has been routed to the
same place that the command status would go, and there is a risk of the
status line being mistaken for another line of COPY data.  Doing that would
break existing scripts, and it doesn't seem worth the benefit --- this case
seems fairly analogous to SELECT, for which we also suppress the command
status.

Kumar Rajeev Rastogi, with substantial review by Amit Khandekar

10 years agoAvoid transaction-commit race condition while receiving a NOTIFY message.
Tom Lane [Thu, 13 Mar 2014 16:02:54 +0000 (12:02 -0400)]
Avoid transaction-commit race condition while receiving a NOTIFY message.

Use TransactionIdIsInProgress, then TransactionIdDidCommit, to distinguish
whether a NOTIFY message's originating transaction is in progress,
committed, or aborted.  The previous coding could accept a message from a
transaction that was still in-progress according to the PGPROC array;
if the client were fast enough at starting a new transaction, it might fail
to see table rows added/updated by the message-sending transaction.  Which
of course would usually be the point of receiving the message.  We noted
this type of race condition long ago in tqual.c, but async.c overlooked it.

The race condition probably cannot occur unless there are multiple NOTIFY
senders in action, since an individual backend doesn't send NOTIFY signals
until well after it's done committing.  But if two senders commit in close
succession, it's certainly possible that we could see the second sender's
message within the race condition window while responding to the signal
from the first one.

Per bug #9557 from Marko Tiikkaja.  This patch is slightly more invasive
than what he proposed, since it removes the now-redundant
TransactionIdDidAbort call.

Back-patch to 9.0, where the current NOTIFY implementation was introduced.

10 years agoFix a couple of typos in docs.
Heikki Linnakangas [Thu, 13 Mar 2014 13:01:45 +0000 (15:01 +0200)]
Fix a couple of typos in docs.

Thom Brown

10 years agoC comments: remove odd blank lines after #ifdef WIN32 lines
Bruce Momjian [Thu, 13 Mar 2014 05:42:24 +0000 (01:42 -0400)]
C comments:  remove odd blank lines after #ifdef WIN32 lines

A few more

10 years agoC comments: remove odd blank lines after #ifdef WIN32 lines
Bruce Momjian [Thu, 13 Mar 2014 05:34:42 +0000 (01:34 -0400)]
C comments:  remove odd blank lines after #ifdef WIN32 lines

10 years agoOnly WAL-log the modified portion in an UPDATE, if possible.
Heikki Linnakangas [Wed, 12 Mar 2014 20:46:04 +0000 (22:46 +0200)]
Only WAL-log the modified portion in an UPDATE, if possible.

When a row is updated, and the new tuple version is put on the same page as
the old one, only WAL-log the part of the new tuple that's not identical to
the old. This saves significantly on the amount of WAL that needs to be
written, in the common case that most fields are not modified.

Amit Kapila, with a lot of back and forth with me, Robert Haas, and others.

10 years agoItems on GIN data pages are no longer always 6 bytes; update gincostestimate.
Heikki Linnakangas [Wed, 12 Mar 2014 18:43:07 +0000 (20:43 +0200)]
Items on GIN data pages are no longer always 6 bytes; update gincostestimate.

Also improve the comments a bit.

10 years agoShow PIDs of lock holders and waiters in log_lock_waits log message.
Fujii Masao [Wed, 12 Mar 2014 18:26:47 +0000 (03:26 +0900)]
Show PIDs of lock holders and waiters in log_lock_waits log message.

Christian Kruse, reviewed by Kumar Rajeev Rastogi.

10 years agotest_decoding: Documentation fix.
Robert Haas [Wed, 12 Mar 2014 18:11:06 +0000 (14:11 -0400)]
test_decoding: Documentation fix.

Andres Freund

10 years agoFix incorrect assertion about historical snapshots.
Robert Haas [Wed, 12 Mar 2014 18:07:41 +0000 (14:07 -0400)]
Fix incorrect assertion about historical snapshots.

Also fix some nearby comments.

Andres Freund

10 years agoComment fixes related to logical decoding.
Robert Haas [Wed, 12 Mar 2014 18:03:09 +0000 (14:03 -0400)]
Comment fixes related to logical decoding.

Andres Freund, per complaints by Peter Eisentraut.

10 years agoAllow opclasses to provide tri-valued GIN consistent functions.
Heikki Linnakangas [Wed, 12 Mar 2014 15:13:22 +0000 (17:13 +0200)]
Allow opclasses to provide tri-valued GIN consistent functions.

With the GIN "fast scan" feature, GIN can skip items without fetching all
the keys for them, if it can prove that they don't match regardless of
those keys. So far, it has done the proving by calling the boolean
consistent function with all combinations of TRUE/FALSE for the unfetched
keys, but since that's O(n^2), it becomes unfeasible with more than a few
keys. We can avoid calling consistent with all the combinations, if we can
tell the operator class implementation directly which keys are unknown.

This commit includes a triConsistent function for the built-in array and
tsvector opclasses.

Alexander Korotkov, with some changes by me.

10 years agoIn WAL replay, restore GIN metapage unconditionally to avoid torn page.
Heikki Linnakangas [Wed, 12 Mar 2014 07:59:49 +0000 (09:59 +0200)]
In WAL replay, restore GIN metapage unconditionally to avoid torn page.

We don't take a full-page image of the GIN metapage; instead, the WAL record
contains all the information required to reconstruct it from scratch. But
to avoid torn page hazards, we must re-initialize it from the WAL record
every time, even if it already has a greater LSN, similar to how normal full
page images are restored.

This was highly unlikely to cause any problems in practice, because the GIN
metapage is small. We rely on an update smaller than a 512 byte disk sector
to be atomic elsewhere, at least in pg_control. But better safe than sorry,
and this would be easy to overlook if more fields are added to the metapage
so that it's no longer small.

Reported by Noah Misch. Backpatch to all supported versions.

10 years agoFix tracking of psql script line numbers during \copy from another place.
Tom Lane [Mon, 10 Mar 2014 19:47:06 +0000 (15:47 -0400)]
Fix tracking of psql script line numbers during \copy from another place.

Commit 08146775acd8bfe0fcc509c71857abb928697171 changed do_copy() to
temporarily scribble on pset.cur_cmd_source.  That was a mighty ugly bit of
code in any case, but in particular it broke handleCopyIn's ability to tell
whether it was reading from the current script source file (in which case
pset.lineno should be incremented for each line of COPY data), or from
someplace else (in which case it shouldn't).  The former case still worked,
the latter not so much.  The visible effect was that line numbers reported
for errors in a script file would be wrong if there were an earlier \copy
that was reading anything other than inline-in-the-script-file data.

To fix, introduce another pset field that holds the file do_copy wants the
COPY code to use.  This is a little bit ugly, but less so than passing the
file down explicitly through several layers that aren't COPY-specific.

Extracted from a larger patch by Kumar Rajeev Rastogi; that patch also
changes printing of COPY command tags, which is not a bug fix and shouldn't
get back-patched.  This particular idea was from a suggestion by Amit
Khandekar, if I'm reading the thread correctly.

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

10 years agoAllow dynamic shared memory segments to be kept until shutdown.
Robert Haas [Mon, 10 Mar 2014 18:04:47 +0000 (14:04 -0400)]
Allow dynamic shared memory segments to be kept until shutdown.

Amit Kapila, reviewed by Kyotaro Horiguchi, with some further
changes by me.

10 years agoAllow logical decoding via the walsender interface.
Robert Haas [Mon, 10 Mar 2014 17:50:28 +0000 (13:50 -0400)]
Allow logical decoding via the walsender interface.

In order for this to work, walsenders need the optional ability to
connect to a database, so the "replication" keyword now allows true
or false, for backward-compatibility, and the new value "database"
(which causes the "dbname" parameter to be respected).

walsender needs to loop not only when idle but also when sending
decoded data to the user and when waiting for more xlog data to decode.
This means that there are now three separate loops inside walsender.c;
although some refactoring has been done here, this is still a bit ugly.

Andres Freund, with contributions from Álvaro Herrera, and further
review by me.

10 years agoTeach on_exit_reset() to discard pending cleanups for dsm.
Robert Haas [Mon, 10 Mar 2014 14:17:19 +0000 (10:17 -0400)]
Teach on_exit_reset() to discard pending cleanups for dsm.

If a postmaster child invokes fork() and then calls on_exit_reset, that
should be sufficient to let it exit() without breaking anything, but
dynamic shared memory broke that by not updating on_exit_reset() to
discard callbacks registered with dynamic shared memory segments.

Per investigation of a complaint from Tom Lane.

10 years agoCorrect copy/pasto in comment for REPLICA IDENTITY
Simon Riggs [Sun, 9 Mar 2014 09:05:16 +0000 (09:05 +0000)]
Correct copy/pasto in comment for REPLICA IDENTITY

10 years agodoc: remove extra whitespace in SGML markup
Bruce Momjian [Sat, 8 Mar 2014 22:08:01 +0000 (17:08 -0500)]
doc: remove extra whitespace in SGML markup

10 years agoC comments: improve description of relfilenode uniqueness
Bruce Momjian [Sat, 8 Mar 2014 17:20:30 +0000 (12:20 -0500)]
C comments: improve description of relfilenode uniqueness

Report by Antonin Houska

10 years agopg_ctl: improve handling of invalid data directory
Bruce Momjian [Sat, 8 Mar 2014 17:15:25 +0000 (12:15 -0500)]
pg_ctl:  improve handling of invalid data directory

Return '4' and report a meaningful error message when a non-existent or
invalid data directory is passed.  Previously, pg_ctl would just report
the server was not running.

Patch by me and Amit Kapila
Report from Peter Eisentraut

10 years agodocs: small adjustements to recent SELECT and pg_upgrade improvements
Bruce Momjian [Sat, 8 Mar 2014 16:26:47 +0000 (11:26 -0500)]
docs:  small adjustements to recent SELECT and pg_upgrade improvements

10 years agopg_upgrade: document delete problems with tablespaces inside the cluster directory
Bruce Momjian [Sat, 8 Mar 2014 03:46:38 +0000 (22:46 -0500)]
pg_upgrade: document delete problems with tablespaces inside the cluster directory

Per report by Marc Mamin

10 years agodoc: improve server's keepalive description
Bruce Momjian [Sat, 8 Mar 2014 03:02:38 +0000 (22:02 -0500)]
doc: improve server's keepalive description

Use superior libpq keepalive description for the server-level
parameters.

Per report by Tatsuo Ishii and Marko Tiikkaja

10 years agodocs: improve TABLE command by showing supported clauses
Bruce Momjian [Sat, 8 Mar 2014 01:56:00 +0000 (20:56 -0500)]
docs:  improve TABLE command by showing supported clauses

Initial patch by Colin 't Hart

10 years agoRemove unportable use of anonymous unions from reorderbuffer.h.
Tom Lane [Fri, 7 Mar 2014 22:02:48 +0000 (17:02 -0500)]
Remove unportable use of anonymous unions from reorderbuffer.h.

In b89e151054a I had assumed it was ok to use anonymous unions as
struct members, but while a longstanding extension in many compilers,
it's only been standardized in C11.

To fix, remove one of the anonymous unions which tried to hide some
implementation specific enum values and give the other a name. The
latter unfortunately requires changes in output plugins, but since the
feature has only been added a few days ago...

Andres Freund

10 years agoFix contrib/postgres_fdw to handle multiple join conditions properly.
Tom Lane [Fri, 7 Mar 2014 21:35:58 +0000 (16:35 -0500)]
Fix contrib/postgres_fdw to handle multiple join conditions properly.

The previous coding supposed that it could consider just a single join
condition in any one parameterized path for the foreign table.  But in
reality, the parameterized-path machinery forces all join clauses that are
"movable to" the foreign table to be evaluated at that node; including
clauses that we might not consider safe to send across.  Such cases would
result in an Assert failure in an assert-enabled build, and otherwise in
sending an unsafe clause to the foreign server, which might result in
errors or silently-wrong answers.  A lesser problem was that the
cost/rowcount estimates generated for the parameterized path failed to
account for any additional join quals that get assigned to the scan.

To fix, rewrite postgresGetForeignPaths so that it correctly collects all
the movable quals for any one outer relation when generating parameterized
paths; we'll now generate just one path per outer relation not one per join
qual.  Also fix bogus assumptions in postgresGetForeignPlan and
estimate_path_cost_size that only safe-to-send join quals will be
presented.

Based on complaint from Etsuro Fujita that the path costs were being
miscalculated, though this is significantly different from his proposed
patch.

10 years agorelease notes: add item missed in 9.2.5 release
Bruce Momjian [Fri, 7 Mar 2014 18:45:38 +0000 (13:45 -0500)]
release notes:  add item missed in 9.2.5 release

Item is "Prevent errors in WAL replay due to references to uninitialized
empty pages".

Report and text by Andres Freund

Backpatch through 9.2.

10 years agofix ReplicationSlotsCountDBSlots for dropping unrelated databases
Bruce Momjian [Fri, 7 Mar 2014 16:42:18 +0000 (11:42 -0500)]
fix ReplicationSlotsCountDBSlots for dropping unrelated databases

YAMAMOTO Takashi

10 years agoFix dangling smgr_owner pointer when a fake relcache entry is freed.
Heikki Linnakangas [Fri, 7 Mar 2014 11:25:11 +0000 (13:25 +0200)]
Fix dangling smgr_owner pointer when a fake relcache entry is freed.

A fake relcache entry can "own" a SmgrRelation object, like a regular
relcache entry. But when it was free'd, the owner field in SmgrRelation
was not cleared, so it was left pointing to free'd memory.

Amazingly this apparently hasn't caused crashes in practice, or we would've
heard about it earlier. Andres found this with Valgrind.

Report and fix by Andres Freund, with minor modifications by me. Backpatch
to all supported versions.

10 years agoAvoid memcpy() with same source and destination address.
Heikki Linnakangas [Fri, 7 Mar 2014 11:13:33 +0000 (13:13 +0200)]
Avoid memcpy() with same source and destination address.

The behavior of that is undefined, although unlikely to lead to problems in
practice.

Found by running regression tests with Valgrind.

10 years agoFix name of syslog_ident GUC in docs.
Heikki Linnakangas [Fri, 7 Mar 2014 08:35:37 +0000 (10:35 +0200)]
Fix name of syslog_ident GUC in docs.

Michael Paquier

10 years agoAvoid getting more than AccessShareLock when deparsing a query.
Tom Lane [Fri, 7 Mar 2014 00:31:05 +0000 (19:31 -0500)]
Avoid getting more than AccessShareLock when deparsing a query.

In make_ruledef and get_query_def, we have long used AcquireRewriteLocks
to ensure that the querytree we are about to deparse is up-to-date and
the schemas of the underlying relations aren't changing.  Howwever, that
function thinks the query is about to be executed, so it acquires locks
that are stronger than necessary for the purpose of deparsing.  Thus for
example, if pg_dump asks to deparse a rule that includes "INSERT INTO t",
we'd acquire RowExclusiveLock on t.  That results in interference with
concurrent transactions that might for example ask for ShareLock on t.
Since pg_dump is documented as being purely read-only, this is unexpected.
(Worse, it used to actually be read-only; this behavior dates back only
to 8.1, cf commit ba4200246.)

Fix this by adding a parameter to AcquireRewriteLocks to tell it whether
we want the "real" execution locks or only AccessShareLock.

Report, diagnosis, and patch by Dean Rasheed.  Back-patch to all supported
branches.

10 years agoisdigit() needs an unsigned char argument.
Heikki Linnakangas [Thu, 6 Mar 2014 19:19:00 +0000 (21:19 +0200)]
isdigit() needs an unsigned char argument.

Per the C standard, the routine should be passed an int, with a value that's
representable as an unsigned char or EOF. Passing a signed char is wrong,
because a negative value is not representable as an unsigned char.
Unfortunately no compiler warns about that.

10 years agoSend keepalives from walsender even when busy sending WAL.
Heikki Linnakangas [Thu, 6 Mar 2014 19:13:38 +0000 (21:13 +0200)]
Send keepalives from walsender even when busy sending WAL.

If walsender doesn't hear from the client for the time specified by
wal_sender_timeout, it will conclude the connection or client is dead, and
disconnect. When half of wal_sender_timeout has elapsed, it sends a ping
to the client, leaving it the remainig half of wal_sender_timeout to
respond. However, it only checked if half of wal_sender_timeout had elapsed
when it was about to sleep, so if it was busy sending WAL to the client for
long enough, it would not send the ping request in time. Then the client
would not know it needs to send a reply, and the walsender will disconnect
even though the client is still alive. Fix that.

Andres Freund, reviewed by Robert Haas, and some further changes by me.
Backpatch to 9.3. Earlier versions relied on the client to send the
keepalives on its own, and hence didn't have this problem.

10 years agoDon't reject ROW_MARK_REFERENCE rowmarks for materialized views.
Tom Lane [Thu, 6 Mar 2014 16:37:02 +0000 (11:37 -0500)]
Don't reject ROW_MARK_REFERENCE rowmarks for materialized views.

We should allow this so that matviews can be referenced in UPDATE/DELETE
statements in READ COMMITTED isolation level.  The requirement for that
is that a re-fetch by TID will see the same row version the query saw
earlier, which is true of matviews, so there's no reason for the
restriction.  Per bug #9398.

Michael Paquier, after a suggestion by me

10 years agoC comment update: relfilenode is only unique with a tablespace
Bruce Momjian [Thu, 6 Mar 2014 01:52:34 +0000 (20:52 -0500)]
C comment update: relfilenode is only unique with a tablespace

Report from Antonin Houska

10 years agodocs: to_timestamp and to_date do minimal range checking
Bruce Momjian [Thu, 6 Mar 2014 01:45:27 +0000 (20:45 -0500)]
docs:  to_timestamp and to_date do minimal range checking

Initial patch from Steve Crawford

10 years agopg_dump: make argument combination error exit code consistent
Bruce Momjian [Wed, 5 Mar 2014 23:15:19 +0000 (18:15 -0500)]
pg_dump:  make argument combination error exit code consistent

Per report from Pavel Golub

10 years agoFix portability issues in recently added make_timestamp/make_interval code.
Tom Lane [Wed, 5 Mar 2014 21:42:18 +0000 (16:42 -0500)]
Fix portability issues in recently added make_timestamp/make_interval code.

Explicitly reject infinity/NaN inputs, rather than just assuming that
something else will do it for us.  Per buildfarm.

While at it, make some over-parenthesized and under-legible code
more readable.

10 years agoAdd comment that ec_relids excludes "child" EquivalenceClass members.
Tom Lane [Wed, 5 Mar 2014 21:00:22 +0000 (16:00 -0500)]
Add comment that ec_relids excludes "child" EquivalenceClass members.

This was already documented a few lines further down, but the comment
just beside the field declaration could be misleading.  Per gripe
from Kyotaro Horiguchi.

10 years agoFix some typos introduced by the logical decoding patch.
Robert Haas [Wed, 5 Mar 2014 18:00:22 +0000 (13:00 -0500)]
Fix some typos introduced by the logical decoding patch.

Erik Rijkers

10 years agoFix test_decoding regression test outputs.
Robert Haas [Wed, 5 Mar 2014 17:55:43 +0000 (12:55 -0500)]
Fix test_decoding regression test outputs.

Commit 6f37c08057685ee3c6c63222dba0dac012760dde removed whitespace
from the SQL file but not the expected-output file, and commit
7e8db2dc420099df3fa73987cf2d2d6d1a609d86 changed the error message
without updating the expected outputs.

10 years agoRemove unused field "evttype".
Tom Lane [Wed, 5 Mar 2014 16:57:53 +0000 (11:57 -0500)]
Remove unused field "evttype".

Apparent oversight in commit 3855968f.

10 years agoRemove the correct pgstat file on DROP DATABASE
Alvaro Herrera [Wed, 5 Mar 2014 16:03:29 +0000 (13:03 -0300)]
Remove the correct pgstat file on DROP DATABASE

We were unlinking the permanent file, not the non-permanent one.  But
since the stat collector already unlinks all permanent files on startup,
there was nothing for it to unlink.  The non-permanent file remained in
place, and was copied to the permanent directory on shutdown, so in
effect no file was ever dropped.

Backpatch to 9.3, where the issue was introduced by commit 187492b6c2e8.
Before that, there were no per-database files and thus no file to drop
on DROP DATABASE.

Per report from Thom Brown.

Author: Tomáš Vondra

10 years agopg_upgrade: improve C comment about what old/new oids match
Bruce Momjian [Wed, 5 Mar 2014 15:43:45 +0000 (10:43 -0500)]
pg_upgrade:  improve C comment about what old/new oids match

10 years agoAllocate fresh memory for post_opts/exec_path
Stephen Frost [Wed, 5 Mar 2014 13:50:12 +0000 (08:50 -0500)]
Allocate fresh memory for post_opts/exec_path

Instead of having read_post_opts() depend on the memory allocated for
the config file (which is now getting free'd), pg_strdup() for
post_opts and exec_path (similar to how it's being done elsewhere).

Noted by Thom Brown.

10 years agoDo wal_level and hot standby checks when doing crash-then-archive recovery.
Heikki Linnakangas [Wed, 5 Mar 2014 12:41:55 +0000 (14:41 +0200)]
Do wal_level and hot standby checks when doing crash-then-archive recovery.

CheckRequiredParameterValues() should perform the checks if archive recovery
was requested, even if we are going to perform crash recovery first.

Reported by Kyotaro HORIGUCHI. Backpatch to 9.2, like the crash-then-archive
recovery mode.

10 years agoFix lastReplayedEndRecPtr calculation when starting from shutdown checkpoint.
Heikki Linnakangas [Wed, 5 Mar 2014 11:27:18 +0000 (13:27 +0200)]
Fix lastReplayedEndRecPtr calculation when starting from shutdown checkpoint.

When entering crash recovery followed by archive recovery, and the latest
checkpoint is a shutdown checkpoint, and there are no more WAL records to
replay before transitioning from crash to archive recovery, we would not
immediately allow read-only connections in hot standby mode even if we
could. That's because when starting from a shutdown checkpoint, we set
lastReplayedEndRecPtr incorrectly to the record before the checkpoint
record, instead of the checkpoint record itself. We don't run the redo
routine of the shutdown checkpoint record, but starting recovery from it
goes through the same motions, so it should be considered as replayed.

Reported by Kyotaro HORIGUCHI. All versions with hot standby are affected,
so backpatch to 9.0.

10 years agoFix issues with pg_ctl
Stephen Frost [Wed, 5 Mar 2014 06:30:03 +0000 (01:30 -0500)]
Fix issues with pg_ctl

The new, small, free_readfile managed to have bug in it which could
cause it to try and free something it shouldn't, and fix the case
where it was being called with an invalid pointer leading to a
segfault.

Noted by Bruce, issues introduced and fixed by me.

10 years agoFix whitespace
Peter Eisentraut [Wed, 5 Mar 2014 02:53:25 +0000 (21:53 -0500)]
Fix whitespace

10 years agoProvide a FORCE NULL option to COPY in CSV mode.
Andrew Dunstan [Tue, 4 Mar 2014 22:31:59 +0000 (17:31 -0500)]
Provide a FORCE NULL option to COPY in CSV mode.

This forces an input field containing the quoted null string to be
returned as a NULL. Without this option, only unquoted null strings
behave this way. This helps where some CSV producers insist on quoting
every field, whether or not it is needed. The option takes a list of
fields, and only applies to those columns. There is an equivalent
column-level option added to file_fdw.

Ian Barwick, with some tweaking by Andrew Dunstan, reviewed by Payal
Singh.

10 years agoauto_explain: Add logging of trigger execution
Alvaro Herrera [Tue, 4 Mar 2014 18:31:18 +0000 (15:31 -0300)]
auto_explain: Add logging of trigger execution

Author: Kyotaro HORIGUCHI
Reviewed-by: Jaime Casanova
10 years agoConstructors for interval, timestamp, timestamptz
Alvaro Herrera [Tue, 4 Mar 2014 18:09:43 +0000 (15:09 -0300)]
Constructors for interval, timestamp, timestamptz

Author: Pavel Stěhule, editorialized somewhat by Álvaro Herrera
Reviewed-by: Tomáš Vondra, Marko Tiikkaja
With input from Fabrízio de Royes Mello, Jim Nasby

10 years agoAllow VACUUM FULL/CLUSTER to bump freeze horizons even for pg_class.
Robert Haas [Tue, 4 Mar 2014 16:08:18 +0000 (11:08 -0500)]
Allow VACUUM FULL/CLUSTER to bump freeze horizons even for pg_class.

pg_class is a special case for CLUSTER and VACUUM FULL, so although
commit 3cff1879f8d03cb729368722ca823a4bf74c0cac caused these
operations to advance relfrozenxid and relminmxid for all other
tables, it did not provide the same benefit for pg_class.  This
plugs that gap.

Andres Freund

10 years agoMinor corrections to logical decoding patch.
Robert Haas [Tue, 4 Mar 2014 16:07:54 +0000 (11:07 -0500)]
Minor corrections to logical decoding patch.

10 years agoError out on send failure in walsender loop.
Heikki Linnakangas [Tue, 4 Mar 2014 13:30:52 +0000 (15:30 +0200)]
Error out on send failure in walsender loop.

I changed the loop in 9.3 to use "goto send_failure" instead of "break" on
errors, but I missed this one case. It was a relatively harmless bug: if
the flush fails once it will most likely fail again as soon as we try to
flush the output again. But it's a bug nevertheless.

Report and fix by Andres Freund.

10 years agoIntroduce logical decoding.
Robert Haas [Mon, 3 Mar 2014 21:32:18 +0000 (16:32 -0500)]
Introduce logical decoding.

This feature, building on previous commits, allows the write-ahead log
stream to be decoded into a series of logical changes; that is,
inserts, updates, and deletes and the transactions which contain them.
It is capable of handling decoding even across changes to the schema
of the effected tables.  The output format is controlled by a
so-called "output plugin"; an example is included.  To make use of
this in a real replication system, the output plugin will need to be
modified to produce output in the format appropriate to that system,
and to perform filtering.

Currently, information can be extracted from the logical decoding
system only via SQL; future commits will add the ability to stream
changes via walsender.

Andres Freund, with review and other contributions from many other
people, including Álvaro Herrera, Abhijit Menon-Sen, Peter Gheogegan,
Kevin Grittner, Robert Haas, Heikki Linnakangas, Fujii Masao, Abhijit
Menon-Sen, Michael Paquier, Simon Riggs, Craig Ringer, and Steve
Singer.

10 years agoFix whitespace
Peter Eisentraut [Mon, 3 Mar 2014 19:05:33 +0000 (14:05 -0500)]
Fix whitespace

10 years agoRename huge_tlb_pages to huge_pages, and improve docs.
Heikki Linnakangas [Mon, 3 Mar 2014 18:52:48 +0000 (20:52 +0200)]
Rename huge_tlb_pages to huge_pages, and improve docs.

Christian Kruse

10 years agopg_dump et al: Add --if-exists option
Alvaro Herrera [Mon, 3 Mar 2014 18:02:18 +0000 (15:02 -0300)]
pg_dump et al: Add --if-exists option

This option makes pg_dump, pg_dumpall and pg_restore inject an IF EXISTS
clause to each DROP command they emit.  (In pg_dumpall, the clause is
not added to individual objects drops, but rather to the CREATE DATABASE
commands, as well as CREATE ROLE and CREATE TABLESPACE.)

This allows for a better user dump experience when using --clean in case
some objects do not already exist.  Per bug #7873 by Dave Rolsky.

Author: Pavel Stěhule
Reviewed-by: Jeevan Chalke, Álvaro Herrera, Josh Kupershmidt
10 years agoUse a longer buffer in libpqrcv_startstreaming.
Robert Haas [Mon, 3 Mar 2014 12:24:52 +0000 (07:24 -0500)]
Use a longer buffer in libpqrcv_startstreaming.

Because of the new SLOT clause in the START_REPLICATION command, it's
possible for the command to end up too long for the old maximum buffer
length.

Andres Freund

10 years agoBump catversion.
Robert Haas [Mon, 3 Mar 2014 12:22:20 +0000 (07:22 -0500)]
Bump catversion.

The previous patch should have entailed a catversion bump, but I
forgot.

10 years agoCorrections to replication slots code and documentation.
Robert Haas [Mon, 3 Mar 2014 12:16:54 +0000 (07:16 -0500)]
Corrections to replication slots code and documentation.

Andres Freund, per a report from Vik Faering

10 years agopageinspect: Use new pg_lsn datatype.
Robert Haas [Mon, 3 Mar 2014 12:14:31 +0000 (07:14 -0500)]
pageinspect: Use new pg_lsn datatype.

Michael Paquier, with slight comment changes by me

10 years agoDefine LSNOID in pg_type.h.
Robert Haas [Mon, 3 Mar 2014 12:03:41 +0000 (07:03 -0500)]
Define LSNOID in pg_type.h.

Most other built-in types have a similarly-named constant, so this
type should probably have one, too.

Michael Paquier

10 years agoAnother round of Coverity fixes
Stephen Frost [Mon, 3 Mar 2014 08:18:51 +0000 (03:18 -0500)]
Another round of Coverity fixes

Additional non-security issues/improvements spotted by Coverity.

In backend/libpq, no sense trying to protect against port->hba being
NULL after we've already dereferenced it in the switch() statement.

Prevent against possible overflow due to 32bit arithmitic in
basebackup throttling (not yet released, so no security concern).

Remove nonsensical check of array pointer against NULL in procarray.c,
looks to be a holdover from 9.1 and earlier when there were pointers
being used but now it's just an array.

Remove pointer check-against-NULL in tsearch/spell.c as we had already
dereferenced it above (in the strcmp()).

Remove dead code from adt/orderedsetaggs.c, isnull is checked
immediately after each tuplesort_getdatum() call and if true we return,
so no point checking it again down at the bottom.

Remove recently added minor error-condition memory leak in pg_regress.

10 years agoVarious Coverity-spotted fixes
Stephen Frost [Sun, 2 Mar 2014 03:14:14 +0000 (22:14 -0500)]
Various Coverity-spotted fixes

A number of issues were identified by the Coverity scanner and are
addressed in this patch.  None of these appear to be security issues
and many are mostly cosmetic changes.

Short comments for each of the changes follows.

Correct the semi-colon placement in be-secure.c regarding SSL retries.
Remove a useless comparison-to-NULL in proc.c (value is dereferenced
  prior to this check and therefore can't be NULL).
Add checking of chmod() return values to initdb.
Fix a couple minor memory leaks in initdb.
Fix memory leak in pg_ctl- involves free'ing the config file contents.
Use an int to capture fgetc() return instead of an enum in pg_dump.
Fix minor memory leaks in pg_dump.
  (note minor change to convertOperatorReference()'s API)
Check fclose()/remove() return codes in psql.
Check fstat(), find_my_exec() return codes in psql.
Various ECPG memory leak fixes.
Check find_my_exec() return in ECPG.
Explicitly ignore pqFlush return in libpq error-path.
Change PQfnumber() to avoid doing an strdup() when no changes required.
Remove a few useless check-against-NULL's (value deref'd beforehand).
Check rmtree(), malloc() results in pg_regress.
Also check get_alternative_expectfile() return in pg_regress.

10 years agoAllow regex operations to be terminated early by query cancel requests.
Tom Lane [Sat, 1 Mar 2014 20:20:56 +0000 (15:20 -0500)]
Allow regex operations to be terminated early by query cancel requests.

The regex code didn't have any provision for query cancel; which is
unsurprising given its non-Postgres origin, but still problematic since
some operations can take a long time.  Introduce a callback function to
check for a pending query cancel or session termination request, and
call it in a couple of strategic spots where we can make the regex code
exit with an error indicator.

If we ever actually split out the regex code as a standalone library,
some additional work will be needed to let the cancel callback function
be specified externally to the library.  But that's straightforward
(certainly so by comparison to putting the locale-dependent character
classification logic on a similar arms-length basis), and there seems
no need to do it right now.

A bigger issue is that there may be more places than these two where
we need to check for cancels.  We can always add more checks later,
now that the infrastructure is in place.

Since there are known examples of not-terribly-long regexes that can
lock up a backend for a long time, back-patch to all supported branches.
I have hopes of fixing the known performance problems later, but adding
query cancel ability seems like a good idea even if they were all fixed.

10 years agoRemove bogus while-loop.
Heikki Linnakangas [Fri, 28 Feb 2014 11:22:25 +0000 (13:22 +0200)]
Remove bogus while-loop.

Commit abf5c5c9a4f142b3343614746bb9e99a794f8e7b added a bogus while-
statement after the for(;;)-loop. It went unnoticed in testing, because
it was dead code.

Report by KONDO Mitsumasa. Backpatch to 9.3. The commit that introduced
this was also applied to 9.2, but not the bogus while-loop part, because
the code in 9.2 looks quite different.

10 years agopgbench: Fix help message
Peter Eisentraut [Fri, 28 Feb 2014 02:52:21 +0000 (21:52 -0500)]
pgbench: Fix help message

Add NUM placeholder to -t option in help message.  It got lost in
79cddb18419778be3202c971b3f21cdd90f7b719.

Author: Fabien COELHO <coelho@cri.ensmp.fr>

10 years agoAllow BASE_BACKUP to be throttled
Alvaro Herrera [Thu, 27 Feb 2014 21:55:57 +0000 (18:55 -0300)]
Allow BASE_BACKUP to be throttled

A new MAX_RATE option allows imposing a limit to the network transfer
rate from the server side.  This is useful to limit the stress that
taking a base backup has on the server.

pg_basebackup is now able to specify a value to the server, too.

Author: Antonin Houska

Patch reviewed by Stefan Radomski, Andres Freund, Zoltán Böszörményi,
Fujii Masao, and Álvaro Herrera.

10 years agoRemove dependency on database encoding in citext regression test.
Tom Lane [Thu, 27 Feb 2014 19:58:47 +0000 (14:58 -0500)]
Remove dependency on database encoding in citext regression test.

Testing convert_to(..., 'ISO-8859-1') fails if there isn't a conversion
function available from the database encoding to ISO-8859-1.  This has
been broken since day one, but the breakage was hidden by
pg_do_encoding_conversion's failure to complain, up till commit
49c817eab78c6f0ce8c3bf46766b73d6cf3190b7.

Since the data being converted in this test is plain ASCII, no actual
conversion need happen (and if it did, it would prove little about citext
anyway).  So that we still have some code coverage of the convert() family
of functions, let's switch to using convert_from, with SQL_ASCII as the
specified source encoding.  Per buildfarm.

10 years agodoc: bgw_main takes a Datum argument, not void *.
Alvaro Herrera [Thu, 27 Feb 2014 14:41:43 +0000 (11:41 -0300)]
doc: bgw_main takes a Datum argument, not void *.

Per report from James Harper.

10 years agoFix WAL replay of locking an updated tuple
Alvaro Herrera [Thu, 27 Feb 2014 14:13:39 +0000 (11:13 -0300)]
Fix WAL replay of locking an updated tuple

We were resetting the tuple's HEAP_HOT_UPDATED flag as well as t_ctid on
WAL replay of a tuple-lock operation, which is incorrect when the tuple
is already updated.

Back-patch to 9.3.  The clearing of both header elements was there
previously, but since no update could be present on a tuple that was
being locked, it was harmless.

Bug reported by Peter Geoghegan and Greg Stark in
CAM3SWZTMQiCi5PV5OWHb+bYkUcnCk=O67w0cSswPvV7XfUcU5g@mail.gmail.com and
CAM-w4HPTOeMT4KP0OJK+mGgzgcTOtLRTvFZyvD0O4aH-7dxo3Q@mail.gmail.com
respectively; diagnosis by Andres Freund.

10 years agobtbuild no longer calls _bt_doinsert(), update comment.
Heikki Linnakangas [Wed, 26 Feb 2014 16:48:21 +0000 (18:48 +0200)]
btbuild no longer calls _bt_doinsert(), update comment.

Peter Geoghegan