
= Housekeeping Tasks
:description: Read about recommended housekeeping tasks to complete to ensure optimum system performance with {page-component-title}, and to perform before upgrading.

This section describes housekeeping tasks that you may want to perform to ensure optimum system performance.
We recommend that you complete some of these tasks before upgrading your {page-component-title} instance.

== Before upgrading

[[prune-events]]
=== Prune unneeded events

For the automated mechanisms in {page-component-title}, including the default events purge, alarm cleanup rules, and where to adjust them, see xref:deep-dive/admin/automatic-cleanup.adoc[Automatic database cleanup].
This section covers the manual one-shot pruning that is sometimes useful before an upgrade.

Use vacuumd or cron to regularly prune unneeded events.
This helps to clean up your events table, and reduces the amount of data in your backups.
We also recommend doing this before you begin the {page-component-title} upgrade process.

For example, run the following to delete events older than six weeks that have no associated outages:

[source, sql]
----
DELETE FROM events WHERE NOT EXISTS
(SELECT svclosteventid FROM outages WHERE svclosteventid = events.eventid
UNION
SELECT svcregainedeventid FROM outages WHERE svcregainedeventid = events.eventid
UNION
SELECT eventid FROM notifications WHERE eventid = events.eventid)
AND eventtime < now() - interval '6 weeks';
----

== After upgrading

=== Troubleshooting

If your {page-component-title} instance fails to start after upgrading, you can run the Fix Karaf script to delete cached items.
The script tries to fix configuration problems by pruning `/opt/opennms/data` and restoring all Karaf-related configuration files to a pristine state.

[source, console]
/opt/opennms/bin/fix-karaf-setup.sh

WARNING: The Fix Karaf script can be destructive to files that may contain user-specific configuration settings.
We recommend that you back up `/opt/opennms/etc` before running the script.
