| From: | Markus Schiltknecht <markus(at)bluegap(dot)ch> | 
|---|---|
| To: | Peter Eisentraut <peter_e(at)gmx(dot)net> | 
| Cc: | pgsql-hackers(at)postgresql(dot)org | 
| Subject: | Re: Lock for table renaming | 
| Date: | 2006-12-06 15:05:00 | 
| Message-ID: | 4576DC1C.6040506@bluegap.ch | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Eric B. Ridge | 2006-12-06 15:05:36 | Re: how to find index columns | 
| Previous Message | Peter Eisentraut | 2006-12-06 15:02:14 | Re: SQL/PSM implemenation for PostgreSQL (roadmap) |