Re: Debugging deadlocks

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Guy Rouillier <guyr(at)masergy(dot)com>
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Debugging deadlocks
Date: 2005-03-28 13:47:21
Message-ID: 20050328134715.GA29581@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, Mar 27, 2005 at 06:02:25PM -0600, Guy Rouillier wrote:
> With the current implementation, it appears I need to either (1) always
> commit after every inserted row, or (2) single thread my entire insert
> logic. Neither of these two alternatives is very desirable. And it is
> only a partial fix (which will work in my case since I'm the only one
> updating this database.) In the general case though, where other
> programmers may be writing code that I may not even know about to update
> parts of this database, avoiding this type of deadlock becomes very
> difficult. It pretty much requires that everyone know what everyone
> else is doing.

The other possibility is to sort the rows on the foreign key as they
are inserted. Then the locks will always be taken in the same order and
hence can never deadlock.

Hope this helps,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Lonni J Friedman 2005-03-28 14:42:45 Re: pg_xlog disk full error, i need help
Previous Message Christopher Browne 2005-03-28 13:42:15 Re: Linux Filesystem for PG