mirror of
https://github.com/postgres/postgres.git
synced 2026-03-22 10:30:21 -04:00
Add test for row-locking and multixids with prepared transactions
This is a repro for the issue fixed in commit ccae90abdb. Backpatch to
v17 like that commit, although that's a little arbitrary as this test
would work on older versions too.
Author: Sami Imseih <samimseih@gmail.com>
Discussion: https://www.postgresql.org/message-id/CAA5RZ0twq5bNMq0r0QNoopQnAEv+J3qJNCrLs7HVqTEntBhJ=g@mail.gmail.com
Backpatch-through: 17
This commit is contained in:
parent
19615a44b3
commit
fe08113aef
2 changed files with 55 additions and 0 deletions
|
|
@ -267,7 +267,37 @@ SELECT gid FROM pg_prepared_xacts WHERE gid ~ '^regress_' ORDER BY gid;
|
|||
-----
|
||||
(0 rows)
|
||||
|
||||
-- Test row-level locks held by prepared transactions
|
||||
CREATE TABLE pxtest_rowlock (id int PRIMARY KEY, data text);
|
||||
INSERT INTO pxtest_rowlock VALUES (1, 'test data');
|
||||
BEGIN;
|
||||
SELECT * FROM pxtest_rowlock WHERE id = 1 FOR SHARE;
|
||||
id | data
|
||||
----+-----------
|
||||
1 | test data
|
||||
(1 row)
|
||||
|
||||
PREPARE TRANSACTION 'regress_p1';
|
||||
-- Should fail because the row is locked
|
||||
SELECT * FROM pxtest_rowlock WHERE id = 1 FOR UPDATE NOWAIT;
|
||||
ERROR: could not obtain lock on row in relation "pxtest_rowlock"
|
||||
-- Test prepared transactions that participate in multixacts. For
|
||||
-- that, lock the same row again, creating a multixid.
|
||||
BEGIN;
|
||||
SELECT * FROM pxtest_rowlock WHERE id = 1 FOR SHARE;
|
||||
id | data
|
||||
----+-----------
|
||||
1 | test data
|
||||
(1 row)
|
||||
|
||||
PREPARE TRANSACTION 'regress_p2';
|
||||
-- Should fail because the row is locked
|
||||
SELECT * FROM pxtest_rowlock WHERE id = 1 FOR UPDATE NOWAIT;
|
||||
ERROR: could not obtain lock on row in relation "pxtest_rowlock"
|
||||
ROLLBACK PREPARED 'regress_p1';
|
||||
ROLLBACK PREPARED 'regress_p2';
|
||||
-- Clean up
|
||||
DROP TABLE pxtest2;
|
||||
-- pxtest3 was already dropped
|
||||
DROP TABLE pxtest4;
|
||||
DROP TABLE pxtest_rowlock;
|
||||
|
|
|
|||
|
|
@ -163,7 +163,32 @@ SELECT * FROM pxtest3;
|
|||
-- There should be no prepared transactions
|
||||
SELECT gid FROM pg_prepared_xacts WHERE gid ~ '^regress_' ORDER BY gid;
|
||||
|
||||
|
||||
-- Test row-level locks held by prepared transactions
|
||||
CREATE TABLE pxtest_rowlock (id int PRIMARY KEY, data text);
|
||||
INSERT INTO pxtest_rowlock VALUES (1, 'test data');
|
||||
|
||||
BEGIN;
|
||||
SELECT * FROM pxtest_rowlock WHERE id = 1 FOR SHARE;
|
||||
PREPARE TRANSACTION 'regress_p1';
|
||||
|
||||
-- Should fail because the row is locked
|
||||
SELECT * FROM pxtest_rowlock WHERE id = 1 FOR UPDATE NOWAIT;
|
||||
|
||||
-- Test prepared transactions that participate in multixacts. For
|
||||
-- that, lock the same row again, creating a multixid.
|
||||
BEGIN;
|
||||
SELECT * FROM pxtest_rowlock WHERE id = 1 FOR SHARE;
|
||||
PREPARE TRANSACTION 'regress_p2';
|
||||
|
||||
-- Should fail because the row is locked
|
||||
SELECT * FROM pxtest_rowlock WHERE id = 1 FOR UPDATE NOWAIT;
|
||||
|
||||
ROLLBACK PREPARED 'regress_p1';
|
||||
ROLLBACK PREPARED 'regress_p2';
|
||||
|
||||
-- Clean up
|
||||
DROP TABLE pxtest2;
|
||||
-- pxtest3 was already dropped
|
||||
DROP TABLE pxtest4;
|
||||
DROP TABLE pxtest_rowlock;
|
||||
|
|
|
|||
Loading…
Reference in a new issue