Fix bugs not to discard statistics when changing stats_fetch_consistency

From: Shinya Kato <Shinya11(dot)Kato(at)oss(dot)nttdata(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Fix bugs not to discard statistics when changing stats_fetch_consistency
Date: 2024-01-11 09:18:38
Message-ID: d77fc5190d4dbe1738d77231488e768b@oss.nttdata.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi, hackers

There is below description in docs for stats_fetch_consistency.
"Changing this parameter in a transaction discards the statistics
snapshot."

However, I wonder if changes stats_fetch_consistency in a transaction,
statistics is not discarded in some cases.

Example:
--
* session 1
=# SET stats_fetch_consistency TO snapshot;
=# BEGIN;
=*# SELECT wal_records, wal_fpi, wal_bytes FROM pg_stat_wal;
wal_records | wal_fpi | wal_bytes
-------------+---------+-----------
23592 | 628 | 5939027
(1 row)

* session 2
=# CREATE TABLE test (i int); -- generate WAL records
=# SELECT wal_records, wal_fpi, wal_bytes FROM pg_stat_wal;
wal_records | wal_fpi | wal_bytes
-------------+---------+-----------
23631 | 644 | 6023411
(1 row)

* session 1
=*# -- snapshot is not discarded, it is right
=*# SELECT wal_records, wal_fpi, wal_bytes FROM pg_stat_wal;
wal_records | wal_fpi | wal_bytes
-------------+---------+-----------
23592 | 628 | 5939027
(1 row)

=*# SET stats_fetch_consistency TO cache;

=*# -- snapshot is not discarded, it is not right
=*# SELECT wal_records, wal_fpi, wal_bytes FROM pg_stat_wal;
wal_records | wal_fpi | wal_bytes
-------------+---------+-----------
23592 | 628 | 5939027
(1 row)
--

I can see similar cases in pg_stat_archiver, pg_stat_bgwriter,
pg_stat_checkpointer, pg_stat_io, and pg_stat_slru.
Is it a bug? I fixed it, and do you think?

--
Regards,
Shinya Kato
NTT DATA GROUP CORPORATION

Attachment Content-Type Size
v1-0001-fix-stats-fetch-consinstency-bugs.patch text/x-diff 3.3 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message shveta malik 2024-01-11 09:33:52 Re: Synchronizing slots from primary to standby
Previous Message Ashutosh Bapat 2024-01-11 09:17:27 Re: Adding facility for injection points (or probe points?) for more advanced tests