To clean up old workers that no longer exist, you can do so from the Prefect UI. However, the exact steps on how to do this are not clearly documented. You can refer to this
discussion thread for more information.
Additionally, you can also consider using the GraphQL API to clean up database space in Prefect Server. Here is an example of how to
delete flow runs older than 30 days which might be helpful.
For more detailed information on how workers function, you can refer to the
Prefect Docs on Custom Workers.