Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cwVbu-00045H-Q4 for pgsql-performance@arkaria.postgresql.org; Fri, 07 Apr 2017 15:15:38 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cwVbu-0004UY-Bb for pgsql-performance@arkaria.postgresql.org; Fri, 07 Apr 2017 15:15:38 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cwVbt-0004I7-8l for pgsql-performance@postgresql.org; Fri, 07 Apr 2017 15:15:37 +0000 Received: from mail.fmed.uba.ar ([157.92.152.1] helo=azteca.fmed.uba.ar) by makus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cwVbj-0003T7-OA for pgsql-performance@postgresql.org; Fri, 07 Apr 2017 15:15:33 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by azteca.fmed.uba.ar (Postfix) with ESMTP id BAD04139C094; Fri, 7 Apr 2017 12:15:39 -0300 (ART) X-Virus-Scanned: amavisd-new at fmed.uba.ar Received: from azteca.fmed.uba.ar ([127.0.0.1]) by localhost (azteca.fmed.uba.ar [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3fUgBnVv1+j2; Fri, 7 Apr 2017 12:15:39 -0300 (ART) Received: from azteca.fmed.uba.ar (azteca.fmed.uba.ar [157.92.152.1]) by azteca.fmed.uba.ar (Postfix) with ESMTP id 1D0CE139C065; Fri, 7 Apr 2017 12:15:37 -0300 (ART) Date: Fri, 7 Apr 2017 12:15:37 -0300 (ART) From: Gerardo Herzig To: Haider Ali Cc: pgsql-performance@postgresql.org Message-ID: <176827072.466738.1491578136971.JavaMail.root@fmed.uba.ar> In-Reply-To: Subject: Re: Understanding PostgreSQL query execution time MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [157.92.152.143] X-Mailer: Zimbra 7.2.7_GA_2942 (ZimbraWebClient - FF3.0 (Linux)/7.2.7_GA_2942) X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org ----- Mensaje original ----- > De: "Haider Ali" > Para: pgsql-performance@postgresql.org > Enviados: Viernes, 7 de Abril 2017 11:56:53 > Asunto: [PERFORM] Understanding PostgreSQL query execution time > > > Hello > > > I want to understand execution time of a query in PostgreSQL then I > want to relate it to the problem i am getting. According to my > observation ( I can't explain why this happen ) whenever we query a > table first time its execution will be high (sometimes very high) as > compare to queries made on same table in a short period of time > followed by first query on that table. For example query given below > > > SELECT "global_configs".* FROM "global_configs" ORDER BY > "global_configs"."id" ASC LIMIT $1 > > > > > executed multiple times instantaneous one after another have > following execution time > > > 1st time => 147.5ms > > 2nd time => 3.0ms > > 3rd time => 3.0ms > > 4th time => 3.0ms > > 5th time => 0.8ms That is the effects of the postgres/Linux cache for shure. > > > I want to understand why there is a huge time difference between 1st > and rest of the executions. > > > Relation to other problem > > > Having experience above behaviour of PostgreSQL now I am using > PostgreSQL managed by Amazon RDS. Observation is no matter how many > times I execute same query its execution times remain same ( > although execution time of a query on RDS is comparatively high as > compare to query running on local instance of PostgreSQL that I can > understand is because of Network latency) > > > Questions > > > > > 1. Why first query on a table takes more time then queries > followed by it ? > 2. Why above behaviour doesn't reflect on Amazon RDS ? > Amazon provides you with SSD like disks, running close to memory speed. That would explain the little impact of having a ram cache. HTH Gerardo > > Haider Ali -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance