How to clean up the trends and trend_counters tables inside the foreman database on Red Hat Satellite 6?

Solution Verified - Updated

Environment

  • Red Hat Satellite 6.x

Issue

Resolution

  • If the trends or the trend_counters table inside the foreman database is consuming too much space and requires cleanup, then follow the steps as instructed below:

    1. Check the current count of records in both tables:

      # su - postgres -c "psql -d foreman -c 'select count(*) as count from trends;'"
      # su - postgres -c "psql -d foreman -c 'select count(*) as count from trend_counters;'"
      
    2. To reduce the number of records, use the following command:

      # foreman-rake trends:reduce --trace --verbose
      
    3. Verify the current count of records:

      # su - postgres -c "psql -d foreman -c 'select count(*) as count from trends;'"
      # su - postgres -c "psql -d foreman -c 'select count(*) as count from trend_counters;'"
      
    4. If the command in step (2) did not help, then deletion can be attempted via the following command:

       # cat << FIX | foreman-rake console
       interval_end = TrendCounter.arel_table[:interval_end]
       TrendCounter.where(interval_end.lt(30.days.ago)).delete_all
       FIX
      

For more KB articles/solutions related to Red Hat Satellite 6.x PostgreSQL-related Issues, please refer to the Consolidated Troubleshooting Article for Red Hat Satellite 6.x PostgreSQL-related Issues


This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.