Is it possible to do an Online Index Rebuild in Postgresql

Is it possible to do an Online Index Rebuild in Postgresql or is your only option to do a drop and recreate? Thank you.


Solution 1:

To rebuild my_idx,

CREATE INDEX CONCURRENTLY new_my_idx ON my_table (my_column);
BEGIN;
DROP INDEX my_idx;
ALTER new_my_idx RENAME TO my_idx;
COMMIT;

With the usual caveats on CONCURRENTLY (it will take longer, as it must wait for any pending writes to finish, twice).