Diagnostic Queries
Symptoms
A newly added enum value was used in the same transaction that added it, which is unsafe. PostgreSQL raises SQLSTATE 55P04 (unsafe_new_enum_value_usage).
- A value added by
ALTER TYPE … ADD VALUEwas used before commit. - New enum values can’t be used in the same transaction (in some cases).
- Common in migrations that add and then use a value.
What the server log shows
ERROR: unsafe use of new value "shipped" of enum type order_status
HINT: New enum values must be committed before they can be used.
Why PostgreSQL raises this — what the manual says
the ALTER TYPE reference (Notes):
“ADD VALUE (the form that adds a new value to an enum type) is executed inside a transaction block, the new value cannot be used until after the transaction has been committed.”
Adding an enum value writes catalog state that other parts of the system rely on being committed before the value can be safely compared/stored. Using it within the same uncommitted transaction risks inconsistency, so PostgreSQL reports 55P04.
Common causes
- Adding an enum value and inserting/using it in one transaction.
- A migration that combines ADD VALUE with data changes.
How to fix it
- Commit the
ADD VALUEfirst, then use the value in a separate transaction. - Split migrations so enum additions are committed before use.
- Run
ALTER TYPE … ADD VALUEoutside the data-loading transaction.
Related & next steps
Reference: PostgreSQL 18 — ALTER TYPE.
Thanks — noted. This helps keep the database accurate.