Search Shortcut cmd + k | ctrl + k
fsquery

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 like path >= '/home/user/docs' or path IN (...) cause only those subtrees to be traversed.
  • Projection pushdown: Only requested columns are computed, skipping unnecessary stat field 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

This extension does not add any function overloads.

Added Types

This extension does not add any types.

Added Settings

This extension does not add any settings.