Обсуждение: Deadlock when one process opens two separate connections?

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

Deadlock when one process opens two separate connections?

От
Kaloyan Iliev
Дата:
Hi,

Yestarday in the software, which my company developes, there happens a
deadlock.
One process opens a transaction, SELECT FOR UPDATE some rows from a
table and then calls another function.
The second function didn't receive (by programmers mistake) database
handler and opens its own transaction and try to modify the same rows.
And in this moment the second transaction WAITS. The first transaction
cannot finish because waits for result from the second
and the second transaction cannot modify the rows because the first
SELECT FOR UPDATE them. In this case the process hangs for 2 hours
when I restart the database. So why didn't the data base discover the
deadlock and cancel one of the transactions?
Probbly beacause both transactions started from one process?
And as second question I look carefuly over the code and select for
update was called on one table of a complex query but for me it seems to
block all
result rows from all tables. I am not absolutely sure about this but I
will make some test and post the result if I prove there is a problem.
We use version:
                                             version
------------------------------------------------------------------------------------------------
 PostgreSQL 8.1.4 on i386-portbld-freebsd6.1, compiled by GCC cc (GCC)
3.4.4 [FreeBSD] 20050518

Kaloyan Iliev

Re: Deadlock when one process opens two separate connections?

От
Florian Weimer
Дата:
* Kaloyan Iliev:

> Probbly beacause both transactions started from one process?

Yes, the deadlock detector isn't psychic.  It can't know about lock
ordering constraints which are external to PostgreSQL.

--
Florian Weimer                <fweimer@bfk.de>
BFK edv-consulting GmbH       http://www.bfk.de/
Durlacher Allee 47            tel: +49-721-96201-1
D-76131 Karlsruhe             fax: +49-721-96201-99