On Thu, Aug 18, 2016 at 5:05 PM, Samed YILDIRIM <samed(at)reddoc(dot)net> wrote:
> Hi Ravi,
>
> You can use CREATE INDEX with CONCURRENTLY keyword. It will not lock your
> table during the process.
>
> After which you would do:
ALTER TABLE tbl ADD PRIMARY KEY USING INDEX <index name from above>;
https://www.postgresql.org/docs/9.5/static/sql-altertable.html
See the note on the linked page advising this exact procedure.
David J.