postgresqlvacuum

Is it always possible to UPDATE a database after a VACUUM FREEZE?


If I do a VACUUM FREEZE on a database, is it always possible to update the frozen rows in the database? Or is VACUUM FREEZE very dangerous because the rows become immutable? That would be a disaster in production!


Solution

  • You completely misunderstand what “freezing” is in PostgreSQL. It has nothing to do with making a row read-only. Rather, when a row is frozen, a flag is set on the row that tells the reader that this row is “old and visible” and the reader shouldn't bother to check the xmin and xmax system columns of the row to determine if it can see the row or not. This is necessary, because the transaction IDs stored in xmin and xmax will “wrap around” after a while (they are 4 byte unsigned integers), and that would cause data corruption unless old rows have been frozen before that happens.

    There is usually no point in running VACUUM (FREEZE) on a table unless you know that the data in the table are not going to be updated or deleted in the future. Otherwise, freezing rows that will get modified later will cause unnecessary writes (since freezing a row makes a buffer dirty), which is bad for performance.