⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prepared_xacts.out

📁 PostgreSQL 8.1.4的源码 适用于Linux下的开源数据库系统
💻 OUT
字号:
---- PREPARED TRANSACTIONS (two-phase commit)---- We can't readily test persistence of prepared xacts within the-- regression script framework, unfortunately.  Note that a crash-- 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 testsCREATE TABLE pxtest1 (foobar VARCHAR(10));INSERT INTO pxtest1 VALUES ('aaa');-- Test PREPARE TRANSACTIONBEGIN;UPDATE pxtest1 SET foobar = 'bbb' WHERE foobar = 'aaa';SELECT * FROM pxtest1; foobar -------- bbb(1 row)PREPARE TRANSACTION 'foo1';SELECT * FROM pxtest1; foobar -------- aaa(1 row)-- Test pg_prepared_xacts system viewSELECT gid FROM pg_prepared_xacts; gid  ------ foo1(1 row)-- Test ROLLBACK PREPAREDROLLBACK PREPARED 'foo1';SELECT * FROM pxtest1; foobar -------- aaa(1 row)SELECT gid FROM pg_prepared_xacts; gid -----(0 rows)-- Test COMMIT PREPAREDBEGIN;INSERT INTO pxtest1 VALUES ('ddd');SELECT * FROM pxtest1; foobar -------- aaa ddd(2 rows)PREPARE TRANSACTION 'foo2';SELECT * FROM pxtest1; foobar -------- aaa(1 row)COMMIT PREPARED 'foo2';SELECT * FROM pxtest1; foobar -------- aaa ddd(2 rows)-- Test duplicate gidsBEGIN;UPDATE pxtest1 SET foobar = 'eee' WHERE foobar = 'ddd';SELECT * FROM pxtest1; foobar -------- aaa eee(2 rows)PREPARE TRANSACTION 'foo3';SELECT gid FROM pg_prepared_xacts; gid  ------ foo3(1 row)BEGIN;INSERT INTO pxtest1 VALUES ('fff');SELECT * FROM pxtest1; foobar -------- aaa ddd fff(3 rows)-- This should fail, because the gid foo3 is already in usePREPARE TRANSACTION 'foo3';ERROR:  transaction identifier "foo3" is already in useSELECT * FROM pxtest1; foobar -------- aaa ddd(2 rows)ROLLBACK PREPARED 'foo3';SELECT * FROM pxtest1; foobar -------- aaa ddd(2 rows)-- Clean upDROP TABLE pxtest1;-- Test subtransactionsBEGIN;  CREATE TABLE pxtest2 (a int);  INSERT INTO pxtest2 VALUES (1);  SAVEPOINT a;    INSERT INTO pxtest2 VALUES (2);  ROLLBACK TO a;  SAVEPOINT b;  INSERT INTO pxtest2 VALUES (3);PREPARE TRANSACTION 'regress-one';CREATE TABLE pxtest3(fff int);-- Test shared invalidationBEGIN;  DROP TABLE pxtest3;  CREATE TABLE pxtest4 (a int);  INSERT INTO pxtest4 VALUES (1);  INSERT INTO pxtest4 VALUES (2);  DECLARE foo CURSOR FOR SELECT * FROM pxtest4;  -- Fetch 1 tuple, keeping the cursor open  FETCH 1 FROM foo; a --- 1(1 row)PREPARE TRANSACTION 'regress-two';-- No such cursorFETCH 1 FROM foo;ERROR:  cursor "foo" does not exist-- Table doesn't exist, the creation hasn't been committed yetSELECT * FROM pxtest2;ERROR:  relation "pxtest2" does not exist-- There should be two prepared transactionsSELECT gid FROM pg_prepared_xacts;     gid     ------------- regress-one regress-two(2 rows)-- pxtest3 should be locked because of the pending DROPset statement_timeout to 1000;SELECT * FROM pxtest3;ERROR:  canceling statement due to statement timeoutreset statement_timeout;-- Disconnect, we will continue testing in a different backend\c --- There should still be two prepared transactionsSELECT gid FROM pg_prepared_xacts;     gid     ------------- regress-one regress-two(2 rows)-- pxtest3 should still be locked because of the pending DROPset statement_timeout to 1000;SELECT * FROM pxtest3;ERROR:  canceling statement due to statement timeoutreset statement_timeout;-- Commit table creationCOMMIT PREPARED 'regress-one';\d pxtest2    Table "public.pxtest2" Column |  Type   | Modifiers --------+---------+----------- a      | integer | SELECT * FROM pxtest2; a --- 1 3(2 rows)-- There should be one prepared transactionSELECT gid FROM pg_prepared_xacts;     gid     ------------- regress-two(1 row)-- Commit table dropCOMMIT PREPARED 'regress-two';SELECT * FROM pxtest3;ERROR:  relation "pxtest3" does not exist-- There should be no prepared transactionsSELECT gid FROM pg_prepared_xacts; gid -----(0 rows)-- Clean upDROP TABLE pxtest2;DROP TABLE pxtest4;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -