Re: COPY FROM and TABLE LOCK question

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Benjamin Franks <benjamin(at)dzhan(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: COPY FROM and TABLE LOCK question
Date: 2002-02-28 03:41:24
Message-ID: 10611.1014867684@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Benjamin Franks <benjamin(at)dzhan(dot)com> writes:
> does the copy from command do an exclusive access lock on the table it is
> writing to?

Certainly not. It gets the same kind of lock as INSERT does, viz
RowExclusiveLock.

> i'd like to do the following:
> --delete all rows from the table
> --drop table indexes
> --copy from the file to the table
> --recreate indexes

> however, i don't want other applications to try to select, insert, or
> update information from the table while the COPY FROM command is
> executing.

You will want to grab an explicit lock on the table. Generally, PG's
philosophy is to get the weakest allowable lock on a table. If you
want a stronger lock, you can grab it via a LOCK command before doing
whatever you want to do.

Dropping indexes requires an exclusive lock, so if you insist on the
above recipe then nothing less than exclusive lock will do.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2002-02-28 04:11:49 Re: sort mem size
Previous Message Frank Bax 2002-02-28 03:32:34 Re: About vacuuming