Bug in PostgreSQL Bloat calculation

CMK version: 2.3.0p31

Error message:

I have a database with a size of 450MB reported in check_mk.
check_mk reports the bloat of 561MB, which can be correct, because the database can’t waste more then it has.

So I’ve inspected the output of agent for bloat calculation:

my_db_test;dfbk;rx_test_tbl;9439;9687;1280;0.868;8407;68870144;68870144;rxtest_test_pkey;9439;110;1222;0.000;0;0;0;68870144
my_db_test;dfbk;rx_test_tbl;9439;9687;1280;0.868;8407;68870144;68870144;rxtesttest_fid;9439;88;1222;0.000;0;0;0;68870144
my_db_test;dfbk;rx_test_tbl;9439;9687;1280;0.868;8407;68870144;68870144;rxtesttest_ffg;9439;79;1222;0.000;0;0;0;68870144
my_db_test;dfbk;rx_test_tbl;9439;9687;1280;0.868;8407;68870144;68870144;rxtesttest_ktyp;9439;100;1222;0.000;0;0;0;68870144
my_db_test;dfbk;rx_test_tbl;9439;9687;1280;0.868;8407;68870144;68870144;rxtesttest_afid;9439;91;1222;0.000;0;0;0;68870144
my_db_test;dfbk;rx_test_tbl;9439;9687;1280;0.868;8407;68870144;68870144;rxtesttest_id44;9439;108;1222;0.000;0;0;0;68870144
my_db_test;dfbk;rx_test_tbl;9439;9687;1280;0.868;8407;68870144;68870144;rxtesttest_gid;9439;110;1222;0.000;0;0;0;68870144
my_db_test;dfbk;rx_test_tbl;9439;9687;1280;0.868;8407;68870144;68870144;rxtesttest_geom;9439;424;1222;0.000;0;0;0;68870144
my_db_test;dfbk;tmp0_test_tbl;9439;3588;1290;0.640;2298;18825216;18825216;testtbl_lfid;9439;68;1230;0.000;0;0;0;18825216
my_db_test;dfbk;tmp0_test_tbl;9439;3588;1290;0.640;2298;18825216;18825216;testtbl_id44;9439;87;1230;0.000;0;0;0;18825216

The 561MB is the sum of all! output lines of the postgresql agent. In the lines are the bloat values for index and table.
In some tables there are multiple indexes like shown in this example. So the table values are existing multiple times if there are more the one indexes per table and are summed up incorrectly:
(688701448+188252162) = 561MB (this is the values which check_mk shows me).

Correct is only to sum up one table bloat value per table from these lines (68870144+18825216) = 83MB.

It would be nice to fix this bug. The current calculation of bloat aren’t helpful for monitoring and preparing maintenance.

As I can see in the source the bug still exists, line 63 sum up every value for agent output for table bloat:

1 Like