]> granicus.if.org Git - postgresql/log
postgresql
10 years agoAnother round of Coverity fixes
Stephen Frost [Mon, 3 Mar 2014 08:18:51 +0000 (03:18 -0500)]
Another round of Coverity fixes

Additional non-security issues/improvements spotted by Coverity.

In backend/libpq, no sense trying to protect against port->hba being
NULL after we've already dereferenced it in the switch() statement.

Prevent against possible overflow due to 32bit arithmitic in
basebackup throttling (not yet released, so no security concern).

Remove nonsensical check of array pointer against NULL in procarray.c,
looks to be a holdover from 9.1 and earlier when there were pointers
being used but now it's just an array.

Remove pointer check-against-NULL in tsearch/spell.c as we had already
dereferenced it above (in the strcmp()).

Remove dead code from adt/orderedsetaggs.c, isnull is checked
immediately after each tuplesort_getdatum() call and if true we return,
so no point checking it again down at the bottom.

Remove recently added minor error-condition memory leak in pg_regress.

10 years agoVarious Coverity-spotted fixes
Stephen Frost [Sun, 2 Mar 2014 03:14:14 +0000 (22:14 -0500)]
Various Coverity-spotted fixes

A number of issues were identified by the Coverity scanner and are
addressed in this patch.  None of these appear to be security issues
and many are mostly cosmetic changes.

Short comments for each of the changes follows.

Correct the semi-colon placement in be-secure.c regarding SSL retries.
Remove a useless comparison-to-NULL in proc.c (value is dereferenced
  prior to this check and therefore can't be NULL).
Add checking of chmod() return values to initdb.
Fix a couple minor memory leaks in initdb.
Fix memory leak in pg_ctl- involves free'ing the config file contents.
Use an int to capture fgetc() return instead of an enum in pg_dump.
Fix minor memory leaks in pg_dump.
  (note minor change to convertOperatorReference()'s API)
Check fclose()/remove() return codes in psql.
Check fstat(), find_my_exec() return codes in psql.
Various ECPG memory leak fixes.
Check find_my_exec() return in ECPG.
Explicitly ignore pqFlush return in libpq error-path.
Change PQfnumber() to avoid doing an strdup() when no changes required.
Remove a few useless check-against-NULL's (value deref'd beforehand).
Check rmtree(), malloc() results in pg_regress.
Also check get_alternative_expectfile() return in pg_regress.

10 years agoAllow regex operations to be terminated early by query cancel requests.
Tom Lane [Sat, 1 Mar 2014 20:20:56 +0000 (15:20 -0500)]
Allow regex operations to be terminated early by query cancel requests.

The regex code didn't have any provision for query cancel; which is
unsurprising given its non-Postgres origin, but still problematic since
some operations can take a long time.  Introduce a callback function to
check for a pending query cancel or session termination request, and
call it in a couple of strategic spots where we can make the regex code
exit with an error indicator.

If we ever actually split out the regex code as a standalone library,
some additional work will be needed to let the cancel callback function
be specified externally to the library.  But that's straightforward
(certainly so by comparison to putting the locale-dependent character
classification logic on a similar arms-length basis), and there seems
no need to do it right now.

A bigger issue is that there may be more places than these two where
we need to check for cancels.  We can always add more checks later,
now that the infrastructure is in place.

Since there are known examples of not-terribly-long regexes that can
lock up a backend for a long time, back-patch to all supported branches.
I have hopes of fixing the known performance problems later, but adding
query cancel ability seems like a good idea even if they were all fixed.

10 years agoRemove bogus while-loop.
Heikki Linnakangas [Fri, 28 Feb 2014 11:22:25 +0000 (13:22 +0200)]
Remove bogus while-loop.

Commit abf5c5c9a4f142b3343614746bb9e99a794f8e7b added a bogus while-
statement after the for(;;)-loop. It went unnoticed in testing, because
it was dead code.

Report by KONDO Mitsumasa. Backpatch to 9.3. The commit that introduced
this was also applied to 9.2, but not the bogus while-loop part, because
the code in 9.2 looks quite different.

10 years agopgbench: Fix help message
Peter Eisentraut [Fri, 28 Feb 2014 02:52:21 +0000 (21:52 -0500)]
pgbench: Fix help message

Add NUM placeholder to -t option in help message.  It got lost in
79cddb18419778be3202c971b3f21cdd90f7b719.

Author: Fabien COELHO <coelho@cri.ensmp.fr>

10 years agoAllow BASE_BACKUP to be throttled
Alvaro Herrera [Thu, 27 Feb 2014 21:55:57 +0000 (18:55 -0300)]
Allow BASE_BACKUP to be throttled

A new MAX_RATE option allows imposing a limit to the network transfer
rate from the server side.  This is useful to limit the stress that
taking a base backup has on the server.

pg_basebackup is now able to specify a value to the server, too.

Author: Antonin Houska

Patch reviewed by Stefan Radomski, Andres Freund, Zoltán Böszörményi,
Fujii Masao, and Álvaro Herrera.

10 years agoRemove dependency on database encoding in citext regression test.
Tom Lane [Thu, 27 Feb 2014 19:58:47 +0000 (14:58 -0500)]
Remove dependency on database encoding in citext regression test.

Testing convert_to(..., 'ISO-8859-1') fails if there isn't a conversion
function available from the database encoding to ISO-8859-1.  This has
been broken since day one, but the breakage was hidden by
pg_do_encoding_conversion's failure to complain, up till commit
49c817eab78c6f0ce8c3bf46766b73d6cf3190b7.

Since the data being converted in this test is plain ASCII, no actual
conversion need happen (and if it did, it would prove little about citext
anyway).  So that we still have some code coverage of the convert() family
of functions, let's switch to using convert_from, with SQL_ASCII as the
specified source encoding.  Per buildfarm.

10 years agodoc: bgw_main takes a Datum argument, not void *.
Alvaro Herrera [Thu, 27 Feb 2014 14:41:43 +0000 (11:41 -0300)]
doc: bgw_main takes a Datum argument, not void *.

Per report from James Harper.

10 years agoFix WAL replay of locking an updated tuple
Alvaro Herrera [Thu, 27 Feb 2014 14:13:39 +0000 (11:13 -0300)]
Fix WAL replay of locking an updated tuple

We were resetting the tuple's HEAP_HOT_UPDATED flag as well as t_ctid on
WAL replay of a tuple-lock operation, which is incorrect when the tuple
is already updated.

Back-patch to 9.3.  The clearing of both header elements was there
previously, but since no update could be present on a tuple that was
being locked, it was harmless.

Bug reported by Peter Geoghegan and Greg Stark in
CAM3SWZTMQiCi5PV5OWHb+bYkUcnCk=O67w0cSswPvV7XfUcU5g@mail.gmail.com and
CAM-w4HPTOeMT4KP0OJK+mGgzgcTOtLRTvFZyvD0O4aH-7dxo3Q@mail.gmail.com
respectively; diagnosis by Andres Freund.

10 years agobtbuild no longer calls _bt_doinsert(), update comment.
Heikki Linnakangas [Wed, 26 Feb 2014 16:48:21 +0000 (18:48 +0200)]
btbuild no longer calls _bt_doinsert(), update comment.

Peter Geoghegan

10 years agoFix crash in json_to_record().
Jeff Davis [Wed, 26 Feb 2014 15:47:09 +0000 (07:47 -0800)]
Fix crash in json_to_record().

json_to_record() depends on get_call_result_type() for the tuple
descriptor of the record that should be returned, but in some cases
that cannot be determined. Add a guard to check if the tuple
descriptor has been properly resolved, similar to other callers of
get_call_result_type().

Also add guard for two other callers of get_call_result_type() in
jsonfuncs.c. Although json_to_record() is the only actual bug, it's a
good idea to follow convention.

10 years agoUse SnapshotDirty rather than an active snapshot to probe index endpoints.
Tom Lane [Tue, 25 Feb 2014 21:04:06 +0000 (16:04 -0500)]
Use SnapshotDirty rather than an active snapshot to probe index endpoints.

If there are lots of uncommitted tuples at the end of the index range,
get_actual_variable_range() ends up fetching each one and doing an MVCC
visibility check on it, until it finally hits a visible tuple.  This is
bad enough in isolation, considering that we don't need an exact answer
only an approximate one.  But because the tuples are not yet committed,
each visibility check does a TransactionIdIsInProgress() test, which
involves scanning the ProcArray.  When multiple sessions do this
concurrently, the ensuing contention results in horrid performance loss.
20X overall throughput loss on not-too-complicated queries is easy to
demonstrate in the back branches (though someone's made it noticeably
less bad in HEAD).

We can dodge the problem fairly effectively by using SnapshotDirty rather
than a normal MVCC snapshot.  This will cause the index probe to take
uncommitted tuples as good, so that we incur only one tuple fetch and test
even if there are many such tuples.  The extent to which this degrades the
estimate is debatable: it's possible the result is actually a more accurate
prediction than before, if the endmost tuple has become committed by the
time we actually execute the query being planned.  In any case, it's not
very likely that it makes the estimate a lot worse.

SnapshotDirty will still reject tuples that are known committed dead, so
we won't give bogus answers if an invalid outlier has been deleted but not
yet vacuumed from the index.  (Because btrees know how to mark such tuples
dead in the index, we shouldn't have a big performance problem in the case
that there are many of them at the end of the range.)  This consideration
motivates not using SnapshotAny, which was also considered as a fix.

Note: the back branches were using SnapshotNow instead of an MVCC snapshot,
but the problem and solution are the same.

Per performance complaints from Bartlomiej Romanski, Josh Berkus, and
others.  Back-patch to 9.0, where the issue was introduced (by commit
40608e7f949fb7e4025c0ddd5be01939adc79eec).

10 years agoUpdate a few comments to mention materialized views.
Robert Haas [Tue, 25 Feb 2014 18:40:12 +0000 (13:40 -0500)]
Update a few comments to mention materialized views.

Etsuro Fujita

10 years agoShow xid and xmin in pg_stat_activity and pg_stat_replication.
Robert Haas [Tue, 25 Feb 2014 17:34:04 +0000 (12:34 -0500)]
Show xid and xmin in pg_stat_activity and pg_stat_replication.

Christian Kruse, reviewed by Andres Freund and myself, with further
minor adjustments by me.

10 years agopg_basebackup: Skip only the *contents* of pg_replslot.
Robert Haas [Tue, 25 Feb 2014 16:23:45 +0000 (11:23 -0500)]
pg_basebackup: Skip only the *contents* of pg_replslot.

Include the directory itself.

Fujii Masao

10 years agoUpdate and clarify ssl_ciphers default
Peter Eisentraut [Tue, 25 Feb 2014 01:30:28 +0000 (20:30 -0500)]
Update and clarify ssl_ciphers default

- Write HIGH:MEDIUM instead of DEFAULT:!LOW:!EXP for clarity.
- Order 3DES last to work around inappropriate OpenSSL default.
- Remove !MD5 and @STRENGTH, because they are irrelevant.
- Add clarifying documentation.

Effectively, the new default is almost the same as the old one, but it
is arguably easier to understand and modify.

Author: Marko Kreen <markokr@gmail.com>

10 years agoIncrease work_mem and maintenance_work_mem defaults by 4x
Bruce Momjian [Mon, 24 Feb 2014 18:04:51 +0000 (13:04 -0500)]
Increase work_mem and maintenance_work_mem defaults by 4x

New defaults are 4MB and 64MB.

10 years agodocs: remove unnecessary references to old PG versions
Bruce Momjian [Mon, 24 Feb 2014 17:56:37 +0000 (12:56 -0500)]
docs:  remove unnecessary references to old PG versions

10 years agopsql: add separate \d display for disabled system triggers
Bruce Momjian [Mon, 24 Feb 2014 17:44:55 +0000 (12:44 -0500)]
psql:  add separate \d display for disabled system triggers

Previously if you disabled all triggers, only user triggers would
show as disabled

Per report from Andres Freund

10 years agopg_dump: fix subtle memory leak in func and arg signature processing
Bruce Momjian [Mon, 24 Feb 2014 17:32:41 +0000 (12:32 -0500)]
pg_dump:  fix subtle memory leak in func and arg signature processing

10 years agoFix markup for CHAR() doc patch
Bruce Momjian [Mon, 24 Feb 2014 17:26:04 +0000 (12:26 -0500)]
Fix markup for CHAR() doc patch

10 years agoAllow single-point polygons to be converted to circles
Bruce Momjian [Mon, 24 Feb 2014 17:24:00 +0000 (12:24 -0500)]
Allow single-point polygons to be converted to circles

This allows finding the center of a single-point polygon and converting
it to a point.

Per report from Josef Grahn

10 years agodocs: document behavior of CHAR() comparisons with chars < space
Bruce Momjian [Mon, 24 Feb 2014 17:09:23 +0000 (12:09 -0500)]
docs: document behavior of CHAR() comparisons with chars < space

Space trimming rather than space-padding causes unusual behavior, which
might not be standards-compliant.

Also remove recently-added now-redundant C comment.

10 years agoUse pg_lsn data type in pg_stat_replication, too.
Robert Haas [Mon, 24 Feb 2014 15:38:45 +0000 (10:38 -0500)]
Use pg_lsn data type in pg_stat_replication, too.

Michael Paquier, per a suggestion from Andres Freund

10 years agoRemove a couple of comments from the pg_lsn regression test.
Robert Haas [Mon, 24 Feb 2014 14:32:21 +0000 (09:32 -0500)]
Remove a couple of comments from the pg_lsn regression test.

Previously, one of these was a negative test case, but that got
changed along the way and the comments didn't get the memo.

Michael Paquier

10 years agodoc: Improve DocBook XML validity
Peter Eisentraut [Mon, 24 Feb 2014 02:25:35 +0000 (21:25 -0500)]
doc: Improve DocBook XML validity

DocBook XML is superficially compatible with DocBook SGML but has a
slightly stricter DTD that we have been violating in a few cases.
Although XSLT doesn't care whether the document is valid, the style
sheets don't necessarily process invalid documents correctly, so we need
to work toward fixing this.

This first commit moves the indexterms in refentry elements to an
allowed position.  It has no impact on the output.

10 years agoPrefer pg_any_to_server/pg_server_to_any over pg_do_encoding_conversion.
Tom Lane [Sun, 23 Feb 2014 21:59:05 +0000 (16:59 -0500)]
Prefer pg_any_to_server/pg_server_to_any over pg_do_encoding_conversion.

A large majority of the callers of pg_do_encoding_conversion were
specifying the database encoding as either source or target of the
conversion, meaning that we can use the less general functions
pg_any_to_server/pg_server_to_any instead.

The main advantage of using the latter functions is that they can make use
of a cached conversion-function lookup in the common case that the other
encoding is the current client_encoding.  It's notationally cleaner too in
most cases, not least because of the historical artifact that the latter
functions use "char *" rather than "unsigned char *" in their APIs.

Note that pg_any_to_server will apply an encoding verification step in
some cases where pg_do_encoding_conversion would have just done nothing.
This seems to me to be a good idea at most of these call sites, though
it partially negates the performance benefit.

Per discussion of bug #9210.

10 years agoPlug some more holes in encoding conversion.
Tom Lane [Sun, 23 Feb 2014 20:22:50 +0000 (15:22 -0500)]
Plug some more holes in encoding conversion.

Various places assume that pg_do_encoding_conversion() and
pg_server_to_any() will ensure encoding validity of their results;
but they failed to do so in the case that the source encoding is SQL_ASCII
while the destination is not.  We cannot perform any actual "conversion"
in that scenario, but we should still validate the string according to the
destination encoding.  Per bug #9210 from Digoal Zhou.

Arguably this is a back-patchable bug fix, but on the other hand adding
more enforcing of encoding checks might break existing applications that
were being sloppy.  On balance there doesn't seem to be much enthusiasm
for a back-patch, so fix in HEAD only.

While at it, remove some apparently-no-longer-needed provisions for
letting pg_do_encoding_conversion() "work" outside a transaction ---
if you consider it "working" to silently fail to do the requested
conversion.

Also, make a few cosmetic improvements in mbutils.c, notably removing
some Asserts that are certainly dead code since the variables they
assert aren't null are never null, even at process start.  (I think
this wasn't true at one time, but it is now.)

10 years agoconfigure.in: Use dnl in place of # where appropriate
Peter Eisentraut [Sun, 23 Feb 2014 01:42:39 +0000 (20:42 -0500)]
configure.in: Use dnl in place of # where appropriate

The comment added by ed011d9754fd4b76eac0eaa8c057fcfc0c302a6a used #,
which means it gets copied into configure, but it doesn't make sense
there.  So use dnl, which gets dropped when creating configure.

10 years agopg_basebackup: Add support for relocating tablespaces
Peter Eisentraut [Sat, 22 Feb 2014 18:38:06 +0000 (13:38 -0500)]
pg_basebackup: Add support for relocating tablespaces

Tablespaces can be relocated in plain backup mode by specifying one or
more -T olddir=newdir options.

Author: Steeve Lennmark <steevel@handeldsbanken.se>
Reviewed-by: Peter Eisentraut <peter_e@gmx.net>
10 years agoDo ScalarArrayOp estimation correctly when array is a stable expression.
Tom Lane [Fri, 21 Feb 2014 22:10:46 +0000 (17:10 -0500)]
Do ScalarArrayOp estimation correctly when array is a stable expression.

Most estimation functions apply estimate_expression_value to see if they
can reduce an expression to a constant; the key difference is that it
allows evaluation of stable as well as immutable functions in hopes of
ending up with a simple Const node.  scalararraysel didn't get the memo
though, and neither did gincost_opexpr/gincost_scalararrayopexpr.  Fix
that, and remove a now-unnecessary estimate_expression_value step in the
subsidiary function scalararraysel_containment.

Per complaint from Alexey Klyukin.  Back-patch to 9.3.  The problem
goes back further, but I'm hesitant to change estimation behavior in
long-stable release branches.

10 years agoAvoid integer overflow in hstore_to_json().
Heikki Linnakangas [Fri, 21 Feb 2014 13:43:31 +0000 (15:43 +0200)]
Avoid integer overflow in hstore_to_json().

The length of the output buffer was calculated based on the size of the
argument hstore. On a sizeof(int) == 4 platform and a huge argument, it
could overflow, causing a too small buffer to be allocated.

Refactor the function to use a StringInfo instead of pre-allocating the
buffer. Makes it shorter and more readable, too.

10 years agodoc: Clarify documentation page header customization code
Peter Eisentraut [Fri, 21 Feb 2014 02:41:24 +0000 (21:41 -0500)]
doc: Clarify documentation page header customization code

The customization overrode the fast-forward code with its custom Up
link.  So this is no longer really the fast-forward feature, so we might
as well turn that off and override the non-ff template instead, thus
removing one mental indirection.

Fix the wrong column span declaration.

Clarify and update the documentation.

10 years agoImprove comment on setting data_checksum GUC.
Heikki Linnakangas [Thu, 20 Feb 2014 08:43:36 +0000 (10:43 +0200)]
Improve comment on setting data_checksum GUC.

There was an extra space there, and "fixed" wasn't very descriptive.

10 years agoRemove inappropriate EXPORTS line.
Tom Lane [Thu, 20 Feb 2014 02:08:50 +0000 (21:08 -0500)]
Remove inappropriate EXPORTS line.

Looks like this gets added later ...

10 years agoAvoid using dllwrap to build pgevent in Mingw builds.
Tom Lane [Thu, 20 Feb 2014 00:34:50 +0000 (19:34 -0500)]
Avoid using dllwrap to build pgevent in Mingw builds.

If this works, we can get rid of configure's support for locating dllwrap
... but let's see what the buildfarm says, first.

Hiroshi Inoue

10 years agoFix some missing .gitignore and "make clean" items in ecpg.
Tom Lane [Wed, 19 Feb 2014 23:50:48 +0000 (18:50 -0500)]
Fix some missing .gitignore and "make clean" items in ecpg.

Some of the files we optionally link in from elsewhere weren't ignored
and/or weren't cleaned up at "make clean".  Noted while testing on a
machine that needs our version of snprintf.c.

10 years agoDocument pg_replslot in storage.sgml.
Robert Haas [Wed, 19 Feb 2014 16:57:31 +0000 (11:57 -0500)]
Document pg_replslot in storage.sgml.

Per an observation from Amit Kapila.

10 years agoSwitch various builtin functions to use pg_lsn instead of text.
Robert Haas [Wed, 19 Feb 2014 16:13:44 +0000 (11:13 -0500)]
Switch various builtin functions to use pg_lsn instead of text.

The functions in slotfuncs.c don't exist in any released version,
but the changes to xlogfuncs.c represent backward-incompatibilities.
Per discussion, we're hoping that the queries using these functions
are few enough and simple enough that this won't cause too much
breakage for users.

Michael Paquier, reviewed by Andres Freund and further modified
by me.

10 years agoFurther code review for pg_lsn data type.
Robert Haas [Wed, 19 Feb 2014 15:06:59 +0000 (10:06 -0500)]
Further code review for pg_lsn data type.

Change input function error messages to be more consistent with what is
done elsewhere.  Remove a bunch of redundant type casts, so that the
compiler will warn us if we screw up.  Don't pass LSNs by value on
platforms where a Datum is only 32 bytes, per buildfarm.  Move macros
for packing and unpacking LSNs to pg_lsn.h so that we can include
access/xlogdefs.h, to avoid an unsatisfied dependency on XLogRecPtr.

10 years agopg_lsn macro naming and type behavior revisions.
Robert Haas [Wed, 19 Feb 2014 14:34:15 +0000 (09:34 -0500)]
pg_lsn macro naming and type behavior revisions.

Change pg_lsn_mi so that it can return negative values when subtracting
LSNs, and clean up some perhaps ill-considered macro names.

10 years agoAdd a pg_lsn data type, to represent an LSN.
Robert Haas [Wed, 19 Feb 2014 13:35:23 +0000 (08:35 -0500)]
Add a pg_lsn data type, to represent an LSN.

Robert Haas and Michael Paquier

10 years agoRemove broken code that tried to handle OVERLAPS with a single argument.
Tom Lane [Tue, 18 Feb 2014 17:44:20 +0000 (12:44 -0500)]
Remove broken code that tried to handle OVERLAPS with a single argument.

The SQL standard says that OVERLAPS should have a two-element row
constructor on each side.  The original coding of OVERLAPS support in
our grammar attempted to extend that by allowing a single-element row
constructor, which it internally duplicated ... or tried to, anyway.
But that code has certainly not worked since our List infrastructure was
rewritten in 2004, and I'm none too sure it worked before that.  As it
stands, it ends up building a List that includes itself, leading to
assorted undesirable behaviors later in the parser.

Even if it worked as intended, it'd be a bit evil because of the
possibility of duplicate evaluation of a volatile function that the user
had written only once.  Given the lack of documentation, test cases, or
complaints, let's just get rid of the idea and only support the standard
syntax.

While we're at it, improve the error cursor positioning for the
wrong-number-of-arguments errors, and inline the makeOverlaps() function
since it's only called in one place anyway.

Per bug #9227 from Joshua Yanovski.  Initial patch by Joshua Yanovski,
extended a bit by me.

10 years agoDisable RandomizedBaseAddress on MSVC builds
Magnus Hagander [Tue, 18 Feb 2014 13:45:58 +0000 (14:45 +0100)]
Disable RandomizedBaseAddress on MSVC builds

The ASLR in Windows 8/Windows 2012 can break PostgreSQL's shared memory. It
doesn't fail every time (which is explained by the Random part in ASLR), but
can fail with errors abut failing to reserve shared memory region.

MauMau, reviewed by Craig Ringer

10 years agoFix comment; checkpointer, not bgwriter, performs checkpoints since 9.2.
Heikki Linnakangas [Tue, 18 Feb 2014 07:48:18 +0000 (09:48 +0200)]
Fix comment; checkpointer, not bgwriter, performs checkpoints since 9.2.

Amit Langote

10 years agoLast-minute updates for release notes.
Tom Lane [Mon, 17 Feb 2014 19:25:34 +0000 (14:25 -0500)]
Last-minute updates for release notes.

Add entries for security issues.

Security: CVE-2014-0060 through CVE-2014-0067

10 years agoFix capitalization in README.
Robert Haas [Mon, 17 Feb 2014 19:02:10 +0000 (14:02 -0500)]
Fix capitalization in README.

Vik Fearing

10 years agoImprove documentation about multixact IDs.
Tom Lane [Mon, 17 Feb 2014 17:20:57 +0000 (12:20 -0500)]
Improve documentation about multixact IDs.

Per gripe from Josh Berkus.

10 years agoDocument risks of "make check" in the regression testing instructions.
Tom Lane [Mon, 17 Feb 2014 16:24:32 +0000 (11:24 -0500)]
Document risks of "make check" in the regression testing instructions.

Since the temporary server started by "make check" uses "trust"
authentication, another user on the same machine could connect to it
as database superuser, and then potentially exploit the privileges of
the operating-system user who started the tests.  We should change
the testing procedures to prevent this risk; but discussion is required
about the best way to do that, as well as more testing than is practical
for an undisclosed security problem.  Besides, the same issue probably
affects some user-written test harnesses.  So for the moment, we'll just
warn people against using "make check" when there are untrusted users on
the same machine.

In passing, remove some ancient advice that suggested making the
regression testing subtree world-writable if you'd built as root.
That looks dangerously insecure in modern contexts, and anyway we
should not be encouraging people to build Postgres as root.

Security: CVE-2014-0067

10 years agoPrevent potential overruns of fixed-size buffers.
Tom Lane [Mon, 17 Feb 2014 16:20:21 +0000 (11:20 -0500)]
Prevent potential overruns of fixed-size buffers.

Coverity identified a number of places in which it couldn't prove that a
string being copied into a fixed-size buffer would fit.  We believe that
most, perhaps all of these are in fact safe, or are copying data that is
coming from a trusted source so that any overrun is not really a security
issue.  Nonetheless it seems prudent to forestall any risk by using
strlcpy() and similar functions.

Fixes by Peter Eisentraut and Jozef Mlich based on Coverity reports.

In addition, fix a potential null-pointer-dereference crash in
contrib/chkpass.  The crypt(3) function is defined to return NULL on
failure, but chkpass.c didn't check for that before using the result.
The main practical case in which this could be an issue is if libc is
configured to refuse to execute unapproved hashing algorithms (e.g.,
"FIPS mode").  This ideally should've been a separate commit, but
since it touches code adjacent to one of the buffer overrun changes,
I included it in this commit to avoid last-minute merge issues.
This issue was reported by Honza Horak.

Security: CVE-2014-0065 for buffer overruns, CVE-2014-0066 for crypt()

10 years agoPredict integer overflow to avoid buffer overruns.
Noah Misch [Mon, 17 Feb 2014 14:33:31 +0000 (09:33 -0500)]
Predict integer overflow to avoid buffer overruns.

Several functions, mostly type input functions, calculated an allocation
size such that the calculation wrapped to a small positive value when
arguments implied a sufficiently-large requirement.  Writes past the end
of the inadvertent small allocation followed shortly thereafter.
Coverity identified the path_in() vulnerability; code inspection led to
the rest.  In passing, add check_stack_depth() to prevent stack overflow
in related functions.

Back-patch to 8.4 (all supported versions).  The non-comment hstore
changes touch code that did not exist in 8.4, so that part stops at 9.0.

Noah Misch and Heikki Linnakangas, reviewed by Tom Lane.

Security: CVE-2014-0064

10 years agoFix handling of wide datetime input/output.
Noah Misch [Mon, 17 Feb 2014 14:33:31 +0000 (09:33 -0500)]
Fix handling of wide datetime input/output.

Many server functions use the MAXDATELEN constant to size a buffer for
parsing or displaying a datetime value.  It was much too small for the
longest possible interval output and slightly too small for certain
valid timestamp input, particularly input with a long timezone name.
The long input was rejected needlessly; the long output caused
interval_out() to overrun its buffer.  ECPG's pgtypes library has a copy
of the vulnerable functions, which bore the same vulnerabilities along
with some of its own.  In contrast to the server, certain long inputs
caused stack overflow rather than failing cleanly.  Back-patch to 8.4
(all supported versions).

Reported by Daniel Schüssler, reviewed by Tom Lane.

Security: CVE-2014-0063

10 years agoAvoid repeated name lookups during table and index DDL.
Robert Haas [Mon, 17 Feb 2014 14:33:31 +0000 (09:33 -0500)]
Avoid repeated name lookups during table and index DDL.

If the name lookups come to different conclusions due to concurrent
activity, we might perform some parts of the DDL on a different table
than other parts.  At least in the case of CREATE INDEX, this can be
used to cause the permissions checks to be performed against a
different table than the index creation, allowing for a privilege
escalation attack.

This changes the calling convention for DefineIndex, CreateTrigger,
transformIndexStmt, transformAlterTableStmt, CheckIndexCompatible
(in 9.2 and newer), and AlterTable (in 9.1 and older).  In addition,
CheckRelationOwnership is removed in 9.2 and newer and the calling
convention is changed in older branches.  A field has also been added
to the Constraint node (FkConstraint in 8.4).  Third-party code calling
these functions or using the Constraint node will require updating.

Report by Andres Freund.  Patch by Robert Haas and Andres Freund,
reviewed by Tom Lane.

Security: CVE-2014-0062

10 years agoDocument security implications of check_function_bodies.
Noah Misch [Mon, 17 Feb 2014 14:33:31 +0000 (09:33 -0500)]
Document security implications of check_function_bodies.

Back-patch to 8.4 (all supported versions).

10 years agoPrevent privilege escalation in explicit calls to PL validators.
Noah Misch [Mon, 17 Feb 2014 14:33:31 +0000 (09:33 -0500)]
Prevent privilege escalation in explicit calls to PL validators.

The primary role of PL validators is to be called implicitly during
CREATE FUNCTION, but they are also normal functions that a user can call
explicitly.  Add a permissions check to each validator to ensure that a
user cannot use explicit validator calls to achieve things he could not
otherwise achieve.  Back-patch to 8.4 (all supported versions).
Non-core procedural language extensions ought to make the same two-line
change to their own validators.

Andres Freund, reviewed by Tom Lane and Noah Misch.

Security: CVE-2014-0061

10 years agoShore up ADMIN OPTION restrictions.
Noah Misch [Mon, 17 Feb 2014 14:33:31 +0000 (09:33 -0500)]
Shore up ADMIN OPTION restrictions.

Granting a role without ADMIN OPTION is supposed to prevent the grantee
from adding or removing members from the granted role.  Issuing SET ROLE
before the GRANT bypassed that, because the role itself had an implicit
right to add or remove members.  Plug that hole by recognizing that
implicit right only when the session user matches the current role.
Additionally, do not recognize it during a security-restricted operation
or during execution of a SECURITY DEFINER function.  The restriction on
SECURITY DEFINER is not security-critical.  However, it seems best for a
user testing his own SECURITY DEFINER function to see the same behavior
others will see.  Back-patch to 8.4 (all supported versions).

The SQL standards do not conflate roles and users as PostgreSQL does;
only SQL roles have members, and only SQL users initiate sessions.  An
application using PostgreSQL users and roles as SQL users and roles will
never attempt to grant membership in the role that is the session user,
so the implicit right to add or remove members will never arise.

The security impact was mostly that a role member could revoke access
from others, contrary to the wishes of his own grantor.  Unapproved role
member additions are less notable, because the member can still largely
achieve that by creating a view or a SECURITY DEFINER function.

Reviewed by Andres Freund and Tom Lane.  Reported, independently, by
Jonas Sundman and Noah Misch.

Security: CVE-2014-0060

10 years agoRelease notes for 9.3.3, 9.2.7, 9.1.12, 9.0.16, 8.4.20.
Tom Lane [Mon, 17 Feb 2014 03:08:28 +0000 (22:08 -0500)]
Release notes for 9.3.3, 9.2.7, 9.1.12, 9.0.16, 8.4.20.

10 years agoPGDLLIMPORT-ify MainLWLockArray, ProcDiePending, proc_exit_inprogress.
Tom Lane [Mon, 17 Feb 2014 01:12:43 +0000 (20:12 -0500)]
PGDLLIMPORT-ify MainLWLockArray, ProcDiePending, proc_exit_inprogress.

These are needed in HEAD to make assorted contrib modules build on Windows.
Now that all the MSVC and Mingw buildfarm members seem to be on the same
page about the need for them, we can have some confidence that future
problems of this ilk will be detected promptly; there seems nothing more
to be learned by delaying this fix further.

I chose to mark QueryCancelPending as well, since it's easy to imagine code
that wants to touch ProcDiePending also caring about QueryCancelPending.

10 years agoFix unportable coding in tarCreateHeader().
Tom Lane [Mon, 17 Feb 2014 01:01:18 +0000 (20:01 -0500)]
Fix unportable coding in tarCreateHeader().

uid_t and gid_t might be wider than int on some platforms.
Per buildfarm member brolga.

10 years agoRevert to using --enable-auto-import in Cygwin builds.
Tom Lane [Sun, 16 Feb 2014 20:14:04 +0000 (15:14 -0500)]
Revert to using --enable-auto-import in Cygwin builds.

Disabling auto-import requires that all libraries we use be careful about
declspecs for exported variables; and it seems they aren't.  This means
that Cygwin will not give us useful info about missing PGDLLIMPORT markers;
but it's probably sufficient that MSVC and Mingw builds do.

10 years agoFurther wordsmithing on 9.3.3 release notes.
Tom Lane [Sun, 16 Feb 2014 19:54:28 +0000 (14:54 -0500)]
Further wordsmithing on 9.3.3 release notes.

No substantive changes, but reorder some items and improve some
descriptions.

10 years agoPGDLLIMPORT'ify DateStyle and IntervalStyle.
Tom Lane [Sun, 16 Feb 2014 17:37:07 +0000 (12:37 -0500)]
PGDLLIMPORT'ify DateStyle and IntervalStyle.

This is needed on Windows to support contrib/postgres_fdw.  Although it's
been broken since last March, we didn't notice until recently because there
were no active buildfarm members that complained about missing PGDLLIMPORT
marking.  Efforts are underway to improve that situation, in support of
which we're delaying fixing some other cases of global variables that
should be marked PGDLLIMPORT.  However, this case affects 9.3, so we
can't wait any longer to fix it.

I chose to mark DateOrder as well, though it's not strictly necessary
for postgres_fdw.

10 years agoImprove release notes per comments from Andres Freund.
Tom Lane [Sun, 16 Feb 2014 17:03:54 +0000 (12:03 -0500)]
Improve release notes per comments from Andres Freund.

Make a bit more noise about the timeout-interrupt bug.  Also, remove the
release note entry for commit 423e1211a; that patch fixed a problem
introduced post-9.3.2, so there's no need to document it in the release
notes.

10 years agoOn Windows, expect to find Tcl DLL in bin directory not lib directory.
Tom Lane [Sun, 16 Feb 2014 16:24:38 +0000 (11:24 -0500)]
On Windows, expect to find Tcl DLL in bin directory not lib directory.

Still another step in the continuing saga of trying to get
--disable-auto-import to work.

Hiroshi Inoue

10 years agoFirst-draft release notes for 9.3.3.
Tom Lane [Sun, 16 Feb 2014 05:40:37 +0000 (00:40 -0500)]
First-draft release notes for 9.3.3.

As usual, the release notes for older branches will be made by cutting
these down, but put them up for community review first.

10 years agoFix unportable coding in BackgroundWorkerStateChange().
Tom Lane [Sat, 15 Feb 2014 22:15:05 +0000 (17:15 -0500)]
Fix unportable coding in BackgroundWorkerStateChange().

PIDs aren't necessarily ints; our usual practice for printing them
is to explicitly cast to long.  Per buildfarm member rover_firefly.

10 years agoFix unportable coding in DetermineSleepTime().
Tom Lane [Sat, 15 Feb 2014 22:09:50 +0000 (17:09 -0500)]
Fix unportable coding in DetermineSleepTime().

We should not assume that struct timeval.tv_sec is a long, because
it ain't necessarily.  (POSIX says that it's a time_t, which might
well be 64 bits now or in the future; or for that matter might be
32 bits on machines with 64-bit longs.)  Per buildfarm member panther.

Back-patch to 9.3 where the dubious coding was introduced.

10 years agoCentralize getopt-related declarations in a new header file pg_getopt.h.
Tom Lane [Sat, 15 Feb 2014 19:31:30 +0000 (14:31 -0500)]
Centralize getopt-related declarations in a new header file pg_getopt.h.

We used to have externs for getopt() and its API variables scattered
all over the place.  Now that we find we're going to need to tweak the
variable declarations for Cygwin, it seems like a good idea to have
just one place to tweak.

In this commit, the variables are declared "#ifndef HAVE_GETOPT_H".
That may or may not work everywhere, but we'll soon find out.

Andres Freund

10 years agoRemove use of sscanf in pg_upgrade, and add C comment to pg_dump
Bruce Momjian [Sat, 15 Feb 2014 16:50:56 +0000 (11:50 -0500)]
Remove use of sscanf in pg_upgrade, and add C comment to pg_dump

Per report from Jackie Chang

10 years agopsql: Add C comment about gset_prefix being freed later
Bruce Momjian [Sat, 15 Feb 2014 05:09:24 +0000 (00:09 -0500)]
psql:  Add C comment about gset_prefix being freed later

10 years agoOoops, forgot to remove solar87 and friends from src/timezone/Makefile.
Tom Lane [Sat, 15 Feb 2014 04:20:08 +0000 (23:20 -0500)]
Ooops, forgot to remove solar87 and friends from src/timezone/Makefile.

Per buildfarm.

10 years agoUpdate time zone data files to tzdata release 2013i.
Tom Lane [Sat, 15 Feb 2014 02:59:13 +0000 (21:59 -0500)]
Update time zone data files to tzdata release 2013i.

DST law changes in Jordan; historical changes in Cuba.

Also, remove the zones Asia/Riyadh87, Asia/Riyadh88, and Asia/Riyadh89.
Per the upstream announcement:
    The files solar87, solar88, and solar89 are no longer distributed.
    They were a negative experiment -- that is, a demonstration that
    tz data can represent solar time only with some difficulty and error.
    Their presence in the distribution caused confusion, as Riyadh
    civil time was generally not solar time in those years.

10 years agoFix fat-fingered makefile changes for pltcl.
Tom Lane [Fri, 14 Feb 2014 22:10:53 +0000 (17:10 -0500)]
Fix fat-fingered makefile changes for pltcl.

I put the OBJS assignments in the wrong order.  Per buildfarm.

10 years agoUpdate regression testing instructions.
Tom Lane [Fri, 14 Feb 2014 21:50:22 +0000 (16:50 -0500)]
Update regression testing instructions.

This documentation never got the word about the existence of check-world or
installcheck-world.  Revise to recommend use of those, and document all the
subsidiary test suites.  Do some minor wordsmithing elsewhere, too.

In passing, remove markup related to generation of plain-text regression
test instructions, since we don't do that anymore.

Back-patch to 9.1 where check-world was added.  (installcheck-world exists
in 9.0; but since check-world doesn't, this patch would need additional
work to cover that branch, and it doesn't seem worth the effort.)

10 years agoIn mingw builds, make our own import library for libtcl, too.
Tom Lane [Fri, 14 Feb 2014 18:13:06 +0000 (13:13 -0500)]
In mingw builds, make our own import library for libtcl, too.

Per buildfarm results.

10 years agoSuggest shell here-documents instead of psql -c for multiple commands.
Tom Lane [Fri, 14 Feb 2014 17:54:39 +0000 (12:54 -0500)]
Suggest shell here-documents instead of psql -c for multiple commands.

The documentation suggested using "echo | psql", but not the often-superior
alternative of a here-document.  Also, be more direct about suggesting
that people avoid -c for multiple commands.  Per discussion.

10 years agoIn mingw builds, make our own import library for libperl.
Tom Lane [Fri, 14 Feb 2014 16:51:02 +0000 (11:51 -0500)]
In mingw builds, make our own import library for libperl.

Borrow the method already used by plpython.  This is pretty ugly, but
it might fix the build failure exhibited by buildfarm member narwhal
since commit 846e91e0223cf9f2821c3ad4dfffffbb929cb027.

Hiroshi Inoue

10 years agoCosmetic improvements in plpython's make rule for libpython import library.
Tom Lane [Fri, 14 Feb 2014 16:31:35 +0000 (11:31 -0500)]
Cosmetic improvements in plpython's make rule for libpython import library.

This build technique is remarkably ugly, but that doesn't mean it has
to be unreadable too.  Be a bit more liberal with the vertical whitespace,
and give the .def file a proper dependency, just in case.

10 years agoChange the order that pg_xlog and WAL archive are polled for WAL segments.
Heikki Linnakangas [Fri, 14 Feb 2014 13:15:09 +0000 (15:15 +0200)]
Change the order that pg_xlog and WAL archive are polled for WAL segments.

If there is a WAL segment with same ID but different TLI present in both
the WAL archive and pg_xlog, prefer the one with higher TLI. Before this
patch, the archive was polled first, for all expected TLIs, and only if no
file was found was pg_xlog scanned. This was a change in behavior from 9.3,
which first scanned archive and pg_xlog for the highest TLI, then archive
and pg_xlog for the next highest TLI and so forth. This patch reverts the
behavior back to what it was in 9.2.

The reason for this is that if for example you try to do archive recovery
to timeline 2, which branched off timeline 1, but the WAL for timeline 2 is
not archived yet, we would replay past the timeline switch point on
timeline 1 using the archived files, before even looking timeline 2's files
in pg_xlog

Report and patch by Kyotaro Horiguchi. Backpatch to 9.3 where the behavior
was changed.

10 years agoFix typo
Peter Eisentraut [Fri, 14 Feb 2014 02:50:43 +0000 (21:50 -0500)]
Fix typo

Stefan Kaltenbrunner

10 years agoAdd C comment about problems with CHAR() space trimming
Bruce Momjian [Fri, 14 Feb 2014 02:45:57 +0000 (21:45 -0500)]
Add C comment about problems with CHAR() space trimming

10 years agoClean up error cases in psql's COPY TO STDOUT/FROM STDIN code.
Tom Lane [Thu, 13 Feb 2014 23:45:12 +0000 (18:45 -0500)]
Clean up error cases in psql's COPY TO STDOUT/FROM STDIN code.

Adjust handleCopyOut() to stop trying to write data once it's failed
one time.  For typical cases such as out-of-disk-space or broken-pipe,
additional attempts aren't going to do anything but waste time, and
in any case clean truncation of the output seems like a better behavior
than randomly dropping blocks in the middle.

Also remove dubious (and misleadingly documented) attempt to force our way
out of COPY_OUT state if libpq didn't do that.  If we did have a situation
like that, it'd be a bug in libpq and would be better fixed there, IMO.
We can hope that commit fa4440f51628d692f077d54b8313aea31af087ea took care
of any such problems, anyway.

Also fix longstanding bug in handleCopyIn(): PQputCopyEnd() only supports
a non-null errormsg parameter in protocol version 3, and will actively
fail if one is passed in version 2.  This would've made our attempts
to get out of COPY_IN state after a failure into infinite loops when
talking to pre-7.4 servers.

Back-patch the COPY_OUT state change business back to 9.2 where it was
introduced, and the other two fixes into all supported branches.

10 years agoSeparate multixact freezing parameters from xid's
Alvaro Herrera [Thu, 13 Feb 2014 22:30:30 +0000 (19:30 -0300)]
Separate multixact freezing parameters from xid's

Previously we were piggybacking on transaction ID parameters to freeze
multixacts; but since there isn't necessarily any relationship between
rates of Xid and multixact consumption, this turns out not to be a good
idea.

Therefore, we now have multixact-specific freezing parameters:

vacuum_multixact_freeze_min_age: when to remove multis as we come across
them in vacuum (default to 5 million, i.e. early in comparison to Xid's
default of 50 million)

vacuum_multixact_freeze_table_age: when to force whole-table scans
instead of scanning only the pages marked as not all visible in
visibility map (default to 150 million, same as for Xids).  Whichever of
both which reaches the 150 million mark earlier will cause a whole-table
scan.

autovacuum_multixact_freeze_max_age: when for cause emergency,
uninterruptible whole-table scans (default to 400 million, double as
that for Xids).  This means there shouldn't be more frequent emergency
vacuuming than previously, unless multixacts are being used very
rapidly.

Backpatch to 9.3 where multixacts were made to persist enough to require
freezing.  To avoid an ABI break in 9.3, VacuumStmt has a couple of
fields in an unnatural place, and StdRdOptions is split in two so that
the newly added fields can go at the end.

Patch by me, reviewed by Robert Haas, with additional input from Andres
Freund and Tom Lane.

10 years agodocs: improve CREATE FUNCTION docs about language case and quoting
Bruce Momjian [Thu, 13 Feb 2014 22:07:05 +0000 (17:07 -0500)]
docs: improve CREATE FUNCTION docs about language case and quoting

Report from Marc Mamin

10 years agopgcrypto: clarify 'md5' (hash) table entry
Bruce Momjian [Thu, 13 Feb 2014 20:38:30 +0000 (15:38 -0500)]
pgcrypto: clarify 'md5' (hash) table entry

Per suggestion from Peter Eisentraut

10 years agoFix length checking for Unicode identifiers containing escapes (U&"...").
Tom Lane [Thu, 13 Feb 2014 19:24:42 +0000 (14:24 -0500)]
Fix length checking for Unicode identifiers containing escapes (U&"...").

We used the length of the input string, not the de-escaped string, as
the trigger for NAMEDATALEN truncation.  AFAICS this would only result
in sometimes printing a phony truncation warning; but it's just luck
that there was no worse problem, since we were violating the API spec
for truncate_identifier().  Per bug #9204 from Joshua Yanovski.

This has been wrong since the Unicode-identifier support was added,
so back-patch to all supported branches.

10 years agopg_upgrade: mention the need for tablespace snapshots in docs
Bruce Momjian [Thu, 13 Feb 2014 10:06:22 +0000 (05:06 -0500)]
pg_upgrade:  mention the need for tablespace snapshots in docs

10 years agopg_upgrade: document use of file system and COW snapshots
Bruce Momjian [Thu, 13 Feb 2014 03:06:38 +0000 (22:06 -0500)]
pg_upgrade: document use of file system and COW snapshots

10 years agoImprove cross-references between minor version release notes.
Tom Lane [Thu, 13 Feb 2014 00:09:18 +0000 (19:09 -0500)]
Improve cross-references between minor version release notes.

We have a practice of providing a "bread crumb" trail between the minor
versions where the migration section actually tells you to do something.
Historically that was just plain text, eg, "see the release notes for
9.2.4"; but if you're using a browser or PDF reader, it's a lot nicer
if it's a live hyperlink.  So use "<xref>" instead.  Any argument against
doing this vanished with the recent decommissioning of plain-text release
notes.

Vik Fearing

10 years agoImprove text of stub HISTORY file.
Tom Lane [Wed, 12 Feb 2014 23:16:17 +0000 (18:16 -0500)]
Improve text of stub HISTORY file.

Per Peter Eisentraut.

10 years agoImprove libpq's error recovery for connection loss during COPY.
Tom Lane [Wed, 12 Feb 2014 22:50:07 +0000 (17:50 -0500)]
Improve libpq's error recovery for connection loss during COPY.

In pqSendSome, if the connection is already closed at entry, discard any
queued output data before returning.  There is no possibility of ever
sending the data, and anyway this corresponds to what we'd do if we'd
detected a hard error while trying to send().  This avoids possible
indefinite bloat of the output buffer if the application keeps trying
to send data (or even just keeps trying to do PQputCopyEnd, as psql
indeed will).

Because PQputCopyEnd won't transition out of PGASYNC_COPY_IN state
until it's successfully queued the COPY END message, and pqPutMsgEnd
doesn't distinguish a queuing failure from a pqSendSome failure,
this omission allowed an infinite loop in psql if the connection closure
occurred when we had at least 8K queued to send.  It might be worth
refactoring so that we can make that distinction, but for the moment
the other changes made here seem to offer adequate defenses.

To guard against other variants of this scenario, do not allow
PQgetResult to return a PGRES_COPY_XXX result if the connection is
already known dead.  Make sure it returns PGRES_FATAL_ERROR instead.

Per report from Stephen Frost.  Back-patch to all active branches.

10 years agoRevert gmake/make release note changes
Bruce Momjian [Wed, 12 Feb 2014 22:32:20 +0000 (17:32 -0500)]
Revert gmake/make release note changes

Backbranch release note changes cause merge conflicts.

10 years agoRename 'gmake' to 'make' in docs and recommended commands
Bruce Momjian [Wed, 12 Feb 2014 22:29:19 +0000 (17:29 -0500)]
Rename 'gmake' to 'make' in docs and recommended commands

This simplifies the docs and makes it easier to cut/paste command lines.

10 years agopg_upgrade: dramatically reduce memory consumption
Bruce Momjian [Wed, 12 Feb 2014 21:35:24 +0000 (16:35 -0500)]
pg_upgrade: dramatically reduce memory consumption

Report from Jeff Janes

10 years agopg_test_fsync: add C comment about direct I/O and write size failure
Bruce Momjian [Wed, 12 Feb 2014 20:38:14 +0000 (15:38 -0500)]
pg_test_fsync: add C comment about direct I/O and write size failure

Report from Marti Raudsepp

10 years agoIn XLogReadBufferExtended, don't assume P_NEW yields consecutive pages.
Tom Lane [Wed, 12 Feb 2014 19:52:16 +0000 (14:52 -0500)]
In XLogReadBufferExtended, don't assume P_NEW yields consecutive pages.

In a database that's not yet reached consistency, it's possible that some
segments of a relation are not full-size but are not the last ones either.
Because of the way smgrnblocks() works, asking for a new page with P_NEW
will fill in the last not-full-size segment --- and if that makes it full
size, the apparent EOF of the relation will increase by more than one page,
so that the next P_NEW request will yield a page past the next consecutive
one.  This breaks the relation-extension logic in XLogReadBufferExtended,
possibly allowing a page update to be applied to some page far past where
it was intended to go.  This appears to be the explanation for reports of
table bloat on replication slaves compared to their masters, and probably
explains some corrupted-slave reports as well.

Fix the loop to check the page number it actually got, rather than merely
Assert()'ing that dead reckoning got it to the desired place.  AFAICT,
there are no other places that make assumptions about exactly which page
they'll get from P_NEW.

Problem identified by Greg Stark, though this is not the same as his
proposed patch.

It's been like this for a long time, so back-patch to all supported
branches.

10 years agoAdd missing include, required on some platforms
Magnus Hagander [Wed, 12 Feb 2014 19:04:13 +0000 (20:04 +0100)]
Add missing include, required on some platforms

Noted by the buildfarm and Andres Freund

10 years agoKill pg_basebackup background process when exiting
Magnus Hagander [Sun, 9 Feb 2014 12:10:14 +0000 (13:10 +0100)]
Kill pg_basebackup background process when exiting

If an error occurs in the foreground (backup) process of pg_basebackup,
and we exit in a controlled way, the background process (streaming
xlog process) would stay around and keep streaming.

10 years agoUse --disable-auto-import linker switch in Mingw builds, too.
Tom Lane [Wed, 12 Feb 2014 17:03:53 +0000 (12:03 -0500)]
Use --disable-auto-import linker switch in Mingw builds, too.

This is evidently the default on buildfarm member narwhal, but that
is a pretty ancient Mingw version, and there is reason to think that
more recent versions of GNU ld have this feature turned on by default.
Since we are trying to achieve consistency of link behavior across
all Windows toolchains, let's just make sure here.

10 years agoRemove --enable-auto-import linker switch in Cygwin build.
Tom Lane [Wed, 12 Feb 2014 16:53:07 +0000 (11:53 -0500)]
Remove --enable-auto-import linker switch in Cygwin build.

This is expected to make it start failing when contrib modules
reference non-PGDLLIMPORT'ed global variables, as the other Windows
build methods do.  Aside from the value of consistency, the underlying
implementation of this switch is pretty ugly and not really something
we want to rely on if we have to use PGDLLIMPORT anyway for MSVC.