Re: COPY FROM and TABLE LOCK question - Mailing list pgsql-general

From Tom Lane
Subject Re: COPY FROM and TABLE LOCK question
Date
Msg-id 10611.1014867684@sss.pgh.pa.us
Whole thread Raw
In response to COPY FROM and TABLE LOCK question  (Benjamin Franks <benjamin@dzhan.com>)
List pgsql-general
Benjamin Franks <benjamin@dzhan.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

pgsql-general by date:

Previous
From: Frank Bax
Date:
Subject: Re: About vacuuming
Next
From: Bruce Momjian
Date:
Subject: Re: sort mem size