# Uploads not getting orphaned and purged

**URL:** https://meta.discourse.org/t/uploads-not-getting-orphaned-and-purged/259036
**Category:** Support
**Created:** [March 22, 2023, 1:47pm UTC](https://meta.discourse.org/t/uploads-not-getting-orphaned-and-purged/259036 "2023-03-22T13:47:52Z")
**Posts on this page:** 1
**Showing post:** 7

<div class="post-metadata">

### Author: ![groove6j](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/groove6j/32/367325_2.png) [@groove6j](https://meta.discourse.org/u/groove6j)
#### Post date: [March 26, 2024, 5:59pm UTC](https://meta.discourse.org/t/uploads-not-getting-orphaned-and-purged/259036/7 "2024-03-26T17:59:57Z")

</div>

Hello. I am facing the same or similar issue, can’t figure out why the files can’t get deleted. Anyone else having this issue still?  
I ran some SQL queries and the “stuck” upload references seems to be all Drafts, but I checked my and other users Drafts and there are none. The Drafts tables are empty.  
The orphan cleaning is enabled and settings are set to delete the orphans as fast as possible.  
I attached a SQL query.

```plaintext
SELECT 
    uploads.original_filename,
    ROUND(uploads.filesize / 1000000.0, 2) AS size_in_mb,
    uploads.extension,
    uploads.created_at,
    uploads.url,
    upload_references.upload_id,
    upload_references.target_id,
    upload_references.target_type,
    upload_references.created_at,
    upload_references.updated_at
FROM upload_references
JOIN uploads ON uploads.id = upload_references.upload_id
ORDER BY uploads.filesize DESC
LIMIT 250

```

[sql.csv](https://meta.discourse.org/uploads/short-url/gdMEhZ3My85lm2CHNX3oq1D30NL.csv) (46,1 KB)

This happens since I installed the forum. Even when there was no custom themes or plugins installed.  
Heck even the old forum logo I uploaded a few times (the first uploaded file ever) is still rerefenced as Draft and still in the uploads folder. 🤦‍♂️  
Theoretically I could filter all upload references and filter for Drafts by target\_type, then delete from database… and let the sidekiq tasks handle the cleanup (am I right?)  
but I’m using a self hosted instance and am quite new to Discourse, so better to ask here…  
That would be a workaround, but still there is a question - why is this happening?

Hope someone has some suggestions, my disk space is growing exponentially 😄

---

_[View the full topic](https://meta.discourse.org/t/uploads-not-getting-orphaned-and-purged/259036)._
