- Systemd example service file could result in database file write issues
if the used systemd version supported ProtectSystem=strict but didn't
support StateDirectory (issue seen at least with systemd 232 in Debian 9)
+ - New
+ - Add configuration option WriteAheadLoggingDatabase to enable SQLite
+ 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
2.2 / 28-Apr-2018
# New configuration settings
+ * 2.3: WriteAheadLoggingDatabase
+
* 2.2: 64bitInterfaceCounters
* 2.1: (none)
# 1 = 64-bit, 0 = 32-bit, -1 = old style logic, -2 = automatic detection
64bitInterfaceCounters -2
+# use SQLite Write-Ahead Logging mode (1 = enabled, 0 = disabled)
+WriteAheadLoggingDatabase 0
+
# vnstati
##
unlimited entries or to 0 to disable the data collection of this
resolution.
+.TP
+.B WriteAheadLoggingDatabase
+Enable or disable SQLite Write-Ahead Logging mode for the database. See SQLite
+documentation for more details and note that support for read-only operations
+isn't available in older versions. 1 = enabled, 0 = disabled.
+
.SH IMAGE OUTPUT RELATED KEYWORDS
.TP
{"LogFile", cfg.logfile, 0, 512, 0},
{"PidFile", cfg.pidfile, 0, 512, 0},
{"64bitInterfaceCounters", 0, &cfg.is64bit, 0, 0},
+ {"WriteAheadLoggingDatabase", 0, &cfg.waldb, 0, 0},
{"HeaderFormat", cfg.hformat, 0, 64, 0},
{"HourlyRate", 0, &cfg.hourlyrate, 0, 0},
{"SummaryRate", 0, &cfg.summaryrate, 0, 0},
validateint("CreateDirs", &cfg.createdirs, CREATEDIRS, 0, 2);
validateint("UpdateFileOwner", &cfg.updatefileowner, UPDATEFILEOWNER, 0, 2);
validateint("64bitInterfaceCounters", &cfg.is64bit, IS64BIT, -2, 1);
+ validatebool("WriteAheadLoggingDatabase", &cfg.waldb, WALDB);
validatebool("TransparentBg", &cfg.transbg, TRANSBG);
validatebool("HourlyRate", &cfg.hourlyrate, HOURLYRATE);
validatebool("SummaryRate", &cfg.summaryrate, SUMMARYRATE);
strncpy_nt(cfg.logfile, LOGFILE, 512);
strncpy_nt(cfg.pidfile, PIDFILE, 512);
cfg.is64bit = IS64BIT;
+ cfg.waldb = WALDB;
cfg.transbg = TRANSBG;
strncpy_nt(cfg.cbg, CBACKGROUND, 8);
printf("ListDays %2d\n", cfg.listdays);
printf("ListMonths %2d\n", cfg.listmonths);
printf("ListYears %2d\n", cfg.listyears);
- printf("ListTop %2d\n", cfg.listtop);
+ printf("ListTop %2d\n\n", cfg.listtop);
- printf("\n\n");
+ printf("\n");
/* vnstatd section */
printf("# vnstatd\n##\n\n");
printf("PidFile \"%s\"\n\n", cfg.pidfile);
printf("# 1 = 64-bit, 0 = 32-bit, -1 = old style logic, -2 = automatic detection\n");
- printf("64bitInterfaceCounters %d\n", cfg.is64bit);
+ printf("64bitInterfaceCounters %d\n\n", cfg.is64bit);
+
+ printf("# use SQLite Write-Ahead Logging mode (1 = enabled, 0 = disabled)\n");
+ printf("WriteAheadLoggingDatabase %d\n\n", cfg.waldb);
- printf("\n\n");
+ printf("\n");
/* vnstati section */
printf("# vnstati\n##\n\n");
#define LOGFILE "/var/log/vnstat/vnstat.log"
#define PIDFILE "/var/run/vnstat/vnstat.pid"
#define IS64BIT -2
+#define WALDB 0
/* no transparency by default */
#define TRANSBG 0
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;
+ int32_t defaultdecimals, hourlydecimals, hourlystyle, is64bit, waldb;
char cfgfile[512], logfile[512], pidfile[512];
char daemonuser[33], daemongroup[33];
int32_t timesyncwait, updateinterval, pollinterval, saveinterval, offsaveinterval, savestatus;
}
/* set pragmas */
- if (!db_setpragmas()) {
- db_close();
- return 0;
+ if (!readonly) {
+ if (!db_setpragmas()) {
+ db_close();
+ return 0;
+ }
}
if (!createdb) {
return 0;
}
+ /* set journal_mode */
+ if (cfg.waldb) {
+ 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;
+ }
+ if (!db_exec("PRAGMA synchronous = 2")) {
+ return 0;
+ }
+ }
+
return 1;
}
}
rc = sqlite3_step(sqlstmt);
- if (rc != SQLITE_DONE) {
+ if (rc != SQLITE_DONE && rc != SQLITE_ROW) {
db_errcode = rc;
snprintf(errorstring, 1024, "Exec step failed (%d: %s): \"%s\"", rc, sqlite3_errmsg(db), sql);
printe(PT_Error);