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 1uP1C1-00FmRj-Rj for pgsql-general@arkaria.postgresql.org; Tue, 10 Jun 2025 15:47:17 +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 1uP1Bz-0066Fd-Sx for pgsql-general@arkaria.postgresql.org; Tue, 10 Jun 2025 15:47:16 +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 1uP1Bz-0066FV-IY for pgsql-general@lists.postgresql.org; Tue, 10 Jun 2025 15:47:16 +0000 Received: from mail-vk1-xa30.google.com ([2607:f8b0:4864:20::a30]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uP1By-001G93-28 for pgsql-general@lists.postgresql.org; Tue, 10 Jun 2025 15:47:15 +0000 Received: by mail-vk1-xa30.google.com with SMTP id 71dfb90a1353d-530807a8691so1885867e0c.0 for ; Tue, 10 Jun 2025 08:47:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749570432; x=1750175232; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=3r1RZ21fySem63hQ/ZjscklMATdpRb9dfjNzYm/QKXw=; b=IQQfWY8KXvmnwPjWuztj4ZssUxYAmgclRyOwTu9Dv36DRzFhCK9t9ZZv0vuA8fl7Bq TWHI9eRnbZK8IHK6pPLOyjf6thSFHOCwjITCPCsWLCRSyaLw9IhpHDBEtXu1OrXMCvYy rRPxzR9ec6kdq1Xd5wDATgXDbEg/ka4uiKyAeETkqntVLjaQGD3Kv0F+Gh56ezDh6JHa Ry1ixSWRmsIFe/Ft8oKn+JmEVjcBhqG3EgZPA2UxD/ib1Vg6VCDWNcaHSTR/9j5i4DNM EjF1LnprSGvM5YmsuYNSvTcH1GGbMLziDXjt1Nnbdk3TwIpA42WG1Yb6u0dWNNHLmjX2 UUIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749570432; x=1750175232; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3r1RZ21fySem63hQ/ZjscklMATdpRb9dfjNzYm/QKXw=; b=E78Jpon2UzgFH5unQXulnmdKIY5xhoC0aIGcEB8zgh+RcwnMGRygzxme9amVgiW+VS ZlLDBxaA6Ucj+rv/ofATTWcqcdAns8n0kz7I+YXSPCqzne1M3+Ao4jaUvPJnClRokydL 5aSfGOti5qEHUxQ6C22xkyz6MSQyHvGaxREem2HnEoQFHkU/D6/8yKoZb2Dpy5rH0o5C sdhKcozZZbTsy3gtjefHtI3ULbJAizwsfGZOSiHMkQ8eAI5dehMkI14xO5YGWp9Mye25 yZ1VmyZWF3amQ7kEnHdwYXKUnY7IG3Pvdk965FIxBY6/CjCuTmgXcc6/RZBxIOgjynj3 /eoA== X-Gm-Message-State: AOJu0YyxfmKa4hVXEVBGvPF9ApbhrQZDG0zDX0n40nV6acMDEhmYJHMr xK2yZsqkAGhJ/lA5ZuHnQUINjSloRSYfPGMzRDajBAZbVupTVn7nqjPAIDaZG2lsYimFFApNswg v4SGNCS6Do0h2Vun4J40UW/Mr5ezmQjOjow== X-Gm-Gg: ASbGncuTdyj4yKuvawafIHXailXUwVihG2gEciFZfUUPpqp7gWtRgRXAI+peIphPOM6 pu/YcDB5kx8z0hgTddZVE61KJ4yr/9wCJ1+jFix+4PhDY6YL51dFNF/pDPtMu4HTcbhAOdd83Y/ NZyjEq56MYEcL+ucUQC5XW4+bUZYqWMseRvqEx68Jr6pSzKQ== X-Google-Smtp-Source: AGHT+IHm1cG5E/EYzwdvZfNeeEHLN1dcTcNONNuwIMDxbkLjO5tEUfHFg9+UZIJoPAFRHSGkjpShGl+lnWXAXtBx8T8= X-Received: by 2002:a05:6871:b12:b0:29e:48d6:2e62 with SMTP id 586e51a60fabf-2ea0083f215mr11939459fac.9.1749570421761; Tue, 10 Jun 2025 08:47:01 -0700 (PDT) MIME-Version: 1.0 References: <755975.1749565677@sss.pgh.pa.us> In-Reply-To: <755975.1749565677@sss.pgh.pa.us> From: Dominique Devienne Date: Tue, 10 Jun 2025 17:46:50 +0200 X-Gm-Features: AX0GCFt5E8Mw6ZqwuUufEQouxlx-pDdFJwStSXK5e41-mDnutr6e9lrYIVOlCqA Message-ID: Subject: Re: is pg_stat_activity "transactional"? How fast does it update? To: Tom Lane Cc: pgsql-general@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Jun 10, 2025 at 4:27=E2=80=AFPM Tom Lane wrote: > Dominique Devienne writes: > > So when and how fast does pg_stat_activity update, in the face of a > > PQfinish? > > The shared state underlying pg_stat_activity is updated > immediately when something changes. However ... > > PQfinish is asynchronous: it sends a "goodbye" message and then > closes the connection without waiting for a response. So > depending on system load, the associated backend could still be > alive for some milliseconds. There might be other client > libraries that do that differently. > > Another thing that might be biting you is that a backend inspecting > pg_stat_activity() takes a snapshot of the view's contents and then > holds onto that snapshot until end of transaction. You can get > around that with pg_stat_clear_snapshot(). Many thanks Tom. Didn't know either of those facts. --DD