刚测了以下,pg是不支持读未提交的。pg把读未提交当成了读提交处理。如果是读提交的话,楼主这个问题是会加锁的。
session 1:
postgres=# show transaction_isolation; ================》STEP 1
transaction_isolation
-----------------------
read uncommitted
(1 row)
postgres=# select * from test; ===================》STEP 2
id
----
1
(1 row)
postgres=# begin;
BEGIN
postgres=# update test set id=2 where id=1; ================》STEP5
UPDATE 1
postgres=# select * from test; ========================》STEP6
id
----
2
(1 row)
postgres=# commit; =================》STEP8
COMMIT
postgres=# select * from test; =================》STEP9
id
----
2
(1 row)
会话2:
postgres=# show transaction_isolation; ===============》STEP 3
transaction_isolation
-----------------------
read uncommitted
(1 row)
postgres=#
postgres=#
postgres=# begin;
BEGIN
postgres=# select * from test; =================》STEP4
id
----
1
(1 row)
postgres=# select * from test;=================》STEP7
id
----
1
(1 row)
postgres=# select * from test; =================》STEP10
id
----
2
(1 row)