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.96) (envelope-from ) id 1vgR6F-00Ccmb-1m for pgsql-hackers@arkaria.postgresql.org; Thu, 15 Jan 2026 17:25:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vgR6E-000rcb-2D for pgsql-hackers@arkaria.postgresql.org; Thu, 15 Jan 2026 17:25:34 +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.96) (envelope-from ) id 1vgR6E-000rcT-1H for pgsql-hackers@lists.postgresql.org; Thu, 15 Jan 2026 17:25:34 +0000 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vgR6C-000ev5-2C for pgsql-hackers@lists.postgresql.org; Thu, 15 Jan 2026 17:25:34 +0000 Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-64d30dc4ed7so2357970a12.0 for ; Thu, 15 Jan 2026 09:25:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768497931; x=1769102731; 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=qnluLRYR9r6oE5Uf4REZDv/ElsB1UTTYNRmxXm3vpwo=; b=OrvURYXFTiP1Eaku8bhs8VVHPds9GBhAXr0VARNbGNBQ95R+jqoa6at3jHh6XYq58l gNGd8pg5D7adONp6Fb9rxfMDQafxQ4jZJnWChfZiwY5tPn+GxAf6G8v4D0z0vPNuLpHY MVeobZFm91o/v0MW5lDtY2Kj6+UzGr8d2niByoN9vSRU3qq9HUKspHBZTN7IobQ/f5fm 1AU8nH8chhQ5ru4hg49LwbrcG57jMxB7aiioi21mf+BZYa2lIlipha1Fjt7oLNnKh7Vh 5uj19wBQQ90FYXneko/teLqRFtEcAo2xj3XXxGHdKF2wz8P2XKOl5YSjwnH18lJpBBII KNUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768497931; x=1769102731; h=content-transfer-encoding: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=qnluLRYR9r6oE5Uf4REZDv/ElsB1UTTYNRmxXm3vpwo=; b=RMacoMk+m2FpxT9I1RRxmLQiALlA8eDGMRGsfo8EQiytGLSxc0uGsQOdvrxIq67j6A vrkR74lWQ2NMxIoaTzpqSxOw7dLX/DACfqx62RWSLhJchgav8XInn+LnG0KH09fSaxhx sxTdmQGYJr7b/pzyi8jwKrKUFq8aS7/1VzIWRYH+8HZFyJDUCkFxZRRUAcuG8NmVdx6j Pe/O12SqzUCkNBLDnfulN0/4Vcci/CBqcJT99hpSxzsZ+3kfQJzqZsK1nIJE/LGhi9Vm jRXlmNK8x3BOkW+jdg6aekZmt+m62EpLVa4AhAQMbovFqk4QnWucdYRc3lWTN5iTLbm0 BtLg== X-Gm-Message-State: AOJu0YwEHdVd00rmr03ZjW1/DPpm/Zea6V6OAfw5EunMiH62NiXeLudf zb+aA9sUTr5YS+i1ZvqyTWO/Uo5k5Jh0zpUuwVXitOMsM1d0b2yxGx1n90pibJQp+iXB4hh8j12 mjHmS+B0zXyp6/hf99Mrf10r4xLIvxVI= X-Gm-Gg: AY/fxX7g/YnUETKgoNxjV9NZrMaq6nYk9cGHdkox+3+073eENcNoPWb+L5JDAejMXPZ R4Qnoyj4ZHBA3vC5wWxp7dsZAFDho2uJfJyv3xdonX1/TmlLP9meHmefXign2nELywRvvUBxTeH g6M9QRag1iCp0Gvz5Vrakka/3FW4X2ey+Lk0wyDTTZEW/P3ecwxH/brNvdhLbVs4SPiC9TgcJhB h5V6ANn1SGnZ/u2XMgFdok6DVh2KL/TNCpp7orqoTnoduiH4L1xhA2nU4KPg1HMz9I= X-Received: by 2002:a05:6402:34c1:b0:64d:170:79a3 with SMTP id 4fb4d7f45d1cf-65452acb1dcmr190521a12.20.1768497931040; Thu, 15 Jan 2026 09:25:31 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Sami Imseih Date: Thu, 15 Jan 2026 11:25:18 -0600 X-Gm-Features: AZwV_Qgrx7iLEZI5j9SIKMU1n7iemNa0d9eMd16CK_Y4ms6yZZxSdW_EQXJKw7w Message-ID: Subject: Re: Flush some statistics within running transactions To: Bertrand Drouvot Cc: pgsql-hackers@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 > > > The 1 second flush interval is currently hardcoded but we could imagi= ne increase > > > it or make it configurable. > > > > Someone may want to turn this off as well. I think a GUC will be needed= . > > I gave this more thoughts and I wonder if this should be configurable at = all. > I mean, we don't do it for PGSTAT_MIN_INTERVAL, PGSTAT_MAX_INTERVAL and > PGSTAT_IDLE_INTERVAL. We could imagine make it configurable if it produce= s > noticeable performance impact but that's not what I observed. Is there a reason we need a new constant (PGSTAT_ANYTIME_FLUSH_INTERVAL) for anytime flushes and can't rely on the existing PGSTAT_MIN_INTERVAL? Also, How did you benchmark? I am less concerned about long running transactions, background processes and more about short/high concurrency transactions see= ing additional overhead due to additional flushing. Is that latter a concern? > > > stats: numscans, tuples_returned, tuples_fetched, blocks_fetched, > > > blocks_hit > > > > I=E2=80=99m concerned that fields being temporarily out of sync might i= mpact monitoring > > calculations, if the formula is dealing with fields that have > > different flush strategies. > > That's a good point. Maybe we should document the fields flush strategy? Yeah, we will need to document this. > > That said, minor discrepancies are usually tolerable for monitoring > > data analysis. > > > > For the numscans, should we not also update the scan timestamp? > > The problem is that we could not call GetCurrentTransactionStopTimestamp(= ), so > we would need to call GetCurrentTimestamp() instead. I'm not sure that ca= lling > GetCurrentTimestamp() every second would be a real issue though, and if i= t is > maybe we could increase this 1s value. > That said I agree that having seq_scan being updated and not last_seq_sca= n is not > that great. with v3 , I checked by running seq scans in a long running transaction, and I observed both for these values being updated at the same time. I thin= k this is OK. # pgstat_relation_flush_anytime_cb ``` tabentry->numscans +=3D lstats->counts.numscans; if (lstats->counts.numscans) { TimestampTz t =3D GetCurrentTimestamp(); if (t > tabentry->lastscan) tabentry->lastscan =3D t; } ``` and # pgstat_relation_flush_cb ``` if (lstats->counts.numscans) { TimestampTz t =3D GetCurrentTransactionStopTimestamp(); if (t > tabentry->lastscan) tabentry->lastscan =3D t; } ``` -- Sami Imseih Amazon Web Services (AWS)