共計 2317 個字符,預(yù)計需要花費 6 分鐘才能閱讀完成。
這篇文章主要講解了“PostgreSQL 禁止的異象是什么”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著丸趣 TV 小編的思路慢慢深入,一起來研究和學(xué)習(xí)“PostgreSQL 禁止的異象是什么”吧!
測試數(shù)據(jù)
數(shù)據(jù)表 idx,在 id 列上有索引,數(shù)據(jù)庫默認(rèn)的隔離級別為可串行化
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 觸發(fā)
操作序列如下:
時間點 T1T2T3t1begin;
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)在執(zhí)行 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 觸發(fā)
操作序列如下:
時間點 T1T2T3t1begin;
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)在執(zhí)行 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 觸發(fā)
操作序列如下:
時間點 T1T2t1begin;
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 執(zhí)行 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 禁止的異象是什么”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對 PostgreSQL 禁止的異象是什么這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是丸趣 TV,丸趣 TV 小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!