Let SQLite perform lightweight maintenance.

Section: Inspect query plans

Run PRAGMA optimize

sql
sql
PRAGMA optimize;
Explanation

A low-cost maintenance step you can run periodically in long-lived applications.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Inspect query plans
Explain a query plan
See whether SQLite scans or uses an index.
OpenIn sheetsqlsame section
Collect statistics with ANALYZE
Help the planner choose better indexes.
OpenIn sheetsqlsame section
Rebuild indexes
Recreate indexes when needed.
OpenIn sheetsqlsame section
Enable automatic EXPLAIN QUERY PLAN in shell
Show plans before each entered statement.
OpenIn sheettextsame section
Create a basic index
Index a frequently filtered column.
OpenIn sheetsql1 tag match
Create a composite index
Index multiple columns in query order.
OpenIn sheetsql1 tag match