Both databases support multiple levels of transaction isolation. Read their
docs to see how this affects concurrent transactions.
Well, actually I did read the docs before asking, I asked the question
to make sure, I understood them correctly.
The best way is to try to avoid locking altogether.
What would be the best way to do this?
I have to make a counter which would display the number of views of a
certain page. It has to be absolutely accurate even in case of multiple
users accessing the page (thus incrementing the counter)
simultaneously.
I could, of course, organise the counter as a separate table with users
adding a new row with the page_id of the accessed page on each view,
but wouldn't be adding hundreds/thousands of new rows, just to measure
the number of views, sort of overkill?
At least from reading the MySQL/PostgreSQL docs it seemed to me that
using postgres would get rid of the problem alltogether due to MVCC
You won’t have trouble in either database. Your best bet is simply ‘update pages set hits=hits+1’. This will obtain an exclusive row lock to do the update.
If you’re doing page = Page.find(…); page.hits += 1; page.save, you need to wrap it in a serialized transaction or lock the page record. Page.find(…, :lock => true)