1.Dd March 11, 2017 2.Dt SQLITE_CONFIG_SINGLETHREAD 3 3.Os 4.Sh NAME 5.Nm SQLITE_CONFIG_SINGLETHREAD , 6.Nm SQLITE_CONFIG_MULTITHREAD , 7.Nm SQLITE_CONFIG_SERIALIZED , 8.Nm SQLITE_CONFIG_MALLOC , 9.Nm SQLITE_CONFIG_GETMALLOC , 10.Nm SQLITE_CONFIG_SCRATCH , 11.Nm SQLITE_CONFIG_PAGECACHE , 12.Nm SQLITE_CONFIG_HEAP , 13.Nm SQLITE_CONFIG_MEMSTATUS , 14.Nm SQLITE_CONFIG_MUTEX , 15.Nm SQLITE_CONFIG_GETMUTEX , 16.Nm SQLITE_CONFIG_LOOKASIDE , 17.Nm SQLITE_CONFIG_PCACHE , 18.Nm SQLITE_CONFIG_GETPCACHE , 19.Nm SQLITE_CONFIG_LOG , 20.Nm SQLITE_CONFIG_URI , 21.Nm SQLITE_CONFIG_PCACHE2 , 22.Nm SQLITE_CONFIG_GETPCACHE2 , 23.Nm SQLITE_CONFIG_COVERING_INDEX_SCAN , 24.Nm SQLITE_CONFIG_SQLLOG , 25.Nm SQLITE_CONFIG_MMAP_SIZE , 26.Nm SQLITE_CONFIG_WIN32_HEAPSIZE , 27.Nm SQLITE_CONFIG_PCACHE_HDRSZ , 28.Nm SQLITE_CONFIG_PMASZ , 29.Nm SQLITE_CONFIG_STMTJRNL_SPILL 30.Nd Configuration Options 31.Sh SYNOPSIS 32.Fd #define SQLITE_CONFIG_SINGLETHREAD 33.Fd #define SQLITE_CONFIG_MULTITHREAD 34.Fd #define SQLITE_CONFIG_SERIALIZED 35.Fd #define SQLITE_CONFIG_MALLOC 36.Fd #define SQLITE_CONFIG_GETMALLOC 37.Fd #define SQLITE_CONFIG_SCRATCH 38.Fd #define SQLITE_CONFIG_PAGECACHE 39.Fd #define SQLITE_CONFIG_HEAP 40.Fd #define SQLITE_CONFIG_MEMSTATUS 41.Fd #define SQLITE_CONFIG_MUTEX 42.Fd #define SQLITE_CONFIG_GETMUTEX 43.Fd #define SQLITE_CONFIG_LOOKASIDE 44.Fd #define SQLITE_CONFIG_PCACHE 45.Fd #define SQLITE_CONFIG_GETPCACHE 46.Fd #define SQLITE_CONFIG_LOG 47.Fd #define SQLITE_CONFIG_URI 48.Fd #define SQLITE_CONFIG_PCACHE2 49.Fd #define SQLITE_CONFIG_GETPCACHE2 50.Fd #define SQLITE_CONFIG_COVERING_INDEX_SCAN 51.Fd #define SQLITE_CONFIG_SQLLOG 52.Fd #define SQLITE_CONFIG_MMAP_SIZE 53.Fd #define SQLITE_CONFIG_WIN32_HEAPSIZE 54.Fd #define SQLITE_CONFIG_PCACHE_HDRSZ 55.Fd #define SQLITE_CONFIG_PMASZ 56.Fd #define SQLITE_CONFIG_STMTJRNL_SPILL 57.Sh DESCRIPTION 58These constants are the available integer configuration options that 59can be passed as the first argument to the sqlite3_config() 60interface. 61.Pp 62New configuration options may be added in future releases of SQLite. 63Existing configuration options might be discontinued. 64Applications should check the return code from sqlite3_config() 65to make sure that the call worked. 66The sqlite3_config() interface will return a non-zero 67error code if a discontinued or unsupported configuration 68option is invoked. 69.Bl -tag -width Ds 70.It SQLITE_CONFIG_SINGLETHREAD 71There are no arguments to this option. 72This option sets the threading mode to Single-thread. 73In other words, it disables all mutexing and puts SQLite into a mode 74where it can only be used by a single thread. 75If SQLite is compiled with the SQLITE_THREADSAFE=0 76compile-time option then it is not possible to change the threading mode 77from its default value of Single-thread and so sqlite3_config() 78will return SQLITE_ERROR if called with the SQLITE_CONFIG_SINGLETHREAD 79configuration option. 80.It SQLITE_CONFIG_MULTITHREAD 81There are no arguments to this option. 82This option sets the threading mode to Multi-thread. 83In other words, it disables mutexing on database connection 84and prepared statement objects. 85The application is responsible for serializing access to database connections 86and prepared statements. 87But other mutexes are enabled so that SQLite will be safe to use in 88a multi-threaded environment as long as no two threads attempt to use 89the same database connection at the same time. 90If SQLite is compiled with the SQLITE_THREADSAFE=0 91compile-time option then it is not possible to set the Multi-thread 92threading mode and sqlite3_config() will 93return SQLITE_ERROR if called with the SQLITE_CONFIG_MULTITHREAD 94configuration option. 95.It SQLITE_CONFIG_SERIALIZED 96There are no arguments to this option. 97This option sets the threading mode to Serialized. 98In other words, this option enables all mutexes including the recursive 99mutexes on database connection and prepared statement 100objects. 101In this mode (which is the default when SQLite is compiled with SQLITE_THREADSAFE=1) 102the SQLite library will itself serialize access to database connections 103and prepared statements so that the application 104is free to use the same database connection or the 105same prepared statement in different threads at the 106same time. 107If SQLite is compiled with the SQLITE_THREADSAFE=0 108compile-time option then it is not possible to set the Serialized threading mode 109and sqlite3_config() will return SQLITE_ERROR 110if called with the SQLITE_CONFIG_SERIALIZED configuration option. 111.It SQLITE_CONFIG_MALLOC 112The SQLITE_CONFIG_MALLOC option takes a single argument which is a 113pointer to an instance of the sqlite3_mem_methods 114structure. 115The argument specifies alternative low-level memory allocation routines 116to be used in place of the memory allocation routines built into SQLite. 117SQLite makes its own private copy of the content of the sqlite3_mem_methods 118structure before the sqlite3_config() call returns. 119.It SQLITE_CONFIG_GETMALLOC 120The SQLITE_CONFIG_GETMALLOC option takes a single argument which is 121a pointer to an instance of the sqlite3_mem_methods 122structure. 123The sqlite3_mem_methods structure is filled with 124the currently defined memory allocation routines. 125This option can be used to overload the default memory allocation routines 126with a wrapper that simulations memory allocation failure or tracks 127memory usage, for example. 128.It SQLITE_CONFIG_MEMSTATUS 129The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int, 130interpreted as a boolean, which enables or disables the collection 131of memory allocation statistics. 132When memory allocation statistics are disabled, the following SQLite 133interfaces become non-operational: 134.Bl -bullet 135.It 136sqlite3_memory_used() 137.It 138sqlite3_memory_highwater() 139.It 140sqlite3_soft_heap_limit64() 141.It 142sqlite3_status64() 143.El 144.Pp 145Memory allocation statistics are enabled by default unless SQLite is 146compiled with SQLITE_DEFAULT_MEMSTATUS=0 in 147which case memory allocation statistics are disabled by default. 148.It SQLITE_CONFIG_SCRATCH 149The SQLITE_CONFIG_SCRATCH option specifies a static memory buffer that 150SQLite can use for scratch memory. 151There are three arguments to SQLITE_CONFIG_SCRATCH: A pointer an 8-byte 152aligned memory buffer from which the scratch allocations will be drawn, 153the size of each scratch allocation (sz), and the maximum number of 154scratch allocations (N). 155The first argument must be a pointer to an 8-byte aligned buffer of 156at least sz*N bytes of memory. 157SQLite will not use more than one scratch buffers per thread. 158SQLite will never request a scratch buffer that is more than 6 times 159the database page size. 160If SQLite needs needs additional scratch memory beyond what is provided 161by this configuration option, then sqlite3_malloc() 162will be used to obtain the memory needed.<p> When the application 163provides any amount of scratch memory using SQLITE_CONFIG_SCRATCH, 164SQLite avoids unnecessary large heap allocations. 165This can help prevent memory allocation failures 166due to heap fragmentation in low-memory embedded systems. 167.It SQLITE_CONFIG_PAGECACHE 168The SQLITE_CONFIG_PAGECACHE option specifies a memory pool that SQLite 169can use for the database page cache with the default page cache implementation. 170This configuration option is a no-op if an application-define page 171cache implementation is loaded using the SQLITE_CONFIG_PCACHE2. 172There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to 1738-byte aligned memory (pMem), the size of each page cache line (sz), 174and the number of cache lines (N). 175The sz argument should be the size of the largest database page (a 176power of two between 512 and 65536) plus some extra bytes for each 177page header. 178The number of extra bytes needed by the page header can be determined 179using SQLITE_CONFIG_PCACHE_HDRSZ. 180It is harmless, apart from the wasted memory, for the sz parameter 181to be larger than necessary. 182The pMem argument must be either a NULL pointer or a pointer to an 1838-byte aligned block of memory of at least sz*N bytes, otherwise subsequent 184behavior is undefined. 185When pMem is not NULL, SQLite will strive to use the memory provided 186to satisfy page cache needs, falling back to sqlite3_malloc() 187if a page cache line is larger than sz bytes or if all of the pMem 188buffer is exhausted. 189If pMem is NULL and N is non-zero, then each database connection does 190an initial bulk allocation for page cache memory from sqlite3_malloc() 191sufficient for N cache lines if N is positive or of -1024*N bytes if 192N is negative, . 193If additional page cache memory is needed beyond what is provided by 194the initial allocation, then SQLite goes to sqlite3_malloc() 195separately for each additional cache line. 196.It SQLITE_CONFIG_HEAP 197The SQLITE_CONFIG_HEAP option specifies a static memory buffer that 198SQLite will use for all of its dynamic memory allocation needs beyond 199those provided for by SQLITE_CONFIG_SCRATCH and 200SQLITE_CONFIG_PAGECACHE. 201The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled 202with either SQLITE_ENABLE_MEMSYS3 or SQLITE_ENABLE_MEMSYS5 203and returns SQLITE_ERROR if invoked otherwise. 204There are three arguments to SQLITE_CONFIG_HEAP: An 8-byte aligned 205pointer to the memory, the number of bytes in the memory buffer, and 206the minimum allocation size. 207If the first pointer (the memory pointer) is NULL, then SQLite reverts 208to using its default memory allocator (the system malloc() implementation), 209undoing any prior invocation of SQLITE_CONFIG_MALLOC. 210If the memory pointer is not NULL then the alternative memory allocator 211is engaged to handle all of SQLites memory allocation needs. 212The first pointer (the memory pointer) must be aligned to an 8-byte 213boundary or subsequent behavior of SQLite will be undefined. 214The minimum allocation size is capped at 2**12. 215Reasonable values for the minimum allocation size are 2**5 through 2162**8. 217.It SQLITE_CONFIG_MUTEX 218The SQLITE_CONFIG_MUTEX option takes a single argument which is a pointer 219to an instance of the sqlite3_mutex_methods structure. 220The argument specifies alternative low-level mutex routines to be used 221in place the mutex routines built into SQLite. 222SQLite makes a copy of the content of the sqlite3_mutex_methods 223structure before the call to sqlite3_config() returns. 224If SQLite is compiled with the SQLITE_THREADSAFE=0 225compile-time option then the entire mutexing subsystem is omitted from 226the build and hence calls to sqlite3_config() with 227the SQLITE_CONFIG_MUTEX configuration option will return SQLITE_ERROR. 228.It SQLITE_CONFIG_GETMUTEX 229The SQLITE_CONFIG_GETMUTEX option takes a single argument which is 230a pointer to an instance of the sqlite3_mutex_methods 231structure. 232The sqlite3_mutex_methods structure is filled 233with the currently defined mutex routines. 234This option can be used to overload the default mutex allocation routines 235with a wrapper used to track mutex usage for performance profiling 236or testing, for example. 237If SQLite is compiled with the SQLITE_THREADSAFE=0 238compile-time option then the entire mutexing subsystem is omitted from 239the build and hence calls to sqlite3_config() with 240the SQLITE_CONFIG_GETMUTEX configuration option will return SQLITE_ERROR. 241.It SQLITE_CONFIG_LOOKASIDE 242The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine 243the default size of lookaside memory on each database connection. 244The first argument is the size of each lookaside buffer slot and the 245second is the number of slots allocated to each database connection. 246SQLITE_CONFIG_LOOKASIDE sets the <i>default</i> lookaside size. 247The SQLITE_DBCONFIG_LOOKASIDE option to sqlite3_db_config() 248can be used to change the lookaside configuration on individual connections. 249.It SQLITE_CONFIG_PCACHE2 250The SQLITE_CONFIG_PCACHE2 option takes a single argument which is a 251pointer to an sqlite3_pcache_methods2 object. 252This object specifies the interface to a custom page cache implementation. 253SQLite makes a copy of the sqlite3_pcache_methods2 254object. 255.It SQLITE_CONFIG_GETPCACHE2 256The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which is 257a pointer to an sqlite3_pcache_methods2 object. 258SQLite copies of the current page cache implementation into that object. 259.It SQLITE_CONFIG_LOG 260The SQLITE_CONFIG_LOG option is used to configure the SQLite global 261error log. 262( The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a 263function with a call signature of void(*)(void*,int,const char*), and 264a pointer to void. 265If the function pointer is not NULL, it is invoked by sqlite3_log() 266to process each logging event. 267If the function pointer is NULL, the sqlite3_log() interface 268becomes a no-op. 269The void pointer that is the second argument to SQLITE_CONFIG_LOG is 270passed through as the first parameter to the application-defined logger 271function whenever that function is invoked. 272The second parameter to the logger function is a copy of the first 273parameter to the corresponding sqlite3_log() call and 274is intended to be a result code or an extended result code. 275The third parameter passed to the logger is log message after formatting 276via sqlite3_snprintf(). 277The SQLite logging interface is not reentrant; the logger function 278supplied by the application must not invoke any SQLite interface. 279In a multi-threaded application, the application-defined logger function 280must be threadsafe. 281.It SQLITE_CONFIG_URI The SQLITE_CONFIG_URI option takes a single argument 282of type int. 283If non-zero, then URI handling is globally enabled. 284If the parameter is zero, then URI handling is globally disabled. 285If URI handling is globally enabled, all filenames passed to sqlite3_open(), 286sqlite3_open_v2(), sqlite3_open16() 287or specified as part of ATTACH commands are interpreted as URIs, 288regardless of whether or not the SQLITE_OPEN_URI flag 289is set when the database connection is opened. 290If it is globally disabled, filenames are only interpreted as URIs 291if the SQLITE_OPEN_URI flag is set when the database connection is 292opened. 293By default, URI handling is globally disabled. 294The default value may be changed by compiling with the SQLITE_USE_URI 295symbol defined. 296.It SQLITE_CONFIG_COVERING_INDEX_SCAN The SQLITE_CONFIG_COVERING_INDEX_SCAN 297option takes a single integer argument which is interpreted as a boolean 298in order to enable or disable the use of covering indices for full 299table scans in the query optimizer. 300The default setting is determined by the SQLITE_ALLOW_COVERING_INDEX_SCAN 301compile-time option, or is "on" if that compile-time option is omitted. 302The ability to disable the use of covering indices for full table scans 303is because some incorrectly coded legacy applications might malfunction 304when the optimization is enabled. 305Providing the ability to disable the optimization allows the older, 306buggy application code to work without change even with newer versions 307of SQLite. 308.It SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE These options are 309obsolete and should not be used by new code. 310They are retained for backwards compatibility but are now no-ops. 311.It SQLITE_CONFIG_SQLLOG This option is only available if sqlite is compiled 312with the SQLITE_ENABLE_SQLLOG pre-processor macro 313defined. 314The first argument should be a pointer to a function of type void(*)(void*,sqlite3*,const 315char*, int). 316The second should be of type (void*). 317The callback is invoked by the library in three separate circumstances, 318identified by the value passed as the fourth parameter. 319If the fourth parameter is 0, then the database connection passed as 320the second argument has just been opened. 321The third argument points to a buffer containing the name of the main 322database file. 323If the fourth parameter is 1, then the SQL statement that the third 324parameter points to has just been executed. 325Or, if the fourth parameter is 2, then the connection being passed 326as the second parameter is being closed. 327The third parameter is passed NULL In this case. 328An example of using this configuration option can be seen in the "test_sqllog.c" 329source file in the canonical SQLite source tree. 330.It SQLITE_CONFIG_MMAP_SIZE SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer 331(sqlite3_int64) values that are the default mmap size limit (the default 332setting for PRAGMA mmap_size) and the maximum allowed 333mmap size limit. 334The default setting can be overridden by each database connection using 335either the PRAGMA mmap_size command, or by using the 336SQLITE_FCNTL_MMAP_SIZE file control. 337The maximum allowed mmap size will be silently truncated if necessary 338so that it does not exceed the compile-time maximum mmap size set by 339the SQLITE_MAX_MMAP_SIZE compile-time option. 340If either argument to this option is negative, then that argument is 341changed to its compile-time default. 342.It SQLITE_CONFIG_WIN32_HEAPSIZE The SQLITE_CONFIG_WIN32_HEAPSIZE option 343is only available if SQLite is compiled for Windows with the SQLITE_WIN32_MALLOC 344pre-processor macro defined. 345SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value 346that specifies the maximum size of the created heap. 347.It SQLITE_CONFIG_PCACHE_HDRSZ The SQLITE_CONFIG_PCACHE_HDRSZ option takes 348a single parameter which is a pointer to an integer and writes into 349that integer the number of extra bytes per page required for each page 350in SQLITE_CONFIG_PAGECACHE. 351The amount of extra space required can change depending on the compiler, 352target platform, and SQLite version. 353.It SQLITE_CONFIG_PMASZ The SQLITE_CONFIG_PMASZ option takes a single 354parameter which is an unsigned integer and sets the "Minimum PMA Size" 355for the multithreaded sorter to that integer. 356The default minimum PMA Size is set by the SQLITE_SORTER_PMASZ 357compile-time option. 358New threads are launched to help with sort operations when multithreaded 359sorting is enabled (using the PRAGMA threads command) 360and the amount of content to be sorted exceeds the page size times 361the minimum of the PRAGMA cache_size setting and this 362value. 363.It SQLITE_CONFIG_STMTJRNL_SPILL The SQLITE_CONFIG_STMTJRNL_SPILL option 364takes a single parameter which becomes the statement journal 365spill-to-disk threshold. 366Statement journals are held in memory until their 367size (in bytes) exceeds this threshold, at which point they are written 368to disk. 369Or if the threshold is -1, statement journals are always held exclusively 370in memory. 371Since many statement journals never become large, setting the spill 372threshold to a value such as 64KiB can greatly reduce the amount of 373I/O required to support statement rollback. 374The default value for this setting is controlled by the SQLITE_STMTJRNL_SPILL 375compile-time option. 376.El 377.Pp 378.Sh SEE ALSO 379.Xr sqlite3 3 , 380.Xr sqlite3_stmt 3 , 381.Xr sqlite3_config 3 , 382.Xr sqlite3_db_config 3 , 383.Xr sqlite3_log 3 , 384.Xr sqlite3_malloc 3 , 385.Xr sqlite3_mem_methods 3 , 386.Xr sqlite3_memory_used 3 , 387.Xr sqlite3_mutex_methods 3 , 388.Xr sqlite3_open 3 , 389.Xr sqlite3_pcache_methods2 3 , 390.Xr sqlite3_mprintf 3 , 391.Xr sqlite3_soft_heap_limit64 3 , 392.Xr sqlite3_status 3 , 393.Xr SQLITE_CONFIG_SINGLETHREAD 3 , 394.Xr SQLITE_DBCONFIG_MAINDBNAME 3 , 395.Xr SQLITE_OK 3 , 396.Xr SQLITE_FCNTL_LOCKSTATE 3 , 397.Xr SQLITE_OPEN_READONLY 3 398