Given a table
bar that we need to compact while maximizing availability of the data in it and minimize load/IO during compaction.
First, if there are any tables with foriegn key columns referencing columns in bar those foreign keys need to be disabled, e.g:
ALTER TABLE foo DISABLE TRIGGER fkey_bar_id
Now we can work on compacting the data by copying it to a new table.
SQL to create a new, empty table and have the current table inherit from it: