Re: Other queries locked out during long insert

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: "Joshua J(dot) Kugler" <joshua(at)eeinternet(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Other queries locked out during long insert
Date: 2008-12-17 10:53:54
Message-ID: 20081217105354.GB7501@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Dec 17, 2008 at 01:18:04AM -0900, Joshua J. Kugler wrote:
> I've read the Pg docs about MVCC and possible locks that indexes can
> create. Even so, I can't figure out why my code is causing all other
> queries to block while it is running. I'm reading data in from a file
> (line by line, its CSV), doing a little pre-processing, and inserting
> it into a table.

Normal updates and inserts indeed use MVCC, but TRUNCATE does not. It
takes an exclusive lock. If you want to be able to continue doing
queries you need to do a DELETE nistead of TRUNCATE.

Another common trick is to load into another table and then rename it
into place.

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while
> boarding. Thank you for flying nlogn airlines.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter Eisentraut 2008-12-17 10:58:11 Re: Other queries locked out during long insert
Previous Message Thomas Kellerer 2008-12-17 10:31:06 Re: A bit confused about Postgres Plus