Re: Slow select query

From: Federico Di Gregorio <fog(at)dndg(dot)it>
To: psycopg(at)postgresql(dot)org
Subject: Re: Slow select query
Date: 2014-04-02 08:37:59
Message-ID: 533BCC67.7070709@dndg.it
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: 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(dot)digregorio(at)dndg(dot)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

In response to

Browse psycopg by date

  From Date Subject
Next Message Tobias Fielitz 2014-04-03 00:00:09 Use of .mogrify
Previous Message Adrian Klaver 2014-03-31 23:17:27 Re: Slow select query