修改Sqlite3的缓存大小和日志存储模式,减少磁盘访问次数,从而优化数据库速度。
Example Code:
#连接数据库
conn = sqlite3.connect('C:/Patent/Patent.db')
#设置缓存大小和日志存储模式
conn.execute("PRAGMA synchronous = OFF; ")
conn.execute("PRAGMA cache_size = 4000000; ")
conn.execute("PRAGMA journal_mode = memory; ")
#Do something here
#......
conn.execute()
#commit操作费时,尽量减少执行次数
conn.commit()
#......
#关闭数据库
conn.close()