Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2019 July PostgreSQL: Example of SERIALIZABLE Isolation Level

PostgreSQL: Example of SERIALIZABLE Isolation Level

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

THE SERIALIZABLE Isolation level is one kind of extended version of the REPEATABLE READ Isolation level.
Now with the SERIALIZABLE Isolation level, you cannot modify the data while another transaction is reading the same data.

For SELECT-only transactions, use the SERIALIZABLE isolation level when you do not want to see the other transaction commits during your transaction.

For UPDATE and DELETE transactions, SERIALIZABLE isolation prevents concurrent modification of the same data row; it should therefore be used with caution.

Create a table with few sample records:

1
2
3
4
5
6
7
8
9
10
CREATE TABLE tbl_Employee
(
EmpID INTEGER
,EmpName VARCHAR(50)
);
INSERT INTO tbl_Employee
VALUES
(1,'Anvesh'),(2,'Neevan')
,(3,'Roy'),(4,'Martin');

Execute in this current session. e.g. Session – A:

1
2
3
4
5
6
7
8
9
10
11
12
BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
 
UPDATE tbl_Employee SET EmpName ='Varlin' WHERE EmpID=4;
 
SELECT *FROM tbl_Employee;
 
empid | empname
-------+---------
1 | Anvesh
2 | Neevan
3 | Roy
4 | Varlin

Execute in anohter session, e.g. Session – B:

1
2
3
4
5
6
7
8
9
10
UPDATE tbl_Employee SET EmpName ='Loother' WHERE EmpID=3;
 
SELECT *FROM tbl_Employee;
 
empid | empname
-------+---------
1 | Anvesh
2 | Neevan
4 | Varlin
3 | Loother

Execute in anohter session, e.g. Session – C:

1
2
3
4
5
6
7
8
9
10
11
12
INSERT INTO tbl_Employee
VALUES (5,'Mahi');
 
SELECT *FROM tbl_Employee;
 
empid | empname
-------+---------
1 | Anvesh
2 | Neevan
4 | Martin
3 | Loother
5 | Mahi

Execute COMMIT on first Current Session – A:

1
2
3
4
5
6
7
8
9
10
11
12
13
--Nothing happen to this Query and Data is as it is.
 
SELECT *FROM tbl_Employee;
 
empid | empname
-------+---------
1 | Anvesh
2 | Neevan
3 | Roy
4 | Varlin
 
-- Now Execute COMMIT:
COMMIT TRANSACTION;

Jul 1, 2019Anvesh Patel
SQL Server: Script to check Network or Connect permission of UserDatabase Theory: What is CAP theorem - Consistency, Availability, Partition
Comments: 1
  1. dinesh
    July 2, 2019 at 2:56 am

    Anvesh good article would you write a articles on Postgresql recovery scenarios like controlfile loss and wal file loss or datafile corruption just like oracle has listed all recovery scenarios using rman..

    ReplyCancel

Leave a Reply Cancel reply

CAPTCHA
Refresh

*

Anvesh Patel
Anvesh Patel

Database Engineer

July 1, 2019 1 Comment PostgreSQLAnvesh Patel, Concurrency Control, database, database research and development, dbrnd, Isolation level, lock table, plpgsql, Postgres Query, postgresql, PostgreSQL Administrator, PostgreSQL Error, PostgreSQL Programming, PostgreSQL Tips and Tricks, SERIALIZABLE Isolation Level, transaction
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....