PostgreSQL禁止的异象是什么
这篇文章主要讲解了“PostgreSQL禁止的异象是什么”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“PostgreSQL禁止的异象是什么”吧!
测试数据数据表idx,在id列上有索引,数据库默认的隔离级别为可串行化
15:44:16[local:/data/run/pg12]:5120pg12@testdb=#\d+idxTable"public.idx"Column|Type|Collation|Nullable|Default|Storage|Statstarget|Description--------+-------------------+-----------+----------+---------+----------+--------------+-------------id|integer||||plain||c1|charactervarying||||extended||Indexes:"idx_id"btree(id)Accessmethod:heap[pg12@localhostpg122db]$grep'isolation'postgresql.confdefault_transaction_isolation='SERIALIZABLE'Write触发
操作序列如下:
t2select * from idx where id = 1;
t3
begin;
t4
select * from idx where id = 10000;
t5
begin;t6
update idx set c1 = ‘x’ where id = 10000;t7
commit;t8
update idx set c1 = ‘x’ where id = 1;
session 2(T2)在执行update操作时会报错
--session215:46:52[local:/data/run/pg12]:5120pg12@testdb=#*updateidxsetc1='x'whereid=1;ERROR:couldnotserializeaccessduetoread/writedependenciesamongtransactionsDETAIL:Reasoncode:Canceledonidentificationasapivot,duringwrite.HINT:Thetransactionmightsucceedifretried.15:47:10[local:/data/run/pg12]:5120pg12@testdb=#!Read触发
操作序列如下:
t2select * from idx where id = 1;
t3
begin;
t4
update idx set c1 = ‘x1’ where id = 1;
t5
begin;t6
update idx set c1 = ‘x’ where id = 10000;t7
commit;t8
select * from idx where id = 10000;
session 2(T2)在执行select操作时会报错
15:54:41[local:/data/run/pg12]:5120pg12@testdb=#*select*fromidxwhereid=10000;ERROR:couldnotserializeaccessduetoread/writedependenciesamongtransactionsDETAIL:Reasoncode:Canceledonconflictouttopivot423284,duringread.HINT:Thetransactionmightsucceedifretried.15:55:16[local:/data/run/pg12]:5120pg12@testdb=#!commit触发
操作序列如下:
t2select * from idx where id = 1;
t3update tbl set c1 = ‘x’ where id = 10000;
t4
begin;t5
select * from idx where id = 10000;t6
update idx set c1 = ‘x’ where id = 1;t7
commit;t8commit;
T1执行commit的时候会报错:
16:07:50[local:/data/run/pg12]:5120pg12@testdb=#*commit;ERROR:couldnotserializeaccessduetoread/writedependenciesamongtransactionsDETAIL:Reasoncode:Canceledonidentificationasapivot,duringcommitattempt.HINT:Thetransactionmightsucceedifretried.
感谢各位的阅读,以上就是“PostgreSQL禁止的异象是什么”的内容了,经过本文的学习后,相信大家对PostgreSQL禁止的异象是什么这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。