How to reduce Postgresql database growth automatically?

Note

These settings are added automatically in version 4.4 and higher.

If your database is growing too quickly, you can try to contain its growth with aggressive “autovacuum” parameters. Autovacuum is a built-in process for maintaining the database structure in an orderly manner.

Steps to achieve the goal:

  • You need to open the console linux on a server with iBatyr Monitor Server installed

  • Open the postgresql settings file for editing (9.5 is your version of postgresql):

sudo nano /etc/postgresql/9.5/main/postgresql.conf
  • At the end of the file, insert the lines:

autovacuum = on # Enable autovacuum subprocess? 'on'
log_autovacuum_min_duration = 0 # -1 disables, 0 logs all actions and
autovacuum_max_workers = 5 # max number of autovacuum subprocesses
autovacuum_naptime = 1min # time between autovacuum runs
autovacuum_vacuum_threshold = 300 # min number of row updates before
autovacuum_analyze_threshold = 200 # min number of row updates before
autovacuum_vacuum_scale_factor = 0.01 # fraction of table size before vacuum
autovacuum_analyze_scale_factor = 0.005 # fraction of table size before analyze
  • Save the file by pressing Ctrl + x and pressing y

  • Restart postgresql

sudo service postgresql restart

After this, the database will grow at an understandable and moderate pace, and will be more predictable in size.