]> granicus.if.org Git - postgresql/log
postgresql
12 years agoRemove extra copies of LogwrtResult.
Heikki Linnakangas [Tue, 6 Mar 2012 07:34:10 +0000 (09:34 +0200)]
Remove extra copies of LogwrtResult.

This simplifies the code a little bit. The new rule is that to update
XLogCtl->LogwrtResult, you must hold both WALWriteLock and info_lck, whereas
before we had two copies, one that was protected by WALWriteLock and another
protected by info_lck. The code that updates them was already holding both
locks, so merging the two is trivial.

The third copy, XLogCtl->Insert.LogwrtResult, was not totally redundant, it
was used in AdvanceXLInsertBuffer to update the backend-local copy, before
acquiring the info_lck to read the up-to-date value. But the value of that
seems dubious; at best it's saving one spinlock acquisition per completed
WAL page, which is not significant compared to all the other work involved.
And in practice, it's probably not saving even that much.

12 years agoSimplify the way changes to full_page_writes are logged.
Heikki Linnakangas [Tue, 6 Mar 2012 07:13:00 +0000 (09:13 +0200)]
Simplify the way changes to full_page_writes are logged.

It's harmless to do full page writes even when not strictly necessary, so
when turning full_page_writes on, we can set the global flag first, and then
call XLogInsert. Likewise, when turning it off, we can write the WAL record
first, and then clear the flag. This way XLogInsert doesn't need any special
handling of the XLOG_FPW_CHANGE record type. XLogInsert is complicated
enough already, so anything we can keep away from there is a good thing.

Actually I don't think the atomicity of the shared memory flag matters,
anyway, because we only write the XLOG_FPW_CHANGE at the end of recovery,
when there are no concurrent WAL insertions going on. But might as well make
it safe, in case we allow changing full_page_writes on the fly in the
future.

12 years agoIn pg_upgrade, only lock the old cluster if link mode is used, and do it
Bruce Momjian [Tue, 6 Mar 2012 02:19:54 +0000 (21:19 -0500)]
In pg_upgrade, only lock the old cluster if link mode is used, and do it
right after we restore the schema (a common failure point), and right
before we do the link operation.

Per suggesgtions from Robert and ^!C^!^@lvaro

12 years agoRedesign PlanForeignScan API to allow multiple paths for a foreign table.
Tom Lane [Mon, 5 Mar 2012 21:15:59 +0000 (16:15 -0500)]
Redesign PlanForeignScan API to allow multiple paths for a foreign table.

The original API specification only allowed an FDW to create a single
access path, which doesn't seem like a terribly good idea in hindsight.
Instead, move the responsibility for building the Path node and calling
add_path() into the FDW's PlanForeignScan function.  Now, it can do that
more than once if appropriate.  There is no longer any need for the
transient FdwPlan struct, so get rid of that.

Etsuro Fujita, Shigeru Hanada, Tom Lane

12 years agoImprove documentation around logging_collector and use of stderr.
Tom Lane [Mon, 5 Mar 2012 19:08:52 +0000 (14:08 -0500)]
Improve documentation around logging_collector and use of stderr.

In backup.sgml, point out that you need to be using the logging collector
if you want to log messages from a failing archive_command script.  (This
is an oversimplification, in that it will work without the collector as
long as you're not sending postmaster stderr to /dev/null; but it seems
like a good idea to encourage use of the collector to avoid problems
with multiple processes concurrently scribbling on one file.)

In config.sgml, do some wordsmithing of logging_collector discussion.

Per bug #6518 from Janning Vygen

12 years agoAdd isolation test to check-world and installcheck-world
Peter Eisentraut [Mon, 5 Mar 2012 18:19:20 +0000 (20:19 +0200)]
Add isolation test to check-world and installcheck-world

12 years agoRewrite GiST support code for rangetypes.
Tom Lane [Mon, 5 Mar 2012 03:50:06 +0000 (22:50 -0500)]
Rewrite GiST support code for rangetypes.

This patch installs significantly smarter penalty and picksplit functions
for ranges, making GiST indexes for them smaller and faster to search.

There is no on-disk format change, so no catversion bump, but you'd need
to REINDEX to get the benefits for any existing index.

Alexander Korotkov, reviewed by Jeff Davis

12 years agoRemove useless "rough estimate" path from mcelem_array_contained_selec.
Tom Lane [Sun, 4 Mar 2012 21:03:38 +0000 (16:03 -0500)]
Remove useless "rough estimate" path from mcelem_array_contained_selec.

The code in this function that tried to cope with a missing count histogram
was quite ineffective for anything except a perfectly flat distribution.
Furthermore, since we were already punting for missing MCELEM slot, it's
rather useless to sweat over missing DECHIST: there are no cases where
ANALYZE will create the first but not the second.  So just simplify the
code by punting rather than pretending we can do something useful.

12 years agoImprove histogram-filling loop in new compute_array_stats() code.
Tom Lane [Sun, 4 Mar 2012 20:40:16 +0000 (15:40 -0500)]
Improve histogram-filling loop in new compute_array_stats() code.

Do "frac" arithmetic in int64 to prevent overflow with large statistics
targets, and improve the comments so people have some chance of
understanding how it works.

Alexander Korotkov and Tom Lane

12 years agoMore carefully validate xlog location string inputs
Magnus Hagander [Sun, 4 Mar 2012 11:24:09 +0000 (12:24 +0100)]
More carefully validate xlog location string inputs

Now that we have validate_xlog_location, call it from the previously
existing functions taking xlog locatoins as a string input.

Suggested by Fujii Masao

12 years agoAdd function pg_xlog_location_diff to help comparisons
Magnus Hagander [Sun, 4 Mar 2012 11:15:24 +0000 (12:15 +0100)]
Add function pg_xlog_location_diff to help comparisons

Comparing two xlog locations are useful for example when calculating
replication lag.

Euler Taveira de Oliveira, reviewed by Fujii Masao, and some cleanups
from me

12 years agoCollect and use element-frequency statistics for arrays.
Tom Lane [Sun, 4 Mar 2012 01:20:19 +0000 (20:20 -0500)]
Collect and use element-frequency statistics for arrays.

This patch improves selectivity estimation for the array <@, &&, and @>
(containment and overlaps) operators.  It enables collection of statistics
about individual array element values by ANALYZE, and introduces
operator-specific estimators that use these stats.  In addition,
ScalarArrayOpExpr constructs of the forms "const = ANY/ALL (array_column)"
and "const <> ANY/ALL (array_column)" are estimated by treating them as
variants of the containment operators.

Since we still collect scalar-style stats about the array values as a
whole, the pg_stats view is expanded to show both these stats and the
array-style stats in separate columns.  This creates an incompatible change
in how stats for tsvector columns are displayed in pg_stats: the stats
about lexemes are now displayed in the array-related columns instead of the
original scalar-related columns.

There are a few loose ends here, notably that it'd be nice to be able to
suppress either the scalar-style stats or the array-element stats for
columns for which they're not useful.  But the patch is in good enough
shape to commit for wider testing.

Alexander Korotkov, reviewed by Noah Misch and Nathan Boley

12 years agoProvide environment overrides for psql file locations.
Andrew Dunstan [Sat, 3 Mar 2012 21:39:26 +0000 (16:39 -0500)]
Provide environment overrides for psql file locations.

PSQL_HISTORY provides an alternative for the command history file,
and PSQLRC provides an alternative location for the .psqlrc file.

12 years agoAllow CREATE TABLE (LIKE ...) from composite type
Peter Eisentraut [Sat, 3 Mar 2012 14:03:05 +0000 (16:03 +0200)]
Allow CREATE TABLE (LIKE ...) from composite type

The only reason this didn't work before was that parserOpenTable()
rejects composite types.  So use relation_openrv() directly and
manually do the errposition() setup that parserOpenTable() does.

12 years agoFix incorrect uses of gzFile
Peter Eisentraut [Fri, 2 Mar 2012 20:30:01 +0000 (22:30 +0200)]
Fix incorrect uses of gzFile

gzFile is already a pointer, so code like

gzFile *handle = gzopen(...)

is wrong.

This used to pass silently because gzFile used to be defined as void*,
and you can assign a void* to a void**.  But somewhere between zlib
versions 1.2.3.4 and 1.2.6, the definition of gzFile was changed to
struct gzFile_s *, and with that new definition this usage causes
compiler warnings.

So remove all those extra pointer decorations.

There is a related issue in pg_backup_archiver.h, where

FILE       *FH;             /* General purpose file handle */

is used throughout pg_dump as sometimes a real FILE* and sometimes a
gzFile handle, which also causes warnings now.  This is not yet fixed
here, because it might need more code restructuring.

12 years agoRe-add "make check" target in src/test/isolation/Makefile
Peter Eisentraut [Fri, 2 Mar 2012 20:09:10 +0000 (22:09 +0200)]
Re-add "make check" target in src/test/isolation/Makefile

This effectively reverts 7886cc73ad12fb9b5a729b6c8152f11a309f5d65,
which was done under the impression that isolationtester needs libpq,
which it no longer does (and never really did).

12 years agoAllow child-relation entries to be made in ec_has_const EquivalenceClasses.
Tom Lane [Fri, 2 Mar 2012 19:28:46 +0000 (14:28 -0500)]
Allow child-relation entries to be made in ec_has_const EquivalenceClasses.

This fixes an oversight in commit 11cad29c91524aac1d0b61e0ea0357398ab79bf8,
which introduced MergeAppend plans.  Before that happened, we never
particularly cared about the sort ordering of scans of inheritance child
relations, since appending their outputs together would destroy any
ordering anyway.  But now it's important to be able to match child relation
sort orderings to those of the surrounding query.  The original coding of
add_child_rel_equivalences skipped ec_has_const EquivalenceClasses, on the
originally-correct grounds that adding child expressions to them was
useless.  The effect of this is that when a parent variable is equated to
a constant, we can't recognize that index columns on the equivalent child
variables are not sort-significant; that is, we can't recognize that a
child index on, say, (x, y) is able to generate output in "ORDER BY y"
order when there is a clause "WHERE x = constant".  Adding child
expressions to the (x, constant) EquivalenceClass fixes this, without any
downside that I can see other than a few more planner cycles expended on
such queries.

Per recent gripe from Robert McGehee.  Back-patch to 9.1 where MergeAppend
was introduced.

12 years agoAdd COLLATION FOR expression
Peter Eisentraut [Fri, 2 Mar 2012 19:12:16 +0000 (21:12 +0200)]
Add COLLATION FOR expression

reviewed by Jaime Casanova

12 years agoecpg: Clean up some const usage
Peter Eisentraut [Fri, 2 Mar 2012 18:51:29 +0000 (20:51 +0200)]
ecpg: Clean up some const usage

12 years agoAdd a rule to optionally build docs with the stylesheet from the website
Magnus Hagander [Sat, 25 Feb 2012 14:13:12 +0000 (15:13 +0100)]
Add a rule to optionally build docs with the stylesheet from the website

For those of us who prefer the formatting of the docs using the
website stylesheets. Use "make STYLE=website draft" (for example) to use.

The stylesheet itself is referenced directly to the website, so there
is currently no copy of it stored in the source repository. Thus, docs
built with it will only look correct if the browser can access the website
when viewing them.

12 years agoWhen a GiST page is split during index build, it might not have a buffer.
Heikki Linnakangas [Fri, 2 Mar 2012 11:16:09 +0000 (13:16 +0200)]
When a GiST page is split during index build, it might not have a buffer.

Previously it was thought that it's impossible as the code stands, because
insertions create buffers as tuples are cascaded downwards, and index
split also creaters buffers eagerly for all halves. But the example from
Jay Levitt demonstrates that it can happen, when the root page is split.
It's in fact OK if the buffer doesn't exist, so we just need to remove the
sanity check. In fact, we've been discussing the possibility of destroying
empty buffers to conserve memory, which would render the sanity check
completely useless anyway.

Fix by Alexander Korotkov

12 years agoSmall possible clarification in pg_basebackup reference page
Peter Eisentraut [Thu, 1 Mar 2012 19:16:24 +0000 (21:16 +0200)]
Small possible clarification in pg_basebackup reference page

The <literal> markup is not visible as distinct on man pages, which
creates a bit of confusion when looking at the documentation of the
pg_basebackup -l option.  Rather than reinventing the entire font
system for man pages to remedy this, just put some quotes around this
particular case, which should also help in other output formats.

12 years agoDon't link pg_isolation_regress with libpq
Peter Eisentraut [Thu, 1 Mar 2012 18:50:36 +0000 (20:50 +0200)]
Don't link pg_isolation_regress with libpq

It's not necessary and can only create confusion about which libpq
installation should be used.

Also remove some dead code from the makefile that was apparently
copied from elsewhere.

12 years agopsql: Improve error display for psql -f -
Peter Eisentraut [Thu, 1 Mar 2012 17:58:10 +0000 (19:58 +0200)]
psql: Improve error display for psql -f -

Running "psql -f -" used to print

psql:<stdin>:1: ERROR:  blah

but that got broken between 8.4 and 9.0 (commit
b291c0fba83a1e93868e2f69c03be195d620f30c), and now it printed

psql:-:1: ERROR:  blah

This reverts to the old behavior and cleans up some code that was left
dead or useless by the mentioned commit.

12 years agoRemove TOAST table from pg_database
Alvaro Herrera [Wed, 29 Feb 2012 02:43:36 +0000 (23:43 -0300)]
Remove TOAST table from pg_database

The only toastable column now is datacl, but we don't really support
long ACLs anyway.  The TOAST table should have been removed when the
pg_db_role_setting catalog was introduced in commit
2eda8dfb52ed9962920282d8384da8bb4c22514d, but I forgot to do that.

Per -hackers discussion on March 2011.

12 years agoSimplify references to backslash-doubling in func.sgml.
Tom Lane [Wed, 29 Feb 2012 17:11:10 +0000 (12:11 -0500)]
Simplify references to backslash-doubling in func.sgml.

Several places were still written as though standard_conforming_strings
didn't exist, much less be the default.  Now that it is on by default,
we can simplify the text and just insert occasional notes suggesting that
you might have to think harder if it's turned off.  Per discussion of a
suggestion from Hannes Frederic Sowa.

Back-patch to 9.1 where standard_conforming_strings was made the default.

12 years agoCorrectly detect SSI conflicts of prepared transactions after crash.
Heikki Linnakangas [Wed, 29 Feb 2012 13:22:49 +0000 (15:22 +0200)]
Correctly detect SSI conflicts of prepared transactions after crash.

A prepared transaction can get new conflicts in and out after preparing, so
we cannot rely on the in- and out-flags stored in the statefile at prepare-
time. As a quick fix, make the conservative assumption that after a restart,
all prepared transactions are considered to have both in- and out-conflicts.
That can lead to unnecessary rollbacks after a crash, but that shouldn't be
a big problem in practice; you don't want prepared transactions to hang
around for a long time anyway.

Dan Ports

12 years agoFix MSVC builds for previous patch's addition of a src/port file.
Tom Lane [Wed, 29 Feb 2012 05:24:01 +0000 (00:24 -0500)]
Fix MSVC builds for previous patch's addition of a src/port file.

(And why in the world is this OBJS list not being scraped from the
corresponding Makefile?)

12 years agoFix typo in comment
Alvaro Herrera [Wed, 29 Feb 2012 02:52:52 +0000 (23:52 -0300)]
Fix typo in comment

Haifeng Liu

12 years agoMove CRC tables to libpgport, and provide them in a separate include file.
Tom Lane [Wed, 29 Feb 2012 00:53:39 +0000 (19:53 -0500)]
Move CRC tables to libpgport, and provide them in a separate include file.

This makes it much more convenient to build tools for Postgres that are
separately compiled and require a matching CRC implementation.

To prevent multiple copies of the CRC polynomial tables being introduced
into the postgres binaries, they are now included in the static library
libpgport that is mainly meant for replacement system functions.  That
seems like a bit of a kludge, but there's no better place.

This cleans up building of the tools pg_controldata and pg_resetxlog,
which previously had to build their own copies of pg_crc.o.

In the future, external programs that need access to the CRC tables can
include the tables directly from the new header file pg_crc_tables.h.

Daniel Farina, reviewed by Abhijit Menon-Sen and Tom Lane

12 years agoFix thinko in new match_join_clauses_to_index() logic.
Tom Lane [Tue, 28 Feb 2012 23:10:40 +0000 (18:10 -0500)]
Fix thinko in new match_join_clauses_to_index() logic.

We don't need to constrain the other side of an indexable join clause to
not be below an outer join; an example here is

SELECT FROM t1 LEFT JOIN t2 ON t1.a = t2.b LEFT JOIN t3 ON t2.c = t3.d;

We can consider an inner indexscan on t3.d using c = d as indexqual, even
though t2.c is potentially nulled by a previous outer join.  The comparable
logic in orindxpath.c has always worked that way, but I was being overly
cautious here.

12 years agoAdd const qualifiers where they are accidentally cast away
Peter Eisentraut [Tue, 28 Feb 2012 10:42:08 +0000 (12:42 +0200)]
Add const qualifiers where they are accidentally cast away

This only produces warnings under -Wcast-qual, but it's more correct
and consistent in any case.

12 years agopsql: when tab-completing, use quotes on file names that need them
Alvaro Herrera [Tue, 28 Feb 2012 04:06:29 +0000 (01:06 -0300)]
psql: when tab-completing, use quotes on file names that need them

psql backslash commands that deal with file or directory names require
quotes around those that have spaces, single quotes, or backslashes.
However, tab-completing such names does not provide said quotes, and is
thus almost useless with them.

This patch fixes the problem by having a wrapper function around
rl_filename_completion_function that dequotes on input and quotes on
output.  This eases dealing with such names.

Author: Noah Misch

12 years agoALTER TABLE: skip FK validation when it's safe to do so
Alvaro Herrera [Mon, 27 Feb 2012 21:28:00 +0000 (18:28 -0300)]
ALTER TABLE: skip FK validation when it's safe to do so

We already skip rewriting the table in these cases, but we still force a
whole table scan to validate the data.  This can be skipped, and thus
we can make the whole ALTER TABLE operation just do some catalog touches
instead of scanning the table, when these two conditions hold:

(a) Old and new pg_constraint.conpfeqop match exactly.  This is actually
stronger than needed; we could loosen things by way of operator
families, but it'd require a lot more effort.

(b) The functions, if any, implementing a cast from the foreign type to
the primary opcintype are the same.  For this purpose, we can consider a
binary coercion equivalent to an exact type match.  When the opcintype
is polymorphic, require that the old and new foreign types match
exactly.  (Since ri_triggers.c does use the executor, the stronger check
for polymorphic types is no mere future-proofing.  However, no core type
exercises its necessity.)

Author: Noah Misch

Committer's note: catalog version bumped due to change of the Constraint
node.  I can't actually find any way to have such a node in a stored
rule, but given that we have "out" support for them, better be safe.

12 years agoCall check_keywords.pl in maintainer-check
Peter Eisentraut [Mon, 27 Feb 2012 11:53:12 +0000 (13:53 +0200)]
Call check_keywords.pl in maintainer-check

For that purpose, have check_keywords.pl print errors to stderr and
return a useful exit status.

12 years agoFix some more bugs in GIN's WAL replay logic.
Tom Lane [Sun, 26 Feb 2012 20:12:17 +0000 (15:12 -0500)]
Fix some more bugs in GIN's WAL replay logic.

In commit 4016bdef8aded77b4903c457050622a5a1815c16 I fixed a bunch of
ginxlog.c bugs having to do with not handling XLogReadBuffer failures
correctly.  However, in ginRedoUpdateMetapage and ginRedoDeleteListPages,
I unaccountably thought that failure to read the metapage would be
impossible and just put in an elog(PANIC) call.  This is of course wrong:
failure is exactly what will happen if the index got dropped (or rebuilt)
between creation of the WAL record and the crash we're trying to recover
from.  I believe this explains Nicholas Wilson's recent report of these
errors getting reached.

Also, fix memory leak in forgetIncompleteSplit.  This wasn't of much
concern when the code was written, but in a long-running standby server
page split records could be expected to accumulate indefinitely.

Back-patch to 8.4 --- before that, GIN didn't have a metapage.

12 years agoRemove useless cast
Peter Eisentraut [Sun, 26 Feb 2012 13:31:16 +0000 (15:31 +0200)]
Remove useless cast

12 years agoRemove useless const qualifier
Peter Eisentraut [Sun, 26 Feb 2012 13:22:27 +0000 (15:22 +0200)]
Remove useless const qualifier

Claiming that the typevar argument to DefineCompositeType() is const
was a plain lie.  A similar case in DefineVirtualRelation() was
already changed in passing in commit 1575fbcb.  Also clean up the now
unnecessary casts that used to cast away the const.

12 years agoFix some typos and correct wording in the monitoring docs patch
Magnus Hagander [Sat, 25 Feb 2012 15:33:57 +0000 (16:33 +0100)]
Fix some typos and correct wording in the monitoring docs patch

Thom Brown

12 years agoMerge the list of statistics functions into the view documentation
Magnus Hagander [Sat, 25 Feb 2012 14:21:04 +0000 (15:21 +0100)]
Merge the list of statistics functions into the view documentation

Most people won't read them individually anyway, it's an easy way to find
them, and it's a lot of duplicated information if they are kept in two
different places.

12 years agoMake each pg_stat_ view into it's own table in the documentation
Magnus Hagander [Sat, 25 Feb 2012 14:20:49 +0000 (15:20 +0100)]
Make each pg_stat_ view into it's own table in the documentation

This makes it easier to match a column name with the description of it,
and makes it possible to add more detailed documentation in the future.

This patch does not add that extra documentation at this point, only
the structure required for it.

Modeled on the changes already done to pg_stat_activity.

12 years agoMerge dissect() into cdissect() to remove a pile of near-duplicate code.
Tom Lane [Fri, 24 Feb 2012 21:26:10 +0000 (16:26 -0500)]
Merge dissect() into cdissect() to remove a pile of near-duplicate code.

The "uncomplicated" case isn't materially less complicated than the full
case, certainly not enough so to justify duplicating nearly 500 lines
of code.  The only extra work being done in the full path is zaptreesubs,
which is very cheap compared to everything else being done here, and
besides that I'm less than convinced that it's not needed in some cases
even without backrefs.

12 years agoAvoid repeated creation/freeing of per-subre DFAs during regex search.
Tom Lane [Fri, 24 Feb 2012 19:56:35 +0000 (14:56 -0500)]
Avoid repeated creation/freeing of per-subre DFAs during regex search.

In nested sub-regex trees, lower-level nodes created DFAs and then
destroyed them again before exiting, which is a bit dumb considering that
the recursive search is likely to call those nodes again later.  Instead
cache each created DFA until the end of pg_regexec().  This is basically a
space for time tradeoff, in that it might increase the maximum memory
usage.  However, in most regex patterns there are not all that many subre
nodes, so not that many DFAs --- and in any case, the peak usage occurs
when reaching the bottom recursion level, and except for alternation cases
that's going to be the same anyway.

12 years agoRemove useless "retry memory" logic within regex engine.
Tom Lane [Fri, 24 Feb 2012 08:36:49 +0000 (03:36 -0500)]
Remove useless "retry memory" logic within regex engine.

Apparently some primordial version of Spencer's engine needed cdissect()
and child functions to be able to continue matching from a previous
position when re-called.  That is dead code, though, since trivial
inspection shows that cdissect can never be entered without having
previously done zapmem which resets the relevant retry counter.  I have
also verified experimentally that no case in the Tcl regression tests
reaches cdissect with a nonzero retry value.  Accordingly, remove that
logic.  This doesn't really save any noticeable number of cycles in itself,
but it is one step towards making dissect() and cdissect() equivalent,
which will allow removing hundreds of lines of near-duplicated code.

Since struct subre's "retry" field is no longer particularly related to
any kind of retry, rename it to "id".  As of this commit it's only used
for identifying a subre node in debug printouts, so you might think we
should get rid of the field entirely; but I have a plan for another use.

12 years agoMention original ctags option name.
Bruce Momjian [Fri, 24 Feb 2012 21:19:18 +0000 (16:19 -0500)]
Mention original ctags option name.

12 years agoUpdate src/tools/make_ctags to avoid Exuberant tags option
Bruce Momjian [Fri, 24 Feb 2012 21:17:07 +0000 (16:17 -0500)]
Update src/tools/make_ctags to avoid Exuberant tags option
that has been renamed and undocumented since 2003;  instead, use the
documented option.  Add comments.

12 years agoPut Debian package list back in alphabetical order
Peter Eisentraut [Fri, 24 Feb 2012 18:40:29 +0000 (20:40 +0200)]
Put Debian package list back in alphabetical order

12 years agoAdd some enumeration commas, for consistency
Peter Eisentraut [Fri, 24 Feb 2012 09:04:45 +0000 (11:04 +0200)]
Add some enumeration commas, for consistency

12 years agoFix the general case of quantified regex back-references.
Tom Lane [Fri, 24 Feb 2012 06:40:18 +0000 (01:40 -0500)]
Fix the general case of quantified regex back-references.

Cases where a back-reference is part of a larger subexpression that
is quantified have never worked in Spencer's regex engine, because
he used a compile-time transformation that neglected the need to
check the back-reference match in iterations before the last one.
(That was okay for capturing parens, and we still do it if the
regex has *only* capturing parens ... but it's not okay for backrefs.)

To make this work properly, we have to add an "iteration" node type
to the regex engine's vocabulary of sub-regex nodes.  Since this is a
moderately large change with a fair risk of introducing new bugs of its
own, apply to HEAD only, even though it's a fix for a longstanding bug.

12 years agoCorrectly handle NULLs in JSON output.
Andrew Dunstan [Fri, 24 Feb 2012 04:44:16 +0000 (23:44 -0500)]
Correctly handle NULLs in JSON output.

Error reported by David Wheeler.

12 years agoLast-minute release note updates.
Tom Lane [Thu, 23 Feb 2012 22:47:52 +0000 (17:47 -0500)]
Last-minute release note updates.

Security: CVE-2012-0866, CVE-2012-0867, CVE-2012-0868

12 years agoConvert newlines to spaces in names written in pg_dump comments.
Tom Lane [Thu, 23 Feb 2012 20:53:09 +0000 (15:53 -0500)]
Convert newlines to spaces in names written in pg_dump comments.

pg_dump was incautious about sanitizing object names that are emitted
within SQL comments in its output script.  A name containing a newline
would at least render the script syntactically incorrect.  Maliciously
crafted object names could present a SQL injection risk when the script
is reloaded.

Reported by Heikki Linnakangas, patch by Robert Haas

Security: CVE-2012-0868

12 years agoRemove arbitrary limitation on length of common name in SSL certificates.
Tom Lane [Thu, 23 Feb 2012 20:48:04 +0000 (15:48 -0500)]
Remove arbitrary limitation on length of common name in SSL certificates.

Both libpq and the backend would truncate a common name extracted from a
certificate at 32 bytes.  Replace that fixed-size buffer with dynamically
allocated string so that there is no hard limit.  While at it, remove the
code for extracting peer_dn, which we weren't using for anything; and
don't bother to store peer_cn longer than we need it in libpq.

This limit was not so terribly unreasonable when the code was written,
because we weren't using the result for anything critical, just logging it.
But now that there are options for checking the common name against the
server host name (in libpq) or using it as the user's name (in the server),
this could result in undesirable failures.  In the worst case it even seems
possible to spoof a server name or user name, if the correct name is
exactly 32 bytes and the attacker can persuade a trusted CA to issue a
certificate in which that string is a prefix of the certificate's common
name.  (To exploit this for a server name, he'd also have to send the
connection astray via phony DNS data or some such.)  The case that this is
a realistic security threat is a bit thin, but nonetheless we'll treat it
as one.

Back-patch to 8.4.  Older releases contain the faulty code, but it's not
a security problem because the common name wasn't used for anything
interesting.

Reported and patched by Heikki Linnakangas

Security: CVE-2012-0867

12 years agoRequire execute permission on the trigger function for CREATE TRIGGER.
Tom Lane [Thu, 23 Feb 2012 20:38:56 +0000 (15:38 -0500)]
Require execute permission on the trigger function for CREATE TRIGGER.

This check was overlooked when we added function execute permissions to the
system years ago.  For an ordinary trigger function it's not a big deal,
since trigger functions execute with the permissions of the table owner,
so they couldn't do anything the user issuing the CREATE TRIGGER couldn't
have done anyway.  However, if a trigger function is SECURITY DEFINER,
that is not the case.  The lack of checking would allow another user to
install it on his own table and then invoke it with, essentially, forged
input data; which the trigger function is unlikely to realize, so it might
do something undesirable, for instance insert false entries in an audit log
table.

Reported by Dinesh Kumar, patch by Robert Haas

Security: CVE-2012-0866

12 years agoAllow MinGW builds to use standardly-named OpenSSL libraries.
Tom Lane [Thu, 23 Feb 2012 20:05:08 +0000 (15:05 -0500)]
Allow MinGW builds to use standardly-named OpenSSL libraries.

In the Fedora variant of MinGW, the openssl libraries have their normal
names, not libeay32 and libssleay32.  Adjust configure probes to allow
that, per bug #6486.

Tomasz Ostrowski

12 years agoRemove inappropriate quotes
Peter Eisentraut [Thu, 23 Feb 2012 10:51:33 +0000 (12:51 +0200)]
Remove inappropriate quotes

And adjust wording for consistency.

12 years agoFix build without OpenSSL
Peter Eisentraut [Thu, 23 Feb 2012 08:20:25 +0000 (10:20 +0200)]
Fix build without OpenSSL

This is a fixup for commit a445cb92ef5b3a31313ebce30e18cc1d6e0bdecb.

12 years agoDon't install hstore--1.0.sql any more.
Robert Haas [Thu, 23 Feb 2012 01:37:13 +0000 (20:37 -0500)]
Don't install hstore--1.0.sql any more.

Since the current version is 1.1, the 1.0 file isn't really needed.  We do
need the 1.0--1.1 upgrade file, so people on 1.0 can upgrade.

Per recent discussion on pgsql-hackers.

12 years agoMake EXPLAIN (BUFFERS) track blocks dirtied, as well as those written.
Robert Haas [Thu, 23 Feb 2012 01:33:05 +0000 (20:33 -0500)]
Make EXPLAIN (BUFFERS) track blocks dirtied, as well as those written.

Also expose the new counters through pg_stat_statements.

Patch by me.  Review by Fujii Masao and Greg Smith.

12 years agoFix typo in comment.
Robert Haas [Thu, 23 Feb 2012 00:44:52 +0000 (19:44 -0500)]
Fix typo in comment.

Sandro Santilli

12 years agoImprove wording of pg_upgrade logfile option:
Bruce Momjian [Wed, 22 Feb 2012 23:40:19 +0000 (18:40 -0500)]
Improve wording of pg_upgrade logfile option:

  -l, --logfile=FILENAME        log internal activity to file\n\

12 years agoDraft release notes for 9.1.3, 9.0.7, 8.4.11, 8.3.18.
Tom Lane [Wed, 22 Feb 2012 23:11:46 +0000 (18:11 -0500)]
Draft release notes for 9.1.3, 9.0.7, 8.4.11, 8.3.18.

12 years agoAdd parameters for controlling locations of server-side SSL files
Peter Eisentraut [Wed, 22 Feb 2012 21:40:46 +0000 (23:40 +0200)]
Add parameters for controlling locations of server-side SSL files

This allows changing the location of the files that were previously
hard-coded to server.crt, server.key, root.crt, root.crl.

server.crt and server.key continue to be the default settings and are
thus required to be present by default if SSL is enabled.  But the
settings for the server-side CA and CRL are now empty by default, and
if they are set, the files are required to be present.  This replaces
the previous behavior of ignoring the functionality if the files were
not found.

12 years agoREASSIGN OWNED: Support foreign data wrappers and servers
Alvaro Herrera [Tue, 21 Feb 2012 20:58:02 +0000 (17:58 -0300)]
REASSIGN OWNED: Support foreign data wrappers and servers

This was overlooked when implementing those kinds of objects, in commit
cae565e503c42a0942ca1771665243b4453c5770.

Per report from Pawel Casperek.

12 years agoDon't clear btpo_cycleid during _bt_vacuum_one_page.
Tom Lane [Tue, 21 Feb 2012 20:03:36 +0000 (15:03 -0500)]
Don't clear btpo_cycleid during _bt_vacuum_one_page.

When "vacuuming" a single btree page by removing LP_DEAD tuples, we are not
actually within a vacuum operation, but rather in an ordinary insertion
process that could well be running concurrently with a vacuum.  So clearing
the cycleid is incorrect, and could cause the concurrent vacuum to miss
removing tuples that it needs to remove.  This is a longstanding bug
introduced by commit e6284649b9e30372b3990107a082bc7520325676 of
2006-07-25.  I believe it explains Maxim Boguk's recent report of index
corruption, and probably some other previously unexplained reports.

In 9.0 and up this is a one-line fix; before that we need to introduce a
flag to tell _bt_delitems what to do.

12 years agoCosmetic cleanup for commit a760893dbda9934e287789d54bbd3c4ca3914ce0.
Tom Lane [Tue, 21 Feb 2012 19:14:16 +0000 (14:14 -0500)]
Cosmetic cleanup for commit a760893dbda9934e287789d54bbd3c4ca3914ce0.

Mostly, fixing overlooked comments.

12 years agoAvoid double close of file handle in syslogger on win32
Magnus Hagander [Tue, 21 Feb 2012 16:12:25 +0000 (17:12 +0100)]
Avoid double close of file handle in syslogger on win32

This causes an exception when running under a debugger or in particular
when running on a debug version of Windows.

Patch from MauMau

12 years agoFix typo, noticed by Will Crawford.
Andrew Dunstan [Tue, 21 Feb 2012 16:03:51 +0000 (11:03 -0500)]
Fix typo, noticed by Will Crawford.

12 years agopg_regress: Add application name setting
Peter Eisentraut [Tue, 21 Feb 2012 14:45:19 +0000 (16:45 +0200)]
pg_regress: Add application name setting

Set the PGAPPNAME environment variable in pg_regress so that it
identifies itself as such instead of "psql".

12 years agoDon't reject threaded Python on FreeBSD.
Tom Lane [Mon, 20 Feb 2012 21:21:28 +0000 (16:21 -0500)]
Don't reject threaded Python on FreeBSD.

According to Chris Rees, this has worked for awhile, and the current
FreeBSD port is removing the test anyway.

12 years agoFix a couple of cases of JSON output.
Andrew Dunstan [Mon, 20 Feb 2012 20:01:03 +0000 (15:01 -0500)]
Fix a couple of cases of JSON output.

First, as noted by Itagaki Takahiro, a datum of type JSON doesn't
need to be escaped. Second, ensure that numeric output not in
the form of a legal JSON number is quoted and escaped.

12 years agoFix regex back-references that are directly quantified with *.
Tom Lane [Mon, 20 Feb 2012 05:52:33 +0000 (00:52 -0500)]
Fix regex back-references that are directly quantified with *.

The syntax "\n*", that is a backref with a * quantifier directly applied
to it, has never worked correctly in Spencer's library.  This has been an
open bug in the Tcl bug tracker since 2005:
https://sourceforge.net/tracker/index.php?func=detail&aid=1115587&group_id=10894&atid=110894

The core of the problem is in parseqatom(), which first changes "\n*" to
"\n+|" and then applies repeat() to the NFA representing the backref atom.
repeat() thinks that any arc leading into its "rp" argument is part of the
sub-NFA to be repeated.  Unfortunately, since parseqatom() already created
the arc that was intended to represent the empty bypass around "\n+", this
arc gets moved too, so that it now leads into the state loop created by
repeat().  Thus, what was supposed to be an "empty" bypass gets turned into
something that represents zero or more repetitions of the NFA representing
the backref atom.  In the original example, in place of
^([bc])\1*$
we now have something that acts like
^([bc])(\1+|[bc]*)$
At runtime, the branch involving the actual backref fails, as it's supposed
to, but then the other branch succeeds anyway.

We could no doubt fix this by some rearrangement of the operations in
parseqatom(), but that code is plenty ugly already, and what's more the
whole business of converting "x*" to "x+|" probably needs to go away to fix
another problem I'll mention in a moment.  Instead, this patch suppresses
the *-conversion when the target is a simple backref atom, leaving the case
of m == 0 to be handled at runtime.  This makes the patch in regcomp.c a
one-liner, at the cost of having to tweak cbrdissect() a little.  In the
event I went a bit further than that and rewrote cbrdissect() to check all
the string-length-related conditions before it starts comparing characters.
It seems a bit stupid to possibly iterate through many copies of an
n-character backreference, only to fail at the end because the target
string's length isn't a multiple of n --- we could have found that out
before starting.  The existing coding could only be a win if integer
division is hugely expensive compared to character comparison, but I don't
know of any modern machine where that might be true.

This does not fix all the problems with quantified back-references.  In
particular, the code is still broken for back-references that appear within
a larger expression that is quantified (so that direct insertion of the
quantification limits into the BACKREF node doesn't apply).  I think fixing
that will take some major surgery on the NFA code, specifically introducing
an explicit iteration node type instead of trying to transform iteration
into concatenation of modified regexps.

Back-patch to all supported branches.  In HEAD, also add a regression test
case for this.  (It may seem a bit silly to create a regression test file
for just one test case; but I'm expecting that we will soon import a whole
bunch of regex regression tests from Tcl, so might as well create the
infrastructure now.)

12 years agoAdd caching of ctype.h/wctype.h results in regc_locale.c.
Tom Lane [Mon, 20 Feb 2012 02:01:13 +0000 (21:01 -0500)]
Add caching of ctype.h/wctype.h results in regc_locale.c.

While this doesn't save a huge amount of runtime, it still seems worth
doing, especially since I realized that the data copying I did in my first
draft was quite unnecessary.  In this version, once we have the results
cached, getting them back for re-use is really very cheap.

Also, remove the hard-wired limitation to not consider wctype.h results for
character codes above 255.  It turns out that we can't push the limit as
far up as I'd originally hoped, because the regex colormap code is not
efficient enough to cope very well with character classes containing many
thousand letters, which a Unicode locale is entirely capable of producing.
Still, we can push it up to U+7FF (which I chose as the limit of 2-byte
UTF8 characters), which will at least make Eastern Europeans happy pending
a better solution.  Thus, this commit resolves the specific complaint in
bug #6457, but not the more general issue that letters of non-western
alphabets are mostly not recognized as matching [[:alpha:]].

12 years agoCreate the beginnings of internals documentation for the regex code.
Tom Lane [Sun, 19 Feb 2012 23:57:38 +0000 (18:57 -0500)]
Create the beginnings of internals documentation for the regex code.

Create src/backend/regex/README to hold an implementation overview of
the regex package, and fill it in with some preliminary notes about
the code's DFA/NFA processing and colormap management.  Much more to
do there of course.

Also, improve some code comments around the colormap and cvec code.
No functional changes except to add one missing assert.

12 years agoImprove pretty printing of viewdefs.
Andrew Dunstan [Sun, 19 Feb 2012 16:43:46 +0000 (11:43 -0500)]
Improve pretty printing of viewdefs.

Some line feeds are added to target lists and from lists to make
them more readable. By default they wrap at 80 columns if possible,
but the wrap column is also selectable - if 0 it wraps after every
item.

Andrew Dunstan, reviewed by Hitoshi Harada.

12 years agoIn ecpglib rewrote code that used strtok_r to not use library functions
Michael Meskes [Sun, 19 Feb 2012 13:50:14 +0000 (14:50 +0100)]
In ecpglib rewrote code that used strtok_r to not use library functions
anymore. This way we don't have to worry which compiler on which OS offers
which version of strtok.

12 years agoUpdate expected/collate.linux.utf8.out for recent plpgsql changes.
Tom Lane [Sat, 18 Feb 2012 23:08:02 +0000 (18:08 -0500)]
Update expected/collate.linux.utf8.out for recent plpgsql changes.

This file was missed in commit 4c6cedd1b014abf2046886a9a92e10e18f0d658e.

12 years agogcc on Windows does not know about strtok_s.
Michael Meskes [Sat, 18 Feb 2012 16:20:53 +0000 (17:20 +0100)]
gcc on Windows does not know about strtok_s.

12 years agoWindows doesn't have strtok_r, so let's use strtok_s instead.
Michael Meskes [Sat, 18 Feb 2012 14:56:39 +0000 (15:56 +0100)]
Windows doesn't have strtok_r, so let's use strtok_s instead.

12 years agoMake sure all connection paramters are used in call to PQconnectdbParams.
Michael Meskes [Fri, 17 Feb 2012 13:53:22 +0000 (14:53 +0100)]
Make sure all connection paramters are used in call to PQconnectdbParams.

12 years agoSync regex code with Tcl 8.5.11.
Tom Lane [Sat, 18 Feb 2012 00:44:26 +0000 (19:44 -0500)]
Sync regex code with Tcl 8.5.11.

Sync our regex code with upstream changes since last time we did this,
which was Tcl 8.5.0 (see commit df1e965e12cdd48c11057ee6e15346ee2b8b02f5).

There are no functional changes here; the main point is just to lay down
a commit-log marker that somebody has looked at this recently, and to do
what we can to keep the two codebases comparable.

12 years agoFix longstanding error in contrib/intarray's int[] & int[] operator.
Tom Lane [Fri, 17 Feb 2012 01:00:11 +0000 (20:00 -0500)]
Fix longstanding error in contrib/intarray's int[] & int[] operator.

The array intersection code would give wrong results if the first entry of
the correct output array would be "1".  (I think only this value could be
at risk, since the previous word would always be a lower-bound entry with
that fixed value.)

Problem spotted by Julien Rouhaud, initial patch by Guillaume Lelarge,
cosmetic improvements by me.

12 years agoImprove statistics estimation to make some use of DISTINCT in sub-queries.
Tom Lane [Thu, 16 Feb 2012 22:33:28 +0000 (17:33 -0500)]
Improve statistics estimation to make some use of DISTINCT in sub-queries.

Formerly, we just punted when trying to estimate stats for variables coming
out of sub-queries using DISTINCT, on the grounds that whatever stats we
might have for underlying table columns would be inapplicable.  But if the
sub-query has only one DISTINCT column, we can consider its output variable
as being unique, which is useful information all by itself.  The scope of
this improvement is pretty narrow, but it costs nearly nothing, so we might
as well do it.  Per discussion with Andres Freund.

This patch differs from the draft I submitted yesterday in updating various
comments about vardata.isunique (to reflect its extended meaning) and in
tweaking the interaction with security_barrier views.  There does not seem
to be a reason why we can't use this sort of knowledge even when the
sub-query is such a view.

12 years agopg_dump: Miscellaneous tightening based on recent refactorings.
Robert Haas [Thu, 16 Feb 2012 18:24:19 +0000 (13:24 -0500)]
pg_dump: Miscellaneous tightening based on recent refactorings.

Use exit_horribly() and ExecuteSqlQueryForSingleRow() in various
places where it's equivalent, or nearly equivalent, to the prior
coding. Apart from being more compact, this also makes the error
messages for the wrong-number-of-tuples case more consistent.

12 years agopg_dump: Remove global connection pointer.
Robert Haas [Thu, 16 Feb 2012 18:00:24 +0000 (13:00 -0500)]
pg_dump: Remove global connection pointer.

Parallel pg_dump wants to have multiple ArchiveHandle objects, and
therefore multiple PGconns, in play at the same time.  This should
be just about the end of the refactoring that we need in order to
make that workable.

12 years agoRefactor pg_dump.c to avoid duplicating returns-one-row check.
Robert Haas [Thu, 16 Feb 2012 17:07:06 +0000 (12:07 -0500)]
Refactor pg_dump.c to avoid duplicating returns-one-row check.

Any patches apt to get broken have probably already been broken by the
error-handling cleanups I just did, so we might as well clean this up
at the same time.

12 years agoInvent on_exit_nicely for pg_dump.
Robert Haas [Thu, 16 Feb 2012 16:49:20 +0000 (11:49 -0500)]
Invent on_exit_nicely for pg_dump.

Per recent discussions on pgsql-hackers regarding parallel pg_dump.

12 years agoRun a portal's cleanup hook immediately when pushing it to FAILED state.
Tom Lane [Wed, 15 Feb 2012 21:18:34 +0000 (16:18 -0500)]
Run a portal's cleanup hook immediately when pushing it to FAILED state.

This extends the changes of commit 6252c4f9e201f619e5eebda12fa867acd4e4200e
so that we run the cleanup hook earlier for failure cases as well as
success cases.  As before, the point is to avoid an assertion failure from
an Assert I added in commit a874fe7b4c890d1fe3455215a83ca777867beadd, which
was meant to check that no user-written code can be called during portal
cleanup.  This fixes a case reported by Pavan Deolasee in which the Assert
could be triggered during backend exit (see the new regression test case),
and also prevents the possibility that the cleanup hook is run after
portions of the portal's state have already been recycled.  That doesn't
really matter in current usage, but it foreseeably could matter in the
future.

Back-patch to 9.1 where the Assert in question was added.

12 years agoFix VPATH builds, broken by my recent commit to speed up tuplesorting.
Robert Haas [Wed, 15 Feb 2012 20:52:44 +0000 (15:52 -0500)]
Fix VPATH builds, broken by my recent commit to speed up tuplesorting.

The relevant commit is 337b6f5ecf05b21b5e997986884d097d60e4e3d0.

12 years agoHave pg_upgrade output 'link' or 'copy' when reporting its status.
Bruce Momjian [Wed, 15 Feb 2012 19:22:54 +0000 (14:22 -0500)]
Have pg_upgrade output 'link' or 'copy' when reporting its status.

Idea from Peter.

12 years agosepgsql: Move some code from hooks.c to label.c
Robert Haas [Wed, 15 Feb 2012 18:54:26 +0000 (13:54 -0500)]
sepgsql: Move some code from hooks.c to label.c

This is some preliminary refactoring related to a pending patch
to allow sepgsql-enable sessions to make dynamic label transitions.
But this commit doesn't involve any functional change: it just puts
some bits of code in more logical places.

KaiGai Kohei

12 years agoSpeed up in-memory tuplesorting.
Robert Haas [Wed, 15 Feb 2012 17:13:32 +0000 (12:13 -0500)]
Speed up in-memory tuplesorting.

Per recent work by Peter Geoghegan, it's significantly faster to
tuplesort on a single sortkey if ApplySortComparator is inlined into
quicksort rather reached via a function pointer.  It's also faster
in general to have a version of quicksort which is specialized for
sorting SortTuple objects rather than objects of arbitrary size and
type.  This requires a couple of additional copies of the quicksort
logic, which in this patch are generate using a Perl script.  There
might be some benefit in adding further specializations here too,
but thus far it's not clear that those gains are worth their weight
in code footprint.

12 years agoMore regression tests for LEAKPROOF/NOT LEAKPROOF stuff.
Robert Haas [Wed, 15 Feb 2012 15:56:26 +0000 (10:56 -0500)]
More regression tests for LEAKPROOF/NOT LEAKPROOF stuff.

Along the way, move create_function_3 into a parallel schedule.

KaiGai Kohei

12 years agoMake CREATE/ALTER FUNCTION support NOT LEAKPROOF.
Robert Haas [Wed, 15 Feb 2012 15:45:08 +0000 (10:45 -0500)]
Make CREATE/ALTER FUNCTION support NOT LEAKPROOF.

Because it isn't good to be able to turn things on, and not off again.

12 years agosepgsql: Reword and fix typo in docs on DML permissions.
Robert Haas [Wed, 15 Feb 2012 14:57:56 +0000 (09:57 -0500)]
sepgsql: Reword and fix typo in docs on DML permissions.

Per report from Christoph Berg.

12 years agoFix pg_test_fsync Win32 problems reported by the build farm; add
Bruce Momjian [Wed, 15 Feb 2012 12:10:48 +0000 (07:10 -0500)]
Fix pg_test_fsync Win32 problems reported by the build farm;  add
comments about the alarm method used on Win32.

12 years agoTry to get pg_test_thread to compile on Windows by using a sleeper
Bruce Momjian [Wed, 15 Feb 2012 02:53:17 +0000 (21:53 -0500)]
Try to get pg_test_thread to compile on Windows by using a sleeper
thread.

12 years agoImprove fsync documentation by stating that -W _0_ turns of write
Bruce Momjian [Tue, 14 Feb 2012 22:41:57 +0000 (17:41 -0500)]
Improve fsync documentation by stating that -W _0_ turns of write
caching.

12 years agoPreserve column names in the execution-time tupledesc for a RowExpr.
Tom Lane [Tue, 14 Feb 2012 22:34:19 +0000 (17:34 -0500)]
Preserve column names in the execution-time tupledesc for a RowExpr.

The hstore and json datatypes both have record-conversion functions that
pay attention to column names in the composite values they're handed.
We used to not worry about inserting correct field names into tuple
descriptors generated at runtime, but given these examples it seems
useful to do so.  Observe the nicer-looking results in the regression
tests whose results changed.

catversion bump because there is a subtle change in requirements for stored
rule parsetrees: RowExprs from ROW() constructs now have to include field
names.

Andrew Dunstan and Tom Lane

12 years agoDocument random page cost is only 4x seqeuntial, and not 40x.
Bruce Momjian [Tue, 14 Feb 2012 21:54:54 +0000 (16:54 -0500)]
Document random page cost is only 4x seqeuntial, and not 40x.