PostgreSQL extra_float_digits log spam

Torbjørn Kristoffersen
2 min readMar 30, 2016

--

If you are using PostgreSQL with JDBC, you may have noticed a lot of log entries such as these:

LOG: duration: 0.256 ms parse <unnamed>: SET extra_float_digits = 3
LOG: duration: 0.018 ms bind <unnamed>: SET extra_float_digits = 3
LOG: duration: 0.016 ms execute <unnamed>: SET extra_float_digits = 3
LOG: duration: 0.160 ms parse <unnamed>: SET extra_float_digits = 3
LOG: duration: 0.018 ms bind <unnamed>: SET extra_float_digits = 3
LOG: duration: 0.014 ms execute <unnamed>: SET extra_float_digits = 3
LOG: duration: 0.225 ms parse <unnamed>: SET extra_float_digits = 3
LOG: duration: 0.015 ms bind <unnamed>: SET extra_float_digits = 3
LOG: duration: 0.013 ms execute <unnamed>: SET extra_float_digits = 3

Fairly annoying. On my system these entries were nearly 10% of the total log files.

In PostgreSQL <9.0 this was required, in order to ensure the float precision was correct.

But since PostgreSQL 9.0 it’s possible to send this information in the startup packet. There is a way to tell the JDBC driver to do this by using the assumeMinServerVersion connection parameter.

According to the PostgreSQL manual:

assumeMinServerVersion = String

Assume that the server is at least the given version, thus enabling to some optimization at connection time instead of trying to be version blind.

And the JDBC source code for the startup :

String sql = “begin; set autocommit = on; set client_encoding = ‘UTF8’; “; 
if (dbVersion.compareTo(“9.0”) >= 0) {
sql += “SET extra_float_digits=3; “;
} else if (dbVersion.compareTo(“7.4”) >= 0) {
sql += “SET extra_float_digits=2; “;
}
sql += “commit”;

In other words, we can add the property like this:

String url = “jdbc:postgresql://localhost/test?user=myuser&password=mypass&assumeMinServerVersion=9.0”;

Or, say, if we’re using Glassfish, it can be added to the JDBC connection pool as such:

There you go. Less spam in your PostgreSQL logs.

--

--