]> granicus.if.org Git - postgresql/log
postgresql
9 years agoFix off-by-one in pg_xlogdump's fuzzy_open_file().
Andres Freund [Sun, 4 Jan 2015 14:35:46 +0000 (15:35 +0100)]
Fix off-by-one in pg_xlogdump's fuzzy_open_file().

In the unlikely case of stdin (fd 0) being closed, the off-by-one
would lead to pg_xlogdump failing to open files.

Spotted by Coverity.

Backpatch to 9.3 where pg_xlogdump was introduced.

9 years agoRemove superflous variable from xlogreader's XLogFindNextRecord().
Andres Freund [Sun, 4 Jan 2015 14:35:46 +0000 (15:35 +0100)]
Remove superflous variable from xlogreader's XLogFindNextRecord().

Pointed out by Coverity.

Since this is mere, and debatable, cosmetics I'm not backpatching
this.

9 years agoAdd missing va_end() call to a early exit in dmetaphone.c's StringAt().
Andres Freund [Sun, 4 Jan 2015 14:35:46 +0000 (15:35 +0100)]
Add missing va_end() call to a early exit in dmetaphone.c's StringAt().

Pointed out by Coverity.

Backpatch to all supported branches, the code has been that way for a
long while.

9 years agoFix inconsequential fd leak in the new mark_file_as_archived() function.
Andres Freund [Sun, 4 Jan 2015 13:36:21 +0000 (14:36 +0100)]
Fix inconsequential fd leak in the new mark_file_as_archived() function.

As every error in mark_file_as_archived() will lead to a failure of
pg_basebackup the FD leak couldn't ever lead to a real problem.  It
seems better to fix the leak anyway though, rather than silence
Coverity, as the usage of the function might get extended or copied at
some point in the future.

Pointed out by Coverity.

Backpatch to 9.2, like the relevant part of the previous patch.

9 years agoPrevent WAL files created by pg_basebackup -x/X from being archived again.
Andres Freund [Sat, 3 Jan 2015 19:51:52 +0000 (20:51 +0100)]
Prevent WAL files created by pg_basebackup -x/X from being archived again.

WAL (and timeline history) files created by pg_basebackup did not
maintain the new base backup's archive status. That's currently not a
problem if the new node is used as a standby - but if that node is
promoted all still existing files can get archived again.  With a high
wal_keep_segment settings that can happen a significant time later -
which is quite confusing.

Change both the backend (for the -x/-X fetch case) and pg_basebackup
(for -X stream) itself to always mark WAL/timeline files included in
the base backup as .done. That's in line with walreceiver.c doing so.

The verbosity of the pg_basebackup changes show pretty clearly that it
needs some refactoring, but that'd result in not be backpatchable
changes.

Backpatch to 9.1 where pg_basebackup was introduced.

Discussion: 20141205002854.GE21964@awork2.anarazel.de

9 years agoAdd pg_string_endswith as the start of a string helper library in src/common.
Andres Freund [Sat, 3 Jan 2015 19:51:52 +0000 (20:51 +0100)]
Add pg_string_endswith as the start of a string helper library in src/common.

Backpatch to 9.3 where src/common was introduce, because a bugfix that
needs to be backpatched, requires the function. Earlier branches will
have to duplicate the code.

9 years agoTreat negative values of recovery_min_apply_delay as having no effect.
Tom Lane [Sat, 3 Jan 2015 18:14:03 +0000 (13:14 -0500)]
Treat negative values of recovery_min_apply_delay as having no effect.

At one point in the development of this feature, it was claimed that
allowing negative values would be useful to compensate for timezone
differences between master and slave servers.  That was based on a mistaken
assumption that commit timestamps are recorded in local time; but of course
they're in UTC.  Nor is a negative apply delay likely to be a sane way of
coping with server clock skew.  However, the committed patch still treated
negative delays as doing something, and the timezone misapprehension
survived in the user documentation as well.

If recovery_min_apply_delay were a proper GUC we'd just set the minimum
allowed value to be zero; but for the moment it seems better to treat
negative settings as if they were zero.

In passing do some extra wordsmithing on the parameter's documentation,
including correcting a second misstatement that the parameter affects
processing of Restore Point records.

Issue noted by Michael Paquier, who also provided the code patch; doc
changes by me.  Back-patch to 9.4 where the feature was introduced.

9 years agoMake path to pg_service.conf absolute in documentation
Magnus Hagander [Sat, 3 Jan 2015 12:18:54 +0000 (13:18 +0100)]
Make path to pg_service.conf absolute in documentation

The system file is always in the absolute path /etc/, not relative.

David Fetter

9 years agoDon't run rowsecurity in parallel with other regression tests.
Tom Lane [Wed, 31 Dec 2014 22:04:27 +0000 (17:04 -0500)]
Don't run rowsecurity in parallel with other regression tests.

The short-lived event trigger in the rowsecurity test causes irreproducible
failures when the concurrent tests do something that the event trigger
can't cope with.  Per buildfarm.

9 years agoDocs: improve descriptions of ISO week-numbering date features.
Tom Lane [Wed, 31 Dec 2014 21:42:42 +0000 (16:42 -0500)]
Docs: improve descriptions of ISO week-numbering date features.

Use the phraseology "ISO 8601 week-numbering year" in place of just
"ISO year", and make related adjustments to other terminology.

The point of this change is that it seems some people see "ISO year"
and think "standard year", whereupon they're surprised when constructs
like to_char(..., "IYYY-MM-DD") produce nonsensical results.  Perhaps
hanging a few more adjectives on it will discourage them from jumping
to false conclusions.  I put in an explicit warning against that
specific usage, too, though the main point is to discourage people
who haven't read this far down the page.

In passing fix some nearby markup and terminology inconsistencies.

9 years agoPrint more information about getObjectIdentityParts() failures.
Tom Lane [Wed, 31 Dec 2014 19:44:43 +0000 (14:44 -0500)]
Print more information about getObjectIdentityParts() failures.

This might help us debug what's happening on some buildfarm members.

In passing, reduce the message from ereport to elog --- it doesn't seem
like this should be a user-facing case, so not worth translating.

9 years agoImprove consistency of parsing of psql's magic variables.
Tom Lane [Wed, 31 Dec 2014 17:16:53 +0000 (12:16 -0500)]
Improve consistency of parsing of psql's magic variables.

For simple boolean variables such as ON_ERROR_STOP, psql has for a long
time recognized variant spellings of "on" and "off" (such as "1"/"0"),
and it also made a point of warning you if you'd misspelled the setting.
But these conveniences did not exist for other keyword-valued variables.
In particular, though ECHO_HIDDEN and ON_ERROR_ROLLBACK include "on" and
"off" as possible values, none of the alternative spellings for those were
recognized; and to make matters worse the code would just silently assume
"on" was meant for any unrecognized spelling.  Several people have reported
getting bitten by this, so let's fix it.  In detail, this patch:

* Allows all spellings recognized by ParseVariableBool() for ECHO_HIDDEN
and ON_ERROR_ROLLBACK.

* Reports a warning for unrecognized values for COMP_KEYWORD_CASE, ECHO,
ECHO_HIDDEN, HISTCONTROL, ON_ERROR_ROLLBACK, and VERBOSITY.

* Recognizes all values for all these variables case-insensitively;
previously there was a mishmash of case-sensitive and case-insensitive
behaviors.

Back-patch to all supported branches.  There is a small risk of breaking
existing scripts that were accidentally failing to malfunction; but the
consensus is that the chance of detecting real problems and preventing
future mistakes outweighs this.

9 years agoAdd missing pstrdup calls
Alvaro Herrera [Wed, 31 Dec 2014 16:19:40 +0000 (13:19 -0300)]
Add missing pstrdup calls

The one for the OCLASS_COLLATION case was noticed by
CLOBBER_CACHE_ALWAYS buildfarm members; the others I spotted by manual
code inspection.

Also remove a redundant check.

9 years agoDon't tab-complete COMMENT ON ... IS with IS.
Robert Haas [Wed, 31 Dec 2014 16:06:43 +0000 (11:06 -0500)]
Don't tab-complete COMMENT ON ... IS with IS.

Ian Barwick

9 years agopg_event_trigger_dropped_objects: Add name/args output columns
Alvaro Herrera [Tue, 30 Dec 2014 20:41:46 +0000 (17:41 -0300)]
pg_event_trigger_dropped_objects: Add name/args output columns

These columns can be passed to pg_get_object_address() and used to
reconstruct the dropped objects identities in a remote server containing
similar objects, so that the drop can be replicated.

Reviewed by Stephen Frost, Heikki Linnakangas, Abhijit Menon-Sen, Andres
Freund.

9 years agoAdd pg_identify_object_as_address
Alvaro Herrera [Tue, 30 Dec 2014 18:41:50 +0000 (15:41 -0300)]
Add pg_identify_object_as_address

This function returns object type and objname/objargs arrays, which can
be passed to pg_get_object_address.  This is especially useful because
the textual representation can be copied to a remote server in order to
obtain the corresponding OID-based address.  In essence, this function
is the inverse of recently added pg_get_object_address().

Catalog version bumped due to the addition of the new function.

Also add docs to pg_get_object_address.

9 years agoFix object_address expected output
Alvaro Herrera [Tue, 30 Dec 2014 18:04:21 +0000 (15:04 -0300)]
Fix object_address expected output

Per pink buildfarm

9 years agoUse TypeName to represent type names in certain commands
Alvaro Herrera [Tue, 30 Dec 2014 16:57:23 +0000 (13:57 -0300)]
Use TypeName to represent type names in certain commands

In COMMENT, DROP, SECURITY LABEL, and the new pg_get_object_address
function, we were representing types as a list of names, same as other
objects; but types are special objects that require their own
representation to be totally accurate.  In the original COMMENT code we
had a note about fixing it which was lost in the course of c10575ff005.
Change all those places to use TypeName instead, as suggested by that
comment.

Right now the original coding doesn't cause any bugs, so no backpatch.
It is more problematic for proposed future code that operate with object
addresses from the SQL interface; type details such as array-ness are
lost when working with the degraded representation.

Thanks to Petr Jelínek and Dimitri Fontaine for offlist help on finding
a solution to a shift/reduce grammar conflict.

9 years agoRevert the GinMaxItemSize calculation so that we fit 3 tuples per page.
Heikki Linnakangas [Tue, 30 Dec 2014 12:29:20 +0000 (14:29 +0200)]
Revert the GinMaxItemSize calculation so that we fit 3 tuples per page.

Commit 36a35c55 changed the divisor from 3 to 6, for no apparent reason.
Reducing GinMaxItemSize like that created a dump/reload hazard: loading a
9.3 database to 9.4 might fail with "index row size XXX exceeds maximum 1352
for index ..." error. Revert the change.

While we're at it, make the calculation slightly more accurate. It used to
divide the available space on page by three, then subtract
sizeof(ItemIdData), and finally round down. That's not totally accurate; the
item pointers for the three items are packed tight right after the page
header, but there is alignment padding after the item pointers. Change the
calculation to reflect that, like BTMaxItemSize does. I tested this with
different block sizes on systems with 4- and 8-byte alignment, and the value
after the final MAXALIGN_DOWN was the same with both methods on all
configurations. So this does not make any difference currently, but let's be
tidy.

Also add a comment explaining what the macro does.

This fixes bug #12292 reported by Robert Thaler. Backpatch to 9.4, where the
bug was introduced.

9 years agoFix resource leak pointed out by Coverity.
Tatsuo Ishii [Tue, 30 Dec 2014 11:19:50 +0000 (20:19 +0900)]
Fix resource leak pointed out by Coverity.

9 years agoAssorted minor fixes for psql metacommand docs.
Tom Lane [Mon, 29 Dec 2014 19:20:54 +0000 (14:20 -0500)]
Assorted minor fixes for psql metacommand docs.

Document the long forms of \H \i \ir \o \p \r \w ... apparently, we have
a long and dishonorable history of leaving out the unabbreviated names of
psql backslash commands.

Avoid saying "Unix shell"; we can just say "shell" with equal clarity,
and not leave Windows users wondering whether the feature works for them.

Improve consistency of documentation of \g \o \w metacommands.  There's
no reason to use slightly different wording or markup for each one.

9 years agoRemove duplicate assignment in new pg_get_object_address() function.
Tom Lane [Sun, 28 Dec 2014 17:03:32 +0000 (12:03 -0500)]
Remove duplicate assignment in new pg_get_object_address() function.

Noted by Coverity.

9 years agoRestrict name list len for domain constraints
Alvaro Herrera [Fri, 26 Dec 2014 17:31:37 +0000 (14:31 -0300)]
Restrict name list len for domain constraints

This avoids an ugly-looking "cache lookup failure" message.

Ugliness pointed out by Andres Freund.

9 years agoRemove event trigger from object_address test
Alvaro Herrera [Fri, 26 Dec 2014 17:18:09 +0000 (14:18 -0300)]
Remove event trigger from object_address test

It is causing trouble when run in parallel mode, because dropping the
function other sessions are running concurrently causes them to fail due
to inability to find the function.

Per buildfarm, as noted by Tom Lane.

9 years agoGrab heavyweight tuple lock only before sleeping
Alvaro Herrera [Fri, 26 Dec 2014 16:52:27 +0000 (13:52 -0300)]
Grab heavyweight tuple lock only before sleeping

We were trying to acquire the lock even when we were subsequently
not sleeping in some other transaction, which opens us up unnecessarily
to deadlocks.  In particular, this is troublesome if an update tries to
lock an updated version of a tuple and finds itself doing EvalPlanQual
update chain walking; more than two sessions doing this concurrently
will find themselves sleeping on each other because the HW tuple lock
acquisition in heap_lock_tuple called from EvalPlanQualFetch races with
the same tuple lock being acquired in heap_update -- one of these
sessions sleeps on the other one to finish while holding the tuple lock,
and the other one sleeps on the tuple lock.

Per trouble report from Andrew Sackville-West in
http://www.postgresql.org/message-id/20140731233051.GN17765@andrew-ThinkPad-X230

His scenario can be simplified down to a relatively simple
isolationtester spec file which I don't include in this commit; the
reason is that the current isolationtester is not able to deal with more
than one blocked session concurrently and it blocks instead of raising
the expected deadlock.  In the future, if we improve isolationtester, it
would be good to include the spec file in the isolation schedule.  I
posted it in
http://www.postgresql.org/message-id/20141212205254.GC1768@alvh.no-ip.org

Hat tip to Mark Kirkwood, who helped diagnose the trouble.

9 years agoHave config_sspi_auth() permit IPv6 localhost connections.
Noah Misch [Thu, 25 Dec 2014 18:52:03 +0000 (13:52 -0500)]
Have config_sspi_auth() permit IPv6 localhost connections.

Windows versions later than Windows Server 2003 map "localhost" to ::1.
Account for that in the generated pg_hba.conf, fixing another oversight
in commit f6dc6dd5ba54d52c0733aaafc50da2fbaeabb8b0.  Back-patch to 9.0,
like that commit.

David Rowley and Noah Misch

9 years agoBlindly fix a dtrace probe in lwlock.c for a removed local variable.
Andres Freund [Thu, 25 Dec 2014 18:48:46 +0000 (19:48 +0100)]
Blindly fix a dtrace probe in lwlock.c for a removed local variable.

Per buildfarm member locust.

9 years agoTemporarily revert "Move pg_lzcompress.c to src/common."
Tom Lane [Thu, 25 Dec 2014 18:22:55 +0000 (13:22 -0500)]
Temporarily revert "Move pg_lzcompress.c to src/common."

This reverts commit 60838df922345b26a616e49ac9fab808a35d1f85.
That change needs a bit more thought to be workable.  In view of
the potentially machine-dependent stuff that went in today,
we need all of the buildfarm to be testing those other changes.

9 years agoLockless StrategyGetBuffer clock sweep hot path.
Andres Freund [Thu, 25 Dec 2014 17:24:20 +0000 (18:24 +0100)]
Lockless StrategyGetBuffer clock sweep hot path.

StrategyGetBuffer() has proven to be a bottleneck in a number of
buffer acquisition heavy workloads. To some degree this has already
been alleviated by 5d7962c6, but it still can be quite a heavy
bottleneck.  The problem is that in unfortunate usage patterns a
single StrategyGetBuffer() call will have to look at a large number of
buffers - in turn making it likely that the process will be put to
sleep while still holding the spinlock.

Replace most of the usage of the buffer_strategy_lock spinlock for the
clock sweep by a atomic nextVictimBuffer variable. That variable,
modulo NBuffers, is the current hand of the clock sweep. The buffer
clock-sweep then only needs to acquire the spinlock after a
wraparound. And even then only in the process that did the wrapping
around. That alleviates nearly all the contention on the relevant
spinlock, although significant contention on the cacheline can still
exist.

Reviewed-By: Robert Haas and Amit Kapila
Discussion: 20141010160020.GG6670@alap3.anarazel.de,
    20141027133218.GA2639@awork2.anarazel.de

9 years agoImprove LWLock scalability.
Andres Freund [Thu, 25 Dec 2014 16:24:30 +0000 (17:24 +0100)]
Improve LWLock scalability.

The old LWLock implementation had the problem that concurrent lock
acquisitions required exclusively acquiring a spinlock. Often that
could lead to acquirers waiting behind the spinlock, even if the
actual LWLock was free.

The new implementation doesn't acquire the spinlock when acquiring the
lock itself. Instead the new atomic operations are used to atomically
manipulate the state. Only the waitqueue, used solely in the slow
path, is still protected by the spinlock. Check lwlock.c's header for
an explanation about the used algorithm.

For some common workloads on larger machines this can yield
significant performance improvements. Particularly in read mostly
workloads.

Reviewed-By: Amit Kapila and Robert Haas
Author: Andres Freund

Discussion: 20130926225545.GB26663@awork2.anarazel.de

9 years agoConvert the PGPROC->lwWaitLink list into a dlist instead of open coding it.
Andres Freund [Thu, 25 Dec 2014 16:24:30 +0000 (17:24 +0100)]
Convert the PGPROC->lwWaitLink list into a dlist instead of open coding it.

Besides being shorter and much easier to read it changes the logic in
LWLockRelease() to release all shared lockers when waking up any. This
can yield some significant performance improvements - and the fairness
isn't really much worse than before, as we always allowed new shared
lockers to jump the queue.

9 years agoAdd capability to suppress CONTEXT: messages to elog machinery.
Andres Freund [Thu, 25 Dec 2014 16:24:30 +0000 (17:24 +0100)]
Add capability to suppress CONTEXT: messages to elog machinery.

Hiding context messages usually is not a good idea - except for rather
verbose debugging/development utensils like LOG_DEBUG. There the
amount of repeated context messages just bloat the log without adding
information.

9 years agoRemove duplicate include of slot.h.
Fujii Masao [Thu, 25 Dec 2014 13:47:53 +0000 (22:47 +0900)]
Remove duplicate include of slot.h.

Back-patch to 9.4, where this problem was added.

9 years agoMove pg_lzcompress.c to src/common.
Fujii Masao [Thu, 25 Dec 2014 11:46:14 +0000 (20:46 +0900)]
Move pg_lzcompress.c to src/common.

Exposing compression and decompression APIs of pglz makes possible its
use by extensions and contrib modules. pglz_decompress contained a call
to elog to emit an error message in case of corrupted data. This function
is changed to return a status code to let its callers return an error instead.

This commit is required for upcoming WAL compression feature so that
the WAL reader facility can decompress the WAL data by using pglz_decompress.

Michael Paquier

9 years agoAdd CST (China Standard Time) to our lists of timezone abbreviations.
Tom Lane [Wed, 24 Dec 2014 21:35:23 +0000 (16:35 -0500)]
Add CST (China Standard Time) to our lists of timezone abbreviations.

For some reason this seems to have been missed when the lists in
src/timezone/tznames/ were first constructed.  We can't put it in Default
because of the conflict with US CST, but we should certainly list it among
the alternative entries in Asia.txt.  (I checked for other oversights, but
all the other abbreviations that are in current use according to the IANA
files seem to be accounted for.)  Noted while responding to bug #12326.

9 years agoFix installcheck case for tap tests
Andrew Dunstan [Wed, 24 Dec 2014 15:31:36 +0000 (10:31 -0500)]
Fix installcheck case for tap tests

9 years agopgbench: remove odd trailing period in init progress output
Bruce Momjian [Wed, 24 Dec 2014 14:20:29 +0000 (09:20 -0500)]
pgbench:  remove odd trailing period in init progress output

9 years agoRemove unused fields from ReindexStmt.
Fujii Masao [Wed, 24 Dec 2014 12:40:47 +0000 (21:40 +0900)]
Remove unused fields from ReindexStmt.

fe263d1 changed the REINDEX logic so that those fields are not used at all,
but forgot to remove them.

Sawada Masahiko

9 years agoSuppress MSVC warning in typeStringToTypeName function.
Andres Freund [Wed, 24 Dec 2014 11:30:08 +0000 (12:30 +0100)]
Suppress MSVC warning in typeStringToTypeName function.

MSVC doesn't realize ereport(ERROR) doesn't return.

David Rowley

9 years agoRemove failing collation case from object_address regression test.
Tom Lane [Tue, 23 Dec 2014 21:55:51 +0000 (16:55 -0500)]
Remove failing collation case from object_address regression test.

Per buildfarm, this test case does not yield consistent results.
I don't think it's useful enough to figure out a workaround, either.

9 years agoRevert "Use a bitmask to represent role attributes"
Alvaro Herrera [Tue, 23 Dec 2014 18:35:49 +0000 (15:35 -0300)]
Revert "Use a bitmask to represent role attributes"

This reverts commit 1826987a46d079458007b7b6bbcbbd852353adbb.

The overall design was deemed unacceptable, in discussion following the
previous commit message; we might find some parts of it still
salvageable, but I don't want to be on the hook for fixing it, so let's
wait until we have a new patch.

9 years agoAdd SQL-callable pg_get_object_address
Alvaro Herrera [Tue, 23 Dec 2014 18:31:29 +0000 (15:31 -0300)]
Add SQL-callable pg_get_object_address

This allows access to get_object_address from SQL, which is useful to
obtain OID addressing information from data equivalent to that emitted
by the parser.  This is necessary infrastructure of a project to let
replication systems propagate object dropping events to remote servers,
where the schema might be different than the server originating the
DROP.

This patch also adds support for OBJECT_DEFAULT to get_object_address;
that is, it is now possible to refer to a column's default value.

Catalog version bumped due to the new function.

Reviewed by Stephen Frost, Heikki Linnakangas, Robert Haas, Andres
Freund, Abhijit Menon-Sen, Adam Brightwell.

9 years agoUse a bitmask to represent role attributes
Alvaro Herrera [Tue, 23 Dec 2014 13:22:09 +0000 (10:22 -0300)]
Use a bitmask to represent role attributes

The previous representation using a boolean column for each attribute
would not scale as well as we want to add further attributes.

Extra auxilliary functions are added to go along with this change, to
make up for the lost convenience of access of the old representation.

Catalog version bumped due to change in catalogs and the new functions.

Author: Adam Brightwell, minor tweaks by Álvaro
Reviewed by: Stephen Frost, Andres Freund, Álvaro Herrera

9 years agoget_object_address: separate domain constraints from table constraints
Alvaro Herrera [Tue, 23 Dec 2014 12:06:44 +0000 (09:06 -0300)]
get_object_address: separate domain constraints from table constraints

Apart from enabling comments on domain constraints, this enables a
future project to replicate object dropping to remote servers: with the
current mechanism there's no way to distinguish between the two types of
constraints, so there's no way to know what to drop.

Also added support for the domain constraint comments in psql's \dd and
pg_dump.

Catalog version bumped due to the change in ObjectType enum.

9 years agoChange local_preload_libraries to PGC_USERSET
Peter Eisentraut [Tue, 23 Dec 2014 04:05:46 +0000 (23:05 -0500)]
Change local_preload_libraries to PGC_USERSET

This allows it to be used with ALTER ROLE SET.

Although the old setting of PGC_BACKEND prevented changes after session
start, after discussion it was more useful to allow ALTER ROLE SET
instead and just document that changes during a session have no effect.
This is similar to how session_preload_libraries works already.

An alternative would be to change things to allow PGC_BACKEND and
PGC_SU_BACKEND settings to be changed by ALTER ROLE SET.  But that might
need further research (e.g., log_connections would probably not work).

based on patch by Kyotaro Horiguchi

9 years agoFurther tidy up on json aggregate documentation
Andrew Dunstan [Mon, 22 Dec 2014 23:30:46 +0000 (18:30 -0500)]
Further tidy up on json aggregate documentation

9 years agoFix documentation of argument type of json_agg and jsonb_agg
Andrew Dunstan [Mon, 22 Dec 2014 19:12:06 +0000 (14:12 -0500)]
Fix documentation of argument type of json_agg and jsonb_agg

json_agg was originally designed to aggregate records. However, it soon
became clear that it is useful for aggregating all kinds of values and
that's what we have on 9.3 and 9.4, and in head for it and jsonb_agg.
The documentation suggested otherwise, so this fixes it.

9 years agoMove rbtree.c from src/backend/utils/misc to src/backend/lib.
Heikki Linnakangas [Mon, 22 Dec 2014 15:52:08 +0000 (17:52 +0200)]
Move rbtree.c from src/backend/utils/misc to src/backend/lib.

We have other general-purpose data structures in src/backend/lib, so it
seems like a better home for the red-black tree as well.

9 years agoTurn much of the btree_gin macros into real functions.
Heikki Linnakangas [Mon, 22 Dec 2014 15:11:53 +0000 (17:11 +0200)]
Turn much of the btree_gin macros into real functions.

This makes the functions much nicer to read and edit, and also makes
debugging easier.

9 years agoUse a pairing heap for the priority queue in kNN-GiST searches.
Heikki Linnakangas [Mon, 22 Dec 2014 10:05:57 +0000 (12:05 +0200)]
Use a pairing heap for the priority queue in kNN-GiST searches.

This performs slightly better, uses less memory, and needs slightly less
code in GiST, than the Red-Black tree previously used.

Reviewed by Peter Geoghegan

9 years agoDocs: clarify treatment of variadic functions with zero variadic arguments.
Tom Lane [Sun, 21 Dec 2014 20:30:39 +0000 (15:30 -0500)]
Docs: clarify treatment of variadic functions with zero variadic arguments.

Explain that you have to use "VARIADIC ARRAY[]" to pass an empty array
to a variadic parameter position.  This was already implicit in the text
but it seems better to spell it out.

Per a suggestion from David Johnston, though I didn't use his proposed
wording.  Back-patch to all supported branches.

9 years agoFix file descriptor leak at end of recovery.
Heikki Linnakangas [Sun, 21 Dec 2014 19:49:03 +0000 (21:49 +0200)]
Fix file descriptor leak at end of recovery.

XLogFileInit() returns a file descriptor, which needs to be closed. The leak
was short-lived, since the startup process exits shortly afterwards, but it
was clearly a bug, nevertheless.

Per Coverity report.

9 years agodoc: Adjust wording of ALTER TABLESPACE restriction
Bruce Momjian [Sat, 20 Dec 2014 01:56:03 +0000 (20:56 -0500)]
doc:  Adjust wording of ALTER TABLESPACE restriction

Report by Noah Misch

9 years agopg_event_trigger_dropped_objects: add behavior flags
Alvaro Herrera [Fri, 19 Dec 2014 18:00:45 +0000 (15:00 -0300)]
pg_event_trigger_dropped_objects: add behavior flags

Add "normal" and "original" flags as output columns to the
pg_event_trigger_dropped_objects() function.  With this it's possible to
distinguish which objects, among those listed, need to be explicitely
referenced when trying to replicate a deletion.

This is necessary so that the list of objects can be pruned to the
minimum necessary to replicate the DROP command in a remote server that
might have slightly different schema (for instance, TOAST tables and
constraints with different names and such.)

Catalog version bumped due to change of function definition.

Reviewed by: Abhijit Menon-Sen, Stephen Frost, Heikki Linnakangas,
Robert Haas.

9 years agoFix timestamp in end-of-recovery WAL records.
Heikki Linnakangas [Fri, 19 Dec 2014 15:00:21 +0000 (17:00 +0200)]
Fix timestamp in end-of-recovery WAL records.

We used time(null) to set a TimestampTz field, which gave bogus results.
Noticed while looking at pg_xlogdump output.

Backpatch to 9.3 and above, where the fast promotion was introduced.

9 years agoPrevent potentially hazardous compiler/cpu reordering during lwlock release.
Andres Freund [Fri, 19 Dec 2014 13:29:52 +0000 (14:29 +0100)]
Prevent potentially hazardous compiler/cpu reordering during lwlock release.

In LWLockRelease() (and in 9.4+ LWLockUpdateVar()) we release enqueued
waiters using PGSemaphoreUnlock(). As there are other sources of such
unlocks backends only wake up if MyProc->lwWaiting is set to false;
which is only done in the aforementioned functions.

Before this commit there were dangers because the store to lwWaitLink
could become visible before the store to lwWaitLink. This could both
happen due to compiler reordering (on most compilers) and on some
platforms due to the CPU reordering stores.

The possible consequence of this is that a backend stops waiting
before lwWaitLink is set to NULL. If that backend then tries to
acquire another lock and has to wait there the list could become
corrupted once the lwWaitLink store is finally performed.

Add a write memory barrier to prevent that issue.

Unfortunately the barrier support has been only added in 9.2. Given
that the issue has not knowingly been observed in praxis it seems
sufficient to prohibit compiler reordering using volatile for 9.0 and
9.1. Actual problems due to compiler reordering are more likely
anyway.

Discussion: 20140210134625.GA15246@awork2.anarazel.de

9 years agoDefine Assert() et al to ((void)0) to avoid pedantic warnings.
Andres Freund [Mon, 8 Dec 2014 19:28:09 +0000 (20:28 +0100)]
Define Assert() et al to ((void)0) to avoid pedantic warnings.

gcc's -Wempty-body warns about the current usage when compiling
postgres without --enable-cassert.

9 years agoImprove documentation about CASE and constant subexpressions.
Tom Lane [Thu, 18 Dec 2014 21:38:52 +0000 (16:38 -0500)]
Improve documentation about CASE and constant subexpressions.

The possibility that constant subexpressions of a CASE might be evaluated
at planning time was touched on in 9.17.1 (CASE expressions), but it really
ought to be explained in 4.2.14 (Expression Evaluation Rules) which is the
primary discussion of such topics.  Add text and an example there, and
revise the <note> under CASE to link there.

Back-patch to all supported branches, since it's acted like this for a
long time (though 9.2+ is probably worse because of its more aggressive
use of constant-folding via replanning of nominally-prepared statements).
Pre-9.4, also back-patch text added in commit 0ce627d4 about CASE versus
aggregate functions.

Tom Lane and David Johnston, per discussion of bug #12273.

9 years agoUse %u to print out BlockNumber variables
Alvaro Herrera [Thu, 18 Dec 2014 20:59:00 +0000 (17:59 -0300)]
Use %u to print out BlockNumber variables

Per Tom Lane

9 years agoHave VACUUM log number of skipped pages due to pins
Alvaro Herrera [Thu, 18 Dec 2014 20:18:33 +0000 (17:18 -0300)]
Have VACUUM log number of skipped pages due to pins

Author: Jim Nasby, some kibitzing by Heikki Linnankangas.
Discussion leading to current behavior and precise wording fueled by
thoughts from Robert Haas and Andres Freund.

9 years agoImprove hash_create's API for selecting simple-binary-key hash functions.
Tom Lane [Thu, 18 Dec 2014 18:36:29 +0000 (13:36 -0500)]
Improve hash_create's API for selecting simple-binary-key hash functions.

Previously, if you wanted anything besides C-string hash keys, you had to
specify a custom hashing function to hash_create().  Nearly all such
callers were specifying tag_hash or oid_hash; which is tedious, and rather
error-prone, since a caller could easily miss the opportunity to optimize
by using hash_uint32 when appropriate.  Replace this with a design whereby
callers using simple binary-data keys just specify HASH_BLOBS and don't
need to mess with specific support functions.  hash_create() itself will
take care of optimizing when the key size is four bytes.

This nets out saving a few hundred bytes of code space, and offers
a measurable performance improvement in tidbitmap.c (which was not
exploiting the opportunity to use hash_uint32 for its 4-byte keys).
There might be some wins elsewhere too, I didn't analyze closely.

In future we could look into offering a similar optimized hashing function
for 8-byte keys.  Under this design that could be done in a centralized
and machine-independent fashion, whereas getting it right for keys of
platform-dependent sizes would've been notationally painful before.

For the moment, the old way still works fine, so as not to break source
code compatibility for loadable modules.  Eventually we might want to
remove tag_hash and friends from the exported API altogether, since there's
no real need for them to be explicitly referenced from outside dynahash.c.

Teodor Sigaev and Tom Lane

9 years agoChange how first WAL segment on new timeline after promotion is created.
Heikki Linnakangas [Thu, 18 Dec 2014 17:38:53 +0000 (19:38 +0200)]
Change how first WAL segment on new timeline after promotion is created.

Two changes:

1. When copying a WAL segment from old timeline to create the first segment
on the new timeline, only copy up to the point where the timeline switch
happens, and zero-fill the rest. This avoids corner cases where we might
think that the copied WAL from the previous timeline belong to the new
timeline.

2. If the timeline switch happens at a segment boundary, don't copy the
whole old segment to the new timeline. It's pointless, because it's 100%
identical to the old segment.

9 years agoAdd memory barriers for PgBackendStatus.st_changecount protocol.
Fujii Masao [Thu, 18 Dec 2014 14:07:51 +0000 (23:07 +0900)]
Add memory barriers for PgBackendStatus.st_changecount protocol.

st_changecount protocol needs the memory barriers to ensure that
the apparent order of execution is as it desires. Otherwise,
for example, the CPU might rearrange the code so that st_changecount
is incremented twice before the modification on a machine with
weak memory ordering. This surprising result can lead to bugs.

This commit introduces the macros to load and store st_changecount
with the memory barriers. These are called before and after
PgBackendStatus entries are modified or copied into private memory,
in order to prevent CPU from reordering PgBackendStatus access.

Per discussion on pgsql-hackers, we decided not to back-patch this
to 9.4 or before until we get an actual bug report about this.

Patch by me. Review by Robert Haas.

9 years agoEnsure variables live across calls in generate_series(numeric, numeric).
Fujii Masao [Thu, 18 Dec 2014 12:13:52 +0000 (21:13 +0900)]
Ensure variables live across calls in generate_series(numeric, numeric).

In generate_series_step_numeric(), the variables "start_num"
and "stop_num" may be potentially freed until the next call.
So they should be put in the location which can survive across calls.
But previously they were not, and which could cause incorrect
behavior of generate_series(numeric, numeric). This commit fixes
this problem by copying them on multi_call_memory_ctx.

Andrew Gierth

9 years agoUpdate .gitignore for config.cache.
Fujii Masao [Thu, 18 Dec 2014 10:56:42 +0000 (19:56 +0900)]
Update .gitignore for config.cache.

Also add a comment about why regreesion.* aren't listed in .gitignore.

Jim Nasby

9 years agoAdjust valgrind suppression to the changes in 2c03216d8311.
Andres Freund [Thu, 18 Dec 2014 09:31:59 +0000 (10:31 +0100)]
Adjust valgrind suppression to the changes in 2c03216d8311.

CRC computation is now done in XLogRecordAssemble.

9 years agoRecognize Makefile line continuations in fetchRegressOpts().
Noah Misch [Thu, 18 Dec 2014 08:55:17 +0000 (03:55 -0500)]
Recognize Makefile line continuations in fetchRegressOpts().

Back-patch to 9.0 (all supported versions).  This is mere
future-proofing in the context of the master branch, but commit
f6dc6dd5ba54d52c0733aaafc50da2fbaeabb8b0 requires it of older branches.

9 years agoRemove odd blank line in comment.
Fujii Masao [Thu, 18 Dec 2014 08:33:38 +0000 (17:33 +0900)]
Remove odd blank line in comment.

Etsuro Fujita

9 years agoFix (re-)starting from a basebackup taken off a standby after a failure.
Andres Freund [Thu, 18 Dec 2014 07:35:27 +0000 (08:35 +0100)]
Fix (re-)starting from a basebackup taken off a standby after a failure.

When starting up from a basebackup taken off a standby extra logic has
to be applied to compute the point where the data directory is
consistent. Normal base backups use a WAL record for that purpose, but
that isn't possible on a standby.

That logic had a error check ensuring that the cluster's control file
indicates being in recovery. Unfortunately that check was too strict,
disregarding the fact that the control file could also indicate that
the cluster was shut down while in recovery.

That's possible when the a cluster starting from a basebackup is shut
down before the backup label has been removed. When everything goes
well that's a short window, but when either restore_command or
primary_conninfo isn't configured correctly the window can get much
wider. That's because inbetween reading and unlinking the label we
restore the last checkpoint from WAL which can need additional WAL.

To fix simply also allow starting when the control file indicates
"shutdown in recovery". There's nicer fixes imaginable, but they'd be
more invasive.

Backpatch to 9.2 where support for taking basebackups from standbys
was added.

9 years agoFix previous commit for TAP test suites in VPATH builds.
Noah Misch [Thu, 18 Dec 2014 06:24:57 +0000 (01:24 -0500)]
Fix previous commit for TAP test suites in VPATH builds.

Per buildfarm member crake.  Back-patch to 9.4, where the TAP suites
were introduced.

9 years agoLock down regression testing temporary clusters on Windows.
Noah Misch [Thu, 18 Dec 2014 03:48:40 +0000 (22:48 -0500)]
Lock down regression testing temporary clusters on Windows.

Use SSPI authentication to allow connections exclusively from the OS
user that launched the test suite.  This closes on Windows the
vulnerability that commit be76a6d39e2832d4b88c0e1cc381aa44a7f86881
closed on other platforms.  Users of "make installcheck" or custom test
harnesses can run "pg_regress --config-auth=DATADIR" to activate the
same authentication configuration that "make check" would use.
Back-patch to 9.0 (all supported versions).

Security: CVE-2014-0067

9 years agoAllow CHECK constraints to be placed on foreign tables.
Tom Lane [Wed, 17 Dec 2014 22:00:53 +0000 (17:00 -0500)]
Allow CHECK constraints to be placed on foreign tables.

As with NOT NULL constraints, we consider that such constraints are merely
reports of constraints that are being enforced by the remote server (or
other underlying storage mechanism).  Their only real use is to allow
planner optimizations, for example in constraint-exclusion checks.  Thus,
the code changes here amount to little more than removal of the error that
was formerly thrown for applying CHECK to a foreign table.

(In passing, do a bit of cleanup of the ALTER FOREIGN TABLE reference page,
which had accumulated some weird decisions about ordering etc.)

Shigeru Hanada and Etsuro Fujita, reviewed by Kyotaro Horiguchi and
Ashutosh Bapat.

9 years agoClarify the regexp used to detect source files in MSVC builds.
Heikki Linnakangas [Wed, 17 Dec 2014 19:55:26 +0000 (21:55 +0200)]
Clarify the regexp used to detect source files in MSVC builds.

The old pattern would match files with strange extensions like *.ry or
*.lpp. Refactor it to only include files with known extensions, and to make
it more readable.

Per Andrew Dunstan's suggestion.

9 years agoFix another poorly worded error message.
Tom Lane [Wed, 17 Dec 2014 18:22:07 +0000 (13:22 -0500)]
Fix another poorly worded error message.

Spotted by Álvaro Herrera.

9 years agoFix poorly worded error message.
Tom Lane [Wed, 17 Dec 2014 18:14:53 +0000 (13:14 -0500)]
Fix poorly worded error message.

Adam Brightwell, per report from Martín Marqués.

9 years agoUpdate .gitignore for pg_upgrade
Magnus Hagander [Wed, 17 Dec 2014 10:55:22 +0000 (11:55 +0100)]
Update .gitignore for pg_upgrade

Add Windows versions of generated scripts, and make sure we only
ignore the scripts int he root directory.

Michael Paquier

9 years agoAdd missing documentation for some vcregress modes
Magnus Hagander [Wed, 17 Dec 2014 10:14:34 +0000 (11:14 +0100)]
Add missing documentation for some vcregress modes

Michael Paquier

9 years agoRemove redundant sentence
Magnus Hagander [Wed, 17 Dec 2014 08:59:21 +0000 (09:59 +0100)]
Remove redundant sentence

Spotted by David Johnston

9 years agoFix off-by-one loop count in MapArrayTypeName, and get rid of static array.
Tom Lane [Tue, 16 Dec 2014 20:35:33 +0000 (15:35 -0500)]
Fix off-by-one loop count in MapArrayTypeName, and get rid of static array.

MapArrayTypeName would copy up to NAMEDATALEN-1 bytes of the base type
name, which of course is wrong: after prepending '_' there is only room for
NAMEDATALEN-2 bytes.  Aside from being the wrong result, this case would
lead to overrunning the statically allocated work buffer.  This would be a
security bug if the function were ever used outside bootstrap mode, but it
isn't, at least not in any currently supported branches.

Aside from fixing the off-by-one loop logic, this patch gets rid of the
static work buffer by having MapArrayTypeName pstrdup its result; the sole
caller was already doing that, so this just requires moving the pstrdup
call.  This saves a few bytes but mainly it makes the API a lot cleaner.

Back-patch on the off chance that there is some third-party code using
MapArrayTypeName with less-secure input.  Pushing pstrdup into the function
should not cause any serious problems for such hypothetical code; at worst
there might be a short term memory leak.

Per Coverity scanning.

9 years agoSuppress bogus statistics when pgbench failed to complete any transactions.
Tom Lane [Tue, 16 Dec 2014 19:53:55 +0000 (14:53 -0500)]
Suppress bogus statistics when pgbench failed to complete any transactions.

Code added in 9.4 would attempt to divide by zero in such cases.
Noted while testing fix for missing-pclose problem.

9 years agoFix file descriptor leak after failure of a \setshell command in pgbench.
Tom Lane [Tue, 16 Dec 2014 18:31:42 +0000 (13:31 -0500)]
Fix file descriptor leak after failure of a \setshell command in pgbench.

If the called command fails to return data, runShellCommand forgot to
pclose() the pipe before returning.  This is fairly harmless in the current
code, because pgbench would then abandon further processing of that client
thread; so no more than nclients descriptors could be leaked this way.  But
it's not hard to imagine future improvements whereby that wouldn't be true.
In any case, it's sloppy coding, so patch all branches.  Found by Coverity.

9 years agoFix some jsonb issues found by Coverity in recent commits.
Andrew Dunstan [Tue, 16 Dec 2014 15:32:06 +0000 (10:32 -0500)]
Fix some jsonb issues found by Coverity in recent commits.

Mostly these issues concern the non-use of function results. These
have been changed to use (void) pushJsonbValue(...) instead of assigning
the result to a variable that gets overwritten before it is used.

There is a larger issue that we should possibly examine the API for
pushJsonbValue(), so that instead of returning a value it modifies a
state argument. The current idiom is rather clumsy. However, changing
that requires quite a bit more work, so this change should do for the
moment.

9 years agoMisc comment typo fixes.
Heikki Linnakangas [Tue, 16 Dec 2014 14:34:56 +0000 (16:34 +0200)]
Misc comment typo fixes.

Backpatch the applicable parts, just to make backpatching future patches
easier.

9 years agoFix incorrect comment about XLogRecordBlockHeader.data_length field.
Heikki Linnakangas [Tue, 16 Dec 2014 13:39:57 +0000 (15:39 +0200)]
Fix incorrect comment about XLogRecordBlockHeader.data_length field.

It does not include the possible full-page image. While at it, reformat the
comment slightly to make it more readable.

Reported by Rahila Syed

9 years agoFix commit_ts test suite for systems with coarse timestamp granularity.
Noah Misch [Tue, 16 Dec 2014 01:56:09 +0000 (20:56 -0500)]
Fix commit_ts test suite for systems with coarse timestamp granularity.

Noticed on a couple of Windows configurations.

Petr Jelinek, reviewed by Michael Paquier.

9 years agoTranslation updates
Peter Eisentraut [Mon, 15 Dec 2014 21:18:13 +0000 (16:18 -0500)]
Translation updates

9 years agoadd missing newline
Alvaro Herrera [Mon, 15 Dec 2014 19:49:41 +0000 (16:49 -0300)]
add missing newline

9 years agoFix point <-> polygon code for zero-distance case.
Tom Lane [Mon, 15 Dec 2014 19:04:27 +0000 (14:04 -0500)]
Fix point <-> polygon code for zero-distance case.

"PG_RETURN_FLOAT8(x)" is not "return x", except perhaps by accident
on some platforms.

9 years agoAdd point <-> polygon distance operator.
Heikki Linnakangas [Mon, 15 Dec 2014 15:02:49 +0000 (17:02 +0200)]
Add point <-> polygon distance operator.

Alexander Korotkov, reviewed by Emre Hasegeli.

9 years agoTranslation updates
Peter Eisentraut [Mon, 15 Dec 2014 05:23:25 +0000 (00:23 -0500)]
Translation updates

9 years agodoc: Add link to how to specify time zone names to initdb man page
Peter Eisentraut [Mon, 15 Dec 2014 01:02:04 +0000 (20:02 -0500)]
doc: Add link to how to specify time zone names to initdb man page

9 years agoImprove documentation around parameter-setting and ALTER SYSTEM.
Tom Lane [Sun, 14 Dec 2014 23:09:51 +0000 (18:09 -0500)]
Improve documentation around parameter-setting and ALTER SYSTEM.

The ALTER SYSTEM ref page hadn't been held to a very high standard, nor
was the feature well integrated into section 18.1 (parameter setting).
Also, though commit 4c4654afe had improved the structure of 18.1, it also
introduced a lot of poor wording, imprecision, and outright falsehoods.
Try to clean that up.

9 years agoUpdate 9.4 release notes.
Tom Lane [Sun, 14 Dec 2014 19:58:03 +0000 (14:58 -0500)]
Update 9.4 release notes.

Set release date, do a final pass of wordsmithing, improve some other
new-in-9.4 documentation.

9 years agodoc: Fix markup
Peter Eisentraut [Sat, 13 Dec 2014 19:16:16 +0000 (14:16 -0500)]
doc: Fix markup

9 years agoAdd CINE option for CREATE TABLE AS and CREATE MATERIALIZED VIEW
Andrew Dunstan [Sat, 13 Dec 2014 18:56:09 +0000 (13:56 -0500)]
Add CINE option for CREATE TABLE AS and CREATE MATERIALIZED VIEW

Fabrízio de Royes Mello reviewed by Rushabh Lathia.

9 years agoImprove recovery target settings documentation.
Tom Lane [Sat, 13 Dec 2014 18:46:44 +0000 (13:46 -0500)]
Improve recovery target settings documentation.

Commit 815d71dee hadn't bothered to update the documentation to match the
behavioral change, and a lot of other text in this section was badly in
need of copy-editing.

9 years agoRepair corner-case bug in array version of percentile_cont().
Tom Lane [Sat, 13 Dec 2014 16:49:16 +0000 (11:49 -0500)]
Repair corner-case bug in array version of percentile_cont().

The code for advancing through the input rows overlooked the case that we
might already be past the first row of the row pair now being considered,
in case the previous percentile also fell between the same two input rows.

Report and patch by Andrew Gierth; logic rewritten a bit for clarity by me.

9 years agoRemove duplicate #define
Heikki Linnakangas [Sat, 13 Dec 2014 16:21:25 +0000 (18:21 +0200)]
Remove duplicate #define

Mark Dilger

9 years agoAvoid instability in output of new REINDEX SCHEMA test.
Tom Lane [Fri, 12 Dec 2014 20:49:03 +0000 (15:49 -0500)]
Avoid instability in output of new REINDEX SCHEMA test.

The planner seems to like to do this join query as a hash join, making
the output ordering machine-dependent; worse, it's a hash on OIDs, so
that it's a bit astonishing that the result doesn't change from run to
run even on one machine.  Add an ORDER BY to get consistent results.
Per buildfarm.

I also suppressed output from the final DROP SCHEMA CASCADE, to avoid
occasional failures similar to those fixed in commit 81d815dc3ed74a7d.
That hasn't been observed in the buildfarm yet, but it seems likely
to happen in future if we leave it as-is.

9 years agoAdd several generator functions for jsonb that exist for json.
Andrew Dunstan [Fri, 12 Dec 2014 20:31:14 +0000 (15:31 -0500)]
Add several generator functions for jsonb that exist for json.

The functions are:
    to_jsonb()
    jsonb_object()
    jsonb_build_object()
    jsonb_build_array()
    jsonb_agg()
    jsonb_object_agg()

Also along the way some better logic is implemented in
json_categorize_type() to match that in the newly implemented
jsonb_categorize_type().

Andrew Dunstan, reviewed by Pavel Stehule and Alvaro Herrera.