]> granicus.if.org Git - postgresql/log
postgresql
11 years agoSilence compiler warning in assertion-enabled builds.
Heikki Linnakangas [Tue, 2 Jul 2013 14:23:42 +0000 (17:23 +0300)]
Silence compiler warning in assertion-enabled builds.

With -Wtype-limits, gcc correctly points out that size_t can never be < 0.
Backpatch to 9.3 and 9.2. It's been like this forever, but in <= 9.1 you got
a lot other warnings with -Wtype-limits anyway (at least with my version of
gcc).

Andres Freund

11 years agoMark index-constraint comments with correct dependency in pg_dump.
Tom Lane [Thu, 27 Jun 2013 17:54:59 +0000 (13:54 -0400)]
Mark index-constraint comments with correct dependency in pg_dump.

When there's a comment on an index that was created with UNIQUE or PRIMARY
KEY constraint syntax, we need to label the comment as depending on the
constraint not the index, since only the constraint object actually appears
in the dump.  This incorrect dependency can lead to parallel pg_restore
trying to restore the comment before the index has been created, per bug
#8257 from Lloyd Albin.

This patch fixes pg_dump to produce the right dependency in dumps made
in the future.  Usually we also try to hack pg_restore to work around
bogus dependencies, so that existing (wrong) dumps can still be restored in
parallel mode; but that doesn't seem practical here since there's no easy
way to relate the constraint dump entry to the comment after the fact.

Andres Freund

11 years agoExpect EWOULDBLOCK from a non-blocking connect() call only on Windows.
Tom Lane [Thu, 27 Jun 2013 16:36:44 +0000 (12:36 -0400)]
Expect EWOULDBLOCK from a non-blocking connect() call only on Windows.

On Unix-ish platforms, EWOULDBLOCK may be the same as EAGAIN, which is
*not* a success return, at least not on Linux.  We need to treat it as a
failure to avoid giving a misleading error message.  Per the Single Unix
Spec, only EINPROGRESS and EINTR returns indicate that the connection
attempt is in progress.

On Windows, on the other hand, EWOULDBLOCK (WSAEWOULDBLOCK) is the expected
case.  We must accept EINPROGRESS as well because Cygwin will return that,
and it doesn't seem worth distinguishing Cygwin from native Windows here.
It's not very clear whether EINTR can occur on Windows, but let's leave
that part of the logic alone in the absence of concrete trouble reports.

Also, remove the test for errno == 0, effectively reverting commit
da9501bddb42222dc33c031b1db6ce2133bcee7b, which AFAICS was just a thinko;
or at best it might have been a workaround for a platform-specific bug,
which we can hope is gone now thirteen years later.  In any case, since
libpq makes no effort to reset errno to zero before calling connect(),
it seems unlikely that that test has ever reliably done anything useful.

Andres Freund and Tom Lane

11 years agoTweak wording in sequence-function docs to avoid PDF build failures.
Tom Lane [Thu, 27 Jun 2013 04:23:37 +0000 (00:23 -0400)]
Tweak wording in sequence-function docs to avoid PDF build failures.

Adjust the wording in the first para of "Sequence Manipulation Functions"
so that neither of the link phrases in it break across line boundaries,
in either A4- or US-page-size PDF output.  This fixes a reported build
failure for the 9.3beta2 A4 PDF docs, and future-proofs this particular
para against causing similar problems in future.  (Perhaps somebody will
fix this issue in the SGML/TeX documentation tool chain someday, but I'm
not holding my breath.)

Back-patch to all supported branches, since the same problem could rise up
to bite us in future updates if anyone changes anything earlier than this
in func.sgml.

11 years agoDocument effect of constant folding on CASE.
Noah Misch [Wed, 26 Jun 2013 23:51:56 +0000 (19:51 -0400)]
Document effect of constant folding on CASE.

Back-patch to all supported versions.

Laurenz Albe

11 years agoProperly dump dropped foreign table cols in binary-upgrade mode.
Andrew Dunstan [Tue, 25 Jun 2013 17:45:03 +0000 (13:45 -0400)]
Properly dump dropped foreign table cols in binary-upgrade mode.

In binary upgrade mode, we need to recreate and then drop dropped
columns so that all the columns get the right attribute number. This is
true for foreign tables as well as for native tables. For foreign
tables we have been getting the first part right but not the second,
leading to bogus columns in the upgraded database. Fix this all the way
back to 9.1, where foreign tables were introduced.

11 years agoSupport clean switchover.
Fujii Masao [Tue, 25 Jun 2013 17:19:26 +0000 (02:19 +0900)]
Support clean switchover.

In replication, when we shutdown the master, walsender tries to send
all the outstanding WAL records to the standby, and then to exit. This
basically means that all the WAL records are fully synced between
two servers after the clean shutdown of the master. So, after
promoting the standby to new master, we can restart the stopped
master as new standby without the need for a fresh backup from
new master.

But there was one problem so far: though walsender tries to send all
the outstanding WAL records, it doesn't wait for them to be replicated
to the standby. Then, before receiving all the WAL records,
walreceiver can detect the closure of connection and exit. We cannot
guarantee that there is no missing WAL in the standby after clean
shutdown of the master. In this case, backup from new master is
required when restarting the stopped master as new standby.

This patch fixes this problem. It just changes walsender so that it
waits for all the outstanding WAL records to be replicated to the
standby before closing the replication connection.

Per discussion, this is a fix that needs to get backpatched rather than
new feature. So, back-patch to 9.1 where enough infrastructure for
this exists.

Patch by me, reviewed by Andres Freund.

11 years agoEnsure no xid gaps during Hot Standby startup
Simon Riggs [Sun, 23 Jun 2013 10:05:02 +0000 (11:05 +0100)]
Ensure no xid gaps during Hot Standby startup

In some cases with higher numbers of subtransactions
it was possible for us to incorrectly initialize
subtrans leading to complaints of missing pages.

Bug report by Sergey Konoplev
Analysis and fix by Andres Freund

11 years agoFurther update CREATE FUNCTION documentation about argument names
Peter Eisentraut [Thu, 20 Jun 2013 02:25:13 +0000 (22:25 -0400)]
Further update CREATE FUNCTION documentation about argument names

More languages than SQL and PL/pgSQL actually support parameter names.

11 years agoFix the create_index regression test for Danish collation.
Kevin Grittner [Wed, 19 Jun 2013 15:37:57 +0000 (10:37 -0500)]
Fix the create_index regression test for Danish collation.

In Danish collations, there are letter combinations which sort
higher than 'Z'.  A test for values > 'WA' was picking up rows
where the value started with 'AA', causing the test to fail.

Backpatch to 9.2, where the failing test was added.

Per report from Svenne Krap and analysis by Jeff Janes

11 years agoFix docs on lock level for ALTER TABLE VALIDATE
Simon Riggs [Tue, 18 Jun 2013 11:00:32 +0000 (12:00 +0100)]
Fix docs on lock level for ALTER TABLE VALIDATE

ALTER TABLE .. VALIDATE CONSTRAINT previously
gave incorrect details about lock levels and
therefore incomplete reasons to use the option.

Initial bug report and fix from Marko Tiikkaja
Reworded by me to include comments by Kevin Grittner

11 years agoFix pg_restore -l with the directory archive to display the correct format name.
Fujii Masao [Sat, 15 Jun 2013 20:13:58 +0000 (05:13 +0900)]
Fix pg_restore -l with the directory archive to display the correct format name.

Back-patch to 9.1 where the directory archive was introduced.

11 years agoAvoid deadlocks during insertion into SP-GiST indexes.
Tom Lane [Fri, 14 Jun 2013 18:26:50 +0000 (14:26 -0400)]
Avoid deadlocks during insertion into SP-GiST indexes.

SP-GiST's original scheme for avoiding deadlocks during concurrent index
insertions doesn't work, as per report from Hailong Li, and there isn't any
evident way to make it work completely.  We could possibly lock individual
inner tuples instead of their whole pages, but preliminary experimentation
suggests that the performance penalty would be huge.  Instead, if we fail
to get a buffer lock while descending the tree, just restart the tree
descent altogether.  We keep the old tuple positioning rules, though, in
hopes of reducing the number of cases where this can happen.

Teodor Sigaev, somewhat edited by Tom Lane

11 years agoOnly install a portal's ResourceOwner if it actually has one.
Tom Lane [Thu, 13 Jun 2013 17:11:35 +0000 (13:11 -0400)]
Only install a portal's ResourceOwner if it actually has one.

In most scenarios a portal without a ResourceOwner is dead and not subject
to any further execution, but a portal for a cursor WITH HOLD remains in
existence with no ResourceOwner after the creating transaction is over.
In this situation, if we attempt to "execute" the portal directly to fetch
data from it, we were setting CurrentResourceOwner to NULL, leading to a
segfault if the datatype output code did anything that required a resource
owner (such as trying to fetch system catalog entries that weren't already
cached).  The case appears to be impossible to provoke with stock libpq,
but psqlODBC at least is able to cause it when working with held cursors.

Simplest fix is to just skip the assignment to CurrentResourceOwner, so
that any resources used by the data output operations will be managed by
the transaction-level resource owner instead.  For consistency I changed
all the places that install a portal's resowner as current, even though
some of them are probably not reachable with a held cursor's portal.

Per report from Joshua Berry (with thanks to Hiroshi Inoue for developing
a self-contained test case).  Back-patch to all supported versions.

11 years agoImprove description of loread/lowrite.
Robert Haas [Wed, 12 Jun 2013 16:20:59 +0000 (12:20 -0400)]
Improve description of loread/lowrite.

Patch by me, reviewed by Tatsuo Ishii.

11 years agoFix cache flush hazard in cache_record_field_properties().
Tom Lane [Tue, 11 Jun 2013 21:26:48 +0000 (17:26 -0400)]
Fix cache flush hazard in cache_record_field_properties().

We need to increment the refcount on the composite type's cached tuple
descriptor while we do lookups of its column types.  Otherwise a cache
flush could occur and release the tuple descriptor before we're done with
it.  This fails reliably with -DCLOBBER_CACHE_ALWAYS, but the odds of a
failure in a production build seem rather low (since the pfree'd descriptor
typically wouldn't get scribbled on immediately).  That may explain the
lack of any previous reports.  Buildfarm issue noted by Christian Ullrich.

Back-patch to 9.1 where the bogus code was added.

11 years agoAdd description that loread()/lowrite() are corresponding to
Tatsuo Ishii [Tue, 11 Jun 2013 05:25:58 +0000 (14:25 +0900)]
Add description that loread()/lowrite() are corresponding to
lo_read()/lo_write() in libpq to avoid confusion.

11 years agoFix ordering of obj id for Rules and EventTriggers in pg_dump.
Joe Conway [Mon, 10 Jun 2013 00:31:26 +0000 (17:31 -0700)]
Fix ordering of obj id for Rules and EventTriggers in pg_dump.

getSchemaData() must identify extension member objects and mark them
as not to be dumped. This must happen after reading all objects that can be
direct members of extensions, but before we begin to process table subsidiary
objects. Both rules and event triggers were wrong in this regard.

Backport rules portion of patch to 9.1 -- event triggers do not exist prior to 9.3.
Suggested fix by Tom Lane, initial complaint and patch by me.

11 years agoRemove unnecessary restrictions about RowExprs in transformAExprIn().
Tom Lane [Sun, 9 Jun 2013 22:39:27 +0000 (18:39 -0400)]
Remove unnecessary restrictions about RowExprs in transformAExprIn().

When the existing code here was written, it made sense to special-case
RowExprs because that was the only way that we could handle row comparisons
at all.  Now that we have record_eq() and arrays of composites, the generic
logic for "scalar" types will in fact work on RowExprs too, so there's no
reason to throw error for combinations of RowExprs and other ways of
forming composite values, nor to ignore the possibility of using a
ScalarArrayOpExpr.  But keep using the old logic when comparing two
RowExprs, for consistency with the main transformAExprOp() logic.  (This
allows some cases with not-quite-identical rowtypes to succeed, so we might
get push-back if we removed it.)  Per bug #8198 from Rafal Rzepecki.

Back-patch to all supported branches, since this works fine as far back as
8.4.

Rafal Rzepecki and Tom Lane

11 years agoRemove ALTER DEFAULT PRIVILEGES' requirement of schema CREATE permissions.
Tom Lane [Sun, 9 Jun 2013 19:26:48 +0000 (15:26 -0400)]
Remove ALTER DEFAULT PRIVILEGES' requirement of schema CREATE permissions.

Per discussion, this restriction isn't needed for any real security reason,
and it seems to confuse people more often than it helps them.  It could
also result in some database states being unrestorable.  So just drop it.

Back-patch to 9.0, where ALTER DEFAULT PRIVILEGES was introduced.

11 years agoRemove fixed limit on the number of concurrent AllocateFile() requests.
Tom Lane [Sun, 9 Jun 2013 17:47:00 +0000 (13:47 -0400)]
Remove fixed limit on the number of concurrent AllocateFile() requests.

AllocateFile(), AllocateDir(), and some sister routines share a small array
for remembering requests, so that the files can be closed on transaction
failure.  Previously that array had a fixed size, MAX_ALLOCATED_DESCS (32).
While historically that had seemed sufficient, Steve Toutant pointed out
that this meant you couldn't scan more than 32 file_fdw foreign tables in
one query, because file_fdw depends on the COPY code which uses
AllocateFile().  There are probably other cases, or will be in the future,
where this nonconfigurable limit impedes users.

We can't completely remove any such limit, at least not without a lot of
work, since each such request requires a kernel file descriptor and most
platforms limit the number we can have.  (In principle we could
"virtualize" these descriptors, as fd.c already does for the main VFD pool,
but not without an additional layer of overhead and a lot of notational
impact on the calling code.)  But we can at least let the array size be
configurable.  Hence, change the code to allow up to max_safe_fds/2
allocated file requests.  On modern platforms this should allow several
hundred concurrent file_fdw scans, or more if one increases the value of
max_files_per_process.  To go much further than that, we'd need to do some
more work on the data structure, since the current code for closing
requests has potentially O(N^2) runtime; but it should still be all right
for request counts in this range.

Back-patch to 9.1 where contrib/file_fdw was introduced.

11 years agoDon't downcase non-ascii identifier chars in multi-byte encodings.
Andrew Dunstan [Sat, 8 Jun 2013 14:21:06 +0000 (10:21 -0400)]
Don't downcase non-ascii identifier chars in multi-byte encodings.

Long-standing code has called tolower() on identifier character bytes
with the high bit set. This is clearly an error and produces junk output
when the encoding is multi-byte. This patch therefore restricts this
activity to cases where there is a character with the high bit set AND
the encoding is single-byte.

There have been numerous gripes about this, most recently from Martin
Schäfer.

Backpatch to all live releases.

11 years agoCorrect the documentation of pg_rewrite.ev_attr.
Kevin Grittner [Fri, 7 Jun 2013 14:23:01 +0000 (09:23 -0500)]
Correct the documentation of pg_rewrite.ev_attr.

It claimed the value was always zero; it is really always -1.

Per report from Hari Babu

backpatch 734fbbd1d2d1babfbd195414e2445024ad549ae3 to 8.4

11 years agoMinor docs wordsmithing.
Tom Lane [Fri, 7 Jun 2013 04:08:02 +0000 (00:08 -0400)]
Minor docs wordsmithing.

Swap the order of a couple of phrases to clarify what the adjective
"subsequent" applies to.

Joshua Tolley

11 years agoFix typo in comment.
Heikki Linnakangas [Thu, 6 Jun 2013 15:25:26 +0000 (18:25 +0300)]
Fix typo in comment.

11 years agoEnsure that XLOG_HEAP2_VISIBLE always targets an initialized page.
Robert Haas [Thu, 6 Jun 2013 14:15:45 +0000 (10:15 -0400)]
Ensure that XLOG_HEAP2_VISIBLE always targets an initialized page.

Andres Freund

11 years agoBackport log_newpage_buffer.
Robert Haas [Thu, 6 Jun 2013 14:14:46 +0000 (10:14 -0400)]
Backport log_newpage_buffer.

Andres' fix for XLOG_HEAP2_VISIBLE on unitialized pages requires
this.

11 years agopg_upgrade: document that --link should be used with --check
Bruce Momjian [Thu, 6 Jun 2013 14:13:54 +0000 (10:13 -0400)]
pg_upgrade:  document that --link should be used with --check
Backpatch to 9.2.

11 years agoPrevent pushing down WHERE clauses into unsafe UNION/INTERSECT nests.
Tom Lane [Thu, 6 Jun 2013 03:44:08 +0000 (23:44 -0400)]
Prevent pushing down WHERE clauses into unsafe UNION/INTERSECT nests.

The planner is aware that it mustn't push down upper-level quals into
subqueries if the quals reference subquery output columns that contain
set-returning functions or volatile functions, or are non-DISTINCT outputs
of a DISTINCT ON subquery.  However, it missed making this check when
there were one or more levels of UNION or INTERSECT above the dangerous
expression.  This could lead to "set-valued function called in context that
cannot accept a set" errors, as seen in bug #8213 from Eric Soroos, or to
silently wrong answers in the other cases.

To fix, refactor the checks so that we make the column-is-unsafe checks
during subquery_is_pushdown_safe(), which already has to recursively
inspect all arms of a set-operation tree.  This makes
qual_is_pushdown_safe() considerably simpler, at the cost that we will
spend some cycles checking output columns that possibly aren't referenced
in any upper qual.  But the cases where this code gets executed at all
are already nontrivial queries, so it's unlikely anybody will notice any
slowdown of planning.

This has been broken since commit 05f916e6add9726bf4ee046e4060c1b03c9961f2,
which makes the bug over ten years old.  A bit surprising nobody noticed it
before now.

11 years agoPut analyze_keyword back in explain_option_name production.
Tom Lane [Wed, 5 Jun 2013 17:32:53 +0000 (13:32 -0400)]
Put analyze_keyword back in explain_option_name production.

In commit 2c92edad48796119c83d7dbe6c33425d1924626d, I broke "EXPLAIN
(ANALYZE)" syntax, because I mistakenly thought that ANALYZE/ANALYSE were
only partially reserved and thus would be included in NonReservedWord;
but actually they're fully reserved so they still need to be called out
here.

A nicer solution would be to demote these words to type_func_name_keyword
status (they can't be less than that because of "VACUUM [ANALYZE] ColId").
While that works fine so far as the core grammar is concerned, it breaks
ECPG's grammar for reasons I don't have time to isolate at the moment.
So do this for the time being.

Per report from Kevin Grittner.  Back-patch to 9.0, like the previous
commit.

11 years agodoc: Add IDs to link targets used by phpPgAdmin
Peter Eisentraut [Wed, 8 May 2013 01:23:21 +0000 (21:23 -0400)]
doc: Add IDs to link targets used by phpPgAdmin

Karl O. Pinc

11 years agoProvide better message when CREATE EXTENSION can't find a target schema.
Tom Lane [Tue, 4 Jun 2013 21:22:29 +0000 (17:22 -0400)]
Provide better message when CREATE EXTENSION can't find a target schema.

The new message (and SQLSTATE) matches the corresponding error cases in
namespace.c.

This was thought to be a "can't happen" case when extension.c was written,
so we didn't think hard about how to report it.  But it definitely can
happen in 9.2 and later, since we no longer require search_path to contain
any valid schema names.  It's probably also possible in 9.1 if search_path
came from a noninteractive source.  So, back-patch to all releases
containing this code.

Per report from Sean Chittenden, though this isn't exactly his patch.

11 years agoAdd ARM64 (aarch64) support to s_lock.h.
Tom Lane [Tue, 4 Jun 2013 19:42:02 +0000 (15:42 -0400)]
Add ARM64 (aarch64) support to s_lock.h.

Use the same gcc atomic functions as we do on newer ARM chips.
(Basically this is a copy and paste of the __arm__ code block,
but omitting the SWPB option since that definitely won't work.)

Back-patch to 9.2.  The patch would work further back, but we'd also
need to update config.guess/config.sub in older branches to make them
build out-of-the-box, and there hasn't been demand for it.

Mark Salter

11 years agoFix memory leak in LogStandbySnapshot().
Tom Lane [Tue, 4 Jun 2013 18:58:52 +0000 (14:58 -0400)]
Fix memory leak in LogStandbySnapshot().

The array allocated by GetRunningTransactionLocks() needs to be pfree'd
when we're done with it.  Otherwise we leak some memory during each
checkpoint, if wal_level = hot_standby.  This manifests as memory bloat
in the checkpointer process, or in bgwriter in versions before we made
the checkpointer separate.

Reported and fixed by Naoya Anzai.  Back-patch to 9.0 where the issue
was introduced.

In passing, improve comments for GetRunningTransactionLocks(), and add
an Assert that we didn't overrun the palloc'd array.

11 years agoAdd semicolons to eval'd strings to hide a minor Perl behavioral change.
Tom Lane [Mon, 3 Jun 2013 18:19:32 +0000 (14:19 -0400)]
Add semicolons to eval'd strings to hide a minor Perl behavioral change.

"eval q{foo}" used to complain that the error was on line 2 of the eval'd
string, because eval internally tacked on "\n;" so that the end of the
erroneous command was indeed on line 2.  But as of Perl 5.18 it more
sanely says that the error is on line 1.  To avoid Perl-version-dependent
regression test results, use "eval q{foo;}" instead in the two places
where this matters.  Per buildfarm.

Since people might try to use newer Perl versions with older PG releases,
back-patch as far as 9.0 where these test cases were added.

11 years agoAllow type_func_name_keywords in some places where they weren't before.
Tom Lane [Mon, 3 Jun 2013 00:09:26 +0000 (20:09 -0400)]
Allow type_func_name_keywords in some places where they weren't before.

This change makes type_func_name_keywords less reserved than they were
before, by allowing them for role names, language names, EXPLAIN and COPY
options, and SET values for GUCs; which are all places where few if any
actual keywords could appear instead, so no new ambiguities are introduced.

The main driver for this change is to allow "COPY ... (FORMAT BINARY)"
to work without quoting the word "binary".  That is an inconsistency that
has been complained of repeatedly over the years (at least by Pavel Golub,
Kurt Lidl, and Simon Riggs); but we hadn't thought of any non-ugly solution
until now.

Back-patch to 9.0 where the COPY (FORMAT BINARY) syntax was introduced.

11 years agoDocument auto_explain.log_timing.
Robert Haas [Wed, 29 May 2013 11:11:21 +0000 (07:11 -0400)]
Document auto_explain.log_timing.

Tomas Vondra

11 years agoDocumentation fix for ALTER TYPE .. RENAME
Stephen Frost [Mon, 27 May 2013 15:12:54 +0000 (11:12 -0400)]
Documentation fix for ALTER TYPE .. RENAME

The documentation for ALTER TYPE .. RENAME claimed to support a
RESTRICT/CASCADE option at the 'type' level, which wasn't implemented
and doesn't make a whole lot of sense to begin with.  What is supported,
and previously undocumented, is

ALTER TYPE .. RENAME ATTRIBUTE .. RESTRICT/CASCADE.

I've updated the documentation and back-patched this to 9.1 where it was
first introduced.

11 years agoFix typo in comment.
Robert Haas [Thu, 23 May 2013 15:34:30 +0000 (11:34 -0400)]
Fix typo in comment.

Pavan Deolasee

11 years agoPrint line number correctly in COPY.
Heikki Linnakangas [Thu, 23 May 2013 11:49:59 +0000 (07:49 -0400)]
Print line number correctly in COPY.

When COPY uses the multi-insert method to insert a batch of tuples into the
heap at a time, incorrect line number was printed if something went wrong in
inserting the index tuples (primary key failure, for exampl), or processing
after row triggers.

Fixes bug #8173 reported by Lloyd Albin. Backpatch to 9.2, where the multi-
insert code was added.

11 years agoFix fd.c to preserve errno where needed.
Tom Lane [Thu, 16 May 2013 19:04:38 +0000 (15:04 -0400)]
Fix fd.c to preserve errno where needed.

PathNameOpenFile failed to ensure that the correct value of errno was
returned to its caller after a failure (because it incorrectly supposed
that free() can never change errno).  In some cases this would result
in a user-visible failure because an expected ENOENT errno was replaced
with something else.  Bogus EINVAL failures have been observed on OS X,
for example.

There were also a couple of places that could mangle an important value
of errno if FDDEBUG was defined.  While the usefulness of that debug
support is highly debatable, we might as well make it safe to use,
so add errno save/restore logic to the DO_DB macro.

Per bug #8167 from Nelson Minar, diagnosed by RhodiumToad.
Back-patch to all supported branches.

11 years agoFix handling of OID wraparound while in standalone mode.
Tom Lane [Mon, 13 May 2013 19:40:16 +0000 (15:40 -0400)]
Fix handling of OID wraparound while in standalone mode.

If OID wraparound should occur while in standalone mode (unlikely but
possible), we want to advance the counter to FirstNormalObjectId not
FirstBootstrapObjectId.  Otherwise, user objects might be created with OIDs
in the system-reserved range.  That isn't immediately harmful but it poses
a risk of conflicts during future pg_upgrade operations.

Noted by Andres Freund.  Back-patch to all supported branches, since all of
them are supported sources for pg_upgrade operations.

11 years agoUpdate CREATE FUNCTION documentation about argument names.
Tom Lane [Sat, 11 May 2013 16:07:47 +0000 (12:07 -0400)]
Update CREATE FUNCTION documentation about argument names.

The 9.2 patch that added argument name support in SQL-language functions
missed updating a parenthetical comment about that in the CREATE FUNCTION
reference page.  Noted by Erwin Brandstetter.

11 years agoGuard against input_rows == 0 in estimate_num_groups().
Tom Lane [Fri, 10 May 2013 21:15:35 +0000 (17:15 -0400)]
Guard against input_rows == 0 in estimate_num_groups().

This case doesn't normally happen, because the planner usually clamps
all row estimates to at least one row; but I found that it can arise
when dealing with relations excluded by constraints.  Without a defense,
estimate_num_groups() can return zero, which leads to divisions by zero
inside the planner as well as assertion failures in the executor.

An alternative fix would be to change set_dummy_rel_pathlist() to make
the size estimate for a dummy relation 1 row instead of 0, but that seemed
pretty ugly; and probably someday we'll want to drop the convention that
the minimum rowcount estimate is 1 row.

Back-patch to 8.4, as the problem can be demonstrated that far back.

11 years agoFix pgp_pub_decrypt() so it works for secret keys with passwords.
Tom Lane [Fri, 10 May 2013 17:06:52 +0000 (13:06 -0400)]
Fix pgp_pub_decrypt() so it works for secret keys with passwords.

Per report from Keith Fiske.

Marko Kreen

11 years agoFix management of fn_extra caching during repeated GiST index scans.
Tom Lane [Fri, 10 May 2013 03:08:25 +0000 (23:08 -0400)]
Fix management of fn_extra caching during repeated GiST index scans.

Commit d22a09dc70f9830fa78c1cd1a3a453e4e473d354 introduced official support
for GiST consistentFns that want to cache data using the FmgrInfo fn_extra
pointer: the idea was to preserve the cached values across gistrescan(),
whereas formerly they'd been leaked.  However, there was an oversight in
that, namely that multiple scan keys might reference the same column's
consistentFn; the code would result in propagating the same cache value
into multiple scan keys, resulting in crashes or wrong answers.  Use a
separate array instead to ensure that each scan key keeps its own state.

Per bug #8143 from Joel Roller.  Back-patch to 9.2 where the bug was
introduced.

11 years agoUse pg_dump's --quote-all-identifiers option in pg_upgrade.
Tom Lane [Thu, 9 May 2013 21:34:40 +0000 (17:34 -0400)]
Use pg_dump's --quote-all-identifiers option in pg_upgrade.

This helps guard against changes in the set of reserved keywords from
one version to another.  In theory it should only be an issue if we
de-reserve a keyword in a newer release, since that can create the type
of problem shown in bug #8128.

Back-patch to 9.1 where the --quote-all-identifiers option was added.

11 years agoRevert "Fix permission tests for views/tables proven empty by constraint exclusion."
Tom Lane [Wed, 8 May 2013 21:01:19 +0000 (17:01 -0400)]
Revert "Fix permission tests for views/tables proven empty by constraint exclusion."

This reverts commit 15b0421002624919c62ae3c6574af2a8452bf6c4.  Per
complaint from Robert Haas, that patch caused crashes on appendrel
cases, and it didn't fix all forms of the problem anyway.  Consensus
is we'll leave this problem alone in the back branches, at least
for now.

11 years agodocs: log_line_prefix session id fix
Bruce Momjian [Sat, 4 May 2013 17:15:54 +0000 (13:15 -0400)]
docs:  log_line_prefix session id fix

Restore 4-byte designation for docs.  Fix 9.3 doc query to properly pad
to four digits.

Backpatch to all active branches

Per suggestions from Ian Lawrence Barwick

11 years agodocs: fix log_line_prefix session id docs
Bruce Momjian [Sat, 4 May 2013 15:05:16 +0000 (11:05 -0400)]
docs:  fix log_line_prefix session id docs

Backpatch to 9.2.

Report from Ian Lawrence Barwick

11 years agoFix thinko in comment.
Heikki Linnakangas [Thu, 2 May 2013 15:08:43 +0000 (18:08 +0300)]
Fix thinko in comment.

WAL segment means a 16 MB physical WAL file; this comment meant a logical
4 GB log file.

Amit Langote. Apply to backbranches only, as the comment is gone in master.

11 years agoFix permission tests for views/tables proven empty by constraint exclusion.
Tom Lane [Wed, 1 May 2013 22:26:58 +0000 (18:26 -0400)]
Fix permission tests for views/tables proven empty by constraint exclusion.

A view defined as "select <something> where false" had the curious property
that the system wouldn't check whether users had the privileges necessary
to select from it.  More generally, permissions checks could be skipped
for tables referenced in sub-selects or views that were proven empty by
constraint exclusion (although some quick testing suggests this seldom
happens in cases of practical interest).  This happened because the planner
failed to include rangetable entries for such tables in the finished plan.

This was noticed in connection with erroneous handling of materialized
views, but actually the issue is quite unrelated to matviews.  Therefore,
revert commit 200ba1667b3a8d7a9d559d2f05f83d209c9d8267 in favor of a more
direct test for the real problem.

Back-patch to 9.2 where the bug was introduced (by commit
7741dd6590073719688891898e85f0cb73453159).

11 years agoInstall recycled WAL segments with current timeline ID during recovery.
Heikki Linnakangas [Tue, 30 Apr 2013 13:31:21 +0000 (16:31 +0300)]
Install recycled WAL segments with current timeline ID during recovery.

This is a follow-up to the earlier fix, which changed the recycling logic
to recycle WAL segments under the current recovery target timeline. That
turns out to be a bad idea, because installing a recycled segment with
a TLI higher than what we're recovering at the moment means that the recovery
logic will find the recycled WAL segment and try to replay it. It will fail,
but but the mere presence of such a WAL segment will mask any other, real,
file with the same log/seg, but smaller TLI.

Per report from Mitsumasa Kondo. Apply to 9.1 and 9.2, like the previous
fix. Master was already doing this differently; this patch makes 9.1 and
9.2 to do the same thing as master.

11 years agoPostpone creation of pathkeys lists to fix bug #8049.
Tom Lane [Mon, 29 Apr 2013 18:49:16 +0000 (14:49 -0400)]
Postpone creation of pathkeys lists to fix bug #8049.

This patch gets rid of the concept of, and infrastructure for,
non-canonical PathKeys; we now only ever create canonical pathkey lists.

The need for non-canonical pathkeys came from the desire to have
grouping_planner initialize query_pathkeys and related pathkey lists before
calling query_planner.  However, since query_planner didn't actually *do*
anything with those lists before they'd been made canonical, we can get rid
of the whole mess by just not creating the lists at all until the point
where we formerly canonicalized them.

There are several ways in which we could implement that without making
query_planner itself deal with grouping/sorting features (which are
supposed to be the province of grouping_planner).  I chose to add a
callback function to query_planner's API; other alternatives would have
required adding more fields to PlannerInfo, which while not bad in itself
would create an ABI break for planner-related plugins in the 9.2 release
series.  This still breaks ABI for anything that calls query_planner
directly, but it seems somewhat unlikely that there are any such plugins.

I had originally conceived of this change as merely a step on the way to
fixing bug #8049 from Teun Hoogendoorn; but it turns out that this fixes
that bug all by itself, as per the added regression test.  The reason is
that now get_eclass_for_sort_expr is adding the ORDER BY expression at the
end of EquivalenceClass creation not the start, and so anything that is in
a multi-member EquivalenceClass has already been created with correct
em_nullable_relids.  I am suspicious that there are related scenarios in
which we still need to teach get_eclass_for_sort_expr to compute correct
nullable_relids, but am not eager to risk destabilizing either 9.2 or 9.3
to fix bugs that are only hypothetical.  So for the moment, do this and
stop here.

Back-patch to 9.2 but not to earlier branches, since they don't exhibit
this bug for lack of join-clause-movement logic that depends on
em_nullable_relids being correct.  (We might have to revisit that choice
if any related bugs turn up.)  In 9.2, don't change the signature of
make_pathkeys_for_sortclauses nor remove canonicalize_pathkeys, so as
not to risk more plugin breakage than we have to.

11 years agoEnsure ANALYZE phase is not skipped because of canceled truncate.
Kevin Grittner [Mon, 29 Apr 2013 18:05:56 +0000 (13:05 -0500)]
Ensure ANALYZE phase is not skipped because of canceled truncate.

Patch b19e4250b45e91c9cbdd18d35ea6391ab5961c8d attempted to
preserve existing behavior regarding statistics generation in the
case that a truncation attempt was canceled due to lock conflicts.
It failed to do this accurately in two regards: (1) autovacuum had
previously generated statistics if the truncate attempt failed to
initially get the lock rather than having started the attempt, and
(2) the VACUUM ANALYZE command had always generated statistics.

Both of these changes were unintended, and are reverted by this
patch.  On review, there seems to be consensus that the previous
failure to generate statistics when the truncate was terminated
was more an unfortunate consequence of how that effort was
previously terminated than a feature we want to keep; so this
patch generates statistics even when an autovacuum truncation
attempt terminates early.  Another unintended change which is kept
on the basis that it is an improvement is that when a VACUUM
command is truncating, it will the new heuristic for avoiding
blocking other processes, rather than keeping an
AccessExclusiveLock on the table for however long the truncation
takes.

Per multiple reports, with some renaming per patch by Jeff Janes.

Backpatch to 9.0, where problem was created.

11 years agoEnsure that user created rows in extension tables get dumped if the table is explicit...
Joe Conway [Fri, 26 Apr 2013 18:54:14 +0000 (11:54 -0700)]
Ensure that user created rows in extension tables get dumped if the table is explicitly requested, either with a -t/--table switch of the table itself, or by -n/--schema switch of the schema containing the extension table. Patch reviewed by Vibhor Kumar and Dimitri Fontaine.

Backpatched to 9.1 when the extension management facility was added.

11 years agoAvoid deadlock between concurrent CREATE INDEX CONCURRENTLY commands.
Tom Lane [Thu, 25 Apr 2013 20:58:10 +0000 (16:58 -0400)]
Avoid deadlock between concurrent CREATE INDEX CONCURRENTLY commands.

There was a high probability of two or more concurrent C.I.C. commands
deadlocking just before completion, because each would wait for the others
to release their reference snapshots.  Fix by releasing the snapshot
before waiting for other snapshots to go away.

Per report from Paul Hinze.  Back-patch to all active branches.

11 years agoFix typo in comment.
Heikki Linnakangas [Thu, 25 Apr 2013 11:03:10 +0000 (14:03 +0300)]
Fix typo in comment.

Peter Geoghegan

11 years agodoc: Fix syntax in example
Peter Eisentraut [Mon, 22 Apr 2013 02:16:12 +0000 (22:16 -0400)]
doc: Fix syntax in example

LANGUAGE 'plpgsql' no longer works.  The single quotes need to be
removed.

Erwin Brandstetter

11 years agoFix longstanding race condition in plancache.c.
Tom Lane [Sat, 20 Apr 2013 20:59:27 +0000 (16:59 -0400)]
Fix longstanding race condition in plancache.c.

When creating or manipulating a cached plan for a transaction control
command (particularly ROLLBACK), we must not perform any catalog accesses,
since we might be in an aborted transaction.  However, plancache.c busily
saved or examined the search_path for every cached plan.  If we were
unlucky enough to do this at a moment where the path's expansion into
schema OIDs wasn't already cached, we'd do some catalog accesses; and with
some more bad luck such as an ill-timed signal arrival, that could lead to
crashes or Assert failures, as exhibited in bug #8095 from Nachiket Vaidya.
Fortunately, there's no real need to consider the search path for such
commands, so we can just skip the relevant steps when the subject statement
is a TransactionStmt.  This is somewhat related to bug #5269, though the
failure happens during initial cached-plan creation rather than
revalidation.

This bug has been there since the plan cache was invented, so back-patch
to all supported branches.

11 years agoUpdate the description for the graphical installers
Magnus Hagander [Wed, 10 Apr 2013 19:37:49 +0000 (21:37 +0200)]
Update the description for the graphical installers

Remove references to "one click", as we're not supposed to call
them that anymore.

11 years agoIn isolationtester, retry after EINTR return from select(2).
Tom Lane [Sun, 7 Apr 2013 02:28:53 +0000 (22:28 -0400)]
In isolationtester, retry after EINTR return from select(2).

Per report from Jaime Casanova.  Very curious that no one else has seen
this failure ... but the code is clearly wrong as-is.

11 years agoImprove documentation about the relationship of extensions and schemas.
Tom Lane [Fri, 5 Apr 2013 02:37:29 +0000 (22:37 -0400)]
Improve documentation about the relationship of extensions and schemas.

There's been some confusion expressed about this point, so clarify.
Extended version of a patch by David Wheeler.

11 years agopsql: fix startup crash caused by PSQLRC containing a tilde
Bruce Momjian [Thu, 4 Apr 2013 16:56:21 +0000 (12:56 -0400)]
psql:  fix startup crash caused by PSQLRC containing a tilde

'strdup' the PSQLRC environment variable value before calling a routine
that might free() it.

Backpatch to 9.2, where the bug first appeared.

11 years agoFix crash on compiling a regular expression with more than 32k colors.
Heikki Linnakangas [Thu, 4 Apr 2013 16:04:57 +0000 (19:04 +0300)]
Fix crash on compiling a regular expression with more than 32k colors.

Throw an error instead.

Backpatch to all supported branches.

11 years agoCalculate # of semaphores correctly with --disable-spinlocks.
Heikki Linnakangas [Thu, 4 Apr 2013 13:31:44 +0000 (16:31 +0300)]
Calculate # of semaphores correctly with --disable-spinlocks.

The old formula didn't take into account that each WAL sender process needs
a spinlock. We had also already exceeded the fixed number of spinlocks
reserved for misc purposes (10). Bump that to 30.

Backpatch to 9.0, where WAL senders were introduced. If I counted correctly,
9.0 had exactly 10 predefined spinlocks, and 9.1 exceeded that, but bump the
limit in 9.0 too because 10 is uncomfortably close to the edge.

11 years agoAvoid updating our PgBackendStatus entry when track_activities is off.
Tom Lane [Wed, 3 Apr 2013 18:13:34 +0000 (14:13 -0400)]
Avoid updating our PgBackendStatus entry when track_activities is off.

The point of turning off track_activities is to avoid this reporting
overhead, but a thinko in commit 4f42b546fd87a80be30c53a0f2c897acb826ad52
caused pgstat_report_activity() to perform half of its updates anyway.
Fix that, and also make sure that we clear all the now-disabled fields
when transitioning to the non-reporting state.

11 years agoMinor robustness improvements for isolationtester.
Tom Lane [Wed, 3 Apr 2013 01:15:45 +0000 (21:15 -0400)]
Minor robustness improvements for isolationtester.

Notice and complain about PQcancel() failures.  Also, don't dump core if
an error PGresult doesn't contain severity and message subfields, as it
might not if it was generated by libpq itself.  (We have a longstanding
TODO item to improve that, but in the meantime isolationtester had better
cope.)

I tripped across the latter item while investigating a trouble report on
buildfarm member spoonbill.  As for the former, there's no evidence that
PQcancel failure is actually involved in spoonbill's problem, but it still
seems like a bad idea to ignore an error return code.

11 years agoStamp 9.2.4. REL9_2_4
Tom Lane [Mon, 1 Apr 2013 18:20:36 +0000 (14:20 -0400)]
Stamp 9.2.4.

11 years agoUpdate release notes for 9.2.4, 9.1.9, 9.0.13, 8.4.17.
Tom Lane [Mon, 1 Apr 2013 18:11:16 +0000 (14:11 -0400)]
Update release notes for 9.2.4, 9.1.9, 9.0.13, 8.4.17.

Security: CVE-2013-1899, CVE-2013-1901

11 years agoFix insecure parsing of server command-line switches.
Tom Lane [Mon, 1 Apr 2013 18:00:59 +0000 (14:00 -0400)]
Fix insecure parsing of server command-line switches.

An oversight in commit e710b65c1c56ca7b91f662c63d37ff2e72862a94 allowed
database names beginning with "-" to be treated as though they were secure
command-line switches; and this switch processing occurs before client
authentication, so that even an unprivileged remote attacker could exploit
the bug, needing only connectivity to the postmaster's port.  Assorted
exploits for this are possible, some requiring a valid database login,
some not.  The worst known problem is that the "-r" switch can be invoked
to redirect the process's stderr output, so that subsequent error messages
will be appended to any file the server can write.  This can for example be
used to corrupt the server's configuration files, so that it will fail when
next restarted.  Complete destruction of database tables is also possible.

Fix by keeping the database name extracted from a startup packet fully
separate from command-line switches, as had already been done with the
user name field.

The Postgres project thanks Mitsumasa Kondo for discovering this bug,
Kyotaro Horiguchi for drafting the fix, and Noah Misch for recognizing
the full extent of the danger.

Security: CVE-2013-1899

11 years agoMake REPLICATION privilege checks test current user not authenticated user.
Tom Lane [Mon, 1 Apr 2013 17:09:29 +0000 (13:09 -0400)]
Make REPLICATION privilege checks test current user not authenticated user.

The pg_start_backup() and pg_stop_backup() functions checked the privileges
of the initially-authenticated user rather than the current user, which is
wrong.  For example, a user-defined index function could successfully call
these functions when executed by ANALYZE within autovacuum.  This could
allow an attacker with valid but low-privilege database access to interfere
with creation of routine backups.  Reported and fixed by Noah Misch.

Security: CVE-2013-1901

11 years agoTranslation updates
Peter Eisentraut [Mon, 1 Apr 2013 03:46:49 +0000 (23:46 -0400)]
Translation updates

11 years agoIgnore extra subquery outputs in set_subquery_size_estimates().
Tom Lane [Sun, 31 Mar 2013 22:33:01 +0000 (18:33 -0400)]
Ignore extra subquery outputs in set_subquery_size_estimates().

In commit 0f61d4dd1b4f95832dcd81c9688dac56fd6b5687, I added code to copy up
column width estimates for each column of a subquery.  That code supposed
that the subquery couldn't have any output columns that didn't correspond
to known columns of the current query level --- which is true when a query
is parsed from scratch, but the assumption fails when planning a view that
depends on another view that's been redefined (adding output columns) since
the upper view was made.  This results in an assertion failure or even a
crash, as per bug #8025 from lindebg.  Remove the Assert and instead skip
the column if its resno is out of the expected range.

11 years agoTranslation updates
Alvaro Herrera [Sun, 31 Mar 2013 19:41:54 +0000 (16:41 -0300)]
Translation updates

11 years agopg_upgrade: don't copy/link files for invalid indexes
Bruce Momjian [Sun, 31 Mar 2013 02:20:53 +0000 (22:20 -0400)]
pg_upgrade:  don't copy/link files for invalid indexes

Now that pg_dump no longer dumps invalid indexes, per commit
683abc73dff549e94555d4020dae8d02f32ed78b, have pg_upgrade also skip
them.  Previously pg_upgrade threw an error if invalid indexes existed.

Backpatch to 9.2, 9.1, and 9.0 (where pg_upgrade was added to git)

11 years agoAvoid moving data directory in upgrade testing.
Andrew Dunstan [Sat, 30 Mar 2013 16:54:36 +0000 (12:54 -0400)]
Avoid moving data directory in upgrade testing.

Windows sometimes gets upset if we rename a large directory and then try
to use the old name quickly, as seen in occasional buildfarm failures.
So we avoid that by building the old version in the intended
destination in the first place instead of renaming it, similar to the
change made for the same reason in commit b7f8465c.

11 years agoDocument encode(bytea, 'escape')'s behavior correctly.
Tom Lane [Fri, 29 Mar 2013 03:14:58 +0000 (23:14 -0400)]
Document encode(bytea, 'escape')'s behavior correctly.

I changed this in commit fd15dba543247eb1ce879d22632b9fdb4c230831, but
missed the fact that the SGML documentation of the function specified
exactly what it did.  Well, one of the two places where it's specified
documented that --- probably I looked at the other place and thought
nothing needed to be done.  Sync the two places where encode() and
decode() are described.

11 years agoMust check indisready not just indisvalid when dumping from 9.2 server.
Tom Lane [Fri, 29 Mar 2013 02:09:20 +0000 (22:09 -0400)]
Must check indisready not just indisvalid when dumping from 9.2 server.

9.2 uses a kluge representation of "indislive"; we have to account for
that when examining pg_index.  Simplest solution is to check indisready
for 9.0 and 9.1 as well; that's harmless though unnecessary, so it's
not worth making a version distinction for.

Fixes oversight in commit 683abc73dff549e94555d4020dae8d02f32ed78b,
as noted by Andres Freund.

11 years agoUpdate time zone data files to tzdata release 2013b.
Tom Lane [Thu, 28 Mar 2013 19:25:54 +0000 (15:25 -0400)]
Update time zone data files to tzdata release 2013b.

DST law changes in Chile, Haiti, Morocco, Paraguay, some Russian areas.
Historical corrections for numerous places.

11 years agoReset OpenSSL randomness state in each postmaster child process.
Tom Lane [Wed, 27 Mar 2013 22:50:25 +0000 (18:50 -0400)]
Reset OpenSSL randomness state in each postmaster child process.

Previously, if the postmaster initialized OpenSSL's PRNG (which it will do
when ssl=on in postgresql.conf), the same pseudo-random state would be
inherited by each forked child process.  The problem is masked to a
considerable extent if the incoming connection uses SSL encryption, but
when it does not, identical pseudo-random state is made available to
functions like contrib/pgcrypto.  The process's PID does get mixed into any
requested random output, but on most systems that still only results in 32K
or so distinct random sequences available across all Postgres sessions.
This might allow an attacker who has database access to guess the results
of "secure" operations happening in another session.

To fix, forcibly reset the PRNG after fork().  Each child process that has
need for random numbers from OpenSSL's generator will thereby be forced to
go through OpenSSL's normal initialization sequence, which should provide
much greater variability of the sequences.  There are other ways we might
do this that would be slightly cheaper, but this approach seems the most
future-proof against SSL-related code changes.

This has been assigned CVE-2013-1900, but since the issue and the patch
have already been publicized on pgsql-hackers, there's no point in trying
to hide this commit.

Back-patch to all supported branches.

Marko Kreen

11 years agoFix buffer pin leak in heap update redo routine.
Heikki Linnakangas [Wed, 27 Mar 2013 19:51:27 +0000 (21:51 +0200)]
Fix buffer pin leak in heap update redo routine.

In a heap update, if the old and new tuple were on different pages, and the
new page no longer existed (because it was subsequently truncated away by
vacuum), heap_xlog_update forgot to release the pin on the old buffer. This
bug was introduced by the "Fix multiple problems in WAL replay" patch,
commit 3bbf668de9f1bc172371681e80a4e769b6d014c8 (on master branch).

With full_page_writes=off, this triggered an "incorrect local pin count"
error later in replay, if the old page was vacuumed.

This fixes bug #7969, reported by Yunong Xiao. Backpatch to 9.0, like the
commit that introduced this bug.

11 years agoIgnore invalid indexes in pg_dump.
Tom Lane [Tue, 26 Mar 2013 21:43:23 +0000 (17:43 -0400)]
Ignore invalid indexes in pg_dump.

Dumping invalid indexes can cause problems at restore time, for example
if the reason the index creation failed was because it tried to enforce
a uniqueness condition not satisfied by the table's data.  Also, if the
index creation is in fact still in progress, it seems reasonable to
consider it to be an uncommitted DDL change, which pg_dump wouldn't be
expected to dump anyway.

Back-patch to all active versions, and teach them to ignore invalid
indexes in servers back to 8.2, where the concept was introduced.

Michael Paquier

11 years agoIn base backup, only include our own tablespace version directory.
Heikki Linnakangas [Mon, 25 Mar 2013 18:19:22 +0000 (20:19 +0200)]
In base backup, only include our own tablespace version directory.

If you have clusters of different versions pointing to the same tablespace
location, we would incorrectly include all the data belonging to the other
versions, too.

Fixes bug #7986, reported by Sergey Burladyan.

11 years agoAdd a server version check to pg_basebackup and pg_receivexlog.
Heikki Linnakangas [Mon, 25 Mar 2013 09:02:55 +0000 (11:02 +0200)]
Add a server version check to pg_basebackup and pg_receivexlog.

These programs don't work against 9.0 or earlier servers, so check that when
the connection is made. That's better than a cryptic error message you got
before.

Also, these programs won't work with a 9.3 server, because the WAL streaming
protocol was changed in a non-backwards-compatible way. As a general rule,
we don't make any guarantee that an old client will work with a new server,
so check that. However, allow a 9.1 client to connect to a 9.2 server, to
avoid breaking environments that currently work; a 9.1 client happens to
work with a 9.2 server, even though we didn't make any great effort to
ensure that.

This patch is for the 9.1 and 9.2 branches, I'll commit a similar patch to
master later. Although this isn't a critical bug fix, it seems safe enough
to back-patch. The error message you got when connecting to a 9.3devel
server without this patch was cryptic enough to warrant backpatching.

11 years agoUpdate time zone abbreviation lists for changes missed since 2006.
Tom Lane [Sat, 23 Mar 2013 23:16:42 +0000 (19:16 -0400)]
Update time zone abbreviation lists for changes missed since 2006.

Most (all?) of Russia has moved to what's effectively year-round daylight
savings time, so that the "standard" zone names now mean an hour later
than they used to.  Update that, notably changing MSK as per recent
complaint from Sergey Konoplev, but also CHOT, GET, IRKT, KGT, KRAT,
MAGT, NOVT, OMST, VLAT, YAKT, YEKT.  The corresponding DST abbreviations
are presumably now obsolete, but I left them in place with their old
definitions, just to reduce any possible breakage from this change.

Also add VOLT (Europe/Volgograd), which for some reason we never had
before, as well as MIST (Antarctica/Macquarie), and fix obsolete
definitions of MAWT, TKT, and WST.

11 years agoAvoid renaming data directory during MSVC upgrade testing.
Andrew Dunstan [Sat, 23 Mar 2013 20:31:01 +0000 (16:31 -0400)]
Avoid renaming data directory during MSVC upgrade testing.

This appears to cause some intermittent file system problems
on Windows 8. Instead, set up the old data directory in its
intended final location to start with.

11 years agoDon't put <indexterm> before <term> in <varlistentry> items.
Tom Lane [Sat, 23 Mar 2013 18:06:37 +0000 (14:06 -0400)]
Don't put <indexterm> before <term> in <varlistentry> items.

Doing that results in a broken index entry in PDF output.  We had only
a few like that, which is probably why nobody noticed before.
Standardize on putting the <term> first.

Josh Kupershmidt

11 years agoFix contrib/dblink to handle inconsistent DateStyle/IntervalStyle safely.
Tom Lane [Fri, 22 Mar 2013 19:22:21 +0000 (15:22 -0400)]
Fix contrib/dblink to handle inconsistent DateStyle/IntervalStyle safely.

If the remote database's settings of these GUCs are different from ours,
ambiguous datetime values may be read incorrectly.  To fix, temporarily
adopt the remote server's settings while we ingest a query result.

This is not a complete fix, since it doesn't do anything about ambiguous
values in commands sent to the remote server; but there seems little we
can do about that end of it given dblink's entirely textual API for
transmitted commands.

Back-patch to 9.2.  The hazard exists in all versions, but this patch
would need more work to apply before 9.2.  Given the lack of field
complaints about this issue, it doesn't seem worth the effort at present.

Daniel Farina and Tom Lane

11 years agoImprove documentation of EXTRACT(WEEK).
Tom Lane [Mon, 18 Mar 2013 17:34:21 +0000 (13:34 -0400)]
Improve documentation of EXTRACT(WEEK).

The docs showed that early-January dates can be considered part of the
previous year for week-counting purposes, but failed to say explicitly
that late-December dates can also be considered part of the next year.
Fix that, and add a cross-reference to the "isoyear" field.  Per bug
#7967 from Pawel Kobylak.

11 years agoFix race condition in DELETE RETURNING.
Tom Lane [Sun, 10 Mar 2013 23:18:44 +0000 (19:18 -0400)]
Fix race condition in DELETE RETURNING.

When RETURNING is specified, ExecDelete would return a virtual-tuple slot
that could contain pointers into an already-unpinned disk buffer.  Another
process could change the buffer contents before we get around to using the
data, resulting in garbage results or even a crash.  This seems of fairly
low probability, which may explain why there are no known field reports of
the problem, but it's definitely possible.  Fix by forcing the result slot
to be "materialized" before we release pin on the disk buffer.

Back-patch to 9.0; in earlier branches there is no bug because
ExecProcessReturning sent the tuple to the destination immediately.  Also,
this is already fixed in HEAD as part of the writable-foreign-tables patch
(where the fix is necessary for DELETE RETURNING to work at all with
postgres_fdw).

11 years agoFix infinite-loop risk in fixempties() stage of regex compilation.
Tom Lane [Thu, 7 Mar 2013 16:51:08 +0000 (11:51 -0500)]
Fix infinite-loop risk in fixempties() stage of regex compilation.

The previous coding of this function could get into situations where it
would never terminate, because successive passes would re-add EMPTY arcs
that had been removed by the previous pass.  Rewrite the function
completely using a new algorithm that is guaranteed to terminate, and
also seems to be usually faster than the old one.  Per Tcl bugs 3604074
and 3606683.

Tom Lane and Don Porter

11 years agoFix tli history file fetching, broken by the archive after crash recevery patch.
Heikki Linnakangas [Thu, 7 Mar 2013 10:18:41 +0000 (12:18 +0200)]
Fix tli history file fetching, broken by the archive after crash recevery patch.

If we were about to enter archive recovery after crash recovery, we scanned
the archive for the latest tli history file, and set the recovery target
timeline to that. However, when we actually tried to read the history file,
we would not fetch the file from the archive, because we were not in archive
recovery yet.

To fix, make readTimeLineHistory and existsTimeLineHistory to always fetch
the file from archive if archive recovery is requested, even if we're not in
archive recovery yet.

Backpatch to 9.2. Mitsumasa KONDO

11 years agoFurther fix to the mode where we enter archive recovery after crash recovery.
Heikki Linnakangas [Thu, 7 Mar 2013 10:12:33 +0000 (12:12 +0200)]
Further fix to the mode where we enter archive recovery after crash recovery.

I missed to returns in the middle of ReadRecord function in my previous fix.
If a WAL file was not found at all during crash recovery, XLogPageRead would
return 'false', and ReadRecord would return without entering archive recovery.

9.2 only. In master, the code is structured differently and does not have this
problem.

Kyotaro HORIGUCHI, Mitsumasa KONDO and me.

11 years agoFix message typo.
Andrew Dunstan [Wed, 6 Mar 2013 14:53:38 +0000 (09:53 -0500)]
Fix message typo.

11 years agoFix to_char() to use ASCII-only case-folding rules where appropriate.
Tom Lane [Tue, 5 Mar 2013 18:02:35 +0000 (13:02 -0500)]
Fix to_char() to use ASCII-only case-folding rules where appropriate.

formatting.c used locale-dependent case folding rules in some code paths
where the result isn't supposed to be locale-dependent, for example
to_char(timestamp, 'DAY').  Since the source data is always just ASCII
in these cases, that usually didn't matter ... but it does matter in
Turkish locales, which have unusual treatment of "i" and "I".  To confuse
matters even more, the misbehavior was only visible in UTF8 encoding,
because in single-byte encodings we used pg_toupper/pg_tolower which
don't have locale-specific behavior for ASCII characters.  Fix by providing
intentionally ASCII-only case-folding functions and using these where
appropriate.  Per bug #7913 from Adnan Dursun.  Back-patch to all active
branches, since it's been like this for a long time.

11 years agoFix overflow check in tm2timestamp (this time for sure).
Tom Lane [Mon, 4 Mar 2013 20:13:31 +0000 (15:13 -0500)]
Fix overflow check in tm2timestamp (this time for sure).

I fixed this code back in commit 841b4a2d5, but didn't think carefully
enough about the behavior near zero, which meant it improperly rejected
1999-12-31 24:00:00.  Per report from Magnus Hagander.

11 years agoFix SQL function execution to be safe with long-lived FmgrInfos.
Tom Lane [Sun, 3 Mar 2013 22:40:04 +0000 (17:40 -0500)]
Fix SQL function execution to be safe with long-lived FmgrInfos.

fmgr_sql had been designed on the assumption that the FmgrInfo it's called
with has only query lifespan.  This is demonstrably unsafe in connection
with range types, as shown in bug #7881 from Andrew Gierth.  Fix things
so that we re-generate the function's cache data if the (sub)transaction
it was made in is no longer active.

Back-patch to 9.2.  This might be needed further back, but it's not clear
whether the case can realistically arise without range types, so for now
I'll desist from back-patching further.

11 years agodoc: A few awkward phrasing fixes
Peter Eisentraut [Sun, 3 Mar 2013 13:49:49 +0000 (08:49 -0500)]
doc: A few awkward phrasing fixes

Josh Kupershmidt

11 years agoExclude utils/probes.h and pg_trace.h from cpluspluscheck
Peter Eisentraut [Sat, 2 Mar 2013 03:43:47 +0000 (22:43 -0500)]
Exclude utils/probes.h and pg_trace.h from cpluspluscheck

They can include sys/sdt.h from SystemTap, which itself contains C++
code and so won't compile with a C++ compiler under extern "C" linkage.