OSDN Git Service

pg-rex/syncrep.git
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.

13 years agoNote explicitly that hash indexes are also not replicated because they're not
Heikki Linnakangas [Tue, 26 Oct 2010 19:50:31 +0000 (22:50 +0300)]
Note explicitly that hash indexes are also not replicated because they're not
WAL-logged. Make the notice about the lack of WAL-logging more visible by
making it a <caution>. Also remove the false statement from hot standby
caveats section that hash indexes are not used during hot standby.

13 years agoBefore removing backup_label and irrevocably changing pg_control file, check
Heikki Linnakangas [Tue, 26 Oct 2010 18:15:42 +0000 (21:15 +0300)]
Before removing backup_label and irrevocably changing pg_control file, check
that WAL file containing the checkpoint redo-location can be found. This
avoids making the cluster irrecoverable if the redo location is in an earlie
WAL file than the checkpoint record.

Report, analysis and patch by Jeff Davis, with small changes by me.

13 years agoFix inline_set_returning_function() to preserve the invalItems list properly.
Tom Lane [Mon, 25 Oct 2010 17:04:42 +0000 (13:04 -0400)]
Fix inline_set_returning_function() to preserve the invalItems list properly.

This avoids a possible crash when inlining a SRF whose argument list
contains a reference to an inline-able user function.  The crash is quite
reproducible with CLOBBER_FREED_MEMORY enabled, but would be less certain
in a production build.  Problem introduced in 9.0 by the named-arguments
patch, which requires invoking eval_const_expressions() before we can try
to inline a SRF.  Per report from Brendan Jurd.

13 years agoAdd semicolon, missed in previous patch. And update the keyword list in
Heikki Linnakangas [Fri, 22 Oct 2010 15:38:31 +0000 (18:38 +0300)]
Add semicolon, missed in previous patch. And update the keyword list in
the docs to reflect that OFF is now unreserved. Spotted by Tom Lane.

13 years agoMake OFF keyword unreserved. It's not hard to imagine wanting to use 'off'
Heikki Linnakangas [Fri, 22 Oct 2010 14:37:38 +0000 (17:37 +0300)]
Make OFF keyword unreserved. It's not hard to imagine wanting to use 'off'
as a variable or column name, and it's not reserved in recent versions of
the SQL spec either. This became particularly annoying in 9.0, before that
PL/pgSQL replaced variable names in queries with parameter markers, so
it was possible to use OFF and many other backend parser keywords as
variable names. Because of that, backpatch to 9.0.

13 years agoRemove obsolete comment, per Josh Kupershmidt.
Tom Lane [Wed, 20 Oct 2010 21:05:15 +0000 (17:05 -0400)]
Remove obsolete comment, per Josh Kupershmidt.

13 years agoIf pk is NULL, the backend would segfault when accessing ->algo and the
Heikki Linnakangas [Wed, 20 Oct 2010 19:20:33 +0000 (22:20 +0300)]
If pk is NULL, the backend would segfault when accessing ->algo and the
following NULL check was never reached.

This problem was found by Coccinelle (null_ref.cocci from coccicheck).

Marti Raudsepp

13 years agoDon't try to fetch database name when SetTransactionIdLimit() is executed
Tom Lane [Wed, 20 Oct 2010 16:48:57 +0000 (12:48 -0400)]
Don't try to fetch database name when SetTransactionIdLimit() is executed
outside a transaction.

This repairs brain fade in my patch of 2009-08-30: the reason we had been
storing oldest-database name, not OID, in ShmemVariableCache was of course
to avoid having to do a catalog lookup at times when it might be unsafe.

This error explains why Aleksandr Dushein is having trouble getting out of
an XID wraparound state in bug #5718, though not how he got into that state
in the first place.  I suspect pg_upgrade is at fault there.

13 years agoFix ecpg test building process to not generate *.dSYM junk on Macs.
Tom Lane [Wed, 20 Oct 2010 04:55:03 +0000 (00:55 -0400)]
Fix ecpg test building process to not generate *.dSYM junk on Macs.

The trick is to not try to build executables directly from .c files,
but to always build the intermediate .o files.  For obscure reasons,
Darwin's version of gcc will leave debug cruft behind in the first
case but not the second.  Per complaint from Robert Haas.

13 years agoUpdate storage.sgml to describe the 9.0 tablespace directory layout.
Tom Lane [Wed, 20 Oct 2010 01:53:08 +0000 (21:53 -0400)]
Update storage.sgml to describe the 9.0 tablespace directory layout.

13 years agoFix incorrect generation of whole-row variables in planner.
Tom Lane [Tue, 19 Oct 2010 19:08:47 +0000 (15:08 -0400)]
Fix incorrect generation of whole-row variables in planner.

A couple of places in the planner need to generate whole-row Vars, and were
cutting corners by setting vartype = RECORDOID in the Vars, even in cases
where there's an identifiable named composite type for the RTE being
referenced.  While we mostly got away with this, it failed when there was
also a parser-generated whole-row reference to the same RTE, because the
two Vars weren't equal() due to the difference in vartype.  Fix by
providing a subroutine the planner can call to generate whole-row Vars
the same way the parser does.

Per bug #5716 from Andrew Tipton.  Back-patch to 9.0 where one of the bogus
calls was introduced (the other one is new in HEAD).

13 years agoAdd removal of PG_VERSION to optional old cluster deletion script.
Bruce Momjian [Tue, 19 Oct 2010 15:52:44 +0000 (15:52 +0000)]
Add removal of PG_VERSION to optional old cluster deletion script.
Backpatch to 9.0.X.

13 years agoAdd mention of using tools/fsync to test fsync methods. Restructure
Bruce Momjian [Tue, 19 Oct 2010 14:58:03 +0000 (14:58 +0000)]
Add mention of using tools/fsync to test fsync methods. Restructure
recent wal_sync_method doc paragraph to be clearer.

13 years agoIn pg_upgrade, rename macro EXEC_EXT to SHELL_EXT for clarity.
Bruce Momjian [Tue, 19 Oct 2010 02:55:58 +0000 (02:55 +0000)]
In pg_upgrade, rename macro EXEC_EXT to SHELL_EXT for clarity.

Backpatch to 9.0.X.

13 years agoRemove tab from SGML.
Bruce Momjian [Mon, 18 Oct 2010 18:51:28 +0000 (18:51 +0000)]
Remove tab from SGML.

13 years agoDocument the tablespace directory "should" be empty, rather than "must"
Bruce Momjian [Mon, 18 Oct 2010 18:16:45 +0000 (18:16 +0000)]
Document the tablespace directory "should" be empty, rather than "must"
be empty.  Because of binary migration usage, it might not be empty.

13 years agoFix msvc build for localized versions of Visual C++
Magnus Hagander [Sun, 17 Oct 2010 14:36:54 +0000 (16:36 +0200)]
Fix msvc build for localized versions of Visual C++

Look only at the non-localized part of the output from "vcbuild /?",
which is used to determine the version of Visual Studio in use. Different
languages seem to localize different amounts of the string, but we assume
the part "Microsoft Visual C++" won't be modified.

13 years agoFix low-risk potential denial of service against RADIUS login.
Magnus Hagander [Fri, 15 Oct 2010 14:59:12 +0000 (16:59 +0200)]
Fix low-risk potential denial of service against RADIUS login.

Corrupt RADIUS responses were treated as errors and not ignored
(which the RFC2865 states they should be). This meant that a
user with unfiltered access to the network of the PostgreSQL
or RADIUS server could send a spoofed RADIUS response
to the PostgreSQL server causing it to reject a valid login,
provided the attacker could also guess (or brute-force) the
correct port number.

Fix is to simply retry the receive in a loop until the timeout
has expired or a valid (signed by the correct RADIUS server)
packet arrives.

Reported by Alan DeKok in bug #5687.

13 years agoCorrect WAL space calculation formula in docs.
Simon Riggs [Fri, 15 Oct 2010 09:19:10 +0000 (10:19 +0100)]
Correct WAL space calculation formula in docs.

Error pointed out by Fujii Masao, though not his patch.

13 years agoAdd pg_user_mappings to the table of system views.
Robert Haas [Thu, 14 Oct 2010 23:12:24 +0000 (19:12 -0400)]
Add pg_user_mappings to the table of system views.

13 years agoImprovements to docs about pg_archive_cleanup and use of archives
Simon Riggs [Thu, 14 Oct 2010 22:23:26 +0000 (23:23 +0100)]
Improvements to docs about pg_archive_cleanup and use of archives

Brendan Jurd

13 years agoComplete the documentation of the USAGE privilege for foreign servers
Peter Eisentraut [Thu, 14 Oct 2010 17:36:42 +0000 (20:36 +0300)]
Complete the documentation of the USAGE privilege for foreign servers

The GRANT reference page failed to mention that the USAGE privilege
allows modifying associated user mappings, although this was already
documented on the CREATE/ALTER/DROP USER MAPPING pages.

13 years agoFix bug in comment of timeline history file.
Simon Riggs [Thu, 14 Oct 2010 18:13:09 +0000 (19:13 +0100)]
Fix bug in comment of timeline history file.

Fujii Masao

13 years agoApplied patch by Itagaki Takahiro to fix incorrect status calculation in
Michael Meskes [Thu, 14 Oct 2010 15:49:01 +0000 (17:49 +0200)]
Applied patch by Itagaki Takahiro to fix incorrect status calculation in
ecpglib. Instead of parsing the statement just as ask the database server.

13 years agoMake title capitalization consistent with surroundings
Peter Eisentraut [Wed, 13 Oct 2010 17:05:16 +0000 (20:05 +0300)]
Make title capitalization consistent with surroundings

13 years agoFix plpython so that it again honors typmod while assigning to tuple fields.
Tom Lane [Tue, 12 Oct 2010 02:16:46 +0000 (22:16 -0400)]
Fix plpython so that it again honors typmod while assigning to tuple fields.

This was broken in 9.0 while improving plpython's conversion behavior for
bytea and boolean.  Per bug report from maizi.

13 years agoFix assorted bugs in GIN's WAL replay logic.
Tom Lane [Mon, 11 Oct 2010 23:04:44 +0000 (19:04 -0400)]
Fix assorted bugs in GIN's WAL replay logic.

The original coding was quite sloppy about handling the case where
XLogReadBuffer fails (because the page has since been deleted).  This
would result in either "bad buffer id: 0" or an Assert failure during
replay, if indeed the page were no longer there.  In a couple of places
it also neglected to check whether the change had already been applied,
which would probably result in corrupted index contents.  I believe that
bug #5703 is an instance of the first problem.  These issues could show up
without replication, but only if you were unfortunate enough to crash
between modification of a GIN index and the next checkpoint.

Back-patch to 8.2, which is as far back as GIN has WAL support.

13 years agoAdjust EXPLAIN documentation, so that it's not unreasonably wide.
Robert Haas [Sat, 9 Oct 2010 02:59:48 +0000 (22:59 -0400)]
Adjust EXPLAIN documentation, so that it's not unreasonably wide.

The new formatting matches what we do for COPY.

Per a complaint from Bruce Momjian.

13 years agoWarn that views can be safely used to hide columns, but not rows.
Robert Haas [Fri, 8 Oct 2010 13:15:17 +0000 (09:15 -0400)]
Warn that views can be safely used to hide columns, but not rows.

13 years agoImprove WAL reliability documentation, and add more cross-references to it.
Robert Haas [Thu, 7 Oct 2010 16:19:03 +0000 (12:19 -0400)]
Improve WAL reliability documentation, and add more cross-references to it.

In particular, we are now more explicit about the fact that you may need
wal_sync_method=fsync_writethrough for crash-safety on some platforms,
including MaxOS X.  There's also now an explicit caution against assuming
that the default setting of wal_sync_method is either crash-safe or best
for performance.

13 years agoCorrect docs for behaviour of ALTER DATABASE .. RENAME during Hot Standby.
Simon Riggs [Tue, 5 Oct 2010 23:20:54 +0000 (00:20 +0100)]
Correct docs for behaviour of ALTER DATABASE .. RENAME during Hot Standby.
Actual behaviour did not match documented behaviour and we have agreed
that it should be the docs that change.

Spotted by Bernd Helmle

13 years agoUndo some poorly-thought-out "proofreading improvements".
Tom Lane [Tue, 5 Oct 2010 22:48:20 +0000 (18:48 -0400)]
Undo some poorly-thought-out "proofreading improvements".
Per Tatsuhito Kasahara.

13 years agoBehave correctly if INSERT ... VALUES is decorated with additional clauses.
Tom Lane [Sun, 3 Oct 2010 00:02:33 +0000 (20:02 -0400)]
Behave correctly if INSERT ... VALUES is decorated with additional clauses.

In versions 8.2 and up, the grammar allows attaching ORDER BY, LIMIT,
FOR UPDATE, or WITH to VALUES, and hence to INSERT ... VALUES.  But the
special-case code for VALUES in transformInsertStmt() wasn't expecting any
of those, and just ignored them, leading to unexpected results.  Rather
than complicate the special-case path, just ensure that the presence of any
of those clauses makes us treat the query as if it had a general SELECT.
Per report from Hitoshi Harada.

13 years agoRemove excess argument to open(2).
Tom Lane [Sat, 2 Oct 2010 22:40:28 +0000 (18:40 -0400)]
Remove excess argument to open(2).

Many compilers don't complain about this, but some do, and it's certainly
wrong.  Back-patch to 8.4 where the error was introduced.

Mark Kirkwood

13 years agoThrow an appropriate error if ALTER COLUMN TYPE finds a dependent trigger.
Tom Lane [Sat, 2 Oct 2010 22:21:41 +0000 (18:21 -0400)]
Throw an appropriate error if ALTER COLUMN TYPE finds a dependent trigger.

Actually making this case work, if the column is used in the trigger's
WHEN condition, will take some new code that probably isn't appropriate
to back-patch.  For now, just throw a FEATURE_NOT_SUPPORTED error rather
than allowing control to reach the "unexpected object" case.  Per bug #5688
from Daniel Grace.  Back-patch to 9.0 where the possibility of such a
dependency was introduced.

13 years agoFix back-branch breakage from ill-advised last-minute commit. REL9_0_1
Tom Lane [Fri, 1 Oct 2010 14:25:44 +0000 (10:25 -0400)]
Fix back-branch breakage from ill-advised last-minute commit.

13 years agoTag 9.0.1
Marc G. Fournier [Fri, 1 Oct 2010 13:28:42 +0000 (10:28 -0300)]
Tag 9.0.1

13 years agoUse a separate interpreter for each calling SQL userid in plperl and pltcl.
Tom Lane [Thu, 30 Sep 2010 21:19:44 +0000 (17:19 -0400)]
Use a separate interpreter for each calling SQL userid in plperl and pltcl.

There are numerous methods by which a Perl or Tcl function can subvert
the behavior of another such function executed later; for example, by
redefining standard functions or operators called by the target function.
If the target function is SECURITY DEFINER, or is called by such a
function, this means that any ordinary SQL user with Perl or Tcl language
usage rights can do essentially anything with the privileges of the target
function's owner.

To close this security hole, create a separate Perl or Tcl interpreter for
each SQL userid under which plperl or pltcl functions are executed within
a session.  However, all plperlu or pltclu functions run within a session
still share a single interpreter, since they all execute at the trust
level of a database superuser anyway.

Note: this change results in a functionality loss when libperl has been
built without the "multiplicity" option: it's no longer possible to call
plperl functions under different userids in one session, since such a
libperl can't support multiple interpreters in one process.  However, such
a libperl already failed to support concurrent use of plperl and plperlu,
so it's likely that few people use such versions with Postgres.

Security: CVE-2010-3433

13 years agoAdjust pg_archivecleanup docs to match message changes made 2010-06-17.
Robert Haas [Thu, 30 Sep 2010 21:05:15 +0000 (17:05 -0400)]
Adjust pg_archivecleanup docs to match message changes made 2010-06-17.

Erik Rijkers

13 years agoTranslation updates for 9.0.1
Peter Eisentraut [Thu, 30 Sep 2010 20:46:16 +0000 (23:46 +0300)]
Translation updates for 9.0.1

13 years agoUpdate release notes for releases 9.0.1, 8.4.5, 8.3.12, 8.2.18, 8.1.22,
Tom Lane [Thu, 30 Sep 2010 18:27:28 +0000 (14:27 -0400)]
Update release notes for releases 9.0.1, 8.4.5, 8.3.12, 8.2.18, 8.1.22,
8.0.26, and 7.4.30.

13 years agoHave pg_upgrade use strtoul(), not strtol().
Bruce Momjian [Wed, 29 Sep 2010 02:40:26 +0000 (02:40 +0000)]
Have pg_upgrade use strtoul(), not strtol().

13 years agoUse macro atooid() for conversion of strings to oids, per suggestion
Bruce Momjian [Tue, 28 Sep 2010 22:11:21 +0000 (22:11 +0000)]
Use macro atooid() for conversion of strings to oids, per suggestion
from Tom.

13 years agoIn pg_upgrade, properly handle oids > 2^31 by using strtoul() internally
Bruce Momjian [Tue, 28 Sep 2010 21:41:03 +0000 (21:41 +0000)]
In pg_upgrade, properly handle oids > 2^31 by using strtoul() internally
rather than atol().

Per report from Brian Hirt