# how thread safe is sqlite?

**URL:** <https://forum.xojo.com/t/how-thread-safe-is-sqlite/34937>\
**Category:** Databases\
**Created:** [December 13, 2016, 3:11am UTC](https://forum.xojo.com/t/how-thread-safe-is-sqlite/34937 "2016-12-13T03:11:47Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phillip\_Smith](https://forum.xojo.com/letter_avatar_proxy/v4/letter/p/ba9def/32.png) [@Phillip\_Smith](https://forum.xojo.com/u/Phillip_Smith)\
**Post date:** [December 13, 2016, 3:11am UTC](https://forum.xojo.com/t/how-thread-safe-is-sqlite/34937/1 "2016-12-13T03:11:47Z")

</div>

Is it safe to have an application with multiple read/write threads who each have their own connection to a single sqlite database? Or is it better to have each thread send its read/write commands to a message queue where the main thread can read and process that?

Thanks,

Phil

---

<div class="post-metadata">

**Author:** ![Tim\_Parnell](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_parnell/32/161_2.png) [@Tim\_Parnell](https://forum.xojo.com/u/Tim_Parnell)\
**Post date:** [December 13, 2016, 3:33am UTC](https://forum.xojo.com/t/how-thread-safe-is-sqlite/34937/2 "2016-12-13T03:33:56Z")

</div>

Not related to threads SQLite isn’t going to handle multiple simultaneous read/writes well, it’s not a multi-user database.

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [December 13, 2016, 3:36am UTC](https://forum.xojo.com/t/how-thread-safe-is-sqlite/34937/3 "2016-12-13T03:36:11Z")

</div>

[http://sqlite.org/lockingv3.html](http://sqlite.org/lockingv3.html)

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [December 13, 2016, 3:38am UTC](https://forum.xojo.com/t/how-thread-safe-is-sqlite/34937/4 "2016-12-13T03:38:57Z")

</div>

> [@303018:@Tim Parnell](#):
>
> Not related to threads SQLite isn’t going to handle multiple simultaneous read/writes well, it’s not a multi-user database.

Actually it does a decent job if you have many apps connected using separate connections  
Now its not going to compete with the kind of heavy loads you can shove on Oracle, PostgreSQL, MS SQL etc it can handle a decent amount of concurrency as it sits.  
It is serverless though so for concurrency you’re limited to apps/processes on the same machine

The guys at [SQLite.org](http://SQLite.org) have documented “appropriate uses” and if you stick to that you’re unlikely to have issues

---

<div class="post-metadata">

**Author:** ![Tim\_Parnell](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_parnell/32/161_2.png) [@Tim\_Parnell](https://forum.xojo.com/u/Tim_Parnell)\
**Post date:** [December 13, 2016, 3:41am UTC](https://forum.xojo.com/t/how-thread-safe-is-sqlite/34937/5 "2016-12-13T03:41:32Z")

</div>

Orly?  
I wonder where I picked up the notion.

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [December 13, 2016, 3:42am UTC](https://forum.xojo.com/t/how-thread-safe-is-sqlite/34937/6 "2016-12-13T03:42:24Z")

</div>

Just read the link I posted

edit - and this one [http://sqlite.org/faq.html#q5](http://sqlite.org/faq.html#q5)

---

<div class="post-metadata">

**Author:** ![scott\_boss](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@scott\_boss](https://forum.xojo.com/u/scott_boss)\
**Post date:** [December 13, 2016, 1:03pm UTC](https://forum.xojo.com/t/how-thread-safe-is-sqlite/34937/7 "2016-12-13T13:03:13Z")

</div>

[quote=303020:@Norman Palardy]Actually it does a decent job if you have many apps connected using separate connections  
Now its not going to compete with the kind of heavy loads you can shove on Oracle, PostgreSQL, MS SQL etc it can handle a decent amount of concurrency as it sits.  
It is serverless though so for concurrency you’re limited to apps/processes on the same machine

The guys at [SQLite.org](http://SQLite.org) have documented “appropriate uses” and if you stick to that you’re unlikely to have issues[/quote]

SQLite v3 has gotten approval for use on board aircraft (for aircraft operations - not just things like entertainment) and they have very strict rules about the ability to have stability under all situations. And from what I remember when I talked to Dr Hipp (of SQLite fame) having a stable multiple app read/writing to the same database (datafile) must be very stable. Like @Norman Palardy said there is a “best practices” or “blue print” of the way to do it to achieve it.v

Now I have have an application that has two separate apps that write/read from the same database (file). I have a perl app that runs out of cron that does some web based pulling of data and placing data in the the database with the `replace` command. Then I have a Xojo app that reads/writes to the database every 100 milliseconds (was going to say constantly but technically it isnt). And never ever had a problem. Now that I think about it, I dont think I have turned on multiuser (WAL) in either app. Now that I write that, I think I need to go and check that out. I might need to fix it.

Helping others on teh forum this morning has lead to me seeing I have 2 different issues at hand (or potential issues).

---

<div class="post-metadata">

**Author:** ![Tim\_Parnell](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_parnell/32/161_2.png) [@Tim\_Parnell](https://forum.xojo.com/u/Tim_Parnell)\
**Post date:** [December 13, 2016, 2:55pm UTC](https://forum.xojo.com/t/how-thread-safe-is-sqlite/34937/8 "2016-12-13T14:55:34Z")

</div>

It’s good to find out SQLite is more robust than I thought it was.

---

<div class="post-metadata">

**Author:** ![scott\_boss](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@scott\_boss](https://forum.xojo.com/u/scott_boss)\
**Post date:** [December 13, 2016, 3:01pm UTC](https://forum.xojo.com/t/how-thread-safe-is-sqlite/34937/9 "2016-12-13T15:01:30Z")

</div>

> [@303130:@Tim Parnell](#):
>
> It’s good to find out SQLite is more robust than I thought it was.

there is military devices that use SQLite. Cant say which ones but they do exist. It was a big win for Dr Hipp but cant talk about the win. I found out from someone in the government.

---

<div class="post-metadata">

**Author:** ![Phillip\_Smith](https://forum.xojo.com/letter_avatar_proxy/v4/letter/p/ba9def/32.png) [@Phillip\_Smith](https://forum.xojo.com/u/Phillip_Smith)\
**Post date:** [December 13, 2016, 3:14pm UTC](https://forum.xojo.com/t/how-thread-safe-is-sqlite/34937/10 "2016-12-13T15:14:25Z")

</div>

> [@303134:@scott boss](#):
>
> there is military devices that use SQLite. Cant say which ones but they do exist. It was a big win for Dr Hipp but cant talk about the win. I found out from someone in the government.

Wow, I can only imagine how hard it is to get certified for military/government use.

---

<div class="post-metadata">

**Author:** ![scott\_boss](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@scott\_boss](https://forum.xojo.com/u/scott_boss)\
**Post date:** [December 13, 2016, 5:01pm UTC](https://forum.xojo.com/t/how-thread-safe-is-sqlite/34937/11 "2016-12-13T17:01:22Z")

</div>

> [@303135:@Phillip Smith](#):
>
> Wow, I can only imagine how hard it is to get certified for military/government use.

it is. and it is only certified to be used in certain places, doing certain things, using the “blue prints” from Dr Hipp.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 6:34pm UTC](https://forum.xojo.com/t/how-thread-safe-is-sqlite/34937/12 "2020-10-29T18:34:49Z")

</div>


