]> granicus.if.org Git - postgresql/log
postgresql
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.

9 years agoRevert misguided change to postgres_fdw FOR UPDATE/SHARE code.
Tom Lane [Fri, 12 Dec 2014 17:41:49 +0000 (12:41 -0500)]
Revert misguided change to postgres_fdw FOR UPDATE/SHARE code.

In commit 462bd95705a0c23ba0b0ba60a78d32566a0384c1, I changed postgres_fdw
to rely on get_plan_rowmark() instead of get_parse_rowmark().  I still
think that's a good idea in the long run, but as Etsuro Fujita pointed out,
it doesn't work today because planner.c forces PlanRowMarks to have
markType = ROW_MARK_COPY for all foreign tables.  There's no urgent reason
to change this in the back branches, so let's just revert that part of
yesterday's commit rather than trying to design a better solution under
time pressure.

Also, add a regression test case showing what postgres_fdw does with FOR
UPDATE/SHARE.  I'd blithely assumed there was one already, else I'd have
realized yesterday that this code didn't work.

9 years agoAdd json_strip_nulls and jsonb_strip_nulls functions.
Andrew Dunstan [Fri, 12 Dec 2014 14:00:43 +0000 (09:00 -0500)]
Add json_strip_nulls and jsonb_strip_nulls functions.

The functions remove object fields, including in nested objects, that
have null as a value. In certain cases this can lead to considerably
smaller datums, with no loss of semantic information.

Andrew Dunstan, reviewed by Pavel Stehule.

9 years agoPut the logic to decide which synchronous standby is active into a function.
Heikki Linnakangas [Fri, 12 Dec 2014 11:39:36 +0000 (13:39 +0200)]
Put the logic to decide which synchronous standby is active into a function.

This avoids duplicating the code.

Michael Paquier, reviewed by Simon Riggs and me

9 years agodoc: Move website-stylesheet setting to a more appropriate location
Peter Eisentraut [Fri, 12 Dec 2014 02:48:01 +0000 (21:48 -0500)]
doc: Move website-stylesheet setting to a more appropriate location

9 years agoSSL tests: Remove trailing blank lines
Peter Eisentraut [Fri, 12 Dec 2014 02:33:58 +0000 (21:33 -0500)]
SSL tests: Remove trailing blank lines

9 years agoSSL tests: Silence pg_ctl output
Peter Eisentraut [Fri, 12 Dec 2014 02:32:30 +0000 (21:32 -0500)]
SSL tests: Silence pg_ctl output

Otherwise the pg_ctl start and stop messages get mixed up with the TAP
output, which isn't technically valid.

9 years agoFix planning of SELECT FOR UPDATE on child table with partial index.
Tom Lane [Fri, 12 Dec 2014 02:02:25 +0000 (21:02 -0500)]
Fix planning of SELECT FOR UPDATE on child table with partial index.

Ordinarily we can omit checking of a WHERE condition that matches a partial
index's condition, when we are using an indexscan on that partial index.
However, in SELECT FOR UPDATE we must include the "redundant" filter
condition in the plan so that it gets checked properly in an EvalPlanQual
recheck.  The planner got this mostly right, but improperly omitted the
filter condition if the index in question was on an inheritance child
table.  In READ COMMITTED mode, this could result in incorrectly returning
just-updated rows that no longer satisfy the filter condition.

The cause of the error is using get_parse_rowmark() when get_plan_rowmark()
is what should be used during planning.  In 9.3 and up, also fix the same
mistake in contrib/postgres_fdw.  It's currently harmless there (for lack
of inheritance support) but wrong is wrong, and the incorrect code might
get copied to someplace where it's more significant.

Report and fix by Kyotaro Horiguchi.  Back-patch to all supported branches.

9 years agoFix corner case where SELECT FOR UPDATE could return a row twice.
Tom Lane [Fri, 12 Dec 2014 00:37:00 +0000 (19:37 -0500)]
Fix corner case where SELECT FOR UPDATE could return a row twice.

In READ COMMITTED mode, if a SELECT FOR UPDATE discovers it has to redo
WHERE-clause checking on rows that have been updated since the SELECT's
snapshot, it invokes EvalPlanQual processing to do that.  If this first
occurs within a non-first child table of an inheritance tree, the previous
coding could accidentally re-return a matching row from an earlier,
already-scanned child table.  (And, to add insult to injury, I think this
could make it miss returning a row that should have been returned, if the
updated row that this happens on should still have passed the WHERE qual.)
Per report from Kyotaro Horiguchi; the added isolation test is based on his
test case.

This has been broken for quite awhile, so back-patch to all supported
branches.

9 years agoFurther changes to REINDEX SCHEMA
Simon Riggs [Thu, 11 Dec 2014 22:54:05 +0000 (22:54 +0000)]
Further changes to REINDEX SCHEMA

Ensure we reindex indexes built on Mat Views.
Based on patch from Micheal Paquier

Add thorough tests to check that indexes on
tables, toast tables and mat views are reindexed.

Simon Riggs

9 years agoMake rowsecurity test clean up after itself, too.
Tom Lane [Thu, 11 Dec 2014 22:45:35 +0000 (17:45 -0500)]
Make rowsecurity test clean up after itself, too.

Leaving global objects like roles hanging around is bad practice.

9 years agoFix completely broken REINDEX SCHEMA testcase.
Tom Lane [Thu, 11 Dec 2014 22:37:17 +0000 (17:37 -0500)]
Fix completely broken REINDEX SCHEMA testcase.

Aside from not testing the case it claimed to test (namely a permissions
failure), it left a login-capable role lying around, which quite aside
from possibly being a security hole would cause subsequent regression runs
to fail since the role would already exist.

9 years agoFix assorted confusion between Oid and int32.
Tom Lane [Thu, 11 Dec 2014 20:41:15 +0000 (15:41 -0500)]
Fix assorted confusion between Oid and int32.

In passing, also make some debugging elog's in pgstat.c a bit more
consistently worded.

Back-patch as far as applicable (9.3 or 9.4; none of these mistakes are
really old).

Mark Dilger identified and patched the type violations; the message
rewordings are mine.

9 years agoUse correct macro for reltablespace.
Heikki Linnakangas [Thu, 11 Dec 2014 08:19:50 +0000 (10:19 +0200)]
Use correct macro for reltablespace.

It's an OID. WRITE_UINT_FIELD is identical to WRITE_OID_FIELD, but let's
be tidy.

Mark Dilger

9 years agoFix typo
Peter Eisentraut [Thu, 11 Dec 2014 01:55:30 +0000 (20:55 -0500)]
Fix typo

Author: Fabrízio de Royes Mello <fabriziomello@gmail.com>

9 years agoFix minor thinko in convertToJsonb().
Tom Lane [Thu, 11 Dec 2014 00:06:27 +0000 (19:06 -0500)]
Fix minor thinko in convertToJsonb().

The amount of space to reserve for the value's varlena header is
VARHDRSZ, not sizeof(VARHDRSZ).  The latter coding accidentally
failed to fail because of the way the VARHDRSZ macro is currently
defined; but if we ever change it to return size_t (as one might
reasonably expect it to do), convertToJsonb() would have failed.

Spotted by Mark Dilger.

9 years agoAdd a regression test suite for SSL support.
Heikki Linnakangas [Tue, 9 Dec 2014 15:21:18 +0000 (17:21 +0200)]
Add a regression test suite for SSL support.

It's not run by the global "check" or "installcheck" targets, because the
temporary installation it creates accepts TCP connections from any user
the same host, which is insecure.

9 years agopg_xlogdump/.gitignore: add committsdesc.c
Alvaro Herrera [Tue, 9 Dec 2014 12:54:14 +0000 (09:54 -0300)]
pg_xlogdump/.gitignore: add committsdesc.c

Author: Michael Paquier

9 years agoSilence REINDEX
Simon Riggs [Tue, 9 Dec 2014 09:05:36 +0000 (18:05 +0900)]
Silence REINDEX

Previously REINDEX DATABASE and REINDEX SCHEMA
produced a stream of NOTICE messages. Removing that
since it is inconsistent for such a command to
produce output without a VERBOSE option.

9 years agoExecute 18 tests for src/bin/scripts/t/090..
Simon Riggs [Mon, 8 Dec 2014 16:51:02 +0000 (01:51 +0900)]
Execute 18 tests for src/bin/scripts/t/090..

Some requests count as two tests.

9 years agoREINDEX SCHEMA
Simon Riggs [Mon, 8 Dec 2014 15:28:00 +0000 (00:28 +0900)]
REINDEX SCHEMA

Add new SCHEMA option to REINDEX and reindexdb.

Sawada Masahiko

Reviewed by Michael Paquier and Fabrízio de Royes Mello

9 years agoWindows: use GetSystemTimePreciseAsFileTime if available
Simon Riggs [Mon, 8 Dec 2014 14:36:06 +0000 (23:36 +0900)]
Windows: use GetSystemTimePreciseAsFileTime if available

PostgreSQL on Windows 8 or Windows Server 2012 will now
get high-resolution timestamps by dynamically loading the
GetSystemTimePreciseAsFileTime function. It'll fall back to
to GetSystemTimeAsFileTime if the higher precision variant
isn't found, so the same binaries without problems on older
Windows releases.

No attempt is made to detect the Windows version.  Only the
presence or absence of the desired function is considered.

Craig Ringer

9 years agoUse GetSystemTimeAsFileTime directly in win32
Simon Riggs [Mon, 8 Dec 2014 14:32:03 +0000 (23:32 +0900)]
Use GetSystemTimeAsFileTime directly in win32

PostgreSQL was calling GetSystemTime followed by SystemTimeToFileTime in the
win32 port gettimeofday function. This is not necessary and limits the reported
precision to the 1ms granularity that the SYSTEMTIME struct can represent. By
using GetSystemTimeAsFileTime we avoid unnecessary conversions and capture
timestamps at 100ns granularity, which is then rounded to 1µs granularity for
storage in a PostgreSQL timestamp.

On most Windows systems this change will actually have no significant effect on
timestamp resolution as the system timer tick is typically between 1ms and 15ms
depending on what timer resolution currently running applications have
requested. You can check this with clockres.exe from sysinternals. Despite the
platform limiation this change still permits capture of finer timestamps where
the system is capable of producing them and it gets rid of an unnecessary
syscall.

The higher resolution GetSystemTimePreciseAsFileTime call available on Windows
8 and Windows Server 2012 has the same interface as GetSystemTimeAsFileTime, so
switching to GetSystemTimeAsFileTime makes it easier to use the Precise variant
later.

Craig Ringer, reviewed by David Rowley

9 years agodoc: Fix DocBook table column count declaration
Peter Eisentraut [Mon, 8 Dec 2014 07:18:29 +0000 (02:18 -0500)]
doc: Fix DocBook table column count declaration

This was broken in 618c9430a82860c84a3be2711eec2c3b43573b2a.

9 years agoCorrect recovery_target_action docs
Simon Riggs [Mon, 8 Dec 2014 00:28:24 +0000 (09:28 +0900)]
Correct recovery_target_action docs

From Michael Paquier

9 years agoRemove duplicate code in heap_prune_chain()
Simon Riggs [Sun, 7 Dec 2014 23:44:37 +0000 (08:44 +0900)]
Remove duplicate code in heap_prune_chain()

No need to set tuple tableOid twice

Jim Nasby

9 years agoEvent Trigger for table_rewrite
Simon Riggs [Sun, 7 Dec 2014 15:55:28 +0000 (00:55 +0900)]
Event Trigger for table_rewrite

Generate a table_rewrite event when ALTER TABLE
attempts to rewrite a table. Provide helper
functions to identify table and reason.

Intended use case is to help assess or to react
to schema changes that might hold exclusive locks
for long periods.

Dimitri Fontaine, triggering an edit by Simon Riggs

Reviewed in detail by Michael Paquier

9 years agoTweaks for recovery_target_action
Simon Riggs [Sun, 7 Dec 2014 12:55:29 +0000 (21:55 +0900)]
Tweaks for recovery_target_action

Rename parameter action_at_recovery_target to
recovery_target_action suggested by Christoph Berg.

Place into recovery.conf suggested by Fujii Masao,
replacing (deprecating) earlier parameters, per
Michael Paquier.

9 years agoGive a proper error message if initdb password file is empty.
Heikki Linnakangas [Fri, 5 Dec 2014 12:27:56 +0000 (14:27 +0200)]
Give a proper error message if initdb password file is empty.

Used to say just "could not read password from file "...": Success", which
isn't very informative.

Mats Erik Andersson. Backpatch to all supported versions.

9 years agoDon't include file type bits in tar archive's mode field.
Heikki Linnakangas [Fri, 5 Dec 2014 11:08:22 +0000 (13:08 +0200)]
Don't include file type bits in tar archive's mode field.

The "file mode" bits in the tar file header is not supposed to include the
file type bits, e.g. S_IFREG or S_IFDIR. The file type is stored in a
separate field. This isn't a problem in practice, all tar programs ignore
the extra bits, but let's be tidy.

This came up in a discussion around bug #11949, reported by Hendrik Grewe,
although this doesn't fix the issue with tar --append. That turned out to be
a bug in GNU tar. Schilly's tartest program revealed this defect in the tar
created by pg_basebackup.

This problem goes as far as we we've had pg_basebackup, but since this
hasn't caused any problems in practice, let's be conservative and fix in
master only.

9 years agoRemove erroneous EXTRA_CLEAN line from Makefile.
Heikki Linnakangas [Fri, 5 Dec 2014 10:13:19 +0000 (12:13 +0200)]
Remove erroneous EXTRA_CLEAN line from Makefile.

After commit da34731, these files are not generated files anymore.

Adam Brightwell

9 years agoPrint new track_commit_timestamp in rm_desc of a parameter-change record.
Heikki Linnakangas [Fri, 5 Dec 2014 10:11:07 +0000 (12:11 +0200)]
Print new track_commit_timestamp in rm_desc of a parameter-change record.

Michael Paquier

9 years agoPrint wal_log_hints in the rm_desc routing of a parameter-change record.
Heikki Linnakangas [Fri, 5 Dec 2014 09:58:24 +0000 (11:58 +0200)]
Print wal_log_hints in the rm_desc routing of a parameter-change record.

It was an oversight in the original commit.

Also note in the sample config file that changing wal_log_hints requires a
restart.

Michael Paquier. Backpatch to 9.4, where wal_log_hints was added.

9 years agoFix pg_xlogdump's calculation of full-page image data.
Heikki Linnakangas [Fri, 5 Dec 2014 09:39:40 +0000 (11:39 +0200)]
Fix pg_xlogdump's calculation of full-page image data.

The old formula was completely bogus with the new WAL record format.

9 years agoDon't dump core if pq_comm_reset() is called before pq_init().
Robert Haas [Fri, 5 Dec 2014 00:47:06 +0000 (19:47 -0500)]
Don't dump core if pq_comm_reset() is called before pq_init().

This can happen if an error occurs in a standalone backend.  This bug
was introduced by commit 2bd9e412f92bc6a68f3e8bcb18e04955cc35001d.

Reported by Álvaro Herrera.

9 years agoDocument that pg_stat_*_tables.n_tup_upd includes n_tup_hot_upd.
Andres Freund [Thu, 4 Dec 2014 22:55:19 +0000 (23:55 +0100)]
Document that pg_stat_*_tables.n_tup_upd includes n_tup_hot_upd.

Author: Peter Geoghegan

9 years agoFix PGXS vpath build when PostgreSQL is built with vpath
Peter Eisentraut [Thu, 4 Dec 2014 22:02:02 +0000 (17:02 -0500)]
Fix PGXS vpath build when PostgreSQL is built with vpath

PGXS computes srcdir from VPATH, PostgreSQL proper computes VPATH from
srcdir, and doing both results in an error from make.  Conditionalize so
only one of these takes effect.

9 years agoRevert haphazard pgxs makefile changes
Peter Eisentraut [Thu, 20 Nov 2014 03:26:32 +0000 (22:26 -0500)]
Revert haphazard pgxs makefile changes

These changes were originally submitted as "adds support for VPATH with
USE_PGXS", but they are not necessary for VPATH support, so they just
add more lines of code for no reason.

9 years agoRemove USE_VPATH make variable from PGXS
Peter Eisentraut [Thu, 20 Nov 2014 02:51:30 +0000 (21:51 -0500)]
Remove USE_VPATH make variable from PGXS

The user can just set VPATH directly.  There is no need to invent
another variable.

9 years agoFix SHLIB_PREREQS use in contrib, allowing PGXS builds
Peter Eisentraut [Thu, 4 Dec 2014 12:58:12 +0000 (07:58 -0500)]
Fix SHLIB_PREREQS use in contrib, allowing PGXS builds

dblink and postgres_fdw use SHLIB_PREREQS = submake-libpq to build libpq
first.  This doesn't work in a PGXS build, because there is no libpq to
build.  So just omit setting SHLIB_PREREQS in this case.

Note that PGXS users can still use SHLIB_PREREQS (although it is not
documented).  The problem here is only that contrib modules can be built
in-tree or using PGXS, and the prerequisite is only applicable in the
former case.

Commit 6697aa2bc25c83b88d6165340348a31328c35de6 previously attempted to
address this by creating a somewhat fake submake-libpq target in
Makefile.global.  That was not the right fix, and it was also done in a
nonportable way, so revert that.

9 years agoMove PG_AUTOCONF_FILENAME definition
Peter Eisentraut [Thu, 4 Dec 2014 00:54:01 +0000 (19:54 -0500)]
Move PG_AUTOCONF_FILENAME definition

Since this is not something that a user should change,
pg_config_manual.h was an inappropriate place for it.

In initdb.c, remove the use of the macro, because utils/guc.h can't be
included by non-backend code.  But we hardcode all the other
configuration file names there, so this isn't a disaster.

9 years agodoc: Fix markup
Alvaro Herrera [Wed, 3 Dec 2014 19:23:38 +0000 (16:23 -0300)]
doc: Fix markup

In the spirit of d34b48a021b181e30c53280d336820740f67570b

Per buildfarm member guaibasaurus, via Stefan Kaltenbrunner.

9 years agoKeep track of transaction commit timestamps
Alvaro Herrera [Wed, 3 Dec 2014 14:53:02 +0000 (11:53 -0300)]
Keep track of transaction commit timestamps

Transactions can now set their commit timestamp directly as they commit,
or an external transaction commit timestamp can be fed from an outside
system using the new function TransactionTreeSetCommitTsData().  This
data is crash-safe, and truncated at Xid freeze point, same as pg_clog.

This module is disabled by default because it causes a performance hit,
but can be enabled in postgresql.conf requiring only a server restart.

A new test in src/test/modules is included.

Catalog version bumped due to the new subdirectory within PGDATA and a
couple of new SQL functions.

Authors: Álvaro Herrera and Petr Jelínek

Reviewed to varying degrees by Michael Paquier, Andres Freund, Robert
Haas, Amit Kapila, Fujii Masao, Jaime Casanova, Simon Riggs, Steven
Singer, Peter Eisentraut

9 years agoFix typos
Alvaro Herrera [Wed, 3 Dec 2014 14:52:15 +0000 (11:52 -0300)]
Fix typos

9 years agoFix whitespace
Peter Eisentraut [Wed, 3 Dec 2014 04:45:03 +0000 (23:45 -0500)]
Fix whitespace