Thread: Slow select query

Slow select query

From
Glenn Pierce
Date:
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 ?

Thanks

Re: Slow select query

From
Federico Di Gregorio
Date:
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