dataset lock

Поиск
Список
Период
Сортировка
От Philipp Kraus
Тема dataset lock
Дата
Msg-id 42C39C32-BB5D-4FFB-9121-3B4709671EFE@flashpixx.de
обсуждение исходный текст
Ответы Re: dataset lock
Список pgsql-general
Hello,

I use a PG database on a HPC system (cluster). My processes get a dataset from the database and change the row, each
processis independend. 
My table shows something like: id, status, data

id = PK a unqiue number
status a enum value which "open", "waiting", "working", "done"

So each process calls a SQL statement select * from where status = "waiting", so the process should get the next
waitingtask, after the process 
gets the task, the status should be changed to "working", so no other process shouldn't get the task. My processes are
independed,so it can 
be, that 2 (or more) processes call the select statement at the same time and get in this case equal tasks, so I need
somelocking. How can 
I do this with Postgres, that each row / task in my table is read / write by one process. On threads I would create a
mutexeg: 

lock()
row = select * from table where status = waiting
update status = working from table where id = row.id
unlock()

do something with row

Which is the best solution with postgres? should I create a procedure which takes the next job, change it and returns
theid, so each process 
calls "select getNextJob()" ?

Thanks

Phil



В списке pgsql-general по дате отправления:

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: Role Authentication Failure
Следующее
От: Nigel Heron
Дата:
Сообщение: Re: currval and DISCARD ALL