Rename Index - Deadlock

Поиск
Список
Период
Сортировка
Искать

Rename Index - Deadlock

От:
Thomas Kenner <thomas.kenner@gmail.com>
Дата:
Hi,

Each day I'm recreating the index my_index of the table my_table. Therefore I 
create a new index my_index_new, drop the old index my_index, and rename the 
new index:
ALTER INDEX my_index_new RENAME TO my_index;

If an insert or select statement is run at the same time as the "ALTER INDEX 
... RENAME TO" statement, it will end up in a deadlock.

The index contains a foreign key (don't know if this information is 
important).

Is this a known issue?

Thanks, Thomas

-- 
Thomas Kenner

Re: Rename Index - Deadlock

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Thomas Kenner  writes:
> Each day I'm recreating the index my_index of the table my_table. Therefore I 
> create a new index my_index_new, drop the old index my_index, and rename the 
> new index:
> ALTER INDEX my_index_new RENAME TO my_index;

> If an insert or select statement is run at the same time as the "ALTER INDEX 
> ... RENAME TO" statement, it will end up in a deadlock.

I doubt it's the RENAME that's the problem, more likely the DROP of the
old index.  That has to get an exclusive lock on the parent table to be
sure there is nothing trying to use the index.

Why exactly do you feel you need to do this every day?
		regards, tom lane

Re: Rename Index - Deadlock

От:
Scott Marlowe <scott.marlowe@gmail.com>
Дата:
On Tue, Mar 16, 2010 at 3:45 AM, Thomas Kenner  wrote:
> Hi,
>
> Each day I'm recreating the index my_index of the table my_table. Therefore I
> create a new index my_index_new, drop the old index my_index, and rename the
> new index:
> ALTER INDEX my_index_new RENAME TO my_index;
>
> If an insert or select statement is run at the same time as the "ALTER INDEX
> ... RENAME TO" statement, it will end up in a deadlock.

A deadlock or just a lock?  What version of pg?  What exact error
messages do you get?

FAQ