Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vIN3o-006Hp9-S6 for pgsql-general@arkaria.postgresql.org; Mon, 10 Nov 2025 08:15:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vIN3n-00EuEZ-G4 for pgsql-general@arkaria.postgresql.org; Mon, 10 Nov 2025 08:15:35 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vIN3n-00EuEQ-1C for pgsql-general@lists.postgresql.org; Mon, 10 Nov 2025 08:15:35 +0000 Received: from mail-lj1-x229.google.com ([2a00:1450:4864:20::229]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vIN3l-006LFV-18 for pgsql-general@postgresql.org; Mon, 10 Nov 2025 08:15:34 +0000 Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-378cffe5e1aso28990081fa.2 for ; Mon, 10 Nov 2025 00:15:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762762532; x=1763367332; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=d2LZRNB4vdm3c0jyoi/1YHX/A99r+uXwb3VGEsBZdaI=; b=guSk/YIz8eLOglgzMi1E1sb6vB1+/ZgA0c8uyQy6m0a/tbcOzwsVC32SsMakULLqRG uBTAzS+nd37e4LFyxkMl3NZ/mBIIuahl07oLNbD5VwVHSV3zsLfqlVQLIdgCtn3ad6HP 3F73qAuitcr0oete4SfmnUUMJHwKzuiSsWwKV1RB9hEzAHOSZ/sEHxv8KY57lOuNW5iv 4z7ZTJkSkYWop5wNt+nfHk3M2Ut2nuZaZI3zeY2/FAXdwkQ2opuZC/4fdMkO3YQzcE1V 3h605iVCUGTzl7b5B38J/HCVwkTZNpoFodERWl3uOXPwHYwIrbFlYyLbEZMQtxZUIoKO 2yRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762762532; x=1763367332; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=d2LZRNB4vdm3c0jyoi/1YHX/A99r+uXwb3VGEsBZdaI=; b=s0nKBqDbdwI5/xvAYj1ZtJClwxe4RpucAS/s2hHURobmFu269yMt/XQHg/MPkl9k8r dek8LKJPJJ2z/slp8v/hI+fX89fljW1QMsnWRkic7Ark9I5USdcW8YYGUUfhfktikYBd O1X32fgS/LM+QM4BA53aZ6pl15+hiEgxJL3km2c63JXacDFtN1JzrVdv2p88yWGsbWVR alxyDoRdaEUqSqftoqY6Fe/FGN3Sj17Kf/5SjWPsEIiRyK9T5f2rGe9YMuRRN8n643wu vERkr5gCQwavxveFazvhUXeMFRBU2GBIHoJEK6cgOv4LBjmxwBCNFmEeaaXi8OknH9ZB i5xQ== X-Gm-Message-State: AOJu0Yxm4kFACnUKXJKSvXXClsAqRrrCAreELZpAwWi9dBYj//VH++WH MKJIsoWaJQVCib4ADs2peLK3awUMZe2um29qc5mmlloLpNPBab91CoQLpTC5rfnBI7RF+frPgdD 5Bx1zPFx5SqZiIGPk1JvqdfXPA6X9qLA= X-Gm-Gg: ASbGncvYMl2b4K/4U35+BUc5Ax3JE/x+qgpVMY73rAFWvj17KIOFkeQ/uf0ck72F56K 0NLPKTjHppLklLOu8l9iQApSN7PNp7UzgGJi+RW6j+Sr1+Gw6JvQnnwk2gwU/Su761lteN/E5ht lsP5xUCdW23y/D2cpNiES11IqCibhFUEnJZQAvnyBJn4Qo1KOX4kQvXsweKFcwanS8mapov4BBr a42jqwcULQ/DW+OOsjy/p60BcW7XGXroxzeol2K1ZaXU3X+qYkf/noZVscJXJynoyyFsFTifffY 9m5kpw== X-Google-Smtp-Source: AGHT+IGgRs3YP10p0HZkpxOum5D3EMfg92Oe3PaRwlMyDEiAsh5ONp97XOKjfvB3U9UyLjAqhSlQQCMfWSkwAp6pLdQ= X-Received: by 2002:a05:6512:318f:b0:594:2f72:2f86 with SMTP id 2adb3069b0e04-5945f20764dmr2072676e87.54.1762762531350; Mon, 10 Nov 2025 00:15:31 -0800 (PST) MIME-Version: 1.0 References: <69982fc8a6ea2b7c2030d8206e16a8af081e7c46.camel@cybertec.at> In-Reply-To: <69982fc8a6ea2b7c2030d8206e16a8af081e7c46.camel@cybertec.at> From: Ashish Mukherjee Date: Mon, 10 Nov 2025 13:45:19 +0530 X-Gm-Features: AWmQ_bntaBzl67C4VfOE6r2j-ppq9YaXaJyIqMqI_QMcL8a_EF_heWGsfrSCLtU Message-ID: Subject: Re: Enquiry about long-running queries To: Laurenz Albe Cc: pgsql-general@postgresql.org Content-Type: multipart/alternative; boundary="000000000000812dc906433922b1" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000812dc906433922b1 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable pgsql 17.5 on Red Hat Enterprise Linux release 8.10 (Ootpa) The query is run from one of our php applications. On Fri, Nov 7, 2025 at 8:59=E2=80=AFPM Laurenz Albe wrote: > On Fri, 2025-11-07 at 19:18 +0530, Ashish Mukherjee wrote: > > I have a query like this showing up on my production database - > > > > s05=3D> SELECT pid, user, usename, application_name, client_addr, > client_hostname, client_port, datname, now() - query_start as "runtime", > > state, wait_event_type, wait_event, > > substr(query, 0, 100) > > FROM pg_stat_activity > > WHERE now() - query_start > '5 minutes'::interval and state =3D 'activ= e' > > ORDER BY runtime DESC; > > pid | user | usename | application_name | client_addr | > client_hostname | client_port | datname | runtime > > | state | wait_event_type | wait_event | > substr > > > -------+--------+-----------------+----------------+---------------------= ----------------------------------------------- > > 356274 | s05 | s05 | scandir | 192.168.64.61 | > | 44098 | s05 | 9 days 18:45:37 > > .65577 | active | IPC | ParallelFinish | select scac_code > from scac where supported_by_smc =3D true > > > > The query when run from psql prompt finishes in a jiffy, so query > performance/cost is not the problem. > > Also, when I try to kill the query through pg_terminate_backend or > pg_cancel_backend, it does not get killed. > > > > I am wondering what could be the root cause of this problem and how it > could be addressed. Any pointers would be appreciated. > > That is strange. The wait event means that the backend is waiting for > parallel > workers to finish. But any existing parallel worker processes would also > have > to show up in the query result. > > On what operating system does PostgreSQL run? > > What exact version is it? > > You could try to "strace" the backend process (or use an equivalent tool, > if > you are not on Linux) and see if the process issues any system calls. > To see what's going on, you'd have to attach to the backend process with = a > debugger and take a stack trace. > > Yours, > Laurenz Albe > --000000000000812dc906433922b1 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
pgsql 17.5 on=C2=A0Red Hat Enterprise Linux release 8.10 (= Ootpa)

The query is run from one of our php applications= .

On Fri, Nov 7, 2025 at 8:59=E2=80=AFPM Lauren= z Albe <laurenz.albe@cyberte= c.at> wrote:
On Fri, 2025-11-07 at 19:18 +0530, Ashish Mukherjee wrote:
> I have a query like this showing up on my production database -=C2=A0<= br> >
> s05=3D> SELECT pid, user, usename, application_name, client_addr, c= lient_hostname, client_port, datname, now() - query_start as "runtime&= quot;,
> state, wait_event_type, wait_event,
> substr(query, 0, 100)
> =C2=A0FROM =C2=A0pg_stat_activity
> =C2=A0WHERE now() - query_start > '5 minutes'::interval and= state =3D 'active'
> =C2=A0ORDER BY runtime DESC;
> =C2=A0 =C2=A0pid =C2=A0 | user | usename | application_name | =C2=A0cl= ient_addr =C2=A0| client_hostname | client_port | datname | =C2=A0 =C2=A0 = =C2=A0 =C2=A0runtime
> =C2=A0 =C2=A0 =C2=A0 =C2=A0| state =C2=A0| wait_event_type | =C2=A0 wa= it_event =C2=A0 | =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 substr
> -------+--------+-----------------+----------------+------------------= --------------------------------------------------
> =C2=A0 356274 | s05 =C2=A0| s05 =C2=A0 =C2=A0 | scandir =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0| 192.168.64.61 | =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 | =C2=A0 =C2=A0 =C2=A0 44098 | s05 =C2=A0 =C2=A0 | 9 d= ays 18:45:37
> .65577 | active | IPC =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | Para= llelFinish | select scac_code from scac where supported_by_smc =3D true
>
> The query when run from psql prompt finishes in a jiffy, so query perf= ormance/cost is not the problem.
> Also, when I try to kill the query through pg_terminate_backend or pg_= cancel_backend, it does not get killed.
>
> I am wondering what could be the root cause of this problem and how it= could be addressed.=C2=A0 Any pointers would be appreciated.

That is strange.=C2=A0 The wait event means that the backend is waiting for= parallel
workers to finish.=C2=A0 But any existing parallel worker processes would a= lso have
to show up in the query result.

On what operating system does PostgreSQL run?

What exact version is it?

You could try to "strace" the backend process (or use an equivale= nt tool, if
you are not on Linux) and see if the process issues any system calls.
To see what's going on, you'd have to attach to the backend process= with a
debugger and take a stack trace.

Yours,
Laurenz Albe
--000000000000812dc906433922b1--