Skip to content

Clean up unused space in a database using vacuum or optimise

Remember sqlite databases are files, you can ask how big it is like du my_database.db

When you drop things from your schema or delete rows, disk usage isn’t immediately reduced, rather those bytes are marked as available for reuse by the DBMS.

Do this in sqlite by running the SQL statement VACUUM; and waiting for some time depending on how many bytes need reallocating. Other DBMSs may call this OPTIMIZE TABLE or similar.

Sources