Re: how to synchronize database operations?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Markus Wagner <magnus(at)gmx(dot)de>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: how to synchronize database operations?
Date: 2002-08-15 15:40:55
Message-ID: 23685.1029426055@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Markus Wagner <magnus(at)gmx(dot)de> writes:
> Hi,
> when I (re)create my db from within C using libpq I do the following:
> I open "template1" and execute "drop database ..." and "create database ...".
> This worked fine for some time. However, I encountered some synchronization
> problem:

> When recreating, which includes the drop command, I get immediately before the
> create command the error "template1 is accessed by other users". Then, when
> doing the same thing again, there is no db to drop, and the create call
> succeeds.

My guess is that you are closing the connection to the backend that did
the DROP and opening a new one for the CREATE. The trouble with this is
that it takes a few milliseconds for the old backend to clean up and go
away. It's quite possible for the new backend to see the old one as
still active, and since it doesn't know what the other one might be
doing to template1, it disallows the CREATE.

If you issue the DROP and the CREATE in the same backend process,
I suspect your problem will go away.

> How can I synchronize that? Just trying to open template1 again and again?

That would probably make it worse ...

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joe Conway 2002-08-15 15:42:51 Re: Bulk row fetching
Previous Message Andrew Sullivan 2002-08-15 15:31:59 Re: Problem with Now()?