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

Source: https://sqlly.app/errors/duckdb/io-file-not-found
Last updated: 2026-11-30
License: Text and data [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) (credit SQLly, sqlly.app); code and SQL snippets [MIT](https://opensource.org/license/mit). [Details](https://sqlly.app/license).
Note: Quoted error message text belongs to its database vendor.

- Exception: `IO Error`
- Category: IO and permission errors

Error message:

```text
IO Error: Cannot open file "/tmp/missing/db.duckdb": No such file or directory
```

## What it means

`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` or `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.

## Common causes

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

## How to fix it

1. Check that the path exists and is reachable from the process, using the exact path the error printed:

   ```sql
   SELECT * FROM glob('/data/exports/*.parquet');
   ```
2. Use absolute paths when opening a database, so the working directory cannot change the meaning:

   ```sql
   ATTACH '/var/lib/myapp/warehouse.duckdb' AS wh;
   ```
3. For reads, check the files exist before querying, and list what a pattern matched:

   ```sql
   SELECT file FROM glob('/data/exports/*.parquet');
   ```
4. Create missing directories outside DuckDB first; it will not mkdir for ATTACH targets.

## Reproduce it safely

```sql
ATTACH '/nonexistent_dir/db.duckdb';   -- IO Error: Cannot open file "/nonexistent_dir/db.duckdb": No such file or directory
```

## Questions

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

## Related errors

- [`IO Error`](https://sqlly.app/errors/duckdb/io-lock): The database file is locked by another process
- [`Catalog Error`](https://sqlly.app/errors/duckdb/catalog-table-not-exist): The table does not exist in this database
- [`Out of Memory Error`](https://sqlly.app/errors/duckdb/out-of-memory): The query hit DuckDB's memory limit
- [`SQLITE_CANTOPEN`](https://sqlly.app/errors/sqlite/sqlite-cantopen): SQLite: unable to open database file
- [`58P01`](https://sqlly.app/errors/postgresql/58P01): PostgreSQL: undefined file

The code and message text are from the [DuckDB documentation](https://duckdb.org/docs/).
