Re: Isolation of schema renames

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ben Leslie <benno(at)benno(dot)id(dot)au>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Isolation of schema renames
Date: 2017-08-10 02:14:47
Message-ID: 18536.1502331287@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ben Leslie <benno(at)benno(dot)id(dot)au> writes:
> I'm wondering if I can/should expect schema renames to be isolated.

Nope, you should not.

This is not an especially easy thing to fix, because to have the system
behave as you wish it did, your second transaction would have to be
ignoring already-committed DDL changes, and it is very easy to show
examples where that would be fatal. For example, consider

S1 S2

create table t (f1 int, f2 bigint);

begin;
insert into t values(42, 43); -- ok

begin;
alter table t add check (f1 < 100);
commit;

insert into t values(1000, 44); -- ok?

begin;
alter table t alter column f2 type int;
commit;

insert into t values(1, 100000000000); -- ok?
commit;

Now, in practice this specific example doesn't go through anyway, because
after its first insert, S2's transaction is holding a lock on t that
precludes the ALTER TABLE steps. But I only wrote it this way for
pedagogic purposes. If S2 had done some things but not touched t2 yet,
the concurrent ALTERs would succeed, and then S2 has no choice but to
respect the results of that DDL.

There are other ways we could define the results of this sort of thing,
but they generally would end up failing one or both of your transactions.
Letting it "just work" is not in the picture.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Munro 2017-08-10 02:34:37 Re: Isolation of schema renames
Previous Message Ben Leslie 2017-08-10 01:44:31 Isolation of schema renames