]> granicus.if.org Git - postgresql/log
postgresql
9 years agoSilence Coverity warnings about unused return values from pushJsonbValue()
Heikki Linnakangas [Tue, 13 Jan 2015 12:29:36 +0000 (14:29 +0200)]
Silence Coverity warnings about unused return values from pushJsonbValue()

Similar warnings from backend were silenced earlier by commit c8315930,
but there were a few more contrib/hstore.

Michael Paquier

9 years agoAdd barriers to the latch code.
Andres Freund [Tue, 13 Jan 2015 11:58:43 +0000 (12:58 +0100)]
Add barriers to the latch code.

Since their introduction latches have required barriers in SetLatch
and ResetLatch - but when they were introduced there wasn't any
barrier abstraction. Instead latches were documented to rely on the
callsites to provide barrier semantics.

Now that the barrier support looks halfway complete, add the necessary
barriers to both latch implementations.

Also remove a now superflous lock acquisition from syncrep.c and a
superflous (and insufficient) barrier from freelist.c. There might be
other cases that can now be simplified, but those are the only ones
I've seen on a quick scan.

We might want to backpatch this at some later point, but right now the
barrier infrastructure in the backbranches isn't totally on par with
master.

Discussion: 20150112154026.GB2092@awork2.anarazel.de

9 years agoAllow latches to wait for socket writability without waiting for readability.
Andres Freund [Tue, 13 Jan 2015 11:58:43 +0000 (12:58 +0100)]
Allow latches to wait for socket writability without waiting for readability.

So far WaitLatchOrSocket() required to pass in WL_SOCKET_READABLE as
that solely was used to indicate error conditions, like EOF. Waiting
for WL_SOCKET_WRITEABLE would have meant to busy wait upon socket
errors.

Adjust the API to signal errors by returning the socket as readable,
writable or both, depending on WL_SOCKET_READABLE/WL_SOCKET_WRITEABLE
being specified.  It would arguably be nicer to return WL_SOCKET_ERROR
but that's not possible on platforms and would probably also result in
more complex callsites.

This previously had explicitly been forbidden in e42a21b9e6c9, as
there was no strong use case at that point. We now are looking into
making FE/BE communication use latches, so changing this makes sense.

There also are some portability concerns because there cases of older
platforms where select(2) is known to, in violation of POSIX, not
return a socket as writable after the peer has closed it.  So far the
platforms where that's the case provide a working poll(2). If we find
one where that's not the case, we'll need to add a workaround for that
platform.

Discussion: 20140927191243.GD5423@alap3.anarazel.de
Reviewed-By: Heikki Linnakangas, Noah Misch
9 years agoFix typos in comment.
Heikki Linnakangas [Tue, 13 Jan 2015 08:29:16 +0000 (10:29 +0200)]
Fix typos in comment.

Plus some tiny wordsmithing of not-quite-typos.

9 years agoFix some functions that were declared static then defined not-static.
Tom Lane [Mon, 12 Jan 2015 21:08:43 +0000 (16:08 -0500)]
Fix some functions that were declared static then defined not-static.

Per testing with a compiler that whines about this.

9 years agoAvoid unexpected slowdown in vacuum regression test.
Tom Lane [Mon, 12 Jan 2015 20:13:28 +0000 (15:13 -0500)]
Avoid unexpected slowdown in vacuum regression test.

I noticed the "vacuum" regression test taking really significantly longer
than it used to on a slow machine.  Investigation pointed the finger at
commit e415b469b33ba328765e39fd62edcd28f30d9c3c, which added creation of
an index using an extremely expensive index function.  That function was
evidently meant to be applied only twice ... but the test re-used an
existing test table, which up till a couple lines before that had had over
two thousand rows.  Depending on timing of the concurrent regression tests,
the intervening VACUUMs might have been unable to remove those
recently-dead rows, and then the index build would need to create index
entries for them too, leading to the wrap_do_analyze() function being
executed 2000+ times not twice.  Avoid this by using a different table
that is guaranteed to have only the intended two rows in it.

Back-patch to 9.0, like the commit that created the problem.

9 years agoTweak heapam's rmgr desc output slightly
Alvaro Herrera [Mon, 12 Jan 2015 19:09:16 +0000 (16:09 -0300)]
Tweak heapam's rmgr desc output slightly

Some spaces were missing, and putting the affected tuple offset first in
the lock cases instead of the locking data makes more sense.

No backpatch since this is cosmetic and surrounding code has changed.

9 years agoFix get_object_address argument type for extension statement
Alvaro Herrera [Mon, 12 Jan 2015 18:32:48 +0000 (15:32 -0300)]
Fix get_object_address argument type for extension statement

Commit 3f88672a4 neglected to update the AlterExtensionContentsStmt
production in the grammar to use TypeName to represent types when
passing objects to get_object_address.

Reported as a pg_upgrade failure by Jeff Janes.

9 years agoUse correct text domain for errcontext() appearing within ereport().
Tom Lane [Mon, 12 Jan 2015 17:40:09 +0000 (12:40 -0500)]
Use correct text domain for errcontext() appearing within ereport().

The mechanism added in commit dbdf9679d7d61b03a3bf73af9b095831b7010eb5
for associating the correct translation domain with errcontext strings
potentially fails in cases where errcontext() is used within an ereport()
macro.  Such usage was not originally envisioned for errcontext(), but we
do have a few places that do it.  In this situation, the intended comma
expression becomes just a couple of arguments to errfinish(), which the
compiler might choose to evaluate right-to-left.

Fortunately, in such cases the textdomain for the errcontext string must
be the same as for the surrounding ereport.  So we can fix this by letting
errstart initialize context_domain along with domain; then it will have
the correct value no matter which order the calls occur in.  (Note that
error stack callback functions are not invoked until errfinish, so normal
usage of errcontext won't affect what happens for errcontext calls within
the ereport macro.)

In passing, make sure that errcontext calls within the main backend set
context_domain to something non-NULL.  This isn't a live bug because
NULL would select the current textdomain() setting which should be the
right thing anyway --- but it seems better to handle this completely
consistently with the regular domain field.

Per report from Dmitry Voronin.  Backpatch to 9.3; before that, there
wasn't any attempt to ensure that errcontext strings were translated
in an appropriate domain.

9 years agoSkip dead backends in MinimumActiveBackends
Stephen Frost [Mon, 12 Jan 2015 15:13:18 +0000 (10:13 -0500)]
Skip dead backends in MinimumActiveBackends

Back in ed0b409, PGPROC was split and moved to static variables in
procarray.c, with procs in ProcArrayStruct replaced by an array of
integers representing process numbers (pgprocnos), with -1 indicating a
dead process which has yet to be removed.  Access to procArray is
generally done under ProcArrayLock and therefore most code does not have
to concern itself with -1 entries.

However, MinimumActiveBackends intentionally does not take
ProcArrayLock, which means it has to be extra careful when accessing
procArray.  Prior to ed0b409, this was handled by checking for a NULL
in the pointer array, but that check was no longer valid after the
split.  Coverity pointed out that the check could never happen and so
it was removed in 5592eba.  That didn't make anything worse, but it
didn't fix the issue either.

The correct fix is to check for pgprocno == -1 and skip over that entry
if it is encountered.

Back-patch to 9.2, since there can be attempts to access the arrays
prior to their start otherwise.  Note that the changes prior to 9.4 will
look a bit different due to the change in 5592eba.

Note that MinimumActiveBackends only returns a bool for heuristic
purposes and any pre-array accesses are strictly read-only and so there
is no security implication and the lack of fields complaints indicates
it's very unlikely to run into issues due to this.

Pointed out by Noah.

9 years agoFix portability breakage in pg_dump.
Tom Lane [Sun, 11 Jan 2015 18:28:26 +0000 (13:28 -0500)]
Fix portability breakage in pg_dump.

Commit 0eea8047bf0e15b402b951e383e39236bdfe57d5 introduced some overly
optimistic assumptions about what could be in a local struct variable's
initializer.  (This might in fact be valid code according to C99, but I've
got at least one pre-C99 compiler that falls over on those nonconstant
address expressions.)  There is no reason whatsoever for main()'s workspace
to not be static, so revert long_options[] to a static and make the
DumpOptions struct static as well.

9 years agoRemove configure test for nonstandard variants of getpwuid_r().
Tom Lane [Sun, 11 Jan 2015 17:52:37 +0000 (12:52 -0500)]
Remove configure test for nonstandard variants of getpwuid_r().

We had code that supposed that some platforms might offer a nonstandard
version of getpwuid_r() with only four arguments.  However, the 5-argument
definition has been standardized at least since the Single Unix Spec v2,
which is our normal reference for what's portable across all Unix-oid
platforms.  (What's more, this wasn't the only pre-standardization version
of getpwuid_r(); my old HPUX 10.20 box has still another signature.)
So let's just get rid of the now-useless configure step.

9 years agoFix libpq's behavior when /etc/passwd isn't readable.
Tom Lane [Sun, 11 Jan 2015 17:35:44 +0000 (12:35 -0500)]
Fix libpq's behavior when /etc/passwd isn't readable.

Some users run their applications in chroot environments that lack an
/etc/passwd file.  This means that the current UID's user name and home
directory are not obtainable.  libpq used to be all right with that,
so long as the database role name to use was specified explicitly.
But commit a4c8f14364c27508233f8a31ac4b10a4c90235a9 broke such cases by
causing any failure of pg_fe_getauthname() to be treated as a hard error.
In any case it did little to advance its nominal goal of causing errors
in pg_fe_getauthname() to be reported better.  So revert that and instead
put some real error-reporting code in place.  This requires changes to the
APIs of pg_fe_getauthname() and pqGetpwuid(), since the latter had
departed from the POSIX-specified API of getpwuid_r() in a way that made
it impossible to distinguish actual lookup errors from "no such user".

To allow such failures to be reported, while not failing if the caller
supplies a role name, add a second call of pg_fe_getauthname() in
connectOptions2().  This is a tad ugly, and could perhaps be avoided with
some refactoring of PQsetdbLogin(), but I'll leave that idea for later.
(Note that the complained-of misbehavior only occurs in PQsetdbLogin,
not when using the PQconnect functions, because in the latter we will
never bother to call pg_fe_getauthname() if the user gives a role name.)

In passing also clean up the Windows-side usage of GetUserName(): the
recommended buffer size is 257 bytes, the passed buffer length should
be the buffer size not buffer size less 1, and any error is reported
by GetLastError() not errno.

Per report from Christoph Berg.  Back-patch to 9.4 where the chroot
failure case was introduced.  The generally poor reporting of errors
here is of very long standing, of course, but given the lack of field
complaints about it we won't risk changing these APIs further back
(even though they're theoretically internal to libpq).

9 years agoProvide a generic fallback for pg_compiler_barrier using an extern function.
Andres Freund [Sun, 11 Jan 2015 00:15:29 +0000 (01:15 +0100)]
Provide a generic fallback for pg_compiler_barrier using an extern function.

If the compiler/arch combination does not provide compiler barriers,
provide a fallback. That fallback simply consists out of a function
call into a externally defined function.  That should guarantee
compiler barrierer semantics except for compilers that do inter
translation unit/global optimization - those better provide an actual
compiler barrier.

Hopefully this fixes Tom's report of linker failures due to
pg_compiler_barrier_impl not being provided.

I'm not backpatching this commit as it builds on the new atomics
infrastructure. If we decide an equivalent fix needs to be
backpatched, I'll do so in a separate commit.

Discussion: 27746.1420930690@sss.pgh.pa.us

Per report from Tom Lane.

9 years agoFix alignment of pg_atomic_uint64 variables on some 32bit platforms.
Andres Freund [Sun, 11 Jan 2015 00:06:37 +0000 (01:06 +0100)]
Fix alignment of pg_atomic_uint64 variables on some 32bit platforms.

I failed to recognize that pg_atomic_uint64 wasn't guaranteed to be 8
byte aligned on some 32bit platforms - which it has to be on some
platforms to guarantee the desired atomicity and which we assert.

As this is all compiler specific code anyway we can just rely on
compiler specific tricks to enforce alignment.

I've been unable to find concrete documentation about the version that
introduce the sunpro alignment support, so that might need additional
guards.

I've verified that this works with gcc x86 32bit, but I don't have
access to any other 32bit environment.

Discussion: op.xpsjdkil0sbe7t@vld-kuci

Per report from Vladimir Koković.

9 years agodocs: improve CREATE TRIGGER defer options list
Bruce Momjian [Sat, 10 Jan 2015 00:19:29 +0000 (19:19 -0500)]
docs: improve CREATE TRIGGER defer options list

Report by Jeff Davis

9 years agopg_upgrade: fix one-byte per empty db memory leak
Bruce Momjian [Fri, 9 Jan 2015 17:12:30 +0000 (12:12 -0500)]
pg_upgrade:  fix one-byte per empty db memory leak

Report by Tatsuo Ishii, Coverity

9 years agoFix typo in execMain.c
Stephen Frost [Fri, 9 Jan 2015 16:01:31 +0000 (11:01 -0500)]
Fix typo in execMain.c

Wee -> We.

Pointed out by Etsuro Fujita.

9 years agoxlogreader.c: Fix report_invalid_record translatability flag
Alvaro Herrera [Fri, 9 Jan 2015 15:34:25 +0000 (12:34 -0300)]
xlogreader.c: Fix report_invalid_record translatability flag

For some reason I overlooked in GETTEXT_TRIGGERS that the right argument
be read by gettext in 7fcbf6a405ffc12a4546a25b98592ee6733783fc.  This
will drop the translation percentages for the backend all the way back
to 9.3 ...

Problem reported by Heikki.

9 years agoMove rowsecurity event trigger test
Stephen Frost [Fri, 2 Jan 2015 20:09:39 +0000 (15:09 -0500)]
Move rowsecurity event trigger test

The event trigger test for rowsecurity can cause problems for other
tests which are run in parallel with it.  Instead of running that test
in the rowsecurity set, move it to the event_trigger set, which runs
isolated from other tests.

Also reverts 7161b08, which moved rowsecurity into its own test group.
That's no longer necessary, now that the event trigger test is gone from
the rowsecurity set of tests.

Pointed out by Tom.

9 years agoRemove comment that was intended to have been removed before commit.
Andres Freund [Thu, 8 Jan 2015 12:10:33 +0000 (13:10 +0100)]
Remove comment that was intended to have been removed before commit.

Noticed by Amit Kapila

9 years agoMove comment about sun cc's __machine_rw_barrier being a full barrier.
Andres Freund [Thu, 8 Jan 2015 12:08:05 +0000 (13:08 +0100)]
Move comment about sun cc's __machine_rw_barrier being a full barrier.

I'd accidentally written the comment besides the read barrier, instead
of the full barrier, implementation.

Noticed by Oskari Saarenmaa

9 years agoFix logging of pages skipped due to pins during vacuum.
Andres Freund [Thu, 8 Jan 2015 11:57:09 +0000 (12:57 +0100)]
Fix logging of pages skipped due to pins during vacuum.

The new logging introduced in 35192f06 made the incorrect assumption
that scan_all vacuums would always wait for buffer pins; but they only
do so if the page actually needs to be frozen.

Fix that inaccuracy by removing the difference in log output based on
scan_all and just always remove the same message.  I chose to keep the
split log message from the original commit for now, it seems likely
that it'll be of use in the future.

Also merge the line about buffer pins in autovacuum's log output into
the existing "pages: ..." line. It seems odd to have a separate line
about pins, without the "topic: " prefix others have.

Also rename the new 'pinned_pages' variable to 'pinskipped_pages'
because it actually tracks the number of pages that could *not* be
pinned.

Discussion: 20150104005324.GC9626@awork2.anarazel.de

9 years agoOn Darwin, refuse postmaster startup when multithreaded.
Noah Misch [Thu, 8 Jan 2015 03:46:59 +0000 (22:46 -0500)]
On Darwin, refuse postmaster startup when multithreaded.

The previous commit introduced its report at LOG level to avoid
surprises at minor release upgrade time.  Compel users deploying the
next major release to also deploy the reported workaround.

9 years agoOn Darwin, detect and report a multithreaded postmaster.
Noah Misch [Thu, 8 Jan 2015 03:35:44 +0000 (22:35 -0500)]
On Darwin, detect and report a multithreaded postmaster.

Darwin --enable-nls builds use a substitute setlocale() that may start a
thread.  Buildfarm member orangutan experienced BackendList corruption
on account of different postmaster threads executing signal handlers
simultaneously.  Furthermore, a multithreaded postmaster risks undefined
behavior from sigprocmask() and fork().  Emit LOG messages about the
problem and its workaround.  Back-patch to 9.0 (all supported versions).

9 years agoAlways set the six locale category environment variables in main().
Noah Misch [Thu, 8 Jan 2015 03:34:57 +0000 (22:34 -0500)]
Always set the six locale category environment variables in main().

Typical server invocations already achieved that.  Invalid locale
settings in the initial postmaster environment interfered, as could
malloc() failure.  Setting "LC_MESSAGES=pt_BR.utf8 LC_ALL=invalid" in
the postmaster environment will now choose C-locale messages, not
Brazilian Portuguese messages.  Most localized programs, including all
PostgreSQL frontend executables, do likewise.  Users are unlikely to
observe changes involving locale categories other than LC_MESSAGES.
CheckMyDatabase() ensures that we successfully set LC_COLLATE and
LC_CTYPE; main() sets the remaining three categories to locale "C",
which almost cannot fail.  Back-patch to 9.0 (all supported versions).

9 years agoReject ANALYZE commands during VACUUM FULL or another ANALYZE.
Noah Misch [Thu, 8 Jan 2015 03:33:58 +0000 (22:33 -0500)]
Reject ANALYZE commands during VACUUM FULL or another ANALYZE.

vacuum()'s static variable handling makes it non-reentrant; an ensuing
null pointer deference crashed the backend.  Back-patch to 9.0 (all
supported versions).

9 years agodocs: Reword CREATE POLICY documentation.
Robert Haas [Wed, 7 Jan 2015 19:49:59 +0000 (14:49 -0500)]
docs: Reword CREATE POLICY documentation.

9 years agoDon't open a WAL segment for writing at end of recovery.
Heikki Linnakangas [Wed, 7 Jan 2015 14:11:33 +0000 (16:11 +0200)]
Don't open a WAL segment for writing at end of recovery.

Since commit ba94518a, we used XLogFileOpen to open the next segment for
writing, but if the end-of-recovery happens exactly at a segment boundary,
the new segment might not exist yet. (Before ba94518a, XLogFileOpen was
correct, because we would open the previous segment if the switch happened
at the boundary.)

Instead of trying to create it if necessary, it's simpler to not bother
opening the segment at all. XLogWrite() will open or create it soon anyway,
after writing the checkpoint or end-of-recovery record.

Reported by Andres Freund.

9 years agoFix namespace handling in xpath function
Peter Eisentraut [Wed, 7 Jan 2015 04:06:13 +0000 (23:06 -0500)]
Fix namespace handling in xpath function

Previously, the xml value resulting from an xpath query would not have
namespace declarations if the namespace declarations were attached to
an ancestor element in the input xml value.  That means the output value
was not correct XML.  Fix that by running the result value through
xmlCopyNode(), which produces the correct namespace declarations.

Author: Ali Akbar <the.apaan@gmail.com>

9 years agoCorrectly handle relcache invalidation corner case during logical decoding.
Andres Freund [Tue, 6 Jan 2015 23:10:19 +0000 (00:10 +0100)]
Correctly handle relcache invalidation corner case during logical decoding.

When using a historic snapshot for logical decoding it can validly
happen that a relation that's in the relcache isn't visible to that
historic snapshot.  E.g. if a newly created relation is referenced in
the query that uses the SQL interface for logical decoding and a
sinval reset occurs.

The earlier commit that fixed the error handling for that corner case
already improves the situation as a ERROR is better than hitting an
assertion... But it's obviously not good enough.  So additionally
allow that case without an error if a historic snapshot is set up -
that won't allow an invalid entry to stay in the cache because it's a)
already marked invalid and will thus be rebuilt during the next access
b) the syscaches will be reset at the end of decoding.

There might be prettier solutions to handle this case, but all that we
could think of so far end up being much more complex than this quite
simple fix.

This fixes the assertion failures reported by the buildfarm (markhor,
tick, leech) after the introduction of new regression tests in
89fd41b390a4. The failure there weren't actually directly caused by
CLOBBER_CACHE_ALWAYS but the extraordinary long runtimes due to it
lead to sinval resets triggering the behaviour.

Discussion: 22459.1418656530@sss.pgh.pa.us

Backpatch to 9.4 where logical decoding was introduced.

9 years agoImprove relcache invalidation handling of currently invisible relations.
Andres Freund [Tue, 6 Jan 2015 23:10:18 +0000 (00:10 +0100)]
Improve relcache invalidation handling of currently invisible relations.

The corner case where a relcache invalidation tried to rebuild the
entry for a referenced relation but couldn't find it in the catalog
wasn't correct.

The code tried to RelationCacheDelete/RelationDestroyRelation the
entry. That didn't work when assertions are enabled because the latter
contains an assertion ensuring the refcount is zero. It's also more
generally a bad idea, because by virtue of being referenced somebody
might actually look at the entry, which is possible if the error is
trapped and handled via a subtransaction abort.

Instead just error out, without deleting the entry. As the entry is
marked invalid, the worst that can happen is that the invalid (and at
some point unused) entry lingers in the relcache.

Discussion: 22459.1418656530@sss.pgh.pa.us

There should be no way to hit this case < 9.4 where logical decoding
introduced a bug that can hit this. But since the code for handling
the corner case is there it should do something halfway sane, so
backpatch all the the way back.  The logical decoding bug will be
handled in a separate commit.

9 years agoDocument that Perl's Tie might add a trailing newline
Bruce Momjian [Tue, 6 Jan 2015 20:51:39 +0000 (15:51 -0500)]
Document that Perl's Tie might add a trailing newline

Report by Stefan Kaltenbrunner

9 years agoFix thinko in plpython error message
Alvaro Herrera [Tue, 6 Jan 2015 18:16:29 +0000 (15:16 -0300)]
Fix thinko in plpython error message

9 years agoClarify which files need manual copyright updates
Bruce Momjian [Tue, 6 Jan 2015 17:53:15 +0000 (12:53 -0500)]
Clarify which files need manual copyright updates

9 years agoSimplify post-copyright update instructions.
Bruce Momjian [Tue, 6 Jan 2015 16:45:17 +0000 (11:45 -0500)]
Simplify post-copyright update instructions.

9 years agoUpdate copyright for 2015
Bruce Momjian [Tue, 6 Jan 2015 16:43:47 +0000 (11:43 -0500)]
Update copyright for 2015

Backpatch certain files through 9.0

9 years agoFix broken pg_dump code for dumping comments on event triggers.
Tom Lane [Tue, 6 Jan 2015 00:27:04 +0000 (19:27 -0500)]
Fix broken pg_dump code for dumping comments on event triggers.

This never worked, I think.  Per report from Marc Munro.

In passing, fix funny spacing in the COMMENT ON command as a result of
excess space in the "label" string.

9 years agoFix oversight in recent pg_basebackup fix causing pg_receivexlog failures.
Andres Freund [Mon, 5 Jan 2015 11:22:50 +0000 (12:22 +0100)]
Fix oversight in recent pg_basebackup fix causing pg_receivexlog failures.

A oversight in 2c0a485896 causes 'could not create archive status file
"...": No such file or directory' errors in pg_receivexlog if the
target directory doesn't happen to contain a archive_status
directory. That's due to a stupidly left over 'true' constant instead
of mark_done being passed down to ProcessXLogDataMsg().

The bug is only present in the master branch, and luckily wasn't
released.

Spotted by Fujii Masao.

9 years agoFix typo in comment.
Fujii Masao [Mon, 5 Jan 2015 07:35:26 +0000 (16:35 +0900)]
Fix typo in comment.

Report by Amit Kapila

9 years agoFix thinko in lock mode enum
Alvaro Herrera [Sun, 4 Jan 2015 18:48:29 +0000 (15:48 -0300)]
Fix thinko in lock mode enum

Commit 0e5680f4737a9c6aa94aa9e77543e5de60411322 contained a thinko
mixing LOCKMODE with LockTupleMode.  This caused misbehavior in the case
where a tuple is marked with a multixact with at most a FOR SHARE lock,
and another transaction tries to acquire a FOR NO KEY EXCLUSIVE lock;
this case should block but doesn't.

Include a new isolation tester spec file to explicitely try all the
tuple lock combinations; without the fix it shows the problem:

    starting permutation: s1_begin s1_lcksvpt s1_tuplock2 s2_tuplock3 s1_commit
    step s1_begin: BEGIN;
    step s1_lcksvpt: SELECT * FROM multixact_conflict FOR KEY SHARE; SAVEPOINT foo;
    a

    1
    step s1_tuplock2: SELECT * FROM multixact_conflict FOR SHARE;
    a

    1
    step s2_tuplock3: SELECT * FROM multixact_conflict FOR NO KEY UPDATE;
    a

    1
    step s1_commit: COMMIT;

With the fixed code, step s2_tuplock3 blocks until session 1 commits,
which is the correct behavior.

All other cases behave correctly.

Backpatch to 9.3, like the commit that introduced the problem.

9 years agoAdd error handling for failing fstat() calls in copy.c.
Andres Freund [Sun, 4 Jan 2015 15:47:23 +0000 (16:47 +0100)]
Add error handling for failing fstat() calls in copy.c.

These calls are pretty much guaranteed not to fail unless something
has gone horribly wrong, and even in that case we'd just error out a
short time later.  But since several code checkers complain about the
missing check it seems worthwile to fix it nonetheless.

Pointed out by Coverity.

9 years agoCorrectly handle test durations of more than 2147s in pg_test_timing.
Andres Freund [Sun, 4 Jan 2015 14:44:49 +0000 (15:44 +0100)]
Correctly handle test durations of more than 2147s in pg_test_timing.

Previously the computation of the total test duration, measured in
microseconds, accidentally overflowed due to accidentally using signed
32bit arithmetic.  As the only consequence is that pg_test_timing
invocations with such, overly large, durations never finished the
practical consequences of this bug are minor.

Pointed out by Coverity.

Backpatch to 9.2 where pg_test_timing was added.

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.