Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove -journal file without compromising the database?

Tags:

sql

sqlite

I'm using SQLite and a php application that runs in background. I have blocked the application using (Ctrl-c) and I just noticed that i have database.sqlite and database.sqlite-journal.

At the moment, How can I remove -journal file without compromising the database?

Thank you!

P.S. SQLite version 3.7.9

EDIT:

-rw-r--r--. 1 damiano damiano  51M  8 mar 18.15 test.sqlite2
-rw-r--r--. 1 damiano damiano 2,6K  8 mar 18.15 test.sqlite2-journal
[damiano@localhost backup]$ sqlite3 test.sqlite2
SQLite version 3.7.13 2012-06-11 02:05:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> 
[damiano@localhost backup]$ ls -lh
-rw-r--r--. 1 damiano damiano  51M  8 mar 18.15 test.sqlite2
-rw-r--r--. 1 damiano damiano 2,6K  8 mar 18.15 test.sqlite2-journal
[damiano@localhost backup]$ 
like image 442
Dail Avatar asked Mar 08 '13 17:03

Dail


People also ask

How do you delete a file in a database?

To delete data or log files from a databaseExpand Databases, right-click the database from which to delete the file, and then click Properties. Select the Files page. In the Database files grid, select the file to delete and then click Remove. Click OK.

Is it safe to delete .LDF file?

Save this answer. Show activity on this post. You should not delete any of the database files since it can severely damage your database! If you run out of disk space you might want to split your database in multiple parts.

Does delete free the space in SQL?

After you use a DELETE statement in Microsoft SQL Server to delete data from a table, you may notice that the space that the table uses is not completely released.


2 Answers

Execute this command:

sqlite3 test.sqlite2 vacuum

It will make your database as small as possible and apply possible outstanding transactions or rollbacks in -journal file (and remove it in process). You can actually execute any other transaction that does something (but simply connect/disconnect is NOT enough), but vacuum seems like easiest approach.

like image 173
mvp Avatar answered Oct 05 '22 07:10

mvp


Just open the database (with your program or with the sqlite3 command-line tool). SQLite will then roll back the changes of your interrupted transaction and afterwards remove the journal.

like image 27
CL. Avatar answered Oct 05 '22 06:10

CL.