// DuckDB error reference

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
カテゴリ
IO and permission errors
エラーメッセージ
IO Error: Cannot open file "/tmp/missing/db.duckdb": No such file or directory

意味

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 または 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.

よくある原因

  • 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();

修正方法

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

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

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

    SELECT file FROM glob('/data/exports/*.parquet');
  4. 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.

安全に再現する

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

質問

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.

関連エラー

コードとメッセージのテキストは、 DuckDB documentation。全容は次で参照 DuckDB error list または すべてのデータベースエラーを検索.

// エラーが減り、修正も速く

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.

このページのテキストとデータ: CC BY 4.0、出典は SQLly (sqlly.app) と明記してください。 コードと SQL スニペット: MIT. ライセンスの詳細 引用したエラーメッセージの文言は、各データベースベンダーに帰属します。