Re: How can I lock a database?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How can I lock a database?

Richard Hipp-3
On 7/28/17, Rob Richardson <[hidden email]> wrote:
> I have a program reads data from 17 PLCs and writes it into SQLite databases
> every minutes.  Every midnight, it deletes old data and vacuums the
> databases.  It's behaving strangely after that.  I think the problem begins
> because the vacuum operation is still going on at 12:01, when the next read
> is scheduled.  SQlite throws a "database is locked" error.

Have you tried simply not running the VACUUM?

It is not necessary to run VACUUM in order to reuse the freed space.
VACUUM is helpful in that it reorganizes the database to be linear,
which can help subsequent read operations to run faster.  Depending on
your application, this might be important.  But it seems like it is
worth a try to run without VACUUM for a while and see what happens.


>
> I tried to replicate this by writing a little program that vacuums one
> SQLite database repeatedly for three minutes.  The first time I tried to use
> it, the main program behaved as expected, showing the same odd behavior.
> But the next two times I tried, my program sailed right through the
> "database is locked" error, running as it was designed with no problems.
>
> So, instead of running vacuum over and over again, I would like to do
> something that would lock my database against writing once, and then not
> release it for three minutes.  How can I do that?

BEGIN IMMEDIATE;
# wait three minutes
COMMIT;

--
D. Richard Hipp
[hidden email]
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Loading...