您好,登錄后才能下訂單哦!
這篇文章主要講解了“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'
操作序列如下:
時間點 | T1 | T2 | T3 |
---|---|---|---|
t1 | begin; | ||
t2 | select * 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=#!
操作序列如下:
時間點 | T1 | T2 | T3 |
---|---|---|---|
t1 | begin; | ||
t2 | select * 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=#!
操作序列如下:
時間點 | T1 | T2 |
---|---|---|
t1 | begin; | |
t2 | select * from idx where id = 1; | |
t3 | update 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; | |
t8 | commit; |
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禁止的異象是什么這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。