Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id CCA8FB5DBC8 for ; Sun, 10 Jul 2011 13:43:04 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 51138-02 for ; Sun, 10 Jul 2011 16:42:58 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 820ADB5DBCA for ; Sun, 10 Jul 2011 13:42:58 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p6AGgtd5002800; Sun, 10 Jul 2011 12:42:55 -0400 (EDT) To: sergio mayoral cc: pgsql-performance@postgresql.org Subject: Re: INSERT query times In-reply-to: References: Comments: In-reply-to sergio mayoral message dated "Thu, 07 Jul 2011 17:35:05 +0200" Date: Sun, 10 Jul 2011 12:42:55 -0400 Message-ID: <2799.1310316175@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201107/81 X-Sequence-Number: 44293 sergio mayoral writes: > i am using libpq library and postgresql 8.4 for my linux application running > on ARM with 256 MB. I am just doing: > PQconnectdb(); > PQexec(INSERT INTO table1 ....); (0.009661 sec.) > PQexec(INSERT INTO table1 ....); (0.004208 sec.) > PQexec(INSERT INTO table2 ....); (0.007352 sec.) > PQexec(INSERT INTO table2 ....); (0.002533 sec.) > PQexec(INSERT INTO table2 ....); (0.002281 sec.) > PQexec(INSERT INTO table2 ....); (0.002244 sec.) > PQexec(INSERT INTO table3 ....); (0.006903 sec.) > PQexec(INSERT INTO table3 ....); (0.002903 sec.) > PQfinnish(); > I check the time for each PQexec with gettimeofday function and I always see > that the first INSERT for each table needs longer than the next ones. The first few commands of *any* type on a new connection are going to take longer than repeat versions of those commands, because the backend needs to load up its internal caches. Once it's cached information about the tables, operators, etc that you are working with, it's a bit faster. This isn't specific to INSERT. > this must be something with the parser stage and since i am doing every time > the same queries, I would like to know if there is a way to cache this > queries in order to speed up the first INSERTs. The only "fix" is to hang onto your connections longer. Consider a connection pooler. regards, tom lane