SQLite Forum

Renaming a database
Login
> It's never, ever generically safe to rename an in-use sqlite3 file.

That somewhat contradicts the suggestion that sqlite works well as an application file format. Never renamed a spreadsheet?

> moved to a different filesystem and therefore gets a new inode - i'm not actually sure what happens in that case

A move to a different filesystem is effectively a copy, and that could be achieved without risk of corruption using the backup API. But I'm looking for a solution that avoids rewriting every page.

> Windows won't let you rename an in-use file

Well actually that would be a good solution. If Windows blocks any unsafe renames, then I can simply retry. Unfortunately I'm on unix.

> In order to safely rename an sqlite db, it must not currently be opened by any clients

So (on unix) is there a way to prevent it being used by any clients? Some exclusive lock that can be taken during the rename?