]> granicus.if.org Git - postgresql/log
postgresql
4 years agoStamp 12beta2. REL_12_BETA2
Tom Lane [Mon, 17 Jun 2019 21:12:29 +0000 (17:12 -0400)]
Stamp 12beta2.

4 years agoTranslation updates
Peter Eisentraut [Mon, 17 Jun 2019 13:07:14 +0000 (15:07 +0200)]
Translation updates

Source-Git-URL: https://git.postgresql.org/git/pgtranslation/messages.git
Source-Git-Hash: 1a710c413ce4c4cd081843e563cde256bb95f490

4 years agoFix buffer overflow when processing SCRAM final message in libpq
Michael Paquier [Mon, 17 Jun 2019 13:13:57 +0000 (22:13 +0900)]
Fix buffer overflow when processing SCRAM final message in libpq

When a client connects to a rogue server sending specifically-crafted
messages, this can suffice to execute arbitrary code as the operating
system account used by the client.

While on it, fix one error handling when decoding an incorrect salt
included in the first message received from server.

Author: Michael Paquier
Reviewed-by: Jonathan Katz, Heikki Linnakangas
Security: CVE-2019-10164
Backpatch-through: 10

4 years agoFix buffer overflow when parsing SCRAM verifiers in backend
Michael Paquier [Mon, 17 Jun 2019 12:48:17 +0000 (21:48 +0900)]
Fix buffer overflow when parsing SCRAM verifiers in backend

Any authenticated user can overflow a stack-based buffer by changing the
user's own password to a purpose-crafted value.  This often suffices to
execute arbitrary code as the PostgreSQL operating system account.

This fix is contributed by multiple folks, based on an initial analysis
from Tom Lane.  This issue has been introduced by 68e61ee, so it was
possible to make use of it at authentication time.  It became more
easily to trigger after ccae190 which has made the SCRAM parsing more
strict when changing a password, in the case where the client passes
down a verifier already hashed using SCRAM.  Back-patch to v10 where
SCRAM has been introduced.

Reported-by: Alexander Lakhin
Author: Jonathan Katz, Heikki Linnakangas, Michael Paquier
Security: CVE-2019-10164
Backpatch-through: 10

4 years agoFix more typos and inconsistencies in the tree
Michael Paquier [Mon, 17 Jun 2019 07:13:16 +0000 (16:13 +0900)]
Fix more typos and inconsistencies in the tree

Author: Alexander Lakhin
Discussion: https://postgr.es/m/0a5419ea-1452-a4e6-72ff-545b1a5a8076@gmail.com

4 years agoRevert "Avoid spurious deadlocks when upgrading a tuple lock"
Alvaro Herrera [Mon, 17 Jun 2019 02:24:21 +0000 (22:24 -0400)]
Revert "Avoid spurious deadlocks when upgrading a tuple lock"

This reverts commits 3da73d6839dc and de87a084c0a5.

This code has some tricky corner cases that I'm not sure are correct and
not properly tested anyway, so I'm reverting the whole thing for next
week's releases (reintroducing the deadlock bug that we set to fix).
I'll try again afterwards.

Discussion: https://postgr.es/m/E1hbXKQ-0003g1-0C@gemulon.postgresql.org

4 years agoDoc: remove description of commit 23bd3cec6 from v12 release notes.
Tom Lane [Sun, 16 Jun 2019 18:02:22 +0000 (14:02 -0400)]
Doc: remove description of commit 23bd3cec6 from v12 release notes.

Now that we've back-patched that, it shouldn't be mentioned in v12
anymore.

4 years agoFurther fix privileges on pg_statistic_ext[_data].
Tom Lane [Sun, 16 Jun 2019 15:00:23 +0000 (11:00 -0400)]
Further fix privileges on pg_statistic_ext[_data].

We don't need to restrict column privileges on pg_statistic_ext;
all of that data is OK to read publicly.  What we *do* need to do,
which was overlooked by 6cbfb784c, is revoke public read access on
pg_statistic_ext_data; otherwise we still have the same security
hole we started with.

Catversion bump to ensure that installations calling themselves
beta2 will have this fix.

Diagnosis/correction by Dean Rasheed and Tomas Vondra, but I'm
going to go ahead and push this fix ASAP so we get more buildfarm
cycles on it.

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

4 years agoFix privileges on pg_statistic_ext.tableoid
Tomas Vondra [Sun, 16 Jun 2019 10:04:40 +0000 (12:04 +0200)]
Fix privileges on pg_statistic_ext.tableoid

The GRANT in system_views allowed SELECT privileges on various columns in
the pg_statistic_ext catalog, but tableoid was not included in the list.
That made pg_dump fail because it's accessing this column when building
the list of extended statistics to dump.

Discussion: https://postgr.es/m/8833.1560647898%40sss.pgh.pa.us

4 years agoFix incorrect CREATE STATISTICS example in docs
Tomas Vondra [Sat, 15 Jun 2019 19:38:53 +0000 (21:38 +0200)]
Fix incorrect CREATE STATISTICS example in docs

The example was incorrectly using parantheses around the list of columns, so
just drop them.

Reported-By: Robert Haas
Discussion: https://postgr.es/m/CA%2BTgmoZZEMAqWMAfvLHZnK57SoxOutgvE-ALO94WsRA7zZ7wyQ%40mail.gmail.com

4 years agoAdd pg_stats_ext view for extended statistics
Tomas Vondra [Thu, 13 Jun 2019 15:25:04 +0000 (17:25 +0200)]
Add pg_stats_ext view for extended statistics

Regular per-column statistics are stored in pg_statistics catalog, which
is however rather difficult to read, so we also have pg_stats view with
a human-reablable version of the data.

For extended statistic the catalog was fairly easy to read, so we did
not have such human-readable view so far.  Commit 9b6babfa2d however did
split the catalog into two, which makes querying harder.  Furthermore,
we want to show the multi-column MCV list in a way similar to per-column
stats (and not as a bytea value).

This commit introduces pg_stats_ext view, joining the two catalogs and
massaging the data to produce human-readable output similar to pg_stats.
It also considers RLS and access privileges - the data is shown only when
the user has access to all columns the extended statistic is defined on.

Bumped CATVERSION due to adding new system view.

Author: Dean Rasheed, with improvements by me
Reviewed-by: Dean Rasheed, John Naylor
Discussion: https://postgr.es/m/CAEZATCUhT9rt7Ui%3DVdx4N%3D%3DVV5XOK5dsXfnGgVOz_JhAicB%3DZA%40mail.gmail.com

4 years agoRework the pg_statistic_ext catalog
Tomas Vondra [Thu, 13 Jun 2019 15:19:21 +0000 (17:19 +0200)]
Rework the pg_statistic_ext catalog

Since extended statistic got introduced in PostgreSQL 10, there was a
single catalog pg_statistic_ext storing both the definitions and built
statistic.  That's however problematic when a user is supposed to have
access only to the definitions, but not to user data.

Consider for example pg_dump on a database with RLS enabled - if the
pg_statistic_ext catalog respects RLS (which it should, if it contains
user data), pg_dump would not see any records and the result would not
define any extended statistics.  That would be a surprising behavior.

Until now this was not a pressing issue, because the existing types of
extended statistic (functional dependencies and ndistinct coefficients)
do not include any user data directly.  This changed with introduction
of MCV lists, which do include most common combinations of values.

The easiest way to fix this is to split the pg_statistic_ext catalog
into two - one for definitions, one for the built statistic values.
The new catalog is called pg_statistic_ext_data, and we're maintaining
a 1:1 relationship with the old catalog - either there are matching
records in both catalogs, or neither of them.

Bumped CATVERSION due to changing system catalog definitions.

Author: Dean Rasheed, with improvements by me
Reviewed-by: Dean Rasheed, John Naylor
Discussion: https://postgr.es/m/CAEZATCUhT9rt7Ui%3DVdx4N%3D%3DVV5XOK5dsXfnGgVOz_JhAicB%3DZA%40mail.gmail.com

4 years agoPrefer timezone name "UTC" over alternative spellings.
Andrew Gierth [Sat, 15 Jun 2019 17:15:23 +0000 (18:15 +0100)]
Prefer timezone name "UTC" over alternative spellings.

tzdb 2019a made "UCT" a link to the "UTC" zone rather than a separate
zone with its own abbreviation. Unfortunately, our code for choosing a
timezone in initdb has an arbitrary preference for names earlier in
the alphabet, and so it would choose the spelling "UCT" over "UTC"
when the system is running on a UTC zone.

Commit 23bd3cec6 was backpatched in order to address this issue, but
that code helps only when /etc/localtime exists as a symlink, and does
nothing to help on systems where /etc/localtime is a copy of a zone
file (as is the standard setup on FreeBSD and probably some other
platforms too) or when /etc/localtime is simply absent (giving UTC as
the default).

Accordingly, add a preference for the spelling "UTC", such that if
multiple zone names have equally good content matches, we prefer that
name before applying the existing arbitrary rules. Also add a slightly
lower preference for "Etc/UTC"; lower because that preserves the
previous behaviour of choosing the shorter name, but letting us still
choose "Etc/UTC" over "Etc/UCT" when both exist but "UTC" does
not (not common, but I've seen it happen).

Backpatch all the way, because the tzdb change that sparked this issue
is in those branches too.

4 years agoAdd pg_dumpall --rows-per-insert
Alvaro Herrera [Fri, 14 Jun 2019 22:21:52 +0000 (18:21 -0400)]
Add pg_dumpall --rows-per-insert

Commit 7e413a0f82c8 added that option to pg_dump, but neglected to teach
pg_dumpall how to pass it along.  Repair.

Author: Fabien Coelho
Reported-by: Peter Eisentraut
Reviewed-by: David Rowley
Discussion: https://postgr.es/m/45f50c59-ddbb-8cf2-eedb-81003f603528@2ndquadrant.com

4 years agoTweak libpq's PQhost, PQhostaddr, and psql's \connect
Alvaro Herrera [Fri, 14 Jun 2019 22:02:26 +0000 (18:02 -0400)]
Tweak libpq's PQhost, PQhostaddr, and psql's \connect

Fixes some problems introduced by 6e5f8d489acc:

* When reusing conninfo data from the previous connection in \connect,
  the host address should only be reused if it was specified as
  hostaddr; if it wasn't, then 'host' is resolved afresh.  We were
  reusing the same IP address, which ignores a possible DNS change
  as well as any other addresses that the name resolves to than the
  one that was used in the original connection.

* PQhost, PQhostaddr: Don't present user-specified hostaddr when we have
  an inet_net_ntop-produced equivalent address.  The latter has been
  put in canonical format, which is cleaner (so it produces "127.0.0.1"
  when given "host=2130706433", for example).

* Document the hostaddr-reusing aspect of \connect.

* Fix some code comments

Author: Fabien Coelho
Reported-by: Noah Misch
Discussion: https://postgr.es/m/20190527203713.GA58392@gust.leadboat.com

4 years agoSilence compiler warning
Alvaro Herrera [Fri, 14 Jun 2019 15:33:40 +0000 (11:33 -0400)]
Silence compiler warning

Introduced in de87a084c0a5.

4 years agodoc: PG 12 relnotes, add mention of single-child optimization
Bruce Momjian [Fri, 14 Jun 2019 13:30:31 +0000 (09:30 -0400)]
doc:  PG 12 relnotes, add mention of single-child optimization

Add mention of single-child optimization for partitions and UNION ALL.

Reported-by: David Rowley
Discussion: https://postgr.es/m/CAKJS1f8R8riwBXw==7ijV=UZNuhP+3qXgDBKSiM+=_cTf4mXXw@mail.gmail.com

4 years agopostgres_fdw: Fix costing of pre-sorted foreign paths with local stats.
Etsuro Fujita [Fri, 14 Jun 2019 11:49:59 +0000 (20:49 +0900)]
postgres_fdw: Fix costing of pre-sorted foreign paths with local stats.

Commit aa09cd242 modified estimate_path_cost_size() so that it reuses
cached costs of a basic foreign path for a given foreign-base/join
relation when costing pre-sorted foreign paths for that relation, but it
incorrectly re-computed retrieved_rows, an estimated number of rows
fetched from the remote side, which is needed for costing both the basic
and pre-sorted foreign paths.  To fix, handle retrieved_rows the same way
as the cached costs: store in that relation's fpinfo the retrieved_rows
estimate computed for costing the basic foreign path, and reuse it when
costing the pre-sorted foreign paths.  Also, reuse the rows/width
estimates stored in that relation's fpinfo when costing the pre-sorted
foreign paths, to make the code consistent.

In commit ffab494a4, to extend the costing mentioned above to the
foreign-grouping case, I made a change to add_foreign_grouping_paths() to
store in a given foreign-grouped relation's RelOptInfo the rows estimate
for that relation for reuse, but this patch makes that change unnecessary
since we already store the row estimate in that relation's fpinfo, which
this patch reuses when costing a foreign path for that relation with the
sortClause ordering; remove that change.

In passing, fix thinko in commit 7012b132d: in estimate_path_cost_size(),
the width estimate for a given foreign-grouped relation to be stored in
that relation's fpinfo was reset incorrectly when costing a basic foreign
path for that relation with local stats.

Apply the patch to HEAD only to avoid destabilizing existing plan choices.

Author: Etsuro Fujita
Discussion: https://postgr.es/m/CAPmGK17jaJLPDEkgnP2VmkOg=5wT8YQ1CqssU8JRpZ_NSE+dqQ@mail.gmail.com

4 years agodocs: PG 12 relnotes, update self-join item to mention ctid
Bruce Momjian [Fri, 14 Jun 2019 02:53:20 +0000 (22:53 -0400)]
docs:  PG 12 relnotes, update self-join item to mention ctid

Reported-by: Robert Haas
Discussion: https://postgr.es/m/CA+TgmoY==TZwk-4cM3Usebq1f=j7Hpm1brFbk1v48h45wsWzzg@mail.gmail.com

4 years agodocs: PG 12 relnotes, move vacuumdb to the client app section
Bruce Momjian [Fri, 14 Jun 2019 02:07:25 +0000 (22:07 -0400)]
docs:  PG 12 relnotes, move vacuumdb to the client app section

It was previously incorrectly placed in the server application section.

Reported-by: Tatsuo Ishii
Discussion: https://postgr.es/m/20190526.215341.1023150119477784132.t-ishii@sraoss.co.jp

4 years agoFix typos and inconsistencies in code comments
Michael Paquier [Fri, 14 Jun 2019 00:34:34 +0000 (09:34 +0900)]
Fix typos and inconsistencies in code comments

Author: Alexander Lakhin
Discussion: https://postgr.es/m/dec6aae8-2d63-639f-4d50-20e229fb83e3@gmail.com

4 years agoUse OpenSSL-specific ifdefs in sha2.h
Michael Paquier [Fri, 14 Jun 2019 00:00:36 +0000 (09:00 +0900)]
Use OpenSSL-specific ifdefs in sha2.h

In order to separate OpenSSL's SHA symbols, this header has been using
USE_SSL, which is equivalent to USE_OPENSSL.  There is now only one SSL
implementation included in the tree, so this works fine, but when
adding a new SSL implementation this would run into failures.

Author: Daniel Gustafsson
Discussion: https://postgr.es/m/0DF29010-CE26-4F51-85A6-9C8ABF5536F9@yesql.se

4 years agoAvoid combinatorial explosion in add_child_rel_equivalences().
Tom Lane [Thu, 13 Jun 2019 22:10:08 +0000 (18:10 -0400)]
Avoid combinatorial explosion in add_child_rel_equivalences().

If an EquivalenceClass member expression includes variables from
multiple appendrels, then instead of producing one substituted
expression per child relation as intended, we'd create additional
child expressions for combinations of children of different appendrels.
This happened because the child expressions generated while considering
the first appendrel were taken as sources during substitution of the
second appendrel, and so on.  The extra expressions are useless, and are
harmless unless there are too many of them --- but if you have several
appendrels with a thousand or so members each, it gets bad fast.

To fix, consider only original (non-em_is_child) EC members as candidates
to be expanded.  This requires the ability to substitute directly from a
top parent relation's Vars to those of an indirect descendant relation,
but we already have that in adjust_appendrel_attrs_multilevel().

Per bug #15847 from Feike Steenbergen.  This is a longstanding misbehavior,
but it's only worth worrying about when there are more appendrel children
than we've historically considered wise to use.  So I'm not going to take
the risk of back-patching this.

Discussion: https://postgr.es/m/15847-ea3734094bf8ae61@postgresql.org

4 years agoAvoid spurious deadlocks when upgrading a tuple lock
Alvaro Herrera [Thu, 13 Jun 2019 21:28:24 +0000 (17:28 -0400)]
Avoid spurious deadlocks when upgrading a tuple lock

When two (or more) transactions are waiting for transaction T1 to release a
tuple-level lock, and transaction T1 upgrades its lock to a higher level, a
spurious deadlock can be reported among the waiting transactions when T1
finishes.  The simplest example case seems to be:

T1: select id from job where name = 'a' for key share;
Y: select id from job where name = 'a' for update; -- starts waiting for X
Z: select id from job where name = 'a' for key share;
T1: update job set name = 'b' where id = 1;
Z: update job set name = 'c' where id = 1; -- starts waiting for X
T1: rollback;

At this point, transaction Y is rolled back on account of a deadlock: Y
holds the heavyweight tuple lock and is waiting for the Xmax to be released,
while Z holds part of the multixact and tries to acquire the heavyweight
lock (per protocol) and goes to sleep; once X releases its part of the
multixact, Z is awakened only to be put back to sleep on the heavyweight
lock that Y is holding while sleeping.  Kaboom.

This can be avoided by having Z skip the heavyweight lock acquisition.  As
far as I can see, the biggest downside is that if there are multiple Z
transactions, the order in which they resume after X finishes is not
guaranteed.

Backpatch to 9.6.  The patch applies cleanly on 9.5, but the new tests don't
work there (because isolationtester is not smart enough), so I'm not going
to risk it.

Author: Oleksii Kliukin
Discussion: https://postgr.es/m/B9C9D7CD-EB94-4635-91B6-E558ACEC0EC3@hintbits.com

4 years agoMark ReplicationSlotCtl as PGDLLIMPORT.
Tom Lane [Thu, 13 Jun 2019 14:53:17 +0000 (10:53 -0400)]
Mark ReplicationSlotCtl as PGDLLIMPORT.

Also MyReplicationSlot, in branches where it wasn't already.

This was discussed in the thread that resulted in c572599c6, but
for some reason nobody pulled the trigger.  Now that we have another
request for the same thing, we should just do it.

Craig Ringer

Discussion: https://postgr.es/m/CAMsr+YFTsq-86MnsNng=mPvjjh5EAbzfMK0ptJPvzyvpFARuRg@mail.gmail.com
Discussion: https://postgr.es/m/345138875.20190611151943@cybertec.at

4 years agoFix double-word typos
Alvaro Herrera [Wed, 12 Jun 2019 18:16:18 +0000 (14:16 -0400)]
Fix double-word typos

Discussion: https://postgr.es/m/20190612184527.GA24266@alvherre.pgsql
Reviewed-by: Michaël Paquier
4 years agodoc: PG 12 relnotes: update wording on truncate/vacuum item
Bruce Momjian [Thu, 13 Jun 2019 13:15:57 +0000 (09:15 -0400)]
doc:  PG 12 relnotes:  update wording on truncate/vacuum item

This item prevents unauthorized locking of relations, and the previous
wording was unclear.

Reported-by: Michael Paquier
Discussion: https://postgr.es/m/20190522072651.GC1278@paquier.xyz

4 years agopostgres_fdw: Account for triggers in non-direct remote UPDATE planning.
Etsuro Fujita [Thu, 13 Jun 2019 08:59:09 +0000 (17:59 +0900)]
postgres_fdw: Account for triggers in non-direct remote UPDATE planning.

Previously, in postgresPlanForeignModify, we planned an UPDATE operation
on a foreign table so that we transmit only columns that were explicitly
targets of the UPDATE, so as to avoid unnecessary data transmission, but
if there were BEFORE ROW UPDATE triggers on the foreign table, those
triggers might change values for non-target columns, in which case we
would miss sending changed values for those columns.  Prevent optimizing
away transmitting all columns if there are BEFORE ROW UPDATE triggers on
the foreign table.

This is an oversight in commit 7cbe57c34 which added triggers on foreign
tables, so apply the patch all the way back to 9.4 where that came in.

Author: Shohei Mochizuki
Reviewed-by: Amit Langote
Discussion: https://postgr.es/m/201905270152.x4R1q3qi014550@toshiba.co.jp

4 years agoDoc: fix bogus example.
Tom Lane [Thu, 13 Jun 2019 03:05:40 +0000 (23:05 -0400)]
Doc: fix bogus example.

This wasn't incorrect SQL, but it was doing cm-to-inch conversion
backward, so it might confuse readers.

Per bug #15849 from TAKATSUKA Haruka.

Discussion: https://postgr.es/m/15849-37ad0c561a836107@postgresql.org

4 years agoDoc: improve description of allowed spellings for Boolean input.
Tom Lane [Thu, 13 Jun 2019 02:54:46 +0000 (22:54 -0400)]
Doc: improve description of allowed spellings for Boolean input.

datatype.sgml failed to explain that boolin() accepts any unique
prefix of the basic input strings.  Indeed it was actively misleading
because it called out a few minimal prefixes without mentioning that
there were more valid inputs.

I also felt that it wasn't doing anybody any favors by conflating
SQL key words, valid Boolean input, and string literals containing
valid Boolean input.  Rewrite in hopes of reducing the confusion.

Per bug #15836 from Yuming Wang, as diagnosed by David Johnston.
Back-patch to supported branches.

Discussion: https://postgr.es/m/15836-656fab055735f511@postgresql.org

4 years agodocs: PG 12 relnotes, update btree items
Bruce Momjian [Thu, 13 Jun 2019 02:48:04 +0000 (22:48 -0400)]
docs: PG 12 relnotes, update btree items

Reported-by: Peter Geoghegan
Discussion: https://postgr.es/m/CAH2-Wzn-aH4ToZEWR05ELSSp7bO_JMn=sMPfUhNruwVmCXKh-w@mail.gmail.com

4 years agoFix incorrect printing of queries with duplicated join names.
Tom Lane [Wed, 12 Jun 2019 23:42:38 +0000 (19:42 -0400)]
Fix incorrect printing of queries with duplicated join names.

Given a query in which multiple JOIN nodes used the same alias
(which'd necessarily be in different sub-SELECTs), ruleutils.c
would assign the JOIN nodes distinct aliases for clarity ...
but then it forgot to print the modified aliases when dumping
the JOIN nodes themselves.  This results in a dump/reload hazard
for views, because the emitted query is flat-out incorrect:
Vars will be printed with table names that have no referent.

This has been wrong for a long time, so back-patch to all supported
branches.

Philip Dubé

Discussion: https://postgr.es/m/CY4PR2101MB080246F2955FF58A6ED1FEAC98140@CY4PR2101MB0802.namprd21.prod.outlook.com

4 years agodoc: Fix grammatical error in partitioning docs
David Rowley [Wed, 12 Jun 2019 22:35:11 +0000 (10:35 +1200)]
doc: Fix grammatical error in partitioning docs

Reported-by: Amit Langote
Discussion: https://postgr.es/m/CA+HiwqGZFkKi0TkBGYpr2_5qrRAbHZoP47AP1BRLUOUkfQdy_A@mail.gmail.com
Backpatch-through: 10

4 years agodoc: PG 12 relnotes, list added snowball/FTS languages
Bruce Momjian [Wed, 12 Jun 2019 21:46:38 +0000 (17:46 -0400)]
doc: PG 12 relnotes, list added snowball/FTS languages

Reported-by: Adrien Nayrat
Discussion: https://postgr.es/m/9d6a7515-bcd8-05be-d2a5-e81dc11023cd@anayrat.info

4 years agodoc: PG 12 relnotes, merge new SQL partition function items
Bruce Momjian [Wed, 12 Jun 2019 21:36:43 +0000 (17:36 -0400)]
doc:  PG 12 relnotes, merge new SQL partition function items

Reported-by: Andres Freund
Discussion: https://postgr.es/m/20190528155823.3e4cezblxjxotq2q@alap3.anarazel.de

4 years agoFix ALTER COLUMN TYPE failure with a partial exclusion constraint.
Tom Lane [Wed, 12 Jun 2019 16:29:24 +0000 (12:29 -0400)]
Fix ALTER COLUMN TYPE failure with a partial exclusion constraint.

ATExecAlterColumnType failed to consider the possibility that an index
that needs to be rebuilt might be a child of a constraint that needs to be
rebuilt.  We missed this so far because usually a constraint index doesn't
have a direct dependency on its table, just on the constraint object.
But if there's a WHERE clause, then dependency analysis of the WHERE
clause results in direct dependencies on the column(s) mentioned in WHERE.
This led to trying to drop and rebuild both the constraint and its
underlying index.

In v11/HEAD, we successfully drop both the index and the constraint,
and then try to rebuild both, and of course the second rebuild hits a
duplicate-index-name problem.  Before v11, it fails with obscure messages
about a missing relation OID, due to trying to drop the index twice.

This is essentially the same kind of problem noted in commit
20bef2c31: the possible dependency linkages are broader than what
ATExecAlterColumnType was designed for.  It was probably OK when
written, but it's certainly been broken since the introduction of
partial exclusion constraints.  Fix by adding an explicit check
for whether any of the indexes-to-be-rebuilt belong to any of the
constraints-to-be-rebuilt, and ignoring any that do.

In passing, fix a latent bug introduced by commit 8b08f7d48: in
get_constraint_index() we must "continue" not "break" when rejecting
a relation of a wrong relkind.  This is harmless today because we don't
expect that code path to be taken anyway; but if there ever were any
relations to be ignored, the existing coding would have an extremely
undesirable dependency on the order of pg_depend entries.

Also adjust a couple of obsolete comments.

Per bug #15835 from Yaroslav Schekin.  Back-patch to all supported
branches.

Discussion: https://postgr.es/m/15835-32d9b7a76c06a7a9@postgresql.org

4 years agoFix handling of COMMENT for domain constraints
Michael Paquier [Wed, 12 Jun 2019 02:30:11 +0000 (11:30 +0900)]
Fix handling of COMMENT for domain constraints

For a non-superuser, changing a comment on a domain constraint was
leading to a cache lookup failure as the code tried to perform the
ownership lookup on the constraint OID itself, thinking that it was a
type, but this check needs to happen on the type the domain constraint
relies on.  As the type a domain constraint relies on can be guessed
directly based on the constraint OID, first fetch its type OID and
perform the ownership on it.

This is broken since 7eca575, which has split the handling of comments
for table constraints and domain constraints, so back-patch down to
9.5.

Reported-by: Clemens Ladisch
Author: Daniel Gustafsson, Michael Paquier
Reviewed-by: Álvaro Herrera
Discussion: https://postgr.es/m/15833-808e11904835d26f@postgresql.org
Backpatch-through: 9.5

4 years agodoc: Add best practises section to partitioning docs
David Rowley [Tue, 11 Jun 2019 20:08:57 +0000 (08:08 +1200)]
doc: Add best practises section to partitioning docs

A few questionable partitioning designs have been cropping up lately
around the mailing lists.  Generally, these cases have been partitioning
using too many partitions which have caused performance or OOM problems for
the users.

Since we have very little else to guide users into good design, here we
add a new section to the partitioning documentation with some best
practise guidelines for good design.

Reviewed-by: Justin Pryzby, Amit Langote, Alvaro Herrera
Discussion: https://postgr.es/m/CAKJS1f-2rx+E9mG3xrCVHupefMjAp1+tpczQa9SEOZWyU7fjEA@mail.gmail.com
Backpatch-through: 10

4 years agoFix conversion of JSON strings to JSON output columns in json_to_record().
Tom Lane [Tue, 11 Jun 2019 17:33:08 +0000 (13:33 -0400)]
Fix conversion of JSON strings to JSON output columns in json_to_record().

json_to_record(), when an output column is declared as type json or jsonb,
should emit the corresponding field of the input JSON object.  But it got
this slightly wrong when the field is just a string literal: it failed to
escape the contents of the string.  That typically resulted in syntax
errors if the string contained any double quotes or backslashes.

jsonb_to_record() handles such cases correctly, but I added corresponding
test cases for it too, to prevent future backsliding.

Improve the documentation, as it provided only a very hand-wavy
description of the conversion rules used by these functions.

Per bug report from Robert Vollmert.  Back-patch to v10 where the
error was introduced (by commit cf35346e8).

Note that PG 9.4 - 9.6 also get this case wrong, but differently so:
they feed the de-escaped contents of the string literal to json[b]_in.
That behavior is less obviously wrong, so possibly it's being depended on
in the field, so I won't risk trying to make the older branches behave
like the newer ones.

Discussion: https://postgr.es/m/D6921B37-BD8E-4664-8D5F-DB3525765DCD@vllmrt.net

4 years agoFix order of steps in DISCARD ALL documentation
Alvaro Herrera [Tue, 11 Jun 2019 16:22:11 +0000 (12:22 -0400)]
Fix order of steps in DISCARD ALL documentation

The docs have always been slightly inaccurate, but got particularly so
in a874fe7b4c89, which made DISCARD ALL occur before everything else;
reorder.

Author: Jan Chochol
Discussion: https://postgr.es/m/CAEASf_3TzBbnXm64HpnD5zCZEh8An9jN8ubMR=De-vOXHMHGeA@mail.gmail.com

4 years agoDon't access catalogs to validate GUCs when not connected to a DB.
Andres Freund [Tue, 11 Jun 2019 06:20:48 +0000 (23:20 -0700)]
Don't access catalogs to validate GUCs when not connected to a DB.

Vignesh found this bug in the check function for
default_table_access_method's check hook, but that was just copied
from older GUCs. Investigation by Michael and me then found the bug in
further places.

When not connected to a database (e.g. in a walsender connection), we
cannot perform (most) GUC checks that need database access. Even when
only shared tables are needed, unless they're
nailed (c.f. RelationCacheInitializePhase2()), they cannot be accessed
without pg_class etc. being present.

Fix by extending the existing IsTransactionState() checks to also
check for MyDatabaseOid.

Reported-By: Vignesh C, Michael Paquier, Andres Freund
Author: Vignesh C, Andres Freund
Discussion: https://postgr.es/m/CALDaNm1KXK9gbZfY-p_peRFm_XrBh1OwQO1Kk6Gig0c0fVZ2uw%40mail.gmail.com
Backpatch: 9.4-

4 years agopostgres_fdw: Reorder C includes.
Etsuro Fujita [Tue, 11 Jun 2019 04:39:31 +0000 (13:39 +0900)]
postgres_fdw: Reorder C includes.

Reorder header files in postgres_fdw.c and connection.c in alphabetical
order.

Author: Etsuro Fujita
Reviewed-by: Alvaro Herrera
Discussion: https://postgr.es/m/CAPmGK17ZmNb-EELqu8LmMh2t2uFdbfWNVDEfDO5-bpejHPONMQ@mail.gmail.com

4 years agoFix documentation of ALTER TABLE for stored values
Michael Paquier [Tue, 11 Jun 2019 03:58:51 +0000 (12:58 +0900)]
Fix documentation of ALTER TABLE for stored values

Author: Masahiko Sawada
Discussion: https://postgr.es/m/CAD21AoAA_gvZ002U6kovOHu0FsM7ieoCzdSqWBd7_KaQL0UMKg@mail.gmail.com

4 years agotableam: Fix index_build_range_scan parameter name.
Robert Haas [Tue, 11 Jun 2019 00:04:44 +0000 (20:04 -0400)]
tableam: Fix index_build_range_scan parameter name.

All of the other code thinks that the 8th parameter is the number of
blocks, but this declaration thinks that it's the ending block number.
Repair this inconsistency.

Patch by me, reviewed by Andres Freund.

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

4 years agoMake pg_dump emit ATTACH PARTITION instead of PARTITION OF (reprise)
Alvaro Herrera [Mon, 10 Jun 2019 22:56:23 +0000 (18:56 -0400)]
Make pg_dump emit ATTACH PARTITION instead of PARTITION OF (reprise)

Using PARTITION OF can result in column ordering being changed from the
database being dumped, if the partition uses a column layout different
from the parent's.  It's not pg_dump's job to editorialize on table
definitions, so this is not acceptable; back-patch all the way back to
pg10, where partitioned tables where introduced.

This change also ensures that partitions end up in the correct
tablespace, if different from the parent's; this is an oversight in
ca4103025dfe (in pg12 only).  Partitioned indexes (in pg11) don't have
this problem, because they're already created as independent indexes and
attached to their parents afterwards.

This change also has the advantage that the partition is restorable from
the dump (as a standalone table) even if its parent table isn't
restored.

The original commits (3b23552ad8bb in branch master) failed to cover
subsidiary column elements correctly, such as NOT NULL constraint and
CHECK constraints, as reported by Rushabh Lathia (initially as a failure
to restore serial columns).  They were reverted.  This recapitulation
commit fixes those problems.

Add some pg_dump tests to verify these things more exhaustively,
including constraints with legacy-inheritance tables, which were not
tested originally.  In branches 10 and 11, add a local constraint to the
pg_dump test partition that was added by commit 2d7eeb1b1492 to master.

Author: Álvaro Herrera, David Rowley
Reviewed-by: Álvaro Herrera
Discussion: https://postgr.es/m/CAKJS1f_1c260nOt_vBJ067AZ3JXptXVRohDVMLEBmudX1YEx-A@mail.gmail.com
Discussion: https://postgr.es/m/20190423185007.GA27954@alvherre.pgsql
Discussion: https://postgr.es/m/CAGPqQf0iQV=PPOv2Btog9J9AwOQp6HmuVd6SbGTR_v3Zp2XT1w@mail.gmail.com

4 years agoFix operator naming in pg_trgm GUC option descriptions
Alexander Korotkov [Mon, 10 Jun 2019 17:14:19 +0000 (20:14 +0300)]
Fix operator naming in pg_trgm GUC option descriptions

Descriptions of pg_trgm GUC options have % replaced with %% like it was
a printf-like format.  But that's not needed since they are just plain strings.
This commit fixed that.  Backpatch to last supported version since this error
present from the beginning.

Reported-by: Masahiko Sawada
Discussion: https://postgr.es/m/CAD21AoAgPKODUsu9gqUFiNqEOAqedStxJ-a0sapsJXWWAVp%3Dxg%40mail.gmail.com
Backpatch-through: 9.4

4 years agoAdd docs of missing GUC to pgtrgm.sgml
Alexander Korotkov [Mon, 10 Jun 2019 16:38:13 +0000 (19:38 +0300)]
Add docs of missing GUC to pgtrgm.sgml

be8a7a68 introduced pg_trgm.strict_word_similarity_threshold GUC, but missed
docs for that.  This commit fixes that.

Discussion: https://postgr.es/m/fc907f70-448e-fda3-3aa4-209a59597af0%402ndquadrant.com
Author: Ian Barwick
Reviewed-by: Masahiko Sawada, Michael Paquier
Backpatch-through: 9.6

4 years agoFix docs indentation in pgtrgm.sgml
Alexander Korotkov [Mon, 10 Jun 2019 16:28:47 +0000 (19:28 +0300)]
Fix docs indentation in pgtrgm.sgml

5871b884 introduced pg_trgm.word_similarity_threshold GUC, but its documentation
contains wrong indentation.  This commit fixes that.  Backpatch for easier
backpatching of other documentation fixes.

Discussion: https://postgr.es/m/4c735d30-ab59-fc0e-45d8-f90eb5ed3855%402ndquadrant.com
Author: Ian Barwick
Backpatch-through: 9.6

4 years agoMSVC: Reconcile clean.bat with PostgreSQL 12 work.
Noah Misch [Sun, 9 Jun 2019 22:50:54 +0000 (15:50 -0700)]
MSVC: Reconcile clean.bat with PostgreSQL 12 work.

4 years agoReconcile nodes/*funcs.c with PostgreSQL 12 work.
Noah Misch [Sun, 9 Jun 2019 21:00:36 +0000 (14:00 -0700)]
Reconcile nodes/*funcs.c with PostgreSQL 12 work.

One would have needed out-of-tree code to observe the defects.  Remove
unreferenced fields instead of completing their support functions.
Since in-tree code can't reach _readIntoClause(), no catversion bump.

4 years agoSwitch position of some declarations in libpq.h
Michael Paquier [Sun, 9 Jun 2019 02:33:52 +0000 (11:33 +0900)]
Switch position of some declarations in libpq.h

This makes the header more consistent with the surroundings, with
declarations associated to a given file grouped together.

Author: Daniel Gustafsson
Discussion: https://postgr.es/m/20190608012439.GB7228@paquier.xyz

4 years agoFix some typos
Michael Paquier [Sun, 9 Jun 2019 02:25:56 +0000 (11:25 +0900)]
Fix some typos

Author: Guillaume Lelarge
Discussion: https://postgr.es/m/CAECtzeWPz4JikzUqZdMjqPTe8dAP3nZxPD-58Y-Hhvirg0fF+A@mail.gmail.com

4 years agoUpdate documentation about SIGKILL of postmaster.
Noah Misch [Sat, 8 Jun 2019 17:12:26 +0000 (10:12 -0700)]
Update documentation about SIGKILL of postmaster.

Removing shared memory and semaphores in response to server start
failure often masks the real problem, a live process associated with the
data directory; see commit 5a907404b52753c4d6c6a7c21765aeaa42fd6a3b.
Since 9.6, it's rarely necessary to kill subprocesses manually.  (When
it is necessary, that commit's HINT will say as much, in all supported
versions.)

4 years agoStop using spelling "nonexistant".
Noah Misch [Sat, 8 Jun 2019 17:12:26 +0000 (10:12 -0700)]
Stop using spelling "nonexistant".

The documentation used "nonexistent" exclusively, and the source tree
used it three times as often as "nonexistant".

4 years agoUpdate stale comments, and fix comment typos.
Noah Misch [Sat, 8 Jun 2019 17:12:26 +0000 (10:12 -0700)]
Update stale comments, and fix comment typos.

4 years agoFix assorted inconsistencies.
Amit Kapila [Sat, 8 Jun 2019 02:46:38 +0000 (08:16 +0530)]
Fix assorted inconsistencies.

There were a number of issues in the recent commits which include typos,
code and comments mismatch, leftover function declarations.  Fix them.

Reported-by: Alexander Lakhin
Author: Alexander Lakhin, Amit Kapila and Amit Langote
Reviewed-by: Amit Kapila
Discussion: https://postgr.es/m/ef0c0232-0c1d-3a35-63d4-0ebd06e31387@gmail.com

4 years agoMove be-gssapi-common.h into src/include/libpq/
Michael Paquier [Sat, 8 Jun 2019 00:59:02 +0000 (09:59 +0900)]
Move be-gssapi-common.h into src/include/libpq/

The file has been introduced in src/backend/libpq/ as of b0b39f72, but
all backend-side headers of libpq are located in src/include/libpq/.
Note that the identification path on top of the file referred to
src/include/libpq/ from the start.

Author: Michael Paquier
Reviewed-by: Stephen Frost
Discussion: https://postgr.es/m/20190607043415.GE1736@paquier.xyz

4 years agoImprove some comments in pg_checksums about the needed clean shutdown
Michael Paquier [Fri, 7 Jun 2019 11:48:39 +0000 (20:48 +0900)]
Improve some comments in pg_checksums about the needed clean shutdown

It was not clear from the code why it is necessary.  And we need a clean
shutdown to avoid random checksum failures caused by torn pages.

Author: Masahiko Sawada
Discussion: https://postgr.es/m/CAD21AoDum5MbAb7F=pa9dOD1W2tukuDMPzWT7NjZceNoWB_6Qw@mail.gmail.com

4 years agoFix copy-pasto in freeing memory on error in vacuumlo.
Heikki Linnakangas [Fri, 7 Jun 2019 09:42:27 +0000 (12:42 +0300)]
Fix copy-pasto in freeing memory on error in vacuumlo.

It's harmless to call PQfreemem() with a NULL argument, so the only
consequence was that if allocating 'schema' failed, but allocating 'table'
or 'field' succeeded, we would leak a bit of memory. That's highly
unlikely to happen, so this is just academical, but let's get it right.

Per bug #15838 from Timur Birsh. Backpatch back to 9.5, where the
PQfreemem() calls were introduced.

Discussion: https://www.postgresql.org/message-id/15838-3221652c72c5e69d@postgresql.org

4 years agoFix default_tablespace usage for partitioned tables
Alvaro Herrera [Fri, 7 Jun 2019 04:44:17 +0000 (00:44 -0400)]
Fix default_tablespace usage for partitioned tables

In commit 87259588d0ab I (Álvaro) tried to rationalize the determination
of tablespace to use for partitioned tables, but failed to handle the
default_tablespace case.  Repair and add proper tests.

Author: Amit Langote, Rushabh Lathia
Reported-by: Rushabh Lathia
Reviewed-by: Amit Langote, Álvaro Herrera
Discussion: https://postgr.es/m/CAGPqQf0cYjm1=rjxk_6gU0SjUS70=yFUAdCJLwWzh9bhNJnyVg@mail.gmail.com

4 years agoFix inconsistency in comments atop ExecParallelEstimate.
Amit Kapila [Thu, 6 Jun 2019 23:53:52 +0000 (05:23 +0530)]
Fix inconsistency in comments atop ExecParallelEstimate.

When this code was initially introduced in commit d1b7c1ff, the structure
used was SharedPlanStateInstrumentation, but later when it got changed to
Instrumentation structure in commit b287df70, we forgot to update the
comment.

Reported-by: Wu Fei
Author: Wu Fei
Reviewed-by: Amit Kapila
Backpatch-through: 9.6
Discussion: https://postgr.es/m/52E6E0843B9D774C8C73D6CF64402F0562215EB2@G08CNEXMBPEKD02.g08.fujitsu.local

4 years agoFix message style
Alvaro Herrera [Thu, 6 Jun 2019 16:18:14 +0000 (12:18 -0400)]
Fix message style

Mark one message not for translation, and prefer "cannot" over "may
not", per commentary from Robert Haas.

Discussion: https://postgr.es/m/20190430145813.GA29872@alvherre.pgsql

4 years agoAdd forgotten translatable string in pg_checksums.c
Michael Paquier [Thu, 6 Jun 2019 13:10:52 +0000 (22:10 +0900)]
Add forgotten translatable string in pg_checksums.c

Oversight in commit 280e5f1.

Author: Kyotaro Horiguchi
Discussion: https://postgr.es/m/20190606.200612.110313249.horikyota.ntt@gmail.com

4 years agopg_waldump: Fix invalid option handling
Peter Eisentraut [Wed, 5 Jun 2019 20:55:16 +0000 (22:55 +0200)]
pg_waldump: Fix invalid option handling

Previously, running pg_waldump with an invalid option (pg_waldump
--foo) would print the help output and exit successfully.  This was
because it tried to process the option letter '?' as a normal option,
but that letter is used by getopt() to report an invalid option.

To fix, process help and version options separately, like we do
everywhere else.  Also add a basic test suite for pg_waldump and run
the basic option handling tests, which would have caught this.

4 years agoFix confusion on different kinds of slots in IndexOnlyScans.
Heikki Linnakangas [Thu, 6 Jun 2019 06:46:52 +0000 (09:46 +0300)]
Fix confusion on different kinds of slots in IndexOnlyScans.

We used the same slot to store a tuple from the index, and to store a
tuple from the table. That's not OK. It worked with the heap, because
heapam_getnextslot() stores a HeapTuple to the slot, and doesn't care how
large the tts_values/nulls arrays are. But when I played with a toy table
AM implementation that used a virtual tuple, it caused memory overruns.

In the passing, tidy up comments on the ioss_PscanLen fields.

4 years agoDocs: concurrent builds of partitioned indexes are not supported
David Rowley [Thu, 6 Jun 2019 00:36:37 +0000 (12:36 +1200)]
Docs: concurrent builds of partitioned indexes are not supported

Document that CREATE INDEX CONCURRENTLY is not currently supported for
indexes on partitioned tables.

Discussion: https://postgr.es/m/CAKJS1f_CErd2z9L21Q8OGLD4TgH7yw1z9MAtHTSO13sXVG-yow@mail.gmail.com
Backpatch-through: 11

4 years agodoc: Add links to tables
Peter Eisentraut [Wed, 5 Jun 2019 20:08:50 +0000 (22:08 +0200)]
doc: Add links to tables

Formal tables should generally have an xref in the text that points to
them.  Add them here.

4 years agoFix confusing NOTICE text in REINDEX CONCURRENTLY
David Rowley [Wed, 5 Jun 2019 09:05:41 +0000 (21:05 +1200)]
Fix confusing NOTICE text in REINDEX CONCURRENTLY

When performing REINDEX TABLE CONCURRENTLY, if all of the table's indexes
could not be reindexed, a NOTICE message claimed that the table had no
indexes.  This was confusing, so let's change the NOTICE text to something
less confusing.

In passing, also mention in the comment before ReindexRelationConcurrently
that materialized views are supported too and also explain what the return
value of the function means.

Author: Ashwin Agrawal
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/CALfoeithHvi13p_VyR8kt9o6Pa7Z=Smi6Nfc2anHnQx5Lj8bTQ@mail.gmail.com

4 years agoFix incorrect index behavior in COPY FROM with partitioned tables
David Rowley [Wed, 5 Jun 2019 06:28:38 +0000 (18:28 +1200)]
Fix incorrect index behavior in COPY FROM with partitioned tables

86b85044e rewrote how COPY FROM works to allow multiple tuple buffers to
exist to once thus allowing multi-inserts to be used in more cases with
partitioned tables.  That commit neglected to update the estate's
es_result_relation_info when flushing the insert buffer to the partition
making it possible for the index tuples to be added into an index on the
wrong partition.

Fix this and also add an Assert in ExecInsertIndexTuples to help ensure
that we never make this mistake again.

Reported-by: Haruka Takatsuka
Author: Ashutosh Sharma
Discussion: https://postgr.es/m/15832-b1bf336a4ee246b5@postgresql.org

4 years agoRework code using list_delete_cell() in MergeAttributes
Michael Paquier [Wed, 5 Jun 2019 06:01:14 +0000 (15:01 +0900)]
Rework code using list_delete_cell() in MergeAttributes

When merging two attributes, we are sure that at least one remains.
However, when deleting one element in the attribute list we may finish
with an empty list returned as NIL by list_delete_cell(), but the code
failed to track that, which is not project-like.  Adjust the call so as
we check for an empty list, and make use of it in an assertion.

This has been introduced by e7b3349, when adding support for CREATE
TABLE OF.

Author: Mark Dilger
Reviewed-by: Álvaro Herrera, Michael Paquier
Discussion: https://postgr.es/m/CAE-h2TpPDqSWgOvfvSziOaMngMPwW+QZcmPpY8hQ_KOJ2+3hXQ@mail.gmail.com

4 years agoDocument piecemeal construction of partitioned indexes
Alvaro Herrera [Tue, 4 Jun 2019 20:42:40 +0000 (16:42 -0400)]
Document piecemeal construction of partitioned indexes

Continuous operation cannot be achieved without applying this technique,
so it needs to be properly described.

Author: Álvaro Herrera
Reported-by: Tom Lane
Discussion: https://postgr.es/m/8756.1556302759@sss.pgh.pa.us

4 years agodoc: Fix whitespace
Peter Eisentraut [Tue, 4 Jun 2019 11:57:38 +0000 (13:57 +0200)]
doc: Fix whitespace

Verbatim environment tags should not be indented.

4 years agoAdd command column to pg_stat_progress_create_index
Peter Eisentraut [Tue, 4 Jun 2019 07:16:02 +0000 (09:16 +0200)]
Add command column to pg_stat_progress_create_index

This allows determining which command is running, similar to
pg_stat_progress_cluster.

Discussion: https://www.postgresql.org/message-id/flat/f0e56b3b-74b7-6cbc-e207-a5ed6bee18dc%402ndquadrant.com

4 years agoFix some typos and inconsistencies in tableam.h
Michael Paquier [Tue, 4 Jun 2019 00:48:25 +0000 (09:48 +0900)]
Fix some typos and inconsistencies in tableam.h

The defined callback definitions have been using references to heap for
a couple of variables and comments.  This makes the whole interface more
consistent by using "table" which is more generic.

A variable storing index information was misspelled as well.

Author: Michael Paquier
Discussion: https://postgr.es/m/20190601190946.GB1905@paquier.xyz

4 years agoFix contrib/auto_explain to not cause problems in parallel workers.
Tom Lane [Mon, 3 Jun 2019 22:06:04 +0000 (18:06 -0400)]
Fix contrib/auto_explain to not cause problems in parallel workers.

A parallel worker process should not be making any decisions of its
own about whether to auto-explain.  If the parent session process
passed down flags asking for instrumentation data, do that, otherwise
not.  Trying to enable instrumentation anyway leads to bugs like the
"could not find key N in shm TOC" failure reported in bug #15821
from Christian Hofstaedtler.

We can implement this cheaply by piggybacking on the existing logic
for not doing anything when we've chosen not to sample a statement.

While at it, clean up some tin-eared coding related to the sampling
feature, including an off-by-one error that meant that asking for 1.0
sampling rate didn't actually result in sampling every statement.

Although the specific case reported here only manifested in >= v11,
I believe that related misbehaviors can be demonstrated in any version
that has parallel query; and the off-by-one error is certainly there
back to 9.6 where that feature was added.  So back-patch to 9.6.

Discussion: https://postgr.es/m/15821-5eb422e980594075@postgresql.org

4 years agoFix unsafe memory management in CloneRowTriggersToPartition().
Tom Lane [Mon, 3 Jun 2019 20:59:16 +0000 (16:59 -0400)]
Fix unsafe memory management in CloneRowTriggersToPartition().

It's not really supported to call systable_getnext() in a different
memory context than systable_beginscan() was called in, and it's
*definitely* not safe to do so and then reset that context between
calls.  I'm not very clear on how this code survived
CLOBBER_CACHE_ALWAYS testing ... but Alexander Lakhin found a case
that would crash it pretty reliably.

Per bug #15828.  Fix, and backpatch to v11 where this code came in.

Discussion: https://postgr.es/m/15828-f6ddd7df4852f473@postgresql.org

4 years agoUpdate SQL conformance information about JSON path
Peter Eisentraut [Mon, 3 Jun 2019 19:33:01 +0000 (21:33 +0200)]
Update SQL conformance information about JSON path

Reviewed-by: Oleg Bartunov <obartunov@postgrespro.ru>
4 years agoFix typos in various places
Michael Paquier [Mon, 3 Jun 2019 04:44:03 +0000 (13:44 +0900)]
Fix typos in various places

Author: Andrea Gelmini
Reviewed-by: Michael Paquier, Justin Pryzby
Discussion: https://postgr.es/m/20190528181718.GA39034@glet

4 years agoFix some issues and improve psql completion for access methods
Michael Paquier [Mon, 3 Jun 2019 02:02:32 +0000 (11:02 +0900)]
Fix some issues and improve psql completion for access methods

The following issues have been spotted:
- CREATE INDEX .. USING suggests both index and table AMs, but it should
consider only index AMs.
- CREATE TABLE .. USING has no completion support.  USING was not being
included in the completion list where it should, and follow-up
suggestions for table AMs have been missing as well.
- CREATE ACCESS METHOD .. TYPE suggests only INDEX, with TABLE missing.

Author: Michael Paquier
Discussion: https://postgr.es/m/20190601191007.GC1905@paquier.xyz

4 years agoMake cpluspluscheck more portable.
Tom Lane [Sun, 2 Jun 2019 17:45:01 +0000 (13:45 -0400)]
Make cpluspluscheck more portable.

Teach it to scrape -I and -D switches from CPPFLAGS in Makefile.global.
This is useful for testing on, eg, FreeBSD, where you won't get far
without "-I/usr/local/include".

Also, expand the set of blacklisted-for-unportability atomics headers,
based on noting that arch-x86.h fails to compile on an ARM box.  The
other ones I'd omitted seem to compile all right on architectures they
don't belong to, but that's surely too shaky to rely on.  Let's do
like we did for the src/include/port/ headers, and ignore all except
the variant that's pulled in by the arch-independent header.

4 years agoClean up PL/Perl's handling of the _() macro.
Tom Lane [Sun, 2 Jun 2019 16:23:39 +0000 (12:23 -0400)]
Clean up PL/Perl's handling of the _() macro.

Perl likes to redefine the _() macro:

#ifdef CAN_PROTOTYPE
#define _(args) args
#else ...

There was lots not to like about the way we dealt with this before:

1. Instead of taking care of the conflict centrally in plperl.h, we
expected every one of its ever-growing number of includers to do so.
This is duplicative and error-prone in itself, plus it means that
plperl.h fails to meet the expectation of being compilable standalone,
resulting in macro-redefinition warnings in cpluspluscheck.

2. We left _() with its Perl definition, meaning that if someone tried
to use it in any Perl-related extension, it would silently fail to
provide run-time translation.  I don't see any live bugs of this ilk,
but it's clearly a hard-to-notice bug waiting to happen.

So fix that by centralizing the cleanup logic, making it match what
we're already doing for other macro conflicts with Perl.  Since we only
expect plperl.h to be included by extensions not core code, we should
redefine _() as dgettext() not gettext().

4 years agoworker_spi needs a .gitignore file now.
Tom Lane [Sun, 2 Jun 2019 15:13:23 +0000 (11:13 -0400)]
worker_spi needs a .gitignore file now.

4 years agoUn-break ecpg tests for Windows.
Tom Lane [Sun, 2 Jun 2019 15:07:54 +0000 (11:07 -0400)]
Un-break ecpg tests for Windows.

Declaring a function "inline" still doesn't work with Windows compilers
(C99? what's that?), unless the macro provided by pg_config.h is
in-scope, which it is not in our ECPG test programs.  So the workaround
I tried to use in commit 7640f9312 doesn't work for Windows.  Revert
the change in printf_hack.h, and instead just blacklist that file
in cpluspluscheck --- since it's a not-installed test file, we don't
really need to verify its C++ cleanliness anyway.

4 years agoIncrease test coverage for worker_spi by ∞%
Alvaro Herrera [Sun, 2 Jun 2019 04:29:49 +0000 (00:29 -0400)]
Increase test coverage for worker_spi by ∞%

This test module was not getting invoked, other than at compile time,
limiting its usefulness -- and keeping its coverage at 0%.  Add a
minimal regression test to ensure it runs on make check-world; this
makes it 92% covered (line-wise), which seems sufficient.

Author: Álvaro Herrera <alvherre@alvh.no-ip.org>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/20190529193256.GA17603@alvherre.pgsql

4 years agoFix documentation of check_option in information_schema.views
Michael Paquier [Sat, 1 Jun 2019 19:33:47 +0000 (15:33 -0400)]
Fix documentation of check_option in information_schema.views

Support of CHECK OPTION for updatable views has been added in 9.4, but
the documentation of information_schema never got the call even if the
information displayed is correct.

Author: Gilles Darold
Discussion: https://postgr.es/m/75d07704-6c74-4f26-656a-10045c01a17e@darold.net
Backpatch-through: 9.4

5 years agoImprove coverage of cpluspluscheck.
Tom Lane [Fri, 31 May 2019 20:32:07 +0000 (16:32 -0400)]
Improve coverage of cpluspluscheck.

Formerly, cpluspluscheck was only meant to examine headers that
we thought of as exported --- but its notion of what we export
was well behind the times.  Let's just make it check *all* .h
files, except for a well-defined blacklist, instead.

While at it, improve its ability to use a C++ compiler other than g++,
by scraping the CXX setting from Makefile.global and making it possible
to override the warning options used (per suggestion from Andres Freund).

Discussion: https://postgr.es/m/b517ec3918d645eb950505eac8dd434e@gaz-is.ru

5 years agoIntegrate cpluspluscheck into build system.
Andres Freund [Fri, 31 May 2019 19:36:17 +0000 (12:36 -0700)]
Integrate cpluspluscheck into build system.

Previously cpluspluscheck wouldn't work in vpath builds, this commit
fixes that. To make it easier to invoke, there's a top-level
cpluspluscheck target.

Discussion: https://postgr.es/20190530220244.kiputcbl4gkl2oo6@alap3.anarazel.de

5 years agoFix incorrect parameter name in comment
David Rowley [Fri, 31 May 2019 17:30:05 +0000 (13:30 -0400)]
Fix incorrect parameter name in comment

Author: Antonin Houska
Discussion: https://postgr.es/m/22370.1559293357@localhost

5 years agoAdjust ecpg expected-results files for commit 7640f9312.
Tom Lane [Fri, 31 May 2019 16:47:19 +0000 (12:47 -0400)]
Adjust ecpg expected-results files for commit 7640f9312.

Mea culpa for not rechecking check-world at the last step :-(
Per buildfarm.

5 years agoFix C++ incompatibilities in ecpg/preproc/ header files.
Tom Lane [Fri, 31 May 2019 16:38:53 +0000 (12:38 -0400)]
Fix C++ incompatibilities in ecpg/preproc/ header files.

There's probably no need to back-patch this, since it seems unlikely
that anybody would be inserting C++ code into ecpg's preprocessor.

Discussion: https://postgr.es/m/b517ec3918d645eb950505eac8dd434e@gaz-is.ru

5 years agoFix C++ incompatibilities in plpgsql's header files.
Tom Lane [Fri, 31 May 2019 16:34:54 +0000 (12:34 -0400)]
Fix C++ incompatibilities in plpgsql's header files.

Rename some exposed parameters so that they don't conflict with
C++ reserved words.

Back-patch to all supported versions.

George Tarasov

Discussion: https://postgr.es/m/b517ec3918d645eb950505eac8dd434e@gaz-is.ru

5 years agoFix assorted header files that failed to compile standalone.
Tom Lane [Fri, 31 May 2019 15:45:33 +0000 (11:45 -0400)]
Fix assorted header files that failed to compile standalone.

We have a longstanding project convention that all .h files should
be includable with no prerequisites other than postgres.h.  This is
tested/relied-on by cpluspluscheck.  However, cpluspluscheck has not
historically been applied to most headers outside the src/include
tree, with the predictable consequence that some of them don't work.
Fix that, usually by adding missing #include dependencies.

The change in printf_hack.h might require some explanation: without
it, my C++ compiler whines that the function is unused.  There's
not so many call sites that "inline" is going to cost much, and
besides all the callers are in test code that we really don't care
about the size of.

There's no actual bugs being fixed here, so I see no need to back-patch.

Discussion: https://postgr.es/m/b517ec3918d645eb950505eac8dd434e@gaz-is.ru

5 years agoMake our perfect hash functions be valid C++.
Tom Lane [Fri, 31 May 2019 14:40:00 +0000 (10:40 -0400)]
Make our perfect hash functions be valid C++.

While C is happy to cast "const void *" to "const unsigned char *"
silently, C++ insists on an explicit cast.  Since we put these
functions into header files, cpluspluscheck whines about that.
Add the cast to pacify it.

Discussion: https://postgr.es/m/b517ec3918d645eb950505eac8dd434e@gaz-is.ru

5 years agoFix double-phrase typo in message
Alvaro Herrera [Fri, 31 May 2019 14:08:37 +0000 (10:08 -0400)]
Fix double-phrase typo in message

New in 147e3722f7e5.

5 years agoRework options of pg_checksums options for filenode handling
Michael Paquier [Thu, 30 May 2019 20:58:17 +0000 (16:58 -0400)]
Rework options of pg_checksums options for filenode handling

This makes the tool consistent with the option set of oid2name, which
has been historically using -f for filenodes, and has more recently
gained long options and --filenode via 1aaf532.

Reported-by: Peter Eisentraut
Author: Fabien Coelho
Discussion: https://postgr.es/m/97045260-fb9e-e145-a950-cf7d28c4eaea@2ndquadrant.com

5 years agoRemove unnecessary (and wrong) forward declaration.
Andres Freund [Thu, 30 May 2019 20:44:38 +0000 (13:44 -0700)]
Remove unnecessary (and wrong) forward declaration.

Interestingly only C++ compilers have, so far, complained about this
odd forward declaration. This originated when IndexBuildCallback was
defined in another file, but now is completely unnecessary (but was
wrong before too, cpluspluscheck just wouldn't have noticed).

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

5 years agoMake error logging in extended statistics more consistent
Tomas Vondra [Thu, 30 May 2019 14:16:12 +0000 (16:16 +0200)]
Make error logging in extended statistics more consistent

Most errors reported in extended statistics are internal issues, and so
should use elog(). The MCV list code was already following this rule, but
the functional dependencies and ndistinct coefficients were using a mix
of elog() and ereport(). Fix this by changing most places to elog(), with
the exception of input functions.

This is a mostly cosmetic change, it makes the life a little bit easier
for translators, as elog() messages are not translated. So backpatch to
PostgreSQL 10, where extended statistics were introduced.

Author: Tomas Vondra
Backpatch-through: 10 where extended statistics were added
Discussion: https://postgr.es/m/20190503154404.GA7478@alvherre.pgsql

5 years agoFix some documentation about access methods
Michael Paquier [Wed, 29 May 2019 15:37:37 +0000 (11:37 -0400)]
Fix some documentation about access methods

Author: Guillaume Lelarge
Discussion: https://postgr.es/m/CAECtzeWPz4JikzUqZdMjqPTe8dAP3nZxPD-58Y-Hhvirg0fF+A@mail.gmail.com

5 years agoFix some documentation about FKs and partitioned tables
Michael Paquier [Wed, 29 May 2019 15:19:06 +0000 (11:19 -0400)]
Fix some documentation about FKs and partitioned tables

This got forgotten in f56f8f which has added foreign key support for
partitioned tables.  In passing, add a mention about caveats applying to
tables partitioned using inheritance regarding indexes and foreign keys.

Author: Paul A Jungwirth
Reviewed-by: Amit Langote, Michael Paquier
Discussion: https://postgr.es/m/CA+renyUuSmYgmZjKc_DfUNVZ0uttF91-FwhDVW3F7WEPj0jL5w@mail.gmail.com

5 years agoMake one message just like all its siblings.
Alvaro Herrera [Wed, 29 May 2019 03:44:22 +0000 (23:44 -0400)]
Make one message just like all its siblings.