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 1vijwZ-00EGKz-0P for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Jan 2026 01:57:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vijwY-00AKZq-0u for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Jan 2026 01:57:06 +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 1vijwX-00AKZU-35 for pgsql-hackers@lists.postgresql.org; Thu, 22 Jan 2026 01:57:06 +0000 Received: from mail-oo1-xc35.google.com ([2607:f8b0:4864:20::c35]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vijwW-001ow3-15 for pgsql-hackers@lists.postgresql.org; Thu, 22 Jan 2026 01:57:06 +0000 Received: by mail-oo1-xc35.google.com with SMTP id 006d021491bc7-6611ca93e45so252571eaf.3 for ; Wed, 21 Jan 2026 17:57:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1769047022; cv=none; d=google.com; s=arc-20240605; b=lVqBp3Z2dQG3h4NWiBaGo49OFJYK9dP0trp18IG6Ugv5LYgPEBAcNnh7jIdQSxM2Ym H/6QycMykySCf2EQ7lBGmjfUAzrmj1K3XtcCBqVq6d8zoBbxzOmA0g8TvZDD1rRUMbxB yc4XrJQ/rRYqU4hJfAMkLoVE55bzQVglkqnt1QTwK1UwnfHQseZSiGU3+KBsHs5TnExh kSG7wF27DFtqOhHFOeITBriorP9sMNkLhdAK2uNAQIicZwCy2V/Yrp8il66mEz8mfRzw FdtCHIJXujPzcLmPObqRXNmjubSoRQ1FYTgaGHrkh2kQb65cJyTnn16UMQaC1xQlWVz8 5yiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=oSc7TvKn1AHer4QKnngiozXqDI8dL0VRTpPR2Kp2smM=; fh=cxEQSHacNRA8+9AMi9TNzCX+zjirsnP1VKEJpo2wanQ=; b=VkjC+G/4OuUz79nP0cxzjqJTEBSsjRHpuzfcRdfQ+w8qFfDH0ZNeYeTCgFHb1xZdsw lNxmdFZHLTjtCvUY8iUMt998ehzOXmd1PvepFo143g3fibdBjqdS47Oo1D06F0VGoMqh mH6drIuANsK6+oXe4LALGy4QXUz10/I3LzNt9xXFJHJ9YDvjIsjpGUMiObkAMlqVsCg1 LuJkx4MHVfRUSz2BmxX7hjhPMwydN4eSCAh05KZwTzw4vfA8WNNU7BedN4/Hjd+/DGip CBXxDw1j/Xrp658Ea/4d+TmUb7O9/2AlGzWHjZjttfo3FBtDojNky+4mo0pZ417JiRob qRew==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769047022; x=1769651822; 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=oSc7TvKn1AHer4QKnngiozXqDI8dL0VRTpPR2Kp2smM=; b=S/+R+diBtMyQS7DszeaYPrnuQEtnzWyO7ZtGf9Xz96p3AEFLElivP1L1MSj2Q1SRYv wl1Tg5a3NLZuXznAxAIZOpoAOxiCetVJDrSMkQI+vdXf8cUugwywreCiqzjIZJf9rPMH Nl908Fy8OjuBCF3WpyLUi5J0hmec7KJE4KXaDbkk++Qv6fASgfMg5GonfSaXwxux8K6z zRKjxg3+yO+nYKNH+SfHx36/CITzYhVL8cDM4oUE3eZFRs1O8MJsVamQgOXehL0OPZ+X whGBVlZ5YuJdzEnf4gNVCPzH4BQ53Zmq8Wq7xjED7XsOI8Jmyyk05a2SxiMHzxU0y1+F wTDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769047022; x=1769651822; 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=oSc7TvKn1AHer4QKnngiozXqDI8dL0VRTpPR2Kp2smM=; b=Gr3n9pbfKZ4cAnC7TkeZWwu7eitCIk0EfhXp7VfsYfiSHQyOREvC1DuwhAThRexgxr BgqibWP3bhJZr5AyQgbETgfxx+6SnHEXp+KPqoj6EUnSQfBkKPtPPKzLHy3qYzIMPNYt cYhgC0ovNKNPRqGfyszxOF78ZOpgGPx0dAD1e4cNJpkvoUdF1XCtaSdC+WGukNfAf4rS lwTolzocGHca1OOqeRZ2kRJMiMEF3K1Dic3IRRKjmfxo6SKeoD50CpjlmrSX0wNyAwXK kG0/ZnYdgdRrqyc1K2gNfbQ6VEYovoNtEskdUYZhJXIcPK1VfraOtrjLfvfOzKXscg9g vjIQ== X-Forwarded-Encrypted: i=1; AJvYcCVJeEJ7ATTe4L5ym0ahgmZCaI68zI3/oV/QtVzJMW4VFr0UTL+sBLpDAJcW2qt/x/C993JoYLSzA3IiZk5+@lists.postgresql.org X-Gm-Message-State: AOJu0YwTDMeSaIrxJ/Wcej15wLWgwOgk1EqZEoBhDTSQvo8Qaysnmm0w Z2FPE/tzK0JE44QvULf2Cdo55A0Yf7Q4z3WcNuaseziPThqPDM8PZlsFnWjUVCqqkswhncpItvp 3OFAGbngSffC4OD2+XkC6Jmm5+xd3hmQ= X-Gm-Gg: AZuq6aKksT8C6z61oxQAH+vPS7o3KWgJPqa/Z0F76npSP2UaZWz8RgRxQNfpAPRHeFV lIw8W5TIP2us1f3QvUeqE5JsfMo233STEGd5nBllo/O7FbmB0rNeRQtCwt/1Bh+rgKj+NQPLV3v aiWIzgq9y1uLAbfJphUrkGfKjmOV0m8BLBngoKSKQmVJ+ClFl+ON03f8TmRbt7qeOPBt4naR9aQ rKuPvj//MWD2uEUzd6thmuk7NEAKmhvAjaYdfC1GBTRm1LOo6ef3Q+clLlmHfpypwJkCtyN266m +/gPvEnU8WvAVnhP5I1xjL2KO6Oycw== X-Received: by 2002:a05:6820:2114:b0:662:b84b:d715 with SMTP id 006d021491bc7-662b84bda38mr1914948eaf.12.1769047022272; Wed, 21 Jan 2026 17:57:02 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Fujii Masao Date: Thu, 22 Jan 2026 10:56:48 +0900 X-Gm-Features: AZwV_Qi1qxqCAxvp3k-TjfkGYzgD4N3F6r878oYzl7KC85har7kND6J9PYewQmk Message-ID: Subject: Re: Flush some statistics within running transactions To: Sami Imseih Cc: Michael Paquier , Bertrand Drouvot , pgsql-hackers@lists.postgresql.org, Zsolt Parragi 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 Thu, Jan 22, 2026 at 10:41=E2=80=AFAM Sami Imseih = wrote: > > > > No, 0003 also changes the flush mode for the database KIND. All the f= ields that > > > I mentioned are inherited from relations stats and are flushed only a= t transaction > > > boundaries (so they don't appear in pg_stat_database until the transa= ction > > > finishes). Does that make sense? (if the database kind is not switche= d to > > > flush any time then none would appear while the transaction is in pro= gress, even > > > the ones inherited from relations stats). > > > > > > PFA v3, also taking care of Zsolt's comment (thanks!) done up-thread. > > > > While reading through 0001, I got to question on which properties > > and/or assumptions of a stats kind one has to rely on to decide to > > what flush_mode should be set. To put is simpler, why don't we just > > do a periodic pgstat_report_stat(false) call that would flush all the > > stats for all stats kinds based on the new timeout registered, > > expanding a bit the flush we currently do when idle in > > ProcessInterrupts()? > > There are some important cases in which we would want to > distinguish between a "transaction boundary" flush vs an > "anytime" flush. > > For example, xact_commit/rollback. I would want those > fields to be in sync with tuples_inserted/updated/deleted > to allow for accurate calculations like number of inserts > per commit, etc. > > Another one would be n_mod_since_analyze, That should > only be updated after commit (or not after rollback). Otherwise, > it may throw autovanalyze threshold calculations way off. Same > for n_dead_tup and autovacuum. > > > I am also not convinced that we have to be that aggressive with these > > extra flushes. The target is long-running analytical queries, that > > could take minutes or even hours. Using the same value as > > PGSTAT_IDLE_INTERVAL (10s), > > PGSTAT_IDLE_INTERVAL is flushing an idle backend every 10 seconds > IIUC. So this value only applies when outside of a transaction. > > > A 1s vs 10s report interval does not really matter for long analytical = queries. > > Sure, Bertrand mentioned early in the thread that the anytime flushes > could be made configurable. Perhaps that is a good idea where we can > default with something large like 10s intervals for anytime flushes, but = allow > the user to configure a more frequent flushes ( although I would think > that 1 sec is the minimum we should allow ). +1 on adding an option to control the interval. With a fixed interval (for example, 1s), log_lock_waits messages could be emitted that frequently= , which may be annoying for some users. Of course, it would be even better if these periodic wakeups did not trigge= r log_lock_waits messages at all, though. Regards, --=20 Fujii Masao