2

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?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your answer. I found the problem that I opened all my connections with SQLITE_OPEN_READWRITE, that is why it was always opened for writing. Do you know any mechanism to know if a file was indeed written?
You mean, you want to know if inotify has a flag for modifications?
Sorry, I just realized that I have to check the IN_MODIFY flag. It is triggered always twice though. Thanks for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.