가장 높은 격리 수준(6)으로서, 더티 읽기, 반복 불가능한 읽기, 유령 읽기 등의 동시성 관련 문제가 발생하지 않는다.
다음과 같은 규칙이 적용된다.
이 격리 수준은 공유 잠금 및 배타 잠금 모두 2단계 잠금 프로토콜을 따르므로, 연산이 수행되더라도 해당 트랜잭션이 종료될 때까지 잠금이 유지된다.
다음은 동시에 수행되는 트랜잭션의 격리 수준이 SERIALIZABLE인 경우 한 트랜잭션에서 객체 읽기 또는 객체 갱신을 수행하는 동안 다른 트랜잭션이 테이블 또는 레코드에 접근할 수 없음을 보여주는 예제이다.
session 1 |
session 2 |
---|---|
;autocommit off AUTOCOMMIT IS OFF
SET TRANSACTION ISOLATION LEVEL 6;
Isolation level set to: SERIALIZABLE |
;autocommit off AUTOCOMMIT IS OFF
SET TRANSACTION ISOLATION LEVEL 6;
Isolation level set to: SERIALIZABLE |
--creating a table
CREATE TABLE isol6_tbl(host_year integer, nation_code char(3));
INSERT INTO isol6_tbl VALUES (2008, 'AUS');
COMMIT; |
|
|
--selecting records from the table SELECT * FROM isol6_tbl WHERE nation_code = 'AUS'; host_year nation_code =================================== 2008 'AUS' |
INSERT INTO isol6_tbl VALUES (2004, 'AUS'); /* unable to insert a row until the tran 2 committed */ |
|
|
COMMIT; |
|
SELECT * FROM isol6_tbl WHERE nation_code = 'AUS';
/* unable to select rows until tran 1 committed */ |
COMMIT; |
host_year nation_code =================================== 2008 'AUS' 2004 'AUS' |
DELETE FROM isol6_tbl WHERE nation_code = 'AUS' and host_year=2008; /* unable to delete rows until tran 2 committed */ |
|
|
COMMIT; |
|
SELECT * FROM isol6_tbl WHERE nation_code = 'AUS'; /* unable to select rows until tran 1 committed */ |
COMMIT; |
host_year nation_code =================================== 2004 'AUS' |
ALTER TABLE isol6_tbl ADD COLUMN gold INT;
/* unable to alter the table schema until tran 2 committed */ |
/* repeatable read is ensured while tran_1 is altering table schema */
SELECT * FROM isol6_tbl WHERE nation_code = 'AUS'; host_year nation_code =================================== 2004 'AUS' |
|
COMMIT; |
|
SELECT * FROM isol6_tbl WHERE nation_code = 'AUS';
/* unable to access the table until tran_1 committed */ |
COMMIT; |
host_year nation_code gold =================================== 2004 'AUS' NULL |