溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

PostgreSQL禁止的異象是什么

發布時間:2021-11-01 09:42:48 來源:億速云 閱讀:195 作者:iii 欄目:關系型數據庫

這篇文章主要講解了“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禁止的異象是什么這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女