Postgres query over ODBC a order of magnitude slower? Postgres query over ODBC a order of magnitude slower? postgresql postgresql

Postgres query over ODBC a order of magnitude slower?


I finally found the problem and it was that psqlodbc's SQLPrepare/SQLExecute by default doesn't execute a PREPARE/EXECUTE. The driver itself builds the SELECT and sends that.

The solution is to add UseServerSidePrepare=1 to the odbc.ini or to the ConnectionString for SQLDriverConnect. The total execution time for one query measured from the application dropped from >100ms to 5-10ms.


I don't think the timing between psql and your program are comparable.

Maybe I'm missing something, but in psql you are only preparing the statements, but never really fetching the data. EXPLAIN PLAN is not sending data either

So the time difference is most probably the network traffic that is needed to send all rows from the server to the client.

The only way to reduce this time is to either get a faster network or to select fewer columns. Do you really need all the columns that are included in "alotofcolumns"?