Commit Graph

35290 Commits

Author SHA1 Message Date
Tom Lane
7f0bc6b448 Fix configure probe for sys/ucred.h.
The configure script's test for <sys/ucred.h> did not work on OpenBSD,
because on that platform <sys/param.h> has to be included first.
As a result, socket peer authentication was disabled on that platform.
Problem introduced in commit be4585b1c2.

Andres Freund, slightly simplified by me.
2013-07-25 11:39:59 -04:00
Bruce Momjian
830d0e0edd pg_upgrade: adjust umask() calls
Since pg_upgrade -j on Windows uses threads, calling umask()
before/after opening a file via fopen_priv() is no longer possible, so
set umask() as we enter the thread-creating loop, and reset it on exit.
Also adjust internal fopen_priv() calls to just use fopen().
Backpatch to 9.3beta.
2013-07-25 11:33:14 -04:00
Bruce Momjian
b48f1dc2d3 pg_upgrade: fix initialization of thread argument
Reorder initialization of thread argument marker to it happens before
reap_child() is called.
Backpatch to 9.3.
2013-07-24 22:01:46 -04:00
Tom Lane
cf707aa70d Improve ilist.h's support for deletion of slist elements during iteration.
Previously one had to use slist_delete(), implying an additional scan of
the list, making this infrastructure considerably less efficient than
traditional Lists when deletion of element(s) in a long list is needed.
Modify the slist_foreach_modify() macro to support deleting the current
element in O(1) time, by keeping a "prev" pointer in addition to "cur"
and "next".  Although this makes iteration with this macro a bit slower,
no real harm is done, since in any scenario where you're not going to
delete the current list element you might as well just use slist_foreach
instead.  Improve the comments about when to use each macro.

Back-patch to 9.3 so that we'll have consistent semantics in all branches
that provide ilist.h.  Note this is an ABI break for callers of
slist_foreach_modify().

Andres Freund and Tom Lane
2013-07-24 17:42:48 -04:00
Bruce Momjian
4a67a9ac13 pg_upgrade: more Windows parallel/-j fixes
More fixes to handle Windows thread parameter passing.
Backpatch to 9.3 beta.
Patch originally from Andrew Dunstan
2013-07-24 13:15:47 -04:00
Bruce Momjian
38afb907af pg_upgrade: fix parallel/-j crash on Windows
This fixes the problem of passing the wrong function pointer when doing
parallel copy/link operations on Windows.
Backpatched to 9.3beta.
Found and patch supplied by Andrew Dunstan
2013-07-24 10:01:18 -04:00
Tom Lane
808d1f8122 Fix booltestsel() for case where we have NULL stats but not MCV stats.
In a boolean column that contains mostly nulls, ANALYZE might not find
enough non-null values to populate the most-common-values stats,
but it would still create a pg_statistic entry with stanullfrac set.
The logic in booltestsel() for this situation did the wrong thing for
"col IS NOT TRUE" and "col IS NOT FALSE" tests, forgetting that null
values would satisfy these tests (so that the true selectivity would
be close to one, not close to zero).  Per bug #8274.

Fix by Andrew Gierth, some comment-smithing by me.
2013-07-24 00:44:22 -04:00
Tom Lane
7f5cfe914d Further hacking on ruleutils' new column-alias-assignment code.
After further thought about implicit coercions appearing in a joinaliasvars
list, I realized that they represent an additional reason why we might need
to reference the join output column directly instead of referencing an
underlying column.  Consider SELECT x FROM t1 LEFT JOIN t2 USING (x) where
t1.x is of type date while t2.x is of type timestamptz.  The merged output
variable is of type timestamptz, but it won't go to null when t2 does,
therefore neither t1.x nor t2.x is a valid substitute reference.

The code in get_variable() actually gets this case right, since it knows
it shouldn't look through a coercion, but we failed to ensure that the
unqualified output column name would be globally unique.  To fix, modify
the code that trawls for a dangerous situation so that it actually scans
through an unnamed join's joinaliasvars list to see if there are any
non-simple-Var entries.
2013-07-23 17:55:23 -04:00
Alvaro Herrera
5ef42547c3 Check for NULL result from strdup
Per Coverity Scan
2013-07-23 17:38:32 -04:00
Tom Lane
b81d0691b9 Change post-rewriter representation of dropped columns in joinaliasvars.
It's possible to drop a column from an input table of a JOIN clause in a
view, if that column is nowhere actually referenced in the view.  But it
will still be there in the JOIN clause's joinaliasvars list.  We used to
replace such entries with NULL Const nodes, which is handy for generation
of RowExpr expansion of a whole-row reference to the view.  The trouble
with that is that it can't be distinguished from the situation after
subquery pull-up of a constant subquery output expression below the JOIN.
Instead, replace such joinaliasvars with null pointers (empty expression
trees), which can't be confused with pulled-up expressions.  expandRTE()
still emits the old convention, though, for convenience of RowExpr
generation and to reduce the risk of breaking extension code.

In HEAD and 9.3, this patch also fixes a problem with some new code in
ruleutils.c that was failing to cope with implicitly-casted joinaliasvars
entries, as per recent report from Feike Steenbergen.  That oversight was
because of an inadequate description of the data structure in parsenodes.h,
which I've now corrected.  There were some pre-existing oversights of the
same ilk elsewhere, which I believe are now all fixed.
2013-07-23 16:23:52 -04:00
Alvaro Herrera
5712eeb2e7 Tweak FOR UPDATE/SHARE error message wording (again)
In commit 0ac5ad5134 I changed some error messages from "FOR
UPDATE/SHARE" to a rather long gobbledygook which nobody liked.  Then,
in commit cb9b66d31 I changed them again, but the alternative chosen
there was deemed suboptimal by Peter Eisentraut, who in message
1373937980.20441.8.camel@vanquo.pezone.net proposed an alternative
involving a dynamically-constructed string based on the actual locking
strength specified in the SQL command.  This patch implements that
suggestion.
2013-07-23 14:04:36 -04:00
Robert Haas
026bc46da3 Back-patch bgworker API changes to 9.3.
Commit 7f7485a0cd made these changes
in master; per discussion, backport the API changes (but not the
functional changes), so that people don't get used to the 9.3 API
only to see it get broken in the next release.  There are already
some people coding to the original 9.3 API, and this will cause
minor breakage, but there will be even more if we wait until next
year to roll out these changes.
2013-07-22 15:41:44 -04:00
Robert Haas
295f9bbf1d Remove bgw_sighup and bgw_sigterm.
Per discussion on pgsql-hackers, these aren't really needed.  Interim
versions of the background worker patch had the worker starting with
signals already unblocked, which would have made this necessary.
But the final version does not, so we don't really need it; and it
doesn't work well with the new facility for starting dynamic background
workers, so just rip it out.

Also per discussion on pgsql-hackers, back-patch this change to 9.3.
It's best to get the API break out of the way before we do an
official release of this facility, to avoid more pain for extension
authors later.
2013-07-22 15:15:22 -04:00
Tom Lane
15b9bdf4d4 Fix error handling in PLy_spi_execute_fetch_result().
If an error is thrown out of the datatype I/O functions called by this
function, we need to do subtransaction cleanup, which the previous coding
entirely failed to do.  Fortunately, both existing callers of this function
already have proper cleanup logic, so re-throwing the exception is enough.

Also, postpone creation of the resultset tupdesc until after the I/O
conversions are complete, so that we won't leak memory in TopMemoryContext
when such an error happens.
2013-07-20 12:44:53 -04:00
Peter Eisentraut
ef8321a57d Clean up new JSON API typedefs
The new JSON API uses a bit of an unusual typedef scheme, where for
example OkeysState is a pointer to okeysState.  And that's not applied
consistently either.  Change that to the more usual PostgreSQL style
where struct typedefs are upper case, and use pointers explicitly.
2013-07-20 06:41:46 -04:00
Alvaro Herrera
0b3859f3b6 Fix HeapTupleSatisfiesVacuum on aborted updater xacts
By using only the macro that checks infomask bits
HEAP_XMAX_IS_LOCKED_ONLY to verify whether a multixact is not an
updater, and not the full HeapTupleHeaderIsOnlyLocked, it would come to
the wrong result in case of a multixact containing an aborted update;
therefore returning the wrong result code.  This would cause predicate.c
to break completely (as in bug report #8273 from David Leverton), and
certain index builds would misbehave.  As far as I can tell, other
callers of the bogus routine would make harmless mistakes or not be
affected by the difference at all; so this was a pretty narrow case.

Also, no other user of the HEAP_XMAX_IS_LOCKED_ONLY macro is as
careless; they all check specifically for the HEAP_XMAX_IS_MULTI case,
and they all verify whether the updater is InvalidXid before concluding
that it's a valid updater.  So there doesn't seem to be any similar bug.
2013-07-19 18:35:07 -04:00
Robert Haas
a9f8fe06bc doc: Fix typos in conversion names.
David Christensen
2013-07-19 10:54:11 -04:00
Michael Meskes
24780e00d2 Initialize day of year value.
There are cases where the day of year value in struct tm is used, but it never
got calculated. Problem found by Coverity scan.
2013-07-19 09:05:41 +02:00
Tom Lane
f8463fba24 Fix regex match failures for backrefs combined with non-greedy quantifiers.
An ancient logic error in cfindloop() could cause the regex engine to fail
to find matches that begin later than the start of the string.  This
function is only used when the regex pattern contains a back reference,
and so far as we can tell the error is only reachable if the pattern is
non-greedy (i.e. its first quantifier uses the ? modifier).  Furthermore,
the actual match must begin after some potential match that satisfies the
DFA but then fails the back-reference's match test.

Reported and fixed by Jeevan Chalke, with cosmetic adjustments by me.
2013-07-18 21:22:43 -04:00
Stephen Frost
dd8ea2eb5e Use correct parameter name for view_option_value
The documentation for ALTER VIEW had a minor copy-and-paste error in
defining the parameters.  Noticed when reviewing the WITH CHECK OPTION
patch.

Backpatch to 9.2 where this was first introduced.
2013-07-17 10:53:32 -04:00
Peter Eisentraut
bdbb1d6738 Fix PQconninfoParse error message handling
The returned error message already includes a newline, but the callers
were adding their own when printing it out.
2013-07-15 20:08:41 -04:00
Stephen Frost
22b7f5c5aa Correct off-by-one when reading from pipe
In pg_basebackup.c:reached_end_position(), we're reading from an
internal pipe with our own background process but we're possibly
reading more bytes than will actually fit into our buffer due to
an off-by-one error.  As we're reading from an internal pipe
there's no real risk here, but it's good form to not depend on
such convenient arrangements.

Bug spotted by the Coverity scanner.

Back-patch to 9.2 where this showed up.
2013-07-15 10:48:01 -04:00
Stephen Frost
8126bfb5b5 Check version before allocating PQExpBuffer
In pg_dump.c:getEventTriggers, check what major version we are on
before calling createPQExpBuffer() to avoid leaking that bit of
memory.

Leak discovered by the Coverity scanner.

Back-patch to 9.3 where support for dumping event triggers was
added.
2013-07-14 21:21:15 -04:00
Stephen Frost
b68a1fc7ff Be sure to close() file descriptor on error case
In receivelog.c:writeTimeLineHistoryFile(), we were not properly
closing the open'd file descriptor in error cases.  While this
wouldn't matter much if we were about to exit due to such an
error, that's not the case with pg_receivexlog as it can be a
long-running process and these errors are non-fatal.

This resource leak was found by the Coverity scanner.

Back-patch to 9.3 where this issue first appeared.
2013-07-14 17:25:47 -04:00
Stephen Frost
e9010b9926 Ensure 64bit arithmetic when calculating tapeSpace
In tuplesort.c:inittapes(), we calculate tapeSpace by first figuring
out how many 'tapes' we can use (maxTapes) and then multiplying the
result by the tape buffer overhead for each.  Unfortunately, when
we are on a system with an 8-byte long, we allow work_mem to be
larger than 2GB and that allows maxTapes to be large enough that the
32bit arithmetic can overflow when multiplied against the buffer
overhead.

When this overflow happens, we end up adding the overflow to the
amount of space available, causing the amount of memory allocated to
be larger than work_mem.

Note that to reach this point, you have to set work mem to at least
24GB and be sorting a set which is at least that size.  Given that a
user who can set work_mem to 24GB could also set it even higher, if
they were looking to run the system out of memory, this isn't
considered a security issue.

This overflow risk was found by the Coverity scanner.

Back-patch to all supported branches, as this issue has existed
since before 8.4.
2013-07-14 16:42:58 -04:00
Peter Eisentraut
5ab811106b pg_isready: Message improvement 2013-07-14 16:08:41 -04:00
Stephen Frost
f5acde9380 pg_receivexlog - Exit on failure to parse
In streamutil.c:GetConnection(), upgrade failure to parse the
connection string to an exit(1) instead of simply returning NULL.
Most callers already immediately exited, but pg_receivexlog would
loop on this case, continually trying to re-parse the connection
string (which can't be changed after pg_receivexlog has started).

GetConnection() was already expected to exit(1) in some cases
(eg: failure to allocate memory or if unable to determine the
integer_datetimes flag), so this change shouldn't surprise anyone.

Began looking at this due to the Coverity scanner complaining that
we were leaking err_msg in this case- no longer an issue since we
just exit(1) immediately.
2013-07-14 15:38:43 -04:00
Stephen Frost
8839e7362c During parallel pg_dump, free commands from master
The command strings read by the child processes during parallel
pg_dump, after being read and handled, were not being free'd.
This patch corrects this relatively minor memory leak.

Leak found by the Coverity scanner.

Back patch to 9.3 where parallel pg_dump was introduced.
2013-07-14 14:36:26 -04:00
Noah Misch
fb7c0ac42e Switch user ID to the object owner when populating a materialized view.
This makes superuser-issued REFRESH MATERIALIZED VIEW safe regardless of
the object's provenance.  REINDEX is an earlier example of this pattern.
As a downside, functions called from materialized views must tolerate
running in a security-restricted operation.  CREATE MATERIALIZED VIEW
need not change user ID.  Nonetheless, avoid creation of materialized
views that will invariably fail REFRESH by making it, too, start a
security-restricted operation.

Back-patch to 9.3 so materialized views have this from the beginning.

Reviewed by Kevin Grittner.
2013-07-12 18:25:41 -04:00
Peter Eisentraut
7484f89daa pg_dump: Formatting cleanup of new messages 2013-07-11 21:48:31 -04:00
Bruce Momjian
02e61a8488 pg_upgrade: document possible pg_hba.conf options
Previously, pg_upgrade docs recommended using .pgpass if using MD5
authentication to avoid being prompted for a password.  Turns out pg_ctl
never prompts for a password, so MD5 requires .pgpass --- document that.
Also recommend 'peer' for authentication too.
Backpatch back to 9.1.
2013-07-11 09:43:19 -04:00
Peter Eisentraut
583435d079 doc: Replace link to pgFouine with pgBadger
From: Ian Lawrence Barwick <barwick@gmail.com>
2013-07-10 22:41:37 -04:00
Peter Eisentraut
bf470b37cc Fix lack of message pluralization 2013-07-09 21:04:55 -04:00
Michael Meskes
d0450f1fa6 Fixed incorrect description of EXEC SQL VAR command.
Thanks to MauMau <maumau307@gmail.com> for finding and fixing this.
2013-07-09 15:48:39 +02:00
Alvaro Herrera
469feb7afb Fix mention of htup.h in pageinspect docs
It's htup_details.h now.

Jeff Janes
2013-07-08 17:11:55 -04:00
Tom Lane
8b6191e1d5 Fix planning of parameterized appendrel paths with expensive join quals.
The code in set_append_rel_pathlist() for building parameterized paths
for append relations (inheritance and UNION ALL combinations) supposed
that the cheapest regular path for a child relation would still be cheapest
when reparameterized.  Which might not be the case, particularly if the
added join conditions are expensive to compute, as in a recent example from
Jeff Janes.  Fix it to compare child path costs *after* reparameterizing.
We can short-circuit that if the cheapest pre-existing path is already
parameterized correctly, which seems likely to be true often enough to be
worth checking for.

Back-patch to 9.2 where parameterized paths were introduced.
2013-07-07 22:37:28 -04:00
Peter Eisentraut
95b4e8761e pg_isready: Make --help output more consistent with other utilities 2013-07-07 16:08:45 -04:00
Peter Eisentraut
8ca0e6870c pg_resetxlog: Make --help consistent with man page
Use "MXID" as placeholder for -m option, instead of just "XID".
2013-07-07 16:08:45 -04:00
Bruce Momjian
bf8d8ddc08 pg_upgrade: document link options
Document that tablespaces and pg_xlog can be on different file systems
for pg_upgrade --link mode.
Backpatch to 9.3.
2013-07-07 15:58:07 -04:00
Magnus Hagander
9f8830dbe2 Fix include-guard
Looks like a cut/paste error in the original addition of the file.

Andres Freund
2013-07-07 13:38:27 +02:00
Michael Meskes
7428a260f6 Also escape double quotes for ECPG's #line statement. 2013-07-06 22:11:14 +02:00
Tom Lane
e407192c93 Rename a function to avoid naming conflict in parallel regression tests.
Commit 31a891857a added some tests in
plpgsql.sql that used a function rather unthinkingly named "foo()".
However, rangefuncs.sql has some much older tests that create a function
of that name, and since these test scripts run in parallel, there is a
chance of failures if the timing is just right.  Use another name to
avoid that.  Per buildfarm (failure seen today on "hamerkop", but
probably it's happened before and not been noticed).
2013-07-06 11:16:53 -04:00
Michael Meskes
7d114fb46f Applied patch by MauMau <maumau307@gmail.com> to escape filenames in #line statements. 2013-07-06 11:49:33 +02:00
Noah Misch
cf183732d2 Update messages, comments and documentation for materialized views.
All instances of the verbiage lagging the code.  Back-patch to 9.3,
where materialized views were introduced.
2013-07-05 15:26:46 -04:00
Magnus Hagander
462b562ab2 Remove stray | character
Erikjan Rijkers
2013-07-05 16:21:26 +02:00
Bruce Momjian
8b4c798973 Add contrib function references in the doc index
Backpatch to 9.3.
Idea from Craig Ringer
2013-07-04 11:33:08 -04:00
Robert Haas
cdaf7bde97 docs: Clarify flag dependencies for background workers.
BGWORKER_BACKEND_DATABASE_CONNECTION can only be used if
BGWORKER_SHMEM_ACCESS is also used.

Michael Paquier, with some tweaks by me.
2013-07-04 11:15:01 -04:00
Peter Eisentraut
f960fae017 doc: Fix typo in event trigger documentation
From: Dimitri Fontaine <dimitri@2ndQuadrant.fr>
2013-07-04 10:28:07 -04:00
Peter Eisentraut
775a9f3025 doc: Add event trigger C API documentation
From: Dimitri Fontaine <dimitri@2ndQuadrant.fr>
2013-07-03 21:07:00 -04:00
Bruce Momjian
d3cc1b2ff0 pg_buffercache: document column meanings
Improve documentation for usagecount and relforknumber.
Backpatch to 9.3
Suggestion from Satoshi Nagayasu
2013-07-03 14:25:06 -04:00