C # compressing SQLite Databases

Source: Internet
Author: User
When data is deleted from the SQLite database, unused disk space is added to an internal "Free List. This part of space can be reused when you insert data next time. The disk space will not be lost, but will not be returned to the operating system.

If you delete a large amount of data and want to reduce the space occupied by database files, run the VACUUM command. Vacuum
The database will be re-organized from scratch. This will use an empty "Free linked list" in the database, and the database file will be minimal. However, it takes some time to execute vacuum.
(During SQLite development, it takes about half a second every M bytes on Linux.) In addition, the execution process requires up to two times the temporary disk space of the original database file.

 

/// <Summary> /// execute the compressed database /// </Summary> /// <returns> compress the database </returns> Public static void executezip () {using (sqliteconnection connection = new sqliteconnection (connectionstring) {using (sqlitecommand cmd = new sqlitecommand ("vacuum", connection) {try {connection. open (); cmd. executenonquery ();} catch (system. data. SQLite. sqliteexception e) {connection. close (); log. debug (E. message); // throw new exception (E. message );}}}}

 

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.