Sample Header Ad - 728x90

How do you test for race conditions in a database?

37 votes
5 answers
9535 views
I try to write database code to make sure that it's not subject to race conditions, to make sure that I've locked the correct rows or tables. But I often wonder: Is my code correct? Is it possible to force any existing race conditions to manifest? I want to be sure that if they do happen in a production environment my application will do the right thing. I generally know exactly which concurrent query is likely to cause a problem, but I've no idea how to force them to run concurrently to see if the correct behavior happens (e.g. I used the correct type of lock), that the right errors are thrown, etc. *Note: I use PostgreSQL and Perl, so if this can't be answered generically it should probably get retagged as such.* ***Update:** I'd prefer it if the solution was programmatic. That way I can write automated tests to make sure there aren't regressions.*
Asked by xenoterracide (2921 rep)
Jan 4, 2011, 11:30 AM
Last activity: Jan 7, 2024, 01:54 PM