Adding a primary key constraint requires an
ACCESS EXCLUSIVE lock that will block all reads and writes to the table while the primary key index is built.
Instead of creating the constraint directly, create the
USING an index.
The index will be created in the background and an
ACCESS EXCLUSIVE lock will only be acquired when updating the table metadata with the
ADD CONSTRAINT ... USING statement. See "disallowed-unique-constraint" for more examples.