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 1tVbxv-009zKA-9U for pgsql-general@arkaria.postgresql.org; Wed, 08 Jan 2025 19:43:43 +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 1tVbxu-005ZZj-MQ for pgsql-general@arkaria.postgresql.org; Wed, 08 Jan 2025 19:43:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tVbxt-005ZZb-QI for pgsql-general@lists.postgresql.org; Wed, 08 Jan 2025 19:43:42 +0000 Received: from fhigh-a4-smtp.messagingengine.com ([103.168.172.155]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tVbxp-000adc-2K for pgsql-general@postgresql.org; Wed, 08 Jan 2025 19:43:41 +0000 Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfhigh.phl.internal (Postfix) with ESMTP id 44AF21140259; Wed, 8 Jan 2025 14:43:37 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Wed, 08 Jan 2025 14:43:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1736365417; x=1736451817; bh=ltHiVn2cgXx/nXW0cN+gEzPX2vJActYlYsnOcmUsZaM=; b= goD9dLzJIwoD1igWmr0Np2dIh+p3l0FHAWcMRHAmy0i6fZJTWeabXBEF7VGnZlMb 86rg8LDs06+Mzqjyu1VcSvxUcOQe+HaS63+WYVTJFXA82JcPUGPIEz1zpGvG/9WH w3zcXqisTBQwFA5XDq0HwaN9981JMvazLwwaeqYQhw3BzpjJdUva2/+N0EP9+AvE QbXDXvM2ETsmBR8qFkH37kuEtip18N6P0HgGP2hBCmA+8xKM4/PD6cjezVWzprmA JfP7h1YmQYVIFiBR8jCpIEslS8MjUfx1qpZ9/pmWWe14YONVAkvvJTKoMgK9nA8l yzp1mJTXlKOIZQ3HdIc9ag== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1736365417; x=1736451817; bh=l tHiVn2cgXx/nXW0cN+gEzPX2vJActYlYsnOcmUsZaM=; b=lS8seUOQ2XydCHdoK a6EH/15CQieUNFez5Zu600R7mKhtDxzZ3wtn2z+iPZAmJ9pR4SeyEUX+VGjNkAuN 8eS6WqYtwEsuzxo9q/YZc8NerdQklT8EOqJdkC3MEi1GNcocNprXll/5ZR+zvQFQ +/iMkp26l8RPG4QEHGZ5gYmG5dsyRFhz1TC2f7tu7RrwlzHziKoycxlIg4DrgmIJ 4LBI/H+qJr6RlBrZAsRwW8pymrKXHnc6IbuK95BuYeDBOtApGQRf4bOxZMhYYpaA BPqG6TPbMwaFCIbgQo6SjGcHz1XokbytDLu2h2IsmTO6gIltx3fpSj4JWU4BlqZm G5ipQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudeggedguddvjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepkfffgg gfuffvfhfhjggtgfesthekredttddvjeenucfhrhhomheptegurhhirghnucfmlhgrvhgv rhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmqeenucggtffrrg htthgvrhhnpefhvdeugedvteehhedtveekhefgjeeviedtudfgvdeijeevveeufefgteek veekkeenucffohhmrghinhepmhhmmhdrihgupdhpohhsthhgrhgvshhqlhdrohhrghdpsh hsrdhmshenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhm pegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmpdhnsggprhgtphhtth hopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehrohhnlhhjohhhnhhsohhn jhhrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepphhgshhqlhdqghgvnhgvrhgrlhesph hoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 8 Jan 2025 14:43:35 -0500 (EST) Message-ID: <8c663eab-6dbd-44f1-a8b5-d25a6a227ea9@aklaver.com> Date: Wed, 8 Jan 2025 11:43:33 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: INTERVAL MINUTE TO SECOND didn't do what I thought it would do To: Ron Johnson , pgsql-general References: Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 1/8/25 11:00 AM, Ron Johnson wrote: > 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. From here: https://www.postgresql.org/docs/current/datatype-datetime.html#DATATYPE-INTERVAL-INPUT "Also, field values “to the right” of the least significant field allowed by the fields specification are silently discarded. For example, writing INTERVAL '1 day 2:03:04' HOUR TO MINUTE results in dropping the seconds field, but not the day field." > > Is there cast magic that does what I want? The only way I can think of extract the epoch from the interval and pass to a function that builds what you 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! -- Adrian Klaver adrian.klaver@aklaver.com