There is definitely some other process competing for the same resource. This is the nature of the impasse. A function like the one displayed can never slow down. See a comment from @kgrittn below , which is a PostgreSQL concurrency expert.
Your version of PostgreSQL is missing. In modern versions, a detailed error message appears. Both processes that compete for resources are listed in detail with standard logging settings. Check your magazine logs.
The fact that you catch an error can prevent Postgres from giving you complete information. Remove the EXCEPTION block from your plpgsql function if you don't get the db log information and try again.
There are a few things you can do to ease deadlocks. If all your clients access resources in a synchronized manner, deadlocks cannot occur. The guide contains the basic strategy for dealing with most cases in the chapter on deadlocks .
As for version 8.3 : consider the possibility of switching to a newer version. In particular, this improvement in version 8.4 should be interesting for you ( quoting the release notes ):
When reporting a deadlock, provide the text of all queries related to the deadlock to the server log (Itagaki Takahiro)
In addition, version 8.3 will meet the end of life in February 2013 . You should start reviewing the update.
The final situation with VACUUM should have been corrected in 8.3.1 .
Erwin brandstetter
source share