Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 3676A64FCC6 for ; Thu, 31 Jul 2008 07:24:42 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 74465-08 for ; Thu, 31 Jul 2008 07:24:34 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from www.postnewspapers.com.au (www.postnewspapers.com.au [202.61.230.242]) by postgresql.org (Postfix) with ESMTP id 3BE2664FCBF for ; Thu, 31 Jul 2008 07:24:37 -0300 (ADT) Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by www.postnewspapers.com.au (Postfix) with ESMTP id AD0015C106; Thu, 31 Jul 2008 18:24:32 +0800 (WST) Received: from [10.0.0.53] (wallace.localnet [10.0.0.53]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 85C251E0434; Thu, 31 Jul 2008 18:24:32 +0800 (WST) Message-ID: <489192E0.9010309@postnewspapers.com.au> Date: Thu, 31 Jul 2008 18:24:32 +0800 From: Craig Ringer User-Agent: Icedove 1.5.0.14eol (X11/20080509) MIME-Version: 1.0 To: Miernik Cc: pgsql-performance@postgresql.org Subject: Re: how to fix problem then when two queries run at the same time, it takes longer to complete then if run in sequence References: <20080723152112.30A4.0.NOFFLE@turbacz.local> <20080723203203.31C4.0.NOFFLE@turbacz.local> <488840D3.2090808@archonet.com> <20080731061522.54FE.0.NOFFLE@turbacz.local> <48916B6A.4070203@archonet.com> <20080731082930.553C.0.NOFFLE@turbacz.local> In-Reply-To: <20080731082930.553C.0.NOFFLE@turbacz.local> X-Enigmail-Version: 0.94.2.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200807/277 X-Sequence-Number: 30877 Miernik wrote: > BTW, doesn't there exist any tool does what "psql -c" does, but is > written in plain C, not perl? I was looking for such psql replacement, > but couldn't find any. As others have noted, psql is written in C, and you're using a wrapper. Assuming your're on Debian or similar you should be able to invoke the real psql with: /usr/lib/postgresql/8.3/bin/psql psql is a C executable that uses libpq directly, and is really rather low-overhead and fast. As for how to issue multiple commands in one statement in a shell script: one way is to use a here document instead of "-c". Eg: psql <<__END__ UPDATE blah SET thingy = 7 WHERE otherthingy = 4; DELETE FROM sometable WHERE criterion = -1; __END__ You can of course wrap statements in explicit transaction BEGIN/COMMIT, etc, as appropriate. As you start doing more complex things, and especially once you start wanting to have both good performance *and* good error handling, you'll want to move away from sql scripts with psql and toward using perl, python, or similar so you can use their native interfaces to libpq. -- Craig Ringer