diff --git a/CHANGELOG.md b/CHANGELOG.md index 9be1be12..55e8b839 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ ### Implementation changes and bug fixes - [PR #827](https://github.com/rqlite/rqlite/pull/827): Upgrade dependencies, including SQLite to 3.36. - [PR #835](https://github.com/rqlite/rqlite/pull/835): Use Go standard libary sql/database abstraction. Fixes [issue #830](https://github.com/rqlite/rqlite/issues/830). -- [PR #835](https://github.com/rqlite/rqlite/pull/835): Use SQLite connection pool. +- [PR #835](https://github.com/rqlite/rqlite/pull/835): Use SQLite connection pool and add pool statistics to status output. +- [PR #836](https://github.com/rqlite/rqlite/pull/836): Add current SQLite journal mode to status output. ## 6.0.1 (June 28th 2021) ### Implementation changes and bug fixes diff --git a/db/db.go b/db/db.go index 0c6c9b2c..0395c65b 100644 --- a/db/db.go +++ b/db/db.go @@ -27,6 +27,7 @@ const ( fkChecks = "PRAGMA foreign_keys" fkChecksEnabled = "PRAGMA foreign_keys=ON" fkChecksDisabled = "PRAGMA foreign_keys=OFF" + journalCheck = "PRAGMA journal_mode" numExecutions = "executions" numExecutionErrors = "execution_errors" @@ -232,6 +233,15 @@ func (db *DB) FKConstraints() (bool, error) { return false, nil } +// JournalMode returns the current journal mode. +func (db *DB) JournalMode() (string, error) { + r, err := db.QueryStringStmt(journalCheck) + if err != nil { + return "", err + } + return r[0].Values[0][0].(string), nil +} + // Size returns the size of the database in bytes. "Size" is defined as // page_count * schema.page_size. func (db *DB) Size() (int64, error) { diff --git a/db/db_test.go b/db/db_test.go index 4cd06477..c59d90bd 100644 --- a/db/db_test.go +++ b/db/db_test.go @@ -762,6 +762,34 @@ func Test_ForeignKeyConstraints(t *testing.T) { } } +func Test_JournalMode(t *testing.T) { + db, path := mustCreateDatabase() + defer db.Close() + defer os.Remove(path) + + m, err := db.JournalMode() + if err != nil { + t.Fatalf("failed to check journal mode: %s", err.Error()) + } + if exp, got := "delete", m; exp != got { + t.Fatalf("got wrong mode for journal, expected %s, got %s", exp, got) + } + + _, err = db.ExecuteStringStmt(`PRAGMA journal_mode=off`) + if err != nil { + t.Fatalf(`failed to execute 'PRAGMA journal_mode' statement: %s`, err.Error()) + } + + m, err = db.JournalMode() + if err != nil { + t.Fatalf("failed to check journal mode: %s", err.Error()) + } + if exp, got := "off", m; exp != got { + t.Fatalf("got wrong mode for journal, expected %s, got %s", exp, got) + } + +} + func Test_UniqueConstraints(t *testing.T) { db, path := mustCreateDatabase() defer db.Close() diff --git a/store/store.go b/store/store.go index 21db75c3..f4234836 100644 --- a/store/store.go +++ b/store/store.go @@ -459,12 +459,17 @@ func (s *Store) Stats() (map[string]interface{}, error) { if err != nil { return nil, err } + jm, err := s.db.JournalMode() + if err != nil { + return nil, err + } dbStatus := map[string]interface{}{ "dsn": s.dbConf.DSN, "fk_constraints": enabledFromBool(fkEnabled), "version": sql.DBVersion, "db_size": dbSz, "conn_pool_stats": s.db.ConnectionPoolStats(), + "journal_mode": jm, } if s.dbConf.Memory { dbStatus["path"] = ":memory:"