Write-Ahead Logging mode which may provide some disk i/o benefits,
see https://www.sqlite.org/wal.html for more details and note that
SQLite 3.22.0 or later is required to support read-only operations
+ - Add configuration option DatabaseSynchronous for changing the SQLite
+ setting of the "synchronous" flag, see
+ https://www.sqlite.org/pragma.html#pragma_synchronous for more details
- Show warning in log if writing cached data to database is slow
- Try database query for up to 5 seconds when database is busy or locked
instead of giving up immediately
# New configuration settings
- * 2.3: WriteAheadLoggingDatabase
+ * 2.3: WriteAheadLoggingDatabase, DatabaseSynchronous
* 2.2: 64bitInterfaceCounters
# use SQLite Write-Ahead Logging mode (1 = enabled, 0 = disabled)
WriteAheadLoggingDatabase 0
+# change the setting of the SQLite "synchronous" flag
+# (-1 = auto, 0 = off, 1, = normal, 2 = full, 3 = extra)
+DatabaseSynchronous -1
+
# vnstati
##
unlimited entries or to 0 to disable the data collection of this
resolution.
+.TP
+.B DatabaseSynchronous
+Change the setting of the SQLite "synchronous" flag which controls how much
+care is taken to ensure disk writes have fully completed when writing data to
+the database before continuing other actions. Higher values take extra steps
+to ensure data safety at the cost of slower performance. A value of 0 will
+result in all handling being left to the filesystem itself. Set to -1 to
+select the default value according to database mode controlled by
+.B WriteAheadLoggingDatabase
+setting. See SQLite documentation for more details regarding values from 1
+to 3. Value range: -1..3
+
.TP
.B HourlyDays
Data retention duration for the one hour resolution entries. The configuration
{"PidFile", cfg.pidfile, 0, 512, 0},
{"64bitInterfaceCounters", 0, &cfg.is64bit, 0, 0},
{"WriteAheadLoggingDatabase", 0, &cfg.waldb, 0, 0},
+ {"DatabaseSynchronous", 0, &cfg.dbsynchronous, 0, 0},
{"HeaderFormat", cfg.hformat, 0, 64, 0},
{"HourlyRate", 0, &cfg.hourlyrate, 0, 0},
{"SummaryRate", 0, &cfg.summaryrate, 0, 0},
validateint("UpdateFileOwner", &cfg.updatefileowner, UPDATEFILEOWNER, 0, 2);
validateint("64bitInterfaceCounters", &cfg.is64bit, IS64BIT, -2, 1);
validatebool("WriteAheadLoggingDatabase", &cfg.waldb, WALDB);
+ validateint("DatabaseSynchronous", &cfg.dbsynchronous, DBSYNCHRONOUS, -1, 3);
validatebool("TransparentBg", &cfg.transbg, TRANSBG);
validatebool("HourlyRate", &cfg.hourlyrate, HOURLYRATE);
validatebool("SummaryRate", &cfg.summaryrate, SUMMARYRATE);
strncpy_nt(cfg.pidfile, PIDFILE, 512);
cfg.is64bit = IS64BIT;
cfg.waldb = WALDB;
+ cfg.dbsynchronous = DBSYNCHRONOUS;
cfg.transbg = TRANSBG;
strncpy_nt(cfg.cbg, CBACKGROUND, 8);
printf("# use SQLite Write-Ahead Logging mode (1 = enabled, 0 = disabled)\n");
printf("WriteAheadLoggingDatabase %d\n\n", cfg.waldb);
+ printf("# change the setting of the SQLite \"synchronous\" flag\n");
+ printf("# (-1 = auto, 0 = off, 1, = normal, 2 = full, 3 = extra)\n");
+ printf("DatabaseSynchronous %d\n\n", cfg.dbsynchronous);
+
printf("\n");
/* vnstati section */
#define WALDB 0
#define WALDBCHECKPOINTINTERVALMINS 240
#define SLOWDBFLUSHWARNLIMIT 3.0
+#define DBSYNCHRONOUS -1
/* database read timeout */
#define DBREADTIMEOUTSECS 5
char cline[8], clinel[8], cvnstat[8], crx[8], crxd[8], ctx[8], ctxd[8];
int32_t unitmode, rateunitmode, rateunit, bvar, qmode, sampletime, hourlyrate, summaryrate;
int32_t monthrotate, monthrotateyears, maxbw, spacecheck, trafficlessentries, transbg, ostyle;
- int32_t defaultdecimals, hourlydecimals, hourlystyle, is64bit, waldb;
+ int32_t defaultdecimals, hourlydecimals, hourlystyle, is64bit, waldb, dbsynchronous;
char cfgfile[512], logfile[512], pidfile[512];
char daemonuser[33], daemongroup[33];
int32_t timesyncwait, updateinterval, pollinterval, saveinterval, offsaveinterval, savestatus;
int db_setpragmas(void)
{
int rc;
+ char sql[25];
sqlite3_stmt *sqlstmt;
/* enable use of foreign keys */
if (!db_exec("PRAGMA journal_mode = WAL")) {
return 0;
}
- if (!db_exec("PRAGMA synchronous = 1")) {
- return 0;
- }
} else {
if (!db_exec("PRAGMA journal_mode = DELETE")) {
return 0;
}
+ }
+#endif
+
+ /* set synchronous */
+ if (cfg.dbsynchronous == -1) {
+#if HAVE_DECL_SQLITE_CHECKPOINT_RESTART
+ if (cfg.waldb) {
+ if (!db_exec("PRAGMA synchronous = 1")) {
+ return 0;
+ }
+ } else {
+ if (!db_exec("PRAGMA synchronous = 2")) {
+ return 0;
+ }
+ }
+#else
if (!db_exec("PRAGMA synchronous = 2")) {
return 0;
}
- }
#endif
+ } else {
+ snprintf(sql, 25, "PRAGMA synchronous = %d", cfg.dbsynchronous);
+ if (!db_exec(sql)) {
+ return 0;
+ }
+ }
return 1;
}