// 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
Catégorie
IO and permission errors
Message d'erreur
IO Error: Cannot open file "/tmp/missing/db.duckdb": No such file or directory

Ce que cela signifie

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

Causes courantes

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

Comment le corriger

  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.

Reproduisez-le en toute sécurité

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.

Erreurs liées

Le code et le texte du message sont issus de DuckDB documentation. Parcourir la liste complète DuckDB error list ou Rechercher toutes les erreurs de base de données.

// moins d'erreurs, corrections plus rapides

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.

Texte et données de cette page : CC BY 4.0, en citant SQLly (sqlly.app). Code et extraits SQL : MIT. Détails de la licence Le texte des messages d’erreur cité appartient à l’éditeur de la base de données.