// sqlite · parallelism & workers

threads

How many auxiliary worker threads one connection may start to help run a query.

По умолчанию
0 (no worker threads)
Range
0 or more threads
Restart needed
Нет
Default checked on
SQLite 3.5x

Что оно делает

The main user is the sorter behind ORDER BY, GROUP BY and CREATE INDEX. 0 keeps everything on the calling thread. The value sets the per-connection SQLITE_LIMIT_WORKER_THREADS limit; SQLITE_DEFAULT_WORKER_THREADS can set the default at compile time and SQLITE_MAX_WORKER_THREADS caps how high it can go.

Значение по умолчанию

0 (no worker threads). 0 (a stock SQLite 3.5x build) unless the build sets SQLITE_DEFAULT_WORKER_THREADS.

Check the current value

PRAGMA threads;

SELECT * FROM pragma_threads;   -- table-valued form, usable in queries

Change it

PRAGMA threads = 4;   -- this connection only

No restart. It applies at once to the connection that runs it and is lost when that connection closes, so set it every time a connection opens.

When to change it

On multi-core machines that run big sorts or build large indexes and can spare the cores; small values such as 2 to 4 are the usual starting point.

What can go wrong

Worker threads duplicate sort buffers and compete with the application for CPU, so on a busy server they can worsen overall latency while speeding up one sort. The limit is per connection, so every pooled connection gets its own allowance.

Questions about threads

What is the default value of threads in SQLite?

0 (no worker threads). 0 (a stock SQLite 3.5x build) unless the build sets SQLITE_DEFAULT_WORKER_THREADS.

Does changing threads require a restart?

No. No restart. It applies at once to the connection that runs it and is lost when that connection closes, so set it every time a connection opens.

When should I change threads?

On multi-core machines that run big sorts or build large indexes and can spare the cores; small values such as 2 to 4 are the usual starting point.

Back to all SQLite settings, or check the SQLite manual for every option.

// one client for every engine

Check threads on your own server

SQLly runs the query above against SQLite and the other engines in this reference, from one desktop app on macOS, Windows and Linux.

Текст и данные на этой странице: CC BY 4.0, с указанием SQLly (sqlly.app). Код и фрагменты SQL: MIT. Подробнее о лицензии