Re: how to synchronize database operations?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: how to synchronize database operations?
Дата
Msg-id 23685.1029426055@sss.pgh.pa.us
обсуждение исходный текст
Ответ на how to synchronize database operations?  (Markus Wagner <magnus@gmx.de>)
Ответы Re: how to synchronize database operations?  (Markus Wagner <magnus@gmx.de>)
Список pgsql-general
Markus Wagner <magnus@gmx.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

В списке pgsql-general по дате отправления:

Предыдущее
От: Andrew Sullivan
Дата:
Сообщение: Re: Problem with Now()?
Следующее
От: Joe Conway
Дата:
Сообщение: Re: Bulk row fetching