pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Torsten Förtsch <tfoertsch123@gmail.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: How to drop a value from an ENUM?
Date: Tue, 29 May 2018 17:09:14 -0400
Message-ID: <835.1527628154@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKkG4_=MMSFLd7RvUho4kStk-YDgHp96hAij_CQZV6xreWj-Rw@mail.gmail.com>
References: <CAKkG4_=MMSFLd7RvUho4kStk-YDgHp96hAij_CQZV6xreWj-Rw@mail.gmail.com>

=?UTF-8?Q?Torsten_F=C3=B6rtsch?= <tfoertsch123@gmail.com> writes:
> I am absolutely sure a certain value of one of my ENUM types is not used in
> the entire database. Now I am asked to drop that value. Unfortunately,
> there is no ALTER TYPE DROP VALUE.

Yup.

> On my development box I tried
> delete from pg_enum
>  where enumtypid='my_type_name'::regtype
>    and enumlabel='my_label'
> It worked and I could not find any adverse effects.
> Given the value is not used anywhere, is this a save command?

No.  If it were, we'd have an ALTER DROP VALUE command.

The key problem that is hard to fix here is that, even if today you have
no live rows containing that value, it may still be present in indexes.
In a btree, for example, the value might've migrated up into upper index
pages as a page boundary value.  Once that's happened, it's likely to
persist indefinitely, even if the live occurrences in the underlying table
get deleted and vacuumed away.

Now, even if that's happened, you might be okay, because of the
optimizations that typically allow enum value comparisons to be done
without consulting pg_enum.  But if you're in the habit of altering
enums, it's that much more likely that you would have done an ALTER TYPE
that defeats those optimizations; so I wouldn't rely on this.  Sooner
or later you're going to get burnt by complaints about an invalid enum
value (not sure of the exact wording) when you access certain parts
of the index.

You could maybe get around all of that by reindexing any indexes
containing the altered enum type after you're certain that all
entries of the unwanted enum value are dead and vacuumed away.
But it's not terribly safe.

			regards, tom lane




view thread (3+ messages)

Message-ID: <835.1527628154@sss.pgh.pa.us>
Permalink:  ../835.1527628154@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/835.1527628154@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, tfoertsch123@gmail.com
  Subject: Re: How to drop a value from an ENUM?
  In-Reply-To: <835.1527628154@sss.pgh.pa.us>
  References: <CAKkG4_=MMSFLd7RvUho4kStk-YDgHp96hAij_CQZV6xreWj-Rw@mail.gmail.com> <835.1527628154@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox