how to move and delete filestore to database po...
बनाया गया: 10 जून 2025
बनाया गया: 10 जून 2025
how to move and delete filestore to database postgresql in odoo 18.0
i want to odoo stateless
Everything that is going to be stored in the file store should be stored in the database.
Below is the proven, repeatable way to go “fully-stateless” in Odoo 18 by migrating every attachment from the disk filestore into PostgreSQL and then deleting the filestore.
(Exactly the same steps work in 16 / 17, so you can test on a staging copy first.)
ir_attachment.location
and give it the value db
– or postgresql:lobject
if you prefer PostgreSQL Large-Objects (they stream big files more efficiently). technaureus.com gorfou.frir_attachment
(db_datas
column) – nothing else to do for them.Odoo ships a helper that does the heavy lifting:
bash# Start an Odoo shell in the same environment as the server odoo -d <your_db_name> shell >>> env['ir.attachment'].force_storage() # copies ➜ DB, unlinks from disk
What happens: for every attachment still on disk, Odoo reads the file, writes the bytes into db_datas
, clears store_fname
, commits, then removes the file. github.com
Tips for large instances
python# run in batches and commit every 1 000 records batch = 1000 offset = 0 while True: recs = env['ir.attachment'].search([], limit=batch, offset=offset) if not recs: break recs.force_storage() env.cr.commit() offset += batch
Always take a fresh DB + filestore backup before the migration and test on staging first.
sqlSELECT count(*) FROM ir_attachment WHERE store_fname IS NOT NULL;
It should return 0 (all attachments now live in the DB).
bashrm -rf /var/lib/odoo/.local/share/Odoo/filestore/<your_db_name>
(Odoo will no longer try to recreate it because the parameter now points to db
.)
With attachments in PostgreSQL, the only persistent volume you still need is the database itself. A typical Docker/Kubernetes recipe now mounts:
yaml- postgres-data:/var/lib/postgresql/data # persistent # no mount for /var/lib/odoo/.local/... # stateless
Sessions are already stored in the DB (ir.sessions
), so nothing else is required.
Topic | Recommendation |
---|---|
Performance | Database BLOBs/LOs are slower than local SSD reads. Use fast storage or consider S3-style back-ends (Odoo’s Filesystem Storage Backend add-on can do that). |
DB size & backups | Expect the DB to grow by the size of the old filestore. Adjust retention policies and make sure your backup tooling can handle bigger dumps. |
Timeouts | For very large uploads you may need to bump Nginx/Proxy and Odoo limits (limit_request_body , proxy_read_timeout , --limit-memory-hard , etc.). |
Rollback safety | force_storage() commits after each record, but a crash can still leave a few orphan files. Keep the original filestore until you finish spot-checks. Past bugs that removed data were fixed in modern versions; using batches + commits as shown adds an extra layer of protection. github.com |
You now have an Odoo 18 instance whose only stateful component is PostgreSQL. Happy containerizing!