Re: Add missing stats_reset column to pg_stat_database_conflicts view

From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Sami Imseih <samimseih(at)gmail(dot)com>
Cc: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, shihao zhong <zhong950419(at)gmail(dot)com>, Kirill Reshke <reshkekirill(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Add missing stats_reset column to pg_stat_database_conflicts view
Date: 2026-03-12 18:09:19
Message-ID: CAHGQGwF3=y-j5LxHdXtthEsmJYY5U6WtcAsgwbestfCtNvvuaw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Mar 13, 2026 at 1:21 AM Sami Imseih <samimseih(at)gmail(dot)com> wrote:
>
> Thanks for the updated patch!
>
> --- Since pg_stat_database stats_reset starts out as NULL, reset it
> once first so we have something to compare it to
> +-- Since stats_reset in pg_stat_database and pg_stat_database_conflicts starts
> +-- out as NULL, reset it once first so we have something to compare it to
> SELECT pg_stat_reset();
> -SELECT stats_reset AS db_reset_ts FROM pg_stat_database WHERE datname
> = (SELECT current_database()) \gset
> +SELECT D.stats_reset AS db_reset_ts, DC.stats_reset AS dbc_reset_ts
> +FROM pg_stat_database D, pg_stat_database_conflicts DC
> +WHERE D.datname = (SELECT current_database()) AND D.datname = DC.datname \gset
> SELECT pg_stat_reset();
> -SELECT stats_reset > :'db_reset_ts'::timestamptz FROM
> pg_stat_database WHERE datname = (SELECT current_database());
> +SELECT D.stats_reset > :'db_reset_ts'::timestamptz,
> + DC.stats_reset > :'dbc_reset_ts'::timestamptz,
> + D.stats_reset = DC.stats_reset
> +FROM pg_stat_database D, pg_stat_database_conflicts DC
> +WHERE D.datname = (SELECT current_database()) AND D.datname = DC.datname;
>
> I think the changes to the test are overcomplicated unnecessarly. We should not
> have to join pg_stat_database and pg_stat_database_conflicts. We can just
> query each fo the stats_reset separately. see v5, I kept the check to
> ensure that
> pg_stat_database and pg_stat_database_conflicts have the same reset
> time. I think
> this is good to have as well. I also updated the existing comment for
> more clarity.

Thanks for updating the patch! I like the simplified test.

+SELECT stats_reset AS dbc_reset_ts FROM pg_stat_database_conflicts
WHERE datname = (SELECT current_database()) \gset

I removed the extra space.

I also made some cosmetic indentation fixes in the docs.
The v6 patch is attached.

Unless there are objections, I'll update the catversion and commit it.

Regards,

--
Fujii Masao

Attachment Content-Type Size
v6-0001-Add-stats_reset-column-to-pg_stat_database_confli.patch application/octet-stream 6.4 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alena Rybakina 2026-03-12 18:10:49 Re: Vacuum statistics
Previous Message Alena Rybakina 2026-03-12 17:57:34 Re: Vacuum statistics