項目里遇到一個問題,在我們程序客戶端運行時,sqlite數據庫會不斷自動生成/刪除 journal 文件,高峰時候會占用大量的IO,導致程序很慢。
由于客戶端本身的數據完整性不重要,性能非常重要,所以想禁止這個文件的生成。
后來查了一下文檔,并實踐過后,發現網絡上所有的關于關閉/打開某些宏來防止生成的方法都不管用。情急之下,只有改源碼了。
改的地方是在main.c 的 sqlite3BtreeFactory 里,直接加個宏就好了 omitJournal
1 int sqlite3BtreeFactory(
2 const sqlite3 *db, /* Main database when opening aux otherwise 0 */
3 const char *zFilename, /* Name of the file containing the BTree database */
4 int omitJournal, /* if TRUE then do not journal this file */
5 int nCache, /* How many pages in the page cache */
6 int vfsFlags, /* Flags passed through to vfsOpen */
7 Btree **ppBtree /* Pointer to new Btree object written here */
8 ){
9 int btFlags = 0;
10 int rc;
11
12 assert( sqlite3_mutex_held(db->mutex) );
13 assert( ppBtree != 0);
14
15 #ifdef OMIT_JOURNAL
16 omitJournal = 1; //!< turn off journal file
17 #endif