postgresqltransaction-logpostgresql-16

postgresql merge into transaction logs


When I use the MERGE INTO statement in PostgreSQL 16 with the WHEN MATCHED THEN UPDATE SET option, will a transaction log only be created on difference, or even if it's the same value? Specifically, if I have 10 or so columns that get assigned, and only one of the values is different, will it just create the transaction log for that one value?

Some of this data is quite large, and I'm concerned about rapid disk space growth.


Solution

  • An UPDATE that doesn't change anything will still write a new version of the row and generate WAL for that. If you want to avoid that, there are two options:

    1. Add additional conditions that avoid the UPDATE if nothing changes.

    2. Use the built-in trigger function suppress_redundant_updates_trigger() with the updated table to skip unnecessary UPDATEs.