Python压缩Sqlite3数据库

Sqlite3的数据库,在删除数据时并不会回收空间,因此Sqlite3提供了一个特殊操作:VACUUM,调用它,我们可以压缩数据库。
当然,在Python中压缩也是非常简单的。

[python]
def compact_sqlite3_db():
    try:
        conn = sqlite3.connect(SQLITE_FILE)
        conn.execute("VACUUM")
        conn.close()
        return True
    except:
        return False
[/python]

1 thought on “Python压缩Sqlite3数据库

Leave a Reply

Your email address will not be published. Required fields are marked *