Story Details

  • A faster way to copy SQLite databases between computers

    Posted: 2025-05-01 11:15:08

    Copying SQLite databases between machines can be faster than simply copying the file. Using the sqlite3 .dump command exports the database schema and data as SQL statements, which can then be piped to sqlite3 on the destination machine to recreate the database. This method avoids copying potentially wasted empty space within the database file, resulting in a smaller transfer and quicker import. While rsync can be efficient, this dump and import method offers an even faster solution, especially for databases with a lot of free space.

    Summary of Comments ( 122 )
    https://news.ycombinator.com/item?id=43856186

    HN users discuss various aspects of copying SQLite databases. Several highlight rsync as a faster, simpler alternative for initial copies and subsequent updates, particularly with the --sparse option for handling holes in files. Some suggest using sqlite3 .dump and sqlite3 .read for logical copies, emphasizing portability but acknowledging potential slowdowns with large datasets. Others delve into the nuances of SQLite's locking behavior and the trade-offs between copying the database file directly versus using the dump/restore method, especially concerning transactional consistency. Finally, the potential benefits of using mmap for faster reads are mentioned.