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 1tVbHv-009t56-1E for pgsql-general@arkaria.postgresql.org; Wed, 08 Jan 2025 19:00:19 +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 1tVbHs-004jvq-Un for pgsql-general@arkaria.postgresql.org; Wed, 08 Jan 2025 19:00:16 +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 1tVbHs-004jvh-HA for pgsql-general@lists.postgresql.org; Wed, 08 Jan 2025 19:00:16 +0000 Received: from mail-ot1-x32c.google.com ([2607:f8b0:4864:20::32c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tVbHp-000Z4w-24 for pgsql-general@postgresql.org; Wed, 08 Jan 2025 19:00:15 +0000 Received: by mail-ot1-x32c.google.com with SMTP id 46e09a7af769-71e15d9629bso25420a34.1 for ; Wed, 08 Jan 2025 11:00:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736362813; x=1736967613; darn=postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=ydn5oEPr6HHReOJ04U0S2unCGHtasFOK5BXmKvrwdLQ=; b=YMMo5q0x25XR89jmyf06tc7xAllRtd+FULqiGiNZYPs1adPYmzktSA8CS9VpR97zO4 AMQigEYfnuZJKFJdzCQGIi67xpy5uZBTE0uf0B7g8luEKUPSeItJDZycwmAJyM1oRchK 9fyciqMkKRKAhpUQB4obltOBY0lgFf6wgJC1gOMk+PmgbW9KvhLsg9fr+F2LDvgUNzT8 qstK/Lt36YRvSQ72fMX1JzLSJl3chqm46nZQy/29RSok38kwC0wgxdYAD/qXZF+e1sSw ryR0NKxyXxuhgBmyZ46d6ChwGMK85C2ziyV+lkLXuZ20S31GsVB3RlUWUzLXxSf0boDH ue8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736362813; x=1736967613; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ydn5oEPr6HHReOJ04U0S2unCGHtasFOK5BXmKvrwdLQ=; b=sf2aNrrTjedOqAK3fegPTgilkRteljISXMLEFzJBVbptCmvL4PxoCVaOAvD9Esv3j3 K06j3g1094uxHXRe0iSh8uhHr4GnqVyH1wKmPOKBqB/N176f7fgCtv+CSv6UJG6DjQGm siOiOMPhQ69uwU7mkfWagbfiIHMGoC84OXe6CxFlVVEfy8Dmc5NTcw/tHD147+rkK3ki 8qGqUXFeaLZP7lDRjO5zRkMiIPc2XMqlII20Bz663zc9C8ACsgAuxVDcTbwKMvBCoGPJ xUG9ORzgKbMscEIl6GUcrNKBTHMUbML3cEafpDjdOKCxBJdoM+ZMDcRd8R+qUZ7wfHl3 LBNw== X-Gm-Message-State: AOJu0YyDwLfxdf4xABKo4kwFIoZ33rX79PJUhMQxpiHkbph2WBQw9vCi QYJfm84QF/KZIq9sD9mI0oWmQXmHdWMirebj6+2wtv3wXOjM8QXNC5eHR/exWpc7ZQmAT0iuxU+ JMo+vUJ/CUOXiWVoy/QLlB4QeREExxaya X-Gm-Gg: ASbGncvCfd5zpPNkQzK2JOKX0B3wg0/qwd6XWXySJarmRlJDb8GT8lvtYIqKR4J8IgY mdBPiTayntCKleA/HBcpvLLTOvi3dtphD4DlMlCdb8pxZ3xJAkpd2keDWCJH9itZjjxiJkET1 X-Google-Smtp-Source: AGHT+IFKHfnSKE3CAGtN3WtOSigBt89dkfmC9TJ/d9TDZIA4utSvHDg/JcgMS39m1ZJnzRuQOMy9xaGBbbqtpUBKJhs= X-Received: by 2002:a05:6871:53c5:b0:29e:6f32:6d91 with SMTP id 586e51a60fabf-2aa06952f22mr1983158fac.33.1736362812825; Wed, 08 Jan 2025 11:00:12 -0800 (PST) MIME-Version: 1.0 From: Ron Johnson Date: Wed, 8 Jan 2025 14:00:00 -0500 X-Gm-Features: AbW1kvZufAodpgJw5Y1pySrI-zr9r1r1z7yIhdZa9mQfNk0vokD7spx07ZNHBQ8 Message-ID: Subject: INTERVAL MINUTE TO SECOND didn't do what I thought it would do To: pgsql-general Content-Type: multipart/alternative; boundary="000000000000a8ea09062b3678ae" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000a8ea09062b3678ae Content-Type: text/plain; charset="UTF-8" PG 14.13 The goal of "(now() - query_start)::INTERVAL MINUTE TO SECOND" column is to see how many minutes and seconds ago that the query started. (Why? Because that's useful to me, and the people I show the output to when queries run for more than a few minutes. We don't need to see hours and days; just the total MMMMM:SS.mmm.) I'd hoped that ::INTERVAL MINUTE TO SECOND would do the trick, but MINUTE TO SECOND seems to be ignored. Is there cast magic that does what I want? TAPc=# select pid ,datname as db, usename ,to_char(query_start, 'YYYY-MM-DD HH24:MI:SS.MS') as qry_start ,(now() - query_start)::INTERVAL MINUTE TO SECOND as qry_elapsed ,cast(state as char(11)) as state from pg_stat_activity WHERE pid != pg_backend_pid() and state != 'idle'; pid | db | usename | qry_start | qry_elapsed | state ---------+------+------------+-------------------------+-------------------------+------------- 657996 | | replicator | 2024-11-11 21:03:00.992 | 57 days 16:38:22.342449 | active 4070070 | TAPc | TAP | 2025-01-08 13:41:23.202 | 00:00:00.132817 | active 4070069 | TAPc | TAP | 2025-01-08 13:41:23.140 | 00:00:00.194222 | active 4070065 | TAPc | TAP | 2025-01-08 13:41:23.238 | 00:00:00.096418 | active (4 rows) -- Death to , and butter sauce. Don't boil me, I'm still alive. lobster! --000000000000a8ea09062b3678ae Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
PG 14.13

The goal of "<= span style=3D"font-family:monospace">(now() - query_start)::INTERVAL MINUTE= TO SECOND"=C2=A0column is to see how many minutes and seconds = ago that the query started.=C2=A0 (Why?=C2=A0 Because that's useful to = me, and the people I show the output to when queries run for more than a fe= w minutes.=C2=A0 We don't need=C2=A0to see hours and days; just the tot= al MMMMM:SS.mmm.)

I'd hoped that ::INTERVAL MI= NUTE TO SECOND would=C2=A0do the trick, but MINUTE TO SECOND seems to be ig= nored.

Is there cast=C2=A0magic that does what I w= ant?

TAPc=3D# select pid =
=C2=A0 =C2=A0 =C2=A0 =C2=A0,datname as db, usename
=C2=A0 =C2=A0 =C2= =A0 =C2=A0,to_char(query_start, 'YYYY-MM-DD HH24:MI:SS.MS') as =C2=A0qry_start
=C2=A0 =C2=A0 =C2=A0 =C2=A0,(no= w() - query_start)::INTERVAL MINUTE TO SECOND as qry_elapsed
=C2=A0 =C2= =A0 =C2=A0 =C2=A0,cast(state as char(11)) as state
from pg_stat_activity=
WHERE pid !=3D pg_backend_pid()
and state !=3D 'idle';
= =C2=A0 =C2=A0pid =C2=A0 | =C2=A0db =C2=A0| =C2=A0usename =C2=A0 | =C2=A0 = =C2=A0 =C2=A0 =C2=A0qry_start =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0 =C2=A0 = =C2=A0 qry_elapsed =C2=A0 =C2=A0 =C2=A0 | =C2=A0 =C2=A0state =C2=A0 =C2=A0<= br>---------+------+------------+-------------------------+----------------= ---------+-------------
=C2=A0 657996 | =C2=A0 =C2=A0 =C2=A0| replicator= | 2024-11-11 21:03:00.992 | 57 days 16:38:22.342449 | active =C2=A0 =C2=A0=
=C2=A04070070 | TAPc | TAP =C2=A0 =C2=A0 =C2=A0 =C2=A0| 2025-01-08 13:= 41:23.202 | 00:00:00.132817 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | active =C2=A0 =C2= =A0
=C2=A04070069 | TAPc | TAP =C2=A0 =C2=A0 =C2=A0 =C2=A0| 2025-01-08 = 13:41:23.140 | 00:00:00.194222 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | active =C2=A0 = =C2=A0
=C2=A04070065 | TAPc | TAP =C2=A0 =C2=A0 =C2=A0 =C2=A0| 2025-01-= 08 13:41:23.238 | 00:00:00.096418 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | active =C2= =A0 =C2=A0
(4 rows)



--
Death t= o <Redacted>, and butter sauce.
Don't boil me, I'm still = alive.
<Redacted> lobster!
=
--000000000000a8ea09062b3678ae--