Re: Query timing stable?

From: "ktm(at)rice(dot)edu" <ktm(at)rice(dot)edu>
To: Cheng <niechenghust(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Query timing stable?
Date: 2012-03-14 18:30:58
Message-ID: 20120314183058.GJ7440@aart.rice.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Wed, Mar 14, 2012 at 02:24:42PM -0400, Cheng wrote:
> Hi,
>
> I turned on "\timing" in the command line. It seems that the timing
> is not stable. For the same query, the query's executing time is
> longer for the first time I run it than for the second and third
> time run it. I think it might be "cached" automatically.
>
> Is there a way to turn the "automatic caching" off so that I can get
> the same "timing" when I run the same query? Or is there some other
> way to get stable query time whenever the query is run?
>
> Thanks,
> Cheng
>

The OS and PostgreSQL will both cache data that has been read from
the disk, in case it is needed again. The amount cached is dependent
on the amount of RAM storage in your machine. This caching causes
a repeated query to run in less time than the initial query. The
caching is automatic, but can only cache what has already been read.
You will need to run a query several times to get a stable timing
and typically discard the time for at least the first run.

Regards,
Ken

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Steve Crawford 2012-03-14 18:32:25 Re: Query timing stable?
Previous Message Cheng 2012-03-14 18:24:42 Query timing stable?