SERIALIZABLE

가장 높은 격리 수준(6)으로서, 더티 읽기, 반복 불가능한 읽기, 유령 읽기 등의 동시성 관련 문제가 발생하지 않는다.

다음과 같은 규칙이 적용된다.

이 격리 수준은 공유 잠금 및 배타 잠금 모두 2단계 잠금 프로토콜을 따르므로, 연산이 수행되더라도 해당 트랜잭션이 종료될 때까지 잠금이 유지된다.

예제

다음은 동시에 수행되는 트랜잭션의 격리 수준이 SERIALIZABLE인 경우 한 트랜잭션에서 객체 읽기 또는 객체 갱신을 수행하는 동안 다른 트랜잭션이 테이블 또는 레코드에 접근할 수 없음을 보여주는 예제이다.

session 1

session 2

;autocommit off

AUTOCOMMIT IS OFF

 

SET TRANSACTION ISOLATION LEVEL 6

;xr

 

Isolation level set to:

SERIALIZABLE

;autocommit off

AUTOCOMMIT IS OFF

 

SET TRANSACTION ISOLATION LEVEL 6

;xr

 

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;

;xr

 

 

--selecting records from the table

SELECT * FROM isol6_tbl WHERE nation_code = 'AUS';

;xr

 

=== <Result of SELECT Command> ===

    host_year  nation_code

===================================

         2008  'AUS'

 

1 rows selected.

INSERT INTO isol6_tbl VALUES (2004, 'AUS');

;xr

 

/* unable to insert a row until the tran 2 committed */

 

1 rows affected.

COMMIT;

;xr

 

SELECT * FROM isol6_tbl WHERE nation_code = 'AUS';

;xr

 

/* unable to select rows until tran 1 committed */

COMMIT;

;xr

=== <Result of SELECT Command> ===

    host_year  nation_code

===================================

         2008  'AUS'

         2004  'AUS'

 

2 rows selected.

DELETE FROM isol6_tbl

WHERE nation_code = 'AUS' and

host_year=2008;

;xr

 

/* unable to delete rows until tran 2 committed */

 

1 rows affected.

 

1 command(s) successfully processed.

COMMIT;

;xr

 

SELECT * FROM isol6_tbl WHERE nation_code = 'AUS';

;xr

 

/* unable to select rows until tran 1 committed */

COMMIT;

;xr

=== <Result of SELECT Command> ===

    host_year  nation_code

===================================

         2004  'AUS'

 

1 rows selected.

ALTER TABLE isol6_tbl

ADD COLUMN gold INT;

;xr

 

/* 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';

;xr

 

=== <Result of SELECT Command> ===

    host_year  nation_code

===================================

         2004  'AUS'

 

1 rows selected.

1 command(s) successfully processed.

COMMIT;

;xr

 

SELECT * FROM isol6_tbl WHERE nation_code = 'AUS';

;xr

 

/* unable to access the table until tran_1 committed */

COMMIT;

;xr

=== <Result of SELECT Command > ===

host_year  nation_code  gold

===================================

  2004  'AUS'           NULL

 

1 rows selected.