Re: Is it safe to rename an index through pg_class update?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Kouber Saparev <kouber(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Is it safe to rename an index through pg_class update?
Date: 2020-02-27 15:52:36
Message-ID: 21995.1582818756@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Kouber Saparev <kouber(at)gmail(dot)com> writes:
> Renaming an index the classical way through "ALTER INDEX xxx RENAME TO yyy"
> needs an AccessExclusiveLock over the table holding the index (at least on
> 9.3 it does). Instead, couldn't I simply:

> UPDATE pg_class SET relname = 'yyy' WHERE oid = 'xxx'::regclass;

There's a lot of stuff like that that you can probably get away with...
but I'm not sure it's prudent to try it on valuable production data.
If it breaks your database nobody is going to have any sympathy for you.

FWIW, I can't immediately think of a reason this would cause a problem,
at least not on 9.4 and up which use MVCC catalog scans. If you're
really still on 9.3 then it's notably more risky. In any case, I've
not had any caffeine yet today, so this doesn't count for much.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2020-02-27 15:52:56 Re: Error “cache lookup failed for function”
Previous Message Iban Rodriguez 2020-02-27 15:30:56 Re: unexpected behavior with pglogical -- bug?