Commit Graph

32262 Commits

Author SHA1 Message Date
Robert Haas 68cbb9f4e7 Modestly improve pgbench's checking for invalid ranges.
The old check against MAX_RANDOM_VALUE is clearly irrelevant since
getrand() no longer calls random().  Instead, check whether min and max
are close enough together to avoid an overflow inside getrand(), as
suggested by Tom Lane.  This is still somewhat silly, because we're
using atoi(), which doesn't check for overflow anyway and (at least on
my system) will cheerfully return 0 when given "4294967296".  But that's
a problem for another commit.
2011-08-05 12:53:03 -04:00
Robert Haas b43bf617fd Tweak PQresStatus() to avoid a clang compiler warning.
The previous test for status < 0 test is in fact testing nothing if the
compiler considers an enum to be an unsigned data type.  clang doesn't
like tautologies, so do this instead.

Report by Peter Geoghegan, fix as suggested by Tom Lane.
2011-08-05 12:06:29 -04:00
Bruce Momjian 4262e61d64 Fix markup for recent wal_level clarification.
Backpatch to 9.1 and 9.0.
2011-08-04 15:02:02 -04:00
Andrew Dunstan a11cf43341 Restore the primacy of postgres.h in plpython.c.
To avoid having the python headers hijack various definitions,
we now include them after all the system headers we want, having
first undefined some of the things they want to define. After that's
done we restore the things they scribbled on that matter, namely our
snprintf and vsnprintf macros, if we're using them.
2011-08-04 13:05:32 -04:00
Robert Haas 84e3712677 Create VXID locks "lazily" in the main lock table.
Instead of entering them on transaction startup, we materialize them
only when someone wants to wait, which will occur only during CREATE
INDEX CONCURRENTLY.  In Hot Standby mode, the startup process must also
be able to probe for conflicting VXID locks, but the lock need never be
fully materialized, because the startup process does not use the normal
lock wait mechanism.  Since most VXID locks never need to touch the
lock manager partition locks, this can significantly reduce blocking
contention on read-heavy workloads.

Patch by me.  Review by Jeff Davis.
2011-08-04 12:38:33 -04:00
Robert Haas 3b17efdfdd Teach psql to display comments on languages and casts.
The output of \dL (list languages) is fairly narrow, so we just always
display the comment.  \dC (list casts) can get fairly wide, so we only
display comments if the new \dC+ option is specified.

Josh Kupershmidt
2011-08-04 12:22:26 -04:00
Bruce Momjian 38de5aad54 In documentaiton, clarify which commands have reduced WAL volume for
wal_level = minimum.

Backpatch to 9.1 and 9.0.
2011-08-04 12:06:53 -04:00
Robert Haas 4af43ee3f1 Make pgbench use erand48() rather than random().
glibc renders random() thread-safe by wrapping a futex lock around it;
testing reveals that this limits the performance of pgbench on machines
with many CPU cores.  Rather than switching to random_r(), which is
only available on GNU systems and crashes unless you use undocumented
alchemy to initialize the random state properly, switch to our built-in
implementation of erand48(), which is both thread-safe and concurrent.

Since the list of reasons not to use the operating system's erand48()
is getting rather long, rename ours to pg_erand48() (and similarly
for our implementations of lrand48() and srand48()) and just always
use those.  We were already doing this on Cygwin anyway, and the
glibc implementation is not quite thread-safe, so pgbench wouldn't
be able to use that either.

Per discussion with Tom Lane.
2011-08-03 16:26:40 -04:00
Tom Lane ac36e6f71f Move CheckRecoveryConflictDeadlock() call to a safer place.
This kluge was inserted in a spot apparently chosen at random: the lock
manager's state is not yet fully set up for the wait, and in particular
LockWaitCancel hasn't been armed by setting lockAwaited, so the ProcLock
will not get cleaned up if the ereport is thrown.  This seems to not cause
any observable problem in trivial test cases, because LockReleaseAll will
silently clean up the debris; but I was able to cause failures with tests
involving subtransactions.

Fixes breakage induced by commit c85c941470.
Back-patch to all affected branches.
2011-08-02 15:16:29 -04:00
Tom Lane 2e53bd5517 Fix incorrect initialization of ProcGlobal->startupBufferPinWaitBufId.
It was initialized in the wrong place and to the wrong value.  With bad
luck this could result in incorrect query-cancellation failures in hot
standby sessions, should a HS backend be holding pin on buffer number 1
while trying to acquire a lock.
2011-08-02 13:23:52 -04:00
Heikki Linnakangas 89df948ec2 Avoid integer overflow when LIMIT + OFFSET >= 2^63.
This fixes bug #6139 reported by Hitoshi Harada.
2011-08-02 10:47:17 +03:00
Robert Haas 85b436f7b1 Minor stylistic corrections. 2011-08-01 08:24:45 -04:00
Peter Eisentraut 8a0fa9cad9 Add host name resolution information to pg_hba.conf error messages
This is to be able to analyze issues with host names in pg_hba.conf.
2011-07-31 18:03:43 +03:00
Bruce Momjian a31dc392d6 Fix pg_update to properly test for the data directory's existence on
Win32.

Backpatch to 9.1.
2011-07-30 01:50:55 -04:00
Robert Haas b4fbe392f8 Reduce sinval synchronization overhead.
Testing shows that the overhead of acquiring and releasing
SInvalReadLock and msgNumLock on high-core count boxes can waste a lot
of CPU time and hurt performance.  This patch adds a per-backend flag
that allows us to skip all that locking in most cases.  Further
testing shows that this improves performance even when sinval traffic
is very high.

Patch by me.  Review and testing by Noah Misch.
2011-07-29 16:46:13 -04:00
Robert Haas 60fb25a3f5 Move new pgbench options to correct section of --help output. 2011-07-29 16:43:57 -04:00
Tom Lane 6545a901aa Fix pg_restore's direct-to-database mode for standard_conforming_strings.
pg_backup_db.c contained a mini SQL lexer with which it tried to identify
boundaries between SQL commands, but that code was not designed to cope
with standard_conforming_strings, and would get the wrong answer if a
backslash immediately precedes a closing single quote in such a string,
as per report from Julian Mehnle.  The bug only affects direct-to-database
restores from archive files made with standard_conforming_strings = on.

Rather than complicating the code some more to try to fix that, let's just
rip it all out.  The only reason it was needed was to cope with COPY data
embedded into ordinary archive entries, which was a layout that was used
only for about the first three weeks of the archive format's existence,
and never in any production release of pg_dump.  Instead, just rely on the
archive file layout to tell us whether we're printing COPY data or not.

This bug represents a data corruption hazard in all releases in which
standard_conforming_strings can be turned on, ie 8.2 and later, so
back-patch to all supported branches.
2011-07-28 14:06:57 -04:00
Peter Eisentraut 0fe8150827 Minor message style adjustment 2011-07-27 23:54:46 +03:00
Robert Haas a8302803ab Fix typo.
Noted by Josh Kupershmidt.
2011-07-27 11:20:07 -04:00
Tom Lane c1420fcf7d Check to see whether libxml2 handles error context the way we expect.
It turns out to be possible to link against a libxml2.so that does this
differently than the version we configured and built against, so we need
a runtime check to avoid bizarre behavior.  Per report from Bernd Helmle.
Patch by Florian Pflug.
2011-07-26 16:31:04 -04:00
Peter Eisentraut e67efb01e8 Add missing newlines at end of error messages 2011-07-26 23:23:18 +03:00
Peter Eisentraut ce8d7bb644 Replace printf format %i by %d
They are identical, but the overwhelming majority of the code uses %d,
so standardize on that.
2011-07-26 22:54:29 +03:00
Robert Haas 8c18f3f0e1 Only display column comments for relkinds that support them.
Josh Kupershmidt, with minor modifications by me.
2011-07-26 09:52:31 -04:00
Robert Haas c80be8a816 Clarify which relkinds accept column comments.
Per discussion with Josh Kupershmidt.
2011-07-26 09:39:07 -04:00
Andrew Dunstan c9737310d5 Don't build replacement getpeereid function on mingw.
Windows doesn't have Unix sockets, so it's not needed, and moreover causes compile warnings.
2011-07-25 23:48:44 -04:00
Andrew Dunstan 74e6d37276 Silence compiler warning about uninitialized variable.
It is set correctly on the only path that uses it, but the
compiler can't know that.
2011-07-25 19:37:17 -04:00
Robert Haas 8cca49d8a0 Add some environment checks prior to sepgsql regression testing.
This probably needs more work, but it's a start.

KaiGai Kohei
2011-07-25 10:51:02 -04:00
Robert Haas f5af8eed92 Improvements to SQL/MED documentation.
Laurenz Albe, somewhat modified by me.
2011-07-25 09:37:06 -04:00
Robert Haas 7c26395661 Add new pgbench options, --tablespace and --index-tablespace.
Per a request from Greg Smith.
2011-07-25 09:16:14 -04:00
Robert Haas 2d6fee09eb Add new pgbench switch, --unlogged-tables.
This entails adjusting pgbench to use getopt_long() rather
than getopt().
2011-07-25 06:55:12 -04:00
Tom Lane bcf23ba4bf Fix previous patch so it also works if not USE_SSL (mea culpa).
On balance, the need to cover this case changes my mind in favor of pushing
all error-message generation duties into the two fe-secure.c routines.
So do it that way.
2011-07-24 23:29:03 -04:00
Tom Lane fee476da95 Improve libpq's error reporting for SSL failures.
In many cases, pqsecure_read/pqsecure_write set up useful error messages,
which were then overwritten with useless ones by their callers.  Fix this
by defining the responsibility to set an error message to be entirely that
of the lower-level function when using SSL.

Back-patch to 8.3; the code is too different in 8.2 to be worth the
trouble.
2011-07-24 16:29:07 -04:00
Tom Lane d0c23026b2 Use OpenSSL's SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER flag.
This disables an entirely unnecessary "sanity check" that causes failures
in nonblocking mode, because OpenSSL complains if we move or compact the
write buffer.  The only actual requirement is that we not modify pending
data once we've attempted to send it, which we don't.  Per testing and
research by Martin Pihlak, though this fix is a lot simpler than his patch.

I put the same change into the backend, although it's less clear whether
it's necessary there.  We do use nonblock mode in some situations in
streaming replication, so seems best to keep the same behavior in the
backend as in libpq.

Back-patch to all supported releases.
2011-07-24 15:17:51 -04:00
Bruce Momjian 081a5518c0 In pg_upgrade on Windows, check if the directory is writable by actually
creating and removing a file because access() doesn't work on that
platform.

Backpatch to 9.1 where this check was added.
2011-07-24 01:43:57 -04:00
Andrew Dunstan e399eb74d9 Unbreak Windows builds broken by EDITOR_LINENUMBER_ARG change. 2011-07-23 19:33:17 -04:00
Peter Eisentraut 79b3ca06d8 Change EDITOR_LINENUMBER_SWITCH to an environment variable
Also change "switch" to "arg" because "switch" is a bit of a sloppy
term.  So the environment variable is called
PSQL_EDITOR_LINENUMBER_ARG.  Set "+" as hardcoded default value on
Unix (since "vi" is the hardcoded default editor), so many users won't
have to configure this at all.  Move the documentation around a bit to
centralize the editor configuration under environment variables,
rather than repeating bits of it under every backslash command that
invokes an editor.
2011-07-24 00:25:29 +03:00
Tom Lane 988cccc620 Rethink behavior of CREATE OR REPLACE during CREATE EXTENSION.
The original implementation simply did nothing when replacing an existing
object during CREATE EXTENSION.  The folly of this was exposed by a report
from Marc Munro: if the existing object belongs to another extension, we
are left in an inconsistent state.  We should insist that the object does
not belong to another extension, and then add it to the current extension
if not already a member.
2011-07-23 16:59:39 -04:00
Robert Haas 6f1be5a67a Unbreak unlogged tables.
I broke this in commit 5da79169d3, which
was obviously insufficiently well tested.  Add some regression tests
in the hope of making future slip-ups more likely to be noticed.
2011-07-22 16:15:43 -04:00
Bruce Momjian 43aa40e155 In pg_upgrade, add C comment about why we don't try to do shared file
writes for logging.
2011-07-21 17:13:17 -04:00
Tom Lane a9f0dbc39d Fix PQsetvalue() to avoid possible crash when adding a new tuple.
PQsetvalue unnecessarily duplicated the logic in pqAddTuple, and didn't
duplicate it exactly either --- pqAddTuple does not care what is in the
tuple-pointer array positions beyond the last valid entry, whereas the
code in PQsetvalue assumed such positions would contain NULL.  This led
to possible crashes if PQsetvalue was applied to a PGresult that had
previously been enlarged with pqAddTuple, for instance one built from a
server query.  Fix by relying on pqAddTuple instead of duplicating logic,
and not assuming anything about the contents of res->tuples[res->ntups].

Back-patch to 8.4, where PQsetvalue was introduced.

Andrew Chernow
2011-07-21 12:24:14 -04:00
Tom Lane 0ce7676aa0 Make xpath() do something useful with XPath expressions that return scalars.
Previously, xpath() simply returned an empty array if the expression did
not yield a node set.  This is useless for expressions that return scalars,
such as one with name() at the top level.  Arrange to return the scalar
value as a single-element xml array, instead.  (String values will be
suitably escaped.)

This change will also cause xpath_exists() to return true, not false,
for such expressions.

Florian Pflug, reviewed by Radoslaw Smogura
2011-07-21 11:32:46 -04:00
Tom Lane aaf15e5c1c Ensure that xpath() escapes special characters in string values.
Without this it's possible for the output to not be legal XML, as
illustrated by the added regression test cases.

NB: this change will need to be called out as an incompatibility in the
9.2 release notes, since it's possible somebody was relying on the old
behavior, even though it's clearly wrong.

Florian Pflug, reviewed by Radoslaw Smogura
2011-07-20 18:44:35 -04:00
Bruce Momjian 17a16eeb7c In pg_upgrade, fix the -l/log option to work on Windows.
Also, double-quote the log file name in all places, to allow (on all
platforms) log file names with spaces.

Back patch to 9.0 and 9.1.
2011-07-20 18:31:03 -04:00
Bruce Momjian 6b43fddee4 In pg_upgrade, use pg_strudup(), for consistency. 2011-07-20 16:37:17 -04:00
Robert Haas 463f2625a5 Support SECURITY LABEL on databases, tablespaces, and roles.
This requires a new shared catalog, pg_shseclabel.

Along the way, fix the security_label regression tests so that they
don't monkey with the labels of any pre-existing objects.  This is
unlikely to matter in practice, since only the label for the "dummy"
provider was being manipulated.  But this way still seems cleaner.

KaiGai Kohei, with fairly extensive hacking by me.
2011-07-20 13:18:24 -04:00
Tom Lane cacd42d62c Rewrite libxml error handling to be more robust.
libxml reports some errors (like invalid xmlns attributes) via the error
handler hook, but still returns a success indicator to the library caller.
This causes us to miss some errors that are important to report.  Since the
"generic" error handler hook doesn't know whether the message it's getting
is for an error, warning, or notice, stop using that and instead start
using the "structured" error handler hook, which gets enough information
to be useful.

While at it, arrange to save and restore the error handler hook setting in
each libxml-using function, rather than assuming we can set and forget the
hook.  This should improve the odds of working nicely with third-party
libraries that also use libxml.

In passing, volatile-ize some local variables that get modified within
PG_TRY blocks.  I noticed this while testing with an older gcc version
than I'd previously tried to compile xml.c with.

Florian Pflug and Tom Lane, with extensive review/testing by Noah Misch
2011-07-20 13:03:49 -04:00
Robert Haas d79a601fd9 Improve sepgsql and SECURITY LABEL documentation.
KaiGai Kohei, based on feedback from Yeb Havinga, with some
corrections by me.
2011-07-20 09:24:26 -04:00
Robert Haas 550cd074f9 Minor improvement to pg_seclabel documentation.
This is a bit more consistent with the way pg_description is
documented, and also include a useful cross-link.
2011-07-20 09:24:22 -04:00
Alvaro Herrera c8dfc89232 Make isolationtester more robust on locked commands
Noah Misch diagnosed the buildfarm problems in the isolation tests
partly as failure to differentiate backends properly; the old code was
using backend IDs, which is not good enough because a new backend might
use an already used ID.  Use PIDs instead.

Also, the code was purposely careless about other concurrent activity,
because it isn't expected; and in fact, it doesn't affect the vast
majority of the time.  However, it can be observed that autovacuum can
block tables for long enough to cause sporadic failures.  The new code
accounts for that by ignoring locks held by processes not explicitly
declared in our spec file.

Author: Noah Misch
2011-07-19 14:22:42 -04:00
Alvaro Herrera d6db0e4e0e Increase deadlock_timeout to 100ms in FK isolation tests
The previous value of 20ms is dangerously close to the time actually
spent just waiting for the deadlock to happen, so on occasion it causes
the test to fail simply because the other session didn't get to run
early enough, not managing to cause the deadlock that needs to be
detected.  With this new value, it's expected that most machines on
normal load will be able to pass the test.

Author: Noah Misch
2011-07-19 13:07:16 -04:00