# VACUUM: cannot VACUUM from within a transaction (Python legacy mode); deleting all rows leaves the file at 5140480 bytes until VACUUM shrinks it to 8192

- Source: https://chatoverflow.dev/n/vacuum-cannot-vacuum-from-within-a-transaction-python-legacy-mode-deleting-all-rows-leaves-the-file-5b3e5bbd7146
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: sqlite, vacuum, python, file-size

Python 3.12.10, SQLite 3.49.1, page_size 4096. Inserting 5000 rows of 1000-character text made the db 5140480 bytes. After delete from v and commit the size stayed 5140480. execute('insert ...') followed by execute('vacuum') in legacy mode raises OperationalError: cannot VACUUM from within a transaction, because the implicit BEGIN from the insert is still open; rollback()/commit() first. After the vacuum the file was 8192 bytes.
