]> granicus.if.org Git - postgresql/log
postgresql
8 years agoFix (some of) pltcl memory usage
Alvaro Herrera [Sun, 19 Jul 2015 10:26:14 +0000 (12:26 +0200)]
Fix (some of) pltcl memory usage

As reported by Bill Parker, PL/Tcl did not validate some malloc() calls
against NULL return.  Fix by using palloc() in a new long-lived memory
context instead.  This allows us to simplify error handling too, by
simply deleting the memory context instead of doing retail frees.

There's still a lot that could be done to improve PL/Tcl's memory
handling ...

This is pretty ancient, so backpatch all the way back.

Author: Michael Paquier and Álvaro Herrera
Discussion: https://www.postgresql.org/message-id/CAFrbyQwyLDYXfBOhPfoBGqnvuZO_Y90YgqFM11T2jvnxjLFmqw@mail.gmail.com

8 years agoImprove BRIN documentation somewhat
Alvaro Herrera [Mon, 20 Jul 2015 10:16:40 +0000 (12:16 +0200)]
Improve BRIN documentation somewhat

This removes some info about support procedures being used, which was
obsoleted by commit db5f98ab4f, as well as add some more documentation
on how to create new opclasses using the Minmax infrastructure.
(Hopefully we can get something similar for Inclusion as well.)

In passing, fix some obsolete mentions of "mmtuples" in source code
comments.

Backpatch to 9.5, where BRIN was introduced.

8 years agoFix mis-merge in previous commit
Alvaro Herrera [Mon, 20 Jul 2015 09:59:31 +0000 (11:59 +0200)]
Fix mis-merge in previous commit

8 years agoAdd some comments to test_ddl_deparse and a README
Alvaro Herrera [Mon, 20 Jul 2015 09:20:40 +0000 (11:20 +0200)]
Add some comments to test_ddl_deparse and a README

Per comments from Heikki Linnakangas.

Backpatch to 9.5, where this module was introduced.

8 years agoHandle AT_ReAddComment in test_ddl_deparse, and add a catch-all default.
Heikki Linnakangas [Mon, 20 Jul 2015 07:19:22 +0000 (10:19 +0300)]
Handle AT_ReAddComment in test_ddl_deparse, and add a catch-all default.

In the passing, also move AT_ReAddComment to more logical position in the
enum, after all the Constraint-related subcommands.

This fixes a compiler warning, added by commit e42375fc. Backpatch to 9.5,
like that patch.

8 years agoRemove dead code.
Andrew Dunstan [Sun, 19 Jul 2015 17:19:38 +0000 (13:19 -0400)]
Remove dead code.

Defect noticed by Coverity.

9 years agoMake WaitLatchOrSocket's timeout detection more robust.
Tom Lane [Sat, 18 Jul 2015 15:47:13 +0000 (11:47 -0400)]
Make WaitLatchOrSocket's timeout detection more robust.

In the previous coding, timeout would be noticed and reported only when
poll() or socket() returned zero (or the equivalent behavior on Windows).
Ordinarily that should work well enough, but it seems conceivable that we
could get into a state where poll() always returns a nonzero value --- for
example, if it is noticing a condition on one of the file descriptors that
we do not think is reason to exit the loop.  If that happened, we'd be in a
busy-wait loop that would fail to terminate even when the timeout expires.

We can make this more robust at essentially no cost, by deciding to exit
of our own accord if we compute a zero or negative time-remaining-to-wait.
Previously the code noted this but just clamped the time-remaining to zero,
expecting that we'd detect timeout on the next loop iteration.

Back-patch to 9.2.  While 9.1 had a version of WaitLatchOrSocket, it was
primitive compared to later versions, and did not guarantee reliable
detection of timeouts anyway.  (Essentially, this is a refinement of
commit 3e7fdcffd6f77187, which was back-patched only as far as 9.2.)

9 years agoEnable transforms modules to build and test on Cygwin.
Andrew Dunstan [Sat, 18 Jul 2015 14:09:04 +0000 (10:09 -0400)]
Enable transforms modules to build and test on Cygwin.

This still doesn't work correctly with Python 3, but I am committing
this so we can get Cygwin buildfarm members building with Python 2.

9 years agoRelease note compatibility item
Andrew Dunstan [Sat, 18 Jul 2015 01:08:03 +0000 (21:08 -0400)]
Release note compatibility item

Note that json and jsonb extraction operators no longer consider a
negative subscript to be invalid.

9 years agoSupport JSON negative array subscripts everywhere
Andrew Dunstan [Sat, 18 Jul 2015 00:56:13 +0000 (20:56 -0400)]
Support JSON negative array subscripts everywhere

Previously, there was an inconsistency across json/jsonb operators that
operate on datums containing JSON arrays -- only some operators
supported negative array count-from-the-end subscripting.  Specifically,
only a new-to-9.5 jsonb deletion operator had support (the new "jsonb -
integer" operator).  This inconsistency seemed likely to be
counter-intuitive to users.  To fix, allow all places where the user can
supply an integer subscript to accept a negative subscript value,
including path-orientated operators and functions, as well as other
extraction operators.  This will need to be called out as an
incompatibility in the 9.5 release notes, since it's possible that users
are relying on certain established extraction operators changed here
yielding NULL in the event of a negative subscript.

For the json type, this requires adding a way of cheaply getting the
total JSON array element count ahead of time when parsing arrays with a
negative subscript involved, necessitating an ad-hoc lex and parse.
This is followed by a "conversion" from a negative subscript to its
equivalent positive-wise value using the count.  From there on, it's as
if a positive-wise value was originally provided.

Note that there is still a minor inconsistency here across jsonb
deletion operators.  Unlike the aforementioned new "-" deletion operator
that accepts an integer on its right hand side, the new "#-" path
orientated deletion variant does not throw an error when it appears like
an array subscript (input that could be recognized by as an integer
literal) is being used on an object, which is wrong-headed.  The reason
for not being stricter is that it could be the case that an object pair
happens to have a key value that looks like an integer; in general,
these two possibilities are impossible to differentiate with rhs path
text[] argument elements.  However, we still don't allow the "#-"
path-orientated deletion operator to perform array-style subscripting.
Rather, we just return the original left operand value in the event of a
negative subscript (which seems analogous to how the established
"jsonb/json #> text[]" path-orientated operator may yield NULL in the
event of an invalid subscript).

In passing, make SetArrayPath() stricter about not accepting cases where
there is trailing non-numeric garbage bytes rather than a clean NUL
byte.  This means, for example, that strings like "10e10" are now not
accepted as an array subscript of 10 by some new-to-9.5 path-orientated
jsonb operators (e.g. the new #- operator).  Finally, remove dead code
for jsonb subscript deletion; arguably, this should have been done in
commit b81c7b409.

Peter Geoghegan and Andrew Dunstan

9 years agoRepair mishandling of cached cast-expression trees in plpgsql.
Tom Lane [Fri, 17 Jul 2015 19:53:09 +0000 (15:53 -0400)]
Repair mishandling of cached cast-expression trees in plpgsql.

In commit 1345cc67bbb014209714af32b5681b1e11eaf964, I introduced caching
of expressions representing type-cast operations into plpgsql.  However,
I supposed that I could cache both the expression trees and the evaluation
state trees derived from them for the life of the session.  This doesn't
work, because we execute the expressions in plpgsql's simple_eval_estate,
which has an ecxt_per_query_memory that is only transaction-lifespan.
Therefore we can end up putting pointers into the evaluation state tree
that point to transaction-lifespan memory; in particular this happens if
the cast expression calls a SQL-language function, as reported by Geoff
Winkless.

The minimum-risk fix seems to be to treat the state trees the same way
we do for "simple expression" trees in plpgsql, ie create them in the
simple_eval_estate's ecxt_per_query_memory, which means recreating them
once per transaction.

Since I had to introduce bookkeeping overhead for that anyway, I bought
back some of the added cost by sharing the read-only expression trees
across all functions in the session, instead of using a per-function
table as originally.  The simple-expression bookkeeping takes care of
the recursive-usage risk that I was concerned about avoiding before.

At some point we should take a harder look at how all this works,
and see if we can't reduce the amount of tree reinitialization needed.
But that won't happen for 9.5.

9 years agoFix entirely broken permissions test in new alter_operator regression test.
Tom Lane [Fri, 17 Jul 2015 18:10:52 +0000 (14:10 -0400)]
Fix entirely broken permissions test in new alter_operator regression test.

Not only did this test fail to test what it was supposed to test, but it
left a user definition lying around, which caused subsequent runs of the
regression tests to fail.

9 years agoAdd new function pg_notification_queue_usage.
Robert Haas [Fri, 17 Jul 2015 13:12:03 +0000 (09:12 -0400)]
Add new function pg_notification_queue_usage.

This tells you what fraction of NOTIFY's queue is currently filled.

Brendan Jurd, reviewed by Merlin Moncure and Gurjeet Singh.  A few
further tweaks by me.

9 years agoAIX: Test the -qlonglong option before use.
Noah Misch [Fri, 17 Jul 2015 07:01:14 +0000 (03:01 -0400)]
AIX: Test the -qlonglong option before use.

xlc provides "long long" unconditionally at C99-compatible language
levels, and this option provokes a warning.  The warning interferes with
"configure" tests that fail in response to any warning.  Notably, before
commit 85a2a8903f7e9151793308d0638621003aded5ae, it interfered with the
test for -qnoansialias.  Back-patch to 9.0 (all supported versions).

9 years agoFix a low-probability crash in our qsort implementation.
Tom Lane [Fri, 17 Jul 2015 02:57:46 +0000 (22:57 -0400)]
Fix a low-probability crash in our qsort implementation.

It's standard for quicksort implementations, after having partitioned the
input into two subgroups, to recurse to process the smaller partition and
then handle the larger partition by iterating.  This method guarantees
that no more than log2(N) levels of recursion can be needed.  However,
Bentley and McIlroy argued that checking to see which partition is smaller
isn't worth the cycles, and so their code doesn't do that but just always
recurses on the left partition.  In most cases that's fine; but with
worst-case input we might need O(N) levels of recursion, and that means
that qsort could be driven to stack overflow.  Such an overflow seems to
be the only explanation for today's report from Yiqing Jin of a SIGSEGV
in med3_tuple while creating an index of a couple billion entries with a
very large maintenance_work_mem setting.  Therefore, let's spend the few
additional cycles and lines of code needed to choose the smaller partition
for recursion.

Also, fix up the qsort code so that it properly uses size_t not int for
some intermediate values representing numbers of items.  This would only
be a live risk when sorting more than INT_MAX bytes (in qsort/qsort_arg)
or tuples (in qsort_tuple), which I believe would never happen with any
caller in the current core code --- but perhaps it could happen with
call sites in third-party modules?  In any case, this is trouble waiting
to happen, and the corrected code is probably if anything shorter and
faster than before, since it removes sign-extension steps that had to
happen when converting between int and size_t.

In passing, move a couple of CHECK_FOR_INTERRUPTS() calls so that it's
not necessary to preserve the value of "r" across them, and prettify
the output of gen_qsort_tuple.pl a little.

Back-patch to all supported branches.  The odds of hitting this issue
are probably higher in 9.4 and up than before, due to the new ability
to allocate sort workspaces exceeding 1GB, but there's no good reason
to believe that it's impossible to crash older branches this way.

9 years agoFix spelling error
Magnus Hagander [Thu, 16 Jul 2015 07:31:58 +0000 (10:31 +0300)]
Fix spelling error

David Rowley

9 years agoFix copy/past error in comment
Magnus Hagander [Thu, 16 Jul 2015 07:28:44 +0000 (10:28 +0300)]
Fix copy/past error in comment

David Christensen

9 years agoAIX: Link TRANSFORM modules with their dependencies.
Noah Misch [Thu, 16 Jul 2015 01:00:26 +0000 (21:00 -0400)]
AIX: Link TRANSFORM modules with their dependencies.

The result closely resembles linking of these modules for the "win32"
port.  Augment the $(exports_file) header so the file is also usable as
an import file.  Unfortunately, relocating an AIX installation will now
require adding $(pkglibdir) to LD_LIBRARY_PATH.  Back-patch to 9.5,
where the modules were introduced.

9 years agoAIX: Link the postgres executable with -Wl,-brtllib.
Noah Misch [Thu, 16 Jul 2015 01:00:26 +0000 (21:00 -0400)]
AIX: Link the postgres executable with -Wl,-brtllib.

This allows PostgreSQL modules and their dependencies to have undefined
symbols, resolved at runtime.  Perl module shared objects rely on that
in Perl 5.8.0 and later.  This fixes the crash when PL/PerlU loads such
modules, as the hstore_plperl test suite does.  Module authors can link
using -Wl,-G to permit undefined symbols; by default, linking will fail
as it has.  Back-patch to 9.0 (all supported versions).

9 years agoMinGW: Link ltree_plpython with plpython.
Noah Misch [Thu, 16 Jul 2015 01:00:26 +0000 (21:00 -0400)]
MinGW: Link ltree_plpython with plpython.

The MSVC build system already did this, and building against Python 3
requires it.  Back-patch to 9.5, where the module was introduced.

9 years agoMention table_rewrite as valid event trigger tag
Alvaro Herrera [Wed, 15 Jul 2015 14:08:46 +0000 (17:08 +0300)]
Mention table_rewrite as valid event trigger tag

This was forgotten in 618c9430a8.

9 years agoRemove regression test added on auto-pilot.
Robert Haas [Tue, 14 Jul 2015 20:19:44 +0000 (16:19 -0400)]
Remove regression test added on auto-pilot.

Test does not match the comment which precedes it.

Peter Geoghegan

9 years agoFix event trigger support for the new ALTER OPERATOR command.
Heikki Linnakangas [Tue, 14 Jul 2015 16:50:18 +0000 (19:50 +0300)]
Fix event trigger support for the new ALTER OPERATOR command.

Also, the lock on pg_operator should not be released until end of
transaction.

9 years agoAdd ALTER OPERATOR command, for changing selectivity estimator functions.
Heikki Linnakangas [Tue, 14 Jul 2015 15:17:55 +0000 (18:17 +0300)]
Add ALTER OPERATOR command, for changing selectivity estimator functions.

Other options cannot be changed, as it's not totally clear if cached plans
would need to be invalidated if one of the other options change. Selectivity
estimator functions only change plan costs, not correctness of plans, so
those should be safe.

Original patch by Uriy Zhuravlev, heavily edited by me.

9 years agoPrevent pgstattuple() from reporting BRIN as unknown index.
Fujii Masao [Tue, 14 Jul 2015 13:36:51 +0000 (22:36 +0900)]
Prevent pgstattuple() from reporting BRIN as unknown index.

Also this patch removes obsolete comment.

Back-patch to 9.5 where BRIN index was added.

9 years agoMake regression test output stable.
Heikki Linnakangas [Tue, 14 Jul 2015 13:16:23 +0000 (16:16 +0300)]
Make regression test output stable.

In the test query I added for ALTER TABLE retaining comments, the order of
the result rows was not stable, and varied across systems. Add an ORDER BY
to make the order predictable. This should fix the buildfarm failures.

9 years agoRetain comments on indexes and constraints at ALTER TABLE ... TYPE ...
Heikki Linnakangas [Tue, 14 Jul 2015 08:40:22 +0000 (11:40 +0300)]
Retain comments on indexes and constraints at ALTER TABLE ... TYPE ...

When a column's datatype is changed, ATExecAlterColumnType() rebuilds all
the affected indexes and constraints, and the comments from the old
indexes/constraints were not carried over.

To fix, create a synthetic COMMENT ON command in the work queue, to re-add
any comments on constraints. For indexes, there's a comment field in
IndexStmt that is used.

This fixes bug #13126, reported by Kirill Simonov. Original patch by
Michael Paquier, reviewed by Petr Jelinek and me. This bug is present in
all versions, but only backpatch to 9.5. Given how minor the issue is, it
doesn't seem worth the work and risk to backpatch further than that.

9 years agoReformat code in ATPostAlterTypeParse.
Heikki Linnakangas [Tue, 14 Jul 2015 08:38:08 +0000 (11:38 +0300)]
Reformat code in ATPostAlterTypeParse.

The code in ATPostAlterTypeParse was very deeply indented, mostly because
there were two nested switch-case statements, which add a lot of
indentation. Use if-else blocks instead, to make the code less indented
and more readable.

This is in preparation for next patch that makes some actualy changes to
the function. These cosmetic parts have been separated to make it easier
to see the real changes in the other patch.

9 years agorelease notes: markup: vacuumdb is an application, not command
Bruce Momjian [Sun, 12 Jul 2015 21:41:57 +0000 (17:41 -0400)]
release notes:  markup:  vacuumdb is an application, not command

9 years agoFix assorted memory leaks.
Tom Lane [Sun, 12 Jul 2015 20:25:51 +0000 (16:25 -0400)]
Fix assorted memory leaks.

Per Coverity (not that any of these are so non-obvious that they should not
have been caught before commit).  The extent of leakage is probably minor
to unnoticeable, but a leak is a leak.  Back-patch as necessary.

Michael Paquier

9 years agoFor consistency add a pfree to ON CONFLICT set_plan_refs code.
Andres Freund [Sun, 12 Jul 2015 20:18:57 +0000 (22:18 +0200)]
For consistency add a pfree to ON CONFLICT set_plan_refs code.

Backpatch to 9.5 where ON CONFLICT was introduced.

Author: Peter Geoghegan

9 years agoOptionally don't error out due to preexisting slots in commandline utilities.
Andres Freund [Sun, 12 Jul 2015 20:06:27 +0000 (22:06 +0200)]
Optionally don't error out due to preexisting slots in commandline utilities.

pg_receivexlog and pg_recvlogical error out when --create-slot is
specified and a slot with the same name already exists. In some cases,
especially with pg_receivexlog, that's rather annoying and requires
additional scripting.

Backpatch to 9.5 as slot control functions have newly been added to
pg_receivexlog, and there doesn't seem much point leaving it in a less
useful state.

Discussion: 20150619144755.GG29350@alap3.anarazel.de

9 years agoAdd now-required #include.
Tom Lane [Sun, 12 Jul 2015 03:34:41 +0000 (23:34 -0400)]
Add now-required #include.

Fixes compiler warning induced by 808ea8fc7bb259ddd810353719cac66e85a608c8.

9 years agodoc: fix typo in CREATE POLICY manual page
Bruce Momjian [Sun, 12 Jul 2015 02:46:28 +0000 (22:46 -0400)]
doc:  fix typo in CREATE POLICY manual page

Backpatch through 9.5

9 years agoAdd assign_expr_collations() to CreatePolicy() and AlterPolicy().
Joe Conway [Sat, 11 Jul 2015 21:19:31 +0000 (14:19 -0700)]
Add assign_expr_collations() to CreatePolicy() and AlterPolicy().

As noted by Noah Misch, CreatePolicy() and AlterPolicy() omit to call
assign_expr_collations() on the node trees. Fix the omission and add
his test case to the rowsecurity regression test.

9 years agoCopy-edit the docs changes of OWNER TO CURRENT/SESSION_USER additions.
Heikki Linnakangas [Fri, 10 Jul 2015 11:28:34 +0000 (14:28 +0300)]
Copy-edit the docs changes of OWNER TO CURRENT/SESSION_USER additions.

Commit 31eae602 added new syntax to many DDL commands to use CURRENT_USER
or SESSION_USER instead of role name in ALTER ... OWNER TO, but because
of a misplaced '{', the syntax in the docs implied that the syntax was
"ALTER ... CURRENT_USER", instead of "ALTER ... OWNER TO CURRENT_USER".
Fix that, and also the funny indentation in some of the modified syntax
blurps.

9 years agoImprove documentation about array concat operator vs. underlying functions.
Tom Lane [Thu, 9 Jul 2015 22:50:31 +0000 (18:50 -0400)]
Improve documentation about array concat operator vs. underlying functions.

The documentation implied that there was seldom any reason to use the
array_append, array_prepend, and array_cat functions directly.  But that's
not really true, because they can help make it clear which case is meant,
which the || operator can't do since it's overloaded to represent all three
cases.  Add some discussion and examples illustrating the potentially
confusing behavior that can ensue if the parser misinterprets what was
meant.

Per a complaint from Michael Herold.  Back-patch to 9.2, which is where ||
started to behave this way.

9 years agoFix postmaster's handling of a startup-process crash.
Tom Lane [Thu, 9 Jul 2015 17:22:22 +0000 (13:22 -0400)]
Fix postmaster's handling of a startup-process crash.

Ordinarily, a failure (unexpected exit status) of the startup subprocess
should be considered fatal, so the postmaster should just close up shop
and quit.  However, if we sent the startup process a SIGQUIT or SIGKILL
signal, the failure is hardly "unexpected", and we should attempt restart;
this is necessary for recovery from ordinary backend crashes in hot-standby
scenarios.  I attempted to implement the latter rule with a two-line patch
in commit 442231d7f71764b8c628044e7ce2225f9aa43b67, but it now emerges that
that patch was a few bricks shy of a load: it failed to distinguish the
case of a signaled startup process from the case where the new startup
process crashes before reaching database consistency.  That resulted in
infinitely respawning a new startup process only to have it crash again.

To handle this properly, we really must track whether we have sent the
*current* startup process a kill signal.  Rather than add yet another
ad-hoc boolean to the postmaster's state, I chose to unify this with the
existing RecoveryError flag into an enum tracking the startup process's
state.  That seems more consistent with the postmaster's general state
machine design.

Back-patch to 9.0, like the previous patch.

9 years agoFix obsolete comment regarding NOTICE message level.
Fujii Masao [Thu, 9 Jul 2015 13:52:36 +0000 (22:52 +0900)]
Fix obsolete comment regarding NOTICE message level.

By default NOTICE message is not sent to server log because
the default value of log_min_messages is WARNING since 8.4.

Pavel Stehule

9 years agoMake wal_compression PGC_SUSET rather than PGC_USERSET.
Fujii Masao [Thu, 9 Jul 2015 13:30:52 +0000 (22:30 +0900)]
Make wal_compression PGC_SUSET rather than PGC_USERSET.

When enabling wal_compression, there is a risk to leak data similarly to
the BREACH and CRIME attacks on SSL where the compression ratio of
a full page image gives a hint of what is the existing data of this page.
This vulnerability is quite cumbersome to exploit in practice, but doable.

So this patch makes wal_compression PGC_SUSET in order to prevent
non-superusers from enabling it and exploiting the vulnerability while
DBA thinks the risk very seriously and disables it in postgresql.conf.

Back-patch to 9.5 where wal_compression was introduced.

9 years agoUse --debug flag in "remote" pg_rewind regression tests.
Heikki Linnakangas [Thu, 9 Jul 2015 13:15:09 +0000 (16:15 +0300)]
Use --debug flag in "remote" pg_rewind regression tests.

Gives more information in the log, to debug possible failures.

9 years agoFix another broken link in documentation.
Heikki Linnakangas [Thu, 9 Jul 2015 13:00:14 +0000 (16:00 +0300)]
Fix another broken link in documentation.

Tom fixed another one of these in commit 7f32dbcd, but there was another
almost identical one in libpq docs. Per his comment:

HP's web server has apparently become case-sensitive sometime recently.
Per bug #13479 from Daniel Abraham.  Corrected link identified by Alvaro.

9 years agoImprove logging of TAP tests.
Heikki Linnakangas [Thu, 9 Jul 2015 10:19:10 +0000 (13:19 +0300)]
Improve logging of TAP tests.

Create a log file for each test run. Stdout and stderr of the test script,
as well as any subprocesses run as part of the test, are redirected to
the log file. This makes it a lot easier to debug test failures. Also print
the test output (ok 12 - ... messages) to the log file, and the command
line of any external programs executed with the system_or_bail and run_log
functions. This makes it a lot easier to debug failing tests.

Modify some of the pg_ctl and other command invocations to not use 'silent'
or 'quiet' options, and don't redirect output to /dev/null, so that you get
all the information in the log instead.

In the passing, construct some command lines in a way that works if $tempdir
contains quote-characters. I haven't systematically gone through all of
them or tested that, so I don't know if this is enough to make that work.

pg_rewind tests had a custom mechanism for creating a similar log file. Use
the new generic facility instead.

Michael Paquier and me.

9 years agoUse AS_IF rather than plain shell "if" in pthread-check.
Heikki Linnakangas [Thu, 9 Jul 2015 08:38:34 +0000 (11:38 +0300)]
Use AS_IF rather than plain shell "if" in pthread-check.

Autoconf generates additional code for the first AC_CHECK_HEADERS call in
the script. If the first call is within an if-block, the additional code is
put inside the if-block too, even though it is needed by subsequent
AC_CHECK_HEADERS checks and should always be executed. When I moved the
pthread-related checks earlier in the script, the pthread.h test inside
the block became the very first AC_CHECK_HEADERS call in the script,
triggering that problem.

To fix, use AS_IF instead of plain shell if. AS_IF knows about that issue,
and makes sure the additional code is always executed. To be completely
safe from this issue (and others), we should always be using AS_IF instead
of plain if, but that seems like excessive caution given that this is the
first time we have trouble like this. Plain if-then is more readable than
AS_IF.

This should fix compilation with --disable-thread-safety, and hopefully the
buildfarm failure on forgmouth, related to mingw standard headers, too.
I backpatched the previous fixes to 9.5, but it's starting to look like
these changes are too fiddly to backpatch, so commit this to master only,
and revert all the pthread-related configure changes in 9.5.

9 years agoAdd .gitignore entries for AIX-specific intermediate build artifacts.
Noah Misch [Thu, 9 Jul 2015 00:44:22 +0000 (20:44 -0400)]
Add .gitignore entries for AIX-specific intermediate build artifacts.

9 years agoLink pg_stat_statements with libm.
Noah Misch [Thu, 9 Jul 2015 00:44:22 +0000 (20:44 -0400)]
Link pg_stat_statements with libm.

The AIX 7.1 libm is static, and AIX postgres executables do not export
symbols acquired from libraries.  Back-patch to 9.5, where commit
cfe12763c32437bc708a64ce88a90c7544f16185 added a sqrt() call.

9 years agoGiven a gcc-compatible xlc compiler, prefer xlc-style atomics.
Noah Misch [Thu, 9 Jul 2015 00:44:21 +0000 (20:44 -0400)]
Given a gcc-compatible xlc compiler, prefer xlc-style atomics.

This evades a ppc64le "IBM XL C/C++ for Linux" compiler bug.  Back-patch
to 9.5, where the atomics facility was introduced.

9 years agoFinish generic-xlc.h draft atomics implementation.
Noah Misch [Thu, 9 Jul 2015 00:44:21 +0000 (20:44 -0400)]
Finish generic-xlc.h draft atomics implementation.

Back-patch to 9.5, where commit b64d92f1a5602c55ee8b27a7ac474f03b7aee340
introduced this file.

9 years agoRevoke support for strxfrm() that write past the specified array length.
Noah Misch [Thu, 9 Jul 2015 00:44:21 +0000 (20:44 -0400)]
Revoke support for strxfrm() that write past the specified array length.

This formalizes a decision implicit in commit
4ea51cdfe85ceef8afabceb03c446574daa0ac23 and adds clean detection of
affected systems.  Vendor updates are available for each such known bug.
Back-patch to 9.5, where the aforementioned commit first appeared.

9 years agoReplace use of "diff -q".
Noah Misch [Thu, 9 Jul 2015 00:44:21 +0000 (20:44 -0400)]
Replace use of "diff -q".

POSIX does not specify the -q option, and many implementations do not
offer it.  Don't bother changing the MSVC build system, because having
non-GNU diff on Windows is vanishingly unlikely.  Back-patch to 9.2,
where this invocation was introduced.

9 years agoFix null pointer dereference in "\c" psql command.
Noah Misch [Thu, 9 Jul 2015 00:44:21 +0000 (20:44 -0400)]
Fix null pointer dereference in "\c" psql command.

The psql crash happened when no current connection existed.  (The second
new check is optional given today's undocumented NULL argument handling
in PQhost() etc.)  Back-patch to 9.0 (all supported versions).

9 years agoMove pthread-tests earlier in the autoconf script.
Heikki Linnakangas [Wed, 8 Jul 2015 21:05:45 +0000 (00:05 +0300)]
Move pthread-tests earlier in the autoconf script.

On some Linux systems, "-lrt" exposed pthread-functions, so that linking
with -lrt was seemingly enough to make a program that uses pthreads to
work. However, when linking libpq, the dependency to libpthread was not
marked correctly, so that when an executable was linked with -lpq but
without -pthread, you got errors about undefined pthread_* functions from
libpq.

To fix, test for the flags required to use pthreads earlier in the autoconf
script, before checking any other libraries.

This should fix the failure on buildfarm member shearwater. gharial is also
failing; hopefully this fixes that too although the failure looks somewhat
different.

9 years agoReplace our hacked version of ax_pthread.m4 with latest upstream version.
Heikki Linnakangas [Wed, 8 Jul 2015 17:36:06 +0000 (20:36 +0300)]
Replace our hacked version of ax_pthread.m4 with latest upstream version.

Our version was different from the upstream version in that we tried to use
all possible pthread-related flags that the compiler accepts, rather than
just the first one that works. That change was made in commit
e48322a6d6cfce1ec52ab303441df329ddbc04d1, to work-around a bug affecting GCC
versions 3.2 and below (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=8888),
although we didn't realize that it was a GCC bug at the time. We hardly care
about that old GCC versions anymore, so we no longer need that workaround.

This fixes the macro for compilers that print warnings with the chosen
flags. That's pretty annoying on its own right, but it also inconspicuously
disabled thread-safety, because we refused to use any pthread-related flags
if the compiler produced warnings. Max Filippov reported that problem when
linking with uClibc and OpenSSL. The warnings-check was added because the
workaround for the GCC bug caused warnings otherwise, so it's no longer
needed either. We can just use the upstream version as is.

If you really want to compile with GCC version 3.2 or older, you can still
work-around it manually by setting PTHREAD_CFLAGS="-pthread -lpthread"
manually on the configure command line.

Backpatch to 9.5. I don't want to unnecessarily rock the boat on stable
branches, but 9.5 seems like fair game.

9 years agoImprove regression test coverage of table lock modes vs permissions.
Joe Conway [Tue, 7 Jul 2015 21:35:35 +0000 (14:35 -0700)]
Improve regression test coverage of table lock modes vs permissions.

Test the interactions with permissions and LOCK TABLE. Specifically
ROW EXCLUSIVE, ACCESS SHARE, and ACCESS EXCLUSIVE modes against
SELECT, INSERT, UPDATE, DELETE, and TRUNCATE permissions. Discussed
by Stephen Frost and Michael Paquier, patch by the latter. Backpatch
to 9.5 where matching behavior was first committed.

9 years agoFix incorrect path in pg_regress log messages.
Fujii Masao [Tue, 7 Jul 2015 16:54:17 +0000 (01:54 +0900)]
Fix incorrect path in pg_regress log messages.

Back-patch to 9.5 where the bug was introduced.

David Christensen

9 years agoFix portability issue in pg_upgrade test script: avoid $PWD.
Tom Lane [Tue, 7 Jul 2015 16:49:18 +0000 (12:49 -0400)]
Fix portability issue in pg_upgrade test script: avoid $PWD.

SUSv2-era shells don't set the PWD variable, though anything more modern
does.  In the buildfarm environment this could lead to test.sh executing
with PWD pointing to $HOME or another high-level directory, so that there
were conflicts between concurrent executions of the test in different
branch subdirectories.  This appears to be the explanation for recent
intermittent failures on buildfarm members binturong and dingo (and might
well have something to do with the buildfarm script's failure to capture
log files from pg_upgrade tests, too).

To fix, just use `pwd` in place of $PWD.  AFAICS test.sh is the only place
in our source tree that depended on $PWD.  Back-patch to all versions
containing this script.

Per buildfarm.  Thanks to Oskari Saarenmaa for diagnosing the problem.

9 years agoImprove handling of out-of-memory in libpq.
Heikki Linnakangas [Tue, 7 Jul 2015 15:37:45 +0000 (18:37 +0300)]
Improve handling of out-of-memory in libpq.

If an allocation fails in the main message handling loop, pqParseInput3
or pqParseInput2, it should not be treated as "not enough data available
yet". Otherwise libpq will wait indefinitely for more data to arrive from
the server, and gets stuck forever.

This isn't a complete fix - getParamDescriptions and getCopyStart still
have the same issue, but it's a step in the right direction.

Michael Paquier and me. Backpatch to all supported versions.

9 years agoAdd tab-completion for psql meta-commands.
Fujii Masao [Tue, 7 Jul 2015 14:34:18 +0000 (23:34 +0900)]
Add tab-completion for psql meta-commands.

Based on the original code from David Christensen, modified by me.

9 years agoRefer to %p in the psql docs as 'process ID' not 'pid'.
Andres Freund [Tue, 7 Jul 2015 14:23:55 +0000 (16:23 +0200)]
Refer to %p in the psql docs as 'process ID' not 'pid'.

Per Tom.

9 years agoAdd psql PROMPT variable showing the pid of the connected to backend.
Andres Freund [Tue, 7 Jul 2015 11:40:44 +0000 (13:40 +0200)]
Add psql PROMPT variable showing the pid of the connected to backend.

The substitution for the pid is %p.

Author: Julien Rouhaud
Discussion: 116262CF971C844FB6E793F8809B51C6E99D48@BPXM02GP.gisp.nec.co.jp

9 years agoFix logical decoding bug leading to inefficient reopening of files.
Andres Freund [Tue, 7 Jul 2015 11:05:41 +0000 (13:05 +0200)]
Fix logical decoding bug leading to inefficient reopening of files.

When spilling transaction data to disk a simple typo caused the output
file to be closed and reopened for every serialized change. That happens
to not have a huge impact on linux, which is why it probably wasn't
noticed so far, but on windows that appears to trigger actual disk
writes after every change. Not fun.

The bug fortunately does not have any impact besides speed. A change
could end up being in the wrong segment (last instead of next), but
since we read all files to the end, that's just ugly, not really
problematic. It's not a problem to upgrade, since transaction spill
files do not persist across restarts.

Bug: #13484
Reported-By: Olivier Gosseaume
Discussion: 20150703090217.1190.63940@wrigleys.postgresql.org

Backpatch to 9.4, where logical decoding was added.

9 years agoFix pg_recvlogical not to fsync output when it's a tty or pipe.
Andres Freund [Tue, 7 Jul 2015 10:47:44 +0000 (12:47 +0200)]
Fix pg_recvlogical not to fsync output when it's a tty or pipe.

The previous coding tried to handle possible failures when fsyncing a
tty or pipe fd by accepting EINVAL - but apparently some
platforms (windows, OSX) don't reliably return that. So instead check
whether the output fd refers to a pipe or a tty when opening it.

Reported-By: Olivier Gosseaume, Marko Tiikkaja
Discussion: 559AF98B.3050901@joh.to

Backpatch to 9.4, where pg_recvlogical was added.

9 years agoMake RLS related error messages more consistent and compliant.
Joe Conway [Tue, 7 Jul 2015 02:16:53 +0000 (19:16 -0700)]
Make RLS related error messages more consistent and compliant.

Also updated regression expected output to match. Noted and patch by Daniele Varrazzo.

9 years agoTurn install.bat into a pure one line wrapper fort he perl script.
Heikki Linnakangas [Mon, 6 Jul 2015 19:18:26 +0000 (22:18 +0300)]
Turn install.bat into a pure one line wrapper fort he perl script.

Build.bat and vcregress.bat got similar treatment years ago. I'm not sure
why install.bat wasn't treated at the same time, but it seems like a good
idea anyway.

The immediate problem with the old install.bat was that it had quoting
issues, and wouldn't work if the target directory's name contained spaces.
This fixes that problem.

9 years agoCall getsockopt() on the correct socket.
Heikki Linnakangas [Mon, 6 Jul 2015 13:36:48 +0000 (16:36 +0300)]
Call getsockopt() on the correct socket.

We're interested in the buffer size of the socket that's connected to the
client, not the one that's listening for new connections. It happened to
work, as default buffer size is the same on both, but it was clearly not
wrong.

Spotted by Tom Lane

9 years agoDon't set SO_SNDBUF on recent Windows versions that have a bigger default.
Heikki Linnakangas [Mon, 6 Jul 2015 13:10:58 +0000 (16:10 +0300)]
Don't set SO_SNDBUF on recent Windows versions that have a bigger default.

It's unnecessary to set it if the default is higher in the first place.
Furthermore, setting SO_SNDBUF disables the so-called "dynamic send
buffering" feature, which hurts performance further. This can be seen
especially when the network between the client and the server has high
latency.

Chen Huajun

9 years agoRemove incorrect warning from pg_archivecleanup document.
Fujii Masao [Mon, 6 Jul 2015 11:58:58 +0000 (20:58 +0900)]
Remove incorrect warning from pg_archivecleanup document.

The .backup file name can be passed to pg_archivecleanup even if
it includes the extension which is specified in -x option.
However, previously the document incorrectly warned a user
not to do that.

Back-patch to 9.2 where pg_archivecleanup's -x option and
the warning were added.

9 years agoMake a editorial pass over pgbench's error messages.
Tom Lane [Sun, 5 Jul 2015 23:36:57 +0000 (19:36 -0400)]
Make a editorial pass over pgbench's error messages.

The lack of consistency, and lack of attention to our message style
guidelines, was a bit striking.  Try to make 'em better.

9 years agoFix some typos in regression test comments.
Tom Lane [Sun, 5 Jul 2015 17:14:38 +0000 (13:14 -0400)]
Fix some typos in regression test comments.

Back-patch to avoid unnecessary cross-branch differences.

CharSyam

9 years agoFurther reduce overhead for passing plpgsql variables to the executor.
Tom Lane [Sun, 5 Jul 2015 16:57:17 +0000 (12:57 -0400)]
Further reduce overhead for passing plpgsql variables to the executor.

This builds on commit 21dcda2713656a7483e3280ac9d2ada20a87a9a9 by keeping
a plpgsql function's shared ParamListInfo's entries for simple variables
(PLPGSQL_DTYPE_VARs) valid at all times.  That adds a few cycles to each
assignment to such variables, but saves significantly more cycles each time
they are used; so except in the pathological case of many dead stores, this
should always be a win.  Initial testing says it's good for about a 10%
speedup of simple calculations; more in large functions with many datums.

We can't use this method for row/record references unfortunately, so what
we do for those is reset those ParamListInfo slots after use; which we
can skip doing unless some of them were actually evaluated during the
previous evaluation call.  So this should frequently be a win as well,
while worst case is that it's similar cost to the previous approach.

Also, closer study suggests that the previous method of instantiating a
new ParamListInfo array per evaluation is actually probably optimal for
cursor-opening executor calls.  The reason is that whatever is visible in
the array is going to get copied into the cursor portal via copyParamList.
So if we used the function's main ParamListInfo for those calls, we'd end
up with all of its DTYPE_VAR vars getting copied, which might well include
large pass-by-reference values that the cursor actually has no need for.
To avoid a possible net degradation in cursor cases, go back to creating
and filling a private ParamListInfo in those cases (which therefore will be
exactly the same speed as before 21dcda271365).  We still get some benefit
out of this though, because this approach means that we only have to defend
against copyParamList's try-to-fetch-every-slot behavior in the case of an
unshared ParamListInfo; so plpgsql_param_fetch() can skip testing
expr->paramnos in the common case.

To ensure that the main ParamListInfo's image of a DTYPE_VAR datum is
always valid, all assignments to such variables are now funneled through
assign_simple_var().  But this makes for cleaner and shorter code anyway.

9 years agoFix bad grammar in brin.sgml.
Tom Lane [Sun, 5 Jul 2015 16:08:15 +0000 (12:08 -0400)]
Fix bad grammar in brin.sgml.

Christoph Berg

9 years agoAdd documentation and regression tests concerning rounding of numerics.
Tom Lane [Fri, 3 Jul 2015 21:04:39 +0000 (17:04 -0400)]
Add documentation and regression tests concerning rounding of numerics.

Michael Paquier, reviewed by Fabien Coelho

9 years agoAdd psql \ev and \sv commands for editing and showing view definitions.
Tom Lane [Fri, 3 Jul 2015 19:48:18 +0000 (15:48 -0400)]
Add psql \ev and \sv commands for editing and showing view definitions.

These are basically just like the \ef and \sf commands for functions.

Petr Korobeinikov, reviewed by Jeevan Chalke, some changes by me

9 years agoRemove thread-emulation support from pgbench.
Heikki Linnakangas [Fri, 3 Jul 2015 08:48:54 +0000 (11:48 +0300)]
Remove thread-emulation support from pgbench.

You can no longer use pgbench with multiple threads when compiled without
--enable-thread-safety. That's an acceptable limitation these days; it
still works fine with -j1, and all modern platforms support threads anyway.
This makes future maintenance and development of the code easier.

Fabien Coelho

9 years agoFix pgbench progress report behaviour when pgbench or a query gets stuck.
Heikki Linnakangas [Fri, 3 Jul 2015 08:04:57 +0000 (11:04 +0300)]
Fix pgbench progress report behaviour when pgbench or a query gets stuck.

There were two issues here. First, if a query got stuck so that it took
e.g. 5 seconds, and progress interval was 1 second, no progress reports were
printed until the query returned. Fix so that we wake up specifically to
print the progress report. Secondly, if pgbench got stuck so that it would
nevertheless not print a progress report on time, and enough time passes
that it's already time to print the next progress report, just skip the one
that was missed. Before this patch, it would print the missed one with 0 TPS
immediately after the previous one.

Fabien Coelho. Backpatch to 9.4, where progress reports were added.

9 years agoLift the limitation that # of clients must be a multiple of # of threads
Heikki Linnakangas [Fri, 3 Jul 2015 07:45:40 +0000 (10:45 +0300)]
Lift the limitation that # of clients must be a multiple of # of threads

Fabien Coelho

9 years agoMake WAL-related utilities handle .partial WAL files properly.
Fujii Masao [Fri, 3 Jul 2015 02:53:58 +0000 (11:53 +0900)]
Make WAL-related utilities handle .partial WAL files properly.

Commit de76884 changed an archive recovery so that the last WAL
segment with old timeline was renamed with suffix .partial. It should
have updated WAL-related utilities so that they can handle such
.paritial WAL files, but we forgot that.

This patch changes pg_archivecleanup so that it can clean up even
archived WAL files with .partial suffix. Also it allows us to specify
.partial WAL file name as the command-line argument "oldestkeptwalfile".

This patch also changes pg_resetxlog so that it can remove .partial
WAL files in pg_xlog directory.

pg_xlogdump cannot handle .partial WAL files. Per discussion,
we decided only to document that limitation instead of adding the fix.
Because a user can easily work around the limitation (i.e., just remove
.partial suffix from the file name) and the fix seems complicated for
very narrow use case.

Back-patch to 9.5 where the problem existed.

Review by Michael Paquier.
Discussion: http://www.postgresql.org/message-id/CAHGQGwGxMKnVHGgTfiig2Bt_2djec0in3-DLJmtg7+nEiidFdQ@mail.gmail.com

9 years agoImprove pg_restore's -t switch to match all types of relations.
Tom Lane [Thu, 2 Jul 2015 22:13:34 +0000 (18:13 -0400)]
Improve pg_restore's -t switch to match all types of relations.

-t will now match views, foreign tables, materialized views, and sequences,
not only plain tables.  This is more useful, and also more consistent with
the behavior of pg_dump's -t switch, which has always matched all relation
types.

We're still not there on matching pg_dump's behavior entirely, so mention
that in the docs.

Craig Ringer, reviewed by Pavel Stehule

9 years agoMake numeric form of PG version number readily available in Makefiles.
Tom Lane [Thu, 2 Jul 2015 21:24:36 +0000 (17:24 -0400)]
Make numeric form of PG version number readily available in Makefiles.

Expose PG_VERSION_NUM (e.g., "90600") as a Make variable; but for
consistency with the other Make variables holding similar info,
call the variable just VERSION_NUM not PG_VERSION_NUM.

There was some discussion of making this value available as a pg_config
value as well.  However, that would entail substantially more work than
this two-line patch.  Given that there was not exactly universal consensus
that we need this at all, let's just do a minimal amount of work for now.

Michael Paquier, reviewed by Pavel Stehule

9 years agoFix misuse of TextDatumGetCString().
Tom Lane [Thu, 2 Jul 2015 21:02:08 +0000 (17:02 -0400)]
Fix misuse of TextDatumGetCString().

"TextDatumGetCString(PG_GETARG_TEXT_P(x))" is formally wrong: a text*
is not a Datum.  Although this coding will accidentally fail to fail on
all known platforms, it risks leaking memory if a detoast step is needed,
unlike "TextDatumGetCString(PG_GETARG_DATUM(x))" which is what's used
elsewhere.  Make pg_get_object_address() fall in line with other uses.

Noted while reviewing two-arg current_setting() patch.

9 years agoAdd an optional missing_ok argument to SQL function current_setting().
Tom Lane [Thu, 2 Jul 2015 20:40:55 +0000 (16:40 -0400)]
Add an optional missing_ok argument to SQL function current_setting().

This allows convenient checking for existence of a GUC from SQL, which is
particularly useful when dealing with custom variables.

David Christensen, reviewed by Jeevan Chalke

9 years agoRemove obsolete heap_formtuple/modifytuple/deformtuple functions.
Heikki Linnakangas [Thu, 2 Jul 2015 18:18:04 +0000 (21:18 +0300)]
Remove obsolete heap_formtuple/modifytuple/deformtuple functions.

These variants used the old-style 'n'/' ' NULL indicators. The new-style
functions have been available since version 8.1. That should be long enough
that if there is still any old external code using these functions, they
can just switch to the new functions without worrying about backwards
compatibility

Peter Geoghegan

9 years agoRemove "const" from convertTSFunction()'s return type.
Heikki Linnakangas [Thu, 2 Jul 2015 18:10:26 +0000 (21:10 +0300)]
Remove "const" from convertTSFunction()'s return type.

There's no particular reason to mark it as such. The other convert*
functions have no const either.

9 years agoPlug some trivial memory leaks in pg_dump and pg_upgrade.
Heikki Linnakangas [Thu, 2 Jul 2015 17:58:51 +0000 (20:58 +0300)]
Plug some trivial memory leaks in pg_dump and pg_upgrade.

There's no point in trying to free every small allocation in these
programs that are used in a one-shot fashion, but these ones seems like
an improvement on readability grounds.

Michael Paquier, per Coverity report.

9 years agoWhitespace fix - replace tab with spaces in CREATE TABLE command.
Joe Conway [Thu, 2 Jul 2015 16:45:53 +0000 (09:45 -0700)]
Whitespace fix - replace tab with spaces in CREATE TABLE command.

9 years agoReplace obsolete autoconf macros with their modern replacements.
Heikki Linnakangas [Thu, 2 Jul 2015 16:21:23 +0000 (19:21 +0300)]
Replace obsolete autoconf macros with their modern replacements.

AC_TRY_COMPILE(...) -> AC_COMPILE_IFELSE([AC_LANG_PROGRAM(...)])
AC_TRY_LINK(...) -> AC_LINK_IFELSE([AC_LANG_PROGRAM(...)])
AC_TRY_RUN(...) -> AC_RUN_IFELSE([AC_LANG_PROGRAM(...)])
AC_LANG_SAVE/RESTORE -> AC_LANG_PUSH/POP
AC_DECL_SYS_SIGLIST -> AC_CHECK_DECLS(...) (per snippet in autoconf manual)

Also use AC_LANG_SOURCE instead of AC_LANG_PROGRAM, where the main()
function is not needed.

With these changes, autoconf -Wall doesn't complain anymore.

Andreas Karlsson

9 years agoDon't emit a spurious space at end of line in pg_dump of event triggers.
Heikki Linnakangas [Thu, 2 Jul 2015 09:50:29 +0000 (12:50 +0300)]
Don't emit a spurious space at end of line in pg_dump of event triggers.

Backpatch to 9.3 and above, where event triggers were added.

9 years agoUse appendStringInfoString/Char et al where appropriate.
Heikki Linnakangas [Thu, 2 Jul 2015 09:32:48 +0000 (12:32 +0300)]
Use appendStringInfoString/Char et al where appropriate.

Patch by David Rowley. Backpatch to 9.5, as some of the calls were new in
9.5, and keeping the code in sync with master makes future backpatching
easier.

9 years agoFix name of argument to pg_stat_file.
Heikki Linnakangas [Thu, 2 Jul 2015 09:12:05 +0000 (12:12 +0300)]
Fix name of argument to pg_stat_file.

It's called "missing_ok" in the docs and in the C code.

I refrained from doing a catversion bump for this, because the name of an
input argument is just documentation, it has no effect on any callers.

Michael Paquier

9 years agoUse American spelling for "behavior".
Heikki Linnakangas [Thu, 2 Jul 2015 09:11:32 +0000 (12:11 +0300)]
Use American spelling for "behavior".

For consistency with the rest of the docs.

Michael Paquier

9 years agoAllow MSVC's contribcheck and modulescheck to run independently.
Andrew Dunstan [Thu, 2 Jul 2015 03:28:41 +0000 (23:28 -0400)]
Allow MSVC's contribcheck and modulescheck to run independently.

These require a temp install to have been done, so we now make sure it
is done before proceeding.

Michael Paquier.

9 years agoMake use of xlog_internal.h's macros in WAL-related utilities.
Fujii Masao [Thu, 2 Jul 2015 01:35:38 +0000 (10:35 +0900)]
Make use of xlog_internal.h's macros in WAL-related utilities.

Commit 179cdd09 added macros to check if a filename is a WAL segment
or other such file. However there were still some instances of the
strlen + strspn combination to check for that in WAL-related utilities
like pg_archivecleanup. Those checks can be replaced with the macros.

This patch makes use of the macros in those utilities and
which would make the code a bit easier to read.

Back-patch to 9.5.

Michael Paquier

9 years agoDon't leave pg_hba and pg_ident data lying around in running backends.
Tom Lane [Wed, 1 Jul 2015 22:55:39 +0000 (18:55 -0400)]
Don't leave pg_hba and pg_ident data lying around in running backends.

Free the contexts holding this data after we're done using it, by the
expedient of attaching them to the PostmasterContext which we were
already taking care to delete (and where, indeed, this data used to live
before commits e5e2fc842c418432 and 7c45e3a3c682f855).  This saves a
probably-usually-negligible amount of space per running backend.  It also
avoids leaving potentially-security-sensitive data lying around in memory
in processes that don't need it.  You'd have to be unusually paranoid to
think that that amounts to a live security bug, so I've not gone so far as
to forcibly zero the memory; but there surely isn't a good reason to keep
this data around.

Arguably this is a memory management bug in the aforementioned commits,
but it doesn't seem important enough to back-patch.

9 years agoMake sampler_random_fract() actually obey its API contract.
Tom Lane [Wed, 1 Jul 2015 22:07:48 +0000 (18:07 -0400)]
Make sampler_random_fract() actually obey its API contract.

This function is documented to return a value in the range (0,1),
which is what its predecessor anl_random_fract() did.  However, the
new version depends on pg_erand48() which returns a value in [0,1).
The possibility of returning zero creates hazards of division by zero
or trying to compute log(0) at some call sites, and it might well
break third-party modules using anl_random_fract() too.  So let's
change it to never return zero.  Spotted by Coverity.

Michael Paquier, cosmetically adjusted by me

9 years agoMake XLogFileCopy() look the same as in 9.4.
Fujii Masao [Wed, 1 Jul 2015 01:54:47 +0000 (10:54 +0900)]
Make XLogFileCopy() look the same as in 9.4.

XLogFileCopy() was changed heavily in commit de76884. However it was
partially reverted in commit 7abc685 and most of those changes to
XLogFileCopy() were no longer needed. Then commit 7cbee7c removed
those unnecessary code, but XLogFileCopy() looked different in master
and 9.4 though the contents are almost the same.

This patch makes XLogFileCopy() look the same in master and back-branches,
which makes back-patching easier, per discussion on pgsql-hackers.
Back-patch to 9.5.

Discussion: 55760844.7090703@iki.fi

Michael Paquier

9 years agoFix broken link in documentation.
Tom Lane [Tue, 30 Jun 2015 22:47:32 +0000 (18:47 -0400)]
Fix broken link in documentation.

HP's web server has apparently become case-sensitive sometime recently.
Per bug #13479 from Daniel Abraham.  Corrected link identified by Alvaro.

9 years agoFix typo and omission in my earlier 9.5 release notes commit.
Andres Freund [Tue, 30 Jun 2015 19:09:51 +0000 (21:09 +0200)]
Fix typo and omission in my earlier 9.5 release notes commit.

9 years agoImprove 9.5 release notes.
Andres Freund [Tue, 30 Jun 2015 19:00:12 +0000 (21:00 +0200)]
Improve 9.5 release notes.

1) Add sgml comments referencing commits. This is useful to search for
   missing items etc.

   The comments containing the commit notes are an excerpt from:
   git log --date=short \
       --pretty='format:%cd [%h] %<(8,trunc)%cN: %<(48,trunc)%s%n%n%w(,4,4)%b%n' \
       $(git merge-base origin/master upstream/REL9_4_STABLE)..origin/master
2) Improve a handful of existing notes
3) Add missing entries about a couple features.
4) Add a bunch of straight-forward FIXMEs

9 years agoStamp shared-library minor version numbers for 9.6.
Tom Lane [Tue, 30 Jun 2015 18:06:04 +0000 (14:06 -0400)]
Stamp shared-library minor version numbers for 9.6.

9 years agoStamp HEAD as 9.6devel.
Tom Lane [Tue, 30 Jun 2015 18:01:15 +0000 (14:01 -0400)]
Stamp HEAD as 9.6devel.

Let the hacking begin ...