On Sat, Jan 26, 2013 at 6:50 PM, Shuki Sasson <gur.mons...@gmail.com> wrote:
>
> Hi all, I read the documentation about the synchronization pragma.
> It got to do with how often xSync method is called.
> With synchronization = FULL xSync is called after each and every change to
> the DataBase file as far as I understand...
>
> Observing the VFS interface used by the SQLITE:
>
> typedef struct sqlite3_io_methods sqlite3_io_methods;
> struct sqlite3_io_methods {
>   int iVersion;
>   int (*xClose)(sqlite3_file*);
>   int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
>   *int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst);*
>   int (*xTruncate)(sqlite3_file*, sqlite3_int64 size);
>  * int (*xSync)(sqlite3_file*, int flags);*
>
> *
> *
>
> I see both xWrite and xSync...
>
> Is this means that xWrite initiate  a FS write to the file?

Yes, in a sense that subsequent read without power cut from the
machine will return written data.

>
> Is that means that xSync makes sure that the FS buffered changes are
> synced to disk?

Yes.

> I guess it is calling fsync in case of LINUX /FreeBSD am I right?

fdatasync() I think.

> If the above is correct and SQLITE operates over modern reliable FS
> that has journaling with each write, than despite the fact that the
> write buffer cache are not fully synced they are protected by the FS
> journal that fully records all the changes to the file and that is
> going to be replayed in case of a FS mount after a system crash.
>
> If  my understanding is correct than assuming the FS journaling  is
> bullet proof than I can safely operate with synchronization = OFF with
> SQLITE and still be fully protected by the FS journal in case system
> crash, right?

I really doubt journaling filesystems work like that. Yes, your file
will be restored using journal if the journal records made it to disk.
But FS just can't physically write every record of the journal to disk
at the moment of that record creation. If it did that your computer
would be really slow. But as FS doesn't do that fdatasync still makes
sense if you want to guarantee that when COMMIT execution is finished
it's safe to cut the power off or crash.

> Meaning synchronization = NORMAL doesn't buy me anything in fact it
> severely slows the Data Base operations.
>
> Am I missing something here?

Please re-check documentation on how journaling FS work.


Pavel
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to