CREATE INDEX, the table will be locked for writes but not reads.
CREATE INDEX CONCURRENTLY to avoid write locks as well.
From the PostgreSQL docs on
When this option is used, PostgreSQL will build the index without
taking any locks that prevent concurrent inserts, updates, or deletes
on the table; whereas a standard index build locks out writes (but not
reads) on the table until it's done. There are several caveats to be
aware of when using this option — see Building Indexes Concurrently.
And more specifically (Like @ypercube commented):
PostgreSQL supports building indexes without locking out writes. This
method is invoked by specifying the
CONCURRENTLY option of
When this option is used, PostgreSQL must perform two scans of
the table, and in addition it must wait for all existing transactions
that could potentially use the index to terminate. Thus this method
requires more total work than a standard index build and takes
significantly longer to complete. However, since it allows normal
operations to continue while the index is built, this method is useful
for adding new indexes in a production environment.
Bold emphasis mine.