# Cleaning up files in Server

**URL:** <https://community.dhis2.org/t/cleaning-up-files-in-server/61029>\
**Category:** Server Administration - Administration-du-Serveur\
**Tags:** tracker, sysadmin\
**Created:** [13 September 2024 09:25 UTC](https://community.dhis2.org/t/cleaning-up-files-in-server/61029 "2024-09-13T09:25:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JaimeLopez](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/jaimelopez/32/40631_2.png) [@JaimeLopez](https://community.dhis2.org/u/JaimeLopez)\
**Post date:** [13 September 2024 09:25 UTC](https://community.dhis2.org/t/cleaning-up-files-in-server/61029/1 "2024-09-13T09:25:07Z")

</div>

Hello.

One of our servers is runing out of space and before investing in an upgrade, I am trying to clean it up and avoid that upgrade as much as I can becouse it might be costly for our organization.

The main usage of our system is based on a tracker program that has images atached to the events of the TEIs. Those images are uploaded by an android app instaled in a Tablet.

One of the tasks I have been doing to free disk space is the deletion of files no longer conected with any TEI. I managed to delete the files older than the first event of the first enrollment in the server.

But I am wondering if there is a way I can know wich files are no longer connected with TEIS (caused by the deletion of TEIS, for example or caused by bad communication between the Tablet and the server).

I have been searching and there is no way I can connect the name of the file shown in the event in DHIS2 with the name of the file in the file system. I understand this is for security reasosn. Is there a way DHIS2 can clean up files no longer connected? Is there any tool I can use to delete those files and free disk space?

Thank you very much in advance.,

---

<div class="post-metadata">

**Author:** ![rcpoudel](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/rcpoudel/32/43632_2.png) [@rcpoudel](https://community.dhis2.org/u/rcpoudel)\
**Post date:** [13 September 2024 11:29 UTC](https://community.dhis2.org/t/cleaning-up-files-in-server/61029/2 "2024-09-13T11:29:08Z")

</div>

Hi @JaimeLopez

You can run a query to list all the file resources currently referenced (the `fileresource` table)

```auto
SELECT * FROM fileresource;

```

The `storagekey` is usually the name or identifier used to store the file in file system.

using a `WHERE event.uid NOT IN` query that can be applied to either **Enrollment** or **events**

**NOTE: Please ensure you double-check the results of your query before performing any delete operations**

---

<div class="post-metadata">

**Author:** ![JaimeLopez](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/jaimelopez/32/40631_2.png) [@JaimeLopez](https://community.dhis2.org/u/JaimeLopez)\
**Post date:** [16 September 2024 08:19 UTC](https://community.dhis2.org/t/cleaning-up-files-in-server/61029/4 "2024-09-16T08:19:20Z")

</div>

Hello RC

Thanks for your answer.  
My DHIS server is in version 2.37.  
How can I execute that query? Do I need to get into command line for the server and use psql? Or there is another way within DHIS2? I am familiar with sql and DHIS2, but not with postgres/DHIS 2 sql queries or sql views.

I am trying to use api call from postman and the response for [https://https](https://https)://\<\>/api/fileresource is “The origin server did not find a current representation for the target resource or is not willing to disclose that one exists”

---

<div class="post-metadata">

**Author:** ![JaimeLopez](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/jaimelopez/32/40631_2.png) [@JaimeLopez](https://community.dhis2.org/u/JaimeLopez)\
**Post date:** [16 September 2024 11:29 UTC](https://community.dhis2.org/t/cleaning-up-files-in-server/61029/5 "2024-09-16T11:29:22Z")

</div>

Hello again RC.

I magnaged to execute query in Maintenance app.

Thanks a lot.
