"Yorwerth, Adam" <Adam.Yorwerth@tesco.com> writes:
> We seem to have found a situation where a query run using explain analyse or pgbench is incredibly fast, but run via
Javaunder load performs very poorly – we’ve checked query performance metrics for our Postgres instance and can confirm
thatit’s the query running slowly, and not a Java problem.
Usually when people report something like this, the explanation is that
it's not actually the same query being tested in both cases.
In particular, if you're parameterizing the query in Java but substituting
constant values when running it manually, that can make a difference.
A further-afield possibility is that your application has been set up to
run with custom values of work_mem, planner cost constants, etc, which
you're failing to duplicate in the manual tests.
If all else fails, try installing auto_explain so that you can capture
the actual query plan used when the application executes this query.
regards, tom lane