Query filesystem metadata using SQL with recursive directory traversal
Maintainer(s):
halgari
Installing and Loading
INSTALL fsquery FROM community;
LOAD fsquery;
Example
-- Scan a directory and find large files
SELECT path, size, mtime
FROM fsquery_scan('/home')
WHERE is_regular_file AND size > 1000000
ORDER BY size DESC
LIMIT 10;
About fsquery
The fsquery extension adds a fsquery_scan(path) table function that recursively
traverses directories and returns file metadata including path, size, timestamps,
permissions, and file type flags.
Features
- 14 metadata columns: path, mode, size, uid, gid, atime, mtime, ctime, nlink, ino, dev, is_regular_file, is_directory, is_symlink
- Filter pushdown: Path prefix filters are pushed down to avoid scanning irrelevant directories. When using
fsquery_scan()(no explicit path), filters likepath >= '/home/user/docs'orpath IN (...)cause only those subtrees to be traversed. - Projection pushdown: Only requested columns are computed, skipping unnecessary
statfield extraction. - Cross-platform support (Linux, macOS, Windows)
Examples
Scan a specific directory:
SELECT path, size, mtime FROM fsquery_scan('/var/log') WHERE is_regular_file;
Filter pushdown — only /etc and /var/log are traversed, not the entire filesystem:
SELECT path, size FROM fsquery_scan()
WHERE path >= '/etc' OR path >= '/var/log';
Find recently modified files:
SELECT path, mtime FROM fsquery_scan('/home')
WHERE is_regular_file AND mtime > TIMESTAMP '2025-01-01'
ORDER BY mtime DESC;
Find all symlinks:
SELECT path FROM fsquery_scan('/usr') WHERE is_symlink;
Added Functions
| function_name | function_type | description | comment | examples |
|---|---|---|---|---|
| fsquery_scan | table | NULL | NULL |
Overloaded Functions
| function_name | function_type | description | comment | examples | |—————|—————|————-|———|———-|
Added Types
| type_name | type_size | logical_type | type_category | internal | |———–|———-:|————–|—————|———-|
Added Settings
| name | description | input_type | scope | aliases | |——|————-|————|——-|———|