@polycode-projects/the-mechanical-code-talker 2.2.0 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/bin/tmct.mjs +4 -5
  2. package/corpus/LICENSES.json +19 -4
  3. package/corpus/README.md +48 -0
  4. package/corpus/generated/README.md +24 -9
  5. package/corpus/generated/ace-surface-variants.jsonl +4 -1
  6. package/corpus/generated/manifest.json +4 -4
  7. package/corpus/prose/manifest.json +512 -0
  8. package/corpus/prose/sqlite/LICENSE-NOTICE +53 -0
  9. package/corpus/prose/sqlite/arch.txt +213 -0
  10. package/corpus/prose/sqlite/atomiccommit.txt +1117 -0
  11. package/corpus/prose/sqlite/faq.txt +473 -0
  12. package/corpus/prose/sqlite/fileformat.txt +1589 -0
  13. package/corpus/prose/sqlite/lang_createtable.txt +1339 -0
  14. package/corpus/prose/sqlite/lang_insert.txt +580 -0
  15. package/corpus/prose/sqlite/lang_select.txt +3293 -0
  16. package/corpus/prose/sqlite/optoverview.txt +908 -0
  17. package/corpus/prose/sqlite/queryplanner.txt +447 -0
  18. package/corpus/prose/sqlite/transactional.txt +41 -0
  19. package/corpus/prose/sqlite/wal.txt +567 -0
  20. package/corpus/prose/sqlite/whentouse.txt +300 -0
  21. package/corpus/prose/wikipedia/Apple.txt +4 -0
  22. package/corpus/prose/wikipedia/Attempto_Controlled_English.txt +169 -0
  23. package/corpus/prose/wikipedia/Automated_planning_and_scheduling.txt +67 -0
  24. package/corpus/prose/wikipedia/Bee.txt +7 -0
  25. package/corpus/prose/wikipedia/Bird.txt +8 -0
  26. package/corpus/prose/wikipedia/Bone.txt +4 -0
  27. package/corpus/prose/wikipedia/Book.txt +7 -0
  28. package/corpus/prose/wikipedia/Bread.txt +6 -0
  29. package/corpus/prose/wikipedia/Butterfly.txt +6 -0
  30. package/corpus/prose/wikipedia/Car.txt +1 -0
  31. package/corpus/prose/wikipedia/Cat.txt +1 -0
  32. package/corpus/prose/wikipedia/Child.txt +3 -0
  33. package/corpus/prose/wikipedia/City.txt +2 -0
  34. package/corpus/prose/wikipedia/Clock.txt +2 -0
  35. package/corpus/prose/wikipedia/Cooking.txt +1 -0
  36. package/corpus/prose/wikipedia/Description_logic.txt +660 -0
  37. package/corpus/prose/wikipedia/Doctor.txt +6 -0
  38. package/corpus/prose/wikipedia/Dog.txt +4 -0
  39. package/corpus/prose/wikipedia/Eagle.txt +4 -0
  40. package/corpus/prose/wikipedia/Emotion.txt +9 -0
  41. package/corpus/prose/wikipedia/Eye.txt +5 -0
  42. package/corpus/prose/wikipedia/Family.txt +3 -0
  43. package/corpus/prose/wikipedia/Farm.txt +4 -0
  44. package/corpus/prose/wikipedia/Fear.txt +4 -0
  45. package/corpus/prose/wikipedia/First-order_logic.txt +1518 -0
  46. package/corpus/prose/wikipedia/Fish.txt +10 -0
  47. package/corpus/prose/wikipedia/Flower.txt +3 -0
  48. package/corpus/prose/wikipedia/Food.txt +10 -0
  49. package/corpus/prose/wikipedia/Grass.txt +9 -0
  50. package/corpus/prose/wikipedia/Hand.txt +2 -0
  51. package/corpus/prose/wikipedia/Happiness.txt +3 -0
  52. package/corpus/prose/wikipedia/Heart.txt +4 -0
  53. package/corpus/prose/wikipedia/Horse.txt +4 -0
  54. package/corpus/prose/wikipedia/House.txt +6 -0
  55. package/corpus/prose/wikipedia/Human.txt +4 -0
  56. package/corpus/prose/wikipedia/Insect.txt +6 -0
  57. package/corpus/prose/wikipedia/Interactive_fiction.txt +112 -0
  58. package/corpus/prose/wikipedia/Knowledge.txt +5 -0
  59. package/corpus/prose/wikipedia/Knowledge_representation_and_reasoning.txt +87 -0
  60. package/corpus/prose/wikipedia/LICENSE-NOTICE +94 -0
  61. package/corpus/prose/wikipedia/Language.txt +10 -0
  62. package/corpus/prose/wikipedia/Learning.txt +4 -0
  63. package/corpus/prose/wikipedia/Mammal.txt +3 -0
  64. package/corpus/prose/wikipedia/Memory.txt +5 -0
  65. package/corpus/prose/wikipedia/Milk.txt +1 -0
  66. package/corpus/prose/wikipedia/Mountain.txt +1 -0
  67. package/corpus/prose/wikipedia/Natural_language_processing.txt +211 -0
  68. package/corpus/prose/wikipedia/Ostrich.txt +2 -0
  69. package/corpus/prose/wikipedia/Owl.txt +2 -0
  70. package/corpus/prose/wikipedia/Penguin.txt +2 -0
  71. package/corpus/prose/wikipedia/Plant.txt +5 -0
  72. package/corpus/prose/wikipedia/Rain.txt +1 -0
  73. package/corpus/prose/wikipedia/Resource_Description_Framework.txt +184 -0
  74. package/corpus/prose/wikipedia/River.txt +1 -0
  75. package/corpus/prose/wikipedia/School.txt +8 -0
  76. package/corpus/prose/wikipedia/Sea.txt +1 -0
  77. package/corpus/prose/wikipedia/Semantic_Web.txt +114 -0
  78. package/corpus/prose/wikipedia/Semantic_reasoner.txt +29 -0
  79. package/corpus/prose/wikipedia/Snow.txt +5 -0
  80. package/corpus/prose/wikipedia/Sun.txt +5 -0
  81. package/corpus/prose/wikipedia/Teacher.txt +4 -0
  82. package/corpus/prose/wikipedia/Team.txt +3 -0
  83. package/corpus/prose/wikipedia/Text-based_game.txt +17 -0
  84. package/corpus/prose/wikipedia/Tool.txt +4 -0
  85. package/corpus/prose/wikipedia/Tree.txt +7 -0
  86. package/corpus/prose/wikipedia/Weather.txt +4 -0
  87. package/corpus/prose/wikipedia/Web_Ontology_Language.txt +133 -0
  88. package/corpus/prose/wikipedia/Wind.txt +8 -0
  89. package/corpus/prose/wikipedia/Writing.txt +5 -0
  90. package/corpus/wordnet/generate.mjs +6 -7
  91. package/package.json +31 -2
  92. package/src/adapters/corpus/conceptnet.mjs +1 -1
  93. package/src/adapters/graph-build.mjs +3 -3
  94. package/src/adapters/memory/blocks.mjs +2 -2
  95. package/src/adapters/memory/core.mjs +5 -5
  96. package/src/adapters/providers/bootstrap.mjs +1 -1
  97. package/src/adapters/providers/fixture.mjs +1 -1
  98. package/src/adapters/wink-model.mjs +1 -1
  99. package/src/adapters/wordnet-source.mjs +70 -0
  100. package/src/domain/answer-variants.json +1 -1
  101. package/src/domain/ask-vocab.mjs +2 -2
  102. package/src/domain/ask.mjs +4 -4
  103. package/src/domain/codegraph.mjs +3 -3
  104. package/src/domain/corpus-matrix.mjs +87 -0
  105. package/src/domain/grammar/ace.mjs +11 -11
  106. package/src/domain/grammar/lexicon.mjs +3 -3
  107. package/src/domain/inflect.mjs +67 -0
  108. package/src/domain/interpret/fuzzy.mjs +1 -1
  109. package/src/domain/interpret/merge.mjs +1 -1
  110. package/src/domain/interpret/normalize.mjs +1 -1
  111. package/src/domain/licences.mjs +68 -0
  112. package/src/domain/memory/capability.mjs +1 -1
  113. package/src/domain/memory/trust.mjs +2 -2
  114. package/src/domain/persona/codegen.mjs +123 -0
  115. package/src/domain/persona/examples.mjs +26 -0
  116. package/src/domain/persona/tiers.mjs +270 -0
  117. package/src/domain/publish-gate.mjs +41 -0
  118. package/src/domain/router/call-validator.mjs +1 -1
  119. package/src/domain/router/drive.mjs +3 -4
  120. package/src/domain/router/registry.mjs +12 -13
  121. package/src/domain/router/resolver.mjs +18 -5
  122. package/src/domain/router/results.mjs +3 -3
  123. package/src/domain/router/taught.mjs +4 -3
  124. package/src/domain/schemaorg/turtle.mjs +25 -0
  125. package/src/domain/semcor/parse.mjs +87 -0
  126. package/src/domain/syllogise.mjs +6 -6
  127. package/src/domain/version-stamp.mjs +36 -0
  128. package/src/domain/wordnet/yaml.mjs +133 -0
  129. package/src/services/chat-session.mjs +2 -2
  130. package/src/services/chat.mjs +2 -2
  131. package/src/services/cli-args.mjs +4 -4
  132. package/src/services/finish.mjs +1 -1
  133. package/src/services/ledger-viz.mjs +2 -3
  134. package/src/services/sessions.mjs +4 -4
  135. package/src/services/viz-theme.mjs +3 -4
  136. package/src/surfaces/web/memory-ask-browser.bundle.js +1 -18
  137. package/src/domain/router/guardrail.mjs +0 -116
@@ -0,0 +1,567 @@
1
+ Write-Ahead Logging
2
+ Small. Fast. Reliable.
3
+ Choose any three.
4
+ Home
5
+ Menu
6
+ About
7
+ Documentation
8
+ Download
9
+ License
10
+ Support
11
+ Purchase
12
+ Search
13
+ About
14
+ Documentation
15
+ Download
16
+ Support
17
+ Purchase
18
+ Search Documentation
19
+ Search Changelog
20
+ Write-Ahead Logging
21
+ Table Of Contents
22
+ 1. Overview
23
+ 2. How WAL Works
24
+ 2.1. Checkpointing
25
+ 2.2. Concurrency
26
+ 2.3. Performance Considerations
27
+ 3. Activating And Configuring WAL Mode
28
+ 3.1. Automatic Checkpoint
29
+ 3.2. Application-Initiated Checkpoints
30
+ 3.3. Persistence of WAL mode
31
+ 4. The WAL File
32
+ 5. Read-Only Databases
33
+ 6. Avoiding Excessively Large WAL Files
34
+ 7. Implementation Of Shared-Memory For The WAL-Index
35
+ 8. Use of WAL Without Shared-Memory
36
+ 9. Sometimes Queries Return SQLITE_BUSY In WAL Mode
37
+ 10. Backwards Compatibility
38
+ 11. The WAL-Reset Bug
39
+ 11.1. Bug Details
40
+ 11.2. Low Probability Of Occurrence
41
+ 1. Overview
42
+ The default method by which SQLite implements
43
+ atomic commit and rollback is a rollback journal .
44
+ Beginning with version 3.7.0 (2010-07-21), a new "Write-Ahead Log" option
45
+ (hereafter referred to as "WAL") is available.
46
+ There are advantages and disadvantages to using WAL instead of
47
+ a rollback journal. Advantages include:
48
+ WAL is significantly faster in most scenarios.
49
+ WAL provides more concurrency as readers do not block writers and
50
+ a writer does not block readers. Reading and writing can proceed
51
+ concurrently.
52
+ Disk I/O operations tends to be more sequential using WAL.
53
+ WAL uses many fewer fsync() operations and is thus less vulnerable to
54
+ problems on systems where the fsync() system call is broken.
55
+ But there are also disadvantages:
56
+ All processes using a database must be on the same host computer;
57
+ WAL does not work over a network filesystem. This is because WAL requires
58
+ all processes to share a small amount of memory and processes on
59
+ separate host machines obviously cannot share memory with each other.
60
+ Transactions that involve changes against multiple ATTACHed
61
+ databases are atomic for each individual database, but are not
62
+ atomic across all databases as a set.
63
+ It is not possible to change the page_size after entering WAL
64
+ mode, either on an empty database or by using VACUUM or by restoring
65
+ from a backup using the backup API . You must be in a rollback journal
66
+ mode to change the page size.
67
+ It is not possible to open read-only WAL databases .
68
+ The opening process must have write privileges for " -shm "
69
+ wal-index shared memory file associated with the database, if that
70
+ file exists, or else write access on the directory containing
71
+ the database file if the " -shm " file does not exist.
72
+ Beginning with version 3.22.0 (2018-01-22), a read-only
73
+ WAL-mode database file can be opened if
74
+ the -shm and -wal files
75
+ already exist or those files can be created or the
76
+ database is immutable .
77
+ WAL might be very slightly slower (perhaps 1% or 2% slower)
78
+ than the traditional rollback-journal approach
79
+ in applications that do mostly reads and seldom write.
80
+ There is an additional quasi-persistent " -wal " file and
81
+ " -shm " shared memory file associated with each
82
+ database, which can make SQLite less appealing for use as an
83
+ application file-format .
84
+ There is the extra operation of checkpointing which, though automatic
85
+ by default, is still something that application developers need to
86
+ be mindful of.
87
+ WAL works best with smaller transactions. WAL does
88
+ not work well for very large transactions. For transactions larger than
89
+ about 100 megabytes, traditional rollback journal modes will likely
90
+ be faster. For transactions in excess of a gigabyte, WAL mode may
91
+ fail with an I/O or disk-full error.
92
+ It is recommended that one of the rollback journal modes be used for
93
+ transactions larger than a few dozen megabytes.
94
+ Beginning with version 3.11.0 (2016-02-15),
95
+ WAL mode works as efficiently with
96
+ large transactions as does rollback mode.
97
+ 2. How WAL Works
98
+ The traditional rollback journal works by writing a copy of the
99
+ original unchanged database content into a separate rollback journal file
100
+ and then writing changes directly into the database file. In the
101
+ event of a crash or ROLLBACK , the original content contained in the
102
+ rollback journal is played back into the database file to
103
+ revert the database file to its original state. The COMMIT occurs
104
+ when the rollback journal is deleted.
105
+ The WAL approach inverts this. The original content is preserved
106
+ in the database file and the changes are appended into a separate
107
+ WAL file. A COMMIT occurs when a special record indicating a commit
108
+ is appended to the WAL. Thus a COMMIT can happen without ever writing
109
+ to the original database, which allows readers to continue operating
110
+ from the original unaltered database while changes are simultaneously being
111
+ committed into the WAL. Multiple transactions can be appended to the
112
+ end of a single WAL file.
113
+ 2.1. Checkpointing
114
+ Of course, one wants to eventually transfer all the transactions that
115
+ are appended in the WAL file back into the original database. Moving
116
+ the WAL file transactions back into the database is called a
117
+ " checkpoint ".
118
+ Another way to think about the difference between rollback and
119
+ write-ahead log is that in the rollback-journal
120
+ approach, there are two primitive operations, reading and writing,
121
+ whereas with a write-ahead log
122
+ there are now three primitive operations: reading, writing, and
123
+ checkpointing.
124
+ By default, SQLite does a checkpoint automatically when the WAL file
125
+ reaches a threshold size of 1000 pages. (The
126
+ SQLITE_DEFAULT_WAL_AUTOCHECKPOINT compile-time option can be used to
127
+ specify a different default.) Applications using WAL do
128
+ not have to do anything in order for these checkpoints to occur.
129
+ But if they want to, applications can adjust the automatic checkpoint
130
+ threshold. Or they can turn off the automatic checkpoints and run
131
+ checkpoints during idle moments or in a separate thread or process.
132
+ 2.2. Concurrency
133
+ When a read operation begins on a WAL-mode database, it first
134
+ remembers the location of the last valid commit record in the WAL.
135
+ Call this point the "end mark". Because the WAL can be growing and
136
+ adding new commit records while various readers connect to the database,
137
+ each reader can potentially have its own end mark. But for any
138
+ particular reader, the end mark is unchanged for the duration of the
139
+ transaction, thus ensuring that a single read transaction only sees
140
+ the database content as it existed at a single point in time.
141
+ When a reader needs a page of content, it first checks the WAL to
142
+ see if that page appears there, and if so it pulls in the last copy
143
+ of the page that occurs in the WAL prior to the reader's end mark.
144
+ If no copy of the page exists in the WAL prior to the reader's end mark,
145
+ then the page is read from the original database file. Readers can
146
+ exist in separate processes, so to avoid forcing every reader to scan
147
+ the entire WAL looking for pages (the WAL file can grow to
148
+ multiple megabytes, depending on how often checkpoints are run), a
149
+ data structure called the "wal-index" is maintained in shared memory
150
+ which helps readers locate pages in the WAL quickly and with a minimum
151
+ of I/O. The wal-index greatly improves the performance of readers,
152
+ but the use of shared memory means that all readers must exist on the
153
+ same machine. This is why the write-ahead log implementation will not
154
+ work on a network filesystem.
155
+ Writers merely append new content to the end of the WAL file.
156
+ Because writers do nothing that would interfere with the actions of
157
+ readers, writers and readers can run at the same time. However,
158
+ since there is only one WAL file, there can only be one writer at
159
+ a time.
160
+ A checkpoint operation takes content from the WAL file
161
+ and transfers it back into the original database file.
162
+ A checkpoint can run concurrently with readers, however the checkpoint
163
+ must stop when it reaches a page in the WAL that is past the end mark
164
+ of any current reader. The checkpoint has to stop at that point because
165
+ otherwise it might overwrite part of the database file that the reader
166
+ is actively using. The checkpoint remembers (in the wal-index) how far
167
+ it got and will resume transferring content from the WAL to the database
168
+ from where it left off on the next invocation.
169
+ Thus a long-running read transaction can prevent a checkpointer from
170
+ making progress. But presumably every read transaction will eventually
171
+ end and the checkpointer will be able to continue.
172
+ Whenever a write operation occurs, the writer checks how much progress
173
+ the checkpointer has made, and if the entire WAL has been transferred into
174
+ the database and synced and if no readers are making use of the WAL, then
175
+ the writer will rewind the WAL back to the beginning and start putting new
176
+ transactions at the beginning of the WAL. This mechanism prevents a WAL
177
+ file from growing without bound.
178
+ 2.3. Performance Considerations
179
+ Write transactions are very fast since they only involve writing
180
+ the content once (versus twice for rollback-journal transactions)
181
+ and because the writes are all sequential. Further, syncing the
182
+ content to the disk is not required, as long as the application is
183
+ willing to sacrifice durability following a power loss or hard reboot.
184
+ (Writers sync the WAL on every transaction commit if
185
+ PRAGMA synchronous is set to FULL but omit this sync if
186
+ PRAGMA synchronous is set to NORMAL.)
187
+ On the other hand, read performance deteriorates as the WAL file
188
+ grows in size since each reader must check the WAL file for the content
189
+ and the time needed to check the WAL file is proportional
190
+ to the size of the WAL file. The wal-index helps find content
191
+ in the WAL file much faster, but performance still falls off with
192
+ increasing WAL file size. Hence, to maintain good read performance
193
+ it is important to keep the WAL file size down by
194
+ running checkpoints at regular intervals.
195
+ Checkpointing does require sync operations in order to avoid
196
+ the possibility of database corruption following a power loss
197
+ or hard reboot. The WAL must be synced to persistent storage
198
+ prior to moving content from the WAL into the database and the
199
+ database file must be synced prior to resetting the WAL.
200
+ Checkpoint also requires more seeking.
201
+ The checkpointer makes an effort to
202
+ do as many sequential page writes to the database as it can (the pages
203
+ are transferred from WAL to database in ascending order) but even
204
+ then there will typically be many seek operations interspersed among
205
+ the page writes. These factors combine to make checkpoints slower than
206
+ write transactions.
207
+ The default strategy is to allow successive write transactions to
208
+ grow the WAL until the WAL becomes about 1000 pages in size, then to
209
+ run a checkpoint operation for each subsequent COMMIT until the WAL
210
+ is reset to be smaller than 1000 pages. By default, the checkpoint will be
211
+ run automatically by the same thread that does the COMMIT that pushes
212
+ the WAL over its size limit. This has the effect of causing most
213
+ COMMIT operations to be very fast but an occasional COMMIT (those that trigger
214
+ a checkpoint) to be much slower. If that effect is undesirable, then
215
+ the application can disable automatic checkpointing and run the
216
+ periodic checkpoints in a separate thread, or separate process.
217
+ (Links to commands and interfaces to accomplish this are
218
+ shown below .)
219
+ Note that with PRAGMA synchronous set to NORMAL, the checkpoint
220
+ is the only operation to issue an I/O barrier or sync operation
221
+ (fsync() on unix or FlushFileBuffers() on windows). If an application
222
+ therefore runs checkpoint in a separate thread or process, the main
223
+ thread or process that is doing database queries and updates will never
224
+ block on a sync operation. This helps to prevent "latch-up" in applications
225
+ running on a busy disk drive. The downside to
226
+ this configuration is that transactions are no longer durable and
227
+ might rollback following a power failure or hard reset.
228
+ Notice too that there is a tradeoff between average read performance
229
+ and average write performance. To maximize the read performance,
230
+ one wants to keep the WAL as small as possible and hence run checkpoints
231
+ frequently, perhaps as often as every COMMIT. To maximize
232
+ write performance, one wants to amortize the cost of each checkpoint
233
+ over as many writes as possible, meaning that one wants to run checkpoints
234
+ infrequently and let the WAL grow as large as possible before each
235
+ checkpoint. The decision of how often to run checkpoints may therefore
236
+ vary from one application to another depending on the relative read
237
+ and write performance requirements of the application.
238
+ The default strategy is to run a checkpoint once the WAL
239
+ reaches 1000 pages and this strategy seems to work well in test applications on
240
+ workstations, but other strategies might work better on different
241
+ platforms or for different workloads.
242
+ 3. Activating And Configuring WAL Mode
243
+ An SQLite database connection defaults to
244
+ journal_mode=DELETE . To convert to WAL mode, use the
245
+ following pragma:
246
+ The journal_mode pragma returns a string which is the new journal mode.
247
+ On success, the pragma will return the string " wal ". If
248
+ the conversion to WAL could not be completed (for example, if the VFS
249
+ does not support the necessary shared-memory primitives) then the
250
+ journaling mode will be unchanged and the string returned from the
251
+ primitive will be the prior journaling mode (for example " delete ").
252
+ 3.1. Automatic Checkpoint
253
+ By default, SQLite will automatically checkpoint whenever a COMMIT
254
+ occurs that causes the WAL file to be 1000 pages or more in size, or when the
255
+ last database connection on a database file closes. The default
256
+ configuration is intended to work well for most applications.
257
+ But programs that want more control can force a checkpoint
258
+ using the wal_checkpoint pragma or by calling the
259
+ sqlite3_wal_checkpoint() C interface. The automatic checkpoint
260
+ threshold can be changed or automatic checkpointing can be completely
261
+ disabled using the wal_autocheckpoint pragma or by calling the
262
+ sqlite3_wal_autocheckpoint() C interface. A program can also
263
+ use sqlite3_wal_hook() to register a callback to be invoked whenever
264
+ any transaction commits to the WAL. This callback can then invoke
265
+ sqlite3_wal_checkpoint() or sqlite3_wal_checkpoint_v2() based on whatever
266
+ criteria it thinks is appropriate. (The automatic checkpoint mechanism
267
+ is implemented as a simple wrapper around sqlite3_wal_hook() .)
268
+ 3.2. Application-Initiated Checkpoints
269
+ An application can initiate a checkpoint using any writable database
270
+ connection on the database simply by invoking
271
+ sqlite3_wal_checkpoint() or sqlite3_wal_checkpoint_v2() .
272
+ There are three subtypes of checkpoints that vary in their aggressiveness:
273
+ PASSIVE, FULL, and RESTART. The default checkpoint style is PASSIVE, which
274
+ does as much work as it can without interfering with other database
275
+ connections, and which might not run to completion if there are
276
+ concurrent readers or writers.
277
+ All checkpoints initiated by sqlite3_wal_checkpoint() and
278
+ by the automatic checkpoint mechanism are PASSIVE. FULL and RESTART
279
+ checkpoints try harder to run the checkpoint to completion and can only
280
+ be initiated by a call to sqlite3_wal_checkpoint_v2() . See the
281
+ sqlite3_wal_checkpoint_v2() documentation for additional information
282
+ on FULL and RESET checkpoints.
283
+ 3.3. Persistence of WAL mode
284
+ Unlike the other journaling modes,
285
+ PRAGMA journal_mode=WAL is
286
+ persistent. If a process sets WAL mode, then closes and reopens the
287
+ database, the database will come back in WAL mode. In contrast, if
288
+ a process sets (for example) PRAGMA journal_mode=TRUNCATE and then closes and
289
+ reopens the database will come back up in the default rollback mode of
290
+ DELETE rather than the previous TRUNCATE setting.
291
+ The persistence of WAL mode means that applications can be converted
292
+ to using SQLite in WAL mode without making any changes to the application
293
+ itself. One has merely to run " PRAGMA journal_mode=WAL; " on the
294
+ database file(s) using the command-line shell or other utility, then
295
+ restart the application.
296
+ The WAL journal mode will be set on all
297
+ connections to the same database file if it is set on any one connection.
298
+ 4. The WAL File
299
+ While a database connection is open on a WAL-mode database, SQLite
300
+ maintains an extra journal file called a "Write Ahead Log" or "WAL File".
301
+ The name of this file on disk is usually the name of the database file
302
+ with an extra " -wal " suffix, though different naming rules may
303
+ apply if SQLite is compiled with SQLITE_ENABLE_8_3_NAMES .
304
+ The WAL file exists for as long as any database connection has the
305
+ database open. Usually, the WAL file is deleted automatically when the
306
+ last connection to the database closes. However, if the last process to
307
+ have the database open exits without cleanly
308
+ shutting down the database connection, or if the
309
+ SQLITE_FCNTL_PERSIST_WAL file control is used, then the WAL file
310
+ might be retained on disk after all connections to the database have
311
+ been closed. The WAL file is part of the persistent state of the
312
+ database and should be kept with the database if the database is copied
313
+ or moved. If a database file is separated from its WAL file, then
314
+ transactions that were previously committed to the database might be lost,
315
+ or the database file might become corrupted.
316
+ The only safe way to remove a WAL file is
317
+ to open the database file using one of the sqlite3_open() interfaces
318
+ then immediately close the database using sqlite3_close() .
319
+ The WAL file format is precisely defined and is cross-platform.
320
+ 5. Read-Only Databases
321
+ Older versions of SQLite could not read a WAL-mode database that was
322
+ read-only. In other words, write access was required in order to read a
323
+ WAL-mode database. This constraint was relaxed beginning with
324
+ SQLite version 3.22.0 (2018-01-22).
325
+ On newer versions of SQLite,
326
+ a WAL-mode database on read-only media, or a WAL-mode database that lacks
327
+ write permission, can still be read as long as one or more of the following
328
+ conditions are met:
329
+ The -shm and -wal files already exist and are readable.
330
+ There is write permission on the directory containing the database so
331
+ that the -shm and -wal files can be created.
332
+ The database connection is opened using the
333
+ immutable query parameter .
334
+ Even though it is possible to open a read-only WAL-mode database,
335
+ it is good practice to convert the database to
336
+ PRAGMA journal_mode=DELETE prior to burning an
337
+ SQLite database image onto read-only media.
338
+ 6. Avoiding Excessively Large WAL Files
339
+ In normal cases, new content is appended to the WAL file until the
340
+ WAL file accumulates about 1000 pages (and is thus about 4MB
341
+ in size) at which point a checkpoint is automatically run and the WAL file
342
+ is recycled. The checkpoint does not normally truncate the WAL file
343
+ (unless the journal_size_limit pragma is set). Instead, it merely
344
+ causes SQLite to start overwriting the WAL file from the beginning.
345
+ This is done because it is normally faster to overwrite an existing file
346
+ than to append. When the last connection to a database closes, that
347
+ connection does one last checkpoint and then deletes the WAL and its
348
+ associated shared-memory file, to clean up the disk.
349
+ So in the vast majority of cases, applications need not worry about
350
+ the WAL file at all. SQLite will automatically take care of it. But
351
+ it is possible to get SQLite into a state where the WAL file will grow
352
+ without bound, causing excess disk space usage and slow query speeds.
353
+ The following bullets enumerate some of the ways that this can happen
354
+ and how to avoid them.
355
+ Disabling the automatic checkpoint mechanism.
356
+ In its default configuration, SQLite will checkpoint the WAL file at the
357
+ conclusion of any transaction when the WAL file is more than 1000 pages
358
+ long. However, compile-time and run-time options exist that can disable
359
+ or defer this automatic checkpoint. If an application disables the
360
+ automatic checkpoint, then there is nothing to prevent the WAL file
361
+ from growing excessively.
362
+ Checkpoint starvation.
363
+ A checkpoint is only able to run to completion, and reset the WAL file,
364
+ if there are no other database connections using the WAL file. If another
365
+ connection has a read transaction open,
366
+ then the checkpoint cannot reset the WAL file because
367
+ doing so might delete content out from under the reader.
368
+ The checkpoint will do as much work as it can without upsetting the
369
+ reader, but it cannot run to completion.
370
+ The checkpoint will start up again where it left off after the next
371
+ write transaction. This repeats until some checkpoint is able to complete.
372
+ However, if a database has many concurrent overlapping readers
373
+ and there is always at least one active reader, then
374
+ no checkpoints will be able to complete
375
+ and hence the WAL file will grow without bound.
376
+ This scenario can be avoided by ensuring that there are "reader gaps":
377
+ times when no processes are reading from the
378
+ database and that checkpoints are attempted during those times.
379
+ In applications with many concurrent readers, one might also consider
380
+ running manual checkpoints with the SQLITE_CHECKPOINT_RESTART or
381
+ SQLITE_CHECKPOINT_TRUNCATE option which will ensure that the checkpoint
382
+ runs to completion before returning. The disadvantage of using
383
+ SQLITE_CHECKPOINT_RESTART and SQLITE_CHECKPOINT_TRUNCATE is that
384
+ readers might block while the checkpoint is running.
385
+ Very large write transactions.
386
+ A checkpoint can only complete when no other transactions are running,
387
+ which means the WAL file cannot be reset in the middle of a write
388
+ transaction. So a large change to a large database
389
+ might result in a large WAL file. The WAL file will be checkpointed
390
+ once the write transaction completes (assuming there are no other readers
391
+ blocking it) but in the meantime, the file can grow very big.
392
+ As of SQLite version 3.11.0 (2016-02-15),
393
+ the WAL file for a single transaction
394
+ should be proportional in size to the transaction itself. Pages that
395
+ are changed by the transaction should only be written into the WAL file
396
+ once. However, with older versions of SQLite, the same page might be
397
+ written into the WAL file multiple times if the transaction grows larger
398
+ than the page cache.
399
+ 7. Implementation Of Shared-Memory For The WAL-Index
400
+ The wal-index is implemented using an ordinary file that is
401
+ mmapped for robustness. Early (pre-release) implementations of WAL mode
402
+ stored the wal-index in volatile shared-memory, such as files created in
403
+ /dev/shm on Linux or /tmp on other unix systems. The problem
404
+ with that approach is that processes with a different root directory
405
+ (changed via chroot )
406
+ will see different files and hence use different shared memory areas,
407
+ leading to database corruption. Other methods for creating nameless
408
+ shared memory blocks are not portable across the various flavors of
409
+ unix. And we could not find any method to create nameless shared
410
+ memory blocks on windows. The only way we have found to guarantee
411
+ that all processes accessing the same database file use the same shared
412
+ memory is to create the shared memory by mmapping a file in the same
413
+ directory as the database itself.
414
+ Using an ordinary disk file to provide shared memory has the
415
+ disadvantage that it might actually do unnecessary disk I/O by
416
+ writing the shared memory to disk. However, the developers do not
417
+ think this is a major concern since the wal-index rarely exceeds
418
+ 32 KiB in size and is never synced. Furthermore, the wal-index
419
+ backing file is deleted when the last database connection disconnects,
420
+ which often prevents any real disk I/O from ever happening.
421
+ Specialized applications for which the default implementation of
422
+ shared memory is unacceptable can devise alternative methods via a
423
+ custom VFS .
424
+ For example, if it is known that a particular database
425
+ will only be accessed by threads within a single process, the wal-index
426
+ can be implemented using heap memory instead of true shared memory.
427
+ 8. Use of WAL Without Shared-Memory
428
+ Beginning in SQLite version 3.7.4 (2010-12-07),
429
+ WAL databases can be created, read, and
430
+ written even if shared memory is unavailable as long as the
431
+ locking_mode is set to EXCLUSIVE before the first attempted access.
432
+ In other words, a process can interact with
433
+ a WAL database without using shared memory if that
434
+ process is guaranteed to be the only process accessing the database.
435
+ This feature allows WAL databases to be created, read, and written
436
+ by legacy VFSes that lack the "version 2" shared-memory
437
+ methods xShmMap, xShmLock, xShmBarrier, and xShmUnmap on the
438
+ sqlite3_io_methods object.
439
+ If EXCLUSIVE locking mode
440
+ is set prior to the first WAL-mode
441
+ database access, then SQLite never attempts to call any of the
442
+ shared-memory methods and hence no shared-memory
443
+ wal-index is ever created.
444
+ In that case, the database connection remains in EXCLUSIVE mode
445
+ as long as the journal mode is WAL; attempts to change the locking
446
+ mode using " PRAGMA locking_mode=NORMAL; " are no-ops.
447
+ The only way to change out of EXCLUSIVE locking mode is to first
448
+ change out of WAL journal mode.
449
+ If NORMAL locking mode is in effect for the first WAL-mode database
450
+ access, then the shared-memory wal-index is created. This means that the
451
+ underlying VFS must support the "version 2" shared-memory.
452
+ If the VFS does not support shared-memory methods, then the attempt to
453
+ open a database that is already in WAL mode, or the attempt to convert a
454
+ database into WAL mode, will fail.
455
+ As long as exactly one connection is using a shared-memory wal-index,
456
+ the locking mode can be changed freely between NORMAL and EXCLUSIVE.
457
+ It is only when the shared-memory wal-index is omitted, when the locking
458
+ mode is EXCLUSIVE prior to the first WAL-mode database access, that the
459
+ locking mode is stuck in EXCLUSIVE.
460
+ 9. Sometimes Queries Return SQLITE_BUSY In WAL Mode
461
+ The second advantage of WAL-mode is that
462
+ writers do not block readers and readers do not block writers.
463
+ This is mostly true.
464
+ But there are some obscure cases where a query against a WAL-mode
465
+ database can return SQLITE_BUSY , so applications should be prepared
466
+ for that happenstance.
467
+ Cases where a query against a WAL-mode database can return SQLITE_BUSY
468
+ include the following:
469
+ If another database connection has the database mode open
470
+ in exclusive locking mode then all queries against the
471
+ database will return SQLITE_BUSY . Both Chrome and Firefox open their
472
+ database files in exclusive locking mode, so attempts to read Chrome or
473
+ Firefox databases while the applications are running will run into this
474
+ problem, for example.
475
+ When the last connection to a particular database is closing,
476
+ that connection will acquire an exclusive lock for a short time while
477
+ it cleans up the WAL and shared-memory files. If a separate attempt
478
+ is made to open and query the database while the first connection is
479
+ still in the middle of its cleanup process, the second connection
480
+ might get an SQLITE_BUSY error.
481
+ If the last connection to a database crashed, then the first new
482
+ connection to open the database will start a recovery process. An
483
+ exclusive lock is held during recovery. So if a third database connection
484
+ tries to jump in and query while the second connection is running recovery,
485
+ the third connection will get an SQLITE_BUSY error.
486
+ 10. Backwards Compatibility
487
+ The database file format is unchanged for WAL mode. However, the
488
+ WAL file and the wal-index are new concepts and so older versions of
489
+ SQLite will not know
490
+ how to recover a crashed SQLite database that was operating in WAL mode
491
+ when the crash occurred.
492
+ To prevent older versions of SQLite (prior to version 3.7.0, 2010-07-22)
493
+ from trying to recover
494
+ a WAL-mode database (and making matters worse) the database file format
495
+ version numbers (bytes 18 and 19 in the database header )
496
+ are increased from 1 to 2 in WAL mode.
497
+ Thus, if an older version of SQLite attempts to connect to an SQLite
498
+ database that is operating in WAL mode, it will report an error along
499
+ the lines of "file is encrypted or is not a database".
500
+ One can explicitly change out of WAL mode using a pragma such as
501
+ this:
502
+ Deliberately changing out of WAL mode changes the database file format
503
+ version numbers back to 1 so that older versions of SQLite can once again
504
+ access the database file.
505
+ 11. The WAL-Reset Bug
506
+ On 2026-03-03, one of the SQLite developers (Dan) found and fixed
507
+ a bug that could, in rare cases, lead to database corruption. We call
508
+ this the "WAL-reset bug".
509
+ Key points:
510
+ The bug is likely present in all version of SQLite from
511
+ 3.7.0 (2010-07-21) through 3.51.2 (2026-01-09). It is
512
+ fixed in version 3.51.3 (2026-03-13) and later. Backports of the fix
513
+ are available for some earlier releases:
514
+ 3.44.6 and
515
+ 3.50.7 .
516
+ The bug only affects databases in WAL mode when there are two or more
517
+ database connections open on the same file, in separate threads or processes,
518
+ and when those two connections attempt to write or checkpoint at the
519
+ same instant.
520
+ The bug is a data race with tight timing constraints. It is unlikely
521
+ to occur in common use. The developers have never been able to reproduce
522
+ the bug organically and had to add special testing logic to SQLite
523
+ that deliberately triggers the circumstances of the the bug in order
524
+ to verify that the issue has been fixed.
525
+ 11.1. Bug Details
526
+ This is what happens:
527
+ One connection does a checkpoint . This first checkpoint must be
528
+ complete. In other words, the checkpoint must successfully copy all
529
+ content from the WAL file back into the database and leave the WAL file
530
+ in a state where it can potentially be reset.
531
+ Shortly after the first checkpoint completes, a second checkpoint
532
+ is started.
533
+ While the second checkpoint from step 2 is starting up, another database
534
+ connection commits a transaction that resets the WAL file and writes new
535
+ content into the beginning of the WAL file.
536
+ Due to a data race, the second checkpoint from step 2 does not realize
537
+ that the WAL file has been reset by the transaction commit in step 3.
538
+ The second checkpoint leaves a field in the header of the WAL-Index set
539
+ incorrectly. That field indicates that part of the WAL file has already
540
+ been checkpointed, when in fact it has not been.
541
+ Additional transactions are committed to increase the number of pages
542
+ in the WAL file to be more than were present for the first checkpoint
543
+ from step 1.
544
+ Later when a third checkpoint occurs, the third checkpoint skips all
545
+ or part of the transaction that was written in step 3. Thus parts of
546
+ the transaction from step 3 never reach the database file, and the
547
+ database file goes corrupt.
548
+ 11.2. Low Probability Of Occurrence
549
+ In order for this bug to happen, many details must align at just
550
+ the right moment. So much so that the SQLite developers were unable
551
+ to reproduce the bug organically in the lab. The only way the developers
552
+ have been able to cause the malfunction was to modify the SQLite sources
553
+ to invoke a callback controlled by sqlite3_test_control()
554
+ that enables a test program or script to trigger the write transaction
555
+ of step 3 at just the right moment during the second checkpoint.
556
+ Without that code hack, the problem has never been observed during
557
+ development and testing.
558
+ This bug, though rare, does have serious consequences, and so
559
+ application developers should upgrade to a version of SQLite
560
+ that fixes the problem.
561
+ However, this is not an emergency.
562
+ Based on available telemetry, the occurrence rate of this problem in the
563
+ wild appears to be less than or equal to the expected occurrence rate of
564
+ SSD malfunctions and/or cosmic-ray hits. So even if you are running an
565
+ unpatched version of SQLite, and unless you are doing something really
566
+ unusual, you are unlikely to ever encounter this problem.
567
+ This page was last updated on 2026-04-13 10:54:51Z