| From: | Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com> |
|---|---|
| To: | Sami Imseih <samimseih(at)gmail(dot)com> |
| Cc: | pgsql-hackers(at)lists(dot)postgresql(dot)org, Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com> |
| Subject: | Re: Flush some statistics within running transactions |
| Date: | 2026-01-22 09:52:41 |
| Message-ID: | aXHzafdxaklDSWXp@ip-10-97-1-34.eu-west-3.compute.internal |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
On Wed, Jan 21, 2026 at 05:41:13PM -0600, Sami Imseih wrote:
> Thanks for the updated patches!
>
> > No, 0003 also changes the flush mode for the database KIND. All the fields that
> > I mentioned are inherited from relations stats and are flushed only at transaction
> > boundaries (so they don't appear in pg_stat_database until the transaction
> > finishes). Does that make sense?
>
> yes, I understand it clearly now.
>
> But, the Note under pg_stat_database reads like this:
>
> "All the statistics are updated while the transactions are in progress,
> except for xact_commit, xact_rollback, tup_inserted, tup_updated
> and tup_deleted that are updated only when the transactions finish."
>
> But that is not true for all pg_stat_database fields, such as session_time,
> active_time, idle_in_transaction_time, etc. From what I can tell some of their
> fields are updated when the connection is closed. For example
> in one session run "select pg_sleep(10)" and in another session monitor
> pg_stat_database.active_time. That will not be updated until the session
> is closed.
>
> This is because these are not relation stats, which makes sense. The
> Note section should elaborate more on this, right?
Yeah, so, while pgstat_database_flush_cb() is now called every second (if there
are pending stats), not all the stats would have their pending entries updated.
For example, pgstat_update_dbstats() updates some of them: xact_commit, xact_rollback,
blk_read_time, blk_write_time, session_time, active_time and idle_in_transaction_time
but only at transaction boundaries. Indeed, pgstat_update_dbstats() is only called
during pgstat_report_stat() and not during pgstat_report_anytime_stat().
I think that we could:
1. Update the doc as you suggest
or
2. Call a modified version of pgstat_update_dbstats() in pgstat_report_anytime_stat()
that would update blk_read_time, blk_write_time, session_time, active_time and
idle_in_transaction_time but that would require an extra GetCurrentTimestamp()
call.
or
3. Call a modified version of pgstat_update_dbstats() in pgstat_report_anytime_stat()
that would update the same as in 2. except session_time then avoiding the need
of a GetCurrentTimestamp() extra call.
I'm tempted to vote for 1. as I'm not sure of the added value of 2. and 3.,
thoughts?
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Xuneng Zhou | 2026-01-22 10:02:54 | Re: Add WALRCV_CONNECTING state to walreceiver |
| Previous Message | John Naylor | 2026-01-22 09:50:26 | Re: refactor architecture-specific popcount code |