Icinga postgres database disk capacity

Hello
I took over a system on which I am experiencing a disk space issue in /var
Some tech details here:

icinga2 - The Icinga 2 network monitoring daemon (version: r2.13.7-1)

OS: RHEL 7.9 

Database: psql (PostgreSQL) 9.6.24

icinga2 feature list:
Disabled features: compatlog debuglog elasticsearch gelf graphite icingadb influxdb influxdb2 opentsdb perfdata statusdata syslog
Enabled features: api checker command ido-pgsql livestatus mainlog notification

So - I have a problem with the postgresql database being occupied on the icinga masterinstance.
The icinga_primary database will take over 12GB

[root@master-instance base]# pwd
/var/lib/pgsql/9.6/data/base

[root@master-instance base]# du -sk *
11572032        22270


postgres=# SELECT datname,oid from pg_database;
    datname     |  oid
----------------+-------
 icinga_primary | 22270

To sort out old entries in history tables myself, I added to the configuration:

/etc/icinga2/features-enabled/ido-pgsql.conf
library "db_ido_pgsql"

object IdoPgsqlConnection "pgsql-ido" {
  host = "127.0.0.1"
  port = "5432"
  user = "icinga"
  password = "xxx"
  database = "icinga_primary"
  cleanup = {
    commenthistory_age = 180d
    downtimehistory_age = 180d
    flappinghistory_age = 180d
    statehistory_age = 180d
    logentries_age = 180d
  }
}

After reboot it took a while, Icinga actually deleted the old data (the oldest one is now as in the file - it is 180 days old, before I had data even from 3 years ago).

These actions, unfortunately, did not bring a significant decrease in the disk space occupied by postgres.
Folder with database still consume about 12GB.

I checked more - and here’s what I found the largest tables:

    table_schema    |               table_name               | row_estimate |   total    |   index    |   toast    |   table    |   total_size_share
--------------------+----------------------------------------+--------------+------------+------------+------------+------------+----------------------
 public             | icinga_statehistory                    |  1.98511e+06 | 8647 MB    | 4135 MB    | 16 MB      | 4496 MB    |    0.765207579729864
 public             | icinga_downtimehistory                 |  1.73735e+06 | 1534 MB    | 662 MB     | 8192 bytes | 872 MB     |    0.135766850297017
 public             | icinga_servicestatus                   |        29947 | 828 MB     | 806 MB     | 216 kB     | 22 MB      |     0.07325094857244
 public             | icinga_customvariables                 |       125673 | 69 MB      | 48 MB      | 272 kB     | 20 MB      |  0.00606754499496676
 public             | icinga_customvariablestatus            |       125673 | 62 MB      | 41 MB      | 272 kB     | 21 MB      |  0.00552619498003297
 public             | icinga_notifications                   |        51260 | 26 MB      | 9592 kB    | 80 kB      | 17 MB      |   0.0023098983395834
 public             | icinga_hoststatus                      |         1639 | 23 MB      | 21 MB      | 8192 bytes | 2072 kB    |  0.00204786557373422
 public             | icinga_scheduleddowntime               |          834 | 23 MB      | 11 MB      | 8192 bytes | 12 MB      |  0.00204648281507539
 public             | icinga_objects                         |        31966 | 23 MB      | 18 MB      | 8192 bytes | 4424 kB    |  0.00199601212402792
 public             | icinga_services                        |        28769 | 20 MB      | 6968 kB    | 8192 bytes | 13 MB      |  0.00172568280622573
 public             | icinga_flappinghistory                 |         9446 | 11 MB      | 1680 kB    |            | 9392 kB    | 0.000956868991913627
 public             | icinga_contactnotifications            |        42902 | 10 MB      | 5840 kB    |            | 4544 kB    | 0.000897410369583734
 public             | icinga_servicegroup_members            |        25079 | 7744 kB    | 5368 kB    |            | 2376 kB    | 0.000669255190876005

Question - what do I need to do to significantly reduce the amount of disk space occupied by the icinga_primary database?

Hello Janusz!

Have you tried VACUUM <table name>;/VACUUM FULL <table name>;?

Best,
A/K