postgres-xl.git
7 years agoEnsure config changes caused by functions are rolled back correctly.
Pavan Deolasee [Fri, 28 Sep 2018 09:24:11 +0000 (14:54 +0530)]
Ensure config changes caused by functions are rolled back correctly.

When a function body has SET clauses attached to it, the function
validation/execution reflects those config changes locally as well as on the
remote nodes. But we were failing to restore the old values back when the
command ends. This had gone unnoticed so far for the lack of any test case
exercising this code. Note that there were existing test cases in this area,
but the bug got unmasked only after we added a temporary table in the session.
When a temporary table is accessed in a session, we don't reset the session at
the end of the transaction and hence the issue surfaced.

This was causing failure in a new test added in the 'rules' test. This patch
fixes that.

7 years agoAccept regression diffs in 'object_address' test case.
Pavan Deolasee [Fri, 28 Sep 2018 07:44:34 +0000 (13:14 +0530)]
Accept regression diffs in 'object_address' test case.

The differences are caused by our lack of support for CREATE
SUBSCRIPTION/PUBLICATION

7 years agoAccept regression diffs in 'portal' test case.
Pavan Deolasee [Fri, 28 Sep 2018 07:40:17 +0000 (13:10 +0530)]
Accept regression diffs in 'portal' test case.

One change relates to the addition of Remote Subplan node and the other relates
to our lack of support for WHERE CURRENT OF

7 years agoFix an oversight in c8a42a0726911b737837d6763707c7d14d9a2987
Pavan Deolasee [Fri, 28 Sep 2018 06:49:43 +0000 (12:19 +0530)]
Fix an oversight in c8a42a0726911b737837d6763707c7d14d9a2987

Well spotted by Virendra Kumar

7 years agoSome edits to a TAP test
Pavan Deolasee [Fri, 28 Sep 2018 05:48:43 +0000 (11:18 +0530)]
Some edits to a TAP test

7 years agoMinor refactoring of the code to send down SET options
Pavan Deolasee [Fri, 28 Sep 2018 04:33:16 +0000 (10:03 +0530)]
Minor refactoring of the code to send down SET options

7 years agoAdd a TAP test to do sanity tests post addition of coordinators/datanodes.
Pavan Deolasee [Thu, 27 Sep 2018 09:56:23 +0000 (15:26 +0530)]
Add a TAP test to do sanity tests post addition of coordinators/datanodes.

Its a very simplistic test right now, but hopefully we can extend this further
in the coming time.

7 years agoUse read-write transaction to dump a database
Pavan Deolasee [Wed, 26 Sep 2018 17:11:59 +0000 (22:41 +0530)]
Use read-write transaction to dump a database

In XL we use nextval() to get a consistent value of a sequence since different
nodes may have stale view of the sequence and hence we must obtain a value from
the GTM. Calling nextval() though requires us to execute the transaction in
read-write mode. So we do that. It shouldn't be a big deal since pg_dump is
very careful about only reading from the database (it was only recently the
transaction was made read-only). More to the point, in XL we'd never used
read-only transaction while dumping a database, but by default direct
connection to a datanode are treated as read-only transaction and hence merely
removing READ ONLY transaction attribute wasn't enough. We had to explicitly
mark it READ WRITE to override the default datanode behaviour.

Per report by Virendra Kumar

7 years agoAccept regression diff in 'xml' test case casued by merge issue
Pavan Deolasee [Wed, 26 Sep 2018 09:29:33 +0000 (14:59 +0530)]
Accept regression diff in 'xml' test case casued by merge issue

7 years agoAccept regression diffs arising due to lack of FDW support
Pavan Deolasee [Wed, 26 Sep 2018 09:25:52 +0000 (14:55 +0530)]
Accept regression diffs arising due to lack of FDW support

7 years agoAccept regression diffs arising due to lack of trigger support
Pavan Deolasee [Wed, 26 Sep 2018 09:24:23 +0000 (14:54 +0530)]
Accept regression diffs arising due to lack of trigger support

7 years agoAccept expected output diffs pertaining to Remote Subplan addition
Pavan Deolasee [Wed, 26 Sep 2018 09:19:55 +0000 (14:49 +0530)]
Accept expected output diffs pertaining to Remote Subplan addition

All these test caes were failing because of Remote Subplan nodes in the explain
output.

7 years agoAccept regression diffs in 'inherit' test case
Pavan Deolasee [Wed, 26 Sep 2018 08:26:21 +0000 (13:56 +0530)]
Accept regression diffs in 'inherit' test case

We're simply adding Remote Subplan nodes to the query plans

7 years agoAccept regression diff in 'create_table' test
Pavan Deolasee [Wed, 26 Sep 2018 08:24:49 +0000 (13:54 +0530)]
Accept regression diff in 'create_table' test

We're simply printing the distribution info too

7 years agoAmend and accept regression diffs in 'insert' test case
Pavan Deolasee [Wed, 26 Sep 2018 08:22:16 +0000 (13:52 +0530)]
Amend and accept regression diffs in 'insert' test case

We don't support triggers and hence the do-nothing trigger doesn't have the
desired effect in XL. As a result, the inserts are not skipped in XL (while
they are skipped because the before-row trigger returns nothing).  Also we
expect columns to be in the same order for partitions. So make those changes
too.

7 years agoEnsure datanode WAL directory changes are reflected on failover.
Pavan Deolasee [Wed, 26 Sep 2018 07:21:28 +0000 (12:51 +0530)]
Ensure datanode WAL directory changes are reflected on failover.

We'd failed to take into account the changes to WAL dirs in pgxc_ctl.conf upon
failover. This would later cause issues while reading the conf file.

Per report and patch by Virendra Kumar

7 years agoMerge tag 'REL_10_5' into XL_10_STABLE
Pavan Deolasee [Tue, 25 Sep 2018 11:04:43 +0000 (16:34 +0530)]
Merge tag 'REL_10_5' into XL_10_STABLE

7 years agoChange some expected output files to reflect change in error message
Pavan Deolasee [Tue, 25 Sep 2018 09:25:01 +0000 (14:55 +0530)]
Change some expected output files to reflect change in error message

This accounts for the change in the error message introduced in
305ad92ae05a7a367501be3f68cde9ff9f827622.

7 years agoLeverage binary-upgrade facility of pg_dump
Pavan Deolasee [Thu, 20 Sep 2018 08:56:42 +0000 (14:26 +0530)]
Leverage binary-upgrade facility of pg_dump

While adding a new coordinator or a datanode, we take a schema dump of an
existing node and restore it on the new node. This has some problems,
especially while restoring tables with dropped columns and different column
ordering. The new node won't restore the dropped columns and may recreate
columns in different ordering, for inheritted tables for example. This then
leads to issues during query execution.

We now leverage binary-upgrade dump facility available in pg_dump/pg_restore.
While XL is not very sensitive to OID preservation across nodes, we do care
about column ordering. So binary-upgrade's OID preservation facility is of not
great interest to us, but it shouldn't harm also.

Also ensure that while restoring sequence states, we don't force update the GTM
state.

A tap test is added to check the node addition this way.

The original report came from Krzysztof Nienartowicz. Patch and further work by
me.

7 years agoCorrect error message to use word "distributed" instead of "partitioned".
Pavan Deolasee [Wed, 19 Sep 2018 06:38:44 +0000 (12:08 +0530)]
Correct error message to use word "distributed" instead of "partitioned".

Per report by Pallavi Sontakke

7 years agoAdd test for Set Returning Functions
Pallavi Sontakke [Fri, 14 Sep 2018 07:18:32 +0000 (12:48 +0530)]
Add test for Set Returning Functions

Fixes #204

7 years agoEnsure consistent output in the 'select_views' test case
Pavan Deolasee [Tue, 18 Sep 2018 10:31:43 +0000 (16:01 +0530)]
Ensure consistent output in the 'select_views' test case

We added ORDER BY clause to the query, but that returns different ordering
depending on the LC_COLLATE setting on a given machine. So enforce the correct
ordering by specifying the desired collation in the query itself.

7 years agoCorrect date in the release notes
Pavan Deolasee [Mon, 17 Sep 2018 13:44:39 +0000 (19:14 +0530)]
Correct date in the release notes

7 years agoRestamp Postgres-XL 10r1beta1 correctly this time.
Pavan Deolasee [Mon, 17 Sep 2018 09:56:58 +0000 (15:26 +0530)]
Restamp Postgres-XL 10r1beta1 correctly this time.

7 years agoCorrect some typos in the release notes
Pavan Deolasee [Mon, 17 Sep 2018 09:56:32 +0000 (15:26 +0530)]
Correct some typos in the release notes

7 years agoStamp Postgres-XL 10r1beta1 XL_10_R1BETA1
Pavan Deolasee [Fri, 14 Sep 2018 08:12:06 +0000 (13:42 +0530)]
Stamp Postgres-XL 10r1beta1

7 years agoMake COPYRIGHT changes
Pavan Deolasee [Mon, 17 Sep 2018 04:09:26 +0000 (09:39 +0530)]
Make COPYRIGHT changes

7 years agoSome updates to the release notes draft
Pavan Deolasee [Fri, 14 Sep 2018 07:53:44 +0000 (13:23 +0530)]
Some updates to the release notes draft

7 years agoFix couple of compiler warnings
Pavan Deolasee [Fri, 14 Sep 2018 05:51:02 +0000 (11:21 +0530)]
Fix couple of compiler warnings

7 years agoFix some more compiler warnings
Pavan Deolasee [Fri, 14 Sep 2018 05:29:48 +0000 (10:59 +0530)]
Fix some more compiler warnings

7 years agoRemove some unused variables, fix compiler warnings
Pavan Deolasee [Fri, 14 Sep 2018 04:47:59 +0000 (10:17 +0530)]
Remove some unused variables, fix compiler warnings

7 years agoFix a few compiler warnings
Pavan Deolasee [Fri, 14 Sep 2018 04:43:54 +0000 (10:13 +0530)]
Fix a few compiler warnings

7 years agoWrite draft release notes for Postgres-XL 10r1beta1
Pavan Deolasee [Thu, 13 Sep 2018 10:12:14 +0000 (15:42 +0530)]
Write draft release notes for Postgres-XL 10r1beta1

7 years agoAdding missing documentation for pgxl_remote_fetch_size
Pavan Deolasee [Thu, 13 Sep 2018 10:11:34 +0000 (15:41 +0530)]
Adding missing documentation for pgxl_remote_fetch_size

7 years agoInitialise a variable correctly.
Pavan Deolasee [Wed, 12 Sep 2018 09:15:55 +0000 (14:45 +0530)]
Initialise a variable correctly.

This was leading to unexpected/unexplained crashes in the cluster monitor
process. Per reprot by Hengbing

7 years agoDisable FQS for explicit cursor queries.
Pavan Deolasee [Wed, 12 Sep 2018 08:55:57 +0000 (14:25 +0530)]
Disable FQS for explicit cursor queries.

The FQS mechanism is not currently handling cursors well as seen by failures in
the 'combocid' test case. The regular planner handles it well though. So for
now disable FQS for such queries.

Also remove the restriction that TID scan cannot be performed by non-FQS
queries. Regression does not throw up any errors. So remove the restriction
unless we see a counter example.

Tomas Vondra commented that this works fine in XL 9.5, so most likely we might
be failing to send a proper snapshot to the datanodes. Further investigations
required.

7 years agoAccept regression diffs in 'xml' test case
Pavan Deolasee [Wed, 12 Sep 2018 08:54:43 +0000 (14:24 +0530)]
Accept regression diffs in 'xml' test case

They are related to our lack of support for subtransactions (exception blocks)
and adding Remote Subquery Scan plan nodes.

7 years agoTest ALTER TABLE.. ADD PRIMARY KEY
Amruta Deolasee [Tue, 11 Sep 2018 06:02:56 +0000 (06:02 +0000)]
Test ALTER TABLE.. ADD PRIMARY KEY

Ensure that this sets columns NOT NULL on all child tables on all nodes

7 years agotest ALTER TYPE.. RENAME VALUE
Amruta Deolasee [Mon, 10 Sep 2018 06:44:12 +0000 (06:44 +0000)]
test ALTER TYPE.. RENAME VALUE

7 years agoRun ANALYZE (COORDINATOR) on remote coordinators iff running outside a txn
Pavan Deolasee [Tue, 11 Sep 2018 09:21:09 +0000 (14:51 +0530)]
Run ANALYZE (COORDINATOR) on remote coordinators iff running outside a txn
block

We'd seen some distributed deadlocks when ANALYZE (COORDINATOR) is run on
remote coordinators, in parallel with VACUUM FULL on catalog tables. The
investigations so far indicate that the auxilliary datanode connections from
the other coordinators can lead to a distributed deadlock as the connections
from the originating coordinator still have the transaction open.

We now restrict remote analyze only when we are not running inside a user
transaction block. This allows us to commit the first transaction and then
start a new transaction to run ANALYZE (COORDINATOR) on the remote
coordinators, thus avoiding the distributed deadlock.

Per report from Pallavi Sontakke and lots of analysis by me, which may not
still be sufficient.

7 years agoRemove a problem test from 'inherit' test case
Pavan Deolasee [Tue, 11 Sep 2018 05:55:09 +0000 (11:25 +0530)]
Remove a problem test from 'inherit' test case

There is a problem with reading an anonymous record type, resulting in an error
such as "ERROR:  input of anonymous composite types is not implemented".

This is an existing issue affecting even XL 9.5, but was masked so far by lack
of testing and also because we inadvertently accepted wrong output in XL 9.5.
For now, move the case to xl_known_bugs and open an issue to track this
potential long standing bug.

7 years agoMove failing tests from 'with' to 'xl_known_bugs'
Pavan Deolasee [Fri, 7 Sep 2018 07:51:56 +0000 (13:21 +0530)]
Move failing tests from 'with' to 'xl_known_bugs'

There are two remaining failures in the 'with' test case. Both of these bugs
exist in XL 9.5 too and hence moving them to the xl_known_bugs test case. We
have issues open for these bugs.

7 years agoAdjust 'limit' test case to avoid regression failures.
Pavan Deolasee [Fri, 7 Sep 2018 06:12:38 +0000 (11:42 +0530)]
Adjust 'limit' test case to avoid regression failures.

There are two known problems in the test case.

1. When nextval() is pushed down to the remote nodes, the coordinator session
won't have seen a nextval() invokation and hence a subsequent currval() will
throw an ERROR or return a stale value.

2. When nextval() is pushed down to the remote nodes and a set of rows are
fetched (either ordered or otherwise), the results may be somewhat inconsistent
because each node will run nextval() concurrently and hence the ordering will
change depending on who runs when.

For now, change the queries to force nextval() evaluation on the coordinator.
Also move the original test cases to xl_known_bugs test case and we also have
an internal issue open to track this problem.

7 years agoFetch sn_xcnt just once to ensure consistent msg
Pavan Deolasee [Fri, 7 Sep 2018 06:08:51 +0000 (11:38 +0530)]
Fetch sn_xcnt just once to ensure consistent msg

We're seeing some reports when fetching snapshot from the GTM hangs forever on
the client side, waiting for data which never arrives. One theory is that the
snapshot->sn_xcnt value changes while sending snapshot from the GTM, thus
causing a mismatch between what the server sends and what the client expects.
We fixed a similar problem in 1078b079d5476e3447bd5268b317eacb4c455f5d, but may
be it's not complete. Put in this experimental patch (which can't make things
any worse for sure) while we also investigate other bugs in that area.

7 years agoFix problems associated with globalXmin tracking by ClusterMonitor
Pavan Deolasee [Thu, 6 Sep 2018 08:12:48 +0000 (13:42 +0530)]
Fix problems associated with globalXmin tracking by ClusterMonitor

The very first report by the cluster monitor may be discarded by the GTM if the
reporting xmin has fallen far behind GTM's view. This leads to the globalXmin
value remaining Invalid in the shared memory state, as tracked by the
ClusterMonitor. ClusterMonitor process usually naps for CLUSTER_MONITOR_NAPTIME
(default 5s) between two successive reporting. But discard that during the
bootup process and report the xmin a bit more aggressively. This should in all
likelihood set the globalXmin correctly, before the regular backends start
processing.

The other major problem with the current code was that when the globalXmin
tracked in the shared memory state is Invalid, the callers were using
FirstNormalXid as the globalXmin. This could be disastrous especially when XID
counter has wrapped around. We could accidentally remove visible rows by using
a wrong value of globalXmin. We now fix that by computing the globalXmin using
the local state (just like we would have computed globalXmin in vanilla PG).
This should ensure that we never use a wrong or a newer value for globalXmin
than what is allowed.

Accept regression diff in txid test case resulting from the fix. The new
expected output actually matches with what upstream produces.

Per report by Hengbing and investigations/fix by me.

7 years agoUse correct format specifier for transaction ids
Pavan Deolasee [Wed, 5 Sep 2018 07:56:02 +0000 (13:26 +0530)]
Use correct format specifier for transaction ids

7 years agoRemove duplicate (and unused) declaration of XidStatus
Pavan Deolasee [Wed, 5 Sep 2018 07:14:39 +0000 (12:44 +0530)]
Remove duplicate (and unused) declaration of XidStatus

7 years agoForce restart cluster monitor process if the GTM restarts
Pavan Deolasee [Fri, 31 Aug 2018 09:42:42 +0000 (15:12 +0530)]
Force restart cluster monitor process if the GTM restarts

If GTM loses node registration information and returns
GTM_ERRCODE_NODE_NOT_REGISTERED to the coordinator/datanode, restart the
cluster monitor process (by simply exiting with exit code 0). This would ensure
that the cluster monitor re-registers with the GTM and start cleanly.

Per report by Virendra Kumar

7 years agoEnsure pgxc_node_str returns the result in correct format
Pavan Deolasee [Wed, 29 Aug 2018 05:58:38 +0000 (11:28 +0530)]
Ensure pgxc_node_str returns the result in correct format

Per report from Krzysztof Nienartowicz, this broke the pgxc_clean command on
XL10.

7 years agoAllow minimum value of pgxl_remote_fetch_size to zero
Pavan Deolasee [Thu, 23 Aug 2018 06:20:23 +0000 (11:50 +0530)]
Allow minimum value of pgxl_remote_fetch_size to zero

This is an experimental work. By setting pgxl_remote_fetch_size to 0, user can
fetch all rows at once from the remote side (instead of fetching a small number
at a time, thus giving the node to produce more rows as the previous set is
consumed). While fetching all rows at once is not very useful, it allows us to
circumvent PostgreSQL's limitation of not supporting parallel queries unless a
Portal is run once and to the end.

We do see hangs in regression while running with PGOPTIONS set to "-c
force_parallel_mode=on -c pgxl_remote_fetch_size=0", so there are issues that
need to be addressed. Also, it doesn't seem quite possible for users to
dynamically set pgxl_remote_fetch_size to enforce parallel query. So this is an
experimental feature that we don't expect users to heavily use, just yet.

7 years agoEnsure parallelModeNeeded flag is sent down to the remote node.
Pavan Deolasee [Thu, 23 Aug 2018 05:24:37 +0000 (10:54 +0530)]
Ensure parallelModeNeeded flag is sent down to the remote node.

This still does not solve the problem that the datanodes don't make use of
parallel queries during distributed execution (they work OK if queries are
FQSed). That's because PostgreSQL does not support parallel queries when a
portal is used to fetch only a part of the result set. We need separate patches
to either fix or work-around that.

7 years agoAccept some more regression diffs in inherit.out
Pavan Deolasee [Wed, 22 Aug 2018 06:15:42 +0000 (11:45 +0530)]
Accept some more regression diffs in inherit.out

We changed one test case to use HASH distribution so that a primary key can be
defined. Another diff turned out to be a change from the upstream.

7 years agoFix an assertion failure
Pavan Deolasee [Tue, 21 Aug 2018 11:53:18 +0000 (17:23 +0530)]
Fix an assertion failure

7 years agoEnsure that RemoteSubplan is marked parallel unsafe.
Pavan Deolasee [Tue, 21 Aug 2018 09:54:13 +0000 (15:24 +0530)]
Ensure that RemoteSubplan is marked parallel unsafe.

We can't support multiple backends running RemoteSubplan in parallel. So block
that. In fact, we'd already done so by setting parallel_safe to false while
creating the path, but there is another code path which builds the plan node
directly and we'd missed that.

7 years agoFix an oversight in 32025718755c4bbf100563fdc88e96225fc1b250
Pavan Deolasee [Mon, 20 Aug 2018 10:47:31 +0000 (16:17 +0530)]
Fix an oversight in 32025718755c4bbf100563fdc88e96225fc1b250

In passing, add test cases and fix other issues around fetching table sizes
from remote nodes. For example, temp handling and names requiring quoting was
broken for long too.

Per report by Virendra Kumar and further tests by me.

7 years agoDo not pushdown aggregates with SRFs in the targetlist
Pavan Deolasee [Mon, 20 Aug 2018 10:43:20 +0000 (16:13 +0530)]
Do not pushdown aggregates with SRFs in the targetlist

7 years agoSome minor changes to tsrf test case
Pavan Deolasee [Fri, 17 Aug 2018 10:09:38 +0000 (15:39 +0530)]
Some minor changes to tsrf test case

We don't support SRF in VALUES clause yet. So make some minor adjustments to
the test case.

7 years agoAccept regression diffs in the sequence test case
Pavan Deolasee [Fri, 17 Aug 2018 09:53:33 +0000 (15:23 +0530)]
Accept regression diffs in the sequence test case

These diffs are on the account of differences in the way we handle WAL logging
and sequences on the coordinator. There is scope for improvement here from
usability perspective, but these are not regressions from the past behaviour.

7 years agoMake improvements to sequence handling
Pavan Deolasee [Thu, 16 Aug 2018 12:01:53 +0000 (17:31 +0530)]
Make improvements to sequence handling

We were pre-maturely checking for maximum and minimum values, thus throwing an
error when the maximum/minimum was still farther by one count. Fix that.
Improve the GTM error message by including the sequence name and the max/min
value reached. This though slightly changes the end user error message because
we also include database and schema in the sequence name at the GTM.

Make some changes to the way sequence is WAL logged. This is still not entirely
correct since we log every time a value is fetched from the GTM. But then WAL
logging is not strictly required in XL because sequence values are managed at
the GTM. In the old code, we were not WAL logging at all (though the code
existed and it was a bit confusing)

The sequence tuple is still not maintained correctly at the coordinator because
it may not know about the sequence values fetched and consumed by the
datanodes. But that's an existing problem and we should look at that
separately.

7 years agoEnsure table name is schema qualified while running remote ANALYZE
Pavan Deolasee [Tue, 14 Aug 2018 08:59:53 +0000 (14:29 +0530)]
Ensure table name is schema qualified while running remote ANALYZE

While sending down ANALYZE (COORDINATOR) command to the remote coordinator, we
must ensure that the table name is properly schema qualified. Also add a few
tests to confirm that this works as expected in various scenarios.

Per report by Virendra Kumar.

7 years agoAutomatically trigger ANALYZE (COORDINATOR) on remote coordinators
Pavan Deolasee [Thu, 9 Aug 2018 08:25:05 +0000 (13:55 +0530)]
Automatically trigger ANALYZE (COORDINATOR) on remote coordinators

One of the long standing problems in multi-coordinator setup is that when a
table is either manually ANALYZEd or auto-analyzed on a coordinator, the other
coordinators don't update their planner statistics automatically. This is even
a bigger problem with auto-analyze because a coordinator which is not involved
in any DMLs, may not be even aware about the changes to the table and hence it
will not pick up the table for auto-analyze, thus often generating very poor
query plans.

We now fix that by automatically running ANALYZE (COORDINATOR) command on the
remote coordinators when a table is either manually or automatically analyzed
on one coordinator. ANALYZE (COORDINATOR) does not force a ANALYZE on the
datanodes, but only rebuilts coordinator side stats using the current stats
available on the datanodes.

One problem with running ANALYZE on the remote coordinators in auto-analyze
process is that if one of the coordinators is down or not reachable, then it
will fail. This seems a bit too harsh because the worst that can happen is that
the unreachably coordinator will be left with stale stats. But that seems
better than letting auto-analyze fail on a running coordinator. We address this
by introducing a new mechanism by which a coordinator can execute a
command/query only on the currently available remote coordinators. We consult
the health-map to decide which coordinators are currently reachable. Since the
health-map itself can be stale for some short duration, there is a risk that
auto-analyze may still fail. But it shouldn't fail forever because the node
will be skipped next time.

7 years agoFetch minmxid from remote nodes and compute local value
Pavan Deolasee [Thu, 9 Aug 2018 08:22:28 +0000 (13:52 +0530)]
Fetch minmxid from remote nodes and compute local value

This was a TODO for quite sometime now. Just like we fetch relfrozenxid from
the remote nodes and compute a value at the coordinator, we now do the same for
multi-xid too.

7 years agoRemove some dead/commented code
Pavan Deolasee [Thu, 9 Aug 2018 08:21:11 +0000 (13:51 +0530)]
Remove some dead/commented code

7 years agoCorrectly track XID obtained by autovac as one from the GTM
Pavan Deolasee [Thu, 9 Aug 2018 07:33:58 +0000 (13:03 +0530)]
Correctly track XID obtained by autovac as one from the GTM

We were observing that a transaction started by the autovac process was left
open on the GTM, thus holding back xmin. This must have been a regression after
recent changes to track autocommit and regular transactions. We now correctly
track and close such transactions on the GTM.

7 years agoAdd a test to do sanity check at the end
Pavan Deolasee [Wed, 8 Aug 2018 05:17:21 +0000 (10:47 +0530)]
Add a test to do sanity check at the end

Right now it only contains a test to check replicated tables and confirm that
all nodes have the same number of rows. More to be added later.

7 years agoStamp 10.5.
Tom Lane [Mon, 6 Aug 2018 20:05:31 +0000 (16:05 -0400)]
Stamp 10.5.

7 years agoTranslation updates
Peter Eisentraut [Mon, 6 Aug 2018 18:03:55 +0000 (20:03 +0200)]
Translation updates

Source-Git-URL: https://git.postgresql.org/git/pgtranslation/messages.git
Source-Git-Hash: 3463878fc340cb1436153b18a300f8cfdcb12adb

7 years agoLast-minute updates for release notes.
Tom Lane [Mon, 6 Aug 2018 17:13:41 +0000 (13:13 -0400)]
Last-minute updates for release notes.

Security: CVE-2018-10915, CVE-2018-10925

7 years agoFix failure to reset libpq's state fully between connection attempts.
Tom Lane [Mon, 6 Aug 2018 14:53:35 +0000 (10:53 -0400)]
Fix failure to reset libpq's state fully between connection attempts.

The logic in PQconnectPoll() did not take care to ensure that all of
a PGconn's internal state variables were reset before trying a new
connection attempt.  If we got far enough in the connection sequence
to have changed any of these variables, and then decided to try a new
server address or server name, the new connection might be completed
with some state that really only applied to the failed connection.

While this has assorted bad consequences, the only one that is clearly
a security issue is that password_needed didn't get reset, so that
if the first server asked for a password and the second didn't,
PQconnectionUsedPassword() would return an incorrect result.  This
could be leveraged by unprivileged users of dblink or postgres_fdw
to allow them to use server-side login credentials that they should
not be able to use.

Other notable problems include the possibility of forcing a v2-protocol
connection to a server capable of supporting v3, or overriding
"sslmode=prefer" to cause a non-encrypted connection to a server that
would have accepted an encrypted one.  Those are certainly bugs but
it's harder to paint them as security problems in themselves.  However,
forcing a v2-protocol connection could result in libpq having a wrong
idea of the server's standard_conforming_strings setting, which opens
the door to SQL-injection attacks.  The extent to which that's actually
a problem, given the prerequisite that the attacker needs control of
the client's connection parameters, is unclear.

These problems have existed for a long time, but became more easily
exploitable in v10, both because it introduced easy ways to force libpq
to abandon a connection attempt at a late stage and then try another one
(rather than just giving up), and because it provided an easy way to
specify multiple target hosts.

Fix by rearranging PQconnectPoll's state machine to provide centralized
places to reset state properly when moving to a new target host or when
dropping and retrying a connection to the same host.

Tom Lane, reviewed by Noah Misch.  Our thanks to Andrew Krasichkov
for finding and reporting the problem.

Security: CVE-2018-10915

7 years agoAdjust error message
Peter Eisentraut [Mon, 11 Jun 2018 21:19:11 +0000 (17:19 -0400)]
Adjust error message

Makes it look more similar to other ones, and avoids the need for
pluralization.

7 years agoRelease notes for 10.5, 9.6.10, 9.5.14, 9.4.19, 9.3.24.
Tom Lane [Sun, 5 Aug 2018 20:38:43 +0000 (16:38 -0400)]
Release notes for 10.5, 9.6.10, 9.5.14, 9.4.19, 9.3.24.

7 years agoDoc: fix incorrectly stated argument list for pgcrypto's hmac() function.
Tom Lane [Sun, 5 Aug 2018 17:03:42 +0000 (13:03 -0400)]
Doc: fix incorrectly stated argument list for pgcrypto's hmac() function.

The bytea variant takes (bytea, bytea, text).
Per unsigned report.

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

7 years agoFix INSERT ON CONFLICT UPDATE through a view that isn't just SELECT *.
Tom Lane [Sat, 4 Aug 2018 23:38:58 +0000 (19:38 -0400)]
Fix INSERT ON CONFLICT UPDATE through a view that isn't just SELECT *.

When expanding an updatable view that is an INSERT's target, the rewriter
failed to rewrite Vars in the ON CONFLICT UPDATE clause.  This accidentally
worked if the view was just "SELECT * FROM ...", as the transformation
would be a no-op in that case.  With more complicated view targetlists,
this omission would often lead to "attribute ... has the wrong type" errors
or even crashes, as reported by Mario De Frutos Dieguez.

Fix by adding code to rewriteTargetView to fix up the data structure
correctly.  The easiest way to update the exclRelTlist list is to rebuild
it from scratch looking at the new target relation, so factor the code
for that out of transformOnConflictClause to make it sharable.

In passing, avoid duplicate permissions checks against the EXCLUDED
pseudo-relation, and prevent useless view expansion of that relation's
dummy RTE.  The latter is only known to happen (after this patch) in cases
where the query would fail later due to not having any INSTEAD OF triggers
for the view.  But by exactly that token, it would create an unintended
and very poorly tested state of the query data structure, so it seems like
a good idea to prevent it from happening at all.

This has been broken since ON CONFLICT was introduced, so back-patch
to 9.5.

Dean Rasheed, based on an earlier patch by Amit Langote;
comment-kibitzing and back-patching by me

Discussion: https://postgr.es/m/CAFYwGJ0xfzy8jaK80hVN2eUWr6huce0RU8AgU04MGD00igqkTg@mail.gmail.com

7 years agoReset properly errno before calling write()
Michael Paquier [Sat, 4 Aug 2018 20:32:12 +0000 (05:32 +0900)]
Reset properly errno before calling write()

6cb3372 enforces errno to ENOSPC when less bytes than what is expected
have been written when it is unset, though it forgot to properly reset
errno before doing a system call to write(), causing errno to
potentially come from a previous system call.

Reported-by: Tom Lane
Author: Michael Paquier
Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/31797.1533326676@sss.pgh.pa.us

7 years agoAdd table relcache invalidation to index builds.
Peter Geoghegan [Fri, 3 Aug 2018 21:44:56 +0000 (14:44 -0700)]
Add table relcache invalidation to index builds.

It's necessary to make sure that owning tables have a relcache
invalidation prior to advancing the command counter to make
newly-entered catalog tuples for the index visible.  inval.c must be
able to maintain the consistency of the local caches in the event of
transaction abort.  There is usually only a problem when CREATE INDEX
transactions abort, since there is a generic invalidation once we reach
index_update_stats().

This bug is of long standing.  Problems were made much more likely by
the addition of parallel CREATE INDEX (commit 9da0cc35284), but it is
strongly suspected that similar problems can be triggered without
involving plan_create_index_workers().  (plan_create_index_workers()
triggers a relcache build or rebuild, which previously only happened in
rare edge cases.)

Author: Peter Geoghegan
Reported-By: Luca Ferrari
Diagnosed-By: Andres Freund
Reviewed-By: Andres Freund
Discussion: https://postgr.es/m/CAKoxK+5fVodiCtMsXKV_1YAKXbzwSfp7DgDqUmcUAzeAhf=HEQ@mail.gmail.com
Backpatch: 9.3-

7 years agoAdd 'n' to list of possible values to pg_default_acl.defaclobjtype
Alvaro Herrera [Fri, 3 Aug 2018 20:45:08 +0000 (16:45 -0400)]
Add 'n' to list of possible values to pg_default_acl.defaclobjtype

This was missed in commit ab89e465cb20; backpatch to v10.

Author: Fabien Coelho <[email protected]>
Discussion: https://postgr.es/m/alpine.DEB.2.21.1807302243001.13230@lancre

7 years agoFix pg_replication_slot example output
Alvaro Herrera [Fri, 3 Aug 2018 20:34:59 +0000 (16:34 -0400)]
Fix pg_replication_slot example output

The example output of pg_replication_slot is wrong.  Correct it and make
the output stable by explicitly listing columns to output.

Author: Kyotaro Horiguchi <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
Discussion: https://postgr.es/m/20180731.190909.42582169[email protected]

7 years agoRemove no-longer-appropriate special case in psql's \conninfo code.
Tom Lane [Fri, 3 Aug 2018 16:20:47 +0000 (12:20 -0400)]
Remove no-longer-appropriate special case in psql's \conninfo code.

\conninfo prints the results of PQhost() and some other libpq functions.
It used to override the PQhost() result with the hostaddr parameter if
that'd been given, but that's unhelpful when multiple hosts were listed
in the connection string.  Furthermore, it seems unnecessary in the wake
of commit 1944cdc98, since PQhost does any useful substitution itself.
So let's just remove the extra code and print PQhost()'s result without
any editorialization.

Back-patch to v10, as 1944cdc98 (just) was.

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

7 years agoChange libpq's internal uses of PQhost() to inspect host field directly.
Tom Lane [Fri, 3 Aug 2018 16:12:10 +0000 (12:12 -0400)]
Change libpq's internal uses of PQhost() to inspect host field directly.

Commit 1944cdc98 changed PQhost() to return the hostaddr value when that
is specified and host isn't.  This is a good idea in general, but
fe-auth.c and related files contain PQhost() calls for which it isn't.
Specifically, when we compare SSL certificates or other server identity
information to the host field, we do not want to use hostaddr instead;
that's not what's documented, that's not what happened pre-v10, and
it doesn't seem like a good idea.

Instead, we can just look at connhost[].host directly.  This does what
we want in v10 and up; in particular, if neither host nor hostaddr
were given, the host field will be replaced with the default host name.
That seems useful, and it's likely the reason that these places were
coded to call PQhost() originally (since pre-v10, the stored field was
not replaced with the default).

Back-patch to v10, as 1944cdc98 (just) was.

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

7 years agolibpq: PQhost to return active connected host or hostaddr
Tom Lane [Fri, 3 Aug 2018 15:30:34 +0000 (11:30 -0400)]
libpq: PQhost to return active connected host or hostaddr

Previously, PQhost didn't return the connected host details when the
connection type was CHT_HOST_ADDRESS (i.e., via hostaddr).  Instead, it
returned the complete host connection parameter (which could contain
multiple hosts) or the default host details, which was confusing and
arguably incorrect.

Change this to return the actually connected host or hostaddr
irrespective of the connection type.  When hostaddr but no host was
specified, hostaddr is now returned.  Never return the original host
connection parameter, and document that PQhost cannot be relied on
before the connection is established.

PQport is similarly changed to always return the active connection port
and never the original connection parameter.

Back-patch of commit 1944cdc98273dbb8439ad9b387ca2858531afcf0
into the v10 branch.

Author: Hari Babu <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
Reviewed-by: Kyotaro HORIGUCHI <[email protected]>
Reviewed-by: David G. Johnston <[email protected]>
7 years agoThis reverts commit 85cd900fef99dab000bba7e2b6be541a03a48706.
Pavan Deolasee [Fri, 3 Aug 2018 08:58:54 +0000 (14:28 +0530)]
This reverts commit 85cd900fef99dab000bba7e2b6be541a03a48706.

I accidentally pushed a local change to the remote repo. So revert a revert.
Looks so stupid :-(

7 years agoUse correct path for tablspaces while creating a basebackup
Pavan Deolasee [Fri, 3 Aug 2018 08:39:12 +0000 (14:09 +0530)]
Use correct path for tablspaces while creating a basebackup

In XL, we embed the nodename in the tablespace subdir name to ensure that
non-conflicting paths are created when multiple coordinators/datanodes are
running on the same server. The code to handle tablespace mapping in basebackup
was missing this support.

Per report and patch by Wanglin.

7 years agoFix buffer usage stats for parallel nodes.
Amit Kapila [Fri, 3 Aug 2018 05:57:11 +0000 (11:27 +0530)]
Fix buffer usage stats for parallel nodes.

The buffer usage stats is accounted only for the execution phase of the
node.  For Gather and Gather Merge nodes, such stats are accumulated at
the time of shutdown of workers which is done after execution of node due
to which we missed to account them for such nodes.  Fix it by treating
nodes as running while we shut down them.

We can also miss accounting for a Limit node when Gather or Gather Merge
is beneath it, because it can finish the execution before shutting down
such nodes.  So we allow a Limit node to shut down the resources before it
completes the execution.

In the passing fix the gather node code to allow workers to shut down as
soon as we find that all the tuples from the workers have been retrieved.
The original code use to do that, but is accidently removed by commit
01edb5c7fc.

Reported-by: Adrien Nayrat
Author: Amit Kapila and Robert Haas
Reviewed-by: Robert Haas and Andres Freund
Backpatch-through: 9.6 where this code was introduced
Discussion: https://postgr.es/m/86137f17-1dfb-42f9-7421-82fd786b04a1@anayrat.info

7 years agoMatch the buffer usage tracking for leader and worker backends.
Amit Kapila [Fri, 3 Aug 2018 04:20:24 +0000 (09:50 +0530)]
Match the buffer usage tracking for leader and worker backends.

In the leader backend, we don't track the buffer usage for ExecutorStart
phase whereas in worker backend we track it for ExecutorStart phase as
well.  This leads to different value for buffer usage stats for the
parallel and non-parallel query.  Change the code so that worker backend
also starts tracking buffer usage after ExecutorStart.

Author: Amit Kapila and Robert Haas
Reviewed-by: Robert Haas and Andres Freund
Backpatch-through: 9.6 where this code was introduced
Discussion:https://postgr.es/m/86137f17-1dfb-42f9-7421-82fd786b04a1@anayrat.info

7 years agoRevert "Correct select the GTM proxy for a new node being added"
Pavan Deolasee [Thu, 2 Aug 2018 07:34:37 +0000 (13:04 +0530)]
Revert "Correct select the GTM proxy for a new node being added"

This reverts commit edbe6703bf8d8749a807762135842b6a06309383.

7 years agoFix libpq's code for searching .pgpass; rationalize empty-list-item cases.
Tom Lane [Wed, 1 Aug 2018 16:30:36 +0000 (12:30 -0400)]
Fix libpq's code for searching .pgpass; rationalize empty-list-item cases.

Before v10, we always searched ~/.pgpass using the host parameter,
and nothing else, to match to the "hostname" field of ~/.pgpass.
(However, null host or host matching DEFAULT_PGSOCKET_DIR was replaced by
"localhost".)  In v10, this got broken by commit 274bb2b38, repaired by
commit bdac9836d, and broken again by commit 7b02ba62e; in the code
actually shipped, we'd search with hostaddr if both that and host were
specified --- though oddly, *not* if only hostaddr were specified.
Since this is directly contrary to the documentation, and not
backwards-compatible, it's clearly a bug.

However, the change wasn't totally without justification, even though it
wasn't done quite right, because the pre-v10 behavior has arguably been
buggy since we added hostaddr.  If hostaddr is specified and host isn't,
the pre-v10 code will search ~/.pgpass for "localhost", and ship that
password off to a server that most likely isn't local at all.  That's
unhelpful at best, and could be a security breach at worst.

Therefore, rather than just revert to that old behavior, let's define
the behavior as "search with host if provided, else with hostaddr if
provided, else search for localhost".  (As before, a host name matching
DEFAULT_PGSOCKET_DIR is replaced by localhost.)  This matches the
behavior of the actual connection code, so that we don't pick up an
inappropriate password; and it allows useful searches to happen when
only hostaddr is given.

While we're messing around here, ensure that empty elements within a
host or hostaddr list select the same behavior as a totally-empty
field would; for instance "host=a,,b" is equivalent to "host=a,/tmp,b"
if DEFAULT_PGSOCKET_DIR is /tmp.  Things worked that way in some cases
already, but not consistently so, which contributed to the confusion
about what key ~/.pgpass would get searched with.

Update documentation accordingly, and also clarify some nearby text.

Back-patch to v10 where the host/hostaddr list functionality was
introduced.

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

7 years agoFix couple of compile time warnings
Pavan Deolasee [Wed, 1 Aug 2018 05:17:21 +0000 (10:47 +0530)]
Fix couple of compile time warnings

7 years agoMove pgxc_clean to src/bin
Pavan Deolasee [Wed, 1 Aug 2018 05:17:06 +0000 (10:47 +0530)]
Move pgxc_clean to src/bin

7 years agoMove pgxc_ctl to src/bin
Pavan Deolasee [Wed, 1 Aug 2018 05:16:55 +0000 (10:46 +0530)]
Move pgxc_ctl to src/bin

pgxc_ctl is now widely used for cluster management and hence it makes every
sense to have it installed by default. In passing, also fix several
problems/kludges in the Makefile

7 years agopg_upgrade: fix --check for live source server checks
Bruce Momjian [Tue, 31 Jul 2018 22:10:06 +0000 (18:10 -0400)]
pg_upgrade:  fix --check for live source server checks

Fix for commit 244142d32afd02e7408a2ef1f249b00393983822.

Backpatch-through: 9.3

7 years agoFurther fixes for quoted-list GUC values in pg_dump and ruleutils.c.
Tom Lane [Tue, 31 Jul 2018 17:00:08 +0000 (13:00 -0400)]
Further fixes for quoted-list GUC values in pg_dump and ruleutils.c.

Commits 742869946 et al turn out to be a couple bricks shy of a load.
We were dumping the stored values of GUC_LIST_QUOTE variables as they
appear in proconfig or setconfig catalog columns.  However, although that
quoting rule looks a lot like SQL-identifier double quotes, there are two
critical differences: empty strings ("") are legal, and depending on which
variable you're considering, values longer than NAMEDATALEN might be valid
too.  So the current technique fails altogether on empty-string list
entries (as reported by Steven Winfield in bug #15248) and it also risks
truncating file pathnames during dump/reload of GUC values that are lists
of pathnames.

To fix, split the stored value without any downcasing or truncation,
and then emit each element as a SQL string literal.

This is a tad annoying, because we now have three copies of the
comma-separated-string splitting logic in varlena.c as well as a fourth
one in dumputils.c.  (Not to mention the randomly-different-from-those
splitting logic in libpq...)  I looked at unifying these, but it would
be rather a mess unless we're willing to tweak the API definitions of
SplitIdentifierString, SplitDirectoriesString, or both.  That might be
worth doing in future; but it seems pretty unsafe for a back-patched
bug fix, so for now accept the duplication.

Back-patch to all supported branches, as the previous fix was.

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

7 years agoEnsure that bad protocol ERROR message is sent to the frontend
Pavan Deolasee [Tue, 31 Jul 2018 06:00:01 +0000 (11:30 +0530)]
Ensure that bad protocol ERROR message is sent to the frontend

In case of receiving bad protocol messages received by the GTM proxy, let
the client know about the error messages.

7 years agoCorrect select the GTM proxy for a new node being added
Pavan Deolasee [Tue, 31 Jul 2018 05:58:21 +0000 (11:28 +0530)]
Correct select the GTM proxy for a new node being added

This fixes an oversight in array index lookup. We should have been using
0-based indexes but were instead using 1-based index.

7 years agoSet ActiveSnapshot when logically replaying inserts
Alvaro Herrera [Mon, 30 Jul 2018 20:30:07 +0000 (16:30 -0400)]
Set ActiveSnapshot when logically replaying inserts

Input functions for the inserted tuples may require a snapshot, when
they are replayed by native logical replication.  An example is a domain
with a constraint using a SQL-language function, which prior to this
commit failed to apply on the subscriber side.

Reported-by: Mai Peng <[email protected]>
Co-authored-by: Minh-Quan TRAN <[email protected]>
Co-authored-by: Álvaro Herrera <[email protected]>
Discussion: https://postgr.es/m/4EB4BD78-BFC3-4D04-B8DA-D53DF7160354@webedia-group.com
Discussion: https://postgr.es/m/153211336163.1404.11721804383024050689@wrigleys.postgresql.org

7 years agoFix pg_dump's failure to dump REPLICA IDENTITY for constraint indexes.
Tom Lane [Mon, 30 Jul 2018 16:35:49 +0000 (12:35 -0400)]
Fix pg_dump's failure to dump REPLICA IDENTITY for constraint indexes.

pg_dump knew about printing ALTER TABLE ... REPLICA IDENTITY USING INDEX
for indexes declared as indexes, but it failed to print that for indexes
declared as unique or primary-key constraints.  Per report from Achilleas
Mantzios.

This has been broken since the feature was introduced, AFAICS.
Back-patch to 9.4.

Discussion: https://postgr.es/m/1e6cc5ad-b84a-7c07-8c08-a4d0c3cdc938@matrix.gatewaynet.com

7 years agoDoc: fix oversimplified example for CREATE POLICY.
Tom Lane [Mon, 30 Jul 2018 15:54:41 +0000 (11:54 -0400)]
Doc: fix oversimplified example for CREATE POLICY.

As written, this policy constrained only the post-image not the pre-image
of rows, meaning that users could delete other users' rows or take
ownership of such rows, contrary to what the docs claimed would happen.
We need two separate policies to achieve the documented effect.

While at it, try to explain what's happening a bit more fully.

Per report from Олег Самойлов.  Back-patch to 9.5 where this was added.
Thanks to Stephen Frost for off-list discussion.

Discussion: https://postgr.es/m/3298321532002010@sas1-2b3c3045b736.qloud-c.yandex.net

7 years agoEnsure partition child tables inherit distribution properties correctly
Pavan Deolasee [Mon, 30 Jul 2018 08:47:20 +0000 (14:17 +0530)]
Ensure partition child tables inherit distribution properties correctly

While in restore mode, that we use to load schema when a new node is added to
the cluster, the partition child tables should correctly inherit the
distribution properties from the parent table. This support was lacking, thus
leading to incorrect handling of such tables.

Per report by Virendra Kumar.

7 years agoFix earthdistance test suite function name typo.
Noah Misch [Sun, 29 Jul 2018 19:02:07 +0000 (12:02 -0700)]
Fix earthdistance test suite function name typo.

Affected test queries have been testing the wrong thing since their
introduction in commit 4c1383efd132e4f532213c8a8cc63a455f55e344.
Back-patch to 9.3 (all supported versions).

7 years agoDocument security implications of qualified names.
Noah Misch [Sun, 29 Jul 2018 03:08:01 +0000 (20:08 -0700)]
Document security implications of qualified names.

Commit 5770172cb0c9df9e6ce27c507b449557e5b45124 documented secure schema
usage, and that advice suffices for using unqualified names securely.
Document, in typeconv-func primarily, the additional issues that arise
with qualified names.  Back-patch to 9.3 (all supported versions).

Reviewed by Jonathan S. Katz.

Discussion: https://postgr.es/m/20180721012446[email protected]

7 years agopgtest: run clean, build, and check stages separately
Bruce Momjian [Sat, 28 Jul 2018 19:34:06 +0000 (15:34 -0400)]
pgtest:  run clean, build, and check stages separately

This allows for cleaner error reporting.

Backpatch-through: 9.5