-- isn't really needed ... stopping and starting the postmaster would
-- be enough, but we can't even do that here.
-- create a simple table that we'll use in the tests
-CREATE TABLE pxtest1 (foobar VARCHAR(10));
+CREATE TABLE pxtest1 (foobar VARCHAR(10)) distribute by replication;
INSERT INTO pxtest1 VALUES ('aaa');
-- Test PREPARE TRANSACTION
BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
INSERT INTO pxtest1 VALUES ('fff');
-SELECT * FROM pxtest1 ORDER BY foobar;
-- This should fail, because the gid foo3 is already in use
PREPARE TRANSACTION 'foo3';
ERROR: transaction identifier "foo3" is already in use
-- This should fail, because the two transactions have a write-skew anomaly
INSERT INTO pxtest1 VALUES ('fff');
-ERROR: could not serialize access due to read/write dependencies among transactions
-DETAIL: Reason code: Canceled on identification as a pivot, during write.
-HINT: The transaction might succeed if retried.
PREPARE TRANSACTION 'foo5';
SELECT gid FROM pg_prepared_xacts;
gid
------
foo4
-(1 row)
+ foo5
+(2 rows)
ROLLBACK PREPARED 'foo4';
SELECT gid FROM pg_prepared_xacts;
- gid
------
-(0 rows)
+ gid
+------
+ foo5
+(1 row)
+-- In Postgres-XL, serializable is not yet supported, and SERIALIZABLE falls to
+-- read-committed silently, so rollback transaction properly
+ROLLBACK PREPARED 'foo5';
-- Clean up
DROP TABLE pxtest1;
-- Test subtransactions
CREATE TABLE pxtest2 (a int);
INSERT INTO pxtest2 VALUES (1);
SAVEPOINT a;
+ERROR: SAVEPOINT is not yet supported.
INSERT INTO pxtest2 VALUES (2);
+ERROR: current transaction is aborted, commands ignored until end of transaction block
ROLLBACK TO a;
+ERROR: no such savepoint
SAVEPOINT b;
+ERROR: current transaction is aborted, commands ignored until end of transaction block
INSERT INTO pxtest2 VALUES (3);
+ERROR: current transaction is aborted, commands ignored until end of transaction block
PREPARE TRANSACTION 'regress-one';
CREATE TABLE pxtest3(fff int);
-- Test shared invalidation
SELECT gid FROM pg_prepared_xacts ORDER BY gid;
gid
-------------
- regress-one
regress-two
-(2 rows)
+(1 row)
+
+-- Check prepared transactions in the cluster
+SELECT pgxc_prepared_xact FROM pgxc_prepared_xacts ORDER by 1;
+ pgxc_prepared_xact
+--------------------
+ regress-two
+(1 row)
-- pxtest3 should be locked because of the pending DROP
begin;
SELECT gid FROM pg_prepared_xacts ORDER BY gid;
gid
-------------
- regress-one
regress-two
-(2 rows)
+(1 row)
+
+-- Check prepared transactions in the cluster
+SELECT pgxc_prepared_xact FROM pgxc_prepared_xacts ORDER by 1;
+ pgxc_prepared_xact
+--------------------
+ regress-two
+(1 row)
-- pxtest3 should still be locked because of the pending DROP
begin;
rollback;
-- Commit table creation
COMMIT PREPARED 'regress-one';
+ERROR: prepared transaction with identifier "regress-one" does not exist
\d pxtest2
- Table "public.pxtest2"
- Column | Type | Modifiers
---------+---------+-----------
- a | integer |
-
SELECT * FROM pxtest2;
- a
----
- 1
- 3
-(2 rows)
-
+ERROR: relation "pxtest2" does not exist
+LINE 1: SELECT * FROM pxtest2;
+ ^
-- There should be one prepared transaction
-SELECT gid FROM pg_prepared_xacts;
+SELECT gid FROM pg_prepared_xacts ORDER BY 1;
gid
-------------
regress-two
-- Clean up
DROP TABLE pxtest2;
+ERROR: table "pxtest2" does not exist
DROP TABLE pxtest3; -- will still be there if prepared xacts are disabled
ERROR: table "pxtest3" does not exist
DROP TABLE pxtest4;