PostgreSQL禁止的异象是什么-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

PostgreSQL禁止的异象是什么

这篇文章主要讲解了“PostgreSQL禁止的异象是什么”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“PostgreSQL禁止的异象是什么”吧!

在旺苍等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都网站设计、网站建设、外贸网站建设 网站设计制作按需网站制作,公司网站建设,企业网站建设,成都品牌网站建设,营销型网站,成都外贸网站建设公司,旺苍网站建设费用合理。

测试数据

数据表idx,在id列上有索引,数据库默认的隔离级别为可串行化

15:44:16 [local:/data/run/pg12]:5120 pg12@testdb=# \d+ idx
                                         Table "public.idx"
 Column |       Type        | Collation | Nullable | Default | Storage  | Stats
target | Description
--------+-------------------+-----------+----------+---------+----------+-------
-------+-------------
 id     | integer           |           |          |         | plain    |
       |
 c1     | character varying |           |          |         | extended |
       |
Indexes:
    "idx_id" btree (id)
Access method: heap
[pg12@localhost pg122db]$ grep 'isolation' postgresql.conf
default_transaction_isolation = 'SERIALIZABLE'

Write触发

操作序列如下:

时间点T1T2T3
t1begin;

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操作时会报错

-- session 2
15:46:52 [local:/data/run/pg12]:5120 pg12@testdb=#* update idx set c1 = 'x' where id = 1;
ERROR:  could not serialize access due to read/write dependencies among transactions
DETAIL:  Reason code: Canceled on identification as a pivot, during write.
HINT:  The transaction might succeed if retried.
15:47:10 [local:/data/run/pg12]:5120 pg12@testdb=#!

Read触发

操作序列如下:

时间点T1T2T3
t1begin;

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]:5120 pg12@testdb=#* select * from idx where id = 10000;
ERROR:  could not serialize access due to read/write dependencies among transactions
DETAIL:  Reason code: Canceled on conflict out to pivot 423284, during read.
HINT:  The transaction might succeed if retried.
15:55:16 [local:/data/run/pg12]:5120 pg12@testdb=#!

commit触发

操作序列如下:

时间点T1T2
t1begin;
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]:5120 pg12@testdb=#* commit;
ERROR:  could not serialize access due to read/write dependencies among transactions
DETAIL:  Reason code: Canceled on identification as a pivot, during commit attempt.
HINT:  The transaction might succeed if retried.

感谢各位的阅读,以上就是“PostgreSQL禁止的异象是什么”的内容了,经过本文的学习后,相信大家对PostgreSQL禁止的异象是什么这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!


标题名称:PostgreSQL禁止的异象是什么
文章网址:http://kswsj.cn/article/psghgc.html

其他资讯