mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2025-01-14 00:05:02 -05:00
set sqlite3 options for full durability
This commit is contained in:
parent
1c904b925a
commit
f80c99a43f
4
db/db.rs
4
db/db.rs
@ -1791,6 +1791,8 @@ impl LockedDatabase {
|
|||||||
/// test code.
|
/// test code.
|
||||||
pub fn init(conn: &mut rusqlite::Connection) -> Result<(), Error> {
|
pub fn init(conn: &mut rusqlite::Connection) -> Result<(), Error> {
|
||||||
conn.execute("pragma foreign_keys = on", &[] as &[&ToSql])?;
|
conn.execute("pragma foreign_keys = on", &[] as &[&ToSql])?;
|
||||||
|
conn.execute("pragma fullfsync = on", &[] as &[&ToSql])?;
|
||||||
|
conn.execute("pragma synchronous = 2", &[] as &[&ToSql])?;
|
||||||
let tx = conn.transaction()?;
|
let tx = conn.transaction()?;
|
||||||
tx.execute_batch(include_str!("schema.sql"))?;
|
tx.execute_batch(include_str!("schema.sql"))?;
|
||||||
{
|
{
|
||||||
@ -1852,6 +1854,8 @@ impl<C: Clocks + Clone> Database<C> {
|
|||||||
pub fn new(clocks: C, conn: rusqlite::Connection,
|
pub fn new(clocks: C, conn: rusqlite::Connection,
|
||||||
read_write: bool) -> Result<Database<C>, Error> {
|
read_write: bool) -> Result<Database<C>, Error> {
|
||||||
conn.execute("pragma foreign_keys = on", &[] as &[&ToSql])?;
|
conn.execute("pragma foreign_keys = on", &[] as &[&ToSql])?;
|
||||||
|
conn.execute("pragma fullfsync = on", &[] as &[&ToSql])?;
|
||||||
|
conn.execute("pragma synchronous = 2", &[] as &[&ToSql])?;
|
||||||
{
|
{
|
||||||
let ver = get_schema_version(&conn)?.ok_or_else(|| format_err!(
|
let ver = get_schema_version(&conn)?.ok_or_else(|| format_err!(
|
||||||
"no such table: version. \
|
"no such table: version. \
|
||||||
|
@ -97,6 +97,10 @@ pub fn run(args: &Args, conn: &mut rusqlite::Connection) -> Result<(), Error> {
|
|||||||
// be careful about the order of operations during the upgrade.
|
// be careful about the order of operations during the upgrade.
|
||||||
conn.execute("pragma foreign_keys = on", &[] as &[&ToSql])?;
|
conn.execute("pragma foreign_keys = on", &[] as &[&ToSql])?;
|
||||||
|
|
||||||
|
// Make the database actually durable.
|
||||||
|
conn.execute("pragma fullfsync = on", &[] as &[&ToSql])?;
|
||||||
|
conn.execute("pragma synchronous = 2", &[] as &[&ToSql])?;
|
||||||
|
|
||||||
// WAL is the preferred journal mode for normal operation; it reduces the number of syncs
|
// WAL is the preferred journal mode for normal operation; it reduces the number of syncs
|
||||||
// without compromising safety.
|
// without compromising safety.
|
||||||
set_journal_mode(&conn, "wal").unwrap();
|
set_journal_mode(&conn, "wal").unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user