Get the SQLite file
A SQLite database file can use any extension - .db, .sqlite, .sqlite3, etc. The extension doesn’t affect functionality; all contain the same SQLite format. To ensure no recent changes are lost, you can either: Pull the associated Write-Ahead Log (WAL) file (with the same name as the database plus the suffix
-wal). Or alternatively, run the command PRAGMA wal_checkpoint(TRUNCATE); on the database before pulling it, which will merge the WAL file’s changes into the main database file.- Android
- iOS
- Web
Ensure your emulator is running, then replace Common database locations:
com.package-name with your application’s package name and your-db-name.sqlite with your database file name.- React Native Quick SQLite:
/data/data/com.package-name/files/ - OP-SQLite:
/data/data/com.package-name/databases/
Inspecting the SQLite file
1. Open your SQLite file
Use thesqlite3 command-line tool or a GUI tool like DB Browser for SQLite to open your database file:
2. Merge the WAL file
Temporary changes are stored in a separate Write-Ahead Log (WAL).wal file. To measure the database size accurately, merge these changes into the main database:
3. Get storage statistics
Query the built-indbstat virtual table to see how much space each table uses on disk:
name: Table namestorage_size: Total storage used on disk (in bytes, including SQLite overhead)payload: Actual data size (in bytes)
The
dbstat table is automatically available in SQLite and provides low-level information about physical storage. Values represent on-disk usage including SQLite’s internal structures (page headers, B-trees, indexes, free space), which is why they’re larger than your logical data size.Understanding the size breakdown
PowerSync databases contain more data than just your application tables to support the sync functionality:- Application data: Your synced data in
ps_data__<table>tables - Operation log (
ps_oplog): A complete copy of all synced data required for offline conflict resolution and sync - Indexes: For efficient queries and lookups
- PowerSync metadata: System tables and views for managing sync state (see Client Architecture)
- SQLite overhead: Page structure, alignment, fragmentation, and internal bookkeeping
storage_size and payload in the dbstat results shows SQLite’s storage overhead. The ps_oplog table will typically be one of the largest tables since it maintains a full copy of your synced data.
To see just the JSON data size in ps_oplog (excluding SQLite overhead), run:
dbstat.
Reducing SQLite file size
Both methods of reducing the size of the SQLite file can be executed within the client using
powerSync.execute().VACUUM Command
TheVACUUM command reclaims unused space in the database:
Increase page size
Increasing the page size from the default 4KB (4096 bytes) to 16KB (16384 bytes) can reduce storage overhead significantly. Additional caveats:- May increase overhead for many small writes.
- Best suited for apps with larger data records
VACUUM. It should be one of the first PRAGMA statements after opening a new database:
If you’re changing the page size on an existing database, you must run
VACUUM immediately after setting it to apply the change. For optimal results, set the page size when first creating the database.