]> granicus.if.org Git - postgresql/log
postgresql
7 years agoDon't explicitly mark range partitioning columns NOT NULL.
Robert Haas [Thu, 18 May 2017 17:48:10 +0000 (13:48 -0400)]
Don't explicitly mark range partitioning columns NOT NULL.

This seemed like a good idea originally because there's no way to mark
a range partition as accepting NULL, but that now seems more like a
current limitation than something we want to lock down for all time.
For example, there's a proposal to add the notion of a default
partition which accepts all rows not otherwise routed, which directly
conflicts with the idea that a range-partitioned table should never
allow nulls anywhere.  So let's change this while we still can, by
putting the NOT NULL test into the partition constraint instead of
changing the column properties.

Amit Langote and Robert Haas, reviewed by Amit Kapila

Discussion: http://postgr.es/m/8e2dd63d-c6fb-bb74-3c2b-ed6d63629c9d@lab.ntt.co.jp

7 years agoFix typo in comment.
Heikki Linnakangas [Thu, 18 May 2017 07:33:16 +0000 (10:33 +0300)]
Fix typo in comment.

Daniel Gustafsson

7 years agopg_dump: Fix dumping of slot_name = NONE
Peter Eisentraut [Thu, 18 May 2017 01:19:14 +0000 (21:19 -0400)]
pg_dump: Fix dumping of slot_name = NONE

It previously wrote out slot_name = '', which was incorrect.

Reported-by: Masahiko Sawada <sawada.mshk@gmail.com>
7 years agoImprove CREATE SUBSCRIPTION option parsing
Peter Eisentraut [Thu, 18 May 2017 00:47:37 +0000 (20:47 -0400)]
Improve CREATE SUBSCRIPTION option parsing

When creating a subscription with slot_name = NONE, we failed to check
that also create_slot = false and enabled = false were set.  This
created an invalid subscription and could later lead to a crash if a
NULL slot name was accessed.  Add more checks around that for
robustness.

Reported-by: tushar <tushar.ahuja@enterprisedb.com>
7 years agoPost-PG 10 beta1 pgperltidy run
Bruce Momjian [Wed, 17 May 2017 23:01:23 +0000 (19:01 -0400)]
Post-PG 10 beta1 pgperltidy run

7 years agoPost-PG 10 beta1 pgindent run
Bruce Momjian [Wed, 17 May 2017 20:31:56 +0000 (16:31 -0400)]
Post-PG 10 beta1 pgindent run

perltidy run not included.

7 years agoUpdate typedefs list in prep. for post-PG10 beta1 pgindent run
Bruce Momjian [Wed, 17 May 2017 19:52:16 +0000 (15:52 -0400)]
Update typedefs list in prep. for post-PG10 beta1 pgindent run

7 years agoAdd download URL for perltidy version v20090616
Bruce Momjian [Wed, 17 May 2017 19:29:37 +0000 (15:29 -0400)]
Add download URL for perltidy version v20090616

7 years agoCode review for make_partition_op_expr.
Robert Haas [Wed, 17 May 2017 18:31:48 +0000 (14:31 -0400)]
Code review for make_partition_op_expr.

It's better to use the actual keynum here rather than 0, because
someday someone might try to make list partitioning work with
multiple partitioning columns.

Jeevan Ladhe

Discussion: http://postgr.es/m/CAOgcT0M6-mx+dSX47JGJuJP1CKr4XssBFVmKNETt0OZYWpFr+w@mail.gmail.com

7 years agoRevert changes to pg_basebackup and pg_waldump usage() code.
Tom Lane [Wed, 17 May 2017 17:04:03 +0000 (13:04 -0400)]
Revert changes to pg_basebackup and pg_waldump usage() code.

Partially revert commit c079673dcb7f210617c9fc1470e6bf166d8a2971.
There were complaints that splitting switch descriptions would
complicate translation efforts.  There are probably ways to resolve
the formatting problem without doing that, but undo it while we're
discussing.

7 years agoRemove redundant has_null member from PartitionBoundInfoData.
Robert Haas [Wed, 17 May 2017 16:48:16 +0000 (12:48 -0400)]
Remove redundant has_null member from PartitionBoundInfoData.

Jeevan Ladhe, with some changes by me.

Discussion: http://postgr.es/m/CAOgcT0NZ_30-pjBpW2OgneV1ammArHkZDZ8B_KFC3q+_Xb2H9A@mail.gmail.com

7 years agoAdd more tests for CREATE SUBSCRIPTION
Peter Eisentraut [Wed, 17 May 2017 16:22:56 +0000 (12:22 -0400)]
Add more tests for CREATE SUBSCRIPTION

Add some tests for parsing different option combinations.  Fix some of
the resulting error messages for recent changes in option naming.

Author: Masahiko Sawada <sawada.mshk@gmail.com>

7 years agoMake psql handle EOF during COPY FROM STDIN properly on all platforms.
Tom Lane [Wed, 17 May 2017 16:24:19 +0000 (12:24 -0400)]
Make psql handle EOF during COPY FROM STDIN properly on all platforms.

When stdin is a terminal, it's possible to end a COPY FROM STDIN with
a keyboard EOF signal (typically control-D), and then keep on issuing
SQL commands.  One would expect another COPY FROM STDIN to work as well,
but on some platforms it did not.  This turns out to be because we were
not resetting the stream's feof() flag, and BSD-ish versions of fread()
and fgets() won't attempt to read more data if that's set.

The misbehavior is observed on BSDen (including macOS), but not Linux,
Windows, or SysV-ish Unixen, which makes this a portability bug not
just a missing feature.

Add a clearerr() call to fix the behavior, and improve the prompt that's
issued when copying from a TTY to mention that EOF signals work.

It's been like this forever, so back-patch to all supported branches.

Thomas Munro

Discussion: https://postgr.es/m/CAEepm=0MCGfYf=JAMiYhO6JPtv9-3ZfBo8fcGeCZ8oMzaw+Z+Q@mail.gmail.com

7 years agoCheck relkind of tables in CREATE/ALTER SUBSCRIPTION
Peter Eisentraut [Wed, 17 May 2017 02:57:16 +0000 (22:57 -0400)]
Check relkind of tables in CREATE/ALTER SUBSCRIPTION

We used to only check for a supported relkind on the subscriber during
replication, which is needed to ensure that the setup is valid and we
don't crash.  But it's also useful to tell the user immediately when
CREATE or ALTER SUBSCRIPTION is executed that the relation being added
to the subscription is not of a supported relkind.

Author: Petr Jelinek <petr.jelinek@2ndquadrant.com>
Reported-by: tushar <tushar.ahuja@enterprisedb.com>
7 years agopsql: publication/subscription tab completion fixes
Peter Eisentraut [Wed, 17 May 2017 02:19:21 +0000 (22:19 -0400)]
psql: publication/subscription tab completion fixes

7 years agoPreventive maintenance in advance of pgindent run.
Tom Lane [Wed, 17 May 2017 00:36:35 +0000 (20:36 -0400)]
Preventive maintenance in advance of pgindent run.

Reformat various places in which pgindent will make a mess, and
fix a few small violations of coding style that I happened to notice
while perusing the diffs from a pgindent dry run.

There is one actual bug fix here: the need-to-enlarge-the-buffer code
path in icu_convert_case was obviously broken.  Perhaps it's unreachable
in our usage?  Or maybe this is just sadly undertested.

7 years agoFix leakage of memory context header in find_all_inheritors().
Tom Lane [Tue, 16 May 2017 23:33:31 +0000 (19:33 -0400)]
Fix leakage of memory context header in find_all_inheritors().

Commit 827d6f977 contained the same misunderstanding of hash_create's API
as commit 090010f2e.  As in 5d00b764c, remove the unnecessary layer of
memory context.  (This bug is less significant than the other one, since
the extra context would be under a relatively short-lived context, but
it's still a bug.)

7 years agoRevert "Add a test for transition table usage in FOR EACH ROW trigger."
Kevin Grittner [Tue, 16 May 2017 22:15:33 +0000 (17:15 -0500)]
Revert "Add a test for transition table usage in FOR EACH ROW trigger."

This reverts commit 4a03f935b3438de27ee00d9e562ffe4e225978a9.

7 years agoAdd a test for transition table usage in FOR EACH ROW trigger.
Kevin Grittner [Tue, 16 May 2017 21:09:55 +0000 (16:09 -0500)]
Add a test for transition table usage in FOR EACH ROW trigger.

7 years agoTry to ensure that stats collector's receive buffer size is at least 100KB.
Tom Lane [Tue, 16 May 2017 19:24:52 +0000 (15:24 -0400)]
Try to ensure that stats collector's receive buffer size is at least 100KB.

Since commit 4e37b3e15, buildfarm member frogmouth has been failing
occasionally with symptoms indicating that some expected stats data is
getting dropped.  The reason that that commit changed the behavior seems
probably to be that more data is getting shoved at the collector in a short
span of time.  In current sources, the stats test's first session sends
about 9KB of data while exiting, which is probably the same as what was
sent just before wait_for_stats() in the previous test design.  But now,
the test's second session is starting up concurrently, and it sends another
2KB (presumably reflecting its initial catalog accesses).  Since frogmouth
is running on Windows XP, which reputedly has a default socket receive
buffer size of only 8KB, it is not very surprising if this has put us over
the threshold where the receive buffer can overflow and drop messages.

The same mechanism could very easily explain the intermittent stats test
failures we've been seeing for years, since background processes such
as the bgwriter will sometimes send data concurrently with all this, and
could thus cause occasional buffer overflows.

Hence, insert some code into pgstat_init() to increase the stats socket's
receive buffer size to 100KB if it's less than that.  (On failure, emit a
LOG message, but keep going.)  Modern systems seem to have default sizes
in the range of 100KB-250KB, but older platforms don't.  I couldn't find
any platforms that wouldn't accept 100KB, so in theory this won't cause
any portability problems.

If this is successful at reducing the buildfarm failure rate in HEAD,
we should back-patch it, because it's certain that similar buffer overflows
happen in the field on platforms with small buffer sizes.  Going forward,
there might be an argument for trying to increase the buffer size even
more, but let's take a baby step first.

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

7 years agoFix relcache leak when row triggers on partitions are fired by COPY.
Robert Haas [Tue, 16 May 2017 16:46:32 +0000 (12:46 -0400)]
Fix relcache leak when row triggers on partitions are fired by COPY.

Thomas Munro, reviewed by Amit Langote

Discussion: http://postgr.es/m/CAEepm=15Jss-yhFApuKzxcoCuFnb8TR8iQiWMjG=CLYPx48QLw@mail.gmail.com

7 years agodoc: Remove unnecessary RETURN statements from example.
Robert Haas [Tue, 16 May 2017 15:35:23 +0000 (11:35 -0400)]
doc: Remove unnecessary RETURN statements from example.

Paul Jungwirth, reviewed by Ashutosh Bapat.

Discussion: http://postgr.es/m/e24a6a6d-5670-739b-00f3-41a226a80f25@illuminatedcomputing.com

7 years agoIn SSL tests, don't scribble on permissions of a repo file.
Tom Lane [Tue, 16 May 2017 03:27:51 +0000 (23:27 -0400)]
In SSL tests, don't scribble on permissions of a repo file.

Modifying the permissions of a persistent file isn't really much nicer
than modifying its contents, even if git doesn't currently notice it.
Adjust the test script to make a copy and set the permissions of that
instead.

Michael Paquier, per a gripe from me.  Back-patch to 9.5 where these
tests were introduced.

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

7 years agoUpdate CREATE SUBSCRIPTION docs for recent syntax change.
Tom Lane [Tue, 16 May 2017 02:06:27 +0000 (22:06 -0400)]
Update CREATE SUBSCRIPTION docs for recent syntax change.

Masahiko Sawada

7 years agoStamp 10beta1. REL_10_BETA1
Tom Lane [Mon, 15 May 2017 21:20:59 +0000 (17:20 -0400)]
Stamp 10beta1.

7 years agogit-ignore intermediate files from new docs toolchain.
Tom Lane [Mon, 15 May 2017 19:48:23 +0000 (15:48 -0400)]
git-ignore intermediate files from new docs toolchain.

Building PDFs with the new toolchain creates *.fo temporary files.

7 years agoAdd missing apostrophe.
Robert Haas [Mon, 15 May 2017 19:41:15 +0000 (15:41 -0400)]
Add missing apostrophe.

Masahiko Sawada

Discussion: http://postgr.es/m/CAD21AoAzaR_XV7j7Wk9-QYXaFoT8H4egKwXvFY63wc8Lw2C9cg@mail.gmail.com

7 years agoUpdate oidjoins regression test for v10.
Tom Lane [Mon, 15 May 2017 18:04:03 +0000 (14:04 -0400)]
Update oidjoins regression test for v10.

7 years agoAdd assertion to quiet Coverity
Peter Eisentraut [Mon, 15 May 2017 17:59:58 +0000 (13:59 -0400)]
Add assertion to quiet Coverity

7 years agoTranslation updates
Peter Eisentraut [Mon, 15 May 2017 16:19:54 +0000 (12:19 -0400)]
Translation updates

Source-Git-URL: git://git.postgresql.org/git/pgtranslation/messages.git
Source-Git-Hash: 398beeef4921df0956f917becd7b5669d2a8a5c4

7 years agodoc: Remove unused file
Peter Eisentraut [Mon, 15 May 2017 16:09:19 +0000 (12:09 -0400)]
doc: Remove unused file

sql.sgml has not been part of the documentation since forever, so it's
pointless to keep it around.

7 years agoFix bogus syntax for CREATE PUBLICATION commands emitted by pg_dump.
Tom Lane [Mon, 15 May 2017 15:48:39 +0000 (11:48 -0400)]
Fix bogus syntax for CREATE PUBLICATION commands emitted by pg_dump.

Original coding was careless about where to insert commas.

Masahiko Sawada

Discussion: https://postgr.es/m/3427593a-61aa-b17e-64ef-383b7742d6d9@enterprisedb.com

7 years agoFix unsafe reference into relcache in constructed CommentStmt.
Tom Lane [Mon, 15 May 2017 15:33:44 +0000 (11:33 -0400)]
Fix unsafe reference into relcache in constructed CommentStmt.

The CommentStmt made by RebuildConstraintComment() has to pstrdup the
relation name, else it will contain a dangling pointer after that
relcache entry is flushed.  (I'm less sure that pstrdup'ing conname
is necessary, but let's be safe.)  Failure to do this leads to weird
errors or crashes, as reported by Marko Elezovic.

Bug introduced by commit e42375fc8, so back-patch to 9.5 as that was.

Fix by David Rowley, regression test by Michael Paquier

Discussion: https://postgr.es/m/DB6PR03MB30775D58E732D4EB0C13725B9AE00@DB6PR03MB3077.eurprd03.prod.outlook.com

7 years agoFix ALTER SEQUENCE locking
Peter Eisentraut [Wed, 10 May 2017 03:35:31 +0000 (23:35 -0400)]
Fix ALTER SEQUENCE locking

In 1753b1b027035029c2a2a1649065762fafbf63f3, the pg_sequence system
catalog was introduced.  This made sequence metadata changes
transactional, while the actual sequence values are still behaving
nontransactionally.  This requires some refinement in how ALTER
SEQUENCE, which operates on both, locks the sequence and the catalog.

The main problems were:

- Concurrent ALTER SEQUENCE causes "tuple concurrently updated" error,
  caused by updates to pg_sequence catalog.

- Sequence WAL writes and catalog updates are not protected by same
  lock, which could lead to inconsistent recovery order.

- nextval() disregarding uncommitted ALTER SEQUENCE changes.

To fix, nextval() and friends now lock the sequence using
RowExclusiveLock instead of AccessShareLock.  ALTER SEQUENCE locks the
sequence using ShareRowExclusiveLock.  This means that nextval() and
ALTER SEQUENCE block each other, and ALTER SEQUENCE on the same sequence
blocks itself.  (This was already the case previously for the OWNER TO,
RENAME, and SET SCHEMA variants.)  Also, rearrange some code so that the
entire AlterSequence is protected by the lock on the sequence.

As an exception, use reduced locking for ALTER SEQUENCE ... RESTART.
Since that is basically a setval(), it does not require the full locking
of other ALTER SEQUENCE actions.  So check whether we are only running a
RESTART and run with less locking if so.

Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
Reported-by: Jason Petersen <jason@citusdata.com>
Reported-by: Andres Freund <andres@anarazel.de>
7 years agoFix typo in comment
Magnus Hagander [Mon, 15 May 2017 09:08:02 +0000 (11:08 +0200)]
Fix typo in comment

Michael Paquier

7 years agostats regression test's wait_for_stats() must check timestamp too.
Tom Lane [Mon, 15 May 2017 03:33:03 +0000 (23:33 -0400)]
stats regression test's wait_for_stats() must check timestamp too.

pg_stat_get_snapshot_timestamp() returns the timestamp seen in the "global"
stats file.  Because pgstat_write_statsfiles() writes per-DB stats files
before the global file (or at least before renaming it into place), there
is a window where the test backend can see all the stats updates that
wait_for_stats() was checking for (all of which come from the per-DB file)
but also see the same global stats file it had seen at the start of the
test script.  This results in a failure in only the "snapshot_newer" query,
as reported by a couple of buildfarm members recently.

I suspect that this ought to be back-patched.  Commit 4e37b3e15 has
evidently increased the probability of this window getting hit, but
it's not apparent why it could not have been hit before.  I'll refrain
for the moment though.

7 years agodoc: update the "current as of" date in the PG 10 release notes
Bruce Momjian [Mon, 15 May 2017 03:15:43 +0000 (23:15 -0400)]
doc:  update the "current as of" date in the PG 10 release notes

7 years agoMake pgstat tabstat lookup hash table less fragile.
Tom Lane [Mon, 15 May 2017 02:52:41 +0000 (22:52 -0400)]
Make pgstat tabstat lookup hash table less fragile.

Code review for commit 090010f2e.

Fix cases where an elog(ERROR) partway through a function would leave the
persistent data structures in a corrupt state.  pgstat_report_stat got this
wrong by invalidating PgStat_TableEntry structs before removing hashtable
entries pointing to them, and get_tabstat_entry got it wrong by ignoring
the possibility of palloc failure after it had already created a hashtable
entry.

Also, avoid leaking a memory context per transaction, which the previous
code did through misunderstanding hash_create's API.  We do not need to
create a context to hold the hash table; hash_create will do that.
(The leak wasn't that large, amounting to only a memory context header
per iteration, but it's still surprising that nobody noticed it yet.)

7 years agodoc: update PG 10 release notes for recent changes
Bruce Momjian [Mon, 15 May 2017 02:45:11 +0000 (22:45 -0400)]
doc:  update PG 10 release notes for recent changes

7 years agoMake stats regression test more robust in the face of parallel query.
Tom Lane [Mon, 15 May 2017 01:39:10 +0000 (21:39 -0400)]
Make stats regression test more robust in the face of parallel query.

Commit 60690a6fe attempted to fix the wait_for_stats() function in this
test so that it would wait properly if the tenk2 scans were done in
parallel workers instead of the main session (typically as a consequence of
force_parallel_mode being turned on).  However, we made it test for whether
the main session's actions had been reported by looking for inserts on
'trunc_stats_test'.  This is the Wrong Thing, because those aren't the last
updates we expect the main session to do.  As shown by recent failures on
buildfarm member frogmouth, it's entirely likely that the trunc_stats_test
updates will be reported in a separate message from later updates, which
means there can be a window in which wait_for_stats() will exit but not all
the updates we are expecting to see will have arrived.  We should test for
the last updates we're expecting, namely those on 'trunc_stats_test4'.

Unfortunately, I doubt that this explains frogmouth's failures, because
there's no reason to believe that it's running the tenk2 queries in
parallel.  Still, the test is wrong on its own terms, so fix and back-patch
to 9.6 where parallel query came in.

7 years agoAttempt to fix compiler warning.
Robert Haas [Mon, 15 May 2017 00:59:28 +0000 (20:59 -0400)]
Attempt to fix compiler warning.

Per a report from Tom Lane, newer versions of gcc apparently think
that partexprs_item_saved can be used uninitialized.  Try to convince
them otherwise.

7 years agoEdit SGML documentation related to extended statistics.
Tom Lane [Sun, 14 May 2017 23:15:52 +0000 (19:15 -0400)]
Edit SGML documentation related to extended statistics.

Use the "statistics object" terminology uniformly here too.  Assorted
copy-editing.  Put new catalogs.sgml sections into alphabetical order.

7 years agoFix maintenance hazards caused by ill-considered use of default: cases.
Tom Lane [Sun, 14 May 2017 17:32:59 +0000 (13:32 -0400)]
Fix maintenance hazards caused by ill-considered use of default: cases.

Remove default cases from assorted switches over ObjectClass and some
related enum types, so that we'll get compiler warnings when someone
adds a new enum value without accounting for it in all these places.

In passing, re-order some switch cases as needed to match the declaration
of enum ObjectClass.  OK, that's just neatnik-ism, but I dislike code
that looks like it was assembled with the help of a dartboard.

Discussion: https://postgr.es/m/20170512221010.nglatgt5azzdxjlj@alvherre.pgsql

7 years agoFix handling of extended statistics during ALTER COLUMN TYPE.
Tom Lane [Sun, 14 May 2017 16:22:16 +0000 (12:22 -0400)]
Fix handling of extended statistics during ALTER COLUMN TYPE.

ALTER COLUMN TYPE on a column used by a statistics object fails since
commit 928c4de30, because the relevant switch in ATExecAlterColumnType
is unprepared for columns to have dependencies from OCLASS_STATISTIC_EXT
objects.

Although the existing types of extended statistics don't actually need us
to do any work for a column type change, it seems completely indefensible
that that assumption is hidden behind the failure of an unrelated module
to contain any code for the case.  Hence, create and call an API function
in statscmds.c where the assumption can be explained, and where we could
add code to deal with the problem when it inevitably becomes real.

Also, the reason this wasn't handled before, neither for extended stats
nor for the last half-dozen new OCLASS kinds :-(, is that the default:
in that switch suppresses compiler warnings, allowing people to miss the
need to consider it when adding an OCLASS.  We don't really need a default
because surely getObjectClass should only return valid values of the enum;
so remove it, and add the missed OCLASS entries where they should be.

Discussion: https://postgr.es/m/20170512221010.nglatgt5azzdxjlj@alvherre.pgsql

7 years agoUpdate config.guess and config.sub
Peter Eisentraut [Sun, 14 May 2017 15:09:34 +0000 (11:09 -0400)]
Update config.guess and config.sub

7 years agoRemove no-longer-needed fields of Hash plan nodes.
Tom Lane [Sun, 14 May 2017 15:07:40 +0000 (11:07 -0400)]
Remove no-longer-needed fields of Hash plan nodes.

skewColType/skewColTypmod are no longer used in the wake of commit
9aab83fc5, and seem unlikely to be wanted in future, so let's drop 'em.

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

7 years agoStandardize terminology for pg_statistic_ext entries.
Tom Lane [Sun, 14 May 2017 14:54:47 +0000 (10:54 -0400)]
Standardize terminology for pg_statistic_ext entries.

Consistently refer to such an entry as a "statistics object", not just
"statistics" or "extended statistics".  Previously we had a mismash of
terms, accompanied by utter confusion as to whether the term was
singular or plural.  That's not only grating (at least to the ear of
a native English speaker) but could be outright misleading, eg in error
messages that seemed to be referring to multiple objects where only one
could be meant.

This commit fixes the code and a lot of comments (though I may have
missed a few).  I also renamed two new SQL functions,
pg_get_statisticsextdef -> pg_get_statisticsobjdef
pg_statistic_ext_is_visible -> pg_statistics_obj_is_visible
to conform better with this terminology.

I have not touched the SGML docs other than fixing those function
names; the docs certainly need work but it seems like a separable task.

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

7 years agoSuppress indentation from Data::Dumper in regression tests
Andrew Dunstan [Sun, 14 May 2017 05:10:18 +0000 (01:10 -0400)]
Suppress indentation from Data::Dumper in regression tests

Ultra-modern versions of the perl Data::Dumper module have apparently
changed how they indent output. Instead of trying to keep up we choose
to tell it to supporess all indentation in the hstore_plperl regression
tests.

Backpatch to 9.5 where this feature was introduced.

7 years agoSpecify --outputdir for isolation install check, not just plain check.
Andres Freund [Sat, 13 May 2017 22:13:17 +0000 (15:13 -0700)]
Specify --outputdir for isolation install check, not just plain check.

This should probably have been part of 60f826c5e62.

Reported-By: Andrew Gierth
7 years agoAvoid superfluous work for commits during logical slot creation.
Andres Freund [Sat, 13 May 2017 21:47:41 +0000 (14:47 -0700)]
Avoid superfluous work for commits during logical slot creation.

Before 955a684e0401 logical decoding snapshot maintenance needed to
cope with transactions it might not have seen in their entirety. For
such transactions we'd to assume they modified the catalog (could have
happened before we were watching), and thus a new snapshot had to be
built, and distributed to concurrently running transactions.

That's problematic because building a new snapshot isn't that cheap ,
especially as the the array of committed transactions needs to be
sorted.  When creating a slot on a server with a lot of transactions,
this could make logical slot creation infeasibly expensive.

After 955a684e0401 there's no need to deal with transaction that
aren't guaranteed to be fully observable.  That allows to avoid
building snapshots for transactions that haven't modified catalog,
even before reaching consistency.

While this isn't necessarily a bugfix, slot creation being impossible
in some production workloads, is severe enough to warrant
backpatching.

Author: Andres Freund, based on a quite different patch from Petr Jelinek
Analyzed-By: Petr Jelinek
Reviewed-By: Petr Jelinek
Discussion: https://postgr.es/m/f37e975c-908f-858e-707f-058d3b1eb214@2ndquadrant.com
Backpatch: 9.4-, where logical decoding has been introduced

7 years agoFix race condition leading to hanging logical slot creation.
Andres Freund [Sat, 13 May 2017 21:21:00 +0000 (14:21 -0700)]
Fix race condition leading to hanging logical slot creation.

The snapshot assembly during the creation of logical slots relied
waiting for transactions in xl_running_xacts to end, by checking for
their commit/abort records.  Unfortunately, despite locking, it is
possible to see an xl_running_xact record listing transactions as
ready, that have already WAL-logged an commit/abort record, as the
locking just prevents the ProcArray to be adjusted, and the commit
record has to be logged first.

That lead to either delayed or hanging snapshot creation, because
snapbuild.c would wait "forever" to see commit/abort records for some
transactions.  That hang resolved only if a xl_running_xacts record
without any running transactions happened to be logged, far from
certain on a busy server.

It's impractical to prevent that via more heavyweight locking, the
likelihood of deadlocks and significantly increased contention would
be too big.

Instead change the initial snapshot creation to be solely based on
tracking the oldest running transaction via
xl_running_xacts->oldestRunningXid - that actually ends up
significantly simplifying the code.  That has two disadvantages:
1) Because we cannot fully "trust" the contents of xl_running_xacts,
   we cannot use it to build the initial snapshot.  Instead we have to
   wait twice for all running transactions to finish.
2) Previously a slot, unless the race occurred, could be created when
   the all transaction perceived as running based on commit/abort
   records, now we have to wait for the next xl_running_xacts record.
To address that, trigger logging new xl_running_xacts record from
within snapbuild.c exactly when necessary.

Unfortunately snabuild.c's SnapBuild is stored on disk, one of the
stupider ideas of a certain Mr Freund, so we can't change it in a
minor release.  As this is going to be backpatched, we have to hack
around a bit to keep on-disk compatibility.  A later commit will
rejigger that on master.

Author: Andres Freund, based on a quite different patch from Petr Jelinek
Analyzed-By: Petr Jelinek
Reviewed-By: Petr Jelinek
Discussion: https://postgr.es/m/f37e975c-908f-858e-707f-058d3b1eb214@2ndquadrant.com
Backpatch: 9.4-, where logical decoding has been introduced

7 years agoRedesign get_attstatsslot()/free_attstatsslot() for more safety and speed.
Tom Lane [Sat, 13 May 2017 19:14:39 +0000 (15:14 -0400)]
Redesign get_attstatsslot()/free_attstatsslot() for more safety and speed.

The mess cleaned up in commit da0759600 is clear evidence that it's a
bug hazard to expect the caller of get_attstatsslot()/free_attstatsslot()
to provide the correct type OID for the array elements in the slot.
Moreover, we weren't even getting any performance benefit from that,
since get_attstatsslot() was extracting the real type OID from the array
anyway.  So we ought to get rid of that requirement; indeed, it would
make more sense for get_attstatsslot() to pass back the type OID it found,
in case the caller isn't sure what to expect, which is likely in binary-
compatible-operator cases.

Another problem with the current implementation is that if the stats array
element type is pass-by-reference, we incur a palloc/memcpy/pfree cycle
for each element.  That seemed acceptable when the code was written because
we were targeting O(10) array sizes --- but these days, stats arrays are
almost always bigger than that, sometimes much bigger.  We can save a
significant number of cycles by doing one palloc/memcpy/pfree of the whole
array.  Indeed, in the now-probably-common case where the array is toasted,
that happens anyway so this method is basically free.  (Note: although the
catcache code will inline any out-of-line toasted values, it doesn't
decompress them.  At the other end of the size range, it doesn't expand
short-header datums either.  In either case, DatumGetArrayTypeP would have
to make a copy.  We do end up using an extra array copy step if the element
type is pass-by-value and the array length is neither small enough for a
short header nor large enough to have suffered compression.  But that
seems like a very acceptable price for winning in pass-by-ref cases.)

Hence, redesign to take these insights into account.  While at it,
convert to an API in which we fill a struct rather than passing a bunch
of pointers to individual output arguments.  That will make it less
painful if we ever want further expansion of what get_attstatsslot can
pass back.

It's certainly arguable that this is new development and not something to
push post-feature-freeze.  However, I view it as primarily bug-proofing
and therefore something that's better to have sooner not later.  Since
we aren't quite at beta phase yet, let's put it in.

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

7 years agoTeach \d+ to show partitioning constraints.
Robert Haas [Sat, 13 May 2017 16:04:53 +0000 (12:04 -0400)]
Teach \d+ to show partitioning constraints.

The fact that we didn't have this in the first place is likely why
the problem fixed by f8bffe9e6d700fd34759a92e47930ce9ba7dcbd5
escaped detection.

Patch by Amit Langote, reviewed and slightly adjusted by me.

Discussion: http://postgr.es/m/CA+TgmoYWnV2GMnYLG-Czsix-E1WGAbo4D+0tx7t9NdfYBDMFsA@mail.gmail.com

7 years agoFix multi-column range partitioning constraints.
Robert Haas [Sat, 13 May 2017 15:35:30 +0000 (11:35 -0400)]
Fix multi-column range partitioning constraints.

The old logic was just plain wrong.

Report by Olaf Gawenda.  Patch by Amit Langote, reviewed by
Beena Emerson and by me.  Minor adjustments by me also.

7 years agoAvoid hard-wired sleep delays in stats regression test.
Tom Lane [Sat, 13 May 2017 13:42:12 +0000 (09:42 -0400)]
Avoid hard-wired sleep delays in stats regression test.

On faster machines, the overall runtime for running the core regression
tests is under twenty seconds these days, of which the hard-wired delays
in the stats test are a significant fraction.  But on closer inspection,
it seems like we shouldn't need those.

The initial 2-second delay is there only to reduce the risk of the test's
stats messages not getting sent due to contention.  But analysis of the
last ten years' worth of buildfarm runs shows no evidence that such
failures actually occur.  (We do see failures that look like stats
messages not getting sent, particularly on Windows; but there is little
reason to believe that the initial delay reduces their frequency.)

The later 1-second delay is there to ensure that our session's stats
will have gotten sent.  But we could also do that by starting a fresh
session, which takes well under 1 second even on very slow machines.

Hence, let's remove both delays and see what happens.  The first delay
was the only test of pg_sleep_for() in the regression tests, but we can
move that responsibility into wait_for_stats().

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

7 years agoUse a better way of skipping all subscription tests on Windows
Andrew Dunstan [Sat, 13 May 2017 06:47:11 +0000 (02:47 -0400)]
Use a better way of skipping all subscription tests on Windows

This way we only need to specify the number of tests in one place, and
the output is also less verbose.

7 years agoComplete tab completion for DROP STATISTICS
Alvaro Herrera [Sat, 13 May 2017 04:05:48 +0000 (01:05 -0300)]
Complete tab completion for DROP STATISTICS

Tab-completing DROP STATISTICS would only work if you started writing
the schema name containing the statistics object, because the visibility
clause was missing.  To add it, we need to add SQL-callable support for
testing visibility of a statistics object, like all other object types
already have.

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

7 years agoAvoid searching for callback functions in CallSyscacheCallbacks().
Tom Lane [Fri, 12 May 2017 23:05:13 +0000 (19:05 -0400)]
Avoid searching for callback functions in CallSyscacheCallbacks().

We have now grown enough registerable syscache-invalidation callback
functions that the original assumption that there would be few of them
is causing performance problems.  In particular, let's fix things so that
CallSyscacheCallbacks doesn't have to search the whole array to find
which callback(s) to invoke for a given cache ID.  Preserve the original
behavior that callbacks are called in order of registration, just in
case there's someplace that depends on that (which I doubt).

In support of this, export the number of syscaches from syscache.h.
People could have found that out anyway from the enum, but adding a
#define makes that much safer.

This provides a useful additional speedup in Mathieu Fenniak's
logical-decoding test case, although we're reaching the point of
diminishing returns there.  I think any further improvement will have
to come from reducing the number of cache invalidations that are
triggered in the first place.  Still, we can hope that this change
gives some incremental benefit for all invalidation scenarios.

Back-patch to 9.4 where logical decoding was introduced.

Discussion: https://postgr.es/m/CAHoiPjzea6N0zuCi=+f9v_j94nfsy6y8SU7-=bp4=7qw6_i=Rg@mail.gmail.com

7 years agodoc: update markup for release note "release date" block
Bruce Momjian [Fri, 12 May 2017 22:31:55 +0000 (18:31 -0400)]
doc:  update markup for release note "release date" block

This has to be backpatched to all supported releases so release markup
added to HEAD and copied to back branches matches the existing markup.

Reported-by: Peter Eisentraut
Discussion: 2b8a2552-fffa-f7c8-97c5-14db47a87731@2ndquadrant.com

Author: initial patch and sample markup by Peter Eisentraut

Backpatch-through: 9.2

7 years agoReduce initial size of RelfilenodeMapHash.
Tom Lane [Fri, 12 May 2017 22:30:02 +0000 (18:30 -0400)]
Reduce initial size of RelfilenodeMapHash.

A test case provided by Mathieu Fenniak shows that hash_seq_search'ing
this hashtable can consume a very significant amount of overhead during
logical decoding, which triggers frequent cache invalidation.  Testing
suggests that the actual population of the hashtable is often no more
than a few dozen entries, so we can cut the overhead just by dropping
the initial number of buckets down from 1024 --- I chose to cut it to 64.
(In situations where we do have a significant number of entries, we
shouldn't get any real penalty from doing this, as the dynahash.c code
will resize the hashtable automatically.)

This gives a further factor-of-two savings in Mathieu's test case.
That may be overly optimistic for real-world benefit, as real cases
may have larger average table populations, but it's hard to see it
turning into a net negative for any workload.

Back-patch to 9.4 where relfilenodemap.c was introduced.

Discussion: https://postgr.es/m/CAHoiPjzea6N0zuCi=+f9v_j94nfsy6y8SU7-=bp4=7qw6_i=Rg@mail.gmail.com

7 years agogetObjectDescription: support extended statistics
Alvaro Herrera [Fri, 12 May 2017 22:22:03 +0000 (19:22 -0300)]
getObjectDescription: support extended statistics

This was missed in 7b504eb282ca.

Remove the "default:" clause in the switch, to avoid this problem in the
future.  Other switches involving the same enum should probably be
changed in the same way, but are not touched by this patch.

Discussion: https://postgr.es/m/20170512204800.iqt2uwyx3c32j45r@alvherre.pgsql

7 years agoAvoid searching for the target catcache in CatalogCacheIdInvalidate.
Tom Lane [Fri, 12 May 2017 22:17:29 +0000 (18:17 -0400)]
Avoid searching for the target catcache in CatalogCacheIdInvalidate.

A test case provided by Mathieu Fenniak shows that the initial search for
the target catcache in CatalogCacheIdInvalidate consumes a very significant
amount of overhead in cases where cache invalidation is triggered but has
little useful work to do.  There is no good reason for that search to exist
at all, as the index array maintained by syscache.c allows direct lookup of
the catcache from its ID.  We just need a frontend function in syscache.c,
matching the division of labor for most other cache-accessing operations.

While there's more that can be done in this area, this patch alone reduces
the runtime of Mathieu's example by 2X.  We can hope that it offers some
useful benefit in other cases too, although usually cache invalidation
overhead is not such a striking fraction of the total runtime.

Back-patch to 9.4 where logical decoding was introduced.  It might be
worth going further back, but presently the only case we know of where
cache invalidation is really a significant burden is in logical decoding.
Also, older branches have fewer catcaches, reducing the possible benefit.

(Note: although this nominally changes catcache's API, we have always
documented CatalogCacheIdInvalidate as a private function, so I would
have little sympathy for an external module calling it directly.  So
backpatching should be fine.)

Discussion: https://postgr.es/m/CAHoiPjzea6N0zuCi=+f9v_j94nfsy6y8SU7-=bp4=7qw6_i=Rg@mail.gmail.com

7 years agoFix dependencies for extended statistics objects.
Tom Lane [Fri, 12 May 2017 20:26:31 +0000 (16:26 -0400)]
Fix dependencies for extended statistics objects.

A stats object ought to have a dependency on each individual column
it reads, not the entire table.  Doing this honestly lets us get rid
of the hard-wired logic in RemoveStatisticsExt, which seems to have
been misguidedly modeled on RemoveStatistics; and it will be far easier
to extend to multiple tables later.

Also, add overlooked dependency on owner, and make the dependency on
schema be NORMAL like every other such dependency.

There remains some unfinished work here, which is to allow statistics
objects to be extension members.  That takes more effort than just
adding the dependency call, though, so I left it out for now.

initdb forced because this changes the set of pg_depend records that
should exist for a statistics object.

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

7 years agoChange CREATE STATISTICS syntax
Alvaro Herrera [Fri, 12 May 2017 17:59:23 +0000 (14:59 -0300)]
Change CREATE STATISTICS syntax

Previously, we had the WITH clause in the middle of the command, where
you'd specify both generic options as well as statistic types.  Few
people liked this, so this commit changes it to remove the WITH keyword
from that clause and makes it accept statistic types only.  (We
currently don't have any generic options, but if we invent in the
future, we will gain a new WITH clause, probably at the end of the
command).

Also, the column list is now specified without parens, which makes the
whole command look more similar to a SELECT command.  This change will
let us expand the command to supporting expressions (not just columns
names) as well as multiple tables and their join conditions.

Tom added lots of code comments and fixed some parts of the CREATE
STATISTICS reference page, too; more changes in this area are
forthcoming.  He also fixed a potential problem in the alter_generic
regression test, reducing verbosity on a cascaded drop to avoid
dependency on message ordering, as we do in other tests.

Tom also closed a security bug: we documented that table ownership was
required in order to create a statistics object on it, but didn't
actually implement it.

Implement tab-completion for statistics objects.  This can stand some
more improvement.

Authors: Alvaro Herrera, with lots of cleanup by Tom Lane
Discussion: https://postgr.es/m/20170420212426.ltvgyhnefvhixm6i@alvherre.pgsql

7 years agoReplace another "transaction log" with "write-ahead log"
Peter Eisentraut [Fri, 12 May 2017 17:53:24 +0000 (13:53 -0400)]
Replace another "transaction log" with "write-ahead log"

Reported-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
7 years agoStandardize "WAL location" terminology
Peter Eisentraut [Fri, 12 May 2017 17:51:27 +0000 (13:51 -0400)]
Standardize "WAL location" terminology

Other previously used terms were "WAL position" or "log position".

7 years agoReplace "transaction log" with "write-ahead log"
Peter Eisentraut [Fri, 12 May 2017 15:49:56 +0000 (11:49 -0400)]
Replace "transaction log" with "write-ahead log"

This makes documentation and error messages match the renaming of "xlog"
to "wal" in APIs and file naming.

7 years agoHonor PROVE_FLAGS environment setting
Andrew Dunstan [Fri, 12 May 2017 15:11:49 +0000 (11:11 -0400)]
Honor PROVE_FLAGS environment setting

On MSVC builds and on back branches that means removing the hardcoded
--verbose setting. On master for Unix that means removing the empty
setting in the global Makefile so that the value can be acquired from
the environment as well as from the make arguments.

Backpatch to 9.4 where we introduced TAP tests

7 years agoAdd libxml2 include path for MSVC builds
Andrew Dunstan [Fri, 12 May 2017 14:17:54 +0000 (10:17 -0400)]
Add libxml2 include path for MSVC builds

On Unix this path is detected via the use of xml2-config, but that's not
available on Windows. This means that users building with libxml2 will
no longer need to move things around from the standard libxml2
installation for MSVC builds.

Backpatch to all live branches.

7 years agopg_dump: Add --no-publications option
Peter Eisentraut [Fri, 12 May 2017 13:15:40 +0000 (09:15 -0400)]
pg_dump: Add --no-publications option

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

7 years agoRework the options syntax for logical replication commands
Peter Eisentraut [Fri, 12 May 2017 12:57:01 +0000 (08:57 -0400)]
Rework the options syntax for logical replication commands

For CREATE/ALTER PUBLICATION/SUBSCRIPTION, use similar option style as
other statements that use a WITH clause for options.

Author: Petr Jelinek <petr.jelinek@2ndquadrant.com>

7 years agoAvoid tests which crash the calling process on Windows
Andrew Dunstan [Fri, 12 May 2017 10:41:23 +0000 (06:41 -0400)]
Avoid tests which crash the calling process on Windows

Certain recovery tests use the Perl IPC::Run module's start/kill_kill
method of processing. On at least some versions of perl this causes the
whole process and its caller to crash. If we ever find a better way of
doing these tests they can be re-enabled on this platform. This does not
affect Mingw or Cygwin builds, which use a different perl and a
different shell and so are not affected.

7 years agoLag tracking for logical replication
Simon Riggs [Fri, 12 May 2017 09:50:56 +0000 (10:50 +0100)]
Lag tracking for logical replication

Lag tracking is called for each commit, but we introduce
a pacing delay to ensure we don't swamp the lag tracker.

Author: Petr Jelinek, with minor pacing delay code from me

7 years agoDoc fix: scale(numeric) returns integer, not numeric.
Tom Lane [Thu, 11 May 2017 22:09:22 +0000 (18:09 -0400)]
Doc fix: scale(numeric) returns integer, not numeric.

Thinko in commit abb173392, which introduced this function.

Report: https://postgr.es/m/20170511215234.1795.54347@wrigleys.postgresql.org

7 years agoIncrease MAX_SYSCACHE_CALLBACKS to provide more room for extensions.
Tom Lane [Thu, 11 May 2017 18:51:21 +0000 (14:51 -0400)]
Increase MAX_SYSCACHE_CALLBACKS to provide more room for extensions.

Increase from the historical value of 32 to 64.  We are up to 31 callers
of CacheRegisterSyscacheCallback() in HEAD, so if they were all to be
exercised in one process that would leave only one slot for add-on modules.
It's probably not possible for that to happen, but still we clearly need
more daylight here.  (At some point it might be worth making the array
dynamically resizable; but since we've never heard a complaint of "out of
syscache_callback_list slots" happening in the field, I doubt it's worth
it yet.)

Back-patch as far as 9.4, which is where we increased the companion limit
MAX_RELCACHE_CALLBACKS (cf commit f01d1ae3a).  It's not as urgent in
released branches, which have only a couple dozen call sites in core, but
it still seems that somebody might hit the limit before these branches die.

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

7 years agoRename WAL-related functions and views to use "lsn" not "location".
Tom Lane [Thu, 11 May 2017 15:49:59 +0000 (11:49 -0400)]
Rename WAL-related functions and views to use "lsn" not "location".

Per discussion, "location" is a rather vague term that could refer to
multiple concepts.  "LSN" is an unambiguous term for WAL locations and
should be preferred.  Some function names, view column names, and function
output argument names used "lsn" already, but others used "location",
as well as yet other terms such as "wal_position".  Since we've already
renamed a lot of things in this area from "xlog" to "wal" for v10,
we may as well incur a bit more compatibility pain and make these names
all consistent.

David Rowley, minor additional docs hacking by me

Discussion: https://postgr.es/m/CAKJS1f8O0njDKe8ePFQ-LK5-EjwThsDws6ohJ-+c6nWK+oUxtg@mail.gmail.com

7 years agoRevert "Permit dump/reload of not-too-large >1GB tuples"
Alvaro Herrera [Wed, 10 May 2017 21:41:27 +0000 (18:41 -0300)]
Revert "Permit dump/reload of not-too-large >1GB tuples"

This reverts commits fa2fa9955280 and 42f50cb8fa98.

While the functionality that was intended to be provided by these
commits is desired, the patch didn't actually solve as many of the
problematic situations as we hoped, and it created a bunch of its own
problems.  Since we're going to require more extensive changes soon for
other reasons and users have been working around these problems for a
long time already, there is no point in spending effort in fixing this
halfway measure.

Per complaint from Tom Lane.
Discussion: https://postgr.es/m/21407.1484606922@sss.pgh.pa.us

(Commit fa2fa9955280 had already been reverted in branches 9.5 as
f858524ee4f and 9.6 as e9e44a0953, so this touches master only.
Commit 42f50cb8fa98 was not present in the older branches.)

7 years agopsql: Add missing translation markers
Peter Eisentraut [Wed, 10 May 2017 14:14:49 +0000 (10:14 -0400)]
psql: Add missing translation markers

7 years agoFix typo.
Robert Haas [Wed, 10 May 2017 03:57:52 +0000 (23:57 -0400)]
Fix typo.

Thomas Munro

Discussion: http://postgr.es/m/CAEepm=3vV1YKxDfLMqq-nYM2fN+STMYLwPKFCoah4M0gxqqNNg@mail.gmail.com

7 years agoAvoid theoretical infinite loop loading relcache partition key.
Robert Haas [Wed, 10 May 2017 03:51:54 +0000 (23:51 -0400)]
Avoid theoretical infinite loop loading relcache partition key.

Amit Langote, per report from 甄明洋

Discussion: http://postgr.es/m/57bd1e1.1886.15bd7b79cee.Coremail.18612389267@yeah.net

7 years agoDocument trigger-firing behavior for inheritance/partitioning.
Robert Haas [Wed, 10 May 2017 03:49:20 +0000 (23:49 -0400)]
Document trigger-firing behavior for inheritance/partitioning.

Amit Langote, reviewed Thomas Munro and by me.

Discussion: http://postgr.es/m/CA+Tgmoadpcs3=mMgdyqVX7L7L_PwO_Dn5j-98a6Tj7ByBuimUQ@mail.gmail.com

7 years agoRemove no-longer-needed compatibility code for hash indexes.
Robert Haas [Wed, 10 May 2017 03:44:21 +0000 (23:44 -0400)]
Remove no-longer-needed compatibility code for hash indexes.

Because commit ea69a0dead5128c421140dc53fac165ba4af8520 bumped the
HASH_VERSION, we don't need to worry about PostgreSQL 10 seeing
bucket pages from earlier versions.

Amit Kapila

Discussion: http://postgr.es/m/CAA4eK1LAo4DGwh+mi-G3U8Pj1WkBBeFL38xdCnUHJv1z4bZFkQ@mail.gmail.com

7 years agoFix typos in comments.
Robert Haas [Wed, 10 May 2017 03:40:08 +0000 (23:40 -0400)]
Fix typos in comments.

Etsuro Fujita

Discussion: http://postgr.es/m/968d99bf-0fa8-085b-f0a1-a379f8d661ff@lab.ntt.co.jp

7 years agoProhibit transition tables on views and foreign tables.
Robert Haas [Wed, 10 May 2017 03:34:02 +0000 (23:34 -0400)]
Prohibit transition tables on views and foreign tables.

Thomas Munro, per off-list report from Prabhat Sabu.  Changes
to the message wording for consistency with the existing
relkind check for partitioned tables by me.

Discussion: http://postgr.es/m/CAEepm=2xJFFpGM+N=gpWx-9Nft2q1oaFZX07_y23AHCrJQLt0g@mail.gmail.com

7 years agoDon't permit transition tables with TRUNCATE triggers.
Robert Haas [Wed, 10 May 2017 03:22:39 +0000 (23:22 -0400)]
Don't permit transition tables with TRUNCATE triggers.

Prior to this prohibition, such a trigger caused a crash.

Thomas Munro, per a report from Neha Sharma.  I added a
regression test.

Discussion: http://postgr.es/m/CAEepm=0VR5W-N38eTkO_FqJbGqQ_ykbBRmzmvHyxDhy1p=0Csw@mail.gmail.com

7 years agoPass EXEC_FLAG_REWIND when initializing a tuplestore scan.
Robert Haas [Wed, 10 May 2017 03:13:21 +0000 (23:13 -0400)]
Pass EXEC_FLAG_REWIND when initializing a tuplestore scan.

Since a rescan is possible, we must be able to rewind.

Thomas Munro, per a report from Prabhat Sabu

Discussion: http://postgr.es/m/CAEepm=2=Uv5fm=exqL+ygBxaO+-tgmC=o+63H4zYAXi9HtXf1w@mail.gmail.com

7 years agoDisallow finite partition bound following earlier UNBOUNDED column.
Robert Haas [Wed, 10 May 2017 02:41:12 +0000 (22:41 -0400)]
Disallow finite partition bound following earlier UNBOUNDED column.

Amit Langote, per an observation by me.

Discussion: http://postgr.es/m/CA+TgmoYWnV2GMnYLG-Czsix-E1WGAbo4D+0tx7t9NdfYBDMFsA@mail.gmail.com

7 years agoImprove memory use in logical replication apply
Peter Eisentraut [Tue, 9 May 2017 18:40:42 +0000 (14:40 -0400)]
Improve memory use in logical replication apply

Previously, the memory used by the logical replication apply worker for
processing messages would never be freed, so that could end up using a
lot of memory.  To improve that, change the existing ApplyContext memory
context to ApplyMessageContext and reset that after every
message (similar to MessageContext used elsewhere).  For consistency of
naming, rename the ApplyCacheContext to ApplyContext.

Author: Stas Kelvich <s.kelvich@postgrespro.ru>

7 years agoIgnore PQcancel errors properly
Alvaro Herrera [Tue, 9 May 2017 17:58:51 +0000 (14:58 -0300)]
Ignore PQcancel errors properly

Add a (void) cast to all PQcancel() calls that purposefully don't check
the return value, to keep compilers and static checkers happy.

Per Coverity.

7 years agopg_dump: Add --no-subscriptions option
Peter Eisentraut [Tue, 9 May 2017 14:58:06 +0000 (10:58 -0400)]
pg_dump: Add --no-subscriptions option

Author: Michael Paquier <michael.paquier@gmail.com>
Reviewed-by: Petr Jelinek <petr.jelinek@2ndquadrant.com>
7 years agodoc: Add info about replication slot management
Peter Eisentraut [Tue, 9 May 2017 14:25:26 +0000 (10:25 -0400)]
doc: Add info about replication slot management

Add some more information about managing replication slots associated
with logical replication subscriptions.

7 years agoRemove the NODROP SLOT option from DROP SUBSCRIPTION
Peter Eisentraut [Tue, 9 May 2017 14:20:42 +0000 (10:20 -0400)]
Remove the NODROP SLOT option from DROP SUBSCRIPTION

It turned out this approach had problems, because a DROP command should
not have any options other than CASCADE and RESTRICT.  Instead, always
attempt to drop the slot if there is one configured, but also add an
ALTER SUBSCRIPTION action to set the slot to NONE.

Author: Petr Jelinek <petr.jelinek@2ndquadrant.com>
Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/29431.1493730652@sss.pgh.pa.us

7 years agopgindent: use HTTP instead of FTP to retrieve pg_bsd_indent src
Bruce Momjian [Tue, 9 May 2017 13:28:44 +0000 (09:28 -0400)]
pgindent:  use HTTP instead of FTP to retrieve pg_bsd_indent src

FTP support will be removed from ftp.postgresql.org in months, but http
still works.  Typedefs already used http.

7 years agoFurther patch rangetypes_selfuncs.c's statistics slot management.
Tom Lane [Mon, 8 May 2017 19:02:57 +0000 (15:02 -0400)]
Further patch rangetypes_selfuncs.c's statistics slot management.

Values in a STATISTIC_KIND_RANGE_LENGTH_HISTOGRAM slot are float8,
not of the type of the column the statistics are for.

This bug is at least partly the fault of sloppy specification comments
for get_attstatsslot()/free_attstatsslot(): the type OID they want is that
of the stavalues entries, not of the underlying column.  (I double-checked
other callers and they seem to get this right.)  Adjust the comments to be
more correct.

Per buildfarm.

Security: CVE-2017-7484

7 years agoCheck connection info string in ALTER SUBSCRIPTION
Peter Eisentraut [Mon, 8 May 2017 18:01:00 +0000 (14:01 -0400)]
Check connection info string in ALTER SUBSCRIPTION

Previously it would allow an invalid connection string to be set.

Author: Petr Jelinek <petr.jelinek@2ndquadrant.com>
Reported-by: tushar <tushar.ahuja@enterprisedb.com>
7 years agoLast-minute updates for release notes.
Tom Lane [Mon, 8 May 2017 16:57:27 +0000 (12:57 -0400)]
Last-minute updates for release notes.

Security: CVE-2017-7484, CVE-2017-7485, CVE-2017-7486

7 years agoFix statistics reporting in logical replication workers
Peter Eisentraut [Mon, 8 May 2017 16:07:59 +0000 (12:07 -0400)]
Fix statistics reporting in logical replication workers

This new arrangement ensures that statistics are reported right after
commit of transactions.  The previous arrangement didn't get this quite
right and could lead to assertion failures.

Author: Petr Jelinek <petr.jelinek@2ndquadrant.com>
Reported-by: Erik Rijkers <er@xs4all.nl>
7 years agoFix possibly-uninitialized variable.
Tom Lane [Mon, 8 May 2017 15:18:40 +0000 (11:18 -0400)]
Fix possibly-uninitialized variable.

Oversight in e2d4ef8de et al (my fault not Peter's).  Per buildfarm.

Security: CVE-2017-7484

7 years agoMatch pg_user_mappings limits to information_schema.user_mapping_options.
Noah Misch [Mon, 8 May 2017 14:24:24 +0000 (07:24 -0700)]
Match pg_user_mappings limits to information_schema.user_mapping_options.

Both views replace the umoptions field with NULL when the user does not
meet qualifications to see it.  They used different qualifications, and
pg_user_mappings documented qualifications did not match its implemented
qualifications.  Make its documentation and implementation match those
of user_mapping_options.  One might argue for stronger qualifications,
but these have long, documented tenure.  pg_user_mappings has always
exhibited this problem, so back-patch to 9.2 (all supported versions).

Michael Paquier and Feike Steenbergen.  Reviewed by Jeff Janes.
Reported by Andrew Wheelwright.

Security: CVE-2017-7486

7 years agoRestore PGREQUIRESSL recognition in libpq.
Noah Misch [Mon, 8 May 2017 14:24:24 +0000 (07:24 -0700)]
Restore PGREQUIRESSL recognition in libpq.

Commit 65c3bf19fd3e1f6a591618e92eb4c54d0b217564 moved handling of the,
already then, deprecated requiressl parameter into conninfo_storeval().
The default PGREQUIRESSL environment variable was however lost in the
change resulting in a potentially silent accept of a non-SSL connection
even when set.  Its documentation remained.  Restore its implementation.
Also amend the documentation to mark PGREQUIRESSL as deprecated for
those not following the link to requiressl.  Back-patch to 9.3, where
commit 65c3bf1 first appeared.

Behavior has been more complex when the user provides both deprecated
and non-deprecated settings.  Before commit 65c3bf1, libpq operated
according to the first of these found:

  requiressl=1
  PGREQUIRESSL=1
  sslmode=*
  PGSSLMODE=*

(Note requiressl=0 didn't override sslmode=*; it would only suppress
PGREQUIRESSL=1 or a previous requiressl=1.  PGREQUIRESSL=0 had no effect
whatsoever.)  Starting with commit 65c3bf1, libpq ignored PGREQUIRESSL,
and order of precedence changed to this:

  last of requiressl=* or sslmode=*
  PGSSLMODE=*

Starting now, adopt the following order of precedence:

  last of requiressl=* or sslmode=*
  PGSSLMODE=*
  PGREQUIRESSL=1

This retains the 65c3bf1 behavior for connection strings that contain
both requiressl=* and sslmode=*.  It retains the 65c3bf1 change that
either connection string option overrides both environment variables.
For the first time, PGSSLMODE has precedence over PGREQUIRESSL; this
avoids reducing security of "PGREQUIRESSL=1 PGSSLMODE=verify-full"
configurations originating under v9.3 and later.

Daniel Gustafsson

Security: CVE-2017-7485