Re: Spurious failure to obtain row lock possible in PG 9.1?

From: "Albe Laurenz" <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "henk de wit *EXTERN*" <henk53602(at)hotmail(dot)com>, <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Spurious failure to obtain row lock possible in PG 9.1?
Date: 2012-09-25 10:48:30
Message-ID: D960CB61B694CF459DCFB4B0128514C20874BBFB@exadv11.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

henk de wit wrote:
> I'm using Postgres 9.1 on Debian Lenny and via a Java server (JBoss AS
6.1) I'm executing a simple
> "select ... for update" query:
>
>
> SELECT
>
> importing
>
> FROM
>
> customer
>
> WHERE
>
> id = :customer_id
>
> FOR UPDATE NOWAIT
>
>
> Once every 10 to 20 times Postgres fails to obtain the lock for no
apparent reason:
>
> 18:22:18,285 WARN [org.hibernate.util.JDBCExceptionReporter] SQL
Error: 0, SQLState: 55P03
> 18:22:18,285 ERROR [org.hibernate.util.JDBCExceptionReporter] ERROR:
could not obtain lock on row in
> relation "customer"
>
>
> I'm "pretty" sure there's really no other process that has the lock,
as I'm the only one on a test DB.
> If I execute the query immediately again, it does succeed in obtaining
the lock. I can however not
> reproduce this via e.g. PGAdmin.
>
>
> Is it possible or perhaps even known that PG has this behavior, or
should I look for the cause in the
> Java code? (I'm using Java EE"s entity manager to execute a native
query inside an EJB bean that lets
> a JDBC connection from a pool join a JTA transaction.)

There must be at least a second database connection that holds
locks on the objects you need.
Look in pg_stat_activity if you see other connections.

It is probably a race condition of some kind.

Turn on logging og connections and disconnections.
Set log_statement='all'

That way you should be able to see from the log entries
who issues what queries concurrently with you.

Yours,
Laurenz Albe

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Kiriakos Tsourapas 2012-09-25 11:01:10 Re: Postgres becoming slow, only full vacuum fixes it
Previous Message Mark Kirkwood 2012-09-24 23:08:34 Re: Postgres becoming slow, only full vacuum fixes it