Search statistics not logged after migration (#405). Fix SQL exception on postgres when query to log is too long.