Hello.
Statistics sender logic during usual commit and two-phase commit do not strictly matches each other and that leads to
delta_live_tuples added to n_live_tup in case of truncate in two phase commit.
That can be see in following example:
CREATE TABLE trunc_stats_test5(id serial);
INSERT INTO trunc_stats_test5 DEFAULT VALUES;
INSERT INTO trunc_stats_test5 DEFAULT VALUES;
INSERT INTO trunc_stats_test5 DEFAULT VALUES;
BEGIN;
TRUNCATE trunc_stats_test5;
PREPARE TRANSACTION 'twophase_stats';
COMMIT PREPARED 'twophase_stats';
After that pg_stat_user_tables will have n_live_tup = 3 instead of 0.
Fix along with test is attached.
--
Stas Kelvich
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company