Avoid dirty/phantom reads while selecting from database
I have two tables A and B.
My transactions are like this:
- Read -> read from table A
- Write -> write in table B, write in table A
I want to avoid dirty/phantom reads since I have multiple nodes making request to same database.
Here is an example:
- Transaction 1 - Update is happening on table B
- Transaction 2 - Read is happening on table A
- Transaction 1 - Update is happening on table A
- Transaction 2 - Completed
- Transaction 1 - Rollback
Now Transaction 2 client has dirty data. How should I avoid this?
sql database transactions informix dirtyread
|
show 2 more comments
I have two tables A and B.
My transactions are like this:
- Read -> read from table A
- Write -> write in table B, write in table A
I want to avoid dirty/phantom reads since I have multiple nodes making request to same database.
Here is an example:
- Transaction 1 - Update is happening on table B
- Transaction 2 - Read is happening on table A
- Transaction 1 - Update is happening on table A
- Transaction 2 - Completed
- Transaction 1 - Rollback
Now Transaction 2 client has dirty data. How should I avoid this?
sql database transactions informix dirtyread
which RDBMS are you using? SQL Server, Oracle, MySQL?
– Rich Benner
Nov 13 '18 at 8:26
informix now. planning to move to SQL server
– Raghunandan J
Nov 13 '18 at 8:37
Are you usingDIRTY READ
isolation level in Informix? In informix it is the only way to read uncommitted data.
– Luís Marques
Nov 13 '18 at 13:52
Dirty read is not recommended I wanted to know if there are any other solutions.
– Raghunandan J
Nov 13 '18 at 14:45
Informix has other isolation levels (there are restrictions depending on the type of database). Have you check the documentation? What you want is probablyCOMMITTED READ
orCOMMITTED READ LAST COMMITTED
.
– Luís Marques
Nov 13 '18 at 16:06
|
show 2 more comments
I have two tables A and B.
My transactions are like this:
- Read -> read from table A
- Write -> write in table B, write in table A
I want to avoid dirty/phantom reads since I have multiple nodes making request to same database.
Here is an example:
- Transaction 1 - Update is happening on table B
- Transaction 2 - Read is happening on table A
- Transaction 1 - Update is happening on table A
- Transaction 2 - Completed
- Transaction 1 - Rollback
Now Transaction 2 client has dirty data. How should I avoid this?
sql database transactions informix dirtyread
I have two tables A and B.
My transactions are like this:
- Read -> read from table A
- Write -> write in table B, write in table A
I want to avoid dirty/phantom reads since I have multiple nodes making request to same database.
Here is an example:
- Transaction 1 - Update is happening on table B
- Transaction 2 - Read is happening on table A
- Transaction 1 - Update is happening on table A
- Transaction 2 - Completed
- Transaction 1 - Rollback
Now Transaction 2 client has dirty data. How should I avoid this?
sql database transactions informix dirtyread
sql database transactions informix dirtyread
edited Nov 13 '18 at 23:19
Jonathan Leffler
561k896681018
561k896681018
asked Nov 13 '18 at 8:17
Raghunandan JRaghunandan J
152214
152214
which RDBMS are you using? SQL Server, Oracle, MySQL?
– Rich Benner
Nov 13 '18 at 8:26
informix now. planning to move to SQL server
– Raghunandan J
Nov 13 '18 at 8:37
Are you usingDIRTY READ
isolation level in Informix? In informix it is the only way to read uncommitted data.
– Luís Marques
Nov 13 '18 at 13:52
Dirty read is not recommended I wanted to know if there are any other solutions.
– Raghunandan J
Nov 13 '18 at 14:45
Informix has other isolation levels (there are restrictions depending on the type of database). Have you check the documentation? What you want is probablyCOMMITTED READ
orCOMMITTED READ LAST COMMITTED
.
– Luís Marques
Nov 13 '18 at 16:06
|
show 2 more comments
which RDBMS are you using? SQL Server, Oracle, MySQL?
– Rich Benner
Nov 13 '18 at 8:26
informix now. planning to move to SQL server
– Raghunandan J
Nov 13 '18 at 8:37
Are you usingDIRTY READ
isolation level in Informix? In informix it is the only way to read uncommitted data.
– Luís Marques
Nov 13 '18 at 13:52
Dirty read is not recommended I wanted to know if there are any other solutions.
– Raghunandan J
Nov 13 '18 at 14:45
Informix has other isolation levels (there are restrictions depending on the type of database). Have you check the documentation? What you want is probablyCOMMITTED READ
orCOMMITTED READ LAST COMMITTED
.
– Luís Marques
Nov 13 '18 at 16:06
which RDBMS are you using? SQL Server, Oracle, MySQL?
– Rich Benner
Nov 13 '18 at 8:26
which RDBMS are you using? SQL Server, Oracle, MySQL?
– Rich Benner
Nov 13 '18 at 8:26
informix now. planning to move to SQL server
– Raghunandan J
Nov 13 '18 at 8:37
informix now. planning to move to SQL server
– Raghunandan J
Nov 13 '18 at 8:37
Are you using
DIRTY READ
isolation level in Informix? In informix it is the only way to read uncommitted data.– Luís Marques
Nov 13 '18 at 13:52
Are you using
DIRTY READ
isolation level in Informix? In informix it is the only way to read uncommitted data.– Luís Marques
Nov 13 '18 at 13:52
Dirty read is not recommended I wanted to know if there are any other solutions.
– Raghunandan J
Nov 13 '18 at 14:45
Dirty read is not recommended I wanted to know if there are any other solutions.
– Raghunandan J
Nov 13 '18 at 14:45
Informix has other isolation levels (there are restrictions depending on the type of database). Have you check the documentation? What you want is probably
COMMITTED READ
or COMMITTED READ LAST COMMITTED
.– Luís Marques
Nov 13 '18 at 16:06
Informix has other isolation levels (there are restrictions depending on the type of database). Have you check the documentation? What you want is probably
COMMITTED READ
or COMMITTED READ LAST COMMITTED
.– Luís Marques
Nov 13 '18 at 16:06
|
show 2 more comments
1 Answer
1
active
oldest
votes
If your database is not logged, there is nothing you can do. By choosing an unlogged database, those who set it up decided this sort of issue was not a problem. The only way to fix the problem here is change the database mode to logged, but that is not something you do casually on a whim — there are lots of ramifications to the change.
Assuming your database is logged — it doesn't matter here whether it is buffered logging or unbuffered logging or (mostly) a MODE ANSI database — then unless you set DIRTY READ isolation, you are running using at least COMMITTED READ isolation (it will be Informix's REPEATABLE READ level, standard SQL's SERIALIZABLE level, if the database is MODE ANSI).
If you want to ensure that data rows do not change after a transaction has read them, you need to run at a higher isolation — REPEATABLE READ. (See SET ISOLATION in the manual for the details. (Beware of the nomenclature for SET TRANSACTION; there's a section of the manual about Comparing SET ISOLATION and SET TRANSACTION and related sections.) The downside to using SET ISOLATION TO REPEATABLE READ (or SET TRANSACTION ISOLATION LEVEL SERIALIZABLE) is that the extra locks needed reduce concurrency — but give you the best guarantees about the state of the database.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53276604%2favoid-dirty-phantom-reads-while-selecting-from-database%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If your database is not logged, there is nothing you can do. By choosing an unlogged database, those who set it up decided this sort of issue was not a problem. The only way to fix the problem here is change the database mode to logged, but that is not something you do casually on a whim — there are lots of ramifications to the change.
Assuming your database is logged — it doesn't matter here whether it is buffered logging or unbuffered logging or (mostly) a MODE ANSI database — then unless you set DIRTY READ isolation, you are running using at least COMMITTED READ isolation (it will be Informix's REPEATABLE READ level, standard SQL's SERIALIZABLE level, if the database is MODE ANSI).
If you want to ensure that data rows do not change after a transaction has read them, you need to run at a higher isolation — REPEATABLE READ. (See SET ISOLATION in the manual for the details. (Beware of the nomenclature for SET TRANSACTION; there's a section of the manual about Comparing SET ISOLATION and SET TRANSACTION and related sections.) The downside to using SET ISOLATION TO REPEATABLE READ (or SET TRANSACTION ISOLATION LEVEL SERIALIZABLE) is that the extra locks needed reduce concurrency — but give you the best guarantees about the state of the database.
add a comment |
If your database is not logged, there is nothing you can do. By choosing an unlogged database, those who set it up decided this sort of issue was not a problem. The only way to fix the problem here is change the database mode to logged, but that is not something you do casually on a whim — there are lots of ramifications to the change.
Assuming your database is logged — it doesn't matter here whether it is buffered logging or unbuffered logging or (mostly) a MODE ANSI database — then unless you set DIRTY READ isolation, you are running using at least COMMITTED READ isolation (it will be Informix's REPEATABLE READ level, standard SQL's SERIALIZABLE level, if the database is MODE ANSI).
If you want to ensure that data rows do not change after a transaction has read them, you need to run at a higher isolation — REPEATABLE READ. (See SET ISOLATION in the manual for the details. (Beware of the nomenclature for SET TRANSACTION; there's a section of the manual about Comparing SET ISOLATION and SET TRANSACTION and related sections.) The downside to using SET ISOLATION TO REPEATABLE READ (or SET TRANSACTION ISOLATION LEVEL SERIALIZABLE) is that the extra locks needed reduce concurrency — but give you the best guarantees about the state of the database.
add a comment |
If your database is not logged, there is nothing you can do. By choosing an unlogged database, those who set it up decided this sort of issue was not a problem. The only way to fix the problem here is change the database mode to logged, but that is not something you do casually on a whim — there are lots of ramifications to the change.
Assuming your database is logged — it doesn't matter here whether it is buffered logging or unbuffered logging or (mostly) a MODE ANSI database — then unless you set DIRTY READ isolation, you are running using at least COMMITTED READ isolation (it will be Informix's REPEATABLE READ level, standard SQL's SERIALIZABLE level, if the database is MODE ANSI).
If you want to ensure that data rows do not change after a transaction has read them, you need to run at a higher isolation — REPEATABLE READ. (See SET ISOLATION in the manual for the details. (Beware of the nomenclature for SET TRANSACTION; there's a section of the manual about Comparing SET ISOLATION and SET TRANSACTION and related sections.) The downside to using SET ISOLATION TO REPEATABLE READ (or SET TRANSACTION ISOLATION LEVEL SERIALIZABLE) is that the extra locks needed reduce concurrency — but give you the best guarantees about the state of the database.
If your database is not logged, there is nothing you can do. By choosing an unlogged database, those who set it up decided this sort of issue was not a problem. The only way to fix the problem here is change the database mode to logged, but that is not something you do casually on a whim — there are lots of ramifications to the change.
Assuming your database is logged — it doesn't matter here whether it is buffered logging or unbuffered logging or (mostly) a MODE ANSI database — then unless you set DIRTY READ isolation, you are running using at least COMMITTED READ isolation (it will be Informix's REPEATABLE READ level, standard SQL's SERIALIZABLE level, if the database is MODE ANSI).
If you want to ensure that data rows do not change after a transaction has read them, you need to run at a higher isolation — REPEATABLE READ. (See SET ISOLATION in the manual for the details. (Beware of the nomenclature for SET TRANSACTION; there's a section of the manual about Comparing SET ISOLATION and SET TRANSACTION and related sections.) The downside to using SET ISOLATION TO REPEATABLE READ (or SET TRANSACTION ISOLATION LEVEL SERIALIZABLE) is that the extra locks needed reduce concurrency — but give you the best guarantees about the state of the database.
answered Nov 14 '18 at 1:19
Jonathan LefflerJonathan Leffler
561k896681018
561k896681018
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53276604%2favoid-dirty-phantom-reads-while-selecting-from-database%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
which RDBMS are you using? SQL Server, Oracle, MySQL?
– Rich Benner
Nov 13 '18 at 8:26
informix now. planning to move to SQL server
– Raghunandan J
Nov 13 '18 at 8:37
Are you using
DIRTY READ
isolation level in Informix? In informix it is the only way to read uncommitted data.– Luís Marques
Nov 13 '18 at 13:52
Dirty read is not recommended I wanted to know if there are any other solutions.
– Raghunandan J
Nov 13 '18 at 14:45
Informix has other isolation levels (there are restrictions depending on the type of database). Have you check the documentation? What you want is probably
COMMITTED READ
orCOMMITTED READ LAST COMMITTED
.– Luís Marques
Nov 13 '18 at 16:06