Re: problem calling psql multiple times from a script ?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Paul Tilles <Paul(dot)Tilles(at)noaa(dot)gov>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: problem calling psql multiple times from a script ?
Date: 2007-05-30 15:23:55
Message-ID: 4104.1180538635@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Paul Tilles <Paul(dot)Tilles(at)noaa(dot)gov> writes:
> I am wondering if one of the previous executions of psql is doing some
> "back room" work in the database while allowing the script to continue.

It takes finite time for the backend to quit, and psql doesn't wait
around for that to happen. I've noticed that on many systems it seems
that the kernel scheduler actively discriminates against an exiting
backend --- maybe it thinks it's a low-priority background process?
The amount of work needed to start a new psql and a new backend
vastly exceeds what it takes to quit (unless you've got lots of temp
tables to drop, or some such), and yet people report cases like this
pretty often.

We could fix it by making PQfinish() wait for the connection to drop,
but that cure could be worse than the disease; most apps would just
see this as useless delay.

In the meantime, a sleep(1) or some such before trying to drop a
recently-used database ought to be a usable workaround.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Aurynn Shaw 2007-05-30 15:43:37 Re: On-line / off-line trace of SQL statements presented to the Postgres SQL engine
Previous Message Joshua D. Drake 2007-05-30 15:04:19 Re: 8.3