Hibou Roost - Odoo: Odoo Database Management: Database Delete

Purpose

This document covers two methods you can use to delete your Odoo database and filestore.

Odoo typically includes two pieces:

  1. The Postgres database

  2. The 'filestore' (typically a directory with ~250 additional directories in it (to spread out the files across 2 characters of the hash of the file content, the files themselves are stored without file extension and hashed by content).

Deleting a database is dangerous but common. For very large databases, deleting the database and filestore can take a lot of time, so sometimes it is desirable to rename the db/filestore instead of deleting it. (Similar to the idea of the "Trash" folder.)

Processes

Odoo Database Manager

Odoo has a database manager that may be accessed via the route /web/database/manager

To use it, you will need the so called 'master password' of the installation. You can use the database manager with a regular browser, and has a built in way to delete a database.

The major limitation is that you must have the route open, and it is tied to the timeouts of a regular web worker process (i.e. it is possible for it to not complete and leave you with a 1/2 way working database).

Hibou Flow Delete

Hibou Flow is built into our Suite containers, and containers built from Suite (customer images). There are numerous command line flags, but only a couple are typically needed to achieve desired results.  

While Flow has its own entrypoint (/flow/entrypoint.sh), using Suite's is generally better as it will provide database connection details out of the Odoo RC file (/etc/odoo/odoo.conf).

The simplest possible scenario would be if you have a source database named test and you want to delete it and its filestore immediately.

/entrypoint.sh flow odoo-delete -d test

The above command will result in the --pg_strategy delete AND --filestore_strategy delete, so your database/filestore is deleted immediately.

Additional --pg_strategy options:

  • Default will be "delete" if db_name is not DO_ALL, when it will default to "do-delete-later".

  • "skip" will do nothing with postgres. 

  • "delete" will kill all connections to that database and drop the database. (delete all data) This is permanent outside of some external backup, or snapshot of the postgres server itself.

  • "delete-later-rename" will kill all connections to the database and rename it with "flow-delete-later"in front of it. This should only be used in situations where the db needs inspected or it is "assumed" to not be needed later. (e.g. a very large production database that just went through a full copy during upgrade).

  • "do-delete-later" used to actually drop the "flow-delete-later." databases. Run as a cron, or when you are ready to actually delete the database. This command allows the db_name to end up being 'DO_ALL' to let the command try to drop 'all' of the pattern databases. 

Additional --filestore_strategy  options:

  • Default will be "delete" if db_name is not DO_ALL, when it will default to "do-delete-later".

  • "skip" will do nothing with the filestore.

  • "delete" deletes the filestore. This is permanent! (delete all data)

  • "delete-later-rename" will rename the filestore with "flow-delete-later." in front of it. This should only be used in situations where the fs needs inspected or it is "assumed" to not be needed later. E.g. a very large production database that just went through a full filestore copy during an upgrade.

  • "do-delete-later" used to actually delete the "flow-delete-later." filestores. Run as a cron, or when you are ready to actually delete the filestore. This command allows the db_name to end up being 'DO_ALL' to let the command try to delete 'all' of the pattern filestores. 

Good to Know!

Not Found?

If a database or filestore does not exist, it will indicate that it finished with "not found".

If your database is very large, or you have special retention needs, then using the strategies of 'delete-later-rename' will simply do a fast rename of the database/filestore to mark it ready for removal later.  It is possible to delete the database at that point by using the delete strategy with the new name OR by using the 'do-delete-later' strategy with the original name.

You could also setup a cronjob or periodically run this command to try to find all of the databases that are ready for removal.

/entrypoint.sh flow odoo-delete -d DO_ALL