<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: atelier rs</title>
    <description>The latest articles on DEV Community by atelier rs (@atelier_rs_4b1759b9f9cdc1).</description>
    <link>https://dev.to/atelier_rs_4b1759b9f9cdc1</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4260855%2Fe0d99add-4bc8-4885-8b05-8e08c3dd39ec.png</url>
      <title>DEV Community: atelier rs</title>
      <link>https://dev.to/atelier_rs_4b1759b9f9cdc1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/atelier_rs_4b1759b9f9cdc1"/>
    <language>en</language>
    <item>
      <title>Odoo filestore too big? Find out what is filling it before you delete anything</title>
      <dc:creator>atelier rs</dc:creator>
      <pubDate>Mon, 23 Nov 2026 14:52:48 +0000</pubDate>
      <link>https://dev.to/atelier_rs_4b1759b9f9cdc1/odoo-filestore-too-big-find-out-what-is-filling-it-before-you-delete-anything-33me</link>
      <guid>https://dev.to/atelier_rs_4b1759b9f9cdc1/odoo-filestore-too-big-find-out-what-is-filling-it-before-you-delete-anything-33me</guid>
      <description>&lt;p&gt;Your Odoo filestore keeps growing, backups take longer, and someone asks "can we just delete old attachments?". Before you compress, move or delete anything, answer one question: &lt;strong&gt;which records, which file types and which years account for the space?&lt;/strong&gt; Usually two or three sources explain most of it, and the right fix depends on which ones.&lt;/p&gt;

&lt;p&gt;This is read-only work. You only need &lt;code&gt;psql&lt;/code&gt; access to the database (self-hosted, or the Odoo.sh shell).&lt;/p&gt;

&lt;h2&gt;
  
  
  1. How Odoo stores attachments (what you need to know)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Each attachment is a row in &lt;code&gt;ir_attachment&lt;/code&gt;. When &lt;code&gt;type = 'binary'&lt;/code&gt; and the file is not in the database, the file lives in the filestore, under the name in &lt;code&gt;store_fname&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Odoo names the file after the SHA-1 of its content, so &lt;strong&gt;identical files are stored once&lt;/strong&gt;, even if several rows point to them. Adding up &lt;code&gt;file_size&lt;/code&gt; over all rows therefore counts shared files several times and overstates the disk use.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;res_model&lt;/code&gt; and &lt;code&gt;res_id&lt;/code&gt; tell you which record the file belongs to (&lt;code&gt;res.partner&lt;/code&gt;, &lt;code&gt;account.move&lt;/code&gt;, &lt;code&gt;mail.message&lt;/code&gt;, ...). When &lt;code&gt;res_field&lt;/code&gt; is set, the file is the value of a binary field (an avatar, a product image) stored as an attachment.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. Total real size on disk
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="nf"&gt;pg_size_pretty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file_size&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;filestore_size&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="nb"&gt;COUNT&lt;/span&gt;&lt;span class="cm"&gt;(*)                      AS files
FROM (
    SELECT DISTINCT ON (store_fname) store_fname, file_size
    FROM ir_attachment
    WHERE store_fname IS NOT NULL
) AS unique_files;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Compare this with the size of the filestore folder (&lt;code&gt;du -sh&lt;/code&gt;) to see if you are looking at the right database.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. By model: who owns the biggest files?
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="nb"&gt;COALESCE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res_model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'(no record)'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="nb"&gt;COUNT&lt;/span&gt;&lt;span class="cm"&gt;(*)                           AS attachments,
       pg_size_pretty(SUM(file_size))     AS size
FROM ir_attachment
WHERE store_fname IS NOT NULL
GROUP BY res_model
ORDER BY SUM(file_size) DESC
LIMIT 15;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This count adds shared files once per row, so read it as a ranking, not as an exact bill. On a fresh database, the top lines are &lt;code&gt;ir.ui.view&lt;/code&gt; (compiled JavaScript and CSS, regenerated by Odoo: ignore them) and product or partner images. On a real database, look for the lines that grow with your business: &lt;code&gt;mail.message&lt;/code&gt; (files attached to emails and chatter), &lt;code&gt;account.move&lt;/code&gt; (invoices and their PDFs), &lt;code&gt;res.partner&lt;/code&gt;, &lt;code&gt;product.template&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. By file type and by year
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;mimetype&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="nb"&gt;COUNT&lt;/span&gt;&lt;span class="cm"&gt;(*)                       AS attachments,
       pg_size_pretty(SUM(file_size)) AS size
FROM ir_attachment
WHERE store_fname IS NOT NULL
GROUP BY mimetype
ORDER BY SUM(file_size) DESC
LIMIT 10;

SELECT date_part('year', create_date)  AS year,
       pg_size_pretty(SUM(file_size))  AS size
FROM ir_attachment
WHERE store_fname IS NOT NULL
GROUP BY 1
ORDER BY 1;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If most of the size is PDFs older than two years, archiving fits. If it is oversized images, compression fits. If it is email attachments, the fix may be a retention rule in the chatter, not storage.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Attachments with no record
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="nb"&gt;COUNT&lt;/span&gt;&lt;span class="cm"&gt;(*) AS rows_without_record,
       pg_size_pretty(SUM(file_size)) AS size
FROM ir_attachment
WHERE store_fname IS NOT NULL
  AND res_model IS NULL
  AND res_field IS NULL;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the databases I tried this on (Odoo 16 to 20), this returns almost nothing: Odoo attaches its compiled web assets (JavaScript and CSS bundles, a few MB) to &lt;code&gt;ir.ui.view&lt;/code&gt;, not to "no record". If you get many rows here, look at their &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;create_date&lt;/code&gt; before concluding anything: they are the first place to look for files that something creates and nobody uses.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. What not to do
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Never delete files in the filestore folder by hand.&lt;/strong&gt; A missing file shows up later as an error on the record. Odoo's own autovacuum already removes files that no row references any more.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test on a copy first&lt;/strong&gt;, and keep a backup of the database &lt;em&gt;and&lt;/em&gt; the filestore together: restoring only one gives broken links.&lt;/li&gt;
&lt;li&gt;Do not delete &lt;code&gt;ir_attachment&lt;/code&gt; rows with SQL. Use the ORM (a script or the Odoo shell), so related data and the file cleanup stay consistent.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  7. Choosing the fix
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;What the numbers show&lt;/th&gt;
&lt;th&gt;A reasonable fix&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Oversized images&lt;/td&gt;
&lt;td&gt;Compression rules on upload or in batch&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Old PDFs on invoices and orders&lt;/td&gt;
&lt;td&gt;Move them to a slower disk or a network share, keep them openable from the record&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Email attachments&lt;/td&gt;
&lt;td&gt;Retention rule for the chatter&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Many attachments without record&lt;/td&gt;
&lt;td&gt;Check what creates them before removing&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  If you would rather not run queries by hand
&lt;/h2&gt;

&lt;p&gt;I wrote an app for this: &lt;a href="https://apps.odoo.com/apps/modules/20.0/attachment_archive_storage" rel="noopener noreferrer"&gt;Attachment Archive &amp;amp; Filestore Storage Report&lt;/a&gt; on the Odoo Apps Store. It shows the same totals by document type, file type and year, previews what a rule would move, and can archive old files to a folder mounted on the server (second disk, NAS or network share) while keeping them openable from Odoo, with a restore button. Each copy is checked against the attachment checksum before the original is replaced.&lt;/p&gt;

&lt;p&gt;Limits you should know before looking at it: it is for self-hosted Odoo on Linux with a folder mounted on the Odoo server. It is not for Odoo Online, and Odoo.sh cannot mount an extra volume. Disclosure: I am the author. The queries above work without it.&lt;/p&gt;

&lt;p&gt;Questions about the queries or about a result that looks odd: write in the comments.&lt;/p&gt;

</description>
      <category>odoo</category>
      <category>postgres</category>
      <category>sql</category>
      <category>erp</category>
    </item>
  </channel>
</rss>
