Re: Doubt about AccessExclusiveLock in ALTER TABLE .. SET ( .. );

From: Fabrízio de Royes Mello <fabriziomello(at)gmail(dot)com>
To: Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>
Cc: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Doubt about AccessExclusiveLock in ALTER TABLE .. SET ( .. );
Date: 2015-03-31 13:11:19
Message-ID: CAFcNs+rv1JT77i1S1GH+odzTGOE_vC33NF9rqE_XUqF2vP2iQw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Mar 30, 2015 at 8:14 PM, Fabrízio de Royes Mello <
fabriziomello(at)gmail(dot)com> wrote:
>
>
>
> On Mon, Mar 30, 2015 at 7:41 PM, Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>
wrote:
> >
> > On 3/27/15 2:23 PM, Fabrízio de Royes Mello wrote:
> >>
> >> Hi all,
> >>
> >> I'm tweaking some autovacuum settings in a table with high write usage
> >> but with ALTER TABLE .. SET ( .. ) this task was impossible, so I did a
> >> catalog update (pg_class) to change reloptions.
> >>
> >> Maybe it's a stupid doubt, but why we need to get an
AccessExclusiveLock
> >> on relation to set reloptions if we just touch in pg_class tuples
> >> (RowExclusiveLock) ?
> >
> >
> > For a very long time catalog access was not MVCC safe. I think that's
been changed, so at this point it may be OK to relax the lock, at least in
the case of autovac settings. There may well be other settings in there
where it would not be safe.
> >
>
> Hummm.... There are a comment in AlterTableGetLockLevel:
>
> 3017 /*
> 3018 * Rel options are more complex than first appears.
Options
> 3019 * are set here for tables, views and indexes; for
historical
> 3020 * reasons these can all be used with ALTER TABLE,
so we can't
> 3021 * decide between them using the basic grammar.
> 3022 *
> 3023 * XXX Look in detail at each option to determine
lock level,
> 3024 * e.g. cmd_lockmode = GetRelOptionsLockLevel((List
*)
> 3025 * cmd->def);
> 3026 */
> 3027 case AT_SetRelOptions: /* Uses MVCC in
getIndexes() and
> 3028 * getTables() */
> 3029 case AT_ResetRelOptions: /* Uses MVCC in
getIndexes() and
> 3030 * getTables() */
> 3031 cmd_lockmode = AccessExclusiveLock;
> 3032 break;
>
>
> Maybe it's time to implement "GetRelOptionsLockLevel" to relax the lock
to autovac settings (AccessShareLock). To other settings we continue using
AccessExclusiveLock.
>
> There are some objection to implement in that way?
>

Attached a very WIP patch to reduce lock level when setting autovacuum
reloptions in "ALTER TABLE .. SET ( .. )" statement.

I confess the implementation is ugly, maybe we should add a new item to
reloptions constants in src/backend/access/common/reloptions.c and a proper
function to get lock level by reloption. Thoughts?

Regards,

--
Fabrízio de Royes Mello
Consultoria/Coaching PostgreSQL
>> Timbira: http://www.timbira.com.br
>> Blog: http://fabriziomello.github.io
>> Linkedin: http://br.linkedin.com/in/fabriziomello
>> Twitter: http://twitter.com/fabriziomello
>> Github: http://github.com/fabriziomello

Attachment Content-Type Size
wip_alter-table-set-reduce-lock-level-for-autovac-reloptions.patch text/x-diff 1.7 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Stephen Frost 2015-03-31 13:12:52 Re: Permission select pg_stat_replication
Previous Message Amit Kapila 2015-03-31 12:53:29 Re: Parallel Seq Scan