← all rules

set-access-method

error

SET ACCESS METHOD

Why it's unsafe

ALTER TABLE ... SET ACCESS METHOD rewrites the entire table and rebuilds its indexes under an ACCESS EXCLUSIVE lock when the access method changes, blocking all reads and writes for the rewrite.

Safe rewrite

There is no online way to change a table's access method. Do it in a maintenance window, or create a new table with the target access method, copy the data in batches, then swap (expand/contract).

Example

Try it in the playground →

Unsafe

ALTER TABLE events SET ACCESS METHOD heap2;

Related