postgres-xl.git
9 years agoSupport yet another syntax for specifying distribution strategy for
Pavan Deolasee [Fri, 15 Jan 2016 10:34:10 +0000 (16:04 +0530)]
Support yet another syntax for specifying distribution strategy for
a table

DISTSTYLE KEY DISTKEY (col) maps to DISTRIBUTE BY HASH (col)
DISTSTYLE EVEN maps to DISTRIBUTE BY ROUNDROBIN
DISTSTYLE ALL maps to DISTRIBUTE BY REPLICATION

9 years agoSupport additional synax for choosing table distribution strategy
Pavan Deolasee [Fri, 15 Jan 2016 07:58:12 +0000 (13:28 +0530)]
Support additional synax for choosing table distribution strategy

DISTRIBUTED BY (col) maps to DISTRIBUTE BY HASH (col)
DISTRIBUTED RANDOMLY maps to DISTRIBUTE BY ROUNDROBIN

9 years agoCheck if target directory is empty (if it already exists) on the remote node.
Pavan Deolasee [Fri, 15 Jan 2016 07:15:54 +0000 (12:45 +0530)]
Check if target directory is empty (if it already exists) on the remote node.

We were wrongly doing this check on the local node, which was clearly wrong.

9 years agoIntroduce a healthmap for tracking health status of all other nodes in the
Pavan Deolasee [Thu, 14 Jan 2016 18:26:06 +0000 (23:56 +0530)]
Introduce a healthmap for tracking health status of all other nodes in the
cluster.

Each node now maintains a healthmap in shared memory to keep track of
availability of all other nodes in the cluster. Whenever a send() or a
receive() call on a socket fails, we try to ping the node once and if that
fails, we mark the node as UNHEALTHY. On the other hand, if later a new
connection is established successfully to a node, we mark the node as HEALTHY.
We also periodically try to ping UNHEALTHY nodes to see if they have come back
to life and update the healthmap accordingly.

The only consumer of a healthmap right now is SELECT queries on replicated
tables. When a table is replicated to more than one node, we now consult the
healthmap and discards nodes that are known to be UNHEALTHY. If all nodes are
found to be UNHEALTHY, one attempt is made to see if any of them have come back
online.

9 years agoFix "make check" so that it now sets up a 2-coordinator, 2-datanode XL cluster
Pavan Deolasee [Thu, 14 Jan 2016 17:40:10 +0000 (23:10 +0530)]
Fix "make check" so that it now sets up a 2-coordinator, 2-datanode XL cluster
and runs a parallel schedule

There were different problems with the way various components were being set
up, including specifying a separate directory to create domain sockets. The
names used for datanodes were also different than what the regression expected
output has. This patch fixes that too

9 years agoTest output, sql changes
Pallavi Sontakke [Wed, 13 Jan 2016 12:04:55 +0000 (17:34 +0530)]
Test output, sql changes

exclude query plan on replicated tables - join
exclude complex queries with 'union all' - equivclass
set sequence_range for nextval() to work fine - xl_functions
accept some FQS format changes in output

9 years agoSelect a node randomly from a list of available nodes for reading from
Pavan Deolasee [Wed, 13 Jan 2016 04:50:39 +0000 (10:20 +0530)]
Select a node randomly from a list of available nodes for reading from
replicated tables

This fixes a bug in FQS logic where it would always pick up the same node for
reading

9 years agoSend out a relcache inval for the relation when its distribution key or
Pavan Deolasee [Tue, 12 Jan 2016 09:16:51 +0000 (14:46 +0530)]
Send out a relcache inval for the relation when its distribution key or
strategy changes.

Without this backends may not reload their relcache entries and thus keep
looking at the old and stale distribution information

9 years agoDo not use FQS for queries with FOR UPDATE/SHARE clause
Pavan Deolasee [Tue, 12 Jan 2016 03:54:46 +0000 (09:24 +0530)]
Do not use FQS for queries with FOR UPDATE/SHARE clause

9 years agoSend XID assigned on a datanode back to the coordinator.
Pavan Deolasee [Mon, 11 Jan 2016 16:05:28 +0000 (21:35 +0530)]
Send XID assigned on a datanode back to the coordinator.

We'd missed out a case where XIDs are assigned on a datanode, but the same is
not sent back to the coordinator. We now also avoid running a 2PC for
transactions which do not have XID assigned to them since such transactions
must not have made any database changes

9 years agoTest, sql changes for insert_conflict
Pallavi Sontakke [Mon, 11 Jan 2016 10:21:28 +0000 (15:51 +0530)]
Test, sql changes for insert_conflict

Accept ERROR for unique index on non-distribution column.
Remove tableoid call, with bug reference.

9 years agoFor FQSed query, run EXPLAIN on the remote node and print the result
Pavan Deolasee [Sat, 9 Jan 2016 13:20:11 +0000 (18:50 +0530)]
For FQSed query, run EXPLAIN on the remote node and print the result

We recently added fast-query-shipping facility to Postgres-XL. But it wouldn't
print the query plan used on the datanodes, which makes it extrememly difficult
to debug bad query plan with EXPLAIN. We now send an EXPLAIN query to one of
the datanodes and print the result. This assumes that all datanodes would plan
queries similarly, assuming a good data distribution.

We also modified the EXPLAIN output for FQSed queries to match is as closely as
possible with the Remote Subplan queries.

9 years agoFix misc issues with two-phase commit protocol and cleaning up of outstanding
Pavan Deolasee [Fri, 8 Jan 2016 17:39:36 +0000 (23:09 +0530)]
Fix misc issues with two-phase commit protocol and cleaning up of outstanding
transactions

When a two-phase commit protocol is interrupted mid-way, for example because of
a server crash, it can leave behind unresolved prepared transactions which must
be resolved when the node comes back. Postgres-XL provides a pgxc_clean utility
to lookup list of prepared transactions and resolve them based on status of
such a transaction on every node. But there were many issues with the utility
because of which it would either fail to resolve all transactions, or worse
resolve it in a wrong manner. This commit fixes all such issues discovered
during some simple crash recovery testing.

One of the problem with the current approach was that the utility would not
know which all nodes were involved in a transaction. So if it sees a
transaction as prepared on a subset of nodes, but does not exist on other
subset, it would not know if originally it was executed on nodes other than
where its prepared, but other nodes failed before they could prepare the
transaction. If it was indeed executed on other nodes, such transaction must be
aborted. Whereas if it was only executed on the set of nodes where its
currently prepared, then it can safely be committed.

We now store the information about nodes partcipating in a 2PC directly in the
GID. This of course has a downside of increasing the GIDSIZE which implies for
shared memory requirement. But with today's server sizes, it should not be a
very big concern. Sure, we could also look at possibility of storing this
information externally, such as on the GTM. But the fix seems good enough for
now.

9 years agoTest changes for insert_conflict
Pallavi Sontakke [Fri, 8 Jan 2016 11:41:51 +0000 (17:11 +0530)]
Test changes for insert_conflict

Accept output changes - we now avoid an additional local connection.

9 years agoFix some protocol issues between GTM and GTM-standby.
Pavan Deolasee [Fri, 8 Jan 2016 04:21:30 +0000 (09:51 +0530)]
Fix some protocol issues between GTM and GTM-standby.

9 years agoMake idle backends exit if the postmaster dies.
Robert Haas [Thu, 12 Nov 2015 14:00:33 +0000 (09:00 -0500)]
Make idle backends exit if the postmaster dies.

Letting backends continue to run if the postmaster has exited prevents
PostgreSQL from being restarted, which in many environments is
catastrophic.  Worse, if some other backend crashes, we no longer have
any protection against shared memory corruption.  So, arrange for them
to exit instead.  We don't want to expend many cycles on this, but
including postmaster death in the set of things that we wait for when
a backend is idle seems cheap enough.

Rajeev Rastogi and Robert Haas

9 years agoTest changes
Pallavi Sontakke [Thu, 7 Jan 2016 08:49:16 +0000 (14:19 +0530)]
Test changes

Changes related to expected output for XL tests, concerning
insensitive cursor, recursive queries, grouping sets, literal
constants autocast.

9 years agoEnd global transaction on the GTM before releasing locks.
Pavan Deolasee [Wed, 6 Jan 2016 13:02:06 +0000 (18:32 +0530)]
End global transaction on the GTM before releasing locks.

Since other backends could be waiting for locks to be released and they must
see end of the transaction, not just locally but also on the GTM (say because
it takes a new snapshot from the GTM, especially for catalog scans). There are
some concerns about doing it the way its done in this patch because we now
exchange messages with the GTM while holding interrupts. But we don't know if
thats really a problem

9 years agoBump default value for sequence_range to 1000.
Pavan Deolasee [Wed, 6 Jan 2016 12:50:08 +0000 (18:20 +0530)]
Bump default value for sequence_range to 1000.

This shows good improvement for workloads which repeatedly asks for sequence
values. We already override the sequence_range value to 1000 for COPY and it
makes a lot of sense to do the same for INSERTs

9 years agoCorrectly handle RESPONSE_WAITXIDS response from a datanode
Pavan Deolasee [Wed, 6 Jan 2016 06:54:23 +0000 (12:24 +0530)]
Correctly handle RESPONSE_WAITXIDS response from a datanode

9 years agoEnsure commit ordering at the GTM when a transaction's update/delete operation
Pavan Deolasee [Tue, 5 Jan 2016 07:20:32 +0000 (12:50 +0530)]
Ensure commit ordering at the GTM when a transaction's update/delete operation
is based on some other transaction's commit

We had handled one part of this problem by recording transactions on which we
wait before proceeding with update/delete. But there is another case where an
updating transaction T1 may commit on the datanode, but before coordinator can
commit the transaction on the GTM, another transaction T2 updates the record
(seeing that the updating transaction is already committed) and also commits on
the GTM. Now if a third transaction T3 takes a snapshot, it will see T1 as
running and T2 as committed. Such a snapshot can then see both old and new
versions of the updated tuple. So we must enforce commit ordering T1->T2 on the
GTM since T2 based its actions on T1 being committed

9 years agoSet XactTopTransactionId also on receiving XID from a datanode
Pavan Deolasee [Thu, 31 Dec 2015 11:11:25 +0000 (16:41 +0530)]
Set XactTopTransactionId also on receiving XID from a datanode

9 years agoSend a single command-complete message from remote coordinator or datanode
Pavan Deolasee [Wed, 30 Dec 2015 11:27:42 +0000 (16:57 +0530)]
Send a single command-complete message from remote coordinator or datanode

When a client sends a multi-command string for execution, Postgres server
executes each command separately and sends a command-complete for each command.
The coordinator is not well equipped though to handle this since it sends the
whole query string as it is to the datanode and expects a single
command-complete.

What we need is a mechanism where coordinator sends each command separately to
the datanode. It already parses multi-command string into multiple parse-trees.
Earlier we did not have mechanism to deparse utility commands, but IIRC we now
have that. So we should look at using that infrastructure

9 years agoAdd a flag to the latest snapshot from GTM when situation demands.
Pavan Deolasee [Wed, 30 Dec 2015 04:55:56 +0000 (10:25 +0530)]
Add a flag to the latest snapshot from GTM when situation demands.

Catalog scans for example require the latest snapshot to see the latest changes
to the catalogs. This patch fixes the problem with catalog scans

9 years agoAssign GTM-generated XID for an auto-commit, single datanode transaction which
Pavan Deolasee [Wed, 30 Dec 2015 04:50:27 +0000 (10:20 +0530)]
Assign GTM-generated XID for an auto-commit, single datanode transaction which
won't receive a coordinator pushed down XID neither will have a transaction
block active

9 years agoCorrect '=' to '==' in an assertion
Pavan Deolasee [Tue, 29 Dec 2015 08:31:57 +0000 (14:01 +0530)]
Correct '=' to '==' in an assertion

10 years agoDrop datanode/coordinator connections while handling transaction aborts,
Pavan Deolasee [Tue, 15 Dec 2015 11:31:44 +0000 (17:01 +0530)]
Drop datanode/coordinator connections while handling transaction aborts,
overriding persistent_datanode_connections setting

10 years agoAdd a developer GUC "enable_datanode_row_triggers" to allow ROW TRIGGERS to be
Pavan Deolasee [Tue, 15 Dec 2015 08:17:32 +0000 (13:47 +0530)]
Add a developer GUC "enable_datanode_row_triggers" to allow ROW TRIGGERS to be
executed on the datanodes.

This must be used with caution. Postgres-XL does not officially support
triggers yet. One of the reasons for not supporting triggers is that a trigger
function executed on a datanode may not have access to all the required data
since the data may not reside on the datanode. But if users are confident that
the triggers can be safely executed on the datanode, they may turn this GUC on.
Still since the feature is not well tested, we don't recommend users to use
this without thorough testing and knowing consequences.

10 years agoMerge remote-tracking branch 'remotes/PGSQL/REL9_5_STABLE' into XL9_5_STABLE
Pavan Deolasee [Thu, 10 Dec 2015 10:08:17 +0000 (15:38 +0530)]
Merge remote-tracking branch 'remotes/PGSQL/REL9_5_STABLE' into XL9_5_STABLE

10 years agoAdd a developer-GUC 'gloabl_snapshot_source' to allow informed users to
Pavan Deolasee [Thu, 10 Dec 2015 05:44:23 +0000 (11:14 +0530)]
Add a developer-GUC 'gloabl_snapshot_source' to allow informed users to
override the way snapshots are computed.

The default value of the GUC is 'gtm' which means that snapshots are always
generated on the GTM so that we get a full and correct view of the currently
running transactions. But with this developer-GUC we now allow users to
override that and work with a coordinator generated snapshots. This can be
especially useful for read-only queries which now don't need to talk to the
GTM. If the snapshots can also be taken locally on a coordinator, this will
even further reduce the round-trips to the GTM. Of course, this can lead to
consistency issues because a coordinator may not be aware of all the
transactions currently running on the XL cluster, especially in a
multi-coordinator setup where different coordinators could be running different
transactions without knowing about each other's activity. But even in a single
coordinator setup, some transactions may start on a datanode and coordinator
may not know about them or may only know quite late.

Its advised that this feature must be used with caution and after due
consideration of the effects

10 years agoAllow on-demand assignment of XID, even on a datanode
Pavan Deolasee [Wed, 9 Dec 2015 11:07:37 +0000 (16:37 +0530)]
Allow on-demand assignment of XID, even on a datanode

Till now, we used to aggressively assign transaction identifiers on the
coordinator, even if the transaction may not actually need one because
it does not do any write operation. PostgreSQL has improved this case many
years back with the usage of Virtual XIDs. But since in Postgres-XL, if a
read-looking SELECT statement later does some write opreation, it would be too
late to assign a transaction identifier when the query is running on the
datanode. But such aggressive XID assignment causes severe performance
problems, especially for read-only queries.

We now solve this by assigning XID on-demand for SELECT queries. If a datanode
ever needs an XID, it will talk to the GTM with a global session identifier
which remains unique for a given global transaction on all nodes. GTM can then
correlate multiple BEGIN TXN requests for the same global transaction and
return the already assigned identifer, instead of opening a new transaction
every time.

For DML queries, we still acquire XID on the coordinator. This will be a loss
if DML ends up not doing any write operation. But since its not going to be a
very regular scenario, it makes sense to pre-acquire an XID. More tests are
required though to verify this

10 years agoForget connection combiner before receving pending messages during cleanup
Pavan Deolasee [Wed, 9 Dec 2015 10:26:09 +0000 (15:56 +0530)]
Forget connection combiner before receving pending messages during cleanup

10 years agoDo not use RemoteSubplan for simple Result plan which can be evaluated on any
Pavan Deolasee [Wed, 9 Dec 2015 10:01:36 +0000 (15:31 +0530)]
Do not use RemoteSubplan for simple Result plan which can be evaluated on any
node

This should reduce connections for a single INSERT statements

10 years agoReduce logging level for tuplestore_end message
Pavan Deolasee [Wed, 9 Dec 2015 08:04:57 +0000 (13:34 +0530)]
Reduce logging level for tuplestore_end message

10 years agoAvoid repeated invalidation on plans because of mismatch in search_path
Pavan Deolasee [Wed, 9 Dec 2015 07:59:48 +0000 (13:29 +0530)]
Avoid repeated invalidation on plans because of mismatch in search_path

10 years agoIntroduce a cluster monitor lock to avoid a race condition between spanshot
Pavan Deolasee [Wed, 9 Dec 2015 07:23:40 +0000 (12:53 +0530)]
Introduce a cluster monitor lock to avoid a race condition between spanshot
fetch and xmin reporting

10 years agoReduce logging level for couple of messages
Pavan Deolasee [Wed, 9 Dec 2015 07:04:57 +0000 (12:34 +0530)]
Reduce logging level for couple of messages

10 years agoOuch. Forgot to take this half-cooked and incorrect code in the previous commit
Pavan Deolasee [Wed, 9 Dec 2015 06:35:29 +0000 (12:05 +0530)]
Ouch. Forgot to take this half-cooked and incorrect code in the previous commit

10 years agoAcquire the right lock for updating latestCompletedXid.
Pavan Deolasee [Tue, 8 Dec 2015 09:05:21 +0000 (14:35 +0530)]
Acquire the right lock for updating latestCompletedXid.

Also make sure that the latestCompletedXid is updated on the nodes irrespective
of whather report-xmin returns success or failure

10 years agoRework handling of idle nodes for xmin reporting and calculation
Pavan Deolasee [Tue, 8 Dec 2015 08:21:57 +0000 (13:51 +0530)]
Rework handling of idle nodes for xmin reporting and calculation

The local value of latestCompletedXid caps the xmin computation on an idle
cluster. So GTM sends back an updated value of latestCompletedXid as part of
report-xmin response. Once latestCompletedXid is updated on the node, the next
iteration will ensure that the local xmin is advanced on an idle server

10 years agoCluster Monitor, which is an auxilliary process need not call InitPostgres and
Pavan Deolasee [Mon, 7 Dec 2015 10:18:33 +0000 (15:48 +0530)]
Cluster Monitor, which is an auxilliary process need not call InitPostgres and
thus should not start a transaction

10 years agoReintroduce XC's Fast Query Shipping (FQS) mechanism to improve performance of
Pavan Deolasee [Mon, 7 Dec 2015 06:58:52 +0000 (12:28 +0530)]
Reintroduce XC's Fast Query Shipping (FQS) mechanism to improve performance of
simple queries that can be fully shipped to the datanodes

This patch backports some of the FQS code from XC/master branch. We only use
this for simple queries that can be fully executed on the datanodes. But
otherwise queries go through the XL planner/executor. This is showing good
performance improvements for such simple queries. This will also allow us to
support certain missing features such GROUPING SETS on replicated tables or
queries that require no coordinator support for final aggregations. This hasn't
yet tested though

This will cause many regression test case output since the EXPLAIN plan for
FQS-ed queries would look very different.

10 years agoAvoid deadlock by ensuring that a rd-lock holder does not request another rd or
Pavan Deolasee [Mon, 30 Nov 2015 07:27:36 +0000 (12:57 +0530)]
Avoid deadlock by ensuring that a rd-lock holder does not request another rd or
wr-lock

While its generally safe for threads to acquire same pthread_rwlock in READ
mode multiple times, if there is a writer blocked on the lock, this can cause
deadlock. So avoid that coding practice.

10 years agoAdd debug facility to GTM_RWLock
Pavan Deolasee [Mon, 30 Nov 2015 06:39:31 +0000 (12:09 +0530)]
Add debug facility to GTM_RWLock

This can be turned on by #define GTM_LOCK_DEBUG and should be useful for
deadlock detections and other such causes

10 years agoUse -w option of pg_ctl to wait for the operation to complete
Pavan Deolasee [Thu, 26 Nov 2015 10:59:09 +0000 (16:29 +0530)]
Use -w option of pg_ctl to wait for the operation to complete

10 years agoReduce logging level for a log message added in commit 257588554
Pavan Deolasee [Thu, 26 Nov 2015 10:58:33 +0000 (16:28 +0530)]
Reduce logging level for a log message added in commit 257588554

10 years agoAdd an user-friendly hint to the (in)famous "Failed to get pooled connection"
Pavan Deolasee [Thu, 26 Nov 2015 08:53:23 +0000 (14:23 +0530)]
Add an user-friendly hint to the (in)famous "Failed to get pooled connection"
error message

At some point we should look at checking various related GUC parameters and
make sure that they have sane values. For example, user may increase
max_connections at the datanodes, but if she forgets to change the
max_pool_size to a more reasonable value, outgoing connections from a
coordinator or a datanode may not be enough, even though the target node can
accept incoming connections. Its generally hard to derive one value from
another because max_pool_size defines limit on outgoing connections from one
node, but max_connections defines the limit on incoming connections. But we can
still provide some useful hints if there is a gross mismatch of values based on
the number of datanodes and coordinators.

10 years agoAdd a cluster monitor postmaster process
Pavan Deolasee [Thu, 26 Nov 2015 07:36:46 +0000 (13:06 +0530)]
Add a cluster monitor postmaster process

Right now the process is responsible for computing the local RecentGlobalXmin
and send periodic updates to the GTM. The GTM then computes a cluster-wide
value of the RecentGlobalXmin and sends it back to all the reporting nodes
(coordinators as well as datanodes). This way GTM does not need to track all
open snapshots in the system, which previously required a transaction to remain
open, even for a read-only operation. While this patch itself may not show
major performance improvements, this will act as a foundation for other major
improvements for transaction handling.

If a node gets disconnected for a long time or stops sending updates to the
GTM, such a node is removed from computation of the RecentGlobalXmin. This is to
ensure that a failed node does not stop advancement of the RecentGlobalXmin
beyond a certain point. Such a node can safely rejoin the cluster as long as
its not using a snapshot with a stale view of the cluster i.e. a snapshot with
xmin less than the RecentGlobalXmin that the GTM is running with.

10 years agoFree memory allocated for tracking prepared statements.
Pavan Deolasee [Fri, 20 Nov 2015 11:30:03 +0000 (17:00 +0530)]
Free memory allocated for tracking prepared statements.

This fixes a long-standing memory leak in the TopMemoryContext. Surprisingly,
the reason why I started diagnosing the problem is because pgbench -S -c 1
would run significantly slowly with every iteration. The reason turned out be
that AllocSetCheck() will run slower and slower (yeah, I was running with
--enable-cassert like every other developer). That lead me to investigate for
the memory leaks. This patch now fixes that issue and pgbench -S runs at a
consistent speed, even for cassert enabled builds.

10 years agoInclude pg_rusage.h whereever necessary
Pavan Deolasee [Fri, 20 Nov 2015 07:58:19 +0000 (13:28 +0530)]
Include pg_rusage.h whereever necessary

10 years agoDo not use READ ONLY transaction while dumping data using pg_dump
Pavan Deolasee [Thu, 19 Nov 2015 10:44:48 +0000 (16:14 +0530)]
Do not use READ ONLY transaction while dumping data using pg_dump

We use nextval(sequence) to get a consistent sequence value directly from the
GTM, since sequence values could be catched at different coordinators. But that
requires a RW transaction. Its not ideal for pg_dump to use RW transaction, but
its not terrible either given that its run in a very controlled manner. So
change it that way until we find a more elegant solution

Also fix some assorted issues with pg_dump. It now seems to pass on the
"regression" database after a round of regression run

10 years agoAdd support for all releases newer than 9.2
Pavan Deolasee [Thu, 19 Nov 2015 09:33:16 +0000 (15:03 +0530)]
Add support for all releases newer than 9.2

10 years agoInitialise root->recursiveOk correcttly.
Pavan Deolasee [Thu, 19 Nov 2015 09:30:51 +0000 (15:00 +0530)]
Initialise root->recursiveOk correcttly.

This was an oversight during the 9.5 merge process, thus breaking WITH
RECURSIVE for replicated and catalog tables. As a side-effect, this also caused
pg_dump to fail.

10 years agoCheck if configuration parametere such as cord/datanode(Specific)ExtraPgHba
Pavan Deolasee [Thu, 19 Nov 2015 05:10:00 +0000 (10:40 +0530)]
Check if configuration parametere such as cord/datanode(Specific)ExtraPgHba
exists before trying to read its value

10 years agoCheck for connection before trying to dereference a pointer
Pavan Deolasee [Thu, 19 Nov 2015 05:09:25 +0000 (10:39 +0530)]
Check for connection before trying to dereference a pointer

10 years agoUse correct index into GTM proxy array for coordinator failovers
Pavan Deolasee [Wed, 18 Nov 2015 09:11:52 +0000 (14:41 +0530)]
Use correct index into GTM proxy array for coordinator failovers

10 years agoDo not use ereport(ERROR) while cleaning up connections because we could
Pavan Deolasee [Thu, 15 Oct 2015 07:37:26 +0000 (13:07 +0530)]
Do not use ereport(ERROR) while cleaning up connections because we could
already be an abort transaction handling, thus causing infinite recursion

10 years agoRun slaves in hot_standby mode so that we can ping them for monitoring purposes
Pavan Deolasee [Wed, 18 Nov 2015 08:16:10 +0000 (13:46 +0530)]
Run slaves in hot_standby mode so that we can ping them for monitoring purposes

This actually restores old behaviour of the utility. XL doesn't currently support
read-only queries on the standbys. But without that PQping fails to connect to
the standby. So restore that for now so that pgxc_ctl monitor works for the
slaves

10 years agoUse whichever coordinator available for running cluster commands
Pavan Deolasee [Wed, 18 Nov 2015 08:15:03 +0000 (13:45 +0530)]
Use whichever coordinator available for running cluster commands

The utility had assumed that the first coordinator at index 0 will always be
available. But that may not be the case when we have actually removed the first
coordinator using "pgxc_ctl remove coordinator master <name>"

10 years agoDo not try to initialise multi-executor if we are running as a wal sender
Pavan Deolasee [Wed, 18 Nov 2015 08:07:54 +0000 (13:37 +0530)]
Do not try to initialise multi-executor if we are running as a wal sender

pg_basebackup had stopped working because of this issue. Should be fixed now

10 years agoEnsure that the array in extended only when adding new entries and not while
Pavan Deolasee [Wed, 18 Nov 2015 05:08:42 +0000 (10:38 +0530)]
Ensure that the array in extended only when adding new entries and not while
replacing existing ones

This should handle the problem of coord and datanode arrays going haywire when
first or in-between coordinators/datanodes are removed using pgxc_ctl

10 years agoWait for the socket to become ready to receive more data before attempting to
Pavan Deolasee [Tue, 17 Nov 2015 12:28:49 +0000 (17:58 +0530)]
Wait for the socket to become ready to receive more data before attempting to
write again

We'd seen that coordinator can become CPU bound while loading large chunks of
data. Upon investigation, it was found that the coordinator process keeps
trying to send more data, even though the underlying networking layer is not
yet ready to receive more data, most likely because the kernel send-buffer is
full. Instead of retrying in a tight loop, we should check for socket readiness
and then write more

This should also fix the problem of COPY process running out of memory on the
coordinator (exhibited by "invalid memory alloc request size" error seen during
pg_restore as well as COPY)

10 years agoCancel queries on remote connections upon transaction abort
Pavan Deolasee [Tue, 17 Nov 2015 11:07:11 +0000 (16:37 +0530)]
Cancel queries on remote connections upon transaction abort

10 years agoAdd more instrumentation options to code
Pavan Deolasee [Mon, 16 Nov 2015 12:42:08 +0000 (18:12 +0530)]
Add more instrumentation options to code

This patch adds two new GUCs, log_gtm_stats and log_remotesubplan_stats to
collect more information about GTM communication stats and remote subplan
stats

10 years agoUse poll() instead of select() at a few places
Pavan Deolasee [Mon, 16 Nov 2015 11:07:45 +0000 (16:37 +0530)]
Use poll() instead of select() at a few places

Patch by Krzysztof Nienartowicz, with some bug fixes and rework by me

10 years agoRemove a lot of XC-specific code from the repo.
Pavan Deolasee [Fri, 13 Nov 2015 13:21:09 +0000 (18:51 +0530)]
Remove a lot of XC-specific code from the repo.

Per discussion on the developer list, this patch removes a bulk of XC-specific
code which is not relevant in XL. This code was mostly left-over in #ifdef
blocks, thus complicating code-reading, bug fixes and merges. One can always do
a "git diff" with the XC code base to see the exact differences.

We still continue to use #ifdef PGXC and #ifdef XCP interchangeably because of
the way code was written. Something we should change. Also, there is probably
still some more dead code (because files were copied to different place or
because the code is not referenced in XL). This requires another cleanup patch,
but not something I plan to do immediately

10 years agoFix typo in docs.
Robert Haas [Thu, 8 Oct 2015 17:21:03 +0000 (13:21 -0400)]
Fix typo in docs.

Pallavi Sontakke

10 years agoFactor out encoding specific tests for json
Andrew Dunstan [Wed, 7 Oct 2015 21:41:45 +0000 (17:41 -0400)]
Factor out encoding specific tests for json

This lets us remove the large alternative results files for the main
json and jsonb tests, which makes modifying those tests simpler for
committers and patch submitters.

Backpatch to 9.4 for jsonb and 9.3 for json.

10 years agoImprove documentation of the role-dropping process.
Tom Lane [Wed, 7 Oct 2015 20:12:05 +0000 (16:12 -0400)]
Improve documentation of the role-dropping process.

In general one may have to run both REASSIGN OWNED and DROP OWNED to get
rid of all the dependencies of a role to be dropped.  This was alluded to
in the REASSIGN OWNED man page, but not really spelled out in full; and in
any case the procedure ought to be documented in a more prominent place
than that.  Add a section to the "Database Roles" chapter explaining this,
and do a bit of wordsmithing in the relevant commands' man pages.

10 years agodocs: add JSONB containment example of a key and empty object
Bruce Momjian [Wed, 7 Oct 2015 14:30:54 +0000 (10:30 -0400)]
docs:  add JSONB containment example of a key and empty object

Backpatch through 9.5

10 years agodocs: Map operator @> to the proper SGML escape for '>'
Bruce Momjian [Wed, 7 Oct 2015 13:42:26 +0000 (09:42 -0400)]
docs:  Map operator @> to the proper SGML escape for '>'

Backpatch through 9.5

10 years agodocs: clarify JSONB operator descriptions
Bruce Momjian [Wed, 7 Oct 2015 13:06:49 +0000 (09:06 -0400)]
docs:  clarify JSONB operator descriptions

No catalog bump as the catalog changes are for SQL operator comments.

Backpatch through 9.5

10 years agoPerform an immediate shutdown if the postmaster.pid file is removed.
Tom Lane [Tue, 6 Oct 2015 21:15:27 +0000 (17:15 -0400)]
Perform an immediate shutdown if the postpid file is removed.

The postmaster now checks every minute or so (worst case, at most two
minutes) that postmaster.pid is still there and still contains its own PID.
If not, it performs an immediate shutdown, as though it had received
SIGQUIT.

The original goal behind this change was to ensure that failed buildfarm
runs would get fully cleaned up, even if the test scripts had left a
postmaster running, which is not an infrequent occurrence.  When the
buildfarm script removes a test postmaster's $PGDATA directory, its next
check on postmaster.pid will fail and cause it to exit.  Previously, manual
intervention was often needed to get rid of such orphaned postmasters,
since they'd block new test postmasters from obtaining the expected socket
address.

However, by checking postmaster.pid and not something else, we can provide
additional robustness: manual removal of postmaster.pid is a frequent DBA
mistake, and now we can at least limit the damage that will ensue if a new
postmaster is started while the old one is still alive.

Back-patch to all supported branches, since we won't get the desired
improvement in buildfarm reliability otherwise.

10 years agoStamp 9.5beta1.
Tom Lane [Mon, 5 Oct 2015 19:09:44 +0000 (15:09 -0400)]
Stamp 9.5beta1.

10 years agodocs: update guidelines on when to use GIN and GiST indexes
Bruce Momjian [Mon, 5 Oct 2015 17:38:36 +0000 (13:38 -0400)]
docs:  update guidelines on when to use GIN and GiST indexes

Report by Tomas Vondra

Backpatch through 9.5

10 years agoDocs: explain contrib/pg_stat_statements' handling of GC failure.
Tom Lane [Mon, 5 Oct 2015 16:44:12 +0000 (12:44 -0400)]
Docs: explain contrib/pg_stat_statements' handling of GC failure.

Failure to perform garbage collection now has a user-visible effect, so
explain that and explain that reducing pgss_max is the way to prevent it.
Per gripe from Andrew Dunstan.

10 years agoFix insufficiently-portable regression test case.
Tom Lane [Mon, 5 Oct 2015 16:19:14 +0000 (12:19 -0400)]
Fix insufficiently-portable regression test case.

Some of the buildfarm members are evidently miserly enough of stack space
to pass the originally-committed form of this test.  Increase the
requirement 10X to hopefully ensure that it fails as-expected everywhere.

Security: CVE-2015-5289

10 years agoTranslation updates
Peter Eisentraut [Mon, 5 Oct 2015 14:59:53 +0000 (10:59 -0400)]
Translation updates

Source-Git-URL: git://git.postgresql.org/git/pgtranslation/messages.git
Source-Git-Hash: 23a52bc86edcd39c3c6b80ee1f7374759c8711f8

10 years agoLast-minute updates for release notes.
Tom Lane [Mon, 5 Oct 2015 14:57:15 +0000 (10:57 -0400)]
Last-minute updates for release notes.

Add entries for security and not-quite-security issues.

Security: CVE-2015-5288, CVE-2015-5289

10 years agoRemove outdated comment about relation level autovacuum freeze limits.
Andres Freund [Mon, 5 Oct 2015 14:09:13 +0000 (16:09 +0200)]
Remove outdated comment about relation level autovacuum freeze limits.

The documentation for the autovacuum_multixact_freeze_max_age and
autovacuum_freeze_max_age relation level parameters contained:
"Note that while you can set autovacuum_multixact_freeze_max_age very
small, or even zero, this is usually unwise since it will force frequent
vacuuming."
which hasn't been true since these options were made relation options,
instead of residing in the pg_autovacuum table (834a6da4f7).

Remove the outdated sentence. Even the lowered limits from 2596d70 are
high enough that this doesn't warrant calling out the risk in the CREATE
TABLE docs.

Per discussion with Tom Lane and Alvaro Herrera

Discussion: 26377.1443105453@sss.pgh.pa.us
Backpatch: 9.0- (in parts)

10 years agoAdd regression tests for INSERT/UPDATE+RETURNING
Stephen Frost [Mon, 5 Oct 2015 14:14:51 +0000 (10:14 -0400)]
Add regression tests for INSERT/UPDATE+RETURNING

This adds regressions tests which are specific to INSERT+RETURNING and
UPDATE+RETURNING to ensure that the SELECT policies are added as
WithCheckOptions (and should therefore throw an error when the policy is
violated).

Per suggestion from Andres.

Back-patch to 9.5 as the prior commit was.

10 years agoPrevent stack overflow in query-type functions.
Noah Misch [Mon, 5 Oct 2015 14:06:30 +0000 (10:06 -0400)]
Prevent stack overflow in query-type functions.

The tsquery, ltxtquery and query_int data types have a common ancestor.
Having acquired check_stack_depth() calls independently, each was
missing at least one call.  Back-patch to 9.0 (all supported versions).

10 years agoPrevent stack overflow in container-type functions.
Noah Misch [Mon, 5 Oct 2015 14:06:29 +0000 (10:06 -0400)]
Prevent stack overflow in container-type functions.

A range type can name another range type as its subtype, and a record
type can bear a column of another record type.  Consequently, functions
like range_cmp() and record_recv() are recursive.  Functions at risk
include operator family members and referents of pg_type regproc
columns.  Treat as recursive any such function that looks up and calls
the same-purpose function for a record column type or the range subtype.
Back-patch to 9.0 (all supported versions).

An array type's element type is never itself an array type, so array
functions are unaffected.  Recursion depth proportional to array
dimensionality, found in array_dim_to_jsonb(), is fine thanks to MAXDIM.

10 years agoPrevent stack overflow in json-related functions.
Noah Misch [Mon, 5 Oct 2015 14:06:29 +0000 (10:06 -0400)]
Prevent stack overflow in json-related functions.

Sufficiently-deep recursion heretofore elicited a SIGSEGV.  If an
application constructs PostgreSQL json or jsonb values from arbitrary
user input, application users could have exploited this to terminate all
active database connections.  That applies to 9.3, where the json parser
adopted recursive descent, and later versions.  Only row_to_json() and
array_to_json() were at risk in 9.2, both in a non-security capacity.
Back-patch to 9.2, where the json type was introduced.

Oskari Saarenmaa, reviewed by Michael Paquier.

Security: CVE-2015-5289

10 years agopgcrypto: Detect and report too-short crypt() salts.
Noah Misch [Mon, 5 Oct 2015 14:06:29 +0000 (10:06 -0400)]
pgcrypto: Detect and report too-short crypt() salts.

Certain short salts crashed the backend or disclosed a few bytes of
backend memory.  For existing salt-induced error conditions, emit a
message saying as much.  Back-patch to 9.0 (all supported versions).

Josh Kupershmidt

Security: CVE-2015-5288

10 years agoApply SELECT policies in INSERT/UPDATE+RETURNING
Stephen Frost [Mon, 5 Oct 2015 11:55:11 +0000 (07:55 -0400)]
Apply SELECT policies in INSERT/UPDATE+RETURNING

Similar to 7d8db3e, given that INSERT+RETURNING requires SELECT rights
on the table, apply the SELECT policies as WCOs to the tuples being
inserted.  Apply the same logic to UPDATE+RETURNING.

Back-patch to 9.5 where RLS was added.

10 years agoDo not write out WCOs in Query
Stephen Frost [Mon, 5 Oct 2015 11:38:56 +0000 (07:38 -0400)]
Do not write out WCOs in Query

The WithCheckOptions list in Query are only populated during rewrite and
do not need to be written out or read in as part of a Query structure.

Further, move WithCheckOptions to the bottom and add comments to clarify
that it is only populated during rewrite.

Back-patch to 9.5 with a catversion bump, as we are still in alpha.

10 years agoRe-Align *_freeze_max_age reloption limits with corresponding GUC limits.
Andres Freund [Mon, 5 Oct 2015 09:53:43 +0000 (11:53 +0200)]
Re-Align *_freeze_max_age reloption limits with corresponding GUC limits.

In 020235a5754 I lowered the autovacuum_*freeze_max_age minimums to
allow for easier testing of wraparounds. I did not touch the
corresponding per-table limits. While those don't matter for the purpose
of wraparound, it seems more consistent to lower them as well.

It's noteworthy that the previous reloption lower limit for
autovacuum_multixact_freeze_max_age was too high by one magnitude, even
before 020235a5754.

Discussion: 26377.1443105453@sss.pgh.pa.us
Backpatch: back to 9.0 (in parts), like the prior patch

10 years agoALTER TABLE .. FORCE ROW LEVEL SECURITY
Stephen Frost [Mon, 5 Oct 2015 01:05:18 +0000 (21:05 -0400)]
ALTER TABLE .. FORCE ROW LEVEL SECURITY

To allow users to force RLS to always be applied, even for table owners,
add ALTER TABLE .. FORCE ROW LEVEL SECURITY.

row_security=off overrides FORCE ROW LEVEL SECURITY, to ensure pg_dump
output is complete (by default).

Also add SECURITY_NOFORCE_RLS context to avoid data corruption when
ALTER TABLE .. FORCE ROW SECURITY is being used. The
SECURITY_NOFORCE_RLS security context is used only during referential
integrity checks and is only considered in check_enable_rls() after we
have already checked that the current user is the owner of the relation
(which should always be the case during referential integrity checks).

Back-patch to 9.5 where RLS was added.

10 years agoRelease notes for 9.5beta1, 9.4.5, 9.3.10, 9.2.14, 9.1.19, 9.0.23.
Tom Lane [Sun, 4 Oct 2015 23:38:00 +0000 (19:38 -0400)]
Release notes for 9.5beta1, 9.4.5, 9.3.10, 9.2.14, 9.1.19, 9.0.23.

10 years agoImprove contrib/pg_stat_statements' handling of garbage collection failure.
Tom Lane [Sun, 4 Oct 2015 21:58:30 +0000 (17:58 -0400)]
Improve contrib/pg_stat_statements' handling of garbage collection failure.

If we can't read the query texts file (whether because out-of-memory, or
for some other reason), give up and reset the file to empty, discarding all
stored query texts, though not the statistics per se.  We used to leave
things alone and hope for better luck next time, but the problem is that
the file is only going to get bigger and even harder to slurp into memory.
Better to do something that will get us out of trouble.

Likewise reset the file to empty for any other failure within gc_qtexts().
The previous behavior after a write error was to discard query texts but
not do anything to truncate the file, which is just weird.

Also, increase the maximum supported file size from MaxAllocSize to
MaxAllocHugeSize; this makes it more likely we'll be able to do a garbage
collection successfully.

Also, fix recalculation of mean_query_len within entry_dealloc() to match
the calculation in gc_qtexts().  The previous coding overlooked the
possibility of dropped texts (query_len == -1) and would underestimate the
mean of the remaining entries in such cases, thus possibly causing excess
garbage collection cycles.

In passing, add some errdetail to the log entry that complains about
insufficient memory to read the query texts file, which after all was
Jim Nasby's original complaint.

Back-patch to 9.4 where the current handling of query texts was
introduced.

Peter Geoghegan, rather editorialized upon by me

10 years agoFurther twiddling of nodeHash.c hashtable sizing calculation.
Tom Lane [Sun, 4 Oct 2015 19:55:07 +0000 (15:55 -0400)]
Further twiddling of nodeHash.c hashtable sizing calculation.

On reflection, the submitted patch didn't really work to prevent the
request size from exceeding MaxAllocSize, because of the fact that we'd
happily round nbuckets up to the next power of 2 after we'd limited it to
max_pointers.  The simplest way to enforce the limit correctly is to
round max_pointers down to a power of 2 when it isn't one already.

(Note that the constraint to INT_MAX / 2, if it were doing anything useful
at all, is properly applied after that.)

10 years agoFix some issues in new hashtable size calculations in nodeHash.c.
Tom Lane [Sun, 4 Oct 2015 18:06:40 +0000 (14:06 -0400)]
Fix some issues in new hashtable size calculations in nodeHash.c.

Limit the size of the hashtable pointer array to not more than
MaxAllocSize, per reports from Kouhei Kaigai and others of "invalid memory
alloc request size" failures.  There was discussion of allowing the array
to get larger than that by using the "huge" palloc API, but so far no proof
that that is actually a good idea, and at this point in the 9.5 cycle major
changes from old behavior don't seem like the way to go.

Fix a rather serious secondary bug in the new code, which was that it
didn't ensure nbuckets remained a power of 2 when recomputing it for the
multiple-batch case.

Clean up sloppy division of labor between ExecHashIncreaseNumBuckets and
its sole call site.

10 years agoDisallow invalid path elements in jsonb_set
Andrew Dunstan [Sun, 4 Oct 2015 17:28:16 +0000 (13:28 -0400)]
Disallow invalid path elements in jsonb_set

Null path elements and, where the object is an array, invalid integer
elements now cause an error.

Incorrect behaviour noted by Thom Brown, patch from Dmitry Dolgov.

Backpatch to 9.5 where jsonb_set was introduced

10 years agoGroup cluster_name and update_process_title settings together
Peter Eisentraut [Sun, 4 Oct 2015 15:14:28 +0000 (11:14 -0400)]
Group cluster_name and update_process_title settings together

10 years agoDocument that row_security is a boolean GUC.
Noah Misch [Sun, 4 Oct 2015 00:20:22 +0000 (20:20 -0400)]
Document that row_security is a boolean GUC.

Oversight in commit 537bd178c73b1d25938347b17e9e3e62898fc231.
Back-patch to 9.5, like that commit.

10 years agoMake BYPASSRLS behave like superuser RLS bypass.
Noah Misch [Sun, 4 Oct 2015 00:19:57 +0000 (20:19 -0400)]
Make BYPASSRLS behave like superuser RLS bypass.

Specifically, make its effect independent from the row_security GUC, and
make it affect permission checks pertinent to views the BYPASSRLS role
owns.  The row_security GUC thereby ceases to change successful-query
behavior; it can only make a query fail with an error.  Back-patch to
9.5, where BYPASSRLS was introduced.

10 years agoImprove errhint() about replication slot naming restrictions.
Andres Freund [Sat, 3 Oct 2015 13:29:08 +0000 (15:29 +0200)]
Improve errhint() about replication slot naming restrictions.

The existing hint talked about "may only contain letters", but the
actual requirement is more strict: only lower case letters are allowed.

Reported-By: Rushabh Lathia
Author: Rushabh Lathia
Discussion: AGPqQf2x50qcwbYOBKzb4x75sO_V3g81ZsA8+Ji9iN5t_khFhQ@mail.gmail.com
Backpatch: 9.4-, where replication slots were added

10 years agoFix several bugs related to ON CONFLICT's EXCLUDED pseudo relation.
Andres Freund [Sat, 3 Oct 2015 13:12:10 +0000 (15:12 +0200)]
Fix several bugs related to ON CONFLICT's EXCLUDED pseudo relation.

Four related issues:

1) attnos/varnos/resnos for EXCLUDED were out of sync when a column
   after one dropped in the underlying relation was referenced.
2) References to whole-row variables (i.e. EXCLUDED.*) lead to errors.
3) It was possible to reference system columns in the EXCLUDED pseudo
   relations, even though they would not have valid contents.
4) References to EXCLUDED were rewritten by the RLS machinery, as
   EXCLUDED was treated as if it were the underlying relation.

To fix the first two issues, generate the excluded targetlist with
dropped columns in mind and add an entry for whole row
variables. Instead of unconditionally adding a wholerow entry we could
pull up the expression if needed, but doing it unconditionally seems
simpler. The wholerow entry is only really needed for ruleutils/EXPLAIN
support anyway.

The remaining two issues are addressed by changing the EXCLUDED RTE to
have relkind = composite. That fits with EXCLUDED not actually being a
real relation, and allows to treat it differently in the relevant
places. scanRTEForColumn now skips looking up system columns when the
RTE has a composite relkind; fireRIRrules() already had a corresponding
check, thereby preventing RLS expansion on EXCLUDED.

Also add tests for these issues, and improve a few comments around
excluded handling in setrefs.c.

Reported-By: Peter Geoghegan, Geoff Winkless
Author: Andres Freund, Amit Langote, Peter Geoghegan
Discussion: CAEzk6fdzJ3xYQZGbcuYM2rBd2BuDkUksmK=mY9UYYDugg_GgZg@mail.gmail.com,
   CAM3SWZS+CauzbiCEcg-GdE6K6ycHE_Bz6Ksszy8AoixcMHOmsA@mail.gmail.com
Backpatch: 9.5, where ON CONFLICT was introduced

10 years agodoc: Update URLs of external projects
Peter Eisentraut [Sat, 3 Oct 2015 01:50:59 +0000 (21:50 -0400)]
doc: Update URLs of external projects