Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite3 pragma synchronous not persistent

Tags:

sqlite

pragma

I am using an SQLite3 database i WAL-mode. The default mode for pragma statement synchronous is 2 (full), but this makes inserts really slow and according to documentation 1 (normal) should be fine.

Changing synchronous mode works as long as the database is open, but seems to reset when the connection is ended:

root@linux:~# sqlite3 mydb.db
SQLite version 3.8.6 2014-08-15 11:46:33
sqlite> pragma synchronous;
2
sqlite> pragma synchronous=1;
sqlite> pragma synchronous;
1
sqlite>[exit]
root@linux:~# sqlite3 mydb.db
SQLite version 3.8.6 2014-08-15 11:46:33
sqlite> pragma synchronous;
2

Nothing else is using the database. Can anyone tell me how to make this change persistent?

Also, what is the difference between setting pragma synchronous and pragma [database name].synchronous? Neither is persistent, by the way.

like image 237
Martin Avatar asked Mar 30 '16 12:03

Martin


1 Answers

Like most other PRAGMAs, this setting applies not to the database but to the database connection.

It cannot be made persistent. You have to make it whenever you open the database.

like image 92
CL. Avatar answered Sep 28 '22 00:09

CL.