Обсуждение: PL/pgsql locking policy

Поиск
Список
Период
Сортировка

PL/pgsql locking policy

От
Richard Emberson
Дата:
If you have a PL/pgsql procedure that first reads from a given table to
verify a condition and
then if the condition is true write to that same table ... and at the
same time you want other
processes to be able to simply read from the table, what is the best
locking policy within the procedure?

While ACCESS EXCLUSIVE MODE prevents others from reading.
allowing other to read means that two process might be concurrently
reading (verifying) within
the procedure, reach the same condition value, and then both attempt to
write data.

Is it better to simply have a helper table, a table created just for
this one procedure, the only mechanism
where writing to the table actually occurs, and use this helper table as
the locking mechanism.

Richard


Re: PL/pgsql locking policy

От
Tom Lane
Дата:
Richard Emberson <emberson@phc.net> writes:
> If you have a PL/pgsql procedure that first reads from a given table to
> verify a condition and
> then if the condition is true write to that same table ... and at the
> same time you want other
> processes to be able to simply read from the table, what is the best
> locking policy within the procedure?

You could use EXCLUSIVE lock mode, which blocks everything except SELECT.

            regards, tom lane