]> granicus.if.org Git - postgresql/log
postgresql
10 years agoMake security barrier views automatically updatable
Stephen Frost [Sun, 13 Apr 2014 01:04:58 +0000 (21:04 -0400)]
Make security barrier views automatically updatable

Views which are marked as security_barrier must have their quals
applied before any user-defined quals are called, to prevent
user-defined functions from being able to see rows which the
security barrier view is intended to prevent them from seeing.

Remove the restriction on security barrier views being automatically
updatable by adding a new securityQuals list to the RTE structure
which keeps track of the quals from security barrier views at each
level, independently of the user-supplied quals.  When RTEs are
later discovered which have securityQuals populated, they are turned
into subquery RTEs which are marked as security_barrier to prevent
any user-supplied quals being pushed down (modulo LEAKPROOF quals).

Dean Rasheed, reviewed by Craig Ringer, Simon Riggs, KaiGai Kohei

10 years agoProvide moving-aggregate support for a bunch of numerical aggregates.
Tom Lane [Sun, 13 Apr 2014 00:33:09 +0000 (20:33 -0400)]
Provide moving-aggregate support for a bunch of numerical aggregates.

First installment of the promised moving-aggregate support in built-in
aggregates: count(), sum(), avg(), stddev() and variance() for
assorted datatypes, though not for float4/float8.

In passing, remove a 2001-vintage kluge in interval_accum(): interval
array elements have been properly aligned since around 2003, but
nobody remembered to take out this workaround.  Also, fix a thinko
in the opr_sanity tests for moving-aggregate catalog entries.

David Rowley and Florian Pflug, reviewed by Dean Rasheed

10 years agoCreate infrastructure for moving-aggregate optimization.
Tom Lane [Sat, 12 Apr 2014 15:58:53 +0000 (11:58 -0400)]
Create infrastructure for moving-aggregate optimization.

Until now, when executing an aggregate function as a window function
within a window with moving frame start (that is, any frame start mode
except UNBOUNDED PRECEDING), we had to recalculate the aggregate from
scratch each time the frame head moved.  This patch allows an aggregate
definition to include an alternate "moving aggregate" implementation
that includes an inverse transition function for removing rows from
the aggregate's running state.  As long as this can be done successfully,
runtime is proportional to the total number of input rows, rather than
to the number of input rows times the average frame length.

This commit includes the core infrastructure, documentation, and regression
tests using user-defined aggregates.  Follow-on commits will update some
of the built-in aggregates to use this feature.

David Rowley and Florian Pflug, reviewed by Dean Rasheed; additional
hacking by me

10 years agodocs: psql '--' comments are not passed to the server
Bruce Momjian [Thu, 10 Apr 2014 21:16:22 +0000 (17:16 -0400)]
docs: psql '--' comments are not passed to the server

C-style block comments are passed to the server.

10 years agoFix bugs in GIN "fast scan" with partial match.
Heikki Linnakangas [Thu, 10 Apr 2014 20:42:04 +0000 (23:42 +0300)]
Fix bugs in GIN "fast scan" with partial match.

There were a couple of bugs here. First, if the fuzzy limit was exceeded,
the loop in entryGetItem might drop out too soon if a whole block needs to
be skipped because it's < advancePast ("continue" in a while-loop checks the
loop condition too). Secondly, the loop checked when stepping to a new page
that there is at least one offset on the page < advancePast, but we cannot
rely on that on subsequent calls of entryGetItem, because advancePast might
change in between. That caused the skipping loop to read bogus items in the
TbmIterateResult's offset array.

First item and fix by Alexander Korotkov, second bug pointed out by Fabrízio
de Royes Mello, by a small variation of Alexander's test query.

10 years agoThe new pointer_to_struct test needs a special command line parameter to ecpg.
Michael Meskes [Thu, 10 Apr 2014 18:37:00 +0000 (20:37 +0200)]
The new pointer_to_struct test needs a special command line parameter to ecpg.
Hopefully this will fix the buildfarm failures on Windows.

10 years agoC comment: track_activity_query_size doesn't support memory units
Bruce Momjian [Thu, 10 Apr 2014 13:56:25 +0000 (09:56 -0400)]
C comment:  track_activity_query_size doesn't support memory units

And explain why.

Per report from Pavel Stehule

10 years agoFix typo in comment.
Heikki Linnakangas [Thu, 10 Apr 2014 10:11:49 +0000 (13:11 +0300)]
Fix typo in comment.

Tomonari Katsumata

10 years agoFix a few more misc typos in comments.
Heikki Linnakangas [Wed, 9 Apr 2014 21:53:15 +0000 (00:53 +0300)]
Fix a few more misc typos in comments.

10 years agodocs: add link to pg_start_backup() from pg_basebackup --checkpoint
Bruce Momjian [Wed, 9 Apr 2014 21:44:59 +0000 (17:44 -0400)]
docs:  add link to pg_start_backup() from pg_basebackup --checkpoint

This references the meaning of the fast/spread checkpoint option.

Per private IM report

10 years agoFix misc typos in comments.
Heikki Linnakangas [Wed, 9 Apr 2014 20:16:08 +0000 (23:16 +0300)]
Fix misc typos in comments.

10 years agoAdd missing include.
Robert Haas [Wed, 9 Apr 2014 15:38:52 +0000 (11:38 -0400)]
Add missing include.

This is more cleanup from commit 11a65eed1637a05b03e174700799b024e104bfb4.

Amit Kapila

10 years agoSeveral fixes to array handling in ecpg.
Michael Meskes [Wed, 9 Apr 2014 09:21:46 +0000 (11:21 +0200)]
Several fixes to array handling in ecpg.

Patches by Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>

10 years agoFix silly oversight in patch to remove dsm state file.
Robert Haas [Tue, 8 Apr 2014 20:22:50 +0000 (16:22 -0400)]
Fix silly oversight in patch to remove dsm state file.

I'm not sure if this is what's causing the Windows buildfarm members
to get unhappy, but I don't think it can be helping anything...

10 years agoAdd an in-core GiST index opclass for inet/cidr types.
Tom Lane [Tue, 8 Apr 2014 19:46:14 +0000 (15:46 -0400)]
Add an in-core GiST index opclass for inet/cidr types.

This operator class can accelerate subnet/supernet tests as well as
btree-equivalent ordered comparisons.  It also handles a new network
operator inet && inet (overlaps, a/k/a "is supernet or subnet of"),
which is expected to be useful in exclusion constraints.

Ideally this opclass would be the default for GiST with inet/cidr data,
but we can't mark it that way until we figure out how to do a more or
less graceful transition from the current situation, in which the
really-completely-bogus inet/cidr opclasses in contrib/btree_gist are
marked as default.  Having the opclass in core and not default is better
than not having it at all, though.

While at it, add new documentation sections to allow us to officially
document GiST/GIN/SP-GiST opclasses, something there was never a clear
place to do before.  I filled these in with some simple tables listing
the existing opclasses and the operators they support, but there's
certainly scope to put more information there.

Emre Hasegeli, reviewed by Andreas Karlsson, further hacking by me

10 years agodoc: Fix typo.
Robert Haas [Tue, 8 Apr 2014 15:47:29 +0000 (11:47 -0400)]
doc: Fix typo.

Ian Barwick

10 years agoGet rid of the dynamic shared memory state file.
Robert Haas [Tue, 8 Apr 2014 15:39:55 +0000 (11:39 -0400)]
Get rid of the dynamic shared memory state file.

Instead of storing the ID of the dynamic shared memory control
segment in a file within the data directory, store it in the main
control segment.  This avoids a number of nasty corner cases,
most seriously that doing an online backup and then using it on
the same machine (e.g. to fire up a standby) would result in the
standby clobbering all of the master's dynamic shared memory
segments.

Per complaints from Heikki Linnakangas, Fujii Masao, and Tom
Lane.

10 years agoAdd new to_reg* functions for error-free OID lookups.
Robert Haas [Tue, 8 Apr 2014 14:27:56 +0000 (10:27 -0400)]
Add new to_reg* functions for error-free OID lookups.

These functions won't throw an error if the object doesn't exist,
or if (for functions and operators) there's more than one matching
object.

Yugo Nagata and Nozomi Anzai, reviewed by Amit Khandekar, Marti
Raudsepp, Amit Kapila, and me.

10 years agoFix hot standby bug with GiST scans.
Heikki Linnakangas [Tue, 8 Apr 2014 11:47:24 +0000 (14:47 +0300)]
Fix hot standby bug with GiST scans.

Don't reset the rightlink of a page when replaying a page update record.
This was a leftover from pre-hot standby days, when it was not possible to
have scans concurrent with WAL replay. Resetting the right-link was not
necessary back then either, but it was done for the sake of tidiness. But
with hot standby, it's wrong, because a concurrent scan might still need it.

Backpatch all versions with hot standby, 9.0 and above.

10 years agoZero padding byte at end of GIN posting list.
Heikki Linnakangas [Mon, 7 Apr 2014 16:48:03 +0000 (19:48 +0300)]
Zero padding byte at end of GIN posting list.

This isn't strictly necessary, but helps debugging.

10 years agoRemove 'make clean' support for ipc_test.
Robert Haas [Mon, 7 Apr 2014 15:44:54 +0000 (11:44 -0400)]
Remove 'make clean' support for ipc_test.

I missed this in the previous commit; Tom Lane spotted my error.

10 years agoAssert that strong-lock count is >0 everywhere it's decremented.
Robert Haas [Mon, 7 Apr 2014 14:59:42 +0000 (10:59 -0400)]
Assert that strong-lock count is >0 everywhere it's decremented.

The one existing assertion of this type has tripped a few times in the
buildfarm lately, but it's not clear whether the problem is really
originating there or whether it's leftovers from a trip through one
of the other two paths that lack a matching assertion.  So add one.

Since the same bug(s) most likely exist(s) in the back-branches also,
back-patch to 9.2, where the fast-path lock mechanism was added.

10 years agoRemove ipc_test.
Robert Haas [Mon, 7 Apr 2014 14:40:47 +0000 (10:40 -0400)]
Remove ipc_test.

This doesn't seem to be useful any more, and it's not really worth the
effort to keep updating it every time relevant dependencies or calling
signatures in the shared memory or semaphore code change.

10 years agoFix WAL replay bug in the new GIN incomplete-split code.
Heikki Linnakangas [Mon, 7 Apr 2014 11:34:31 +0000 (14:34 +0300)]
Fix WAL replay bug in the new GIN incomplete-split code.

Forgot to set the incomplete-split flag on the left page half, in redo of a
page split.

Spotted this by comparing the page contents on master and standby, after
inserting/applying each WAL record.

10 years agoExtra warnings and errors for PL/pgSQL
Simon Riggs [Sun, 6 Apr 2014 16:21:51 +0000 (12:21 -0400)]
Extra warnings and errors for PL/pgSQL

Infrastructure to allow
 plpgsql.extra_warnings
 plpgsql.extra_errors

Initial extra checks only for shadowed_variables

Marko Tiikkaja and Petr Jelinek
Reviewed by Simon Riggs and Pavel Stěhule

10 years agoIsolation test files for ALTER TABLE patch
Simon Riggs [Sun, 6 Apr 2014 15:44:24 +0000 (11:44 -0400)]
Isolation test files for ALTER TABLE patch

10 years agoReduce lock levels of some ALTER TABLE cmds
Simon Riggs [Sun, 6 Apr 2014 15:13:43 +0000 (11:13 -0400)]
Reduce lock levels of some ALTER TABLE cmds

VALIDATE CONSTRAINT

CLUSTER ON
SET WITHOUT CLUSTER

ALTER COLUMN SET STATISTICS
ALTER COLUMN SET ()
ALTER COLUMN RESET ()

All other sub-commands use AccessExclusiveLock

Simon Riggs and Noah Misch

Reviews by Robert Haas and Andres Freund

10 years agoImprove contrib/pg_trgm's heuristics for regexp index searches.
Tom Lane [Sun, 6 Apr 2014 00:48:47 +0000 (20:48 -0400)]
Improve contrib/pg_trgm's heuristics for regexp index searches.

When extracting trigrams from a regular expression for search of a GIN or
GIST trigram index, it's useful to penalize (preferentially discard)
trigrams that contain whitespace, since those are typically far more common
in the index than trigrams not containing whitespace.  Of course, this
should only be a preference not a hard rule, since we might otherwise end
up with no trigrams to search for.  The previous coding tended to produce
fairly inefficient trigram search sets for anchored regexp patterns, as
reported by Erik Rijkers.  This patch penalizes whitespace-containing
trigrams, and also reduces the target number of extracted trigrams, since
experience suggests that the original coding tended to select too many
trigrams to search for.

Alexander Korotkov, reviewed by Tom Lane

10 years agoBlock signals earlier during postmaster startup.
Tom Lane [Sat, 5 Apr 2014 22:16:08 +0000 (18:16 -0400)]
Block signals earlier during postmaster startup.

Formerly, we set up the postmaster's signal handling only when we were
about to start launching subprocesses.  This is a bad idea though, as
it means that for example a SIGINT arriving before that will kill the
postmaster instantly, perhaps leaving lockfiles, socket files, shared
memory, etc laying about.  We'd rather that such a signal caused orderly
postmaster termination including releasing of those resources.  A simple
fix is to move the PostmasterMain stanza that initializes signal handling
to an earlier point, before we've created any such resources.  Then, an
early-arriving signal will be blocked until we're ready to deal with it
in the usual way.  (The only part that really needs to be moved up is
blocking of signals, but it seems best to keep the signal handler
installation calls together with that; for one thing this ensures the
kernel won't drop any signals we wished to get.  The handlers won't get
invoked in any case until we unblock signals in ServerLoop.)

Per a report from MauMau.  He proposed changing the way "pg_ctl stop"
works to deal with this, but that'd just be masking one symptom not
fixing the core issue.

It's been like this since forever, so back-patch to all supported branches.

10 years agoFix another palloc in critical section.
Heikki Linnakangas [Sat, 5 Apr 2014 19:02:28 +0000 (22:02 +0300)]
Fix another palloc in critical section.

Also add a regression test for a GIN index with enough items with the same
key, so that a GIN posting tree gets created. Apparently none of the
existing GIN tests were large enough for that.

This code is new, no backpatching required.

10 years agoFix processing of PGC_BACKEND GUC parameters on Windows.
Tom Lane [Sat, 5 Apr 2014 16:41:25 +0000 (12:41 -0400)]
Fix processing of PGC_BACKEND GUC parameters on Windows.

EXEC_BACKEND builds (i.e., Windows) failed to absorb values of PGC_BACKEND
parameters if they'd been changed post-startup via the config file.  This
for example prevented log_connections from working if it were turned on
post-startup.  The mechanism for handling this case has always been a bit
of a kluge, and it wasn't revisited when we implemented EXEC_BACKEND.
While in a normal forking environment new backends will inherit the
postmaster's value of such settings, EXEC_BACKEND backends have to read
the settings from the CONFIG_EXEC_PARAMS file, and they were mistakenly
rejecting them.  So this case has always been broken in the Windows port;
so back-patch to all supported branches.

Amit Kapila

10 years agoecpg/ecpglib must build the src/port files it uses with -DFRONTEND.
Tom Lane [Sat, 5 Apr 2014 06:20:25 +0000 (02:20 -0400)]
ecpg/ecpglib must build the src/port files it uses with -DFRONTEND.

Remarkably, this hasn't been noticed before, though it surely should
have been happening since around the fall of the Byzantine empire.
Commit 438b529604 changed path.c to depend on FRONTEND, and that exposed
the omission, per buildfarm reports.

I'm suspicious that some other subdirectories are missing this too,
but this one change is enough to make ecpg tests pass for me.

10 years agoFix tablespace creation WAL replay to work on Windows.
Tom Lane [Sat, 5 Apr 2014 03:09:35 +0000 (23:09 -0400)]
Fix tablespace creation WAL replay to work on Windows.

The code segment that removes the old symlink (if present) wasn't clued
into the fact that on Windows, symlinks are junction points which have
to be removed with rmdir().

Backpatch to 9.0, where the failing code was introduced.

MauMau, reviewed by Muhammad Asif Naeem and Amit Kapila

10 years agoAllow "-C variable" and "--describe-config" even to root users.
Tom Lane [Sat, 5 Apr 2014 02:03:35 +0000 (22:03 -0400)]
Allow "-C variable" and "--describe-config" even to root users.

There's no really compelling reason to refuse to do these read-only,
non-server-starting options as root, and there's at least one good
reason to allow -C: pg_ctl uses -C to find out the true data directory
location when pointed at a config-only directory.  On Windows, this is
done before dropping administrator privileges, which means that pg_ctl
fails for administrators if and only if a config-only layout is used.

Since the root-privilege check is done so early in startup, it's a bit
awkward to check for these switches.  Make the somewhat arbitrary
decision that we'll only skip the root check if -C is the first switch.
This is not just to make the code a bit simpler: it also guarantees that
we can't misinterpret a --boot mode switch.  (While AuxiliaryProcessMain
doesn't currently recognize any such switch, it might have one in the
future.)  This is no particular problem for pg_ctl, and since the whole
behavior is undocumented anyhow, it's not a documentation issue either.
(--describe-config only works as the first switch anyway, so this is
no restriction for that case either.)

Back-patch to 9.2 where pg_ctl first began to use -C.

MauMau, heavily edited by me

10 years agoPreserve errno across free().
Tom Lane [Fri, 4 Apr 2014 23:07:37 +0000 (19:07 -0400)]
Preserve errno across free().

Dept. of second thoughts: free() isn't guaranteed not to change errno.
Make sure we report the right error if getcwd() fails.

10 years agoMake sure -D is an absolute path when starting server on Windows.
Tom Lane [Fri, 4 Apr 2014 22:42:13 +0000 (18:42 -0400)]
Make sure -D is an absolute path when starting server on Windows.

This is needed because Windows services may get started with a different
current directory than where pg_ctl is executed.  We want relative -D
paths to be interpreted relative to pg_ctl's CWD, similarly to what
happens on other platforms.

In support of this, move the backend's make_absolute_path() function
into src/port/path.c (where it probably should have been long since)
and get rid of the rather inferior version in pg_regress.

Kumar Rajeev Rastogi, reviewed by MauMau

10 years agoFix bogus time printout in walreceiver's debug log messages.
Tom Lane [Fri, 4 Apr 2014 15:43:34 +0000 (11:43 -0400)]
Fix bogus time printout in walreceiver's debug log messages.

The displayed sendtime and receipttime were always exactly equal, because
somebody forgot that timestamptz_to_str returns a static buffer (thereby
simplifying life for most callers, at the cost of complicating it for those
who need two results concurrently).  Apply the same pstrdup solution used
by the other call sites with this issue.  Back-patch to 9.2 where the
faulty code was introduced.  Per bug #9849 from Haruka Takatsuka, though
this is not exactly his patch.

Possibly we should change timestamptz_to_str's API, but I wouldn't want
to do so in the back branches.

10 years agoFix some compiler warnings that clang emits with -pedantic.
Robert Haas [Fri, 4 Apr 2014 15:26:01 +0000 (11:26 -0400)]
Fix some compiler warnings that clang emits with -pedantic.

Andres Freund

10 years agoMove multixid allocation out of critical section.
Heikki Linnakangas [Fri, 4 Apr 2014 15:20:22 +0000 (18:20 +0300)]
Move multixid allocation out of critical section.

It can fail if you run out of memory.

This call was added in 9.3, so backpatch to 9.3 only.

10 years agoIn checkpoint, move the check for in-progress xacts out of critical section.
Heikki Linnakangas [Fri, 4 Apr 2014 14:29:50 +0000 (17:29 +0300)]
In checkpoint, move the check for in-progress xacts out of critical section.

GetVirtualXIDsDelayingChkpt calls palloc, which isn't safe in a critical
section. I thought I covered this case with the exemption for the
checkpointer, but CreateCheckPoint is also called from the startup process.

10 years agoAdd an Assertion that you don't palloc within a critical section.
Heikki Linnakangas [Fri, 4 Apr 2014 11:27:18 +0000 (14:27 +0300)]
Add an Assertion that you don't palloc within a critical section.

This caught a bunch of cases doing that already, which I just fixed in
previous commit. This is the assertion itself.

Per Tom Lane's idea.

10 years agoAvoid allocations in critical sections.
Heikki Linnakangas [Fri, 4 Apr 2014 10:12:38 +0000 (13:12 +0300)]
Avoid allocations in critical sections.

If a palloc in a critical section fails, it becomes a PANIC.

10 years agoFix non-equivalence of VARIADIC and non-VARIADIC function call formats.
Tom Lane [Fri, 4 Apr 2014 02:02:24 +0000 (22:02 -0400)]
Fix non-equivalence of VARIADIC and non-VARIADIC function call formats.

For variadic functions (other than VARIADIC ANY), the syntaxes foo(x,y,...)
and foo(VARIADIC ARRAY[x,y,...]) should be considered equivalent, since the
former is converted to the latter at parse time.  They have indeed been
equivalent, in all releases before 9.3.  However, commit 75b39e790 made an
ill-considered decision to record which syntax had been used in FuncExpr
nodes, and then to make equal() test that in checking node equality ---
which caused the syntaxes to not be seen as equivalent by the planner.
This is the underlying cause of bug #9817 from Dmitry Ryabov.

It might seem that a quick fix would be to make equal() disregard
FuncExpr.funcvariadic, but the same commit made that untenable, because
the field actually *is* semantically significant for some VARIADIC ANY
functions.  This patch instead adopts the approach of redefining
funcvariadic (and aggvariadic, in HEAD) as meaning that the last argument
is a variadic array, whether it got that way by parser intervention or was
supplied explicitly by the user.  Therefore the value will always be true
for non-ANY variadic functions, restoring the principle of equivalence.
(However, the planner will continue to consider use of VARIADIC as a
meaningful difference for VARIADIC ANY functions, even though some such
functions might disregard it.)

In HEAD, this change lets us simplify the decompilation logic in
ruleutils.c, since the funcvariadic/aggvariadic flag tells directly whether
to print VARIADIC.  However, in 9.3 we have to continue to cope with
existing stored rules/views that might contain the previous definition.
Fortunately, this just means no change in ruleutils.c, since its existing
behavior effectively ignores funcvariadic for all cases other than VARIADIC
ANY functions.

In HEAD, bump catversion to reflect the fact that FuncExpr.funcvariadic
changed meanings; this is sort of pro forma, since I don't believe any
built-in views are affected.

Unfortunately, this patch doesn't magically fix everything for affected
9.3 users.  After installing 9.3.5, they might need to recreate their
rules/views/indexes containing variadic function calls in order to get
everything consistent with the new definition.  As in the cited bug,
the symptom of a problem would be failure to use a nominally matching
index that has a variadic function call in its definition.  We'll need
to mention this in the 9.3.5 release notes.

10 years agoCode review for commit d26888bc4d1e539a82f21382b0000fe5bbf889d9.
Tom Lane [Thu, 3 Apr 2014 20:57:45 +0000 (16:57 -0400)]
Code review for commit d26888bc4d1e539a82f21382b0000fe5bbf889d9.

Mostly, copy-edit the comments; but also fix it to not reject domains over
arrays.

10 years agoFix documentation about joining pg_locks to other views.
Tom Lane [Thu, 3 Apr 2014 18:18:25 +0000 (14:18 -0400)]
Fix documentation about joining pg_locks to other views.

The advice to join to pg_prepared_xacts via the transaction column was not
updated when the transaction column was replaced by virtualtransaction.
Since it's not quite obvious how to do that join, give an explicit example.
For consistency also give an example for the adjacent case of joining to
pg_stat_activity.  And link-ify the view references too, just because we
can.  Per bug #9840 from Alexey Bashtanov.

Michael Paquier and Tom Lane

10 years agoAvoid promising that "ADD COLUMN ... DEFAULT NULL" is free.
Tom Lane [Thu, 3 Apr 2014 16:38:00 +0000 (12:38 -0400)]
Avoid promising that "ADD COLUMN ... DEFAULT NULL" is free.

The system realizes that DEFAULT NULL is dummy in simple cases, but not if
a cast function (such as a length coercion) needs to be applied.  It's
dubious that suppressing that function call would be appropriate, anyway.
For the moment, let's just adjust the docs to say that you should omit the
DEFAULT clause if you don't want a rewrite to happen.  Per gripe from Amit
Langote.

10 years agoAvoid palloc in critical section in GiST WAL-logging.
Heikki Linnakangas [Thu, 3 Apr 2014 12:09:37 +0000 (15:09 +0300)]
Avoid palloc in critical section in GiST WAL-logging.

Memory allocation can fail if you run out of memory, and inside a critical
section that will lead to a PANIC. Use conservatively-sized arrays in stack
instead.

There was previously no explicit limit on the number of pages a GiST split
can produce, it was only limited by the number of LWLocks that can be held
simultaneously (100 at the moment). This patch adds an explicit limit of 75
pages. That should be plenty, a typical split shouldn't produce more than
2-3 page halves.

The bug has been there forever, but only backpatch down to 9.1. The code
was changed significantly in 9.1, and it doesn't seem worth the risk or
trouble to adapt this for 9.0 and 8.4.

10 years agoFix assorted issues in client host name lookup.
Tom Lane [Wed, 2 Apr 2014 21:11:24 +0000 (17:11 -0400)]
Fix assorted issues in client host name lookup.

The code for matching clients to pg_hba.conf lines that specify host names
(instead of IP address ranges) failed to complain if reverse DNS lookup
failed; instead it silently didn't match, so that you might end up getting
a surprising "no pg_hba.conf entry for ..." error, as seen in bug #9518
from Mike Blackwell.  Since we don't want to make this a fatal error in
situations where pg_hba.conf contains a mixture of host names and IP
addresses (clients matching one of the numeric entries should not have to
have rDNS data), remember the lookup failure and mention it as DETAIL if
we get to "no pg_hba.conf entry".  Apply the same approach to forward-DNS
lookup failures, too, rather than treating them as immediate hard errors.

Along the way, fix a couple of bugs that prevented us from detecting an
rDNS lookup error reliably, and make sure that we make only one rDNS lookup
attempt; formerly, if the lookup attempt failed, the code would try again
for each host name entry in pg_hba.conf.  Since more or less the whole
point of this design is to ensure there's only one lookup attempt not one
per entry, the latter point represents a performance bug that seems
sufficient justification for back-patching.

Also, adjust src/port/getaddrinfo.c so that it plays as well as it can
with this code.  Which is not all that well, since it does not have actual
support for rDNS lookup, but at least it should return the expected (and
required by spec) error codes so that the main code correctly perceives the
lack of functionality as a lookup failure.  It's unlikely that PG is still
being used in production on any machines that require our getaddrinfo.c,
so I'm not excited about working harder than this.

To keep the code in the various branches similar, this includes
back-patching commits c424d0d1052cb4053c8712ac44123f9b9a9aa3f2 and
1997f34db4687e671690ed054c8f30bb501b1168 into 9.2 and earlier.

Back-patch to 9.1 where the facility for hostnames in pg_hba.conf was
introduced.

10 years agoDe-anonymize the union in JsonbValue.
Tom Lane [Wed, 2 Apr 2014 18:30:08 +0000 (14:30 -0400)]
De-anonymize the union in JsonbValue.

Needed for strict C89 compliance.

10 years agoFix bugs in manipulation of PgBackendStatus.st_clienthostname.
Tom Lane [Wed, 2 Apr 2014 01:30:08 +0000 (21:30 -0400)]
Fix bugs in manipulation of PgBackendStatus.st_clienthostname.

Initialization of this field was not being done according to the
st_changecount protocol (it has to be done within the changecount increment
range, not outside).  And the test to see if the value should be reported
as null was wrong.  Noted while perusing uses of Port.remote_hostname.

This was wrong from the introduction of this code (commit 4a25bc145),
so back-patch to 9.1.

10 years agoFix bug in the new GIN incomplete-split code.
Heikki Linnakangas [Tue, 1 Apr 2014 19:45:10 +0000 (22:45 +0300)]
Fix bug in the new GIN incomplete-split code.

Inserting a downlink to an internal page clears the incomplete-split flag
of the child's left sibling, so the left sibling's LSN also needs to be
updated and it needs to be marked dirty. The codepath for an insertion got
this right, but the case where the internal node is split because of
inserting the new downlink missed that.

10 years agoDoc: improve discussion of reverse+forward host name lookup in pg_hba.conf.
Tom Lane [Tue, 1 Apr 2014 19:20:30 +0000 (15:20 -0400)]
Doc: improve discussion of reverse+forward host name lookup in pg_hba.conf.

Fix some grammatical issues and make it a bit more readable.

10 years agoRemove dead check for backup block, replace with Assert.
Heikki Linnakangas [Tue, 1 Apr 2014 18:16:10 +0000 (21:16 +0300)]
Remove dead check for backup block, replace with Assert.

We don't use backup blocks with GIN vacuum records anymore, the page is
always recreated from scratch.

10 years agoFix bug in the new B-tree incomplete-split code.
Heikki Linnakangas [Tue, 1 Apr 2014 16:19:47 +0000 (19:19 +0300)]
Fix bug in the new B-tree incomplete-split code.

Inserting a downlink to an internal page clears the incomplete-split flag
of the child's left sibling, so the left sibling's LSN also needs to be
updated.

10 years agoMove SizeOfHeapNewCid next to xl_heap_new_cid struct.
Heikki Linnakangas [Tue, 1 Apr 2014 13:23:16 +0000 (16:23 +0300)]
Move SizeOfHeapNewCid next to xl_heap_new_cid struct.

They belong together, but the xl_heap_rewrite_mapping struct was wedged
in between.

10 years agoFix typo in comment.
Heikki Linnakangas [Tue, 1 Apr 2014 06:27:37 +0000 (09:27 +0300)]
Fix typo in comment.

Amit Langote

10 years agoMark FastPathStrongRelationLocks volatile.
Robert Haas [Mon, 31 Mar 2014 18:32:12 +0000 (14:32 -0400)]
Mark FastPathStrongRelationLocks volatile.

Otherwise, the compiler might decide to move modifications to data
within this structure outside the enclosing SpinLockAcquire /
SpinLockRelease pair, leading to shared memory corruption.

This may or may not explain a recent lmgr-related buildfarm failure
on prairiedog, but it needs to be fixed either way.

10 years agotest_decoding: Update .gitignore
Robert Haas [Mon, 31 Mar 2014 18:18:35 +0000 (14:18 -0400)]
test_decoding: Update .gitignore

Commit 7317d8d961f210c3a6b20972cd605bcd9bffb06e changed the set of
things that need to be ignored, but neglected to update .gitignore.

10 years agoCount buffers dirtied due to hints in pgBufferUsage.shared_blks_dirtied.
Robert Haas [Mon, 31 Mar 2014 17:06:26 +0000 (13:06 -0400)]
Count buffers dirtied due to hints in pgBufferUsage.shared_blks_dirtied.

Previously, such buffers weren't counted, with the possible result that
EXPLAIN (BUFFERS) and pg_stat_statements would understate the true
number of blocks dirtied by an SQL statement.

Back-patch to 9.2, where this counter was introduced.

Amit Kapila

10 years agoFix thinko in logical decoding code.
Robert Haas [Mon, 31 Mar 2014 17:03:18 +0000 (13:03 -0400)]
Fix thinko in logical decoding code.

Andres Freund

10 years agoRewrite the way GIN posting lists are packed on a page, to reduce WAL volume.
Heikki Linnakangas [Mon, 31 Mar 2014 12:15:19 +0000 (15:15 +0300)]
Rewrite the way GIN posting lists are packed on a page, to reduce WAL volume.

Inserting (in retail) into the new 9.4 format GIN posting tree created much
larger WAL records than in 9.3. The previous strategy to WAL logging was
basically to log the whole page on each change, with the exception of
completely unmodified segments up to the first modified one. That was not
too bad when appending to the end of the page, as only the last segment had
to be WAL-logged, but per Fujii Masao's testing, even that produced 2x the
WAL volume that 9.3 did.

The new strategy is to keep track of changes to the posting lists in a more
fine-grained fashion, and also make the repacking" code smarter to avoid
decoding and re-encoding segments unnecessarily.

10 years agoRename GinLogicValue to GinTernaryValue.
Heikki Linnakangas [Mon, 31 Mar 2014 07:26:38 +0000 (10:26 +0300)]
Rename GinLogicValue to GinTernaryValue.

It's more descriptive. Also, get rid of the enum, and use #defines instead,
per Greg Stark's suggestion.

10 years agoUse separate output dirs for test_decoding's two runs.
Andrew Dunstan [Sun, 30 Mar 2014 22:30:59 +0000 (18:30 -0400)]
Use separate output dirs for test_decoding's two runs.

contrib/test_decoding's "make check" runs two sets of tests. Unless we
specify separate output directories for each set the isolation tests
will overwrite the output from the  normal regression set. Doing this
will help the buildfarm collect complete logs.

10 years agopsql: display "Replica Identity" only for FULL and NOTHING
Bruce Momjian [Sat, 29 Mar 2014 23:00:11 +0000 (19:00 -0400)]
psql:  display "Replica Identity" only for FULL and NOTHING

INDEX is already displayed on the index, and we now exclude pg_catalog.
DEFAULT is not displayed.

10 years agoFix dumping of a materialized view that depends on a table's primary key.
Tom Lane [Sat, 29 Mar 2014 21:34:00 +0000 (17:34 -0400)]
Fix dumping of a materialized view that depends on a table's primary key.

It is possible for a view or materialized view to depend on a table's
primary key, if the view query relies on functional dependency to
abbreviate a GROUP BY list.  This is problematic for pg_dump since we
ordinarily want to dump view definitions in the pre-data section but
indexes in post-data.  pg_dump knows how to deal with this situation for
regular views, by breaking the view's ON SELECT rule apart from the view
proper.  But it had not been taught what to do about materialized views,
and in fact mistakenly dumped them as regular views in such cases, as
seen in bug #9616 from Jesse Denardo.

If we had CREATE OR REPLACE MATERIALIZED VIEW, we could fix this in a
manner analogous to what's done for regular views; but we don't yet,
and we'd not back-patch such a thing into 9.3 anyway.  As a hopefully-
temporary workaround, break the circularity by postponing the matview
into post-data altogether when this case occurs.

10 years agoRevert "Secure Unix-domain sockets of "make check" temporary clusters."
Noah Misch [Sat, 29 Mar 2014 07:12:00 +0000 (03:12 -0400)]
Revert "Secure Unix-domain sockets of "make check" temporary clusters."

About half of the buildfarm members use too-long directory names,
strongly suggesting that this approach is a dead end.

10 years agoSecure Unix-domain sockets of "make check" temporary clusters.
Noah Misch [Sat, 29 Mar 2014 04:52:56 +0000 (00:52 -0400)]
Secure Unix-domain sockets of "make check" temporary clusters.

Any OS user able to access the socket can connect as the bootstrap
superuser and in turn execute arbitrary code as the OS user running the
test.  Protect against that by placing the socket in the temporary data
directory, which has mode 0700 thanks to initdb.  Back-patch to 8.4 (all
supported versions).  The hazard remains wherever the temporary cluster
accepts TCP connections, notably on Windows.

Attempts to run "make check" from a directory with a long name will now
fail.  An alternative not sharing that problem was to place the socket
in a subdirectory of /tmp, but that is only secure if /tmp is sticky.
The PG_REGRESS_SOCK_DIR environment variable is available as a
workaround when testing from long directory paths.

As a convenient side effect, this lets testing proceed smoothly in
builds that override DEFAULT_PGSOCKET_DIR.  Popular non-default values
like /var/run/postgresql are often unwritable to the build user.

Security: CVE-2014-0067

10 years agoDocument platform-specificity of unix_socket_permissions.
Noah Misch [Sat, 29 Mar 2014 04:52:31 +0000 (00:52 -0400)]
Document platform-specificity of unix_socket_permissions.

Back-patch to 8.4 (all supported versions).

10 years agoForce consistent row order in contrib/test_decoding regression test.
Noah Misch [Sat, 29 Mar 2014 04:31:44 +0000 (00:31 -0400)]
Force consistent row order in contrib/test_decoding regression test.

10 years agoImprove regression test for pg_filenode_relation().
Tom Lane [Fri, 28 Mar 2014 20:58:09 +0000 (16:58 -0400)]
Improve regression test for pg_filenode_relation().

Make it print the details in case there's a failure.

Andres Freund, slightly modified by me

10 years agoAdjust getpwuid() fix commit to display errno string on failure
Bruce Momjian [Fri, 28 Mar 2014 16:50:11 +0000 (12:50 -0400)]
Adjust getpwuid() fix commit to display errno string on failure

This adjusts patch 613c6d26bd42dd8c2dd0664315be9551475b8864.

10 years agoFix EquivalenceClass processing for nested append relations.
Tom Lane [Fri, 28 Mar 2014 15:50:01 +0000 (11:50 -0400)]
Fix EquivalenceClass processing for nested append relations.

The original coding of EquivalenceClasses didn't foresee that appendrel
child relations might themselves be appendrels; but this is possible for
example when a UNION ALL subquery scans a table with inheritance children.
The oversight led to failure to optimize ordering-related issues very well
for the grandchild tables.  After some false starts involving explicitly
flattening the appendrel representation, we found that this could be fixed
easily by removing a few implicit assumptions about appendrel parent rels
not being children themselves.

Kyotaro Horiguchi and Tom Lane, reviewed by Noah Misch

10 years agoUn-break peer authentication.
Tom Lane [Fri, 28 Mar 2014 14:30:37 +0000 (10:30 -0400)]
Un-break peer authentication.

Commit 613c6d26bd42dd8c2dd0664315be9551475b8864 sloppily replaced a
lookup of the UID obtained from getpeereid() with a lookup of the
server's own user name, thus totally destroying peer authentication.
Revert.  Per report from Christoph Berg.

In passing, make sure get_user_name() zeroes *errstr on success on
Windows as well as non-Windows.  I don't think any callers actually
depend on this ATM, but we should be consistent across platforms.

10 years agoImprove documentation note about Python 2.3 and cdecimal.
Tom Lane [Thu, 27 Mar 2014 21:15:45 +0000 (17:15 -0400)]
Improve documentation note about Python 2.3 and cdecimal.

Explain exactly what fails (ie, function arguments of type numeric)
if you don't have it.

10 years agocontrib/test_decoding: adjust expected output
Bruce Momjian [Thu, 27 Mar 2014 14:47:48 +0000 (10:47 -0400)]
contrib/test_decoding:  adjust expected output

Expected output has changed because of psql replica identity output
changes.

Reported by Christoph Berg

10 years agoSilence compiler warnings in new jsonb code.
Heikki Linnakangas [Thu, 27 Mar 2014 06:53:44 +0000 (08:53 +0200)]
Silence compiler warnings in new jsonb code.

Amit Kapila.

10 years agoDocument that Python 2.3 requires cdecimal module for full functionality.
Tom Lane [Thu, 27 Mar 2014 02:43:22 +0000 (22:43 -0400)]
Document that Python 2.3 requires cdecimal module for full functionality.

This has been true for some time, but we were leaving users to discover it
the hard way.

Back-patch to 9.2.  It might've been true before that, but we were claiming
Python 2.2 compatibility before that, so I won't guess at the exact
requirements back then.

10 years agoFix uninitialized variables in json's populate_record_worker().
Andrew Dunstan [Wed, 26 Mar 2014 22:20:56 +0000 (18:20 -0400)]
Fix uninitialized variables in json's populate_record_worker().

Peter Geoghegan.

10 years agoFix refcounting bug in PLy_modify_tuple().
Tom Lane [Wed, 26 Mar 2014 20:41:32 +0000 (16:41 -0400)]
Fix refcounting bug in PLy_modify_tuple().

We must increment the refcount on "plntup" as soon as we have the
reference, not sometime later.  Otherwise, if an error is thrown in
between, the Py_XDECREF(plntup) call in the PG_CATCH block removes a
refcount we didn't add, allowing the object to be freed even though
it's still part of the plpython function's parsetree.

This appears to be the cause of crashes seen on buildfarm member
prairiedog.  It's a bit surprising that we've not seen it fail repeatably
before, considering that the regression tests have been exercising the
faulty code path since 2009.

The real-world impact is probably minimal, since it's unlikely anyone would
be provoking the "TD["new"] is not a dictionary" error in production, and
that's the only case that is actually wrong.  Still, it's a bug affecting
the regression tests, so patch all supported branches.

In passing, remove dead variable "plstr", and demote "platt" to a local
variable inside the PG_TRY block, since we don't need to clean it up
in the PG_CATCH path.

10 years agoPass more than the first XLogRecData entry to rm_desc, with WAL_DEBUG.
Heikki Linnakangas [Wed, 26 Mar 2014 16:04:57 +0000 (18:04 +0200)]
Pass more than the first XLogRecData entry to rm_desc, with WAL_DEBUG.

If you compile with WAL_DEBUG and enable it with wal_debug=on, we used to
only pass the first XLogRecData entry to the rm_desc routine. I think the
original assumprion was that the first XLogRecData entry contains all the
necessary information for the rm_desc routine, but that's a pretty shaky
assumption. At least standby_redo didn't get the memo.

To fix, piece together all the data in a temporary buffer, and pass that to
the rm_desc routine.

It's been like this forever, but the patch didn't apply cleanly to
back-branches. Probably wouldn't be hard to fix the conflicts, but it's
not worth the trouble.

10 years agopsql: update "replica identity" display for \d+
Bruce Momjian [Wed, 26 Mar 2014 15:13:17 +0000 (11:13 -0400)]
psql:  update "replica identity" display for \d+

Display "replica identity" only for \d plus mode, exclude system schema
objects, and display all possible values, not just non-default,
non-index ones.

10 years agopg_upgrade: use pg_usleep(); remove Windows workaround
Bruce Momjian [Wed, 26 Mar 2014 14:22:16 +0000 (10:22 -0400)]
pg_upgrade: use pg_usleep();  remove Windows workaround

10 years agoCleanup around json_to_record/json_to_recordset
Andrew Dunstan [Wed, 26 Mar 2014 14:18:24 +0000 (10:18 -0400)]
Cleanup around json_to_record/json_to_recordset

Set function parameter names and defaults. Add jsonb versions (which the
code already provided for so the actual new code is trivial). Add jsonb
regression tests and docs.

Bump catalog version (which I apparently forgot to do when jsonb was
committed).

10 years agoUse pg_usleep() instead of plain sleep(), to fix Windows build
Heikki Linnakangas [Wed, 26 Mar 2014 13:25:39 +0000 (15:25 +0200)]
Use pg_usleep() instead of plain sleep(), to fix Windows build

Per buildfarm.

10 years agoAdd -f/--follow option to pg_xlogdump.
Heikki Linnakangas [Wed, 26 Mar 2014 11:48:20 +0000 (13:48 +0200)]
Add -f/--follow option to pg_xlogdump.

This is useful for seeing what WAL records are inserted in real-time, by
pointing pg_xlogdump to a live server.

10 years agoFix 'recheck' flag in tsquery's GIN tri-consistent function.
Heikki Linnakangas [Wed, 26 Mar 2014 08:13:44 +0000 (10:13 +0200)]
Fix 'recheck' flag in tsquery's GIN tri-consistent function.

It needs to be initialized, like in the boolean gin_tsquery_consistent
version.

Peter Geoghegan.

10 years agoTidy up the populate/to_record{set} code for json a bit.
Andrew Dunstan [Wed, 26 Mar 2014 01:20:54 +0000 (21:20 -0400)]
Tidy up the populate/to_record{set} code for json a bit.

In the process fix a small bug.

10 years agoDon't forget to flush XLOG_PARAMETER_CHANGE record.
Fujii Masao [Tue, 25 Mar 2014 17:12:39 +0000 (02:12 +0900)]
Don't forget to flush XLOG_PARAMETER_CHANGE record.

Backpatch to 9.0 where XLOG_PARAMETER_CHANGE record was instroduced.

10 years agoFix typos in pg_basebackup documentation
Magnus Hagander [Tue, 25 Mar 2014 10:16:57 +0000 (11:16 +0100)]
Fix typos in pg_basebackup documentation

Joshua Tolley

10 years agodoc: list unlogged tables as a non-durable option
Bruce Momjian [Tue, 25 Mar 2014 02:04:44 +0000 (22:04 -0400)]
doc:  list unlogged tables as a non-durable option

10 years agoRemove wchar.c Asserts that were stricter than the main code
Bruce Momjian [Mon, 24 Mar 2014 19:59:38 +0000 (15:59 -0400)]
Remove wchar.c Asserts that were stricter than the main code

Assert errors were thrown for functions being passed invalid encodings,
while the main code handled it just fine.

Also document that libpq's PQclientEncoding() returns -1 for an encoding
lookup failure.

Per report from Peter Geoghegan

10 years agodocs: Add short "cover density" description
Bruce Momjian [Mon, 24 Mar 2014 19:46:59 +0000 (15:46 -0400)]
docs:  Add short "cover density" description

Also, previous commit 1420f3a9827a39e5c6c998f6fa35a6fc97903145 to fix
ts_rank_cd() for stripped lexemes was from a patch created by Alex Hill.

10 years agoFix ts_rank_cd() to ignore stripped lexemes
Bruce Momjian [Mon, 24 Mar 2014 18:36:36 +0000 (14:36 -0400)]
Fix ts_rank_cd() to ignore stripped lexemes

Previously, stripped lexemes got a default location and could be
considered if mixed with non-stripped lexemes.

BACKWARD INCOMPATIBILITY CHANGE

10 years agoChange ginMergeItemPointers to return a palloc'd array.
Heikki Linnakangas [Mon, 24 Mar 2014 16:40:26 +0000 (18:40 +0200)]
Change ginMergeItemPointers to return a palloc'd array.

That seems nicer than making it the caller's responsibility to pass a
suitable-sized array. All the callers were just palloc'ing an array anyway.

10 years agoFix START_REPLICATION syntax in document.
Fujii Masao [Mon, 24 Mar 2014 10:23:32 +0000 (19:23 +0900)]
Fix START_REPLICATION syntax in document.

Enclose "TIMELINE tli" part with brackets because it's optional.

Backport to 9.3 where TIMELINE option was introduced.

Noted by Marko Tiikkaja

10 years agoRemove dead code and add comments.
Heikki Linnakangas [Mon, 24 Mar 2014 09:02:23 +0000 (11:02 +0200)]
Remove dead code and add comments.

'cbuffer' variable was left over from an earlier version of the patch to
rewrite the incomplete split handling.

10 years agoFix "the the" typos.
Heikki Linnakangas [Mon, 24 Mar 2014 06:42:13 +0000 (08:42 +0200)]
Fix "the the" typos.

Erik Rijkers

10 years agoDo jsonb regression test input in the conventional way.
Andrew Dunstan [Mon, 24 Mar 2014 00:18:06 +0000 (20:18 -0400)]
Do jsonb regression test input in the conventional way.

This should make the buildfarm happier.

10 years agoFix mis-spelling in jsonb docs.
Andrew Dunstan [Sun, 23 Mar 2014 22:25:16 +0000 (18:25 -0400)]
Fix mis-spelling in jsonb docs.

Per Thom Brown.

10 years agoIntroduce jsonb, a structured format for storing json.
Andrew Dunstan [Sun, 23 Mar 2014 20:40:19 +0000 (16:40 -0400)]
Introduce jsonb, a structured format for storing json.

The new format accepts exactly the same data as the json type. However, it is
stored in a format that does not require reparsing the orgiginal text in order
to process it, making it much more suitable for indexing and other operations.
Insignificant whitespace is discarded, and the order of object keys is not
preserved. Neither are duplicate object keys kept - the later value for a given
key is the only one stored.

The new type has all the functions and operators that the json type has,
with the exception of the json generation functions (to_json, json_agg etc.)
and with identical semantics. In addition, there are operator classes for
hash and btree indexing, and two classes for GIN indexing, that have no
equivalent in the json type.

This feature grew out of previous work by Oleg Bartunov and Teodor Sigaev, which
was intended to provide similar facilities to a nested hstore type, but which
in the end proved to have some significant compatibility issues.

Authors: Oleg Bartunov,  Teodor Sigaev, Peter Geoghegan and Andrew Dunstan.
Review: Andres Freund