From: Craig Ringer <craig@postnewspapers.com.au>
To: Miernik <public@public.miernik.name>
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
Date: Thu, 31 Jul 2008 18:24:32 +0800
Message-ID: <489192E0.9010309@postnewspapers.com.au> (raw)
In-Reply-To: <20080731082930.553C.0.NOFFLE@turbacz.local>
References: <20080723152112.30A4.0.NOFFLE@turbacz.local>
<dcc563d10807231025s617c6b16neb93c6348a658cdb@mail.gmail.com>
<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>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: craig@postnewspapers.com.au, public@public.miernik.name
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
In-Reply-To: <489192E0.9010309@postnewspapers.com.au>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox