The diskused(X) SQL function is an SQLite extension that does an analysis of how filesystem space is used by the tables and indexes that comprise an SQLite database file. The argument X is the schema that contains the database (usually 'main'). The output is text that provides self-explanatory, human-readable facts about filesystem space utilization.
The diskused() SQL function is used to implement the .diskused command in the CLI. This is a replacement for the legacy sqlite3_analyzer utility program, which is now deprecated.
The CLI uses the diskused() function to implement its ".diskused" command. The preferred way to get a complete analysis of the space utilization for an SQLite database file "demo.db" is to run a command like this:
sqlite3 demo.db .diskused
Internally, the ".diskused" dot-command runs:
SELECT diskused('main');
And then displays the returned text, unformatted, on standard output.
The output is SQL text for a CREATE TABLE statement for a table named "space_used", with a large human-readable comment up front. Most users simply read the comment and ignore the CREATE TABLE statement. However, users can run the output text as SQL to create the "space_used" table and then run queries against the "space_used" table for more detailed analysis.
The diskused() SQL function is implemented as an application-defined SQL function by the source code file ext/misc/diskused.c in the SQLite source tree. The diskused() function is built into the CLI, but it is not included in the amalgamation ("sqlite3.c"). Third-party applications that want to make use of the diskused() SQL function will need to compile it separately and load it using the sqlite3_load_extension() API.
The diskused() function is built atop of the DBSTAT virtual table. Thus, SQLite must be compiled with -DSQLITE_ENABLE_DBSTAT_VTAB in order for the diskused() function to work.
This page was last updated on 2026-05-29 15:17:09Z
*** DRAFT ***