How to use SQLite 3's vacuum command in Python

后端 未结 3 1171
既然无缘
既然无缘 2021-02-12 06:29

I cannot find any example on the net of how the SQLite 3 vacuum command is done on a database.

相关标签:
3条回答
  • 2021-02-12 06:44

    Just open a connection and execute the VACUUM command;

    conn=sqlite3.connect(SQLITE_FILE)
    conn.execute("VACUUM")
    conn.close()
    
    0 讨论(0)
  • 2021-02-12 06:44
    import sqlite3  
    
    con = sqlite3.connect(<file_name>)  
    ..  
    con.execute("VACUUM") 
    .. 
    
    0 讨论(0)
  • 2021-02-12 06:46

    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()
    
    0 讨论(0)
提交回复
热议问题