]> granicus.if.org Git - postgresql/log
postgresql
6 years agos/NULL byte/NUL byte/ in comment refering to C string terminator.
Andres Freund [Tue, 19 Sep 2017 23:39:18 +0000 (16:39 -0700)]
s/NULL byte/NUL byte/ in comment refering to C string terminator.

Reported-By: Robert Haas
Discussion: https://postgr.es/m/CA+Tgmoa+YBvWgFST2NVoeXjVSohEpK=vqnVCsoCkhTVVxfLcVQ@mail.gmail.com

6 years agoAdd basic TAP test setup for pg_upgrade
Peter Eisentraut [Tue, 19 Sep 2017 22:29:12 +0000 (18:29 -0400)]
Add basic TAP test setup for pg_upgrade

The plan is to convert the current pg_upgrade test to the TAP
framework.  This commit just puts a basic TAP test in place so that we
can see how the build farm behaves, since the build farm client has some
special knowledge of the pg_upgrade tests.

Author: Michael Paquier <michael.paquier@gmail.com>

6 years agoAvoid use of non-portable strnlen() in pgstat_clip_activity().
Andres Freund [Tue, 19 Sep 2017 21:17:20 +0000 (14:17 -0700)]
Avoid use of non-portable strnlen() in pgstat_clip_activity().

The use of strnlen rather than strlen was just paranoia. Instead of
giving up on the paranoia, just implement the safeguard
differently. And add a comment explaining why we're careful.

Author: Andres Freund
Discussion: https://postgr.es/m/E1duOkJ-0001Mc-U5@gemulon.postgresql.org

6 years agoSpeedup pgstat_report_activity by moving mb-aware truncation to read side.
Andres Freund [Tue, 19 Sep 2017 18:46:07 +0000 (11:46 -0700)]
Speedup pgstat_report_activity by moving mb-aware truncation to read side.

Previously multi-byte aware truncation was done on every
pgstat_report_activity() call - proving to be a bottleneck for
workloads with long query strings that execute quickly.

Instead move the truncation to the read side, which commonly is
executed far less frequently. That's possible because all server
encodings allow to determine the length of a multi-byte string from
the first byte.

Rename PgBackendStatus.st_activity to st_activity_raw so existing
extension users of the field break - their code has to be adjusted to
use pgstat_clip_activity().

Author: Andres Freund
Tested-By: Khuntal Ghosh
Reviewed-By: Robert Haas, Tom Lane
Discussion: https://postgr.es/m/20170912071948.pa7igbpkkkviecpz@alap3.anarazel.de

6 years agoDisable multi-byte citext tests
Andrew Dunstan [Tue, 19 Sep 2017 19:31:37 +0000 (15:31 -0400)]
Disable multi-byte citext tests

This reverts commit 890faaf1 which attempted unsuccessfully to deal with
the problem, and instead just comments out these tests like other similar
tests elsewhere in the script.

6 years agoCache datatype-output-function lookup info across calls of concat().
Tom Lane [Tue, 19 Sep 2017 19:09:34 +0000 (15:09 -0400)]
Cache datatype-output-function lookup info across calls of concat().

Testing indicates this can save a third to a half of the runtime
of the function.

Pavel Stehule, reviewed by Alexander Kuzmenkov

Discussion: https://postgr.es/m/CAFj8pRAT62pRgjoHbgTfJUc2uLmeQ4saUj+yVJAEZUiMwNCmdg@mail.gmail.com

6 years agoSet client encoding to UTF8 for the citext regression script
Andrew Dunstan [Tue, 19 Sep 2017 18:51:51 +0000 (14:51 -0400)]
Set client encoding to UTF8 for the citext regression script

Problem introduced with non-ascii characters in commit f2464997644c
and discovered on various buildfarm animals.

6 years agoMake new crash restart test a bit more robust.
Andres Freund [Tue, 19 Sep 2017 17:32:51 +0000 (10:32 -0700)]
Make new crash restart test a bit more robust.

Add timeouts in case psql doesn't deliver the expected output, and try
to cause the monitoring psql to be fully connected to a backend.  This
isn't necessarily everything needed, but at least the timeouts should
reduce the pain for buildfarm owners.

Author: Andres Freund
Reported-By: Tom Lane, BF animals prairiedog and calliphoridae
Discussion: https://postgr.es/m/E1du6ZT-00043I-91@gemulon.postgresql.org

6 years agodoc: add example of % substitution for connection URIs
Bruce Momjian [Tue, 19 Sep 2017 16:23:18 +0000 (12:23 -0400)]
doc:  add example of % substitution for connection URIs

Reported-by: Zhou Digoal
Discussion: https://postgr.es/m/20170912133722.25637.91@wrigleys.postgresql.org

Backpatch-through: 10

6 years agoAdd citext_pattern_ops for citext contrib module
Andrew Dunstan [Tue, 19 Sep 2017 12:31:45 +0000 (08:31 -0400)]
Add citext_pattern_ops for citext contrib module

This is similar to text_pattern_ops.

Alexey Chernyshov, reviewed by Jacob Champion.

6 years agoRearm statement_timeout after each executed query.
Andres Freund [Tue, 19 Sep 2017 02:36:44 +0000 (19:36 -0700)]
Rearm statement_timeout after each executed query.

Previously statement_timeout, in the extended protocol, affected all
messages till a Sync message.  For clients that pipeline/batch query
execution that's problematic.

Instead disable timeout after each Execute message, and enable, if
necessary, the timer in start_xact_command(). As that's done only for
Execute and not Parse / Bind, pipelining the latter two could still
cause undesirable timeouts. But a survey of protocol implementations
shows that all drivers issue Sync messages when preparing, and adding
timeout rearming to both is fairly expensive for the common parse /
bind / execute sequence.

Author: Tatsuo Ishii, editorialized by Andres Freund
Reviewed-By: Takayuki Tsunakawa, Andres Freund
Discussion: https://postgr.es/m/20170222.115044.1665674502985097185.t-ishii@sraoss.co.jp

6 years agoFix uninitialized variable in dshash.c.
Andres Freund [Tue, 19 Sep 2017 00:43:37 +0000 (17:43 -0700)]
Fix uninitialized variable in dshash.c.

A bugfix for commit 8c0d7bafad36434cb08ac2c78e69ae72c194ca20.  The code
would have crashed if hashtable->size_log2 ever had the same value as
hashtable->control->size_log2 by coincidence.

Per Valgrind.

Author: Thomas Munro
Reported-By: Tomas Vondra
Discussion: https://postgr.es/m/e72fb33c-4f31-f276-e972-263d9b59554d%402ndquadrant.com

6 years agoAdd test for postmaster crash restarts.
Andres Freund [Mon, 18 Sep 2017 06:05:58 +0000 (23:05 -0700)]
Add test for postmaster crash restarts.

Given that I managed to break this...  We probably should extend the
tests to also cover other sub-processes dying, but that's something
for later.

Author: Andres Freund
Discussion: https://postgr.es/m/20170917080752.rcmihzfmgbeuqjk2@alap3.anarazel.de

6 years agoFix crash restart bug introduced in 8356753c212.
Andres Freund [Sun, 17 Sep 2017 08:00:39 +0000 (01:00 -0700)]
Fix crash restart bug introduced in 8356753c212.

The bug was caused by not re-reading the control file during crash
recovery restarts, which lead to an attempt to pfree() shared memory
contents. The fix is to re-read the control file, which seems good
anyway.

It's unclear as of this moment, whether we want to keep the
refactoring introduced in the commit referenced above, or come up with
an alternative approach. But fixing the bug in the mean time seems
like a good idea regardless.

A followup commit will introduce regression test coverage for crash
restarts.

Reported-By: Tom Lane
Discussion: https://postgr.es/m/14134.1505572349@sss.pgh.pa.us

6 years agoMinor code-cleanliness improvements for btree.
Tom Lane [Mon, 18 Sep 2017 20:36:28 +0000 (16:36 -0400)]
Minor code-cleanliness improvements for btree.

Make the btree page-flags test macros (P_ISLEAF and friends) return clean
boolean values, rather than values that might not fit in a bool.  Use them
in a few places that were randomly referencing the flag bits directly.

In passing, change access/nbtree/'s only direct use of BUFFER_LOCK_SHARE to
BT_READ.  (Some think we should go the other way, but as long as we have
BT_READ/BT_WRITE, let's use them consistently.)

Masahiko Sawada, reviewed by Doug Doole

Discussion: https://postgr.es/m/CAD21AoBmWPeN=WBB5Jvyz_Nt3rmW1ebUyAnk3ZbJP3RMXALJog@mail.gmail.com

6 years agoMake ExplainOpenGroup and ExplainCloseGroup public.
Tom Lane [Mon, 18 Sep 2017 20:01:16 +0000 (16:01 -0400)]
Make ExplainOpenGroup and ExplainCloseGroup public.

Extensions with custom plan nodes might like to use these in their
EXPLAIN output.

Hadi Moshayedi

Discussion: https://postgr.es/m/CA+_kT_dU-rHCN0u6pjA6bN5CZniMfD=-wVqPY4QLrKUY_uJq5w@mail.gmail.com

6 years agoMake DatumGetFoo/PG_GETARG_FOO/PG_RETURN_FOO macro names more consistent.
Tom Lane [Mon, 18 Sep 2017 19:21:23 +0000 (15:21 -0400)]
Make DatumGetFoo/PG_GETARG_FOO/PG_RETURN_FOO macro names more consistent.

By project convention, these names should include "P" when dealing with a
pointer type; that is, if the result of a GETARG macro is of type FOO *,
it should be called PG_GETARG_FOO_P not just PG_GETARG_FOO.  Some newer
types such as JSONB and ranges had not followed the convention, and a
number of contrib modules hadn't gotten that memo either.  Rename the
offending macros to improve consistency.

In passing, fix a few places that thought PG_DETOAST_DATUM() returns
a Datum; it does not, it returns "struct varlena *".  Applying
DatumGetPointer to that happens not to cause any bad effects today,
but it's formally wrong.  Also, adjust an ltree macro that was designed
without any thought for what pgindent would do with it.

This is all cosmetic and shouldn't have any impact on generated code.

Mark Dilger, some further tweaks by me

Discussion: https://postgr.es/m/EA5676F4-766F-4F38-8348-ECC7DB427C6A@gmail.com

6 years agoFix, or at least ameliorate, bugs in logicalrep_worker_launch().
Tom Lane [Mon, 18 Sep 2017 15:39:44 +0000 (11:39 -0400)]
Fix, or at least ameliorate, bugs in logicalrep_worker_launch().

If we failed to get a background worker slot, the code just walked
away from the logicalrep-worker slot it already had, leaving that
looking like the worker is still starting up.  This led to an indefinite
hang in subscription startup, as reported by Thomas Munro.  We must
release the slot on failure.

Also fix a thinko: we must capture the worker slot's generation before
releasing LogicalRepWorkerLock the first time, else testing to see if
it's changed is pretty meaningless.

BTW, the CHECK_FOR_INTERRUPTS() in WaitForReplicationWorkerAttach is a
ticking time bomb, even without considering the possibility of elog(ERROR)
in one of the other functions it calls.  Really, this entire business needs
a redesign with some actual thought about error recovery.  But for now
I'm just band-aiding the case observed in testing.

Back-patch to v10 where this code was added.

Discussion: https://postgr.es/m/CAEepm=2bP3TBMFBArP6o20AZaRduWjMnjCjt22hSdnA-EvrtCw@mail.gmail.com

6 years agoUpdate some dead external links in the documentation
Peter Eisentraut [Mon, 18 Sep 2017 15:09:15 +0000 (11:09 -0400)]
Update some dead external links in the documentation

6 years agoRemove dead external links from documentation
Peter Eisentraut [Mon, 18 Sep 2017 14:41:48 +0000 (10:41 -0400)]
Remove dead external links from documentation

6 years agoFix DROP SUBSCRIPTION hang
Peter Eisentraut [Mon, 18 Sep 2017 01:37:02 +0000 (21:37 -0400)]
Fix DROP SUBSCRIPTION hang

When ALTER SUBSCRIPTION DISABLE is run in the same transaction before
DROP SUBSCRIPTION, the latter will hang because workers will still be
running, not having seen the DISABLE committed, and DROP SUBSCRIPTION
will wait until the workers have vacated the replication origin slots.

Previously, DROP SUBSCRIPTION killed the logical replication workers
immediately only if it was going to drop the replication slot, otherwise
it scheduled the worker killing for the end of the transaction, as a
result of 7e174fa793a2df89fe03d002a5087ef67abcdde8.  This, however,
causes the present problem.  To fix, kill the workers immediately in all
cases.  This covers all cases: A subscription that doesn't have a
replication slot must be disabled.  It was either disabled in the same
transaction, or it was already disabled before the current transaction,
but then there shouldn't be any workers left and this won't make a
difference.

Reported-by: Arseny Sher <a.sher@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/87mv6av84w.fsf%40ars-thinkpad

6 years agoDoc: update v10 release notes through today.
Tom Lane [Sun, 17 Sep 2017 21:04:21 +0000 (17:04 -0400)]
Doc: update v10 release notes through today.

Add item about number of times statement-level triggers will be fired.
Rearrange the compatibility items into (what seems to me) a less
random ordering.

6 years agoAllow rel_is_distinct_for() to look through RelabelType below OpExpr.
Tom Lane [Sun, 17 Sep 2017 19:28:51 +0000 (15:28 -0400)]
Allow rel_is_distinct_for() to look through RelabelType below OpExpr.

This lets it do the right thing for, eg, varchar columns.
Back-patch to 9.5 where this logic appeared.

David Rowley, per report from Kim Rose Carlsen

Discussion: https://postgr.es/m/VI1PR05MB17091F9A9876528055D6A827C76D0@VI1PR05MB1709.eurprd05.prod.outlook.com

6 years agoFix possible dangling pointer dereference in trigger.c.
Tom Lane [Sun, 17 Sep 2017 18:50:01 +0000 (14:50 -0400)]
Fix possible dangling pointer dereference in trigger.c.

AfterTriggerEndQuery correctly notes that the query_stack could get
repalloc'd during a trigger firing, but it nonetheless passes the address
of a query_stack entry to afterTriggerInvokeEvents, so that if such a
repalloc occurs, afterTriggerInvokeEvents is already working with an
obsolete dangling pointer while it scans the rest of the events.  Oops.
The only code at risk is its "delete_ok" cleanup code, so we can
prevent unsafe behavior by passing delete_ok = false instead of true.

However, that could have a significant performance penalty, because the
point of passing delete_ok = true is to not have to re-scan possibly
a large number of dead trigger events on the next time through the loop.
There's more than one way to skin that cat, though.  What we can do is
delete all the "chunks" in the event list except the last one, since
we know all events in them must be dead.  Deleting the chunks is work
we'd have had to do later in AfterTriggerEndQuery anyway, and it ends
up saving rescanning of just about the same events we'd have gotten
rid of with delete_ok = true.

In v10 and HEAD, we also have to be careful to mop up any per-table
after_trig_events pointers that would become dangling.  This is slightly
annoying, but I don't think that normal use-cases will traverse this code
path often enough for it to be a performance problem.

It's pretty hard to hit this in practice because of the unlikelihood
of the query_stack getting resized at just the wrong time.  Nonetheless,
it's definitely a live bug of ancient standing, so back-patch to all
supported branches.

Discussion: https://postgr.es/m/2891.1505419542@sss.pgh.pa.us

6 years agoEnsure that BEFORE STATEMENT triggers fire the right number of times.
Tom Lane [Sun, 17 Sep 2017 16:16:38 +0000 (12:16 -0400)]
Ensure that BEFORE STATEMENT triggers fire the right number of times.

Commit 0f79440fb introduced mechanism to keep AFTER STATEMENT triggers
from firing more than once per statement, which was formerly possible
if more than one FK enforcement action had to be applied to a given
table.  Add a similar mechanism for BEFORE STATEMENT triggers, so that
we don't have the unexpected situation of firing BEFORE STATEMENT
triggers more often than AFTER STATEMENT.

As with the previous patch, back-patch to v10.

Discussion: https://postgr.es/m/22315.1505584992@sss.pgh.pa.us

6 years agoFix bogus size calculation introduced by commit cc5f81366.
Tom Lane [Sun, 17 Sep 2017 15:35:27 +0000 (11:35 -0400)]
Fix bogus size calculation introduced by commit cc5f81366.

The elements of RecordCacheArray are TupleDesc, not TupleDesc *.
Those are actually the same size, so that this error is harmless,
but it's still wrong --- and it might bite us someday, if TupleDesc
ever became a struct, say.

Per Coverity.

6 years agoDoc: add example of transition table use in a trigger.
Tom Lane [Sat, 16 Sep 2017 19:31:26 +0000 (15:31 -0400)]
Doc: add example of transition table use in a trigger.

I noticed that there were exactly no complete examples of use of
a transition table in a trigger function, and no clear description
of just how you'd do it either.  Improve that.

6 years agoFix SQL-spec incompatibilities in new transition table feature.
Tom Lane [Sat, 16 Sep 2017 17:20:32 +0000 (13:20 -0400)]
Fix SQL-spec incompatibilities in new transition table feature.

The standard says that all changes of the same kind (insert, update, or
delete) caused in one table by a single SQL statement should be reported
in a single transition table; and by that, they mean to include foreign key
enforcement actions cascading from the statement's direct effects.  It's
also reasonable to conclude that if the standard had wCTEs, they would say
that effects of wCTEs applying to the same table as each other or the outer
statement should be merged into one transition table.  We weren't doing it
like that.

Hence, arrange to merge tuples from multiple update actions into a single
transition table as much as we can.  There is a problem, which is that if
the firing of FK enforcement triggers and after-row triggers with
transition tables is interspersed, we might need to report more tuples
after some triggers have already seen the transition table.  It seems like
a bad idea for the transition table to be mutable between trigger calls.
There's no good way around this without a major redesign of the FK logic,
so for now, resolve it by opening a new transition table each time this
happens.

Also, ensure that AFTER STATEMENT triggers fire just once per statement,
or once per transition table when we're forced to make more than one.
Previous versions of Postgres have allowed each FK enforcement query
to cause an additional firing of the AFTER STATEMENT triggers for the
referencing table, but that's certainly not per spec.  (We're still
doing multiple firings of BEFORE STATEMENT triggers, though; is that
something worth changing?)

Also, forbid using transition tables with column-specific UPDATE triggers.
The spec requires such transition tables to show only the tuples for which
the UPDATE trigger would have fired, which means maintaining multiple
transition tables or else somehow filtering the contents at readout.
Maybe someday we'll bother to support that option, but it looks like a
lot of trouble for a marginal feature.

The transition tables are now managed by the AfterTriggers data structures,
rather than being directly the responsibility of ModifyTable nodes.  This
removes a subtransaction-lifespan memory leak introduced by my previous
band-aid patch 3c4359521.

In passing, refactor the AfterTriggers data structures to reduce the
management overhead for them, by using arrays of structs rather than
several parallel arrays for per-query-level and per-subtransaction state.

I failed to resist the temptation to do some copy-editing on the SGML
docs about triggers, above and beyond merely documenting the effects
of this patch.

Back-patch to v10, because we don't want the semantics of transition
tables to change post-release.

Patch by me, with help and review from Thomas Munro.

Discussion: https://postgr.es/m/20170909064853.25630.12825@wrigleys.postgresql.org

6 years agodocs: clarify pg_upgrade docs regarding standbys and rsync
Bruce Momjian [Sat, 16 Sep 2017 15:58:00 +0000 (11:58 -0400)]
docs:  clarify pg_upgrade docs regarding standbys and rsync

Document that rsync is an _optional_ way to upgrade standbys, suggest
rsync option --dry-run, and mention a way of upgrading one standby from
another using rsync.  Also clarify some instructions by specifying if
they operate on the old or new clusters.

Reported-by: Stephen Frost, Magnus Hagander
Discussion: https://postgr.es/m/20170914191250.GB6595@momjian.us

Backpatch-through: 9.5

6 years agoAfter a MINVALUE/MAXVALUE bound, allow only more of the same.
Robert Haas [Sat, 16 Sep 2017 01:15:55 +0000 (21:15 -0400)]
After a MINVALUE/MAXVALUE bound, allow only more of the same.

In the old syntax, which used UNBOUNDED, we had a similar restriction,
but commit d363d42bb9a4399a0207bd3b371c966e22e06bd3, which changed the
syntax, eliminated it.  Put it back.

Patch by me, reviewed by Dean Rasheed.

Discussion: http://postgr.es/m/CA+Tgmobs+pLPC27tS3gOpEAxAffHrq5w509cvkwTf9pF6cWYbg@mail.gmail.com

6 years agosrc/test/ldap: Fix test function in Linux port
Alvaro Herrera [Fri, 15 Sep 2017 22:39:37 +0000 (00:39 +0200)]
src/test/ldap: Fix test function in Linux port

6 years agoApply pg_get_serial_sequence() to identity column sequences as well
Peter Eisentraut [Fri, 15 Sep 2017 18:04:51 +0000 (14:04 -0400)]
Apply pg_get_serial_sequence() to identity column sequences as well

Bug: #14813

6 years agoAdd LDAP authentication test suite
Peter Eisentraut [Fri, 15 Sep 2017 15:41:15 +0000 (11:41 -0400)]
Add LDAP authentication test suite

Like the SSL test suite, this will not be run by default.

Reviewed-by: Thomas Munro <thomas.munro@enterprisedb.com>
6 years agoGet rid of shared_record_typmod_registry_worker_detach; it doesn't work.
Tom Lane [Fri, 15 Sep 2017 14:52:30 +0000 (10:52 -0400)]
Get rid of shared_record_typmod_registry_worker_detach; it doesn't work.

This code is unsafe, as proven by buildfarm failures, because it tries
to access shared memory that might already be gone.  It's also unnecessary,
because we're about to exit the process anyway and so the record type cache
should never be accessed again.  The idea was to lay some foundations for
someday recycling workers --- which would require attaching to a different
shared tupdesc registry --- but that will require considerably more
thought.  In the meantime let's save some bytes by just removing the
nonfunctional code.

Problem identification, and proposal to fix by removing functionality
from the detach function, by Thomas Munro.  I went a bit further by
removing the function altogether.

Discussion: https://postgr.es/m/E1dsguX-00056N-9x@gemulon.postgresql.org

6 years agoTest coverage for CREATE/ALTER FOREIGN DATA WRAPPER .. HANDLER.
Robert Haas [Fri, 15 Sep 2017 12:07:22 +0000 (08:07 -0400)]
Test coverage for CREATE/ALTER FOREIGN DATA WRAPPER .. HANDLER.

Amit Langote, per a suggestion from Mark Dilger.  Reviewed by
Marc Dilger and Ashutosh Bapat.

Discussion: http://postgr.es/m/CAFjFpReL0oeN7SCpnsEPbqJhB2Bp1wnH1uvbOF_w6KEuv6ZXvg@mail.gmail.com

6 years agoDon't use anonymous unions.
Tom Lane [Fri, 15 Sep 2017 04:57:38 +0000 (00:57 -0400)]
Don't use anonymous unions.

Commit cc5f81366c36b3dd8f02bd9be1cf75b2cc8482bd introduced a language
feature that is not acceptable to strict C89 compilers.

Thomas Munro

Per buildfarm.

6 years agoAvoid duplicate typedef for SharedRecordTypmodRegistry.
Tom Lane [Fri, 15 Sep 2017 04:25:33 +0000 (00:25 -0400)]
Avoid duplicate typedef for SharedRecordTypmodRegistry.

This isn't our usual solution for such problems, and older compilers
(not terribly old, either) don't like it.

Per buildfarm and local testing.

6 years agoRemove TupleDesc remapping logic from tqueue.c.
Andres Freund [Fri, 15 Sep 2017 02:59:02 +0000 (19:59 -0700)]
Remove TupleDesc remapping logic from tqueue.c.

With the introduction of a shared memory record typmod registry, it is no
longer necessary to remap record typmods when sending tuples between backends
so most of tqueue.c can be removed.

Author: Thomas Munro
Reviewed-By: Andres Freund
Discussion: https://postgr.es/m/CAEepm=0ZtQ-SpsgCyzzYpsXS6e=kZWqk3g5Ygn3MDV7A8dabUA@mail.gmail.com

6 years agoAdd support for coordinating record typmods among parallel workers.
Andres Freund [Fri, 15 Sep 2017 02:59:21 +0000 (19:59 -0700)]
Add support for coordinating record typmods among parallel workers.

Tuples can have type RECORDOID and a typmod number that identifies a blessed
TupleDesc in a backend-private cache.  To support the sharing of such tuples
through shared memory and temporary files, provide a typmod registry in
shared memory.

To achieve that, introduce per-session DSM segments, created on demand when a
backend first runs a parallel query.  The per-session DSM segment has a
table-of-contents just like the per-query DSM segment, and initially the
contents are a shared record typmod registry and a DSA area to provide the
space it needs to grow.

State relating to the current session is accessed via a Session object
reached through global variable CurrentSession that may require significant
redesign further down the road as we figure out what else needs to be shared
or remodelled.

Author: Thomas Munro
Reviewed-By: Andres Freund
Discussion: https://postgr.es/m/CAEepm=0ZtQ-SpsgCyzzYpsXS6e=kZWqk3g5Ygn3MDV7A8dabUA@mail.gmail.com

6 years agoisn: Fix debug code
Peter Eisentraut [Sat, 12 Aug 2017 01:04:04 +0000 (21:04 -0400)]
isn: Fix debug code

The ISN_DEBUG code did not compile.  Fix that code, don't hide it behind
an #ifdef, make it run when building with asserts, and make it error out
instead of just logging if it fails.

Reviewed-by: David Steele <david@pgmasters.net>
6 years agopg_archivecleanup: Add test suite
Peter Eisentraut [Sat, 12 Aug 2017 01:04:04 +0000 (21:04 -0400)]
pg_archivecleanup: Add test suite

Reviewed-by: David Steele <david@pgmasters.net>
6 years agopasswordcheck: Add test suite
Peter Eisentraut [Sat, 12 Aug 2017 01:04:04 +0000 (21:04 -0400)]
passwordcheck: Add test suite

Also improve one error message.

Reviewed-by: David Steele <david@pgmasters.net>
6 years agochkpass: Add test suite
Peter Eisentraut [Sat, 12 Aug 2017 01:04:04 +0000 (21:04 -0400)]
chkpass: Add test suite

Reviewed-by: David Steele <david@pgmasters.net>
6 years agolo: Add test suite
Peter Eisentraut [Sat, 12 Aug 2017 01:04:04 +0000 (21:04 -0400)]
lo: Add test suite

Reviewed-by: David Steele <david@pgmasters.net>
6 years agofuzzystrmatch: Add test suite
Peter Eisentraut [Sat, 12 Aug 2017 01:04:04 +0000 (21:04 -0400)]
fuzzystrmatch: Add test suite

Reviewed-by: David Steele <david@pgmasters.net>
6 years agoadminpack: Add test suite
Peter Eisentraut [Sat, 12 Aug 2017 01:04:04 +0000 (21:04 -0400)]
adminpack: Add test suite

Reviewed-by: David Steele <david@pgmasters.net>
6 years agoAdd missing tags to GetCommandLogLevel.
Robert Haas [Thu, 14 Sep 2017 20:25:19 +0000 (16:25 -0400)]
Add missing tags to GetCommandLogLevel.

Otherwise, log_statement = 'ddl' causes errors if those statement
types are used.

Michael Paquier, reviewed by Ashutosh Sharma

Discussion: http://postgr.es/m/CAB7nPqStC3HkE76Q1MnHsVd1vF1Td9zXApzYadzDMyLMRkkGrw@mail.gmail.com

6 years agoPerform only one ReadControlFile() during startup.
Andres Freund [Wed, 13 Sep 2017 09:12:17 +0000 (02:12 -0700)]
Perform only one ReadControlFile() during startup.

Previously we read the control file in multiple places. But soon the
segment size will be configurable and stored in the control file, and
that needs to be available earlier than it currently is needed.

Instead of adding yet another place where it's read, refactor things
so there's a single processing of the control file during startup (in
EXEC_BACKEND that's every individual backend's startup).

Author: Andres Freund
Discussion: http://postgr.es/m/20170913092828.aozd3gvvmw67gmyc@alap3.anarazel.de

6 years agoExpand partitioned table RTEs level by level, without flattening.
Robert Haas [Thu, 14 Sep 2017 19:41:08 +0000 (15:41 -0400)]
Expand partitioned table RTEs level by level, without flattening.

Flattening the partitioning hierarchy at this stage makes various
desirable optimizations difficult.  The original use case for this
patch was partition-wise join, which wants to match up the partitions
in one partitioning hierarchy with those in another such hierarchy.
However, it now seems that it will also be useful in making partition
pruning work using the PartitionDesc rather than constraint exclusion,
because with a flattened expansion, we have no easy way to figure out
which PartitionDescs apply to which leaf tables in a multi-level
partition hierarchy.

As it turns out, we end up creating both rte->inh and !rte->inh RTEs
for each intermediate partitioned table, just as we previously did for
the root table.  This seems unnecessary since the partitioned tables
have no storage and are not scanned.  We might want to go back and
rejigger things so that no partitioned tables (including the parent)
need !rte->inh RTEs, but that seems to require some adjustments not
related to the core purpose of this patch.

Ashutosh Bapat, reviewed by me and by Amit Langote.  Some final
adjustments by me.

Discussion: http://postgr.es/m/CAFjFpRd=1venqLL7oGU=C1dEkuvk2DJgvF+7uKbnPHaum1mvHQ@mail.gmail.com

6 years agoAvoid use of bool in thread_test.c
Peter Eisentraut [Wed, 16 Aug 2017 04:22:32 +0000 (00:22 -0400)]
Avoid use of bool in thread_test.c

It's not necessary for such a small program, and it causes unnecessary
extra work to get the correct definition of bool, more so if we are
going to introduce stdbool.h later.

Reviewed-by: Thomas Munro <thomas.munro@enterprisedb.com>
6 years agoMake RelationGetPartitionDispatchInfo expand depth-first.
Robert Haas [Thu, 14 Sep 2017 16:28:50 +0000 (12:28 -0400)]
Make RelationGetPartitionDispatchInfo expand depth-first.

With this change, the order of leaf partitions as returned by
RelationGetPartitionDispatchInfo should now be the same as the
order used by expand_inherited_rtentry.  This will make it simpler
for future patches to match up the partition dispatch information
with the planner data structures.  The new code is also, in my
opinion anyway, simpler and easier to understand.

Amit Langote, reviewed by Amit Khandekar.  I also reviewed and
made a few cosmetic revisions.

Discussion: http://postgr.es/m/d98d4761-5071-1762-501e-0e15047c714b@lab.ntt.co.jp

6 years agoRemove BoolPtr type
Peter Eisentraut [Wed, 16 Aug 2017 04:22:32 +0000 (00:22 -0400)]
Remove BoolPtr type

Not used and doesn't seem useful.

Reviewed-by: Thomas Munro <thomas.munro@enterprisedb.com>
6 years agoFix bool/int type confusion
Peter Eisentraut [Wed, 16 Aug 2017 04:22:32 +0000 (00:22 -0400)]
Fix bool/int type confusion

Using ++ on a bool variable doesn't work well when stdbool.h is in use.
The original BSD code appears to use int here, so use that instead.

Reviewed-by: Thomas Munro <thomas.munro@enterprisedb.com>
6 years agoFix inconsistent capitalization.
Robert Haas [Thu, 14 Sep 2017 15:11:12 +0000 (11:11 -0400)]
Fix inconsistent capitalization.

Amit Langote

Discussion: http://postgr.es/m/a83a0899-19f5-594c-9aac-3ba0f16989a1@lab.ntt.co.jp

6 years agoSet partitioned_rels appropriately when UNION ALL is used.
Robert Haas [Thu, 14 Sep 2017 14:43:44 +0000 (10:43 -0400)]
Set partitioned_rels appropriately when UNION ALL is used.

In most cases, this omission won't matter, because the appropriate
locks will have been acquired during parse/plan or by AcquireExecutorLocks.
But it's a bug all the same.

Report by Ashutosh Bapat.  Patch by me, reviewed by Amit Langote.

Discussion: http://postgr.es/m/CAFjFpRdHb_ZnoDTuBXqrudWXh3H1ibLkr6nHsCFT96fSK4DXtA@mail.gmail.com

6 years agoProperly check interrupts in execScan.c.
Andres Freund [Thu, 14 Sep 2017 08:53:10 +0000 (01:53 -0700)]
Properly check interrupts in execScan.c.

During the development of d47cfef711 the CFI()s in ExecScan() were
moved back and forth, ending up in the wrong place. Thus queries that
largely spend their time in ExecScan(), and have neither projection
nor a qual, can't be cancelled in a timely manner.

Reported-By: Jeff Janes
Author: Andres Freund
Discussion: https://postgr.es/m/CAMkU=1weDXp8eLLPt9SO1LEUsJYYK9cScaGhLKpuN+WbYo9b5g@mail.gmail.com
Backpatch: 10, as d47cfef711

6 years agoFix ordering in pg_dump of GRANTs
Stephen Frost [Thu, 14 Sep 2017 00:02:09 +0000 (20:02 -0400)]
Fix ordering in pg_dump of GRANTs

The order in which GRANTs are output is important as GRANTs which have
been GRANT'd by individuals via WITH GRANT OPTION GRANTs have to come
after the GRANT which included the WITH GRANT OPTION.  This happens
naturally in the backend during normal operation as we only change
existing ACLs in-place, only add new ACLs to the end, and when removing
an ACL we remove any which depend on it also.

Also, adjust the comments in acl.h to make this clear.

Unfortunately, the updates to pg_dump to handle initial privileges
involved pulling apart ACLs and then combining them back together and
could end up putting them back together in an invalid order, leading to
dumps which wouldn't restore.

Fix this by adjusting the queries used by pg_dump to ensure that the
ACLs are rebuilt in the same order in which they were originally.

Back-patch to 9.6 where the changes for initial privileges were done.

6 years agoAdjust unstable regression test case.
Tom Lane [Wed, 13 Sep 2017 16:27:01 +0000 (12:27 -0400)]
Adjust unstable regression test case.

Test queries added by commit 69835bc89 are giving unexpected results
on some smaller buildfarm critters.  I think probably the seqscan
logic is kicking in to cause the scans to not start at the beginning
of the table.  Add ORDER BY to make them be indexscans instead.

Per buildfarm member chipmunk.

6 years agoUpdate contrib/seg for new scalarlesel/scalargesel selectivity functions.
Tom Lane [Wed, 13 Sep 2017 15:54:55 +0000 (11:54 -0400)]
Update contrib/seg for new scalarlesel/scalargesel selectivity functions.

I somehow missed this module in commit 7d08ce286.

6 years agoDistinguish selectivity of < from <= and > from >=.
Tom Lane [Wed, 13 Sep 2017 15:12:39 +0000 (11:12 -0400)]
Distinguish selectivity of < from <= and > from >=.

Historically, the selectivity functions have simply not distinguished
< from <=, or > from >=, arguing that the fraction of the population that
satisfies the "=" aspect can be considered to be vanishingly small, if the
comparison value isn't any of the most-common-values for the variable.
(If it is, the code path that executes the operator against each MCV will
take care of things properly.)  But that isn't really true unless we're
dealing with a continuum of variable values, and in practice we seldom are.
If "x = const" would estimate a nonzero number of rows for a given const
value, then it follows that we ought to estimate different numbers of rows
for "x < const" and "x <= const", even if the const is not one of the MCVs.
Handling this more honestly makes a significant difference in edge cases,
such as the estimate for a tight range (x BETWEEN y AND z where y and z
are close together).

Hence, split scalarltsel into scalarltsel/scalarlesel, and similarly
split scalargtsel into scalargtsel/scalargesel.  Adjust <= and >=
operator definitions to reference the new selectivity functions.
Improve the core ineq_histogram_selectivity() function to make a
correction for equality.  (Along the way, I learned quite a bit about
exactly why that function gives good answers, which I tried to memorialize
in improved comments.)

The corresponding join selectivity functions were, and remain, just stubs.
But I chose to split them similarly, to avoid confusion and to prevent the
need for doing this exercise again if someone ever makes them less stubby.

In passing, change ineq_histogram_selectivity's clamp for extreme
probability estimates so that it varies depending on the histogram
size, instead of being hardwired at 0.0001.  With the default histogram
size of 100 entries, you still get the old clamp value, but bigger
histograms should allow us to put more faith in edge values.

Tom Lane, reviewed by Aleksander Alekseev and Kuntal Ghosh

Discussion: https://postgr.es/m/12232.1499140410@sss.pgh.pa.us

6 years agodoc: Remove incorrect SCRAM protocol documentation
Peter Eisentraut [Wed, 13 Sep 2017 14:10:34 +0000 (10:10 -0400)]
doc: Remove incorrect SCRAM protocol documentation

The documentation claimed that one should send
"pg_same_as_startup_message" as the user name in the SCRAM messages, but
this did not match the actual implementation, so remove it.

6 years agodocs: adjust "link mode" mention in pg_upgrade streaming steps
Bruce Momjian [Wed, 13 Sep 2017 13:22:18 +0000 (09:22 -0400)]
docs:  adjust "link mode" mention in pg_upgrade streaming steps

Backpatch-through: 9.5

6 years agodocs: improve pg_upgrade standby instructions
Bruce Momjian [Wed, 13 Sep 2017 13:11:28 +0000 (09:11 -0400)]
docs:  improve pg_upgrade standby instructions

This makes it clear that pg_upgrade standby upgrade instructions should
only be used in link mode, adds examples, and explains how rsync works
with links.

Reported-by: Andreas Joseph Krogh
Discussion: https://postgr.es/m/VisenaEmail.6c.c0e592c5af4ef0a2.15e785dcb61@tc7-visena

Backpatch-through: 9.5

6 years agoImprove error message in WAL sender
Peter Eisentraut [Wed, 13 Sep 2017 12:31:03 +0000 (08:31 -0400)]
Improve error message in WAL sender

The previous error message when attempting to run a general SQL command
in a physical replication WAL sender was a bit sloppy.

Reported-by: Fujii Masao <masao.fujii@gmail.com>
6 years agoDefine LDAP_NO_ATTRS if necessary.
Peter Eisentraut [Wed, 13 Sep 2017 12:20:45 +0000 (08:20 -0400)]
Define LDAP_NO_ATTRS if necessary.

Commit 83aaac41c66959a3ebaec7daadc4885b5f98f561 introduced the use of
LDAP_NO_ATTRS to avoid requesting a dummy attribute when doing search+bind
LDAP authentication.  It turns out that not all LDAP implementations define
that macro, but its value is fixed by the protocol so we can define it
ourselves if it's missing.

Author: Thomas Munro
Reported-By: Ashutosh Sharma
Discussion: https://postgr.es/m/CAE9k0Pm6FKCfPCiAr26-L_SMGOA7dT_k0%2B3pEbB8%2B-oT39xRpw%40mail.gmail.com

6 years agoAdd psql variables to track success/failure of SQL queries.
Tom Lane [Tue, 12 Sep 2017 23:27:48 +0000 (19:27 -0400)]
Add psql variables to track success/failure of SQL queries.

This patch adds ERROR, SQLSTATE, and ROW_COUNT, which are updated after
every query, as well as LAST_ERROR_MESSAGE and LAST_ERROR_SQLSTATE,
which are updated only when a query fails.  The expected usage of these
is for scripting.

Fabien Coelho, reviewed by Pavel Stehule

Discussion: https://postgr.es/m/alpine.DEB.2.20.1704042158020.12290@lancre

6 years agoIntroduce BYTES unit for GUCs.
Andres Freund [Tue, 12 Sep 2017 19:13:12 +0000 (12:13 -0700)]
Introduce BYTES unit for GUCs.

This is already useful for track_activity_query_size, and will further
be used in a later commit making the WAL segment size configurable.

Author: Beena Emerson
Reviewed-By: Andres Freund
Discussion: https://postgr.es/m/CAOG9ApEu8bXVwBxkOO9J7ZpM76TASK_vFMEEiCEjwhMmSLiaqQ@mail.gmail.com

6 years agodocs: improve pg_upgrade rsync instructions
Bruce Momjian [Tue, 12 Sep 2017 17:17:52 +0000 (13:17 -0400)]
docs:  improve pg_upgrade rsync instructions

This explains how rsync accomplishes updating standby servers and
clarifies the instructions.

Reported-by: Andreas Joseph Krogh
Discussion: https://postgr.es/m/VisenaEmail.10.2b4049e43870bd16.15d898d696f@tc7-visena

Backpatch-through: 9.5

6 years agodoc: Remove useless marked section
Peter Eisentraut [Tue, 12 Sep 2017 14:55:04 +0000 (10:55 -0400)]
doc: Remove useless marked section

This was left around when this text was moved from installation.sgml in
c5ba11f8fb1701441b96a755ea410b96bfe36170.

6 years agodoc: Document default scope in LDAP URL
Peter Eisentraut [Tue, 12 Sep 2017 14:02:34 +0000 (10:02 -0400)]
doc: Document default scope in LDAP URL

6 years agoAllow custom search filters to be configured for LDAP auth
Peter Eisentraut [Tue, 12 Sep 2017 13:46:14 +0000 (09:46 -0400)]
Allow custom search filters to be configured for LDAP auth

Before, only filters of the form "(<ldapsearchattribute>=<user>)"
could be used to search an LDAP server.  Introduce ldapsearchfilter
so that more general filters can be configured using patterns, like
"(|(uid=$username)(mail=$username))" and "(&(uid=$username)
(objectClass=posixAccount))".  Also allow search filters to be included
in an LDAP URL.

Author: Thomas Munro
Reviewed-By: Peter Eisentraut, Mark Cave-Ayland, Magnus Hagander
Discussion: https://postgr.es/m/CAEepm=0XTkYvMci0WRubZcf_1am8=gP=7oJErpsUfRYcKF2gwg@mail.gmail.com

6 years agoFixed ECPG to correctly handle out-of-scope cursor declarations with pointers
Michael Meskes [Mon, 11 Sep 2017 19:10:36 +0000 (21:10 +0200)]
Fixed ECPG to correctly handle out-of-scope cursor declarations with pointers
or array variables.

6 years agoFix RecursiveCopy.pm to cope with disappearing files.
Tom Lane [Tue, 12 Sep 2017 02:02:58 +0000 (22:02 -0400)]
Fix RecursiveCopy.pm to cope with disappearing files.

When copying from an active database tree, it's possible for files to be
deleted after we see them in a readdir() scan but before we can open them.
(Once we've got a file open, we don't expect any further errors from it
getting unlinked, though.)  Tweak RecursiveCopy so it can cope with this
case, so as to avoid irreproducible test failures.

Back-patch to 9.6 where this code was added.  In v10 and HEAD, also
remove unused "use RecursiveCopy" in one recovery test script.

Michael Paquier and Tom Lane

Discussion: https://postgr.es/m/24621.1504924323@sss.pgh.pa.us

6 years agoPG 10 release notes: change trigger transition tables
Bruce Momjian [Mon, 11 Sep 2017 23:56:44 +0000 (19:56 -0400)]
PG 10 release notes:  change trigger transition tables

Add attribution of trigger transition tables for Thomas Munro.

Reported-by: Thomas Munro
Discussion: https://postgr.es/m/CAEepm=2bDFgr4ut+1-QjKQY4MA=5ek8Ap3nyB19y2tpTL6xxtA@mail.gmail.com

Backpatch-through: 10

6 years agoPG 10 release notes: update PL/Tcl functions item
Bruce Momjian [Mon, 11 Sep 2017 23:43:49 +0000 (19:43 -0400)]
PG 10 release notes:  update PL/Tcl functions item

Update attribution of PL/Tcl functions item from Jim Nasby to Karl
Lehenbauer.

Reported-by: Jim Nasby
Discussion: https://postgr.es/m/ed42f3d6-4251-dabc-747f-1ff936763b2b@nasby.net

Backpatch-through: 10

6 years agopg_receivewal: Add --endpos option
Peter Eisentraut [Mon, 11 Sep 2017 20:30:50 +0000 (16:30 -0400)]
pg_receivewal: Add --endpos option

This is primarily useful for making tests of this utility more
deterministic, to avoid the complexity of starting pg_receivewal as a
deamon in TAP tests.

While this is less useful than the equivalent pg_recvlogical option,
users can as well use it for example to enforce WAL streaming up to a
end-of-backup position, to save only a minimal amount of WAL.

Use this new option to stream WAL data in a deterministic way within a
new set of TAP tests.

Author: Michael Paquier <michael.paquier@gmail.com>

6 years agoConstify numeric.c.
Andres Freund [Sun, 10 Sep 2017 23:20:41 +0000 (16:20 -0700)]
Constify numeric.c.

This allows the compiler/linker to move the static variables to a
read-only segment.  Not all the signature changes are necessary, but
it seems better to apply const in a consistent manner.

Reviewed-By: Tom Lane
Discussion: https://postgr.es/m/20170910232154.asgml44ji2b7lv3d@alap3.anarazel.de

6 years agoPrefer argument name over "$n" for the refname of a plpgsql argument.
Tom Lane [Mon, 11 Sep 2017 20:24:34 +0000 (16:24 -0400)]
Prefer argument name over "$n" for the refname of a plpgsql argument.

If a function argument has a name, use that as the "refname" of the
PLpgSQL_datum representing the argument, instead of $n as before.
This allows better error messages in some cases.

Pavel Stehule, reviewed by Jeevan Chalke

Discussion: https://postgr.es/m/CAFj8pRB9GyU2U1Sb2ssgP26DZ_yq-FYDfpvUvGQ=k4R=yOPVjg@mail.gmail.com

6 years agodoc: Document function pointer source code style
Peter Eisentraut [Mon, 11 Sep 2017 18:47:15 +0000 (14:47 -0400)]
doc: Document function pointer source code style

as implemented in 1356f78ea93395c107cbc75dc923e29a0efccd8a

6 years agoMessage style fixes
Peter Eisentraut [Mon, 11 Sep 2017 15:20:47 +0000 (11:20 -0400)]
Message style fixes

6 years agoQuick-hack fix for foreign key cascade vs triggers with transition tables.
Tom Lane [Sun, 10 Sep 2017 18:59:56 +0000 (14:59 -0400)]
Quick-hack fix for foreign key cascade vs triggers with transition tables.

AFTER triggers using transition tables crashed if they were fired due
to a foreign key ON CASCADE update.  This is because ExecEndModifyTable
flushes the transition tables, on the assumption that any trigger that
could need them was already fired during ExecutorFinish.  Normally
that's true, because we don't allow transition-table-using triggers
to be deferred.  However, foreign key CASCADE updates force any
triggers on the referencing table to be deferred to the outer query
level, by means of the EXEC_FLAG_SKIP_TRIGGERS flag.  I don't recall
all the details of why it's like that and am pretty loath to redesign
it right now.  Instead, just teach ExecEndModifyTable to skip destroying
the TransitionCaptureState when that flag is set.  This will allow the
transition table data to survive until end of the current subtransaction.

This isn't a terribly satisfactory solution, because (1) we might be
leaking the transition tables for much longer than really necessary,
and (2) as things stand, an AFTER STATEMENT trigger will fire once per
RI updating query, ie once per row updated or deleted in the referenced
table.  I suspect that is not per SQL spec.  But redesigning this is a
research project that we're certainly not going to get done for v10.
So let's go with this hackish answer for now.

In passing, tweak AfterTriggerSaveEvent to not save the transition_capture
pointer into the event record for a deferrable trigger.  This is not
necessary to fix the current bug, but it avoids letting dangling pointers
to long-gone transition tables persist in the trigger event queue.  That's
at least a safety feature.  It might also allow merging shared trigger
states in more cases than before.

I added a regression test that demonstrates the crash on unpatched code,
and also exposes the behavior of firing the AFTER STATEMENT triggers
once per row update.

Per bug #14808 from Philippe Beaudoin.  Back-patch to v10.

Discussion: https://postgr.es/m/20170909064853.25630.12825@wrigleys.postgresql.org

6 years agoAdd a test harness for the red-black tree code.
Tom Lane [Sun, 10 Sep 2017 17:26:46 +0000 (13:26 -0400)]
Add a test harness for the red-black tree code.

This improves the regression tests' coverage of rbtree.c from pretty
awful (because some of the functions aren't used yet) to basically 100%.

Victor Drobny, reviewed by Aleksander Alekseev and myself

Discussion: https://postgr.es/m/c9d61310e16e75f8acaf6cb1c48b7b77@postgrespro.ru

6 years agoRemove pre-order and post-order traversal logic for red-black trees.
Tom Lane [Sun, 10 Sep 2017 17:19:11 +0000 (13:19 -0400)]
Remove pre-order and post-order traversal logic for red-black trees.

This code isn't used, and there's no clear reason why anybody would ever
want to use it.  These traversal mechanisms don't yield a visitation order
that is semantically meaningful for any external purpose, nor are they
any faster or simpler than the left-to-right or right-to-left traversals.
(In fact, some rough testing suggests they are slower :-(.)  Moreover,
these mechanisms are impossible to test in any arm's-length fashion; doing
so requires knowledge of the red-black tree's internal implementation.
Hence, let's just jettison them.

Discussion: https://postgr.es/m/17735.1505003111@sss.pgh.pa.us

6 years agopg_upgrade: Message style fixes
Peter Eisentraut [Sat, 9 Sep 2017 21:32:10 +0000 (17:32 -0400)]
pg_upgrade: Message style fixes

6 years agoFix failure-to-copy bug in commit 6f6b99d13.
Tom Lane [Sat, 9 Sep 2017 00:45:31 +0000 (20:45 -0400)]
Fix failure-to-copy bug in commit 6f6b99d13.

The previous coding of get_qual_for_list() was careful to copy everything
it was using from the input data structure.  The new version missed
making a copy of pass-by-ref datum values that it's inserting into Consts.
This is not optional, however, as revealed by buildfarm failures on
machines running -DRELCACHE_FORCE_RELEASE: we're copying from a relcache
entry that could go away before the required lifespan of our output
expression.  I'm pretty sure -DCLOBBER_CACHE_ALWAYS machines won't like
this either, but none of them have reported in yet.

6 years agoFix uninitialized-variable bug.
Tom Lane [Fri, 8 Sep 2017 23:04:32 +0000 (19:04 -0400)]
Fix uninitialized-variable bug.

map_partition_varattnos() failed to set its found_whole_row output
parameter if the given expression list was NIL.  This seems to be
a pre-existing bug that chanced to be exposed by commit 6f6b99d13.
It might be unreachable in v10, but I have little faith in that
proposition, so back-patch.

Per buildfarm.

6 years agoFix more portability issues in new pgbench TAP tests.
Tom Lane [Fri, 8 Sep 2017 21:37:43 +0000 (17:37 -0400)]
Fix more portability issues in new pgbench TAP tests.

Not completely sure, but I think bowerbird is spitting up on attempting
to include ">" in a temporary file name.  (Why in the world are we
writing this stuff into files at all?  A hash would be a better answer.)

6 years agoAllow a partitioned table to have a default partition.
Robert Haas [Fri, 8 Sep 2017 21:28:04 +0000 (17:28 -0400)]
Allow a partitioned table to have a default partition.

Any tuples that don't route to any other partition will route to the
default partition.

Jeevan Ladhe, Beena Emerson, Ashutosh Bapat, Rahila Syed, and Robert
Haas, with review and testing at various stages by (at least) Rushabh
Lathia, Keith Fiske, Amit Langote, Amul Sul, Rajkumar Raghuanshi, Sven
Kunze, Kyotaro Horiguchi, Thom Brown, Rafia Sabih, and Dilip Kumar.

Discussion: http://postgr.es/m/CAH2L28tbN4SYyhS7YV1YBWcitkqbhSWfQCy0G=apRcC_PEO-bg@mail.gmail.com
Discussion: http://postgr.es/m/CAOG9ApEYj34fWMcvBMBQ-YtqR9fTdXhdN82QEKG0SVZ6zeL1xg@mail.gmail.com

6 years agoFix pgbench TAP tests to work with --disable-thread-safety.
Tom Lane [Fri, 8 Sep 2017 21:25:11 +0000 (17:25 -0400)]
Fix pgbench TAP tests to work with --disable-thread-safety.

Probably matters to nobody but me; but I'd like to still be able to get
through the TAP tests on gaur/pademelon, from time to time.

6 years agoDoc: update v10 release notes through today.
Tom Lane [Fri, 8 Sep 2017 20:59:26 +0000 (16:59 -0400)]
Doc: update v10 release notes through today.

Also, another round of copy-editing.  I merged a few items that
didn't seem to be meaningfully different from a user's perspective.

6 years agoRemove mention of password_encryption = plain in postgresql.conf.sample.
Tom Lane [Fri, 8 Sep 2017 18:38:54 +0000 (14:38 -0400)]
Remove mention of password_encryption = plain in postgresql.conf.sample.

Evidently missed in commit eb61136dc.

Spotted by Oleg Bartunov.

Discussion: https://postgr.es/m/CAF4Au4wz_iK5r4fnTnnd8XqioAZQs-P7-VsEAfivW34zMVpAmw@mail.gmail.com

6 years agoFix more portability issues in new pgbench TAP tests.
Tom Lane [Fri, 8 Sep 2017 18:01:51 +0000 (14:01 -0400)]
Fix more portability issues in new pgbench TAP tests.

Strike two on the --bad-option test.
Three strikes and it's out.

Fabien Coelho, per buildfarm

6 years agoFix more portability issues in new pgbench TAP tests.
Tom Lane [Fri, 8 Sep 2017 17:36:13 +0000 (13:36 -0400)]
Fix more portability issues in new pgbench TAP tests.

* Remove no-such-user test case, output isn't stable, and we really
don't need to be testing such cases here anyway.

* Fix the process exit code test logic to match PostgresNode::psql
(but I didn't bother with looking at the "core" flag).

* Give up on inf/nan tests.

Per buildfarm.

6 years agoClean up excessive code
Peter Eisentraut [Thu, 31 Aug 2017 02:28:36 +0000 (22:28 -0400)]
Clean up excessive code

The encoding ID was converted between string and number too many times,
probably a remnant from the shell script days.

Reviewed-by: Aleksandr Parfenov <a.parfenov@postgrespro.ru>
6 years agoRemove useless empty string initializations
Peter Eisentraut [Thu, 31 Aug 2017 02:28:36 +0000 (22:28 -0400)]
Remove useless empty string initializations

This coding style probably stems from the days of shell scripts.

Reviewed-by: Aleksandr Parfenov <a.parfenov@postgrespro.ru>
6 years agoRemove useless dead code
Peter Eisentraut [Thu, 31 Aug 2017 02:28:36 +0000 (22:28 -0400)]
Remove useless dead code

Reviewed-by: Aleksandr Parfenov <a.parfenov@postgrespro.ru>
6 years agoFix assorted portability issues in new pgbench TAP tests.
Tom Lane [Fri, 8 Sep 2017 15:28:02 +0000 (11:28 -0400)]
Fix assorted portability issues in new pgbench TAP tests.

* Our own version of getopt_long doesn't support abbreviation of
long options.

* It doesn't do automatic rearrangement of non-option arguments to the end,
either.

* Test was way too optimistic about the platform independence of
NaN and Infinity outputs.  I rather imagine we might have to lose
those tests altogether, but for the moment just allow case variation
and fully spelled out Infinity.

Per buildfarm.

6 years agoAdd much-more-extensive TAP tests for pgbench.
Tom Lane [Fri, 8 Sep 2017 13:32:50 +0000 (09:32 -0400)]
Add much-more-extensive TAP tests for pgbench.

Fabien Coelho, reviewed by Nikolay Shaplov and myself

Discussion: https://postgr.es/m/alpine.DEB.2.20.1704171422500.4025@lancre

6 years agoRefactor get_partition_for_tuple a bit.
Robert Haas [Fri, 8 Sep 2017 01:07:47 +0000 (21:07 -0400)]
Refactor get_partition_for_tuple a bit.

Pending patches for both default partitioning and hash partitioning
find the current coding pattern to be inconvenient.  Change it so that
we switch on the partitioning method first and then do whatever is
needed.

Amul Sul, reviewed by Jeevan Ladhe, with a few adjustments by me.

Discussion: http://postgr.es/m/CAAJ_b97mTb=dG2pv6+1ougxEVZFVnZJajW+0QHj46mEE7WsoOQ@mail.gmail.com
Discussion: http://postgr.es/m/CAOgcT0M37CAztEinpvjJc18EdHfm23fw0EG9-36Ya=+rEFUqaQ@mail.gmail.com

6 years agoImprove performance of get_actual_variable_range with recently-dead tuples.
Tom Lane [Thu, 7 Sep 2017 23:41:51 +0000 (19:41 -0400)]
Improve performance of get_actual_variable_range with recently-dead tuples.

In commit fccebe421, we hacked get_actual_variable_range() to scan the
index with SnapshotDirty, so that if there are many uncommitted tuples
at the end of the index range, it wouldn't laboriously scan through all
of them looking for a live value to return.  However, that didn't fix it
for the case of many recently-dead tuples at the end of the index;
SnapshotDirty recognizes those as committed dead and so we're back to
the same problem.

To improve the situation, invent a "SnapshotNonVacuumable" snapshot type
and use that instead.  The reason this helps is that, if the snapshot
rejects a given index entry, we know that the indexscan will mark that
index entry as killed.  This means the next get_actual_variable_range()
scan will proceed past that entry without visiting the heap, making the
scan a lot faster.  We may end up accepting a recently-dead tuple as
being the estimated extremal value, but that doesn't seem much worse than
the compromise we made before to accept not-yet-committed extremal values.

The cost of the scan is still proportional to the number of dead index
entries at the end of the range, so in the interval after a mass delete
but before VACUUM's cleaned up the mess, it's still possible for
get_actual_variable_range() to take a noticeable amount of time, if you've
got enough such dead entries.  But the constant factor is much much better
than before, since all we need to do with each index entry is test its
"killed" bit.

We chose to back-patch commit fccebe421 at the time, but I'm hesitant to
do so here, because this form of the problem seems to affect many fewer
people.  Also, even when it happens, it's less bad than the case fixed
by commit fccebe421 because we don't get the contention effects from
expensive TransactionIdIsInProgress tests.

Dmitriy Sarafannikov, reviewed by Andrey Borodin

Discussion: https://postgr.es/m/05C72CF7-B5F6-4DB9-8A09-5AC897653113@yandex.ru