Created
April 10, 2017 02:15
-
-
Save Nyahua/cc4303eaec3dd0122124851882d23277 to your computer and use it in GitHub Desktop.
VACUUM sqlite in python3.6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3, os | |
def vacuum(db_name): | |
print("Filesize of {} before vaccum is {:,d} bytes.". | |
format(db_name, os.stat(db_name).st_size) | |
) | |
conn = sqlite3.connect(db_name) | |
isolation = conn.isolation_level | |
print(isolation) | |
conn.isolation_level = None | |
print('begin vacumming.....') | |
conn.execute('VACUUM') | |
conn.isolation_level = isolation | |
print("Filesize of {} after vaccum is {:,d} bytes.". | |
format(db_name, os.stat(db_name).st_size) | |
) | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment