Re: LOCK TABLE oddness in PLpgSQL function called via JDBC - Mailing list pgsql-jdbc

From Tom Lane
Subject Re: LOCK TABLE oddness in PLpgSQL function called via JDBC
Date
Msg-id 19799.1002061752@sss.pgh.pa.us
Whole thread Raw
In response to Re: LOCK TABLE oddness in PLpgSQL function called via JDBC  (Dave Harkness <daveh@MEconomy.com>)
Responses Re: LOCK TABLE oddness in PLpgSQL function called via  (Dave Harkness <daveh@MEconomy.com>)
List pgsql-jdbc
Dave Harkness <daveh@MEconomy.com> writes:
> Running in serializable mode, I'm getting a Postgres exception:
>      ERROR:  Can't serialize access due to concurrent update

Well, in that case my theory about it all being one transaction is
wrong; you couldn't get that error without a cross-transaction conflict.

> It seems to me that the table locks grabbed in the PLpgSQL function aren't
> actually locking the tables. They check to make sure they can *get* the
> lock, but don't actually hold the lock. Same with the select for update. It
> makes sure it can get the lock, but still lets others get the same lock.

Once a lock has been grabbed, the *only* way it can be let go is to
end the transaction.  So my new theory is that the JDBC driver is
issuing an auto-commit at points where you're not expecting it.

I'm not familiar enough with the behavior of "setAutoCommit" and friends
to be sure what's happening; but if you turn on query logging in the
server you'll probably see the evidence soon enough.

            regards, tom lane

pgsql-jdbc by date:

Previous
From: Tom Lane
Date:
Subject: Re: driver fails to handle strings in query statements properly
Next
From: Dave Harkness
Date:
Subject: Re: LOCK TABLE oddness in PLpgSQL function called via