Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the maximum number of connections for a SQLite3 database?

People also ask

Can you have multiple connections to SQLite database?

SQLite does support multiple concurrent connections, and therefore it can be used with a multi-threaded or multi-process application. The catch is that when SQLite opens a write transaction, it will lock all the tables.

How many users can SQLite handle?

Yes SQLite can support multiple users at once. It does however lock the whole database when writing, so if you have lots of concurrent writes it is not the database you want (usually the time the database is locked is a few milliseconds - so for most uses this does not matter).

How big can sqlite3 database be?

SQLite database files have a maximum size of about 140 TB. On a phone, the size of the storage (a few GB) will limit your database file size, while the memory size will limit how much data you can retrieve from a query. Furthermore, Android cursors have a limit of 1 MB for the results.

How many requests per second can SQLite handle?

Actually, SQLite will easily do 50,000 or more INSERT statements per second on an average desktop computer. But it will only do a few dozen transactions per second. Transaction speed is limited by the rotational speed of your disk drive.


http://sqlite.org/whentouse.html explains "Situations Where Another RDBMS May Work Better":

SQLite uses reader/writer locks on the entire database file. That means if any process is reading from any part of the database, all other processes are prevented from writing any other part of the database. Similarly, if any one process is writing to the database, all other processes are prevented from reading any other part of the database. For many situations, this is not a problem. Each application does its database work quickly and moves on, and no lock lasts for more than a few dozen milliseconds. But there are some applications that require more concurrency, and those applications may need to seek a different solution.


There is actually no pre-defined limit for number of concurrent connections in sqlite for the same process. This is upto your system's performance. The quotation given by user647772 is about limit of concurrent processes or applications using the same sqlite DB, not valid for concurrent threads in the same process.


Under different system, this value may be different, the python test code:

import sqlite3
import sys

# connect to multiple databases
def multi_connect(conn_num):
    dbs = []
    for i in range(0, conn_num):
        try:
            con = sqlite3.connect(str(i) + '.db')
        except Exception as e:
            print('connect to %d.db failed' % i)
            sys.exit(-1)


# multiple connections to single database
def multi_connect2(conn_num):
    db_name = 'x.db'
    conns = []
    for i in range(0, conn_num):
        try:
            conn = sqlite3.connect(db_name)
        except Exception as e:
            print('connect failed at %d' % i)
            sys.exit(-1)

Under ubuntu, the failed count is 1021, you can test it under different OS.