Fixed file size unchanged after SQLite deleted data (VACUUM)

Source: Internet
Author: User
Tags sqlite

Delete all data from the table:

DELETE from [Name]

When a large amount of data has been deleted in SQLite, the size of the database file remains the same. The reason: After deleting data from SQLite, unused disk space is added to an intrinsic "free list" to store the data you insert next. Disk space is not lost. However, it does not return disk space to the operating system.

There are two ways to solve the problem:
1, after the data is deleted, manually execute the SQL "VACUUM" command, the execution method is very simple. Recommended use.
2, set the auto_vacuum to "1" when the database file is built. The second method, however, has the disadvantage of truncating only the pages in the free list from the database file, without reclaiming the fragments in the database, or re-organizing the contents of the database like a vacuum command. In fact, Auto-vacuum will produce more fragmentation because of the need to move pages in the database file. Also, there is the. db-journal file that is generated when the delete operation is performed. To use auto-vacuum, you need some preconditions. The database needs to store some extra information to record each database page it tracks back to its pointer location. Therefore, the Auto-vacumm must be opened before the table is built. After a table is created, Auto-vacumm can no longer be turned on or off.

http://blog.csdn.net/libaineu2004/article/details/28433633

Fixed file size unchanged after SQLite deleted data (VACUUM)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.