]> granicus.if.org Git - postgresql/log
postgresql
9 years agoRevert the GinMaxItemSize calculation so that we fit 3 tuples per page.
Heikki Linnakangas [Tue, 30 Dec 2014 12:29:20 +0000 (14:29 +0200)]
Revert the GinMaxItemSize calculation so that we fit 3 tuples per page.

Commit 36a35c55 changed the divisor from 3 to 6, for no apparent reason.
Reducing GinMaxItemSize like that created a dump/reload hazard: loading a
9.3 database to 9.4 might fail with "index row size XXX exceeds maximum 1352
for index ..." error. Revert the change.

While we're at it, make the calculation slightly more accurate. It used to
divide the available space on page by three, then subtract
sizeof(ItemIdData), and finally round down. That's not totally accurate; the
item pointers for the three items are packed tight right after the page
header, but there is alignment padding after the item pointers. Change the
calculation to reflect that, like BTMaxItemSize does. I tested this with
different block sizes on systems with 4- and 8-byte alignment, and the value
after the final MAXALIGN_DOWN was the same with both methods on all
configurations. So this does not make any difference currently, but let's be
tidy.

Also add a comment explaining what the macro does.

This fixes bug #12292 reported by Robert Thaler. Backpatch to 9.4, where the
bug was introduced.

9 years agoFix resource leak pointed out by Coverity.
Tatsuo Ishii [Tue, 30 Dec 2014 11:19:50 +0000 (20:19 +0900)]
Fix resource leak pointed out by Coverity.

9 years agoBackpatch variable renaming in formatting.c
Bruce Momjian [Tue, 30 Dec 2014 02:25:23 +0000 (21:25 -0500)]
Backpatch variable renaming in formatting.c

Backpatch a9c22d1480aa8e6d97a000292d05ef2b31bbde4e to make future
backpatching easier.

Backpatch through 9.0

9 years agoAssorted minor fixes for psql metacommand docs.
Tom Lane [Mon, 29 Dec 2014 19:20:56 +0000 (14:20 -0500)]
Assorted minor fixes for psql metacommand docs.

Document the long forms of \H \i \ir \o \p \r \w ... apparently, we have
a long and dishonorable history of leaving out the unabbreviated names of
psql backslash commands.

Avoid saying "Unix shell"; we can just say "shell" with equal clarity,
and not leave Windows users wondering whether the feature works for them.

Improve consistency of documentation of \g \o \w metacommands.  There's
no reason to use slightly different wording or markup for each one.

9 years agoGrab heavyweight tuple lock only before sleeping
Alvaro Herrera [Fri, 26 Dec 2014 16:52:27 +0000 (13:52 -0300)]
Grab heavyweight tuple lock only before sleeping

We were trying to acquire the lock even when we were subsequently
not sleeping in some other transaction, which opens us up unnecessarily
to deadlocks.  In particular, this is troublesome if an update tries to
lock an updated version of a tuple and finds itself doing EvalPlanQual
update chain walking; more than two sessions doing this concurrently
will find themselves sleeping on each other because the HW tuple lock
acquisition in heap_lock_tuple called from EvalPlanQualFetch races with
the same tuple lock being acquired in heap_update -- one of these
sessions sleeps on the other one to finish while holding the tuple lock,
and the other one sleeps on the tuple lock.

Per trouble report from Andrew Sackville-West in
http://www.postgresql.org/message-id/20140731233051.GN17765@andrew-ThinkPad-X230

His scenario can be simplified down to a relatively simple
isolationtester spec file which I don't include in this commit; the
reason is that the current isolationtester is not able to deal with more
than one blocked session concurrently and it blocks instead of raising
the expected deadlock.  In the future, if we improve isolationtester, it
would be good to include the spec file in the isolation schedule.  I
posted it in
http://www.postgresql.org/message-id/20141212205254.GC1768@alvh.no-ip.org

Hat tip to Mark Kirkwood, who helped diagnose the trouble.

9 years agoHave config_sspi_auth() permit IPv6 localhost connections.
Noah Misch [Thu, 25 Dec 2014 18:52:03 +0000 (13:52 -0500)]
Have config_sspi_auth() permit IPv6 localhost connections.

Windows versions later than Windows Server 2003 map "localhost" to ::1.
Account for that in the generated pg_hba.conf, fixing another oversight
in commit f6dc6dd5ba54d52c0733aaafc50da2fbaeabb8b0.  Back-patch to 9.0,
like that commit.

David Rowley and Noah Misch

9 years agoRemove duplicate include of slot.h.
Fujii Masao [Thu, 25 Dec 2014 13:47:53 +0000 (22:47 +0900)]
Remove duplicate include of slot.h.

Back-patch to 9.4, where this problem was added.

9 years agoAdd CST (China Standard Time) to our lists of timezone abbreviations.
Tom Lane [Wed, 24 Dec 2014 21:35:23 +0000 (16:35 -0500)]
Add CST (China Standard Time) to our lists of timezone abbreviations.

For some reason this seems to have been missed when the lists in
src/timezone/tznames/ were first constructed.  We can't put it in Default
because of the conflict with US CST, but we should certainly list it among
the alternative entries in Asia.txt.  (I checked for other oversights, but
all the other abbreviations that are in current use according to the IANA
files seem to be accounted for.)  Noted while responding to bug #12326.

9 years agoFix installcheck case for tap tests
Andrew Dunstan [Wed, 24 Dec 2014 15:31:36 +0000 (10:31 -0500)]
Fix installcheck case for tap tests

9 years agoFurther tidy up on json aggregate documentation
Andrew Dunstan [Mon, 22 Dec 2014 23:31:25 +0000 (18:31 -0500)]
Further tidy up on json aggregate documentation

9 years agoFix documentation of argument type of json_agg and jsonb_agg
Andrew Dunstan [Mon, 22 Dec 2014 19:20:19 +0000 (14:20 -0500)]
Fix documentation of argument type of json_agg and jsonb_agg

json_agg was originally designed to aggregate records. However, it soon
became clear that it is useful for aggregating all kinds of values and
that's what we have on 9.3 and 9.4, and in head for it and jsonb_agg.
The documentation suggested otherwise, so this fixes it.

9 years agoDocs: clarify treatment of variadic functions with zero variadic arguments.
Tom Lane [Sun, 21 Dec 2014 20:30:39 +0000 (15:30 -0500)]
Docs: clarify treatment of variadic functions with zero variadic arguments.

Explain that you have to use "VARIADIC ARRAY[]" to pass an empty array
to a variadic parameter position.  This was already implicit in the text
but it seems better to spell it out.

Per a suggestion from David Johnston, though I didn't use his proposed
wording.  Back-patch to all supported branches.

9 years agoFix timestamp in end-of-recovery WAL records.
Heikki Linnakangas [Fri, 19 Dec 2014 15:00:21 +0000 (17:00 +0200)]
Fix timestamp in end-of-recovery WAL records.

We used time(null) to set a TimestampTz field, which gave bogus results.
Noticed while looking at pg_xlogdump output.

Backpatch to 9.3 and above, where the fast promotion was introduced.

9 years agoPrevent potentially hazardous compiler/cpu reordering during lwlock release.
Andres Freund [Fri, 19 Dec 2014 13:29:52 +0000 (14:29 +0100)]
Prevent potentially hazardous compiler/cpu reordering during lwlock release.

In LWLockRelease() (and in 9.4+ LWLockUpdateVar()) we release enqueued
waiters using PGSemaphoreUnlock(). As there are other sources of such
unlocks backends only wake up if MyProc->lwWaiting is set to false;
which is only done in the aforementioned functions.

Before this commit there were dangers because the store to lwWaitLink
could become visible before the store to lwWaitLink. This could both
happen due to compiler reordering (on most compilers) and on some
platforms due to the CPU reordering stores.

The possible consequence of this is that a backend stops waiting
before lwWaitLink is set to NULL. If that backend then tries to
acquire another lock and has to wait there the list could become
corrupted once the lwWaitLink store is finally performed.

Add a write memory barrier to prevent that issue.

Unfortunately the barrier support has been only added in 9.2. Given
that the issue has not knowingly been observed in praxis it seems
sufficient to prohibit compiler reordering using volatile for 9.0 and
9.1. Actual problems due to compiler reordering are more likely
anyway.

Discussion: 20140210134625.GA15246@awork2.anarazel.de

9 years agoImprove documentation about CASE and constant subexpressions.
Tom Lane [Thu, 18 Dec 2014 21:38:55 +0000 (16:38 -0500)]
Improve documentation about CASE and constant subexpressions.

The possibility that constant subexpressions of a CASE might be evaluated
at planning time was touched on in 9.17.1 (CASE expressions), but it really
ought to be explained in 4.2.14 (Expression Evaluation Rules) which is the
primary discussion of such topics.  Add text and an example there, and
revise the <note> under CASE to link there.

Back-patch to all supported branches, since it's acted like this for a
long time (though 9.2+ is probably worse because of its more aggressive
use of constant-folding via replanning of nominally-prepared statements).
Pre-9.4, also back-patch text added in commit 0ce627d4 about CASE versus
aggregate functions.

Tom Lane and David Johnston, per discussion of bug #12273.

9 years agoRecognize Makefile line continuations in fetchRegressOpts().
Noah Misch [Thu, 18 Dec 2014 08:55:17 +0000 (03:55 -0500)]
Recognize Makefile line continuations in fetchRegressOpts().

Back-patch to 9.0 (all supported versions).  This is mere
future-proofing in the context of the master branch, but commit
f6dc6dd5ba54d52c0733aaafc50da2fbaeabb8b0 requires it of older branches.

9 years agoFix (re-)starting from a basebackup taken off a standby after a failure.
Andres Freund [Thu, 18 Dec 2014 07:35:27 +0000 (08:35 +0100)]
Fix (re-)starting from a basebackup taken off a standby after a failure.

When starting up from a basebackup taken off a standby extra logic has
to be applied to compute the point where the data directory is
consistent. Normal base backups use a WAL record for that purpose, but
that isn't possible on a standby.

That logic had a error check ensuring that the cluster's control file
indicates being in recovery. Unfortunately that check was too strict,
disregarding the fact that the control file could also indicate that
the cluster was shut down while in recovery.

That's possible when the a cluster starting from a basebackup is shut
down before the backup label has been removed. When everything goes
well that's a short window, but when either restore_command or
primary_conninfo isn't configured correctly the window can get much
wider. That's because inbetween reading and unlinking the label we
restore the last checkpoint from WAL which can need additional WAL.

To fix simply also allow starting when the control file indicates
"shutdown in recovery". There's nicer fixes imaginable, but they'd be
more invasive.

Backpatch to 9.2 where support for taking basebackups from standbys
was added.

9 years agoFix previous commit for TAP test suites in VPATH builds.
Noah Misch [Thu, 18 Dec 2014 06:24:57 +0000 (01:24 -0500)]
Fix previous commit for TAP test suites in VPATH builds.

Per buildfarm member crake.  Back-patch to 9.4, where the TAP suites
were introduced.

9 years agoLock down regression testing temporary clusters on Windows.
Noah Misch [Thu, 18 Dec 2014 03:48:40 +0000 (22:48 -0500)]
Lock down regression testing temporary clusters on Windows.

Use SSPI authentication to allow connections exclusively from the OS
user that launched the test suite.  This closes on Windows the
vulnerability that commit be76a6d39e2832d4b88c0e1cc381aa44a7f86881
closed on other platforms.  Users of "make installcheck" or custom test
harnesses can run "pg_regress --config-auth=DATADIR" to activate the
same authentication configuration that "make check" would use.
Back-patch to 9.0 (all supported versions).

Security: CVE-2014-0067

9 years agoFix another poorly worded error message.
Tom Lane [Wed, 17 Dec 2014 18:22:07 +0000 (13:22 -0500)]
Fix another poorly worded error message.

Spotted by Álvaro Herrera.

9 years agoFix poorly worded error message.
Tom Lane [Wed, 17 Dec 2014 18:14:57 +0000 (13:14 -0500)]
Fix poorly worded error message.

Adam Brightwell, per report from Martín Marqués.

9 years agoUpdate .gitignore for pg_upgrade
Magnus Hagander [Wed, 17 Dec 2014 10:55:22 +0000 (11:55 +0100)]
Update .gitignore for pg_upgrade

Add Windows versions of generated scripts, and make sure we only
ignore the scripts int he root directory.

Michael Paquier

9 years agoAdd missing documentation for some vcregress modes
Magnus Hagander [Wed, 17 Dec 2014 10:14:34 +0000 (11:14 +0100)]
Add missing documentation for some vcregress modes

Michael Paquier

9 years agoRemove redundant sentence
Magnus Hagander [Wed, 17 Dec 2014 08:59:21 +0000 (09:59 +0100)]
Remove redundant sentence

Spotted by David Johnston

9 years agoFix off-by-one loop count in MapArrayTypeName, and get rid of static array.
Tom Lane [Tue, 16 Dec 2014 20:35:36 +0000 (15:35 -0500)]
Fix off-by-one loop count in MapArrayTypeName, and get rid of static array.

MapArrayTypeName would copy up to NAMEDATALEN-1 bytes of the base type
name, which of course is wrong: after prepending '_' there is only room for
NAMEDATALEN-2 bytes.  Aside from being the wrong result, this case would
lead to overrunning the statically allocated work buffer.  This would be a
security bug if the function were ever used outside bootstrap mode, but it
isn't, at least not in any currently supported branches.

Aside from fixing the off-by-one loop logic, this patch gets rid of the
static work buffer by having MapArrayTypeName pstrdup its result; the sole
caller was already doing that, so this just requires moving the pstrdup
call.  This saves a few bytes but mainly it makes the API a lot cleaner.

Back-patch on the off chance that there is some third-party code using
MapArrayTypeName with less-secure input.  Pushing pstrdup into the function
should not cause any serious problems for such hypothetical code; at worst
there might be a short term memory leak.

Per Coverity scanning.

9 years agoSuppress bogus statistics when pgbench failed to complete any transactions.
Tom Lane [Tue, 16 Dec 2014 19:53:58 +0000 (14:53 -0500)]
Suppress bogus statistics when pgbench failed to complete any transactions.

Code added in 9.4 would attempt to divide by zero in such cases.
Noted while testing fix for missing-pclose problem.

9 years agoFix file descriptor leak after failure of a \setshell command in pgbench.
Tom Lane [Tue, 16 Dec 2014 18:31:42 +0000 (13:31 -0500)]
Fix file descriptor leak after failure of a \setshell command in pgbench.

If the called command fails to return data, runShellCommand forgot to
pclose() the pipe before returning.  This is fairly harmless in the current
code, because pgbench would then abandon further processing of that client
thread; so no more than nclients descriptors could be leaked this way.  But
it's not hard to imagine future improvements whereby that wouldn't be true.
In any case, it's sloppy coding, so patch all branches.  Found by Coverity.

9 years agoMisc comment typo fixes.
Heikki Linnakangas [Tue, 16 Dec 2014 14:34:56 +0000 (16:34 +0200)]
Misc comment typo fixes.

Backpatch the applicable parts, just to make backpatching future patches
easier.

9 years agoStamp 9.4.0. REL9_4_0
Tom Lane [Tue, 16 Dec 2014 01:07:34 +0000 (20:07 -0500)]
Stamp 9.4.0.

9 years agoTranslation updates
Alvaro Herrera [Mon, 15 Dec 2014 22:27:12 +0000 (19:27 -0300)]
Translation updates

9 years agoTranslation updates
Peter Eisentraut [Mon, 15 Dec 2014 21:18:13 +0000 (16:18 -0500)]
Translation updates

9 years agoadd missing newline
Alvaro Herrera [Mon, 15 Dec 2014 19:49:41 +0000 (16:49 -0300)]
add missing newline

9 years agoTranslation updates
Peter Eisentraut [Mon, 15 Dec 2014 05:23:25 +0000 (00:23 -0500)]
Translation updates

9 years agodoc: Add link to how to specify time zone names to initdb man page
Peter Eisentraut [Mon, 15 Dec 2014 01:02:04 +0000 (20:02 -0500)]
doc: Add link to how to specify time zone names to initdb man page

9 years agoImprove documentation around parameter-setting and ALTER SYSTEM.
Tom Lane [Sun, 14 Dec 2014 23:09:55 +0000 (18:09 -0500)]
Improve documentation around parameter-setting and ALTER SYSTEM.

The ALTER SYSTEM ref page hadn't been held to a very high standard, nor
was the feature well integrated into section 18.1 (parameter setting).
Also, though commit 4c4654afe had improved the structure of 18.1, it also
introduced a lot of poor wording, imprecision, and outright falsehoods.
Try to clean that up.

9 years agoUpdate 9.4 release notes.
Tom Lane [Sun, 14 Dec 2014 19:58:06 +0000 (14:58 -0500)]
Update 9.4 release notes.

Set release date, do a final pass of wordsmithing, improve some other
new-in-9.4 documentation.

9 years agoImprove recovery target settings documentation.
Tom Lane [Sat, 13 Dec 2014 18:46:46 +0000 (13:46 -0500)]
Improve recovery target settings documentation.

Commit 815d71dee hadn't bothered to update the documentation to match the
behavioral change, and a lot of other text in this section was badly in
need of copy-editing.

9 years agoRepair corner-case bug in array version of percentile_cont().
Tom Lane [Sat, 13 Dec 2014 16:49:20 +0000 (11:49 -0500)]
Repair corner-case bug in array version of percentile_cont().

The code for advancing through the input rows overlooked the case that we
might already be past the first row of the row pair now being considered,
in case the previous percentile also fell between the same two input rows.

Report and patch by Andrew Gierth; logic rewritten a bit for clarity by me.

9 years agoRevert misguided change to postgres_fdw FOR UPDATE/SHARE code.
Tom Lane [Fri, 12 Dec 2014 17:41:52 +0000 (12:41 -0500)]
Revert misguided change to postgres_fdw FOR UPDATE/SHARE code.

In commit 462bd95705a0c23ba0b0ba60a78d32566a0384c1, I changed postgres_fdw
to rely on get_plan_rowmark() instead of get_parse_rowmark().  I still
think that's a good idea in the long run, but as Etsuro Fujita pointed out,
it doesn't work today because planner.c forces PlanRowMarks to have
markType = ROW_MARK_COPY for all foreign tables.  There's no urgent reason
to change this in the back branches, so let's just revert that part of
yesterday's commit rather than trying to design a better solution under
time pressure.

Also, add a regression test case showing what postgres_fdw does with FOR
UPDATE/SHARE.  I'd blithely assumed there was one already, else I'd have
realized yesterday that this code didn't work.

9 years agoFix planning of SELECT FOR UPDATE on child table with partial index.
Tom Lane [Fri, 12 Dec 2014 02:02:28 +0000 (21:02 -0500)]
Fix planning of SELECT FOR UPDATE on child table with partial index.

Ordinarily we can omit checking of a WHERE condition that matches a partial
index's condition, when we are using an indexscan on that partial index.
However, in SELECT FOR UPDATE we must include the "redundant" filter
condition in the plan so that it gets checked properly in an EvalPlanQual
recheck.  The planner got this mostly right, but improperly omitted the
filter condition if the index in question was on an inheritance child
table.  In READ COMMITTED mode, this could result in incorrectly returning
just-updated rows that no longer satisfy the filter condition.

The cause of the error is using get_parse_rowmark() when get_plan_rowmark()
is what should be used during planning.  In 9.3 and up, also fix the same
mistake in contrib/postgres_fdw.  It's currently harmless there (for lack
of inheritance support) but wrong is wrong, and the incorrect code might
get copied to someplace where it's more significant.

Report and fix by Kyotaro Horiguchi.  Back-patch to all supported branches.

9 years agoFix corner case where SELECT FOR UPDATE could return a row twice.
Tom Lane [Fri, 12 Dec 2014 00:37:03 +0000 (19:37 -0500)]
Fix corner case where SELECT FOR UPDATE could return a row twice.

In READ COMMITTED mode, if a SELECT FOR UPDATE discovers it has to redo
WHERE-clause checking on rows that have been updated since the SELECT's
snapshot, it invokes EvalPlanQual processing to do that.  If this first
occurs within a non-first child table of an inheritance tree, the previous
coding could accidentally re-return a matching row from an earlier,
already-scanned child table.  (And, to add insult to injury, I think this
could make it miss returning a row that should have been returned, if the
updated row that this happens on should still have passed the WHERE qual.)
Per report from Kyotaro Horiguchi; the added isolation test is based on his
test case.

This has been broken for quite awhile, so back-patch to all supported
branches.

9 years agoFix assorted confusion between Oid and int32.
Tom Lane [Thu, 11 Dec 2014 20:41:20 +0000 (15:41 -0500)]
Fix assorted confusion between Oid and int32.

In passing, also make some debugging elog's in pgstat.c a bit more
consistently worded.

Back-patch as far as applicable (9.3 or 9.4; none of these mistakes are
really old).

Mark Dilger identified and patched the type violations; the message
rewordings are mine.

9 years agoFix typo
Peter Eisentraut [Thu, 11 Dec 2014 01:55:30 +0000 (20:55 -0500)]
Fix typo

Author: Fabrízio de Royes Mello <fabriziomello@gmail.com>

9 years agoFix minor thinko in convertToJsonb().
Tom Lane [Thu, 11 Dec 2014 00:06:27 +0000 (19:06 -0500)]
Fix minor thinko in convertToJsonb().

The amount of space to reserve for the value's varlena header is
VARHDRSZ, not sizeof(VARHDRSZ).  The latter coding accidentally
failed to fail because of the way the VARHDRSZ macro is currently
defined; but if we ever change it to return size_t (as one might
reasonably expect it to do), convertToJsonb() would have failed.

Spotted by Mark Dilger.

9 years agoGive a proper error message if initdb password file is empty.
Heikki Linnakangas [Fri, 5 Dec 2014 12:27:56 +0000 (14:27 +0200)]
Give a proper error message if initdb password file is empty.

Used to say just "could not read password from file "...": Success", which
isn't very informative.

Mats Erik Andersson. Backpatch to all supported versions.

9 years agoPrint wal_log_hints in the rm_desc routing of a parameter-change record.
Heikki Linnakangas [Fri, 5 Dec 2014 09:58:24 +0000 (11:58 +0200)]
Print wal_log_hints in the rm_desc routing of a parameter-change record.

It was an oversight in the original commit.

Also note in the sample config file that changing wal_log_hints requires a
restart.

Michael Paquier. Backpatch to 9.4, where wal_log_hints was added.

9 years agoFix PGXS vpath build when PostgreSQL is built with vpath
Peter Eisentraut [Thu, 4 Dec 2014 22:02:02 +0000 (17:02 -0500)]
Fix PGXS vpath build when PostgreSQL is built with vpath

PGXS computes srcdir from VPATH, PostgreSQL proper computes VPATH from
srcdir, and doing both results in an error from make.  Conditionalize so
only one of these takes effect.

9 years agoRemove USE_VPATH make variable from PGXS
Peter Eisentraut [Thu, 20 Nov 2014 02:51:30 +0000 (21:51 -0500)]
Remove USE_VPATH make variable from PGXS

The user can just set VPATH directly.  There is no need to invent
another variable.

9 years agoFix SHLIB_PREREQS use in contrib, allowing PGXS builds
Peter Eisentraut [Thu, 4 Dec 2014 12:58:12 +0000 (07:58 -0500)]
Fix SHLIB_PREREQS use in contrib, allowing PGXS builds

dblink and postgres_fdw use SHLIB_PREREQS = submake-libpq to build libpq
first.  This doesn't work in a PGXS build, because there is no libpq to
build.  So just omit setting SHLIB_PREREQS in this case.

Note that PGXS users can still use SHLIB_PREREQS (although it is not
documented).  The problem here is only that contrib modules can be built
in-tree or using PGXS, and the prerequisite is only applicable in the
former case.

Commit 6697aa2bc25c83b88d6165340348a31328c35de6 previously attempted to
address this by creating a somewhat fake submake-libpq target in
Makefile.global.  That was not the right fix, and it was also done in a
nonportable way, so revert that.

9 years agoMove PG_AUTOCONF_FILENAME definition
Peter Eisentraut [Thu, 4 Dec 2014 00:54:01 +0000 (19:54 -0500)]
Move PG_AUTOCONF_FILENAME definition

Since this is not something that a user should change,
pg_config_manual.h was an inappropriate place for it.

In initdb.c, remove the use of the macro, because utils/guc.h can't be
included by non-backend code.  But we hardcode all the other
configuration file names there, so this isn't a disaster.

9 years agoFix typos
Alvaro Herrera [Wed, 3 Dec 2014 14:52:16 +0000 (11:52 -0300)]
Fix typos

9 years agoImprove error messages for malformed array input strings.
Tom Lane [Tue, 2 Dec 2014 23:23:20 +0000 (18:23 -0500)]
Improve error messages for malformed array input strings.

Make the error messages issued by array_in() uniformly follow the style
ERROR: malformed array literal: "actual input string"
DETAIL: specific complaint here
and rewrite many of the specific complaints to be clearer.

The immediate motivation for doing this is a complaint from Josh Berkus
that json_to_record() produced an unintelligible error message when
dealing with an array item, because it tries to feed the JSON-format
array value to array_in().  Really it ought to be smart enough to
perform JSON-to-Postgres array conversion, but that's a future feature
not a bug fix.  In the meantime, this change is something we agreed
we could back-patch into 9.4, and it should help de-confuse things a bit.

9 years agoDon't skip SQL backends in logical decoding for visibility computation.
Andres Freund [Tue, 2 Dec 2014 22:42:26 +0000 (23:42 +0100)]
Don't skip SQL backends in logical decoding for visibility computation.

The logical decoding patchset introduced PROC_IN_LOGICAL_DECODING flag
PGXACT flag, that allows such backends to be skipped when computing
the xmin horizon/snapshots. That's fine and sensible for walsenders
streaming out logical changes, but not at all fine for SQL backends
doing logical decoding. If the latter set that flag any change they
have performed outside of logical decoding will not be regarded as
visible - which e.g. can lead to that change being vacuumed away.

Note that not setting the flag for SQL backends isn't particularly
bothersome - the SQL backend doesn't do streaming, so it only runs for
a limited amount of time.

Per buildfarm member 'tick' and Alvaro.

Backpatch to 9.4, where logical decoding was introduced.

9 years agoFix JSON aggregates to work properly when final function is re-executed.
Tom Lane [Tue, 2 Dec 2014 20:02:40 +0000 (15:02 -0500)]
Fix JSON aggregates to work properly when final function is re-executed.

Davide S. reported that json_agg() sometimes produced multiple trailing
right brackets.  This turns out to be because json_agg_finalfn() attaches
the final right bracket, and was doing so by modifying the aggregate state
in-place.  That's verboten, though unfortunately it seems there's no way
for nodeAgg.c to check for such mistakes.

Fix that back to 9.3 where the broken code was introduced.  In 9.4 and
HEAD, likewise fix json_object_agg(), which had copied the erroneous logic.
Make some cosmetic cleanups as well.

9 years agoGuard against bad "dscale" values in numeric_recv().
Tom Lane [Mon, 1 Dec 2014 20:25:05 +0000 (15:25 -0500)]
Guard against bad "dscale" values in numeric_recv().

We were not checking to see if the supplied dscale was valid for the given
digit array when receiving binary-format numeric values.  While dscale can
validly be more than the number of nonzero fractional digits, it shouldn't
be less; that case causes fractional digits to be hidden on display even
though they're there and participate in arithmetic.

Bug #12053 from Tommaso Sala indicates that there's at least one broken
client library out there that sometimes supplies an incorrect dscale value,
leading to strange behavior.  This suggests that simply throwing an error
might not be the best response; it would lead to failures in applications
that might seem to be working fine today.  What seems the least risky fix
is to truncate away any digits that would be hidden by dscale.  This
preserves the existing behavior in terms of what will be printed for the
transmitted value, while preventing subsequent arithmetic from producing
results inconsistent with that.

In passing, throw a specific error for the case of dscale being outside
the range that will fit into a numeric's header.  Before you got "value
overflows numeric format", which is a bit misleading.

Back-patch to all supported branches.

9 years agoFix hstore_to_json_loose's detection of valid JSON number values.
Andrew Dunstan [Mon, 1 Dec 2014 16:28:45 +0000 (11:28 -0500)]
Fix hstore_to_json_loose's detection of valid JSON number values.

We expose a function IsValidJsonNumber that internally calls the lexer
for json numbers. That allows us to use the same test everywhere,
instead of inventing a broken test for hstore conversions. The new
function is also used in datum_to_json, replacing the code that is now
moved to the new function.

Backpatch to 9.3 where hstore_to_json_loose was introduced.

9 years agoFix missing space in documentation
Magnus Hagander [Mon, 1 Dec 2014 11:12:07 +0000 (12:12 +0100)]
Fix missing space in documentation

Ian Barwick

9 years agoFix minor bugs in commit 30bf4689a96cd283af33edcdd6b7210df3f20cd8 et al.
Tom Lane [Sun, 30 Nov 2014 17:20:47 +0000 (12:20 -0500)]
Fix minor bugs in commit 30bf4689a96cd283af33edcdd6b7210df3f20cd8 et al.

Coverity complained that the "else" added to fillPGconn() was unreachable,
which it was.  Remove the dead code.  In passing, rearrange the tests so as
not to bother trying to fetch values for options that can't be assigned.

Pre-9.3 did not have that issue, but it did have a "return" that should be
"goto oom_error" to ensure that a suitable error message gets filled in.

9 years agoRemove PQhostaddr() from 9.4 release notes.
Noah Misch [Sat, 29 Nov 2014 20:53:05 +0000 (15:53 -0500)]
Remove PQhostaddr() from 9.4 release notes.

Back-patch to 9.4, like the feature's removal.

9 years agoReimplement 9f80f4835a55a1cbffcda5d23a617917f3286c14 with PQconninfo().
Noah Misch [Sat, 29 Nov 2014 17:31:43 +0000 (12:31 -0500)]
Reimplement 9f80f4835a55a1cbffcda5d23a617917f3286c14 with PQconninfo().

Apart from ignoring "hostaddr" set to the empty string, this behaves
identically to its predecessor.  Back-patch to 9.4, where the original
commit first appeared.

Reviewed by Fujii Masao.

9 years agoRevert "Add libpq function PQhostaddr()."
Noah Misch [Sat, 29 Nov 2014 17:31:21 +0000 (12:31 -0500)]
Revert "Add libpq function PQhostaddr()."

This reverts commit 9f80f4835a55a1cbffcda5d23a617917f3286c14.  The
function returned the raw value of a connection parameter, a task served
by PQconninfo().  The next commit will reimplement the psql \conninfo
change that way.  Back-patch to 9.4, where that commit first appeared.

9 years agoUpdate transaction README for persistent multixacts
Alvaro Herrera [Fri, 28 Nov 2014 21:06:18 +0000 (18:06 -0300)]
Update transaction README for persistent multixacts

Multixacts are now maintained during recovery, but the README didn't get
the memo.  Backpatch to 9.3, where the divergence was introduced.

9 years agoAdd tab-completion for ALTER TABLE ALTER CONSTRAINT in psql.
Fujii Masao [Fri, 28 Nov 2014 12:29:45 +0000 (21:29 +0900)]
Add tab-completion for ALTER TABLE ALTER CONSTRAINT in psql.

Back-patch to 9.4 where ALTER TABLE ALTER CONSTRAINT was added.

Michael Paquier, bug reported by Andrey Lizenko.

9 years agoMake \watch respect the user's \pset null setting.
Fujii Masao [Thu, 27 Nov 2014 17:42:43 +0000 (02:42 +0900)]
Make \watch respect the user's \pset null setting.

Previously \watch always ignored the user's \pset null setting.
\pset null setting should be ignored for \d and similar queries.
For those, the code can reasonably have an opinion about what
the presentation should be like, since it knows what SQL query
it's issuing. This argument surely doesn't apply to \watch,
so this commit makes \watch use the user's \pset null setting.

Back-patch to 9.3 where \watch was added.

9 years agoMark response messages for translation in pg_isready.
Fujii Masao [Thu, 27 Nov 2014 17:12:45 +0000 (02:12 +0900)]
Mark response messages for translation in pg_isready.

Back-patch to 9.3 where pg_isready was added.

Mats Erik Andersson

9 years agoFree libxml2/libxslt resources in a safer order.
Tom Lane [Thu, 27 Nov 2014 16:12:47 +0000 (11:12 -0500)]
Free libxml2/libxslt resources in a safer order.

Mark Simonetti reported that libxslt sometimes crashes for him, and that
swapping xslt_process's object-freeing calls around to do them in reverse
order of creation seemed to fix it.  I've not reproduced the crash, but
valgrind clearly shows a reference to already-freed memory, which is
consistent with the idea that shutdown of the xsltTransformContext is
trying to reference the already-freed stylesheet or input document.
With this patch, valgrind is no longer unhappy.

I have an inquiry in to see if this is a libxslt bug or if we're just
abusing the library; but even if it's a library bug, we'd want to adjust
our code so it doesn't fail with unpatched libraries.

Back-patch to all supported branches, because we've been doing this in
the wrong(?) order for a long time.

9 years agoAllow "dbname" from connection string to be overridden in PQconnectDBParams
Heikki Linnakangas [Tue, 25 Nov 2014 15:12:07 +0000 (17:12 +0200)]
Allow "dbname" from connection string to be overridden in PQconnectDBParams

If the "dbname" attribute in PQconnectDBParams contained a connection string
or URI (and expand_dbname = TRUE), the database name from the connection
string could not be overridden by a subsequent "dbname" keyword in the
array. That was not intentional; all other options can be overridden.
Furthermore, any subsequent "dbname" caused the connection string from the
first dbname value to be processed again, overriding any values for the same
options that were given between the connection string and the second dbname
option.

In the passing, clarify in the docs that only the first dbname option in the
array is parsed as a connection string.

Alex Shulgin. Backpatch to all supported versions.

9 years agoCheck return value of strdup() in libpq connection option parsing.
Heikki Linnakangas [Tue, 25 Nov 2014 10:55:00 +0000 (12:55 +0200)]
Check return value of strdup() in libpq connection option parsing.

An out-of-memory in most of these would lead to strange behavior, like
connecting to a different database than intended, but some would lead to
an outright segfault.

Alex Shulgin and me. Backpatch to all supported versions.

9 years agoFix mishandling of system columns in FDW queries.
Tom Lane [Sat, 22 Nov 2014 21:01:08 +0000 (16:01 -0500)]
Fix mishandling of system columns in FDW queries.

postgres_fdw would send query conditions involving system columns to the
remote server, even though it makes no effort to ensure that system
columns other than CTID match what the remote side thinks.  tableoid,
in particular, probably won't match and might have some use in queries.
Hence, prevent sending conditions that include non-CTID system columns.

Also, create_foreignscan_plan neglected to check local restriction
conditions while determining whether to set fsSystemCol for a foreign
scan plan node.  This again would bollix the results for queries that
test a foreign table's tableoid.

Back-patch the first fix to 9.3 where postgres_fdw was introduced.
Back-patch the second to 9.2.  The code is probably broken in 9.1 as
well, but the patch doesn't apply cleanly there; given the weak state
of support for FDWs in 9.1, it doesn't seem worth fixing.

Etsuro Fujita, reviewed by Ashutosh Bapat, and somewhat modified by me

9 years agoImprove documentation's description of JOIN clauses.
Tom Lane [Wed, 19 Nov 2014 21:00:27 +0000 (16:00 -0500)]
Improve documentation's description of JOIN clauses.

In bug #12000, Andreas Kunert complained that the documentation was
misleading in saying "FROM T1 CROSS JOIN T2 is equivalent to FROM T1, T2".
That's correct as far as it goes, but the equivalence doesn't hold when
you consider three or more tables, since JOIN binds more tightly than
comma.  I added a <note> to explain this, and ended up rearranging some
of the existing text so that the note would make sense in context.

In passing, rewrite the description of JOIN USING, which was unnecessarily
vague, and hadn't been helped any by somebody's reliance on markup as a
substitute for clear writing.  (Mostly this involved reintroducing a
concrete example that was unaccountably removed by commit 032f3b7e166cfa28.)

Back-patch to all supported branches.

9 years agoAvoid file descriptor leak in pg_test_fsync.
Robert Haas [Wed, 19 Nov 2014 16:57:54 +0000 (11:57 -0500)]
Avoid file descriptor leak in pg_test_fsync.

This can cause problems on Windows, where files that are still open
can't be unlinked.

Jeff Janes

9 years agoFix bug in the test of file descriptor of current WAL file in pg_receivexlog.
Fujii Masao [Wed, 19 Nov 2014 10:11:03 +0000 (19:11 +0900)]
Fix bug in the test of file descriptor of current WAL file in pg_receivexlog.

In pg_receivexlog, in order to check whether the current WAL file is
being opened or not, its file descriptor has to be checked against -1
as an invalid value. But, oops, 7900e94 added the incorrect test
checking the descriptor against 1. This commit fixes that bug.

Back-patch to 9.4 where the bug was added.

Spotted by Magnus Hagander

9 years agoFix pg_receivexlog --slot so that it doesn't prevent the server shutdown.
Fujii Masao [Wed, 19 Nov 2014 05:11:48 +0000 (14:11 +0900)]
Fix pg_receivexlog --slot so that it doesn't prevent the server shutdown.

When pg_receivexlog --slot is connecting to the server, at the shutdown
of the server, walsender keeps waiting for the last WAL record to be
replicated and flushed in pg_receivexlog. But previously pg_receivexlog
issued sync command only when WAL file was switched. So there was
the case where the last WAL was never flushed and walsender had to
keep waiting infinitely. This caused the server shutdown to get stuck.

pg_recvlogical handles this problem by calling fsync() when it receives
the request of immediate reply from the server. That is, at shutdown,
walsender sends the request, pg_recvlogical receives it, flushes the last
WAL record, and sends the flush location back to the server. Since
walsender can see that the last WAL record is successfully flushed, it can
exit cleanly.

This commit introduces the same logic as pg_recvlogical has,
to pg_receivexlog.

Back-patch to 9.4 where pg_receivexlog was changed so that it can use
the replication slot.

Original patch by Michael Paquier, rewritten by me.
Bug report by Furuya Osamu.

9 years agoDon't require bleeding-edge timezone data in timestamptz regression test.
Tom Lane [Wed, 19 Nov 2014 02:36:43 +0000 (21:36 -0500)]
Don't require bleeding-edge timezone data in timestamptz regression test.

The regression test cases added in commits b2cbced9e et al depended in part
on the Russian timezone offset changes of Oct 2014.  While this is of no
particular concern for a default Postgres build, it was possible for a
build using --with-system-tzdata to fail the tests if the system tzdata
database wasn't au courant.  Bjorn Munch and Christoph Berg both complained
about this while packaging 9.4rc1, so we probably shouldn't insist on the
system tzdata being up-to-date.  Instead, make an equivalent test using a
zone change that occurred in Venezuela in 2007.  With this patch, the
regression tests should pass using any tzdata set from 2012 or later.
(I can't muster much sympathy for somebody using --with-system-tzdata
on a machine whose system tzdata is more than three years out-of-date.)

9 years agoFix some bogus direct uses of realloc().
Tom Lane [Tue, 18 Nov 2014 18:28:09 +0000 (13:28 -0500)]
Fix some bogus direct uses of realloc().

pg_dump/parallel.c was using realloc() directly with no error check.
While the odds of an actual failure here seem pretty low, Coverity
complains about it, so fix by using pg_realloc() instead.

While looking for other instances, I noticed a couple of places in
psql that hadn't gotten the memo about the availability of pg_realloc.
These aren't bugs, since they did have error checks, but verbosely
inconsistent code is not a good thing.

Back-patch as far as 9.3.  9.2 did not have pg_dump/parallel.c, nor
did it have pg_realloc available in all frontend code.

9 years agoStamp 9.4rc1. REL9_4_RC1
Tom Lane [Mon, 17 Nov 2014 20:54:40 +0000 (15:54 -0500)]
Stamp 9.4rc1.

9 years agoUpdate 9.4 release notes for commits through today.
Tom Lane [Mon, 17 Nov 2014 19:47:13 +0000 (14:47 -0500)]
Update 9.4 release notes for commits through today.

9 years agoUpdate time zone data files to tzdata release 2014j.
Tom Lane [Mon, 17 Nov 2014 17:08:02 +0000 (12:08 -0500)]
Update time zone data files to tzdata release 2014j.

DST law changes in the Turks & Caicos Islands (America/Grand_Turk) and
in Fiji.  New zone Pacific/Bougainville for portions of Papua New Guinea.
Historical changes for Korea and Vietnam.

9 years agoFix WAL-logging of B-tree "unlink halfdead page" operation.
Heikki Linnakangas [Mon, 17 Nov 2014 16:42:04 +0000 (18:42 +0200)]
Fix WAL-logging of B-tree "unlink halfdead page" operation.

There was some confusion on how to record the case that the operation
unlinks the last non-leaf page in the branch being deleted.
_bt_unlink_halfdead_page set the "topdead" field in the WAL record to
the leaf page, but the redo routine assumed that it would be an invalid
block number in that case. This commit fixes _bt_unlink_halfdead_page to
do what the redo routine expected.

This code is new in 9.4, so backpatch there.

9 years agoTranslation updates
Peter Eisentraut [Mon, 17 Nov 2014 02:31:08 +0000 (21:31 -0500)]
Translation updates

9 years agoMention the TZ environment variable for initdb
Magnus Hagander [Sun, 16 Nov 2014 14:48:30 +0000 (15:48 +0100)]
Mention the TZ environment variable for initdb

Daniel Gustafsson

9 years agoFix duplicated platforms due to copy/paste error
Magnus Hagander [Sun, 16 Nov 2014 14:47:10 +0000 (15:47 +0100)]
Fix duplicated platforms due to copy/paste error

Patch from Michael Paquier, mistake spotted by KOIZUMI Satoru

9 years agoFix initdb --sync-only to also sync tablespaces.
Andres Freund [Fri, 14 Nov 2014 17:22:12 +0000 (18:22 +0100)]
Fix initdb --sync-only to also sync tablespaces.

630cd14426dc added initdb --sync-only, for use by pg_upgrade, by just
exposing the existing fsync code. That's wrong, because initdb so far
had absolutely no reason to deal with tablespaces.

Fix --sync-only by additionally explicitly syncing each of the
tablespaces.

Backpatch to 9.3 where --sync-only was introduced.

Abhijit Menon-Sen and Andres Freund

9 years agoSync unlogged relations to disk after they have been reset.
Andres Freund [Fri, 14 Nov 2014 17:21:30 +0000 (18:21 +0100)]
Sync unlogged relations to disk after they have been reset.

Unlogged relations are only reset when performing a unclean
restart. That means they have to be synced to disk during clean
shutdowns. During normal processing that's achieved by registering a
buffer's file to be fsynced at the next checkpoint when flushed. But
ResetUnloggedRelations() doesn't go through the buffer manager, so
nothing will force reset relations to disk before the next shutdown
checkpoint.

So just make ResetUnloggedRelations() fsync the newly created main
forks to disk.

Discussion: 20140912112246.GA4984@alap3.anarazel.de

Backpatch to 9.1 where unlogged tables were introduced.

Abhijit Menon-Sen and Andres Freund

9 years agoEnsure unlogged tables are reset even if crash recovery errors out.
Andres Freund [Fri, 14 Nov 2014 17:20:59 +0000 (18:20 +0100)]
Ensure unlogged tables are reset even if crash recovery errors out.

Unlogged relations are reset at the end of crash recovery as they're
only synced to disk during a proper shutdown. Unfortunately that and
later steps can fail, e.g. due to running out of space. This reset
was, up to now performed after marking the database as having finished
crash recovery successfully. As out of space errors trigger a crash
restart that could lead to the situation that not all unlogged
relations are reset.

Once that happend usage of unlogged relations could yield errors like
"could not open file "...": No such file or directory". Luckily
clusters that show the problem can be fixed by performing a immediate
shutdown, and starting the database again.

To fix, just call ResetUnloggedRelations(UNLOGGED_RELATION_INIT)
earlier, before marking the database as having successfully recovered.

Discussion: 20140912112246.GA4984@alap3.anarazel.de

Backpatch to 9.1 where unlogged tables were introduced.

Abhijit Menon-Sen and Andres Freund

9 years agoDocument evaluation-order considerations for aggregate functions.
Tom Lane [Fri, 14 Nov 2014 22:19:29 +0000 (17:19 -0500)]
Document evaluation-order considerations for aggregate functions.

The SELECT reference page didn't really address the question of when
aggregate function evaluation occurs, nor did the "expression evaluation
rules" documentation mention that CASE can't be used to control whether
an aggregate gets evaluated or not.  Improve that.

Per discussion of bug #11661.  Original text by Marti Raudsepp and Michael
Paquier, rewritten significantly by me.

9 years agoRevert change to ALTER TABLESPACE summary.
Stephen Frost [Fri, 14 Nov 2014 20:16:01 +0000 (15:16 -0500)]
Revert change to ALTER TABLESPACE summary.

When ALTER TABLESPACE MOVE ALL was changed to be ALTER TABLE ALL IN
TABLESPACE, the ALTER TABLESPACE summary should have been adjusted back
to its original definition.

Patch by Thom Brown (thanks!).

9 years agoAllow interrupting GetMultiXactIdMembers
Alvaro Herrera [Fri, 14 Nov 2014 18:14:02 +0000 (15:14 -0300)]
Allow interrupting GetMultiXactIdMembers

This function has a loop which can lead to uninterruptible process
"stalls" (actually infinite loops) when some bugs are triggered.  Avoid
that unpleasant situation by adding a check for interrupts in a place
that shouldn't degrade performance in the normal case.

Backpatch to 9.3.  Older branches have an identical loop here, but the
aforementioned bugs are only a problem starting in 9.3 so there doesn't
seem to be any point in backpatching any further.

9 years agoImprove logical decoding log messages
Peter Eisentraut [Fri, 14 Nov 2014 01:43:55 +0000 (20:43 -0500)]
Improve logical decoding log messages

suggestions from Robert Haas

9 years agoFix pg_dumpall to restore its ability to dump from ancient servers.
Tom Lane [Thu, 13 Nov 2014 23:19:28 +0000 (18:19 -0500)]
Fix pg_dumpall to restore its ability to dump from ancient servers.

Fix breakage induced by commits d8d3d2a4f37f6df5d0118b7f5211978cca22091a
and 463f2625a5fb183b6a8925ccde98bb3889f921d9: pg_dumpall has crashed when
attempting to dump from pre-8.1 servers since then, due to faulty
construction of the query used for dumping roles from older servers.
The query was erroneous as of the earlier commit, but it wasn't exposed
unless you tried to use --binary-upgrade, which you presumably wouldn't
with a pre-8.1 server.  However commit 463f2625a made it fail always.

In HEAD, also fix additional breakage induced in the same query by
commit 491c029dbc4206779cf659aa0ff986af7831d2ff, which evidently wasn't
tested against pre-8.1 servers either.

The bug is only latent in 9.1 because 463f2625a hadn't landed yet, but
it seems best to back-patch all branches containing the faulty query.

Gilles Darold

9 years agoFix and improve cache invalidation logic for logical decoding.
Andres Freund [Thu, 13 Nov 2014 18:06:43 +0000 (19:06 +0100)]
Fix and improve cache invalidation logic for logical decoding.

There are basically three situations in which logical decoding needs
to perform cache invalidation. During/After replaying a transaction
with catalog changes, when skipping a uninteresting transaction that
performed catalog changes and when erroring out while replaying a
transaction. Unfortunately these three cases were all done slightly
differently - partially because 8de3e410fa, which greatly simplifies
matters, got committed in the midst of the development of logical
decoding.

The actually problematic case was when logical decoding skipped
transaction commits (and thus processed invalidations). When used via
the SQL interface cache invalidation could access the catalog - bad,
because we didn't set up enough state to allow that correctly. It'd
not be hard to setup sufficient state, but the simpler solution is to
always perform cache invalidation outside a valid transaction.

Also make the different cache invalidation cases look as similar as
possible, to ease code review.

This fixes the assertion failure reported by Antonin Houska in
53EE02D9.7040702@gmail.com. The presented testcase has been expanded
into a regression test.

Backpatch to 9.4, where logical decoding was introduced.

9 years agoFix xmin/xmax horizon computation during logical decoding initialization.
Andres Freund [Thu, 13 Nov 2014 18:06:43 +0000 (19:06 +0100)]
Fix xmin/xmax horizon computation during logical decoding initialization.

When building the initial historic catalog snapshot there were
scenarios where snapbuild.c would use incorrect xmin/xmax values when
starting from a xl_running_xacts record. The values used were always a
bit suspect, but happened to be correct in the easy to test
cases. Notably the values used when the the initial snapshot was
computed while no other transactions were running were correct.

This is likely to be the cause of the occasional buildfarm failures on
animals markhor and tick; but it's quite possible to reproduce
problems without CLOBBER_CACHE_ALWAYS.

Backpatch to 9.4, where logical decoding was introduced.

9 years agoFix race condition between hot standby and restoring a full-page image.
Heikki Linnakangas [Thu, 13 Nov 2014 17:47:44 +0000 (19:47 +0200)]
Fix race condition between hot standby and restoring a full-page image.

There was a window in RestoreBackupBlock where a page would be zeroed out,
but not yet locked. If a backend pinned and locked the page in that window,
it saw the zeroed page instead of the old page or new page contents, which
could lead to missing rows in a result set, or errors.

To fix, replace RBM_ZERO with RBM_ZERO_AND_LOCK, which atomically pins,
zeroes, and locks the page, if it's not in the buffer cache already.

In stable branches, the old RBM_ZERO constant is renamed to RBM_DO_NOT_USE,
to avoid breaking any 3rd party extensions that might use RBM_ZERO. More
importantly, this avoids renumbering the other enum values, which would
cause even bigger confusion in extensions that use ReadBufferExtended, but
haven't been recompiled.

Backpatch to all supported versions; this has been racy since hot standby
was introduced.

9 years agoTweak row-level locking documentation
Alvaro Herrera [Thu, 13 Nov 2014 17:45:58 +0000 (14:45 -0300)]
Tweak row-level locking documentation

Move the meat of locking levels to mvcc.sgml, leaving only a link to it
in the SELECT reference page.

Michael Paquier, with some tweaks by Álvaro

9 years agodoc: Add index entry for "hypothetical-set aggregate"
Peter Eisentraut [Thu, 13 Nov 2014 16:57:16 +0000 (11:57 -0500)]
doc: Add index entry for "hypothetical-set aggregate"

9 years agoExplicitly support the case that a plancache's raw_parse_tree is NULL.
Tom Lane [Wed, 12 Nov 2014 20:58:40 +0000 (15:58 -0500)]
Explicitly support the case that a plancache's raw_parse_tree is NULL.

This only happens if a client issues a Parse message with an empty query
string, which is a bit odd; but since it is explicitly called out as legal
by our FE/BE protocol spec, we'd probably better continue to allow it.

Fix by adding tests everywhere that the raw_parse_tree field is passed to
functions that don't or shouldn't accept NULL.  Also make it clear in the
relevant comments that NULL is an expected case.

This reverts commits a73c9dbab0165b3395dfe8a44a7dfd16166963c4 and
2e9650cbcff8c8fb0d9ef807c73a44f241822eee, which fixed specific crash
symptoms by hacking things at what now seems to be the wrong end, ie the
callee functions.  Making the callees allow NULL is superficially more
robust, but it's not always true that there is a defensible thing for the
callee to do in such cases.  The caller has more context and is better
able to decide what the empty-query case ought to do.

Per followup discussion of bug #11335.  Back-patch to 9.2.  The code
before that is sufficiently different that it would require development
of a separate patch, which doesn't seem worthwhile for what is believed
to be an essentially cosmetic change.

9 years agoFix several weaknesses in slot and logical replication on-disk serialization.
Andres Freund [Wed, 12 Nov 2014 17:52:49 +0000 (18:52 +0100)]
Fix several weaknesses in slot and logical replication on-disk serialization.

Heikki noticed in 544E23C0.8090605@vmware.com that slot.c and
snapbuild.c were missing the FIN_CRC32 call when computing/checking
checksums of on disk files. That doesn't lower the the error detection
capabilities of the checksum, but is inconsistent with other usages.

In a followup mail Heikki also noticed that, contrary to a comment,
the 'version' and 'length' struct fields of replication slot's on disk
data where not covered by the checksum. That's not likely to lead to
actually missed corruption as those fields are cross checked with the
expected version and the actual file length. But it's wrong
nonetheless.

As fixing these issues makes existing on disk files unreadable, bump
the expected versions of on disk files for both slots and logical
decoding historic catalog snapshots.  This means that loading old
files will fail with
ERROR: "replication slot file ... has unsupported version 1"
and
ERROR: "snapbuild state file ... has unsupported version 1 instead of
2" respectively. Given the low likelihood of anybody already using
these new features in a production setup that seems acceptable.

Fixing these issues made me notice that there's no regression test
covering the loading of historic snapshot from disk - so add one.

Backpatch to 9.4 where these features were introduced.

9 years agoAdd interrupt checks to contrib/pg_prewarm.
Andres Freund [Wed, 12 Nov 2014 17:52:49 +0000 (18:52 +0100)]
Add interrupt checks to contrib/pg_prewarm.

Currently the extension's pg_prewarm() function didn't check
interrupts once it started "warming" data. Since individual calls can
take a long while it's important for them to be interruptible.

Backpatch to 9.4 where pg_prewarm was introduced.

9 years agoUse just one database connection in the "tablespace" test.
Noah Misch [Wed, 12 Nov 2014 12:33:17 +0000 (07:33 -0500)]
Use just one database connection in the "tablespace" test.

On Windows, DROP TABLESPACE has a race condition when run concurrently
with other processes having opened files in the tablespace.  This led to
a rare failure on buildfarm member frogmouth.  Back-patch to 9.4, where
the reconnection was introduced.

9 years agoMessage improvements
Peter Eisentraut [Wed, 12 Nov 2014 01:00:58 +0000 (20:00 -0500)]
Message improvements