OSDN Git Service

pg-rex/syncrep.git
13 years agoOn further reflection, we'd better do the same in int.c.
Tom Lane [Sat, 12 Mar 2011 00:04:05 +0000 (19:04 -0500)]
On further reflection, we'd better do the same in int.c.

We previously heard of the same problem in int24div(), so there's not a
good reason to suppose the problem is confined to cases involving int8.

13 years agoPut in some more safeguards against executing a division-by-zero.
Tom Lane [Fri, 11 Mar 2011 23:18:59 +0000 (18:18 -0500)]
Put in some more safeguards against executing a division-by-zero.

Add dummy returns before every potential division-by-zero in int8.c,
because apparently further "improvements" in gcc's optimizer have
enabled it to break functions that weren't broken before.

Aurelien Jarno, via Martin Pitt

13 years agoIn ecpg preprocessor, don't try to look up constants in the test for
Heikki Linnakangas [Fri, 11 Mar 2011 13:44:40 +0000 (15:44 +0200)]
In ecpg preprocessor, don't try to look up constants in the test for
variable hiding. A constant is not a variable. It worked in most cases by
accident, because we add constants to the global list of variables (why?),
but float constants like 1.23 were interpreted as struct field references,
and not found.

Backpatch to 9.0, where the test for variable hiding was added.

13 years agoDon't throw a warning if vacuum sees PD_ALL_VISIBLE flag set on a page that
Heikki Linnakangas [Tue, 8 Mar 2011 18:13:52 +0000 (20:13 +0200)]
Don't throw a warning if vacuum sees PD_ALL_VISIBLE flag set on a page that
contains newly-inserted tuples that according to our OldestXmin are not
yet visible to everyone. The value returned by GetOldestXmin() is conservative,
and it can move backwards on repeated calls, so if we see that contradiction
between the PD_ALL_VISIBLE flag and status of tuples on the page, we have to
assume it's because an earlier vacuum calculated a higher OldestXmin value,
and all the tuples really are visible to everyone.

We have received several reports of this bug, with the "PD_ALL_VISIBLE flag
was incorrectly set in relation ..." warning appearing in logs. We were
finally able to hunt it down with David Gould's help to run extra diagnostics
in an environment where this happened frequently.

Also reword the warning, per Robert Haas' suggestion, to not imply that the
PD_ALL_VISIBLE flag is necessarily at fault, as it might also be a symptom
of corruption on a tuple header.

Backpatch to 8.4, where the PD_ALL_VISIBLE flag was introduced.

13 years agoIn initialize_SSL, don't fail unnecessarily when home dir is unavailable.
Tom Lane [Fri, 4 Mar 2011 16:38:45 +0000 (11:38 -0500)]
In initialize_SSL, don't fail unnecessarily when home dir is unavailable.

Instead, just act as though the certificate file(s) are not present.
There is only one case where this need be a hard failure condition: when
sslmode is verify-ca or verify-full, not having a root cert file is an
error.  Change the logic so that we complain only in that case, and
otherwise fall through cleanly.  This is how it used to behave pre-9.0,
but my patch 4ed4b6c54e5fab24ab2624d80e26f7546edc88ad of 2010-05-26 broke
the case.  Per report from Christian Kastner.

13 years agoCorrect mistaken claims about EXPLAIN ANALYZE's handling of triggers.
Tom Lane [Wed, 2 Mar 2011 16:17:07 +0000 (11:17 -0500)]
Correct mistaken claims about EXPLAIN ANALYZE's handling of triggers.

Time spent executing AFTER triggers is not included in the runtime of the
associated ModifyTable node; in my patch of yesterday I confused queuing of
these triggers with their actual execution.  Spotted by Marko Tiikkaja.

13 years agoUpdate discussion of EXPLAIN to reflect existence of ModifyTable nodes.
Tom Lane [Tue, 1 Mar 2011 16:36:09 +0000 (11:36 -0500)]
Update discussion of EXPLAIN to reflect existence of ModifyTable nodes.

Back-patch to 9.0, since this was changed then.

13 years agoFix dangling-pointer problem in before-row update trigger processing.
Tom Lane [Tue, 22 Feb 2011 02:18:13 +0000 (21:18 -0500)]
Fix dangling-pointer problem in before-row update trigger processing.

ExecUpdate checked for whether ExecBRUpdateTriggers had returned a new
tuple value by seeing if the returned tuple was pointer-equal to the old
one.  But the "old one" was in estate->es_junkFilter's result slot, which
would be scribbled on if we had done an EvalPlanQual update in response to
a concurrent update of the target tuple; therefore we were comparing a
dangling pointer to a live one.  Given the right set of circumstances we
could get a false match, resulting in not forcing the tuple to be stored in
the slot we thought it was stored in.  In the case reported by Maxim Boguk
in bug #5798, this led to "cannot extract system attribute from virtual
tuple" failures when trying to do "RETURNING ctid".  I believe there is a
very-low-probability chance of more serious errors, such as generating
incorrect index entries based on the original rather than the
trigger-modified version of the row.

In HEAD, change all of ExecBRInsertTriggers, ExecIRInsertTriggers,
ExecBRUpdateTriggers, and ExecIRUpdateTriggers so that they continue to
have similar APIs.  In the back branches I just changed
ExecBRUpdateTriggers, since there is no bug in the ExecBRInsertTriggers
case.

13 years agoFix parallel pg_restore to handle comments on POST_DATA items correctly.
Tom Lane [Fri, 18 Feb 2011 18:11:50 +0000 (13:11 -0500)]
Fix parallel pg_restore to handle comments on POST_DATA items correctly.

The previous coding would try to process all SECTION_NONE items in the
initial sequential-restore pass, which failed if they were dependencies of
not-yet-restored items.  Fix by postponing such items into the parallel
processing pass once we have skipped any non-PRE_DATA item.

Back-patch into 9.0; the original parallel-restore coding in 8.4 did not
have this bug, so no need to change it.

Report and diagnosis by Arnd Hannemann.

13 years agoFix tsmatchsel() to account properly for null rows.
Tom Lane [Fri, 18 Feb 2011 00:00:54 +0000 (19:00 -0500)]
Fix tsmatchsel() to account properly for null rows.

ts_typanalyze.c computes MCE statistics as fractions of the non-null rows,
which seems fairly reasonable, and anyway changing it in released versions
wouldn't be a good idea.  But then ts_selfuncs.c has to account for that.
Failure to do so results in overestimates in columns with a significant
fraction of null documents.  Back-patch to 8.4 where this stuff was
introduced.

Jesper Krogh

13 years agoFix bogus test for hypothetical indexes in get_actual_variable_range().
Tom Lane [Thu, 17 Feb 2011 00:24:50 +0000 (19:24 -0500)]
Fix bogus test for hypothetical indexes in get_actual_variable_range().

That function was supposing that indexoid == 0 for a hypothetical index,
but that is not likely to be true in any non-toy implementation of an index
adviser, since assigning a fake OID is the only way to know at EXPLAIN time
which hypothetical index got selected.  Fix by adding a flag to
IndexOptInfo to mark hypothetical indexes.  Back-patch to 9.0 where
get_actual_variable_range() was added.

Gurjeet Singh

13 years agoAdd CheckTableNotInUse calls in DROP TABLE and DROP INDEX.
Tom Lane [Tue, 15 Feb 2011 20:49:59 +0000 (15:49 -0500)]
Add CheckTableNotInUse calls in DROP TABLE and DROP INDEX.

Recent releases had a check on rel->rd_refcnt in heap_drop_with_catalog,
but failed to cover the possibility of pending trigger events at DROP time.
(Before 8.4 we didn't even check the refcnt.)  When the trigger events were
eventually fired, you'd get "could not open relation with OID nnn" errors,
as in recent report from strk.  Better to throw a suitable error when the
DROP is attempted.

Also add a similar check in DROP INDEX.

Back-patch to all supported branches.

13 years agoClarify documentation for libpq's PQescapeBytea to mention the new hex
Bruce Momjian [Sun, 13 Feb 2011 14:29:01 +0000 (09:29 -0500)]
Clarify documentation for libpq's PQescapeBytea to mention the new hex
format.

Modify PQescapeStringConn() docs to be consisent with other escaping
functions.

Add mention problems with pre-9.0 versions of libpq using not understanding
bytea hex format to the 9.0 release notes.

Backpatch to 9.0 docs.

13 years agoFix improper matching of resjunk column names for FOR UPDATE in subselect.
Tom Lane [Thu, 10 Feb 2011 04:27:16 +0000 (23:27 -0500)]
Fix improper matching of resjunk column names for FOR UPDATE in subselect.

Flattening of subquery range tables during setrefs.c could lead to the
rangetable indexes in PlanRowMark nodes not matching up with the column
names previously assigned to the corresponding resjunk ctid (resp. tableoid
or wholerow) columns.  Typical symptom would be either a "cannot extract
system attribute from virtual tuple" error or an Assert failure.  This
wasn't a problem before 9.0 because we didn't support FOR UPDATE below the
top query level, and so the final flattening could never renumber an RTE
that was relevant to FOR UPDATE.  Fix by using a plan-tree-wide unique
number for each PlanRowMark to label the associated resjunk columns, so
that the number need not change during flattening.

Per report from David Johnston (though I'm darned if I can see how this got
past initial testing of the relevant code).  Back-patch to 9.0.

13 years agoFix typo.
Magnus Hagander [Thu, 3 Feb 2011 10:24:47 +0000 (11:24 +0100)]
Fix typo.

Thom Brown

13 years agoUndefine setlocale() macro on Win32
Magnus Hagander [Tue, 1 Feb 2011 12:19:18 +0000 (13:19 +0100)]
Undefine setlocale() macro on Win32

New versions of libintl redefine setlocale() to a macro
which causes problems when the backend and libintl are
linked against different versions of the runtime, which
is often the case in msvc builds.

Hiroshi Inoue, slightly updated comment by me

13 years agoCreate new errcode for recovery conflict caused by db drop on master.
Simon Riggs [Tue, 1 Feb 2011 08:49:58 +0000 (08:49 +0000)]
Create new errcode for recovery conflict caused by db drop on 
Previously reported as ERRCODE_ADMIN_SHUTDOWN, this case is now
reported as ERRCODE_DATABASE_DROPPED. No message text change.
Unlikely to happen on most servers, so low impact change to allow
session poolers to correctly handle this situation.

Tatsuo Ishii and Simon Riggs

13 years agoFix wrong error reports in 'number of array dimensions exceeds the
Itagaki Takahiro [Tue, 1 Feb 2011 06:21:32 +0000 (15:21 +0900)]
Fix wrong error reports in 'number of array dimensions exceeds the
maximum allowed' messages, that have reported one-less dimensions.

Alexey Klyukin

13 years agoFix error code for canceling statement due to conflict with recovery.
Simon Riggs [Mon, 31 Jan 2011 19:24:29 +0000 (19:24 +0000)]
Fix error code for canceling statement due to conflict with recovery.
All retryable conflict errors now have an error code that indicates that
a retry is possible, correcting my incomplete fix of 2010/05/12

Tatsuo Ishii and Simon Riggs, input from Robert Haas and Florian Pflug

13 years agoMake reduce_outer_joins() smarter about semijoins.
Tom Lane [Sun, 30 Jan 2011 22:04:31 +0000 (17:04 -0500)]
Make reduce_outer_joins() smarter about semijoins.

reduce_outer_joins() mistakenly treated a semijoin like a left join for
purposes of deciding whether not-null constraints created by the join's
quals could be passed down into the join's left-hand side (possibly
resulting in outer-join simplification there).  Actually, semijoin works
like inner join for this purpose, ie, we do not need to see any rows that
can't possibly satisfy the quals.  Hence, two-line fix to treat semi and
inner joins alike.  Per observation by Andres Freund about a performance
gripe from Yazan Suleiman.

Back-patch to 8.4, since this oversight has been there since the current
handling of semijoins was implemented.

13 years agoTag 9.0.3 REL9_0_3
Marc G. Fournier [Fri, 28 Jan 2011 02:21:31 +0000 (22:21 -0400)]
Tag 9.0.3

13 years agoUpdate release notes.
Tom Lane [Thu, 27 Jan 2011 22:45:42 +0000 (17:45 -0500)]
Update release notes.

Security: CVE-2010-4015

13 years agoPrevent buffer overrun while parsing an integer in a "query_int" value.
Tom Lane [Thu, 27 Jan 2011 22:41:46 +0000 (17:41 -0500)]
Prevent buffer overrun while parsing an integer in a "query_int" value.

contrib/intarray's gettoken() uses a fixed-size buffer to collect an
integer's digits, and did not guard against overrunning the buffer.
This is at least a backend crash risk, and in principle might allow
arbitrary code execution.  The code didn't check for overflow of the
integer value either, which while not presenting a crash risk was still
bad.

Thanks to Apple Inc's security team for reporting this issue and supplying
the fix.

Security: CVE-2010-4015

13 years agoDon't include <asm/ia64regs.h> unnecessarily.
Tom Lane [Thu, 27 Jan 2011 21:27:27 +0000 (16:27 -0500)]
Don't include <asm/ia64regs.h> unnecessarily.

We only need that header when compiling with icc, since the gcc variant of
ia64_get_bsp() uses in-line assembly code.  Per report from Frank Brendel,
the header doesn't exist on all IA64 platforms; so don't include it unless
we need it.

13 years agoTranslation updates for release 9.0.3
Peter Eisentraut [Thu, 27 Jan 2011 19:25:25 +0000 (21:25 +0200)]
Translation updates for release 9.0.3

13 years agoUpdate release notes for releases 9.0.3, 8.4.7, 8.3.14, and 8.2.20.
Tom Lane [Thu, 27 Jan 2011 21:09:51 +0000 (16:09 -0500)]
Update release notes for releases 9.0.3, 8.4.7, 8.3.14, and 8.2.20.

13 years agoCorrect ALTER TYPE -> SET DATA TYPE in ALTER TABLE documentation.
Robert Haas [Tue, 25 Jan 2011 23:50:35 +0000 (18:50 -0500)]
Correct ALTER TYPE -> SET DATA TYPE in ALTER TABLE documentation.

The latter is the correct name of the operation to change the data type
of a column.

Noah Misch

13 years agoMake ALTER TABLE revalidate uniqueness and exclusion constraints.
Robert Haas [Fri, 21 Jan 2011 03:44:10 +0000 (22:44 -0500)]
Make ALTER TABLE revalidate uniqueness and exclusion constraints.

Failure to do so can lead to constraint violations.  This was broken by
commit 1ddc2703a936d03953657f43345460b9242bbed1 on 2010-02-07, so
back-patch to 9.0.

Noah Misch.  Regression test by me.

13 years agoDocument that WITH queries are also called Common Table Expressions.
Robert Haas [Thu, 20 Jan 2011 02:21:33 +0000 (21:21 -0500)]
Document that WITH queries are also called Common Table Expressions.

Peter Geoghegan, reviewed by Stephen Frost

13 years agoFix miscalculation of itemsafter in array_set_slice().
Tom Lane [Mon, 17 Jan 2011 17:38:52 +0000 (12:38 -0500)]
Fix miscalculation of itemsafter in array_set_slice().

If the slice to be assigned to was before the existing array lower bound
(requiring at least one null element to spring into existence to fill the
gap), the code miscalculated how many entries needed to be copied from
the old array's null bitmap.  This could result in trashing the array's
data area (as seen in bug #5840 from Karsten Loesing), or worse.

This has been broken since we first allowed the behavior of assigning to
non-adjacent slices, in 8.2.  Back-patch to all affected versions.

13 years agoIncrement Py_None refcount for NULL array elements
Alvaro Herrera [Mon, 17 Jan 2011 16:01:04 +0000 (13:01 -0300)]
Increment Py_None refcount for NULL array elements

Per bug #5835 by Julien Demoor
Author: Alex Hunsaker

13 years agoBefore exiting walreceiver, fsync() all the WAL received.
Heikki Linnakangas [Mon, 17 Jan 2011 10:22:24 +0000 (12:22 +0200)]
Before exiting walreceiver, fsync() all the WAL received.

Otherwise WAL recovery will replay the un-flushed WAL after walreceiver has
exited, which can lead to a non-recoverable standby if the system crashes hard
at that point.

13 years agoFix the logic in libpqrcv_receive() to determine if there's any incoming data
Heikki Linnakangas [Thu, 13 Jan 2011 15:51:28 +0000 (17:51 +0200)]
Fix the logic in libpqrcv_receive() to determine if there's any incoming data
that can be read without blocking. It used to conclude that there isn't, even
though there was data in the socket receive buffer. That lead walreceiver to
flush the WAL after every received chunk, potentially causing big performance
issues.

Backpatch to 9.0, because the performance impact can be very significant.

13 years agoFix PlanRowMark/ExecRowMark structures to handle inheritance correctly.
Tom Lane [Thu, 13 Jan 2011 01:47:09 +0000 (20:47 -0500)]
Fix PlanRowMark/ExecRowMark structures to handle inheritance correctly.

In an inherited UPDATE/DELETE, each target table has its own subplan,
because it might have a column set different from other targets.  This
means that the resjunk columns we add to support EvalPlanQual might be
at different physical column numbers in each subplan.  The EvalPlanQual
rewrite I did for 9.0 failed to account for this, resulting in possible
misbehavior or even crashes during concurrent updates to the same row,
as seen in a recent report from Gordon Shannon.  Revise the data structure
so that we track resjunk column numbers separately for each subplan.

I also chose to move responsibility for identifying the physical column
numbers back to executor startup, instead of assuming that numbers derived
during preprocess_targetlist would stay valid throughout subsequent
massaging of the plan.  That's a bit slower, so we might want to consider
undoing it someday; but it would complicate the patch considerably and
didn't seem justifiable in a bug fix that has to be back-patched to 9.0.

13 years agoTypo fix
Magnus Hagander [Tue, 11 Jan 2011 09:45:16 +0000 (10:45 +0100)]
Typo fix

Josh Kupershmidt

13 years agoEnsure the directory for gram.h is created on win32
Magnus Hagander [Sun, 9 Jan 2011 16:01:15 +0000 (17:01 +0100)]
Ensure the directory for gram.h is created on win32

Result of bad testing of my last commit.

13 years agoProperly install gram.h on MSVC builds
Magnus Hagander [Sun, 9 Jan 2011 14:31:48 +0000 (15:31 +0100)]
Properly install gram.h on MSVC builds

This file is now needed by pgAdmin builds, which started
failing since it was missing in the installer builds.

13 years agoIn ecpg's parser removed a fixed length limit for constants defining an array dimension.
Michael Meskes [Sat, 8 Jan 2011 17:35:37 +0000 (18:35 +0100)]
In ecpg's parser removed a fixed length limit for constants defining an array dimension.

13 years agoRemove bogus claims regarding createuser defaults.
Robert Haas [Sat, 8 Jan 2011 11:12:05 +0000 (06:12 -0500)]
Remove bogus claims regarding createuser defaults.

Josh Kupershmidt

13 years agoUpdate documentation to say that \lo_import sets :LASTOID, not
Bruce Momjian [Thu, 6 Jan 2011 02:32:13 +0000 (21:32 -0500)]
Update documentation to say that \lo_import sets :LASTOID, not
lo_insert.

13 years agoIn pg_upgrade, copy pg_largeobject_metadata and its index for 9.0+
Bruce Momjian [Wed, 5 Jan 2011 04:35:52 +0000 (23:35 -0500)]
In pg_upgrade, copy pg_largeobject_metadata and its index for 9.0+
servers because, like pg_largeobject, it is a system table whose
contents are not dumped by pg_dump --schema-only.

13 years agoIn pg_upgrade, fix backward logging display of link operations.
Bruce Momjian [Wed, 5 Jan 2011 02:33:37 +0000 (21:33 -0500)]
In pg_upgrade, fix backward logging display of link operations.

13 years agoImprove pg_upgrade's checks for required executables.
Tom Lane [Wed, 29 Dec 2010 18:43:58 +0000 (13:43 -0500)]
Improve pg_upgrade's checks for required executables.

Don't insist on pg_dumpall and psql being present in the old cluster,
since they are not needed.  Do insist on pg_resetxlog being present
(in both old and new), since we need it.  Also check for pg_config,
but only in the new cluster.  Remove the useless attempt to call
pg_config in the old cluster; we don't need to know the old value of
--pkglibdir.  (In the case of a stripped-down migration installation
there might be nothing there to look at anyway, so any future change
that might reintroduce that need would have to be considered carefully.)

Per my attempts to build a minimal previous-version installation to support
pg_upgrade.

13 years agoAvoid unexpected conversion overflow in planner for distant date values.
Tom Lane [Wed, 29 Dec 2010 03:49:57 +0000 (22:49 -0500)]
Avoid unexpected conversion overflow in planner for distant date values.

The "date" type supports a wider range of dates than int64 timestamps do.
However, there is pre-int64-timestamp code in the planner that assumes that
all date values can be converted to timestamp with impunity.  Fortunately,
what we really need out of the conversion is always a double (float8)
value; so even when the date is out of timestamp's range it's possible to
produce a sane answer.  All we need is a code path that doesn't try to
force the result into int64.  Per trouble report from David Rericha.

Back-patch to all supported versions.  Although this is surely a corner
case, there's not much point in advertising a date range wider than
timestamp's if we will choke on such values in unexpected places.

13 years agoCorrect spelling: longjump() -> longjmp().
Robert Haas [Sat, 25 Dec 2010 03:21:50 +0000 (22:21 -0500)]
Correct spelling: longjump() -> longjmp().

13 years agoFix grammar
Peter Eisentraut [Fri, 24 Dec 2010 20:08:15 +0000 (22:08 +0200)]
Fix grammar

13 years agoAllow vpath builds and regression tests to succeed on Mingw. Backpatch to release...
Andrew Dunstan [Fri, 24 Dec 2010 18:31:48 +0000 (13:31 -0500)]
Allow vpath builds and regression tests to succeed on Mingw. Backpatch to release 8.4 - earlier releases would require more changes and it's not worth the trouble.

13 years agoBackpatch to 9.0 a doc mention that a BBU does not prevent partial page
Bruce Momjian [Fri, 24 Dec 2010 16:32:52 +0000 (11:32 -0500)]
Backpatch to 9.0 a doc mention that a BBU does not prevent partial page
writes.

13 years agoFix up handling of simple-form CASE with constant test expression.
Tom Lane [Sun, 19 Dec 2010 20:30:44 +0000 (15:30 -0500)]
Fix up handling of simple-form CASE with constant test expression.

eval_const_expressions() can replace CaseTestExprs with constants when
the surrounding CASE's test expression is a constant.  This confuses
ruleutils.c's heuristic for deparsing simple-form CASEs, leading to
Assert failures or "unexpected CASE WHEN clause" errors.  I had put in
a hack solution for that years ago (see commit
514ce7a331c5bea8e55b106d624e55732a002295 of 2006-10-01), but bug #5794
from Peter Speck shows that that solution failed to cover all cases.

Fortunately, there's a much better way, which came to me upon reflecting
that Peter's "CASE TRUE WHEN" seemed pretty redundant: we can "simplify"
the simple-form CASE to the general form of CASE, by simply omitting the
constant test expression from the rebuilt CASE construct.  This is
intuitively valid because there is no need for the executor to evaluate
the test expression at runtime; it will never be referenced, because any
CaseTestExprs that would have referenced it are now replaced by constants.
This won't save a whole lot of cycles, since evaluating a Const is pretty
cheap, but a cycle saved is a cycle earned.  In any case it beats kluging
ruleutils.c still further.  So this patch improves const-simplification
and reverts the previous change in ruleutils.c.

Back-patch to all supported branches.  The bug exists in 8.1 too, but it's
out of warranty.

13 years agoFix erroneous parsing of tsquery input "... & !(subexpression) | ..."
Tom Lane [Sun, 19 Dec 2010 17:48:41 +0000 (12:48 -0500)]
Fix erroneous parsing of tsquery input "... & !(subexpression) | ..."

After parsing a parenthesized subexpression, we must pop all pending
ANDs and NOTs off the stack, just like the case for a simple operand.
Per bug #5793.

Also fix clones of this routine in contrib/intarray and contrib/ltree,
where input of types query_int and ltxtquery had the same problem.

Back-patch to all supported versions.

13 years agoDocument unavailable parameters in some configurations
Magnus Hagander [Sat, 18 Dec 2010 15:30:00 +0000 (16:30 +0100)]
Document unavailable parameters in some configurations

Add a note to user-facing parameters that can be removed completely
(and not just empty) by #ifdef's depending on build configuration.

13 years agoRemove optreset from src/port/ implementations of getopt and getopt_long.
Tom Lane [Thu, 16 Dec 2010 21:22:12 +0000 (16:22 -0500)]
Remove optreset from src/port/ implementations of getopt and getopt_long.

We don't actually need optreset, because we can easily fix the code to
ensure that it's cleanly restartable after having completed a scan over the
argv array; which is the only case we need to restart in.  Getting rid of
it avoids a class of interactions with the system libraries and allows
reversion of my change of yesterday in postmaster.c and postgres.c.

Back-patch to 8.4.  Before that the getopt code was a bit different anyway.

13 years agoFix up getopt() reset management so it works on recent mingw.
Tom Lane [Thu, 16 Dec 2010 04:50:49 +0000 (23:50 -0500)]
Fix up getopt() reset management so it works on recent mingw.

The mingw people don't appear to care about compatibility with non-GNU
versions of getopt, so force use of our own copy of getopt on Windows.
Also, ensure that we make use of optreset when using our own copy.

Per report from Andrew Dunstan.  Back-patch to all versions supported
on Windows.

13 years agoFix contrib/seg's GiST picksplit method.
Tom Lane [Thu, 16 Dec 2010 02:22:38 +0000 (21:22 -0500)]
Fix contrib/seg's GiST picksplit method.

Fix the same size_alpha versus size_beta typo that was recently fixed
in contrib/cube.  Noted by Alexander Korotkov.

Back-patch to all supported branches (there is a more invasive fix in
HEAD).

13 years agoTag 9.0.2. REL9_0_2
Marc G. Fournier [Tue, 14 Dec 2010 02:55:50 +0000 (22:55 -0400)]
Tag 9.0.2.

13 years agoUpdate release notes for releases 9.0.2, 8.4.6, 8.3.13, 8.2.19, and 8.1.23.
Tom Lane [Tue, 14 Dec 2010 01:21:55 +0000 (20:21 -0500)]
Update release notes for releases 9.0.2, 8.4.6, 8.3.13, 8.2.19, and 8.1.23.

13 years agoTranslation updates for release 9.0.2
Peter Eisentraut [Mon, 13 Dec 2010 21:20:00 +0000 (23:20 +0200)]
Translation updates for release 9.0.2

13 years agoUpdate time zone data files to tzdata release 2010o: DST law changes in
Tom Lane [Mon, 13 Dec 2010 17:41:57 +0000 (12:41 -0500)]
Update time zone data files to tzdata release 2010o: DST law changes in
Fiji and Samoa.  Historical corrections for Hong Kong.

13 years agoFix efficiency problems in tuplestore_trim().
Tom Lane [Fri, 10 Dec 2010 16:33:38 +0000 (11:33 -0500)]
Fix efficiency problems in tuplestore_trim().

The original coding in tuplestore_trim() was only meant to work efficiently
in cases where each trim call deleted most of the tuples in the store.
Which, in fact, was the pattern of the original usage with a Material node
supporting mark/restore operations underneath a MergeJoin.  However,
WindowAgg now uses tuplestores and it has considerably less friendly
trimming behavior.  In particular it can attempt to trim one tuple at a
time off a large tuplestore.  tuplestore_trim() had O(N^2) runtime in this
situation because of repeatedly shifting its tuple pointer array.  Fix by
avoiding shifting the array until a reasonably large number of tuples have
been deleted.  This can waste some pointer space, but we do still reclaim
the tuples themselves, so the percentage wastage should be pretty small.

Per Jie Li's report of slow percent_rank() evaluation.  cume_dist() and
ntile() would certainly be affected as well, along with any other window
function that has a moving frame start and requires reading substantially
ahead of the current row.

Back-patch to 8.4, where window functions were introduced.  There's no
need to tweak it before that.

13 years agoReduce spurious Hot Standby conflicts from never-visible records.
Simon Riggs [Fri, 10 Dec 2010 06:59:33 +0000 (06:59 +0000)]
Reduce spurious Hot Standby conflicts from never-visible records.
Hot Standby conflicts only with tuples that were visible at
some point. So ignore tuples from aborted transactions or for
tuples updated/deleted during the inserting transaction when
generating the conflict transaction ids.

Following detailed analysis and test case by Noah Misch.
Original report covered btree delete records, correctly observed
by Heikki Linnakangas that this applies to other cases also.
Fix covers all sources of cleanup records via common code.
Includes additional fix compared to commit on HEAD

13 years agoEliminate O(N^2) behavior in parallel restore with many blobs.
Tom Lane [Thu, 9 Dec 2010 18:03:11 +0000 (13:03 -0500)]
Eliminate O(N^2) behavior in parallel restore with many blobs.

With hundreds of thousands of TOC entries, the repeated searches in
reduce_dependencies() become the dominant cost.  Get rid of that searching
by constructing reverse-dependency lists, which we can do in O(N) time
during the fix_dependencies() preprocessing.  I chose to store the reverse
dependencies as DumpId arrays for consistency with the forward-dependency
representation, and keep the previously-transient tocsByDumpId[] array
around to locate actual TOC entry structs quickly from dump IDs.

While this fixes the slow case reported by Vlad Arkhipov, there is still
a potential for O(N^2) behavior with sufficiently many tables:
fix_dependencies itself, as well as mark_create_done and
inhibit_data_for_failed_table, are doing repeated searches to deal with
table-to-table-data dependencies.  Possibly this work could be extended
to deal with that, although the latter two functions are also used in
non-parallel restore where we currently don't run fix_dependencies.

Another TODO is that we fail to parallelize restore of multiple blobs
at all.  This appears to require changes in the archive format to fix.

Back-patch to 9.0 where the problem was reported.  8.4 has potential issues
as well; but since it doesn't create a separate TOC entry for each blob,
it's at much less risk of having enough TOC entries to cause real problems.

13 years agoForce default wal_sync_method to be fdatasync on Linux.
Tom Lane [Thu, 9 Dec 2010 01:01:14 +0000 (20:01 -0500)]
Force default wal_sync_method to be fdatasync on Linux.

Recent versions of the Linux system header files cause xlogdefs.h to
believe that open_datasync should be the default sync method, whereas
formerly fdatasync was the default on Linux.  open_datasync is a bad
choice, first because it doesn't actually outperform fdatasync (in fact
the reverse), and second because we try to use O_DIRECT with it, causing
failures on certain filesystems (e.g., ext4 with data=journal option).
This part of the patch is largely per a proposal from Marti Raudsepp.
More extensive changes are likely to follow in HEAD, but this is as much
change as we want to back-patch.

Also clean up confusing code and incorrect documentation surrounding the
fsync_writethrough option.  Those changes shouldn't result in any actual
behavioral change, but I chose to back-patch them anyway to keep the
branches looking similar in this area.

In 9.0 and HEAD, also do some copy-editing on the WAL Reliability
documentation section.

Back-patch to all supported branches, since any of them might get used
on modern Linux versions.

13 years agoFix bugs in the hot standby known-assigned-xids tracking logic. If there's
Heikki Linnakangas [Tue, 7 Dec 2010 08:23:30 +0000 (09:23 +0100)]
Fix bugs in the hot standby known-assigned-xids tracking logic. If there's
an old transaction running in the master, and a lot of transactions have
started and finished since, and a WAL-record is written in the gap between
the creating the running-xacts snapshot and WAL-logging it, recovery will fail
with "too many KnownAssignedXids" error. This bug was reported by
Joachim Wieland on Nov 19th.

In the same scenario, when fewer transactions have started so that all the
xids fit in KnownAssignedXids despite the first bug, a more serious bug
arises. We incorrectly initialize the clog code with the oldest still running
transaction, and when we see the WAL record belonging to a transaction with
an XID larger than one that committed already before the checkpoint we're
recovering from, we zero the clog page containing the already committed
transaction, leading to data loss.

In hindsight, trying to track xids in the known-assigned-xids array before
seeing the running-xacts record was too complicated. To fix that, hold
XidGenLock while the running-xacts snapshot is taken and WAL-logged. That
ensures that no transaction can begin or end in that gap, so that in recvoery
we know that the snapshot contains all transactions running at that point in
WAL.

13 years agoAdd a stack overflow check to copyObject().
Tom Lane [Tue, 7 Dec 2010 03:55:51 +0000 (22:55 -0500)]
Add a stack overflow check to copyObject().

There are some code paths, such as SPI_execute(), where we invoke
copyObject() on raw parse trees before doing parse analysis on them.  Since
the bison grammar is capable of building heavily nested parsetrees while
itself using only minimal stack depth, this means that copyObject() can be
the front-line function that hits stack overflow before anything else does.
Accordingly, it had better have a check_stack_depth() call.  I did a bit of
performance testing and found that this slows down copyObject() by only a
few percent, so the hit ought to be negligible in the context of complete
processing of a query.

Per off-list report from Toshihide Katayama.  Back-patch to all supported
branches.

13 years agoFix two typos, by Fujii Masao.
Heikki Linnakangas [Mon, 6 Dec 2010 11:36:26 +0000 (12:36 +0100)]
Fix two typos, by Fujii Masao.

13 years agoPrevent inlining a SQL function with multiple OUT parameters.
Tom Lane [Wed, 1 Dec 2010 05:53:23 +0000 (00:53 -0500)]
Prevent inlining a SQL function with multiple OUT parameters.

There were corner cases in which the planner would attempt to inline such
a function, which would result in a failure at runtime due to loss of
information about exactly what the result record type is.  Fix by disabling
inlining when the function's recorded result type is RECORD.  There might
be some sub-cases where inlining could still be allowed, but this is a
simple and backpatchable fix, so leave refinements for another day.
Per bug #5777 from Nate Carson.

Back-patch to all supported branches.  8.1 happens to avoid a core-dump
here, but it still does the wrong thing.

13 years agoMove call to GetTopTransactionId() earlier in LockAcquire(),
Simon Riggs [Mon, 29 Nov 2010 01:10:56 +0000 (01:10 +0000)]
Move call to GetTopTransactionId() earlier in LockAcquire(),
removing an infrequently occurring race condition in Hot Standby.
An xid must be assigned before a lock appears in shared memory,
rather than immediately after, else GetRunningTransactionLocks()
may see InvalidTransactionId, causing assertion failures during
lock processing on standby.

Bug report and diagnosis by Fujii Masao, fix by me.

13 years agoFix significant memory leak in contrib/xml2 functions.
Tom Lane [Fri, 26 Nov 2010 20:20:55 +0000 (15:20 -0500)]
Fix significant memory leak in contrib/xml2 functions.

Most of the functions that execute XPath queries leaked the data structures
created by libxml2.  This memory would not be recovered until end of
session, so it mounts up pretty quickly in any serious use of the feature.
Per report from Pavel Stehule, though this isn't his patch.

Back-patch to all supported branches.

13 years agoDon't raise "identifier will be truncated" messages in dblink
Itagaki Takahiro [Thu, 25 Nov 2010 10:40:58 +0000 (19:40 +0900)]
Don't raise "identifier will be truncated" messages in dblink
except creating new connections.

13 years agoFix leakage of cost_limit when multiple autovacuum workers are active.
Tom Lane [Sat, 20 Nov 2010 03:28:25 +0000 (22:28 -0500)]
Fix leakage of cost_limit when multiple autovacuum workers are active.

When using default autovacuum_vac_cost_limit, autovac_balance_cost relied
on VacuumCostLimit to contain the correct global value ... but after the
first time through in a particular worker process, it didn't, because we'd
trashed it in previous iterations.  Depending on the state of other autovac
workers, this could result in a steady reduction of the effective
cost_limit setting as a particular worker processed more and more tables,
causing it to go slower and slower.  Spotted by Simon Poole (bug #5759).
Fix by saving and restoring the GUC variables in the loop in do_autovacuum.

In passing, improve a few comments.

Back-patch to 8.3 ... the cost rebalancing code has been buggy since it was
put in.

13 years agoImprove plpgsql's error reporting for no-such-column cases.
Tom Lane [Thu, 18 Nov 2010 22:06:57 +0000 (17:06 -0500)]
Improve plpgsql's error reporting for no-such-column cases.

Given a column reference foo.bar, where there is a composite plpgsql
variable foo but it doesn't contain a column bar, the pre-9.0 coding would
immediately throw a "record foo has no field bar" error.  In 9.0 the parser
hook instead falls through to let the core parser see if it can resolve the
reference.  If not, you get a complaint about "missing FROM-clause entry
for table foo", which while in some sense correct isn't terribly helpful.
Complicate things a bit so that we can throw the old error message if
neither the core parser nor the hook are able to resolve the column
reference, while not changing the behavior in any other case.
Per bug #5757 from Andrey Galkin.

13 years agoSend paramHandle to subprocesses as 64-bit on Win64
Magnus Hagander [Tue, 16 Nov 2010 11:40:56 +0000 (12:40 +0100)]
Send paramHandle to subprocesses as 64-bit on Win64

The handle to the shared memory segment containing startup
parameters was sent as 32-bit even on 64-bit systems. Since
HANDLEs appear to be allocated sequentially this shouldn't
be a problem until we reach 2^32 open handles in the postmaster,
but a 64-bit value should be sent across as 64-bit, and not
zero out the top 32 bits.

Noted by Tom Lane.

13 years agoThe GiST scan algorithm uses LSNs to detect concurrent pages splits, but
Heikki Linnakangas [Tue, 16 Nov 2010 09:02:11 +0000 (11:02 +0200)]
The GiST scan algorithm uses LSNs to detect concurrent pages splits, but
temporary indexes are not WAL-logged. We used a constant LSN for temporary
indexes, on the assumption that we don't need to worry about concurrent page
splits in temporary indexes because they're only visible to the current
session. But that assumption is wrong, it's possible to insert rows and
split pages in the same session, while a scan is in progress. For example,
by opening a cursor and fetching some rows, and INSERTing new rows before
fetching some more.

Fix by generating fake increasing LSNs, used in place of real LSNs in
temporary GiST indexes.

13 years agoFix aboriginal mistake in plpython's set-returning-function support.
Tom Lane [Mon, 15 Nov 2010 19:27:00 +0000 (14:27 -0500)]
Fix aboriginal mistake in plpython's set-returning-function support.

We must stay in the function's SPI context until done calling the iterator
that returns the set result.  Otherwise, any attempt to invoke SPI features
in the python code called by the iterator will malfunction.  Diagnosis and
patch by Jan Urbanski, per bug report from Jean-Baptiste Quenot.

Back-patch to 8.2; there was no support for SRFs in previous versions of
plpython.

13 years agoAvoid spurious Hot Standby conflicts from btree delete records.
Simon Riggs [Mon, 15 Nov 2010 09:31:23 +0000 (09:31 +0000)]
Avoid spurious Hot Standby conflicts from btree delete records.
Similar conflicts were already avoided for related record types.
Massive over-caution resulted in a usability bug. Clear theoretical
basis for doing this is now confirmed by me.
Request to remove from Heikki (twice), over-caution by me.

13 years agoFix bug in cube picksplit algorithm.
Robert Haas [Mon, 15 Nov 2010 02:27:34 +0000 (21:27 -0500)]
Fix bug in cube picksplit algorithm.

Alexander Korotkov

13 years agoFix canAcceptConnections() bugs introduced by replication-related patches.
Tom Lane [Sun, 14 Nov 2010 20:57:42 +0000 (15:57 -0500)]
Fix canAcceptConnections() bugs introduced by replication-related patches.

We must not return any "okay to proceed" result code without having checked
for too many children, else we might fail later on when trying to add the
new child to one of the per-child state arrays.  It's not clear whether
this oversight explains Stefan Kaltenbrunner's recent report, but it could
certainly produce a similar symptom.

Back-patch to 8.4; the logic was not broken before that.

13 years agoAdd missing outfuncs.c support for struct InhRelation.
Tom Lane [Sat, 13 Nov 2010 05:34:50 +0000 (00:34 -0500)]
Add missing outfuncs.c support for struct InhRelation.

This is needed to support debug_print_parse, per report from Jon Nelson.
Cursory testing via the regression tests suggests we aren't missing
anything else.

13 years agoFix old oversight in const-simplification of COALESCE() expressions.
Tom Lane [Fri, 12 Nov 2010 20:14:51 +0000 (15:14 -0500)]
Fix old oversight in const-simplification of COALESCE() expressions.

Once we have found a non-null constant argument, there is no need to
examine additional arguments of the COALESCE.  The previous coding got it
right only if the constant was in the first argument position; otherwise
it tried to simplify following arguments too, leading to unexpected
behavior like this:

regression=# select coalesce(f1, 42, 1/0) from int4_tbl;
ERROR:  division by zero

It's a minor corner case, but a bug is a bug, so back-patch all the way.

13 years agodocs -> documentation
Peter Eisentraut [Fri, 12 Nov 2010 19:25:57 +0000 (21:25 +0200)]
docs -> documentation

13 years agoAdd missing support for removing foreign data wrapper / server privileges
Heikki Linnakangas [Fri, 12 Nov 2010 13:19:14 +0000 (15:19 +0200)]
Add missing support for removing foreign data wrapper / server privileges
belonging to a user at DROP OWNED BY. Foreign data wrappers and servers
don't do anything useful yet, which is why no-one has noticed, but since we
have them, seems prudent to fix this. Per report from Chetan Suttraway.
Backpatch to 9.0, 8.4 has the same problem but this patch didn't apply
there so I'm not going to bother.

13 years agoFix bug introduced by the recent patch to check that the checkpoint redo
Heikki Linnakangas [Thu, 11 Nov 2010 17:21:49 +0000 (19:21 +0200)]
Fix bug introduced by the recent patch to check that the checkpoint redo
location read from backup label file can be found: wasShutdown was set
incorrectly when a backup label file was found.

Jeff Davis, with a little tweaking by me.

13 years agoFix line_construct_pm() for the case of "infinite" (DBL_MAX) slope.
Tom Lane [Wed, 10 Nov 2010 21:51:39 +0000 (16:51 -0500)]
Fix line_construct_pm() for the case of "infinite" (DBL_MAX) slope.

This code was just plain wrong: what you got was not a line through the
given point but a line almost indistinguishable from the Y-axis, although
not truly vertical.  The only caller that tries to use this function with
m == DBL_MAX is dist_ps_internal for the case where the lseg is horizontal;
it would end up producing the distance from the given point to the place
where the lseg's line crosses the Y-axis.  That function is used by other
operators too, so there are several operators that could compute wrong
distances from a line segment to something else.  Per bug #5745 from
jindiax.

Back-patch to all supported branches.

13 years agoMention that pg_upgrade requires compatible 32/64-bit binaries.
Bruce Momjian [Wed, 10 Nov 2010 14:33:37 +0000 (14:33 +0000)]
Mention that pg_upgrade requires compatible 32/64-bit binaries.

13 years agoDon't use __declspec (dllimport) for PGDLLEXPORT to reduce warnings
Itagaki Takahiro [Wed, 10 Nov 2010 03:17:43 +0000 (12:17 +0900)]
Don't use __declspec (dllimport) for PGDLLEXPORT to reduce warnings
by gcc version 4 on mingw and cygwin. We don't use dllexport here
because dllexport and dllwrap don't work well together.

13 years agoRepair memory leakage while ANALYZE-ing complex index expressions.
Tom Lane [Tue, 9 Nov 2010 16:28:18 +0000 (11:28 -0500)]
Repair memory leakage while ANALYZE-ing complex index expressions.

The general design of memory management in Postgres is that intermediate
results computed by an expression are not freed until the end of the tuple
cycle.  For expression indexes, ANALYZE has to re-evaluate each expression
for each of its sample rows, and it wasn't bothering to free intermediate
results until the end of processing of that index.  This could lead to very
substantial leakage if the intermediate results were large, as in a recent
example from Jakub Ouhrabka.  Fix by doing ResetExprContext for each sample
row.  This necessitates adding a datumCopy step to ensure that the final
expression value isn't recycled too.  Some quick testing suggests that this
change adds at worst about 10% to the time needed to analyze a table with
an expression index; which is annoying, but seems a tolerable price to pay
to avoid unexpected out-of-memory problems.

Back-patch to all supported branches.

13 years agoIn rewriteheap.c (used by VACUUM FULL and CLUSTER), calculate the tuple
Heikki Linnakangas [Tue, 9 Nov 2010 15:40:09 +0000 (17:40 +0200)]
In rewriteheap.c (used by VACUUM FULL and CLUSTER), calculate the tuple
length stored in the line pointer the same way it's calculated in the normal
heap_insert() codepath. As noted by Jeff Davis, the length stored by
raw_heap_insert() included padding but the one stored by the normal codepath
did not. While the mismatch seems to be harmless, inconsistency isn't good,
and the normal codepath has received a lot more testing over the years.

Backpatch to 8.3 where the heap rewrite code was introduced.

13 years agoplpython has plpy.Error instead of plpy.ERROR
Alvaro Herrera [Tue, 9 Nov 2010 14:00:56 +0000 (11:00 -0300)]
plpython has plpy.Error instead of plpy.ERROR

Author: Marti Raudsepp <marti@juffo.org>

13 years agoFix error handling in temp-file deletion with log_temp_files active.
Tom Lane [Tue, 9 Nov 2010 03:14:55 +0000 (22:14 -0500)]
Fix error handling in temp-file deletion with log_temp_files active.

The original coding in FileClose() reset the file-is-temp flag before
unlinking the file, so that if control came back through due to an error,
it wouldn't try to unlink the file twice.  This was correct when written,
but when the log_temp_files feature was added, the logging action was put
in between those two steps.  An error occurring during the logging action
--- such as a query cancel --- would result in the unlink not getting done
at all, as in recent report from Michael Glaesemann.

To fix this, make sure that we do both the stat and the unlink before doing
anything that could conceivably CHECK_FOR_INTERRUPTS.  There is a judgment
call here, which is which log message to emit first: if you can see only
one, which should it be?  I chose to log unlink failure at the risk of
losing the log_temp_files log message --- after all, if the unlink does
fail, the temp file is still there for you to see.

Back-patch to all versions that have log_temp_files.  The code was OK
before that.

13 years agoFix permanent memory leak in autovacuum launcher
Alvaro Herrera [Mon, 8 Nov 2010 21:35:42 +0000 (18:35 -0300)]
Fix permanent memory leak in autovacuum launcher

get_database_list was uselessly allocating its output data, along some
created along the way, in a permanent memory context.  This didn't
matter when autovacuum was a single, short-lived process, but now that
the launcher is permanent, it shows up as a permanent leak.

To fix, make get_database list allocate its output data in the caller's
context, which is in charge of freeing it when appropriate; and the
memory leaked by heap_beginscan et al is allocated in a throwaway
transaction context.

13 years agoAdd support for detecting register-stack overrun on IA64.
Tom Lane [Sun, 7 Nov 2010 02:59:09 +0000 (22:59 -0400)]
Add support for detecting register-stack overrun on IA64.

Per recent investigation, the register stack can grow faster than the
regular stack depending on compiler and choice of options.  To avoid
crashes we must check both stacks in check_stack_depth().

Back-patch to all supported versions.

13 years agoReduce recursion depth in recently-added regression test.
Tom Lane [Wed, 3 Nov 2010 17:41:53 +0000 (13:41 -0400)]
Reduce recursion depth in recently-added regression test.

Some buildfarm members fail the test with the original depth of 10 levels,
apparently because they are running at the minimum max_stack_depth setting
of 100kB and using ~ 10k per recursion level.  While it might be
interesting to try to figure out why they're eating so much stack, it isn't
likely that any fix for that would be back-patchable.  So just change the
test to recurse only 5 levels.  The extra levels don't prove anything
correctness-wise anyway.

13 years agoFix adjust_semi_join to be more cautious about clauseless joins.
Tom Lane [Tue, 2 Nov 2010 22:45:44 +0000 (18:45 -0400)]
Fix adjust_semi_join to be more cautious about clauseless joins.

It was reporting that these were fully indexed (hence cheap), when of
course they're the exact opposite of that.  I'm not certain if the case
would arise in practice, since a clauseless semijoin is hard to produce
in SQL, but if it did happen we'd make some dumb decisions.

13 years agoFix buffer overrun in pg_upgrade.
Tom Lane [Tue, 2 Nov 2010 21:31:54 +0000 (17:31 -0400)]
Fix buffer overrun in pg_upgrade.

Problem reported, and cause identified, by Hernan Gonzalez.

13 years agoEnsure an index that uses a whole-row Var still depends on its table.
Tom Lane [Tue, 2 Nov 2010 21:15:13 +0000 (17:15 -0400)]
Ensure an index that uses a whole-row Var still depends on its table.

We failed to record any dependency on the underlying table for an index
declared like "create index i on t (foo(t.*))".  This would create trouble
if the table were dropped without previously dropping the index.  To fix,
simplify some overly-cute code in index_create(), accepting the possibility
that sometimes the whole-table dependency will be redundant.  Also document
this hazard in dependency.c.  Per report from Kevin Grittner.

In passing, prevent a core dump in pg_get_indexdef() if the index's table
can't be found.  I came across this while experimenting with Kevin's
example.  Not sure it's a real issue when the catalogs aren't corrupt, but
might as well be cautious.

Back-patch to all supported versions.

13 years agoBootstrap WAL to begin at segment logid=0 logseg=1 (000000010000000000000001)
Heikki Linnakangas [Tue, 2 Nov 2010 09:23:43 +0000 (11:23 +0200)]
Bootstrap WAL to begin at segment logid=0 logseg=1 (000000010000000000000001)
rather than 0/0, so that we can safely use 0/0 as an invalid value. This is a
more future-proof fix for the corner-case bug in streaming replication that
was fixed yesterday. We had a similar corner-case bug with log/seg 0/0 back in
February as well. Avoiding 0/0 as a valid value should prevent bugs like that
in the future. Per Tom Lane's idea.

Back-patch to 9.0. Since this only affects bootstrapping, it makes no
difference to existing installations. We don't need to worry about the
bug in existing installations, because if you've managed to get past the
initial base backup already, you won't hit the bug in the future either.

13 years agoFix corner-case bug in tracking of latest removed WAL segment during
Heikki Linnakangas [Mon, 1 Nov 2010 07:56:45 +0000 (09:56 +0200)]
Fix corner-case bug in tracking of latest removed WAL segment during
streaming replication. We used log/seg 0/0 to indicate that no WAL segments
have been removed since startup, but 0/0 is a valid value for the very first
WAL segment after initdb. To make that disambiguous, store
(latest removed WAL segment + 1) in the global variable.

Per report from Matt Chesler, also reproduced by Greg Smith.

13 years agoFix plpgsql's handling of "simple" expression evaluation.
Tom Lane [Thu, 28 Oct 2010 17:01:01 +0000 (13:01 -0400)]
Fix plpgsql's handling of "simple" expression evaluation.

In general, expression execution state trees aren't re-entrantly usable,
since functions can store private state information in them.
For efficiency reasons, plpgsql tries to cache and reuse state trees for
"simple" expressions.  It can get away with that most of the time, but it
can fail if the state tree is dirty from a previous failed execution (as
in an example from Alvaro) or is being used recursively (as noted by me).

Fix by tracking whether a state tree is in use, and falling back to the
"non-simple" code path if so.  This results in a pretty considerable speed
hit when the non-simple path is taken, but the available alternatives seem
even more unpleasant because they add overhead in the simple path.  Per
idea from Heikki.

Back-patch to all supported branches.

13 years agoFix long-standing segfault when accept() or one of the calls made right
Heikki Linnakangas [Wed, 27 Oct 2010 17:03:00 +0000 (20:03 +0300)]
Fix long-standing segfault when accept() or one of the calls made right
after accepting a connection fails, and the server is compiled with GSSAPI
support. Report and patch by Alexander V. Chernikov, bug #5731.

13 years agoFix up some oversights in psql's Unicode-escape support.
Tom Lane [Wed, 27 Oct 2010 02:23:16 +0000 (22:23 -0400)]
Fix up some oversights in psql's Unicode-escape support.

Original patch failed to include new exclusive states in a switch that
needed to include them; and also was guilty of very fuzzy thinking
about how to handle error cases.  Per bug #5729 from Alan Choi.