Mmm. I've failed to create a brand-new thread.. Thank you for the comment.
At Fri, 20 Oct 2017 19:15:16 +0900, Masahiko Sawada <sawada.m...@gmail.com> wrote in <CAD21AoAkaw-u0feAVN_VrKZA5tvzp7jT=mqcqp-svmegkxh...@mail.gmail.com> > On Tue, Oct 10, 2017 at 7:26 PM, Kyotaro HORIGUCHI > <horiguchi.kyot...@lab.ntt.co.jp> wrote: > > Hello. > > Once in a while I am asked about table bloat. In most cases the > > cause is long lasting transactions and vacuum canceling in some > > cases. Whatever the case users don't have enough clues to why > > they have bloated tables. > > > > At the top of the annoyances list for users would be that they > > cannot know whether autovacuum decided that a table needs vacuum > > or not. I suppose that it could be shown in pg_stat_*_tables. > > > > n_mod_since_analyze | 20000 > > + vacuum_requred | true > > last_vacuum | 2017-10-10 17:21:54.380805+09 > > > > If vacuum_required remains true for a certain time, it means that > > vacuuming stopped halfway or someone is killing it repeatedly. > > That status could be shown in the same view. > > Because the table statistics is updated at end of the vacuum I think > that the autovacuum will process the table at the next cycle if it has > stopped halfway or has killed. So you mean that vacuum_required is for > uses who want to reclaim garbage without wait for autovacuum retry? It could be used for the purpose and for just knowing that a table is left for a long time needing a vacuum and it would be a trigger for users to take measures to deal with the situation. > > n_mod_since_analyze | 20000 > > + vacuum_requred | true > > last_vacuum | 2017-10-10 17:21:54.380805+09 > > last_autovacuum | 2017-10-10 17:21:54.380805+09 > > + last_autovacuum_status | Killed by lock conflict > > > > Where the "Killed by lock conflict" would be one of the followings. > > > > - Completed (oldest xmin = 8023) > > - May not be fully truncated (yielded at 1324 of 6447 expected) > > - Truncation skipped > > - Skipped by lock failure > > - Killed by lock conflict > > > > > > If we want more formal expression, we can show the values in the > > following shape. And adding some more values could be useful. > > > > n_mod_since_analyze | 20000 > > + vacuum_requred | true > > + last_vacuum_oldest_xid | 8023 > > + last_vacuum_left_to_truncate | 5123 > > + last_vacuum_truncated | 387 > > last_vacuum | 2017-10-10 17:21:54.380805+09 > > last_autovacuum | 2017-10-10 17:21:54.380805+09 > > + last_autovacuum_status | Killed by lock conflict > > ... > > autovacuum_count | 128 > > + incomplete_autovacuum_count | 53 > > > > # The last one might be needless.. > > I'm not sure that the above informations will help for users or DBA > but personally I sometimes want to have the number of index scans of > the last autovacuum in the pg_stat_user_tables view. That value > indicates how efficiently vacuums performed and would be a signal to > increase the setting of autovacuum_work_mem for user. Btree and all existing index AMs (except brin) seem to visit the all pages in every index scan so it would be valuable. Instead the number of visited index pages during a table scan might be usable. It is more relevant to performance than the number of scans, on the other hand it is a bit difficult to get something worth from the number in a moment. I'll show the number of scans in the first cut. > > Where the "Killed by lock conflict" is one of the followings. > > > > - Completed > > - Truncation skipped > > - Partially truncated > > - Skipped > > - Killed by lock conflict > > > > This seems enough to find the cause of a table bloat. The same > > discussion could be applied to analyze but it might be the > > another issue. > > > > There may be a better way to indicate the vacuum soundness. Any > > opinions and suggestions are welcome. > > > > I'm going to make a patch to do the 'formal' one for the time > > being. regards, -- Kyotaro Horiguchi NTT Open Source Software Center -- Sent via pgsql-hackers mailing list (firstname.lastname@example.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers