Hi,

On Fri, Nov 13, 2026 at 01:22:27PM -0600, Sami Imseih wrote:
> With v19, your example reports n_tup_ins = 1 during the sleep. I added
> a test for this in stats.sql.

Thanks for the new patch version!

> I also spent some more time looking at this patch, and found a few
> unrelated fixes:
> 
> 1/ I removed the CHECK_FOR_INTERRUPTS() from the flush loop. The loop
> is short anyway, and the check could let a cancel request turn the
> flush at idle into an ERROR after the query had already finished.

What about omitting the CFI only for idle flush case?

Also, I think this:

+       deadtuples -= rel->pgstat_info->tab.counts_xact.delta_dead_tuples -
+           rel->pgstat_info->tab.flushed_xact.delta_dead_tuples;

can produce a wrong n_dead_tup value after a committed TRUNCATE. For example:

"
CREATE TABLE analyze_flush_bug(id int) WITH (autovacuum_enabled = off);

CREATE PROCEDURE analyze_flush_probe(
  INOUT after_first_flush bigint DEFAULT NULL,
  INOUT after_analyze bigint DEFAULT NULL)
LANGUAGE plpgsql AS $$
BEGIN
  BEGIN
    INSERT INTO analyze_flush_bug SELECT generate_series(1, 5);
    RAISE EXCEPTION 'abort subxact';
  EXCEPTION WHEN OTHERS THEN
    NULL;
  END;

  PERFORM pg_stat_force_next_flush();

  SELECT n_dead_tup INTO after_first_flush
    FROM pg_stat_user_tables
    WHERE relname = 'analyze_flush_bug';

  TRUNCATE analyze_flush_bug;
  COMMIT;

  ANALYZE analyze_flush_bug;

  SELECT n_dead_tup INTO after_analyze
    FROM pg_stat_user_tables
    WHERE relname = 'analyze_flush_bug';
END
$$;

CALL analyze_flush_probe();
"

produces:

 after_first_flush | after_analyze
-------------------+---------------
                 5 |             5


I'd expect after_analyze to be 0. Maybe the flushed live/dead tuple baselines
should also be reset when a committed TRUNCATE resets the corresponding counts?

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com


Reply via email to