Skip to content

Instantly share code, notes, and snippets.

@mohanraj-nagasamy
Last active May 18, 2016 04:36
Show Gist options
  • Save mohanraj-nagasamy/77473876fcafd0979410 to your computer and use it in GitHub Desktop.
Save mohanraj-nagasamy/77473876fcafd0979410 to your computer and use it in GitHub Desktop.
Transactional Locks in DBs

TX1

BEGIN ;
UPDATE banks SET balance = 100 WHERE id = 825;

TX2

BEGIN ;
UPDATE banks SET balance = 201 WHERE id = 824;
UPDATE banks SET balance = 200 WHERE id = 825;

TX1

UPDATE banks SET balance = 101 WHERE id = 824;

Tables to look at

SELECT  * from pg_stat_activity;
SELECT  * from pg_locks;
select 1460461::regclass;

Look at current isolation

SHOW transaction_isolation; OR --select current_setting('transaction_isolation')
SHOW ALL; --Displays all the settings

Set tx

SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;

Resource

MySql

Isolaction levels

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment