Executing the same query multiple times gets slow

From: Blake McBride <blake1024(at)gmail(dot)com>
To: pgsql-jdbc(at)lists(dot)postgresql(dot)org
Subject: Executing the same query multiple times gets slow
Date: 2023-07-20 16:33:10
Message-ID: CABwHSOurbLHgmvsEzTBRncvFoSt35RU1bs9jvF-287r6dDfD0Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Greetings,

I have a complex query that returns about 5,000 records and only a few
columns. If I run it in psql repeatedly, it's always fast. If I run it
through JDBC it runs fast at first but then it gets real slow (> 50
seconds). I can't understand why it would get slow after 30 runs of the
exact same query.

I am running:

Linux / 64GB RAM
PostgreSQL 15.1
postgresql-42.5.4.jar

I am using a prepared statement but a new one each time even though it is
the same query (there are reasons for this).

I found the line that's having the delay is: pstat.executeQuery();

where: PreparedStatement pstat;

Sure appreciate any pointers!

Thanks.

Blake

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Dave Cramer 2023-07-21 21:58:10 Re: Executing the same query multiple times gets slow
Previous Message Matthew Bellew 2023-03-26 22:23:01 Parameter marker swapping in {fn timestampdiff()}