guides/learning/operational_maintenance.md
This guide walks you through maintaining a production Oban setup from an operational perspective. Proper maintenance ensures your job processing system remains efficient, responsive, and reliable over time.
Oban stores all jobs in the database, which offers several advantages:
However, this persistence strategy means that without proper maintenance, your job table will grow indefinitely.
Job stats and queue introspection are built on keeping job rows in the database after they have
completed. This allows administrators to review completed jobs and build informative aggregates,
at the expense of storage and an unbounded table size. To prevent the oban_jobs table from
growing indefinitely, Oban actively prunes completed, cancelled, and discarded jobs.
By default, the pruner plugin retains jobs for 60 seconds. You can
configure a longer retention period by providing a :max_age in seconds to the pruner plugin.
config :my_app, Oban,
plugins: [{Oban.Plugins.Pruner, max_age: _5_minutes_in_seconds = 300}],
# ...
The pruner plugin periodically runs SQL queries to delete jobs that:
completed, cancelled, or discarded)This happens in the background without impacting job execution.
Oban relies on database indexes to efficiently query and process jobs. As the oban_jobs table
experiences high write activity, index bloat and fragmentation can occur over time, potentially
degrading performance.
Oban creates several important indexes on the oban_jobs table:
With heavy usage, these indexes can become less efficient due to:
Oban provides a dedicated plugin for maintaining index health: Oban.Plugins.Reindexer. This
plugin periodically rebuilds indexes concurrently to ensure optimal performance.
To enable automatic index maintenance, add the Reindexer to your Oban configuration:
config :my_app, Oban,
plugins: [Oban.Plugins.Pruner, Oban.Plugins.Reindexer],
# ...
Pruning is best-effort and performed out-of-band. This means that all limits are soft; jobs beyond a specified age may not be pruned immediately after jobs complete.
Pruning is only applied to jobs that are completed, cancelled, or discarded. It'll never
delete a new job, a scheduled job, or a job that failed and will be retried.
Schedule reindexing during low-traffic periods when possible because it can be resource-intensive.