Search code examples
sqliteinotify

SQLite Database written on read


I have been playing around with inotify and a sqlite database as I wanted to know how often the database file was written.

The thing is that the database file is written everytime I send a query. It does not matter if it is to read (SELECT) or to modify (UPDATE). The inotify flag IN_CLOSE_WRITE is always activated after that.

I wanted to avoid as much writing as possible. Am I missing anything here? Should not the database only be written when performing operations to modify it?


Solution

  • The IN_CLOSE_WRITE flag does not indicate that something was written, only that the file was openend for writing.

    The database does not know whether you will write something later, so it opens the file with write access to avoid having to reopen it.

    If you know you never want to write, use the SQLITE_OPEN_READONLY flag.