A minimal PostgreSQL extension that suppresses SQLSTATE 40001 (serialization_failure) messages from the server log.
When using SERIALIZABLE transaction isolation, serialization failures are expected and applications must detect and retry them (see PostgreSQL docs on transaction isolation). Because these errors can occur very frequently under contention, logging each one at ERROR level creates noise and can fill up disk space. This extension suppresses only the server-side log entry; the error is still returned to the client as usual.
The extension is 2 lines of real logic. It uses PostgreSQL's emit_log_hook to intercept log messages and set output_to_server = false for SQLSTATE 40001.
Requires a PostgreSQL development installation (headers and pg_config).
make PG_CONFIG=/path/to/pg_configThis produces pg_silence_serialization_40001_errors.so (e.g. on Linux, or .dylib on macOS).
Copy the .so into PostgreSQL's lib directory:
make PG_CONFIG=/path/to/pg_config installThen add to postgresql.conf:
shared_preload_libraries = 'pg_silence_serialization_40001_errors'Restart PostgreSQL for the change to take effect.
For reproducible builds with Nix, see default.nix.
To bundle it into a PostgreSQL package with the extension included:
postgresql_with_extension = postgresql_14.withPackages (_: [
pg_silence_serialization_40001_errors
]);A NixOS VM test is included in nixos-vm-test.nix.
It provokes real serialization failures.
nix-build nixos-vm-test.nix
ls result/Tested with PostgreSQL 14. The emit_log_hook API has been stable across PostgreSQL versions, so it should work with other versions as well.
Public domain / CC0 1.0.