Compact DB on startup

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for SQLite
Post Reply
johnselkirk
Posts: 10
Joined: Thu 07 Oct 2010 00:03
Location: US

Compact DB on startup

Post by johnselkirk » Mon 07 Jan 2013 13:11

Hi,

I am using EF with a SQL Lite DB which has 'Journal Mode=WAL' set in the connection string as there are a few processes that could be accessing the DB.

I would like to compact the DB on startup of any of processes and have no clue if that is safe to do or what the best setting is to do that. (connection string/code/??)

Any advice would be greatly appreciated.

John.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Compact DB on startup

Post by Shalex » Wed 09 Jan 2013 15:42

Please execute the "VACUUM" statement to compact your SQLite database:

Code: Select all

using (SQLiteCommand cmd = conn.CreateCommand())
{
  cmd.CommandText = "VACUUM";
  cmd.ExecuteNonQuery();
}

Fretek
Posts: 8
Joined: Sun 13 Mar 2011 12:03

Re: Compact DB on startup

Post by Fretek » Sun 03 Feb 2013 09:45

Shalex wrote:Please execute the "VACUUM" statement to compact your SQLite database:

Code: Select all

using (SQLiteCommand cmd = conn.CreateCommand())
{
  cmd.CommandText = "VACUUM";
  cmd.ExecuteNonQuery();
}
Which way is best to use? Code (as in the example above) or with connctionsting - AutoVaccuum = Full?
What is the difference between these two ways?

Fretek
Posts: 8
Joined: Sun 13 Mar 2011 12:03

Re: Compact DB on startup

Post by Fretek » Thu 07 Feb 2013 15:50

Fretek wrote:
Shalex wrote:Please execute the "VACUUM" statement to compact your SQLite database:

Code: Select all

using (SQLiteCommand cmd = conn.CreateCommand())
{
  cmd.CommandText = "VACUUM";
  cmd.ExecuteNonQuery();
}
Which way is best to use? Code (as in the example above) or with connctionsting - AutoVaccuum = Full?
What is the difference between these two ways?
Wish to know which method is considered the best and fastest

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Compact DB on startup

Post by Shalex » Fri 08 Feb 2013 09:31

Sorry for the delay.

The "AutoVaccuum=Full;" connection string parameter turns on the following pragma: http://sqlite.org/pragma.html#pragma_auto_vacuum.

The SQLiteCommand with the "VACUUM" command text calls this command: http://sqlite.org/lang_vacuum.html.

Post Reply