A
A
Alexander Bardin2019-04-02 14:05:16
PostgreSQL
Alexander Bardin, 2019-04-02 14:05:16

How to properly organize concurrent data access?

The bottom line is that the data can be edited by N users, but in fact the ideal option is that the one who first opened the record edits it, the rest can open the record only for viewing.
perhaps there is already such a bike (you can write your own, but I don’t think I’m the only one who has come across this), or perhaps there is a more correct solution and approach to this problem

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ruslan., 2019-04-02
@LaRN

We solved a similar problem as follows: We
created a table into which an object is entered when it is raised for editing. All other users, when trying to edit this object, receive a message that the user "such and such" is already editing it and the form rises in read-only mode.
When the first user closes the form with the object, the record is removed from the table and the object can be edited by another user.
Sometimes there were failures (for example, a disconnect) and the user who opened the object for editing could not correctly release the object being edited. In this case, if the object is in the editable table, but the process with its spid and username is not on the SQL server, we forcibly delete the object from the editable table.
Without such a mechanism, inconsistencies of the form were periodically scored: "I changed the object, saved it, raised it for viewing, and it's different."

S
Stanislav Makarov, 2019-04-02
@Nipheris

The bottom line is that the data can be edited by N users, but in fact the ideal option is that the one who first opened the record edits it, the rest can open the record only for viewing.

The approach you describe is called pessimistic locking. I propose to search for this term as this is implemented.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question