sql標準的4種隔離機制。
isolation level
dirty reads
non-repeatable reads
phantoms
read uncommitted
may occur
may occur
may occur
read committed
don't occur
may occur
may occur
repeatable read
don't occur
don't occur
may occur
serializable
don't occur
don't occur
don't occur
常見的關係型資料庫的預設事務隔離級別採用的是read_commited,例如postgresql、oracle、sql server和db2。但是使用innodb引擎的mysql資料庫預設事務隔離級別是repeatable_read。
查詢postgresql預設的隔離級別:
highgo=> show default_transaction_isolation;
default_transaction_isolation
read committed
(1 row)
檢查當前隔離級別:
highgo=# show transaction_isolation;
transaction_isolation
read committed
(1 row)
修改隔離級別:
1.修改當前事務的隔離級別,須在事物中執行:
highgo=# begin;
highgo=# set transaction isolation level serializable;
sethighgo=# show transaction_isolation;
transaction_isolation
serializable
(1 row)
2.修改當前會話預設的隔離級別:
highgo=# begin;
highgo=# set default_transaction_isolation='repeatable read';
sethighgo=# show transaction_isolation;
transaction_isolation
serializable
(1 row)
highgo=# show default_transaction_isolation;
default_transaction_isolation
repeatable read
(1 row)
highgo=# commit;
commit
highgo=# show transaction_isolation;
transaction_isolation
repeatable read
(1 row)
highgo=# show default_transaction_isolation;
default_transaction_isolation
read committed
(1 row)
highgo=# set default_transaction_isolation='repeatable read';
sethighgo=# show default_transaction_isolation;
default_transaction_isolation
repeatable read
(1 row)
highgo=# show transaction_isolation;
transaction_isolation
repeatable read
(1 row)
如果在事物中修改預設的隔離級別是不影響當前事物的。否則即時生效。
也可以在資料庫級別設定預設的隔離級別:
[highgo@db1 data]$ cat postgresql.conf |grep default_transaction_isolation
#default_transaction_isolation = 'read committed'
PostgreSQL的事務隔離分析
不懂的同學先補補概念 reference wiki 隔離級別 isolation levels 有四種隔離級別 昨天被問了乙個問題 當存在表test id int 並有id 1一條記錄,那麼以下兩種操作會有什麼行為 sessiona啟動事務後,sessionb做了更新id 2操作後,此時sessio...
postgresql中設定預設編碼
postgresql有兩個預設模板template0和template1,建立資料庫預設是以template1作為模板,兩個模板的區別是,如果以template0作為模板,可以自定義編碼,如下 create database db template template0問題似乎變得很明朗,想要改變po...
Postgresql 函式 事務隔離級別 實踐
過程大致意思 驗證 func 函式中依次呼叫 funca,funcb函式,三個函式中均有update操作,看看三個函式的select 是否可檢視未提交的update 表 create table public.audit id text collate pg catalog.default name...