IO Error: A file could not be opened
DuckDB could not open, create or read a file it was pointed at: a missing database file, a bad path in read_csv, or an unreadable directory.
- Exception
IO Error- Categoría
- IO and permission errors
Qué significa
IO Error is the class for file-level failures outside the engine: ATTACH on a path whose parent directory does not exist (an unknown file name in an existing directory creates a new empty database instead), read_csv over a pattern that matches nothing, or a file operation in a directory the process cannot enter. The message carries the operating system's reason, such as No such file or directory o Permission denied, after the path.
Two messages mean different things: Cannot open file ... No such file or directory comes from opening a database path such as ATTACH, while read_csv and read_parquet report No files found that match the pattern ... for any path that matches no file, including a plain path that does not exist. Relative paths are resolved against the process working directory, which is the usual reason a file that exists is reported missing.
Causas comunes
- The database file path is wrong, relative to the wrong directory, or the file was moved or deleted.
- A parent directory of the target does not exist, so DuckDB cannot create the file in it.
- A read_csv or read_parquet pattern matched no files, for example after an upstream job renamed its outputs.
- A network share or removable drive is unmounted, so the path exists in name only.
Find the cause
-- Does the pattern match anything, and what exactly?
SELECT * FROM glob('/data/exports/*.parquet');
-- What can this process see at the directory level:
SELECT * FROM glob('/data/*');
-- For a database file, check the connection actually points where you think:
SELECT database_name, path FROM duckdb_databases();
Cómo solucionarlo
-
Check that the path exists and is reachable from the process, using the exact path the error printed:
SELECT * FROM glob('/data/exports/*.parquet'); -
Use absolute paths when opening a database, so the working directory cannot change the meaning:
ATTACH '/var/lib/myapp/warehouse.duckdb' AS wh;
-
For reads, check the files exist before querying, and list what a pattern matched:
SELECT file FROM glob('/data/exports/*.parquet'); -
Create missing directories outside DuckDB first; it will not mkdir for ATTACH targets.
Other ways to handle it
If the file is genuinely gone, restore from backup before any write attempt; DuckDB may create a fresh empty database at the same path, which then looks like a data loss. For external files that arrive late, check with glob in the orchestrator before scheduling the query.
Reprodúcelo de forma segura
ATTACH '/nonexistent_dir/db.duckdb'; -- IO Error: Cannot open file "/nonexistent_dir/db.duckdb": No such file or directory
Preguntas
The file is right there. Why can't DuckDB open it?
The process's working directory is probably not where you think. A relative path resolves against it, so run the open with an absolute path or print the working directory from the same process.
read_csv says no files found but my path is a plain file. Why?
Table functions like read_csv accept globs, and the pattern message appears when nothing matches. Check the pattern with SELECT * FROM glob('...') to see what it resolves to.
Errores relacionados
IO ErrorThe database file is locked by another processCatalog ErrorThe table does not exist in this databaseOut of Memory ErrorThe query hit DuckDB's memory limitSQLITE_CANTOPENSQLite: unable to open database file58P01PostgreSQL: undefined file
El código y el texto del mensaje son de DuckDB documentation. Explora la lista completa de DuckDB error list o buscar cada error de base de datos.
Work on DuckDB in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for DuckDB and the other databases you use.
Texto y datos de esta página: CC BY 4.0, con atribución a SQLly (sqlly.app). Código y fragmentos SQL: MIT. Detalles de la licencia El texto citado de los mensajes de error pertenece a su proveedor de base de datos.