From: Kris Jurka <books@ejurka.com>
To: Vit Timchishin <tivv@gtech-ua.com>
Cc: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: Re: Deadlock problem
Date: Mon, 21 Nov 2005 18:06:37 -0500 (EST)
Message-ID: <Pine.BSO.4.61.0511211801550.23994@leary.csoft.net> (raw)
In-Reply-To: <200511211409.000000EG@dev-null>
References: <200511211409.000000EG@dev-null>
On Mon, 21 Nov 2005, Vit Timchishin wrote:
> I am not using one connection and at the time of block there is only one
> active query (that is locked) at the whole database (in my test case).
> But for one transaction it may be used by different java threads (e.g.
> main thread and finalizer) and it seems that this is producing problems
> because exclusive lock is held after statement have finished. It is
> possible that I am still having open resultsets (did not check), but
> they are all forward only and not updateable.
>
Locks are always held until transaction commit, not the end of an
individual statement. So, while you may only have one statement executing
you have more than one transaction in progress and this is causing your
deadlocks. Consider a table with a primary key:
CREATE TABLE t(a int primary key);
Connection 1:
BEGIN;
INSERT INTO t VALUES (1);
Connection 2:
BEGIN;
INSERT INTO t VALUES (1);
Connection 2 must wait for connection 1 to either commit or rollback
before it knows whether it can legally insert its value. This is true
even if connection 1 performed its insert a week ago, the transaction is
still in doubt even if the statement has completed running.
Kris Jurka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: books@ejurka.com, tivv@gtech-ua.com
Subject: Re: Deadlock problem
In-Reply-To: <Pine.BSO.4.61.0511211801550.23994@leary.csoft.net>
References: <200511211409.000000EG@dev-null> <Pine.BSO.4.61.0511211801550.23994@leary.csoft.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox