Re: Lock for table renaming

Поиск
Список
Период
Сортировка
От Markus Schiltknecht
Тема Re: Lock for table renaming
Дата
Msg-id 4576DC1C.6040506@bluegap.ch
обсуждение исходный текст
Ответ на Lock for table renaming  (Peter Eisentraut <peter_e@gmx.net>)
Список pgsql-hackers
Hello Peter,

Peter Eisentraut wrote:
> Why does renaming a table take out an access exclusive lock on the target 
> table?  Isn't this just an UPDATE on a few system catalog rows.

I guess because system catalog updates are visible immediately? Try the 
following:

markus=# CREATE TABLE test (a INT);
CREATE TABLE
markus=# BEGIN;
BEGIN
markus=# SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
SET
markus=# INSERT INTO TEST (a) VALUES (1);
INSERT 0 1

Then switch to another terminal and rename the table by hand (to 
circumvent the lock):

markus=# UPDATE pg_class SET relname='gone' WHERE relname = 'test';
UPDATE 1

Go back to the first transaction and try to read from the table again:

markus=# SELECT * FROM test;
ERROR:  relation "test" does not exist

What works instead, is:

postgres=# SELECT * FROM gone; a
--- 1
(1 row)


AFAICT, that applies to both, READ COMMITTED as well as SERIALIZABLE. 
Please correct me if I'm wrong here.

Regards

Markus


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: SQL/PSM implemenation for PostgreSQL (roadmap)
Следующее
От: "Eric B. Ridge"
Дата:
Сообщение: Re: how to find index columns