how to move and delete filestore to database po...

Creato il: 10 giugno 2025

Risposto usando O3 da Chat01

Domanda

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.

Pensiero

Configuring attachment storage in Odoo

To store attachments in the database, set the 'ir_attachment.location' parameter to 'db', or use 'postgresql:lobject' for storing large objects in PostgreSQL. For migration, use the following method in the Odoo environment:

python
env['ir.attachment'].with_user(1).force_storage()

This will move attachments to the database. Remember, you can also find relevant information in the GitHub repository, and rely on the method referenced there for specifics.

Thought for 46 seconds

Risposta

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.)


1 . Tell Odoo to use the database from now on

  1. Log in as an administrator and open Settings ▸ Technical ▸ Parameters ▸ System Parameters.
  2. Create / edit the key 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.fr
  3. Restart the Odoo service (or your containers) so the new storage backend is picked up.
    All new files uploaded after the restart are already stored in the table ir_attachment (db_datas column) – nothing else to do for them.

2 . Bulk-move the existing filestore into the database

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.


3 . Verify & drop the old filestore

  1. Run a quick check:
sql
SELECT count(*) FROM ir_attachment WHERE store_fname IS NOT NULL;

It should return 0 (all attachments now live in the DB).

  1. Delete the directory that held the filestore, e.g.
bash
rm -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.)


4 . Operate Odoo in stateless containers

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.


Caveats & best-practices

TopicRecommendation
PerformanceDatabase 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 & backupsExpect the DB to grow by the size of the old filestore. Adjust retention policies and make sure your backup tooling can handle bigger dumps.
TimeoutsFor very large uploads you may need to bump Nginx/Proxy and Odoo limits (limit_request_body, proxy_read_timeout, --limit-memory-hard, etc.).
Rollback safetyforce_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!

Condividi questa Q&A