Re: Slow select query - Mailing list psycopg

From Federico Di Gregorio
Subject Re: Slow select query
Date
Msg-id 533BCC67.7070709@dndg.it
Whole thread Raw
In response to Slow select query  (Glenn Pierce <glennpierce@gmail.com>)
List psycopg
On 31/03/2014 22:16, Glenn Pierce wrote:
> Hi I have a query that returns a fair amount of data ~ 730000 rows.
> In pgadmin The query after multiple runs takes around 5-6 seconds.
>
> When  try to get all the data through psycopg it takes around 20 seconds.
>
> I have turned of ssl for postgres.
>
> Does anyone no any reasons why this is ? or is this normal behavior ?

psycopg converts text to Python types and even if this is done in C
(mostly) it can take time. You have several ways to optimize your query:

* grab only the columns you need
* if you don't need all the rows, use a server side cursor

federico

--
Federico Di Gregorio                         federico.digregorio@dndg.it
Di Nunzio & Di Gregorio srl                               http://dndg.it
 Credo fermamente che da qualche parte, in una scatola ci sia un gatto
  che non è vivo ne morto. Credo anche che se i fisici non si sbrigano
  a dargli una scatoletta, ben presto sarà solo morto.
                              -- adattato da una frase di Sam Black Crow


psycopg by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Slow select query
Next
From: Tobias Fielitz
Date:
Subject: Use of .mogrify