暂无图片
pg在读未提交隔离下,开启一个事务,然后deletefrom表明where id =,id是主键,行上柜加锁吗?
我来答
分享
nanjing_2013
2022-09-01
pg在读未提交隔离下,开启一个事务,然后deletefrom表明where id =,id是主键,行上柜加锁吗?
pg在读未提交隔离下,开启一个事务,然后deletefrom表明where id =,id是主键,行上柜加锁吗?
我来答
添加附件
收藏
分享
问题补充
1条回答
默认
最新
张sir

刚测了以下,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)

暂无图片 评论
暂无图片 有用 0
回答交流
提交
问题信息
请登录之后查看
邀请回答
暂无人订阅该标签,敬请期待~~
暂无图片墨值悬赏