on-run-end hooks collect test results and dbt artifacts to provide comprehensive observability. However, for large projects or when running only a subset of models, these hooks can add significant time to your dbt runs. This guide explains how to control the timing of on-run-end hooks to make them more efficient and avoid unnecessary runs while maintaining the observability you need.
Overview
The Elementary on-run-end hooks perform several operations that can impact run time:- Metadata artifacts upload: Uploads all project metadata (models, tests, sources, etc.)
- Run results upload: Uploads test results and model execution results
- dbt invocation upload: Uploads dbt invocation metadata
Control Metadata Artifacts Upload Timing
The most effective way to reduce on-run-end time is to control when metadata artifacts are uploaded. Instead of uploading all project metadata (models, tests, etc.) on every run, you can upload artifacts on a schedule that matches when your project actually changes.Configuration
Add the following to yourdbt_project.yml:
dbt_project.yml
Upload Artifacts When Needed
When you need to update metadata (e.g., after schema changes or adding new models), upload artifacts either manually or via a recurring job (e.g., daily):enable_elementary_models pattern in dbt_project.yml, see Can I disable / exclude the Elementary models?.
Metadata artifacts only need to be uploaded when your project structure changes (new models, tests, sources, etc.). For most runs, you only need run results, which are much faster to upload.
Control Other Hooks Timing
You can further control when different parts of the on-run-end logic run by setting additional variables.Available Configuration Variables
dbt_project.yml
disable_run_results: Controls when model execution results are uploadeddisable_tests_results: Controls when test results are uploadeddisable_dbt_invocation_autoupload: Controls when dbt invocation metadata is uploaded
Disable test table cleanup during on-run-end
Elementary creates temporary tables during test execution and cleans them up at the end of each run. For large projects with many tests, this cleanup phase can become a significant portion of theon_run_end time.
If you observe in the logs that the slow phase is the test table cleanup, you can disable it during on_run_end and offload it to a dedicated scheduled job instead.
Disable automatic cleanup
Add the following to yourdbt_project.yml:
dbt_project.yml
Run cleanup in a dedicated job
After disabling automatic cleanup, schedule a recurring dbt operation to clean up stale test tables:hours(default:24): Only delete test tables that are older than this many hours. Increase this value if you want to retain temporary tables for longer before cleanup.limit(default:2000): Maximum number of tables to delete per run. Use this to cap the cleanup operation and avoid long-running jobs when many stale tables have accumulated.
We recommend scheduling this job to run daily. If a large number of stale tables have built up, the
limit parameter prevents the first cleanup from running indefinitely — you can run the job multiple times until all stale tables are removed.Limit Hooks to Production or Specific Targets
If you only need full observability in production, configure Elementary to run hooks only for specific targets. This is especially useful when you want to:- Speed up local development
- Reduce costs in non-production environments
- Focus monitoring on production workloads
Configuration by Target
Configure hooks to run only for specific targets:dbt_project.yml
Disable Entire Package for Non-Production
Alternatively, you can disable the entire Elementary package for non-production targets:dbt_project.yml

