Re: Re: VACUUM is hanging - Mailing list pgsql-general

From Tom Lane
Subject Re: Re: VACUUM is hanging
Date
Msg-id 4278.989034847@sss.pgh.pa.us
Whole thread Raw
In response to Re: VACUUM is hanging  (Ashley Clark <aclark@ghoti.org>)
List pgsql-general
Ashley Clark <aclark@ghoti.org> writes:
>> Try not to leave open transactions hanging around in your Apache
>> code. An idle database connection couldn't block VACUUM like that;
>> it'd have to have been in the middle of a BEGIN block, or maybe even
>> an unfinished query.

> That appears to be the culprit. I don't really understand why an
> uncommitted SELECT statement could/should lock the table though. How
> does that differ from just an open transaction where no query has
> happened yet?

If you've just done BEGIN then you aren't holding any locks.  But having
done a SELECT, you have a read lock on that table, which will persist
until you commit or abort the transaction.  A read lock doesn't normally
prevent other transactions from doing things with the table --- but it
does block "exclusive" locks, which are obtained for actions like DROP
TABLE, ALTER TABLE, and VACUUM.  Those guys want to know that there
ain't no one messin' with that table.

            regards, tom lane

pgsql-general by date:

Previous
From: "David Wall"
Date:
Subject: Re: VACUUM is hanging
Next
From: "Muhammad Rusydi"
Date:
Subject: Re: how can i get plpgsql in function?