Informix Error -331
-331 Cannot drop database directory.
While the database server was executing the DROP DATABASE statement, it removed all database-related files from the dbname.dbs directory and tried to remove the directory itself, but an error occurred. Check the accompanying ISAM error code for more detailed information on the cause. The most likely cause is that you or another user created nondatabase files in the same directory, and the directory cannot be removed because it is not yet empty.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-331 fires late in a DROP DATABASE operation: the server has already successfully deleted the
actual database files from the dbname.dbs directory, but then fails to remove the directory
itself. The typical cause is that the directory isn't actually empty — something other than
Informix's own database files is sitting in it.
- Non-database files placed in the
dbname.dbsdirectory — backup copies, log files, editor swap files, or anything else a DBA or script may have dropped in there, preventing removal since the directory isn't empty. - A file left open by another process with a handle into that directory, which some filesystems treat as still "in use" even after content deletion.
- Filesystem-level permission issues preventing directory removal even though the files inside were successfully deleted.
Solutions / Resolution
- Check the accompanying ISAM error code first, per the official guidance, for the specific underlying reason.
- Manually inspect the
dbname.dbsdirectory for any leftover non-database files and remove them if they're confirmed to be safe to delete (backups, stray files, etc.). - Confirm no other process still has a file open within that directory before retrying.
- Retry the directory removal manually (at the OS level) once the directory is confirmed empty, if the database's actual data was already successfully dropped.
Examples
Inspecting the directory for stray files
ls -la /informix/dbspaces/sales.dbs/
-- look for anything that isn't a normal Informix database file
-- (e.g. a stray .bak, .swp, or manually copied file)
Removing confirmed-safe leftover files, then retrying
rm /informix/dbspaces/sales.dbs/stray_backup_file
rmdir /informix/dbspaces/sales.dbs/
Diagnostic Checks
- Read the accompanying ISAM error code for the specific failure reason.
- List the contents of the database's
.dbsdirectory to identify what's preventing its removal. - Check whether another process holds an open file handle in that directory.
Related Errors / Related Topics
- -330 — "Cannot create or rename the database." A related database-lifecycle failure, on the creation/rename side rather than the drop side.
The database's actual data was already dropped successfully by the time this error surfaces — this is purely about leftover files blocking the directory's own removal.