# cache_spill

> Let the pager write dirty cache pages to the database file in the middle of a transaction.

Source: https://sqlly.app/sql-configuration/sqlite/cache-spill
Last updated: 2026-11-30
License: Text and data [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) (credit SQLly, sqlly.app); code and SQL snippets [MIT](https://opensource.org/license/mit). [Details](https://sqlly.app/license).

**Default**

`1 (on)`

**Range**

ON, OFF, or a page-count threshold

**Restart needed**

No

**Default checked on**

SQLite 3.5x

## What it does

On by default. Spilling keeps long transactions from holding every dirty page in memory, but a spill takes an EXCLUSIVE lock on the database file that lasts until COMMIT. The boolean form covers every attached database; cache_spill=N raises the threshold for main (or a named schema) alone, and pages then have to pass both that threshold and cache_size before spilling starts.

## Default value

`1 (on)`. On (a stock SQLite 3.5x build).

## Check the current value

```
PRAGMA cache_spill;

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

## Change it

```
PRAGMA cache_spill = OFF;   -- 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

Leave it on unless a very large, long-running transaction should not take the file's EXCLUSIVE lock early, so other writers are not locked out until COMMIT.

## What can go wrong

With spilling off, dirty pages pile up in memory, so a transaction writing more pages than the cache holds has nowhere to put them until COMMIT; memory use jumps and the commit itself does more work at once.

## Questions about cache_spill

### What is the default value of cache_spill in SQLite?

1 (on). On (a stock SQLite 3.5x build).

### Does changing cache_spill 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 cache_spill?

Leave it on unless a very large, long-running transaction should not take the file's EXCLUSIVE lock early, so other writers are not locked out until COMMIT.

Back to all [SQLite settings](https://sqlly.app/sql-configuration/sqlite), or check the [SQLite manual](https://www.sqlite.org/pragma.html) for every option.

## Related SQLite settings

- [`cache_size` Page cache size for this connection: positive numbers are pages, negative numbers are KiB.](https://sqlly.app/sql-configuration/sqlite/cache-size)
- [`journal_mode` How SQLite keeps transactions atomic: a rollback journal or a write-ahead log (WAL).](https://sqlly.app/sql-configuration/sqlite/journal-mode)
- [`locking_mode` Whether the connection releases file locks after each transaction (NORMAL) or keeps them (EXCLUSIVE).](https://sqlly.app/sql-configuration/sqlite/locking-mode)

## Related on SQLly

- [SQLite query performance troubleshooting Performance guide](https://sqlly.app/sql-performance/sqlite)
