Maintain the Red Hat Satellite database.
Outcomes
Remove audit records.
Remove unused tasks.
Reclaim space from PostgreSQL.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command prepares your environment and ensures that all required resources are available.
[student@workstation ~]$ lab start maintain-db
Instructions
Log in to the satellite system as the student user and switch to the root user.
[student@workstation ~]$ssh satellite[student@satellite ~]$sudo -i[sudo] password for student:student[root@satellite ~]#
On the satellite system, remove audit records that expired more than one day ago.
Count the audit records. The number of audit records would differ on your system.
[root@satellite ~]# hammer audit list | wc -l
220Remove audit records that expired more than one day ago.
[root@satellite ~]# foreman-rake audits:expire days=1
...output omitted...
Deleting audits older than 2022-07-25 13:08:17 UTC. This might take a few minutes...
Successfully deleted 216 audits!Review the default cron job, which removes successfully completed tasks that expired more than 30 days ago, and all tasks that expired more than a year ago.
Review the cron job.
Note the time specification, the command to run, and the file where the output is saved.
[root@satellite ~]# cat /etc/cron.d/foreman-tasks
SHELL=/bin/sh
RAILS_ENV=production
FOREMAN_HOME=/usr/share/foreman
TASK_BACKUP=false
# Clean up expired tasks from the database
45 19 * * * foreman /usr/sbin/foreman-rake foreman_tasks:cleanup >>/var/log/foreman/cron.log 2>&1You can modify the cron job configuration by editing the /etc/foreman/plugins/foreman-tasks.yaml file.
Examine this file to view the configuration settings and their default values.
Do not make any changes.
[root@satellite ~]# cat /etc/foreman/plugins/foreman-tasks.yaml
:foreman-tasks:
#
# Logging configuration can be changed by uncommenting the loggers
# section and the logger configuration desired.
#
# :loggers:
# :dynflow:
# :enabled: true
# :action:
# :enabled: true
# Task backup configuration can be changed by altering the values in
# the backup section
#
:backup:
#
# Whether to back up tasks when they are removed
#
:backup_deleted_tasks: true
#
# Where to put the tasks which were backed up
#
:backup_dir: /var/lib/foreman/tasks-backup
# Cleaning configuration: how long should the actions be kept before deleted
# by `rake foreman_tasks:clean` task
#
:cleanup:
#
# the period after which to delete all the tasks (by default all tasks are not being deleted after some period)
# will be deprecated in Foreman 1.18 and the use of rules is recommended.
#
# :after: 30d
#
# per action settings to override the default defined in the actions (self.cleanup_after method)
#
# :actions:
# - :name: Actions::Foreman::Host::ImportFacts
# :after: 10d
#
# Rules defined in this section by default don't operate
# on tasks specified in the actions section. This behavior
# can be overriden by setting the override_actions to true
:rules:
# Delete successful tasks after a month
- :filter: result = success
:after: 30d
# Delete everything (any action, any state) after one year
- :states: all # Either list of state names or all
:after: 1y
:override_actions: trueReclaim unused space in the PostgreSQL database. Compare the database size before and after reclaiming unused space.
Stop all Satellite Server services, except for the postgresql service.
[root@satellite ~]# satellite-maintain service stop --exclude postgresqlSwitch to the postgres user.
[root@satellite ~]# su - postgres
[postgres@satellite ~]$Verify the foreman database size.
[postgres@satellite ~]$psql -c "SELECT pg_database_size('foreman');"pg_database_size ------------------75203439(1 row)
Reclaim unused space in the database.
[postgres@satellite ~]$ vacuumdb --full --dbname=foreman
vacuumdb: vacuuming database "foreman"Determine the new database size, and then exit the postgres user shell.
[postgres@satellite ~]$psql -c "SELECT pg_database_size('foreman');"pg_database_size ------------------58909187(1 row) [postgres@satellite ~]$exitlogout [root@satellite ~]#
Start all of the Satellite Server services.
[root@satellite ~]# satellite-maintain service start
...output omitted...Return to the workstation system as the student user.
[root@satellite ~]#exitlogout [student@satellite ~]$exitlogout Connection to satellite closed. [student@workstation ~]$