客户端A:
epmdb=> start transaction ;
START TRANSACTION
epmdb=> update t1.dbversion set value =1200 where dbversionid=1;
UPDATE 1
epmdb=>
客户端B:
epmdb=> start transaction
epmdb-> ;
START TRANSACTION
epmdb=> select * from t1.dbversion ;
dbversionid | value | currentdataversion | targetdataversion
-------------+--------+--------------------+-------------------
1 | 110000 | 100 | 1
(1 row)
客户端A修改后,结果不变:
epmdb=> select * from t1.dbversion ;
dbversionid | value | currentdataversion | targetdataversion
-------------+--------+--------------------+-------------------
1 | 110000 | 100 | 1
A提交:
epmdb=> commit
epmdb-> ;
COMMIT
B查询:
epmdb=> select * from t1.dbversion ;
dbversionid | value | currentdataversion | targetdataversion
-------------+-------+--------------------+-------------------
1 | 1200 | 100 | 1
(1 row)
epmdb=> show default_transaction_isolation ;
default_transaction_isolation
-------------------------------
serializable
(1 row)
修改隔离级别一定要开启事务,然后修改,再提交,直接set 不会生效。
B开启事务,查询:
epmdb=> start transaction ;
START TRANSACTION
epmdb=> select * from t1.dbversion ;
dbversionid | value | currentdataversion | targetdataversion
-------------+-------+--------------------+-------------------
1 | 66 | 100 | 1
2 | 3 | 4 | 50
(2 rows)
epmdb=> select * from t1.dbversion ;
dbversionid | value | currentdataversion | targetdataversion
-------------+-------+--------------------+-------------------
1 | 66 | 100 | 1
2 | 3 | 4 | 50
(2 rows)
A开启事务,试图修改或者插入:
epmdb=> start transaction ;
START TRANSACTION
epmdb=> select * from t1.dbversion ;
dbversionid | value | currentdataversion | targetdataversion
-------------+-------+--------------------+-------------------
1 | 66 | 100 | 1
2 | 3 | 4 | 50
(2 rows)
START TRANSACTION
epmdb=> update t1.dbversion set value =644446 where dbversionid=1;
UPDATE 1
epmdb=> insert into t1.dbversion (dbversionid,value,currentdataversion,targetdataversion) values(12444,3,4,50);
INSERT 0 1
epmdb=> commit;
COMMIT
都成功,查询文档,得知,serial是把事务并行提交,转换为串行执行
Suppose that serializable transaction A computes:
SELECT SUM(value) FROM mytab WHERE class = 1;
and then inserts the result (30) as the value in a new row with class = 2. Concurrently, serializable transaction B computes:
SELECT SUM(value) FROM mytab WHERE class = 2;
and obtains the result 300, which it inserts in a new row with class = 1. Then both transactions try to commit. If either transaction were running at the Repeatable Read isolation level, both would be allowed to commit; but since there is no serial order of execution consistent with the result, using Serializable transactions will allow one transaction to commit and will roll the other back with this message:
ERROR: could not serialize access due to read/write dependencies among transactions由于无法测试同时提交两个查询,无法测试