Re: Locking for Rename To new_name works differently for different objects

From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Locking for Rename To new_name works differently for different objects
Date: 2014-10-16 04:37:10
Message-ID: CAA4eK1+Rpx5B4Xbsys7bSmG6hf=gez8x_a0c+6yptKxW-5GjHA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Oct 15, 2014 at 9:34 PM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
> On Wed, Oct 15, 2014 at 10:04 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> > Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> writes:
> >> I have observed that for renaming some of the objects
> >> AccessExclusiveLock is taken on object whereas for
> >> other kind of objects no lock is taken on object before
> >> renaming the object.
> >
> > The usual theory for DDL updates of all types (not just rename)
> > is that an explicit lock is only needed for objects whose catalog
> > representation comprises more than one row. Otherwise, the implicit
> > locking involved in updating that row is sufficient to serialize
> > different updates.

I am not sure if this rule is followed for all DDL's, as an example, I
tried to compare for FUNCTION and SCHEMA.

Function has entries in pg_proc, pg_depend (schema, language,
returntype, etc.), so by above theory any update should take explicit
lock which I think holds good whereas if we see for Schema, it has
entries in pg_namespace, pg_depend (owner), but it doesn't take
explicit lock during Rename.

Yet another anomaly is for "Comment on <Object> .." there is only
one row in pg_description, however it still takes explicit lock to
avoid concurrent activity which looks right to me.

> That's an interesting point that I hadn't considered, but I'm willing
> to believe that at least some of the differences might also be
> haphazard.

Yeah, I also think so, is it important enough that we spend energy to
find all such differences and fix them.

With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2014-10-16 05:05:21 Re: TODO : Allow parallel cores to be used by vacuumdb [ WIP ]
Previous Message Fujii Masao 2014-10-16 04:25:59 CREATE POLICY and RETURNING