Skip to content

benaco/pg_silence_serialization_40001_errors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pg_silence_serialization_40001_errors

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.

Building

Requires a PostgreSQL development installation (headers and pg_config).

make PG_CONFIG=/path/to/pg_config

This produces pg_silence_serialization_40001_errors.so (e.g. on Linux, or .dylib on macOS).

Installation

Copy the .so into PostgreSQL's lib directory:

make PG_CONFIG=/path/to/pg_config install

Then add to postgresql.conf:

shared_preload_libraries = 'pg_silence_serialization_40001_errors'

Restart PostgreSQL for the change to take effect.

Nix

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
]);

Testing

A NixOS VM test is included in nixos-vm-test.nix. It provokes real serialization failures.

nix-build nixos-vm-test.nix
ls result/

Compatibility

Tested with PostgreSQL 14. The emit_log_hook API has been stable across PostgreSQL versions, so it should work with other versions as well.

License

Public domain / CC0 1.0.

About

A minimal PostgreSQL extension that suppresses SQLSTATE `40001` (`serialization_failure`) messages from the server log.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors