I have found the reason. It is because in jdbc the communication is via only
tcp sockets.In psql client it uses unix sockets for local host.
--
View this message in context: http://postgresql.1045698.n5.nabble.com/Slow-statement-when-using-JDBC-tp3368379p5812721.html
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.