views:

205

answers:

2

In postgresql a query in the querylog gets something like this:

2009-02-05 00:12:27 CET LOG:  duration: 3781.634 ms  execute <unnamed>: SELECT QUERY ....

Is there a possibility to put something more usable into the "< unnamed >" placed like the url the query was requested from?

Are there any other possibilities to track the origin of a query in postgresql using jdbc from java?

Thanks

A: 

I am actually curious as to where this "querylog" can be found? No where in my postgres logs do I see anything with the syntax like you posted above. Where can this data be located?

Thanks.

  • Nicholas
Nicholas Kreidberg
It depends on the PostgreSQL configuration. Typically, you need:log_statement = 'all' Warning: it slows down PostgreSQL a lot.
bortzmeyer
+2  A: 

Short answer is "no"

The name can be set when preparing the statement, using the PREPARE command, but that requires rewriting all your SQL. There is no option to simply add a name parameter to your JDBC methods.

The JDBC driver makes use of both named and unnamed prepared statements. It will give them a name when it wishes to reuse them, which it will deem appropriate if the same PreparedStatement object is executed 5 times (though that is configurable through setting the prepareThreshold).

Documentation is here

More info can also be found by searching the PostgreSQL JDBC mailling list

Stephen Denne