Home update a single record for 200 concurrent user in postgres
Reply: 1

update a single record for 200 concurrent user in postgres

Santosh Savan
Santosh Savan Published in 2017-12-07 13:15:47Z

I have a single record containing the version, initially 1. 200 concurrent users are updating the same record, every update version should increase by 1.if everything goes proper, then version must be 200.

I am unable to update the record properly.

Max connection pool size = 50
Database = Postgres

Could you please suggest? Thanks in Advance :)

Laurenz Albe
Laurenz Albe Reply to 2017-12-13 08:32:43Z

There is no need for anything complicated here, and no need for explicit transactions management.

All involved sessions just issue

UPDATE mytab
SET version=version+1
WHERE key=42
RETURNING version;

By default each statement runs in its own transaction, and these transactions will lock each other out with an exclusive lock on the row, so they will be serialized automatically.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.378237 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO