Re: PREPARE in bash scripts

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: "A(dot)j(dot) Langereis" <a(dot)j(dot)langereis(at)inter(dot)nl(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: PREPARE in bash scripts
Date: 2005-11-23 10:05:39
Message-ID: 20051123100538.GB8374@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Nov 23, 2005 at 10:38:03AM +0100, A.j. Langereis wrote:
> Dear all,
>
> I've written a bash script that looks like the one below:

<snip>

> Note that this is very stripped version of the real script, but it gives the
> same errors:
>
> ERROR: prepared statement "test_statement" does not exist

I think your speed is being limited by backend startup time and
transaction commit time more than anything else. I don't think prepared
statements will help in your case.

The way I usually do it is pipe the output of a whole loop to psql like
so:

for i in blah ; do
echo "insert into ..."
done | psql -q

Or more commonly, just have the script emit all the commands to stdout
and then run it like so:

./myscript | psql -q

An important way to increase speed would be to use explicit
transactions (BEGIN/END). When executing a lot of statements this will
speed up things considerably. Finally, if it's just INSERTs, consider
using COPY, for even more efficiency.

Hope this helps,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Hannes Dorbath 2005-11-23 10:21:19 TSearch2 / UTF-8 and stat() function
Previous Message Hannes Dorbath 2005-11-23 09:57:34 TSearch2 / German compound words / UTF-8