Documentation Source Text

Check-in [516e342f08]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Enhance the how-to-corrupt document to warn against carrying an open database connection across a fork().
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | version-3.23
Files: files | file ages | folders
SHA3-256: 516e342f088c8fb3fd3948ba59588e0412d1eb595a6ffd29f614ed85964c4edd
User & Date: drh 2018-04-04 00:56:34.963
Context
2018-04-06
12:16
Align the use of the "BLOB" affinity in lang_createtable.html with the definitions in datatype3.html. (check-in: e4161dc6b1 user: drh tags: version-3.23)
2018-04-04
00:56
Enhance the how-to-corrupt document to warn against carrying an open database connection across a fork(). (check-in: 516e342f08 user: drh tags: version-3.23)
2018-04-02
21:24
Fix a typo in the CLI document. (check-in: 7bf84d856a user: drh tags: version-3.23)
Changes
Unified Diff Ignore Whitespace Patch
Changes to pages/howtocorrupt.in.
227
228
229
230
231
232
233

















234
235
236
237
238
239
240

<p>Beginning with SQLite [version 3.10.0] ([dateof:3.10.0]), 
the unix OS interface will
attempt to resolve symbolic links and open the database file by its
canonical name.  Prior to version 3.10.0, opening a database file 
through a symbolic link was similar to opening a database file
that had multiple hard links and resulted in undefined behavior.</p>


















<h1> Failure to sync</h1>

<p>In order to guarantee that database files are always consistent, SQLite
will occasionally ask the operating system to flush all pending writes to
persistent storage then wait for that flush to complete.  This is 
accomplished using the <tt>fsync()</tt> system call under unix and







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257

<p>Beginning with SQLite [version 3.10.0] ([dateof:3.10.0]), 
the unix OS interface will
attempt to resolve symbolic links and open the database file by its
canonical name.  Prior to version 3.10.0, opening a database file 
through a symbolic link was similar to opening a database file
that had multiple hard links and resulted in undefined behavior.</p>

<tcl>hd_fragment fork</tcl>
<h2> Carrying an open database connection across a fork() </h2>

<p> Do not open an SQLite database connection, then fork(), then try
to use that database connection in the child process.  All kinds of
locking problems will result and you can easily end up with a corrupt
database.  SQLite is not designed to support that kind of behavior.
Any database connection that is used in a child process must be opened
in the child process, not inherited from the parent.

<p> Do not even call [sqlite3_close()] on a database connection from a
child process if the connection was opened in the parent.  It is safe
to close the underlying file descriptor, but the [sqlite3_close()]
interface might invoke cleanup activities that will delete content out
from under the parent, leading to errors and perhaps even database
corruption.

<h1> Failure to sync</h1>

<p>In order to guarantee that database files are always consistent, SQLite
will occasionally ask the operating system to flush all pending writes to
persistent storage then wait for that flush to complete.  This is 
accomplished using the <tt>fsync()</tt> system call under unix and