Enums

ALTER TYPE ... ADD VALUE

PostgreSQL 12+

Lock mode EXCLUSIVE
Risk LOW
Blocks writes, other DDL
pgfence rule alter-enum-add-value
ALTER TYPE order_status ADD VALUE 'refunded';

What this does

The lock is on the type object itself, not on any table that uses the enum, so no table is blocked. Instant on PostgreSQL 12 and later, but the new value cannot be used in the same transaction that added it: using it immediately raises 'unsafe use of new value.'

Safe rewrite

Commit the ADD VALUE before inserting rows that use the new value

-- COMMIT after ADD VALUE, then use the new value in a later transaction.
-- Using it in the same transaction raises: unsafe use of new value "refunded" of enum type order_status

Read more

More in Enums