Performance issues with postgresql-42.2 and above #2877
Replies: 19 comments 35 replies
-
I doubt anyone has measured it. |
Beta Was this translation helpful? Give feedback.
-
I have done more testing and isolated to one query that is being ran 1482 times. We are using the PgPreparedStatement executeQuery() method and with the postgresql-42.0.0.jre7 jar, the query averages 2.37 ms but with the 42.2.20 jar, the average is 14.48 ms. After processing the results returned for each run, we call PgStatement.cancel() and PgStatement.close(). |
Beta Was this translation helpful? Give feedback.
-
To clarify the same query runs in 13 ms in psql and 14 ms using 42.2.20 ? As I said I'd like to see the server logs to see how the query is really being run. |
Beta Was this translation helpful? Give feedback.
-
The times vary between 11 - 14 ms in psql and 13 - 20 in 42.2.20. I was just averaging based on the total time it took for all 1482 in the postgres jar. I didn't run 1482 in psql. Which server logs would you want to see? We have postgres configured to los queries that take longer than 1000 ms. When doing these tests, I had 1 or2 that would show in the log that happen to take 1.1 second. Overall, they are typically in the teens and do not pull to the log. |
Beta Was this translation helpful? Give feedback.
-
My guess is that 42.0.0 is using simple query and 42.2.20 is using extended query, but I'd need to see the logs. If you have one that took 1.1 seconds then that works |
Beta Was this translation helpful? Give feedback.
-
I pulled this from the log: |
Beta Was this translation helpful? Give feedback.
-
So for sure this is using ExtendedQuery, but I think 42.0.0 is as well. I guess you don't have any logs with that driver ? |
Beta Was this translation helpful? Give feedback.
-
It looks like both 42.0.0 & 42.2.20 default to ExendedQuery and as far as I know I haven't changed that setting. |
Beta Was this translation helpful? Give feedback.
-
I set the Postgres log_min_duration_statement to 0 to log all queries and have ran a few tests. The run I am using is returning 508 resources which should call the query I posted earlier at most 508 times. When I use the 42.0.0.jre7 jar, the first run after starting my service the pg_log shows 1036 executions and it varies by 8 to 10 each subsequent time. With the 42.2.20 jar, the log shows the query being executed 2032 times each time I hit my service. I am still trying to run tests to make sure I am not calling the query execution multiple times but the only change I am making it to swap out the postgresql jar in my class path each time without changes to my Java application. |
Beta Was this translation helpful? Give feedback.
-
Is the query the same in both instances ? |
Beta Was this translation helpful? Give feedback.
-
Yes. The query is the same but the duration varies each time it runs. The parameters vary but do repeat many times over the course of all runs. Here is a sample from the 42.2.20 version: 2023-04-24 09:49:02.504 CDT [66907] LOG: duration: 8.672 ms parse : SELECT * FROM ( (SELECT practv_facid, practv_arid, practv_origin, practv_employee, practv_physician, practv_inactive_dt, practv_grp, practv_grp_desc, practv_empno, practv_prtype, practv_prcomp, practv_phyno, practv_logname, practv_name, practv_first_name, practv_middle_name, practv_last_name, practv_credentials, practv_npi, practv_dea, practv_taxno, practv_addr1, practv_addr2, practv_city, practv_state, practv_zip, practv_phone, practv_organization_npi, practv_organization_taxno, practv_org_addr1, practv_org_addr2, practv_org_city, practv_org_state, practv_org_zip, practv_org_phone, practv_cl_group, practv_facility_name, practv_abbrev, practv_mcc_sec_msg, $1 ::integer AS id_index FROM practitioner_view |
Beta Was this translation helpful? Give feedback.
-
I'm at a loss here, if the query is exactly the same I'm not sure how the driver is effecting this. |
Beta Was this translation helpful? Give feedback.
-
I noticed in the pg_log file when using 42.0.0.jre7, there were initially 4 log lines per call for the query and each one logged: Those were the lines for the first 4 times. On the 5th time, it changed to: Then it changed to just 2 log lines: So for my Java applications 508 calls to execute the query, this jar only logged 1036 entries in the pg_log When using the 42.2.20 jar all 508 calls to the query log 4 entries per call for a total of 2032 log entries in the pg_log. The difference is that in this jar, once the log entry changes to include a name "S_4", it continues to do the parse then changes the name: S_4, S_16, S_22, etc |
Beta Was this translation helpful? Give feedback.
-
Ok, now this is getting interesting. |
Beta Was this translation helpful? Give feedback.
-
any chance you can share the schema for that table with me. my email is davecramer@gmail.com if you prefer sending it to me privately |
Beta Was this translation helpful? Give feedback.
-
I have tried several versions of the postgres jar while I was just timing my Java application. I haven't had the logging turned on except with 42.0.0.jre7, 42.2.20 and 42.3.6. My Java application timing changed at 42.2.20 and all versions higher. postgresql-42.1.2.jar postgresql-42.2.1.jar postgresql-42.2.27.jre7.jar |
Beta Was this translation helpful? Give feedback.
-
using the following code on 42.6.0 a server side prepared statement is used.
@kyleand315 is this approximately the schema ? |
Beta Was this translation helpful? Give feedback.
-
When did we introduce binary support for the numeric type?
…On Wed, Apr 26, 2023 at 11:43 AM kyleand315 ***@***.***> wrote:
I'm not sure where I'm changing the type. I stepped through the code and
we call PgPreparedStatement getParameterMetaData() which comes from the
postgres jar and use that to determine the sql type for our parameters
using getParameterType(sqlIdx). We then call stmt.setObject(sqlIdx,
params[idx], sqlType); and the setObject method does a switch on the
sqlType to call the specific setter for the type. I have stepped through
the code using both the 42.0.0.jre7 and the 42.2.20 jars and both seem to
be doing the exact same thing. I get the same sqlType for each parameter in
both jars.
With the 42.2.20 jar, when it gets to the 5th time doing the query and
names it S_4, the pg_log shows:
2023-04-25 11:18:24 FINEST org.postgresql.core.v3.QueryExecutorImpl
sendBind FE=>
Bind(stmt=S_4,portal=null,$1=<0>,type=INT4,$2=<58>,type=NUMERIC,$3=<'logname'>,type=VARCHAR)
The next call shows:
2023-04-25 11:18:24 FINER org.postgresql.core.v3.SimpleQuery isPreparedFor
Statement S_4 does not match new parameter types. Will have to un-prepare
it and parse once again. To avoid performance issues, use the same data
type for the same bind position. Bind index (1-based) is 1, preparedType
was INT4 (after describe INT4), current bind type is UNSPECIFIED
Then it does the bind using the same data types in the same order.
2023-04-25 11:18:24 FINEST org.postgresql.core.v3.QueryExecutorImpl
sendBind FE=>
Bind(stmt=S_10,portal=null,$1=<0>,type=INT4,$2=<58>,type=NUMERIC,$3=<'logname'>,type=VARCHAR)
—
Reply to this email directly, view it on GitHub
<#2877 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAW3U3OUARANKK3ZMHBZJALXDFGBPANCNFSM6AAAAAAXDAFDQU>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
we can see in REL42.1.4...REL42.2.2 that there are quite a few differences in SimpleQuery.java |
Beta Was this translation helpful? Give feedback.
-
I am running a Java application that is looping and doing over 1000 sql queries. When using postgresql-42.0.0.jre7, it is averaging 8.9 seconds. When I upgrade to postgresql-42.2.2 and above, the same queries average 29.4 seconds. Has anyone else observed a performance degradation like this?
Beta Was this translation helpful? Give feedback.
All reactions