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

6 years agoImprove documentation about behavior of multi-statement Query messages.
Tom Lane [Thu, 7 Sep 2017 18:04:41 +0000 (14:04 -0400)]
Improve documentation about behavior of multi-statement Query messages.

We've long done our best to sweep this topic under the rug, but in view
of recent work it seems like it's time to explain it more precisely.
Here's an initial cut at doing that.

Discussion: https://postgr.es/m/0A3221C70F24FB45833433255569204D1F6BE40D@G01JPEXMBYT05

6 years agoReduce excessive dereferencing of function pointers
Peter Eisentraut [Thu, 7 Sep 2017 16:06:23 +0000 (12:06 -0400)]
Reduce excessive dereferencing of function pointers

It is equivalent in ANSI C to write (*funcptr) () and funcptr().  These
two styles have been applied inconsistently.  After discussion, we'll
use the more verbose style for plain function pointer variables, to make
it clear that it's a variable, and the shorter style when the function
pointer is in a struct (s.func() or s->func()), because then it's clear
that it's not a plain function name, and otherwise the excessive
punctuation makes some of those invocations hard to read.

Discussion: https://www.postgresql.org/message-id/f52c16db-14ed-757d-4b48-7ef360b1631d@2ndquadrant.com

6 years agoEven if some partitions are foreign, allow tuple routing.
Robert Haas [Thu, 7 Sep 2017 14:55:45 +0000 (10:55 -0400)]
Even if some partitions are foreign, allow tuple routing.

This doesn't allow routing tuple to the foreign partitions themselves,
but it permits tuples to be routed to regular partitions despite the
presence of foreign partitions in the same inheritance hierarchy.

Etsuro Fujita, reviewed by Amit Langote and by me.

Discussion: http://postgr.es/m/bc3db4c1-1693-3b8a-559f-33ad2b50b7ad@lab.ntt.co.jp

6 years agoFix handling of savepoint commands within multi-statement Query strings.
Tom Lane [Thu, 7 Sep 2017 13:49:55 +0000 (09:49 -0400)]
Fix handling of savepoint commands within multi-statement Query strings.

Issuing a savepoint-related command in a Query message that contains
multiple SQL statements led to a FATAL exit with a complaint about
"unexpected state STARTED".  This is a shortcoming of commit 4f896dac1,
which attempted to prevent such misbehaviors in multi-statement strings;
its quick hack of marking the individual statements as "not top-level"
does the wrong thing in this case, and isn't a very accurate description
of the situation anyway.

To fix, let's introduce into xact.c an explicit model of what happens for
multi-statement Query strings.  This is an "implicit transaction block
in progress" state, which for many purposes works like the normal
TBLOCK_INPROGRESS state --- in particular, IsTransactionBlock returns true,
causing the desired result that PreventTransactionChain will throw error.
But in case of error abort it works like TBLOCK_STARTED, allowing the
transaction to be cancelled without need for an explicit ROLLBACK command.

Commit 4f896dac1 is reverted in toto, so that we go back to treating the
individual statements as "top level".  We could have left it as-is, but
this allows sharpening the error message for PreventTransactionChain
calls inside functions.

Except for getting a normal error instead of a FATAL exit for savepoint
commands, this patch should result in no user-visible behavioral change
(other than that one error message rewording).  There are some things
we might want to do in the line of changing the appearance or wording of
error and warning messages around this behavior, which would be much
simpler to do now that it's an explicitly modeled state.  But I haven't
done them here.

Although this fixes a long-standing bug, no backpatch.  The consequences
of the bug don't seem severe enough to justify the risk that this commit
itself creates some new issue.

Patch by me, but it owes something to previous investigation by
Takayuki Tsunakawa, who also reported the bug in the first place.
Also thanks to Michael Paquier for reviewing.

Discussion: https://postgr.es/m/0A3221C70F24FB45833433255569204D1F6BE40D@G01JPEXMBYT05

6 years agoFurther marginal hacking on generic atomic ops.
Tom Lane [Thu, 7 Sep 2017 12:50:01 +0000 (08:50 -0400)]
Further marginal hacking on generic atomic ops.

In the generic atomic ops that rely on a loop around a CAS primitive,
there's no need to force the initial read of the "old" value to be atomic.
In the typically-rare case that we get a torn value, that simply means
that the first CAS attempt will fail; but it will update "old" to the
atomically-read value, so the next attempt has a chance of succeeding.
It was already being done that way in pg_atomic_exchange_u64_impl(),
but let's duplicate the approach in the rest.

(Given the current coding of the pg_atomic_read functions, this change
is a no-op anyway on popular platforms; it only makes a difference where
pg_atomic_read_u64_impl() is implemented as a CAS.)

In passing, also remove unnecessary take-a-pointer-and-dereference-it
coding in the pg_atomic_read functions.  That seems to have been based
on a misunderstanding of what the C standard requires.  What actually
matters is that the pointer be declared as pointing to volatile, which
it is.

I don't believe this will change the assembly code at all on x86
platforms (even ignoring the likelihood that these implementations
get overridden by others); but it may help on less-mainstream CPUs.

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

6 years agoExclude special values in recovery_target_time
Simon Riggs [Thu, 7 Sep 2017 11:56:34 +0000 (04:56 -0700)]
Exclude special values in recovery_target_time

recovery_target_time accepts timestamp input, though
does not allow use of special values, e.g. ā€œtodayā€.
Report a useful error message for these cases.

Reported-by: Piotr Stefaniak
Author: Simon Riggs
Discussion: https://postgr.es/m/CANP8+jJdKA+BkkYLWz9zAm16Y0s2ExBv0WfpAwXdTpPfWnA9Bg@mail.gmail.com

6 years agoSync function prototype with its actual definition.
Tom Lane [Wed, 6 Sep 2017 21:52:08 +0000 (17:52 -0400)]
Sync function prototype with its actual definition.

Use the same parameter names as in the definition.  Cosmetic fix only.

Tatsuro Yamada

Discussion: https://postgr.es/m/58E711AF.7070305@lab.ntt.co.jp

6 years agoMerge duplicative code for \sf/\sv, \ef/\ev in psql/command.c.
Tom Lane [Wed, 6 Sep 2017 21:32:40 +0000 (17:32 -0400)]
Merge duplicative code for \sf/\sv, \ef/\ev in psql/command.c.

Saves ~150 lines, costs little.

Fabien Coelho, reviewed by Victor Drobny

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

6 years agoAllow SET STATISTICS on expression indexes
Simon Riggs [Wed, 6 Sep 2017 20:46:01 +0000 (13:46 -0700)]
Allow SET STATISTICS on expression indexes

Index columns are referenced by ordinal number rather than name, e.g.
CREATE INDEX coord_idx ON measured (x, y, (z + t));
ALTER INDEX coord_idx ALTER COLUMN 3 SET STATISTICS 1000;

Incompatibility note for release notes:
\d+ for indexes now also displays Stats Target

Authors: Alexander Korotkov, with contribution by Adrien NAYRAT
Review: Adrien NAYRAT, Simon Riggs
Wordsmith: Simon Riggs

6 years agoUse more of gcc's __sync_fetch_and_xxx builtin functions for atomic ops.
Tom Lane [Wed, 6 Sep 2017 18:21:39 +0000 (14:21 -0400)]
Use more of gcc's __sync_fetch_and_xxx builtin functions for atomic ops.

In addition to __sync_fetch_and_add, gcc offers __sync_fetch_and_sub,
__sync_fetch_and_and, and __sync_fetch_and_or, which correspond directly
to primitive atomic ops that we want.  Testing shows that in some cases
they generate better code than our generic implementations, so use them.

We've assumed that configure's test for __sync_val_compare_and_swap is
sufficient to allow assuming that __sync_fetch_and_add is available, so
make the same assumption for these functions.  Should that prove to be
wrong, we can add more configure tests.

Yura Sokolov, reviewed by Jesper Pedersen and myself

Discussion: https://postgr.es/m/7f65886daca545067f82bf2b463b218d@postgrespro.ru

6 years agoRemove duplicate reads from the inner loops in generic atomic ops.
Tom Lane [Wed, 6 Sep 2017 18:06:09 +0000 (14:06 -0400)]
Remove duplicate reads from the inner loops in generic atomic ops.

The pg_atomic_compare_exchange_xxx functions are defined to update
*expected to whatever they read from the target variable.  Therefore,
there's no need to do additional explicit reads after we've initialized
the "old" variable.  The actual benefit of this is somewhat debatable,
but it seems fairly unlikely to hurt anything, especially since we
will override the generic implementations in most performance-sensitive
cases.

Yura Sokolov, reviewed by Jesper Pedersen and myself

Discussion: https://postgr.es/m/7f65886daca545067f82bf2b463b218d@postgrespro.ru

6 years agodoc: Make function synopsis formatting more uniform
Peter Eisentraut [Wed, 6 Sep 2017 15:38:28 +0000 (11:38 -0400)]
doc: Make function synopsis formatting more uniform

Whitespace use was inconsistent in the same chapter.

6 years agoEscape < and & in SGML
Peter Eisentraut [Wed, 6 Sep 2017 15:22:43 +0000 (11:22 -0400)]
Escape < and & in SGML

This is not required in SGML, but will be in XML, so this is a step to
prepare for the conversion to XML.  (It is still not required to escape
>, but we did it here in some cases for symmetry.)

Add a command-line option to osx/onsgmls calls to warn about unescaped
occurrences in the future.

Author: Alexander Law <exclusion@gmail.com>
Author: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>

6 years agoClean up handling of dropped columns in NAMEDTUPLESTORE RTEs.
Tom Lane [Wed, 6 Sep 2017 14:41:05 +0000 (10:41 -0400)]
Clean up handling of dropped columns in NAMEDTUPLESTORE RTEs.

The NAMEDTUPLESTORE patch piggybacked on the infrastructure for
TABLEFUNC/VALUES/CTE RTEs, none of which can ever have dropped columns,
so the possibility was ignored most places.  Fix that, including adding a
specification to parsenodes.h about what it's supposed to look like.

In passing, clean up assorted comments that hadn't been maintained
properly by said patch.

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

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

6 years agodoc: Clarify pg_inherits description
Peter Eisentraut [Wed, 6 Sep 2017 01:35:59 +0000 (21:35 -0400)]
doc: Clarify pg_inherits description

Reported-by: mjustin.lists@gmail.com
6 years agoAdd \gdesc psql command.
Tom Lane [Tue, 5 Sep 2017 22:17:47 +0000 (18:17 -0400)]
Add \gdesc psql command.

This command acts somewhat like \g, but instead of executing the query
buffer, it merely prints a description of the columns that the query
result would have.  (Of course, this still requires parsing the query;
if parse analysis fails, you get an error anyway.)  We accomplish this
using an unnamed prepared statement, which should be invisible to psql
users.

Pavel Stehule, reviewed by Fabien Coelho

Discussion: https://postgr.es/m/CAFj8pRBhYVvO34FU=EKb=nAF5t3b++krKt1FneCmR0kuF5m-QA@mail.gmail.com

6 years agoUse lfirst_node() and linitial_node() where appropriate in planner.c.
Tom Lane [Tue, 5 Sep 2017 19:57:48 +0000 (15:57 -0400)]
Use lfirst_node() and linitial_node() where appropriate in planner.c.

There's no particular reason to target this module for the first
wholesale application of these macros; but we gotta start somewhere.

Ashutosh Bapat and Jeevan Chalke

Discussion: https://postgr.es/m/CAFjFpRcNr3r=u0ni=7A4GD9NnHQVq+dkFafzqo2rS6zy=dt1eg@mail.gmail.com

6 years agoRemove endof macro
Peter Eisentraut [Thu, 17 Aug 2017 16:39:20 +0000 (12:39 -0400)]
Remove endof macro

It has not been used in a long time, and it doesn't seem safe anyway, so
drop it.

Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
Reviewed-by: Ryan Murphy <ryanfmurphy@gmail.com>
6 years agoRemove unnecessary casts
Peter Eisentraut [Thu, 17 Aug 2017 16:39:20 +0000 (12:39 -0400)]
Remove unnecessary casts

Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
Reviewed-by: Ryan Murphy <ryanfmurphy@gmail.com>
6 years agoRemove unnecessary parentheses in return statements
Peter Eisentraut [Thu, 17 Aug 2017 16:39:20 +0000 (12:39 -0400)]
Remove unnecessary parentheses in return statements

The parenthesized style has only been used in a few modules.  Change
that to use the style that is predominant across the whole tree.

Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
Reviewed-by: Ryan Murphy <ryanfmurphy@gmail.com>
6 years agoRemove our own definition of NULL
Peter Eisentraut [Thu, 17 Aug 2017 16:39:20 +0000 (12:39 -0400)]
Remove our own definition of NULL

Surely everyone has that by now.

Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
Reviewed-by: Ryan Murphy <ryanfmurphy@gmail.com>
6 years agofuzzystrmatch: Remove dead code
Peter Eisentraut [Thu, 17 Aug 2017 16:39:20 +0000 (12:39 -0400)]
fuzzystrmatch: Remove dead code

Remnants left behind by a323ede2802956f115d71599514fbc01f2575dee

Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
Reviewed-by: Ryan Murphy <ryanfmurphy@gmail.com>
6 years agoSupport retaining data dirs on successful TAP tests
Peter Eisentraut [Tue, 5 Sep 2017 16:22:33 +0000 (12:22 -0400)]
Support retaining data dirs on successful TAP tests

This moves the data directories from using temporary directories with
randomness in the directory name to a static name, to make it easier to
debug.  The data directory will be retained if tests fail or the test
code dies/exits with failure, and is automatically removed on the next
make check.

If the environment variable PG_TEST_NOCLEAN is defined, the data
directories will be retained regardless of test or exit status.

Author: Daniel Gustafsson <daniel@yesql.se>

6 years agoIn psql, use PSQL_PAGER in preference to PAGER, if it's set.
Tom Lane [Tue, 5 Sep 2017 16:02:06 +0000 (12:02 -0400)]
In psql, use PSQL_PAGER in preference to PAGER, if it's set.

This allows the user's environment to set up a psql-specific choice
of pager, in much the same way that we provide PSQL_EDITOR to allow
a psql-specific override of the more widely known EDITOR variable.

Pavel Stehule, reviewed by Thomas Munro

Discussion: https://postgr.es/m/CAFj8pRD3RRk9S1eRbnGm_T6brc3Ss5mohraNzTSJquzx+pmtKA@mail.gmail.com

6 years agoCorrect base backup throttling
Alvaro Herrera [Tue, 5 Sep 2017 14:59:39 +0000 (16:59 +0200)]
Correct base backup throttling

Throttling for sending a base backup in walsender is broken for the case
where there is a lot of WAL traffic, because the latch used to put the
walsender to sleep is also signalled by regular WAL traffic (and each
signal causes an additional batch of data to be sent); the net effect is
that there is no or little actual throttling.  This is undesirable, so
rewrite the sleep into a loop to achieve the desired effeect.

Author: Jeff Janes, small tweaks by me
Reviewed-by: Antonin Houska
Discussion: https://postgr.es/m/CAMkU=1xH6mde-yL-Eo1TKBGNd0PB1-TMxvrNvqcAkN-qr2E9mw@mail.gmail.com

6 years agoAdd psql variables showing server version and psql version.
Tom Lane [Tue, 5 Sep 2017 14:51:36 +0000 (10:51 -0400)]
Add psql variables showing server version and psql version.

We already had a psql variable VERSION that shows the verbose form of
psql's own version.  Add VERSION_NAME to show the short form (e.g.,
"11devel") and VERSION_NUM to show the numeric form (e.g., 110000).
Also add SERVER_VERSION_NAME and SERVER_VERSION_NUM to show the short and
numeric forms of the server's version.  (We'd probably add SERVER_VERSION
with the verbose string if it were readily available; but adding another
network round trip to get it seems too expensive.)

The numeric forms, in particular, are expected to be useful for scripting
purposes, now that psql can do conditional tests.

Fabien Coelho, reviewed by Pavel Stehule

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

6 years agoReformat psql's --help=variables output.
Tom Lane [Tue, 5 Sep 2017 14:17:10 +0000 (10:17 -0400)]
Reformat psql's --help=variables output.

The previous format with variable names and descriptions in separate
columns was extremely constraining about the length of the descriptions.
We'd dealt with that in several inconsistent ways over the years,
including letting the lines run over 80 characters, breaking descriptions
into multiple lines, or shoving the description onto a separate line.
But it's been a long time since the output could realistically fit onto
a single screen vertically, so let's just rely even more heavily on the
pager to deal with the vertical distance, and split each entry into two
(or more) lines, in the format

  variable-name
    variable description goes here

Each variable name + description remains a single translatable string,
in hopes of reducing translator confusion; we're just changing the
embedded whitespace.

I failed to resist the temptation to copy-edit one or two of the
descriptions while at it.

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

6 years agoBe more careful about newline-chomping in pgbench.
Tom Lane [Mon, 4 Sep 2017 21:25:31 +0000 (17:25 -0400)]
Be more careful about newline-chomping in pgbench.

process_backslash_command would drop the last character of the input
command on the assumption that it was a newline.  Given a non newline
terminated input file, this could result in dropping the last character
of the command.  Fix that by doing an actual test that we're removing
a newline.

While at it, allow for Windows newlines (\r\n), and suppress multiple
newlines if any.  I do not think either of those cases really occur,
since (a) we read script files in text mode and (b) the lexer stops
when it hits a newline.  But it's cheap enough and it provides a
stronger guarantee about what the result string looks like.

This is just cosmetic, I think, since the possibly-overly-chomped
line was only used for display not for further processing.  So
it doesn't seem necessary to back-patch.

Fabien Coelho, reviewed by Nikolay Shaplov, whacked around a bit by me

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

6 years agoFix some subtle problems in pgbench transaction stats counting.
Tom Lane [Mon, 4 Sep 2017 20:24:08 +0000 (16:24 -0400)]
Fix some subtle problems in pgbench transaction stats counting.

With --latency-limit, transactions might get skipped even beyond the
transaction count limit specified by -t, throwing off the expected
number of transactions and thus the denominator for later stats.
Be sure to stop skipping transactions once -t is reached.

Also, include skipped transactions in the "cnt" fields; this requires
discounting them again in a couple of places, but most places are
better off with this definition.  In particular this is needed to
get correct overall stats for the combination of -R/-L/-t options.
Merge some more processing into processXactStats() to simplify this.

In passing, add a check that --progress-timestamp is specified only
when --progress is.

We might consider back-patching this, but given that it only matters
for a combination of options, and given the lack of field complaints,
consensus seems to be not to bother.

Fabien Coelho, reviewed by Nikolay Shaplov

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

6 years agoAdjust pgbench to allow non-ASCII characters in variable names.
Tom Lane [Mon, 4 Sep 2017 17:45:20 +0000 (13:45 -0400)]
Adjust pgbench to allow non-ASCII characters in variable names.

This puts it in sync with psql's notion of what is a valid variable name.
Like psql, we document that "non-Latin letters" are allowed, but actually
any non-ASCII character is accepted.

Fabien Coelho

Discussion: https://postgr.es/m/20170405.094548.1184280384967203518.t-ishii@sraoss.co.jp

6 years agoFix translatable string
Alvaro Herrera [Mon, 4 Sep 2017 09:08:52 +0000 (11:08 +0200)]
Fix translatable string

Discussion: https://postgr.es/m/20170828130545.sdajqlpr37hmmd6a@alvherre.pgsql

6 years agoSuppress compiler warnings in dshash.c.
Tom Lane [Sun, 3 Sep 2017 15:12:29 +0000 (11:12 -0400)]
Suppress compiler warnings in dshash.c.

Some compilers complain, not unreasonably, about left-shifting an
int32 "1" and then assigning the result to an int64.  In practice
I sure hope that this data structure never gets large enough that
an overflow would actually occur; but let's cast the constant to
the right type to avoid the hazard.

In passing, fix a typo in dshash.h.

Amit Kapila, adjusted as per comment from Thomas Munro.

Discussion: https://postgr.es/m/CAA4eK1+5vfVMYtjK_NX8O3-42yM3o80qdqWnQzGquPrbq6mb+A@mail.gmail.com

6 years agoFix macro-redefinition warning on MSVC.
Tom Lane [Sun, 3 Sep 2017 15:01:08 +0000 (11:01 -0400)]
Fix macro-redefinition warning on MSVC.

In commit 9d6b160d7, I tweaked pg_config.h.win32 to use
"#define HAVE_LONG_LONG_INT_64 1" rather than defining it as empty,
for consistency with what happens in an autoconf'd build.
But Solution.pm injects another definition of that macro into
ecpg_config.h, leading to justifiable (though harmless) compiler whining.
Make that one consistent too.  Back-patch, like the previous patch.

Discussion: https://postgr.es/m/CAEepm=1dWsXROuSbRg8PbKLh0S=8Ou-V8sr05DxmJOF5chBxqQ@mail.gmail.com

6 years agodoc: Fix typos and other minor issues
Peter Eisentraut [Sat, 2 Sep 2017 03:34:12 +0000 (23:34 -0400)]
doc: Fix typos and other minor issues

Author: Alexander Lakhin <exclusion@gmail.com>

6 years agoImprove division of labor between execParallel.c and nodeGather[Merge].c.
Tom Lane [Fri, 1 Sep 2017 21:38:54 +0000 (17:38 -0400)]
Improve division of labor between execParallel.c and nodeGather[Merge].c.

Move the responsibility for creating/destroying TupleQueueReaders into
execParallel.c, to avoid duplicative coding in nodeGather.c and
nodeGatherMerge.c.  Also, instead of having DestroyTupleQueueReader do
shm_mq_detach, do it in the caller (which is now only ExecParallelFinish).
This means execParallel.c does both the attaching and detaching of the
tuple-queue-reader shm_mqs, which seems less weird than the previous
arrangement.

These changes also eliminate a vestigial memory leak (of the pei->tqueue
array).  It's now demonstrable that rescans of Gather or GatherMerge don't
leak memory.

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

6 years agoAdd memory info to getrusage output
Peter Eisentraut [Fri, 1 Sep 2017 19:36:33 +0000 (15:36 -0400)]
Add memory info to getrusage output

Add the maxrss field to the getrusage output (log_*_stats).  This was
previously omitted because of portability concerns, but we feel this
might not be a concern anymore.

based on patch by Justin Pryzby <pryzby@telsasoft.com>

6 years agoTighten up some code in RelationBuildPartitionDesc.
Robert Haas [Fri, 1 Sep 2017 19:16:44 +0000 (15:16 -0400)]
Tighten up some code in RelationBuildPartitionDesc.

This probably doesn't save anything meaningful in terms of
performance, but making the code simpler is a good idea anyway.

Code by Beena Emerson, extracted from a larger patch by Jeevan
Ladhe, slightly adjusted by me.

Discussion: http://postgr.es/m/CAOgcT0ONgwajdtkoq+AuYkdTPY9cLWWLjxt_k4SXue3eieAr+g@mail.gmail.com

6 years agoMake [U]INT64CONST safe for use in #if conditions.
Tom Lane [Fri, 1 Sep 2017 19:14:18 +0000 (15:14 -0400)]
Make [U]INT64CONST safe for use in #if conditions.

Instead of using a cast to force the constant to be the right width,
assume we can plaster on an L, UL, LL, or ULL suffix as appropriate.
The old approach to this is very hoary, dating from before we were
willing to require compilers to have working int64 types.

This fix makes the PG_INT64_MIN, PG_INT64_MAX, and PG_UINT64_MAX
constants safe to use in preprocessor conditions, where a cast
doesn't work.  Other symbolic constants that might be defined using
[U]INT64CONST are likewise safer than before.

Also fix the SIZE_MAX macro to be similarly safe, if we are forced
to provide a definition for that.  The test added in commit 2e70d6b5e
happens to do what we want even with the hack "(size_t) -1" definition,
but we could easily get burnt on other tests in future.

Back-patch to all supported branches, like the previous commits.

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

6 years agodoc: Remove mentions of server-side CRL and CA file names
Peter Eisentraut [Fri, 1 Sep 2017 18:18:45 +0000 (14:18 -0400)]
doc: Remove mentions of server-side CRL and CA file names

Commit a445cb92ef5b3a31313ebce30e18cc1d6e0bdecb removed the default file
names for server-side CRL and CA files, but left them in the docs with a
small note.  This removes the note and the previous default names to
clarify, as well as changes mentions of the file names to make it
clearer that they are configurable.

Author: Daniel Gustafsson <daniel@yesql.se>
Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
6 years agoEnsure SIZE_MAX can be used throughout our code.
Tom Lane [Fri, 1 Sep 2017 17:52:53 +0000 (13:52 -0400)]
Ensure SIZE_MAX can be used throughout our code.

Pre-C99 platforms may lack <stdint.h> and thereby SIZE_MAX.  We have
a couple of places using the hack "(size_t) -1" as a fallback, but
it wasn't universally available; which means the code added in commit
2e70d6b5e fails to compile everywhere.  Move that hack to c.h so that
we can rely on having SIZE_MAX everywhere.

Per discussion, it'd be a good idea to make the macro's value safe
for use in #if-tests, but that will take a bit more work.  This is
just a quick expedient to get the buildfarm green again.

Back-patch to all supported branches, like the previous commit.

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

6 years agopg_dumpall: Add a -E flag to set the encoding, like pg_dump has.
Robert Haas [Fri, 1 Sep 2017 16:23:16 +0000 (12:23 -0400)]
pg_dumpall: Add a -E flag to set the encoding, like pg_dump has.

Michael Paquier, reviewed by Fabien Coelho

Discussion: http://postgr.es/m/CAB7nPqQcYWmrm2n-dVaMUhYPKFU_DxQwPuUGuC4ZF+8B=dS5xQ@mail.gmail.com

6 years agoProvisional list of Major Features
Simon Riggs [Fri, 1 Sep 2017 16:20:18 +0000 (17:20 +0100)]
Provisional list of Major Features

6 years agoUse group updates when setting transaction status in clog.
Robert Haas [Fri, 1 Sep 2017 15:45:17 +0000 (11:45 -0400)]
Use group updates when setting transaction status in clog.

Commit 0e141c0fbb211bdd23783afa731e3eef95c9ad7a introduced a mechanism
to reduce contention on ProcArrayLock by having a single process clear
XIDs in the procArray on behalf of multiple processes, reducing the
need to hand the lock around.  A previous attempt to introduce a similar
mechanism for CLogControlLock in ccce90b398673d55b0387b3de66639b1b30d451b
crashed and burned, but the design problem which resulted in those
failures is believed to have been corrected in this version.

Amit Kapila, with some cosmetic changes by me.  See the previous commit
message for additional credits.

Discussion: http://postgr.es/m/CAA4eK1KudxzgWhuywY_X=yeSAhJMT4DwCjroV5Ay60xaeB2Eew@mail.gmail.com

6 years agoFix two-phase commit test for recovery mode
Alvaro Herrera [Fri, 1 Sep 2017 14:51:55 +0000 (16:51 +0200)]
Fix two-phase commit test for recovery mode

The original code had a race condition because it never ensured the
standby was caught up before proceeding; add a wait similar to every
other place that does this.

Author: MichaĆ«l Paquier
Discussion: https://postgr.es/m/CAB7nPqTm9p+LCm1mVJYvgpwagRK+uibT-pKq0O2-paOWxT62jw@mail.gmail.com

6 years agoRestore behavior for replication origin drop
Alvaro Herrera [Fri, 1 Sep 2017 14:30:02 +0000 (16:30 +0200)]
Restore behavior for replication origin drop

Do for replication origins what the previous commit did for replication
slots: restore the original behavior of replication origin drop to raise
an error rather than blocking, because users might be depending on the
original behavior.  Maintain the blocking behavior when invoked
internally from logical replication subscription handling.

Discussion: https://postgr.es/m/20170830133922.tlpo3lgfejm4n2cs@alvherre.pgsql

6 years agoAvoid race condition in logical replication test
Simon Riggs [Fri, 1 Sep 2017 13:55:44 +0000 (14:55 +0100)]
Avoid race condition in logical replication test

Wait for slot to become inactive before continuing.

Author: Petr Jelinek

6 years agoAdd a WAIT option to DROP_REPLICATION_SLOT
Alvaro Herrera [Fri, 1 Sep 2017 11:44:14 +0000 (13:44 +0200)]
Add a WAIT option to DROP_REPLICATION_SLOT

Commit 9915de6c1cb2 changed the default behavior of
DROP_REPLICATION_SLOT so that it would wait until any session holding
the slot active would release it, instead of raising an error.  But
users are already depending on the original behavior, so revert to it by
default and add a WAIT option to invoke the new behavior.

Per complaint from Simone Gotti, in
Discussion: https://postgr.es/m/CAEvsy6Wgdf90O6pUvg2wSVXL2omH5OPC-38OD4Zzgk-FXavj3Q@mail.gmail.com

6 years agoAdd note about diskspace usage of pg_commit_ts
Simon Riggs [Fri, 1 Sep 2017 06:57:05 +0000 (07:57 +0100)]
Add note about diskspace usage of pg_commit_ts

Author: Thomas Munro

6 years agoFix assorted carelessness about Datum vs. int64 vs. uint64
Robert Haas [Fri, 1 Sep 2017 04:13:25 +0000 (00:13 -0400)]
Fix assorted carelessness about Datum vs. int64 vs. uint64

Bugs introduced by commit 81c5e46c490e2426db243eada186995da5bb0ba7

6 years agoTry to repair poorly-considered code in previous commit.
Robert Haas [Fri, 1 Sep 2017 03:09:00 +0000 (23:09 -0400)]
Try to repair poorly-considered code in previous commit.

6 years agoIntroduce 64-bit hash functions with a 64-bit seed.
Robert Haas [Fri, 1 Sep 2017 02:21:21 +0000 (22:21 -0400)]
Introduce 64-bit hash functions with a 64-bit seed.

This will be useful for hash partitioning, which needs a way to seed
the hash functions to avoid problems such as a hash index on a hash
partitioned table clumping all values into a small portion of the
bucket space; it's also useful for anything that wants a 64-bit hash
value rather than a 32-bit hash value.

Just in case somebody wants a 64-bit hash value that is compatible
with the existing 32-bit hash values, make the low 32-bits of the
64-bit hash value match the 32-bit hash value when the seed is 0.

Robert Haas and Amul Sul

Discussion: http://postgr.es/m/CA+Tgmoafx2yoJuhCQQOL5CocEi-w_uG4S2xT0EtgiJnPGcHW3g@mail.gmail.com

6 years agoAvoid memory leaks when a GatherMerge node is rescanned.
Tom Lane [Thu, 31 Aug 2017 20:20:58 +0000 (16:20 -0400)]
Avoid memory leaks when a GatherMerge node is rescanned.

Rescanning a GatherMerge led to leaking some memory in the executor's
query-lifespan context, because most of the node's working data structures
were simply abandoned and rebuilt from scratch.  In practice, this might
never amount to much, given the cost of relaunching worker processes ---
but it's still pretty messy, so let's fix it.

We can rearrange things so that the tuple arrays are simply cleared and
reused, and we don't need to rebuild the TupleTableSlots either, just
clear them.  One small complication is that because we might get a
different number of workers on each iteration, we can't keep the old
convention that the leader's gm_slots[] entry is the last one; the leader
might clobber a TupleTableSlot that we need for a worker in a future
iteration.  Hence, adjust the logic so that the leader has slot 0 always,
while the active workers have slots 1..n.

Back-patch to v10 to keep all the existing versions of nodeGatherMerge.c
in sync --- because of the renumbering of the slots, there would otherwise
be a very large risk that any future backpatches in this module would
introduce bugs.

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

6 years agoExpand partitioned tables in PartDesc order.
Robert Haas [Thu, 31 Aug 2017 19:50:18 +0000 (15:50 -0400)]
Expand partitioned tables in PartDesc order.

Previously, we expanded the inheritance hierarchy in the order in
which find_all_inheritors had locked the tables, but that turns out
to block quite a bit of useful optimization.  For example, a
partition-wise join can't count on two tables with matching bounds
to get expanded in the same order.

Where possible, this change results in expanding partitioned tables in
*bound* order.  Bound order isn't well-defined for a list-partitioned
table with a null-accepting partition or for a list-partitioned table
where the bounds for a single partition are interleaved with other
partitions.  However, when expansion in bound order is possible, it
opens up further opportunities for optimization, such as
strength-reducing MergeAppend to Append when the expansion order
matches the desired sort order.

Patch by me, with cosmetic revisions by Ashutosh Bapat.

Discussion: http://postgr.es/m/CA+TgmoZrKj7kEzcMSum3aXV4eyvvbh9WD=c6m=002WMheDyE3A@mail.gmail.com

6 years agoClean up shm_mq cleanup.
Tom Lane [Thu, 31 Aug 2017 19:10:24 +0000 (15:10 -0400)]
Clean up shm_mq cleanup.

The logic around shm_mq_detach was a few bricks shy of a load, because
(contrary to the comments for shm_mq_attach) all it did was update the
shared shm_mq state.  That left us leaking a bit of process-local
memory, but much worse, the on_dsm_detach callback for shm_mq_detach
was still armed.  That means that whenever we ultimately detach from
the DSM segment, we'd run shm_mq_detach again for already-detached,
possibly long-dead queues.  This accidentally fails to fail today,
because we only ever re-use a shm_mq's memory for another shm_mq, and
multiple detach attempts on the last such shm_mq are fairly harmless.
But it's gonna bite us someday, so let's clean it up.

To do that, change shm_mq_detach's API so it takes a shm_mq_handle
not the underlying shm_mq.  This makes the callers simpler in most
cases anyway.  Also fix a few places in parallel.c that were just
pfree'ing the handle structs rather than doing proper cleanup.

Back-patch to v10 because of the risk that the revenant shm_mq_detach
callbacks would cause a live bug sometime.  Since this is an API
change, it's too late to do it in 9.6.  (We could make a variant
patch that preserves API, but I'm not excited enough to do that.)

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