Clean up postgres to recover storage

we have MAAS 3.4 in deployed running as a region+rack controller. we have used the same system to test various deployments to various machines and the postgres database files have ballooned to over 60gb, and there is no change in database size even after removing all machines, custom images, and running vacuum on the database. Is there a better way to go about this? we would simply like to reset maas to a fresh installation state.

Could you post the full output of the following query?

select
  table_name,
  pg_size_pretty(pg_total_relation_size(quote_ident(table_name))),
  pg_total_relation_size(quote_ident(table_name))
from information_schema.tables
where table_schema = 'public';

btw if you want to start from scratch why don’t you drop the db, create a new one and re-initialize MAAS?

This is of interest to me too - here is our output from that for reference.

                    table_name                    | pg_size_pretty | pg_total_relation_size 
--------------------------------------------------+----------------+------------------------
 maasserver_discovery                             | 0 bytes        |                      0
 django_session                                   | 592 kB         |                 606208
 maasserver_routable_pairs                        | 0 bytes        |                      0
 maasserver_podhost                               | 0 bytes        |                      0
 django_migrations                                | 80 kB          |                  81920
 django_site                                      | 56 kB          |                  57344
 maas_support__ssh_keys__by_user                  | 0 bytes        |                      0
 auth_user                                        | 80 kB          |                  81920
 auth_group                                       | 24 kB          |                  24576
 auth_permission                                  | 160 kB         |                 163840
 django_content_type                              | 40 kB          |                  40960
 auth_user_user_permissions                       | 32 kB          |                  32768
 auth_user_groups                                 | 32 kB          |                  32768
 maasserver_bootresource                          | 112 kB         |                 114688
 maasserver_bootresourceset                       | 104 kB         |                 106496
 maasserver_bootsource                            | 64 kB          |                  65536
 maasserver_dnsresource                           | 40 kB          |                  40960
 maasserver_fabric                                | 88 kB          |                  90112
 maasserver_dnspublication                        | 400 kB         |                 409600
 maasserver_dnsdata                               | 24 kB          |                  24576
 maasserver_mdns                                  | 24 kB          |                  24576
 maasserver_neighbour                             | 776 kB         |                 794624
 maasserver_globaldefault                         | 40 kB          |                  40960
 maasserver_rootkey                               | 16 kB          |                  16384
 maasserver_resourcepool                          | 64 kB          |                  65536
 maasserver_zone                                  | 64 kB          |                  65536
 maasserver_vmcluster                             | 48 kB          |                  49152
 maasserver_nodekey                               | 160 kB         |                 163840
 maasserver_virtualblockdevice                    | 96 kB          |                  98304
 maasserver_tag                                   | 64 kB          |                  65536
 piston3_consumer                                 | 2544 kB        |                2605056
 piston3_nonce                                    | 15 MB          |               16146432
 piston3_token                                    | 904 kB         |                 925696
 maasserver_domain                                | 72 kB          |                  73728
 auth_group_permissions                           | 32 kB          |                  32768
 maasserver_secret                                | 264 kB         |                 270336
 maasserver_vaultsecret                           | 24 kB          |                  24576
 maasserver_bootsourceselection                   | 64 kB          |                  65536
 maasserver_cacheset                              | 8192 bytes     |                   8192
 maasserver_config                                | 64 kB          |                  65536
 maasserver_filestorage                           | 48 kB          |                  49152
 maasserver_bootresourcefile                      | 128 kB         |                 131072
 maasserver_script                                | 144 kB         |                 147456
 maasserver_bootsourcecache                       | 432 kB         |                 442368
 maasserver_eventtype                             | 88 kB          |                  90112
 maasserver_filesystemgroup                       | 64 kB          |                  65536
 maasserver_forwarddnsserver                      | 24 kB          |                  24576
 maasserver_forwarddnsserver_domains              | 32 kB          |                  32768
 maasserver_interfacerelationship                 | 688 kB         |                 704512
 maasserver_keysource                             | 24 kB          |                  24576
 maasserver_largefile                             | 96 kB          |                  98304
 maasserver_licensekey                            | 24 kB          |                  24576
 maasserver_controllerinfo                        | 112 kB         |                 114688
 maasserver_event                                 | 2984 MB        |             3128549376
 maasserver_bmcroutablerackcontrollerrelationship | 184 kB         |                 188416
 maasserver_nodeconfig                            | 200 kB         |                 204800
 maasserver_blockdevice                           | 3040 kB        |                3112960
 maasserver_nodedevicevpd                         | 1648 kB        |                1687552
 maasserver_nodemetadata                          | 1824 kB        |                1867776
 maasserver_nodeuserdata                          | 2200 kB        |                2252800
 maasserver_notification                          | 80 kB          |                  81920
 maasserver_notificationdismissal                 | 64 kB          |                  65536
 maasserver_numanode                              | 448 kB         |                 458752
 maasserver_nodedevice                            | 25 MB          |               25911296
 maasserver_interface                             | 5728 kB        |                5865472
 maasserver_physicalblockdevice                   | 1384 kB        |                1417216
 maasserver_numanodehugepages                     | 88 kB          |                  90112
 maasserver_ownerdata                             | 32 kB          |                  32768
 maasserver_packagerepository                     | 64 kB          |                  65536
 maasserver_filesystem                            | 1264 kB        |                1294336
 maasserver_partitiontable                        | 152 kB         |                 155648
 maasserver_podhints                              | 88 kB          |                  90112
 maasserver_partition                             | 472 kB         |                 483328
 maasserver_podhints_nodes                        | 32 kB          |                  32768
 maasserver_podstoragepool                        | 48 kB          |                  49152
 maasserver_rbaclastsync                          | 32 kB          |                  32768
 maasserver_rbacsync                              | 16 kB          |                  16384
 maasserver_rdns                                  | 824 kB         |                 843776
 maasserver_regioncontrollerprocess               | 88 kB          |                  90112
 maasserver_regioncontrollerprocessendpoint       | 96 kB          |                  98304
 maasserver_regionrackrpcconnection               | 112 kB         |                 114688
 maasserver_scriptset                             | 1264 kB        |                1294336
 maasserver_vlan                                  | 168 kB         |                 172032
 maasserver_service                               | 144 kB         |                 147456
 maasserver_space                                 | 48 kB          |                  49152
 maasserver_sshkey                                | 72 kB          |                  73728
 maasserver_sslkey                                | 32 kB          |                  32768
 maasserver_node                                  | 1648 kB        |                1687552
 maasserver_interface_ip_addresses                | 2680 kB        |                2744320
 maasserver_dnsresource_ip_addresses              | 336 kB         |                 344064
 maasserver_bmc                                   | 456 kB         |                 466944
 maasserver_subnet                                | 64 kB          |                  65536
 maasserver_staticroute                           | 40 kB          |                  40960
 maasserver_iprange                               | 72 kB          |                  73728
 maasserver_staticipaddress                       | 2824 kB        |                2891776
 maasserver_nodegrouptorackcontroller             | 16 kB          |                  16384
 maasserver_node_tags                             | 384 kB         |                 393216
 maasserver_userprofile                           | 40 kB          |                  40960
 maasserver_dhcpsnippet                           | 96 kB          |                  98304
 maasserver_versionedtextfile                     | 664 kB         |                 679936
 maasserver_scriptresult                          | 1287 MB        |             1349427200
 maasserver_template                              | 40 kB          |                  40960
 maasserver_virtualmachine                        | 128 kB         |                 131072
 maasserver_virtualmachinedisk                    | 144 kB         |                 147456
 maasserver_virtualmachineinterface               | 232 kB         |                 237568
(105 rows)

Our database has only grown to 15GB over years of use, but I am interested in pruning old material from it. Is there advice available for that? I don’t want to wipe any existing machines.