Disclosure: I build Schemity , a desktop ERD tool - this post is from our blog and uses it for the examples.
TL;DR: The catalog answers half the question: a sequence attached to a column, used by a column default or by a BEGIN ATOMIC function cannot be dropped by accident, and PostgreSQL says so. A legacy default written as nextval('s'::text) , a function whose body is a string and application code record no dependency at all, so the drop succeeds and the next insert fails. Find those by searching defaults and function bodies, then watch last_value for a while before dropping anything.
You find unused sequences in PostgreSQL in two passes: the catalog tells you which sequences a column, a default or a function provably depends on, and a text search finds the callers the catalog never recorded. The second pass matters more than it looks.…