Why does adding a simple CHECK constraint take so long on Postgres
when creating the constraint, check pg_locks for granted  is false or pg_stat_activity for wait_event_type and wait_event where pid = &lt;pid that adds the check&gt; (note that these two columns are new in 9.6 - in earlier versions you see only the fact that it is waiting).

Most probably your ALTER TABLE was waiting for other process to release a lock before it could acquire exclusive one.