Re: Is it possible to stop sessions killing eachother when they all authorize as the same role?

Поиск
Список
Период
Сортировка
От Guillaume Lelarge
Тема Re: Is it possible to stop sessions killing eachother when they all authorize as the same role?
Дата
Msg-id CAECtzeX0PmhiaOxe8c9=3J16SiP=S_Tx5LXftWS0UygjPPzdpA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Is it possible to stop sessions killing eachother when they all authorize as the same role?  (Bryn Llewellyn <bryn@yugabyte.com>)
Список pgsql-general
Le mer. 14 sept. 2022 à 00:35, Bryn Llewellyn <bryn@yugabyte.com> a écrit :
guillaume@lelarge.info wrote:

This won't answer your question

It has been answered now. See my "case closed" email here:


…but still… I usually really like your scripts, it's nicely written, but this part seems really weird to me:

bryn@yugabyte.com wrote:

-- No error
do $body$
declare
  p int not null := 0;
begin
  for p in (
    select pid
    from pg_stat_activity
    where backend_type =  'client backend'
    and   pid          <> pg_backend_pid())
  loop
    perform pg_terminate_backend(p);
  end loop;
end;
$body$;

While your script works great, I'm wondering why you don't write it this way:

SELECT pg_terminate_backend(pid) FROM pg_stat_activity
WHERE backend_type =  'client backend' AND pid <> pg_backend_pid();

As it is less code, it's quicker to understand what it does.

Well, yes… I have often been accused of being anally fixated on details—and of verbosity. This is just the old chestnut that a "select" statement shouldn't have side effects.

Oh, OK, looks like a good reason to me. I will probably still do the quick SELECT, but I understand your view on it.
 
"pg_terminate_backend(p)" ought, by the book, to be a procedure. But I suppose that it dates from the time when PG had only user-defined functions (and no shipped procedures). And "perform" makes a function feel to me to be a bit more like a procedure than just selecting it feels. Others might well disagree…


--
Guillaume.

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

Предыдущее
От: Rama Krishnan
Дата:
Сообщение: Re: Postgresql acid components
Следующее
От: Karsten Hilbert
Дата:
Сообщение: Re: Is it possible to stop sessions killing eachother when they all authorize as the same role?