Skip to content

Instantly share code, notes, and snippets.

@Nyahua
Created April 10, 2017 02:15
Show Gist options
  • Save Nyahua/cc4303eaec3dd0122124851882d23277 to your computer and use it in GitHub Desktop.
Save Nyahua/cc4303eaec3dd0122124851882d23277 to your computer and use it in GitHub Desktop.
VACUUM sqlite in python3.6
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