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

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.


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.


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.