Skip to Content

Delete an Odoo database

deletedb permanently drops a PostgreSQL database and removes its matching filestore if present. The name deliberately differs from PostgreSQL's dropdb.

./deletedb --dry-run example_copy
./deletedb example_copy
./deletedb --yes --filestore /path/to/data/filestore example_copy

Without --yes (or -y), type the exact database name at the confirmation prompt. --dry-run checks and displays the targets without deleting anything. No host installation is needed when invoking the executable by path.

The filestore root defaults to /srv/pmiverse/_pmisuite18/data/filestore. Override it with FILESTORE_BASE or --filestore (the CLI option wins). Only <root>/<database> is removed, never the root itself. A missing filestore or filestore root is allowed. Symlinks in the target path and non-directory targets are rejected. Symlinks inside the filestore are removed without following them. GNU rm --one-file-system avoids descending into nested filesystems on different devices; do not use mounted directories as filestore deletion targets.

Connections use the usual PostgreSQL environment variables, including PGHOST, PGPORT, PGUSER, and PGPASSFILE, with postgres as the maintenance database. The script does not read Odoo configuration or prompt for PostgreSQL passwords. Use the database owner (or an authorized PostgreSQL superuser) and an OS account with permission to delete the filestore. Requires Bash, PostgreSQL client tools, and GNU coreutils. postgres, template0, and template1 are protected.

Stop Odoo, close database connections, and ensure the backup you need exists before deletion. The script does not stop services or force connections closed. Do not run concurrent database or filestore operations against the target. With a remote PostgreSQL connection, explicitly verify that the local filestore root belongs to that server and database.

The database is dropped first. If that fails, the filestore remains intact. A missing database is an error and any orphaned filestore is preserved. The script also refuses to remove a filestore whose directory identity changes during the operation. If file removal fails after the database is dropped, the database cannot be recovered by this script; the command reports failure and leaves the remaining files for manual inspection. Deletion is not atomic across PostgreSQL and the filesystem. An interruption may likewise leave the filestore behind.

Bash completion

The shared completion supports options, filestore directories, and live database names, with the same three-second timeout and registry fallback as duplication. Load it in a Bash session with bash-completion installed:

source /usr/share/bash-completion/bash_completion
source /srv/pmiverse/_pmiconfig/scripts/completion/pmiverse-completion.bash

Validation

From the repository root:

bash tests/test_deletedb.sh
bash tests/test_duplicate_completion.sh

Tests mock PostgreSQL commands and operate only on synthetic temporary files.