Concurrent Connection Support for Psql

Overview

This patch adds support for opening multiple independent connections to different Postgres databases in a single psql client. This allows the implementation of regression tests that test the interaction between multiple connections such as locking and transaction semantics.

The original inspiration for the user interface came from the traditional shell job control where & allows the user to start commands asynchronously and assigns each job a sequential number.

Download

concurrent-psql-v4.patch.gz

Usage

The patch adds a suite of new commands to psql to create new connections, switch between connections, and issue SQL commands asynchronously (the choice of specific names are open for discussion):

Example

This example demonstrates the recently discovered bug in lock handling in the face of savepoints where the user takes locks on the same record from two different levels within the same outermost transaction.
regression=> drop table test;
DROP TABLE

regression=> create table test (i integer);
CREATE TABLE

regression=> insert into test values (0);
INSERT 0 1

regression=> begin;
BEGIN

regression=> select * from test for update;
 i 
---
 0
(1 row)

regression=> savepoint x;
SAVEPOINT

regression=> update test set i = 1;
UPDATE 1

regression=> rollback to x;
ROLLBACK

regression=> \c&
[2] You are now connected to database "regression".

regression[2]=> \cnowait

regression[2]=> update test set i = 2;
UPDATE 1

regression[2]=> \cwait 1

regression[2]=> \cswitch 1
[1] You are now connected to database "regression"

regression[1]=> rollback;
ROLLBACK

regression[1]=> \cswitch 2
[2] You are now connected to database "regression"

TODO

The patch breaks the FETCH_COUNT handling with \pager is enabled. Instead of starting a single pager for the entire result set a separate pager will be started for each fetch_count rows. The column headings and table borders will also treat each fetch_count rows as a separate result set instead of a single result set as teh stock psql's fetch_count code displays it.