ÖrnekNon-blocking Select for Update StatementsWhen the applications selects some rows for update, other processes are forced to wait for the transaction to end before they can get a hold of that lock.If the processing takes too long to complete, for whatever reason, other parts of the system might be blocked. This can be undesirable. We can use the select ... for update nowait statement to prevent blocking calls to our database. This query will error out if the rows are not available for selection.
Şöyle yaparız
process A: SELECT * FROM purchases WHERE processed = false;--- process B tries to select the data, but failsprocess B: SELECT * FROM purchases FOR UPDATE NOWAIT;process B: ERROR could not obtain lock on row in relation "purchases"process A: UPDATE purchases SET ...;
Hiç yorum yok:
Yorum Gönder