Re: Clients disconnect but query still runs

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Clients disconnect but query still runs
Дата
Msg-id 3415.1248745744@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Clients disconnect but query still runs  (Robert James <srobertjames@gmail.com>)
Ответы Re: Clients disconnect but query still runs
Re: Clients disconnect but query still runs
Список pgsql-general
Robert James <srobertjames@gmail.com> writes:
> Hi.  I noticed that when clients (both psql and pgAdmin) disconnect or
> cancel, queries are often still running on the server.  A few questions:
> 1) Is there a way to reconnect and get the results?

No.

> 2) Is there a way to tell postgres to automatically stop all queries when
> the client who queried them disconnects?

No.

> 3) Is there a way to see all queries whose clients have disconnected?

No.

> 4) And finally: Why is this the behavior?

It's not easy to tell whether a client has disconnected (particularly if
the network stack is unhelpful, which is depressingly often true).
Postgres will cancel a query if it gets told that the connection's been
dropped, but it will only discover this when an attempt to output to the
client fails.  It does not spend cycles looking aside to see if the
connection has dropped when it is doing something that doesn't involve
output to the client.

If your client code is polite enough to send a cancel request before
disconnecting, that should terminate the query reasonably promptly.
But just "yanking the plug" doesn't do that.

            regards, tom lane

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

Предыдущее
От: Jeff Davis
Дата:
Сообщение: Re: Relational Algebra and Aggregate Functions
Следующее
От: Tom Lane
Дата:
Сообщение: Re: A question about the permissions