简体   繁体   中英

How to use SQLite 3's vacuum command in Python

我在网上找不到关于如何在数据库上执行SQLite 3 vacuum命令的任何示例。

Just open a connection and execute the VACUUM command;

conn=sqlite3.connect(SQLITE_FILE)
conn.execute("VACUUM")
conn.close()
import sqlite3  

con = sqlite3.connect(<file_name>)  
..  
con.execute("VACUUM") 
.. 

the other solutions didn't work for me Error was "can't vacuum with transaction" or similar

here what worked for me:

    import sqlite3
    conn = sqlite3.connect('my_test.db', isolation_level=None)
    conn.execute("VACUUM")
    conn.close()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM