Re: including pid's for `There are XX other sessions using the database`

From: "Euler Taveira" <euler(at)eulerto(dot)com>
To: "Zhihong Yu" <zyu(at)yugabyte(dot)com>, "PostgreSQL Developers" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: including pid's for `There are XX other sessions using the database`
Date: 2022-08-20 04:31:01
Message-ID: 4f650f65-8640-4805-ae37-4f5e492fd6eb@www.fastmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Aug 19, 2022, at 2:10 PM, Zhihong Yu wrote:
> I want to poll the community on whether including proc->pid's in the error message would be useful for troubleshooting.
Such message is only useful for a parameter into a pg_stat_activity query. You
don't need the PID list if you already have the most important information:
database name. I don't think revealing the current session PIDs from the
database you want to drop will buy you anything. It could be a long list and it
does not help you to solve the issue: why wasn't that database removed?

Besides that, if you know that there is a possibility that a connection is
open, you can always use the FORCE option. The old/other alternative is to use
a query like

SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'foo';

(possibly combined with a REVOKE CONNECT or pg_hba.conf modification) before
executing DROP DATABASE.

--
Euler Taveira
EDB https://www.enterprisedb.com/

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2022-08-20 04:34:41 Re: Fix typo with logical connector (src/backend/commands/vacuumparallel.c)
Previous Message Amit Kapila 2022-08-20 04:02:57 Re: Fix typo with logical connector (src/backend/commands/vacuumparallel.c)