2
2
3
3
This package implements the SQLite [ OS Interface] ( https://sqlite.org/vfs.html ) (aka VFS).
4
4
5
- It replaces the default SQLite VFS with a ** pure Go** implementation.
6
-
7
- It also exposes [ interfaces] ( https://pkg.go.dev/github.com/ncruces/go-sqlite3/vfs#VFS )
5
+ It replaces the default SQLite VFS with a ** pure Go** implementation,
6
+ and exposes [ interfaces] ( https://pkg.go.dev/github.com/ncruces/go-sqlite3/vfs#VFS )
8
7
that should allow you to implement your own custom VFSes.
9
8
10
9
Since it is a from scratch reimplementation,
11
10
there are naturally some ways it deviates from the original.
12
11
13
- The main differences are [ file locking] ( #file-locking ) and [ WAL mode] ( write-ahead-logging ) support.
12
+ The main differences are [ file locking] ( #file-locking ) and [ WAL mode] ( # write-ahead-logging) support.
14
13
15
14
### File Locking
16
15
@@ -22,21 +21,22 @@ On Linux and macOS, this module uses
22
21
to synchronize access to database files.
23
22
OFD locks are fully compatible with POSIX advisory locks.
24
23
25
- On BSD Unixes, this module uses
26
- [ BSD locks] ( https://man.freebsd.org/cgi/man.cgi?query=flock&sektion=2 ) .
27
- On BSD, macOS, and illumos, these locks are fully compatible with POSIX advisory locks;
28
- on Linux and z/OS, they are fully functional, but incompatible with POSIX advisory locks.
29
- However, concurrency is always reduced with BSD locks
30
- (` BEGIN IMMEDIATE ` behaves the same as ` BEGIN EXCLUSIVE ` ).
31
- You can opt into BSD locks with the ` sqlite3_flock ` build tag.
24
+ This module can also use
25
+ [ BSD locks] ( https://man.freebsd.org/cgi/man.cgi?query=flock&sektion=2 ) ,
26
+ albeit with reduced concurrency (` BEGIN IMMEDIATE ` behaves like ` BEGIN EXCLUSIVE ` ).
27
+ On BSD, macOS, and illumos, BSD locks are fully compatible with POSIX advisory locks;
28
+ on Linux and z/OS, they are fully functional, but incompatible;
29
+ elsewhere, they are very likely broken.
30
+ BSD locks are the default on BSD and illumos,
31
+ but you can opt into them with the ` sqlite3_flock ` build tag.
32
32
33
33
On Windows, this module uses ` LockFileEx ` and ` UnlockFileEx ` ,
34
34
like SQLite.
35
35
36
- On all other platforms , file locking is not supported, and you must use
36
+ Otherwise , file locking is not supported, and you must use
37
37
[ ` nolock=1 ` ] ( https://sqlite.org/uri.html#urinolock )
38
38
(or [ ` immutable=1 ` ] ( https://sqlite.org/uri.html#uriimmutable ) )
39
- to open database files.\
39
+ to open database files.
40
40
To use the [ ` database/sql ` ] ( https://pkg.go.dev/database/sql ) driver
41
41
with ` nolock=1 ` you must disable connection pooling by calling
42
42
[ ` db.SetMaxOpenConns(1) ` ] ( https://pkg.go.dev/database/sql#DB.SetMaxOpenConns ) .
@@ -50,41 +50,37 @@ On 64-bit Linux and macOS, this module uses `mmap` to implement
50
50
[ shared-memory for the WAL-index] ( https://sqlite.org/wal.html#implementation_of_shared_memory_for_the_wal_index ) ,
51
51
like SQLite.
52
52
53
- To allow ` mmap ` to work, each connection needs to reserve up to 4GB of address space.\
54
- To limit the amount of address space each connection needs ,
53
+ To allow ` mmap ` to work, each connection needs to reserve up to 4GB of address space.
54
+ To limit the address space each connection reserves ,
55
55
use [ ` WithMemoryLimitPages ` ] ( ../tests/testcfg/testcfg.go ) .
56
56
57
- On Windows, and with BSD locks, [ WAL] ( https://sqlite.org/wal.html ) support is
58
- [ limited] ( https://sqlite.org/wal.html#noshm ) .
59
- ` EXCLUSIVE ` locking mode can be set to create, read, and write WAL databases.\
57
+ Otherwise, [ WAL support is limited] ( https://sqlite.org/wal.html#noshm ) ,
58
+ and ` EXCLUSIVE ` locking mode must be set to create, read, and write WAL databases.
60
59
To use ` EXCLUSIVE ` locking mode with the
61
60
[ ` database/sql ` ] ( https://pkg.go.dev/database/sql ) driver
62
61
you must disable connection pooling by calling
63
62
[ ` db.SetMaxOpenConns(1) ` ] ( https://pkg.go.dev/database/sql#DB.SetMaxOpenConns ) .
64
63
65
- On all other platforms, where file locking is not supported, WAL mode is disabled.
66
-
67
64
You can use [ ` vfs.SupportsSharedMemory ` ] ( https://pkg.go.dev/github.com/ncruces/go-sqlite3/vfs#SupportsSharedMemory )
68
65
to check if your build supports shared memory.
69
66
70
67
### Batch-Atomic Write
71
68
72
69
On 64-bit Linux, this module supports [ batch-atomic writes] ( https://sqlite.org/cgi/src/technote/714 )
73
- with the F2FS filesystem.
70
+ on the F2FS filesystem.
74
71
75
72
### Build Tags
76
73
77
74
The VFS can be customized with a few build tags:
78
- - ` sqlite3_flock ` forces the use of BSD locks; it can be used on z/OS for locking support ,
79
- and elsewhere to test the BSD locks.
75
+ - ` sqlite3_flock ` forces the use of BSD locks; it can be used on z/OS to enable locking ,
76
+ and elsewhere to test BSD locks.
80
77
- ` sqlite3_nosys ` prevents importing [ ` x/sys ` ] ( https://pkg.go.dev/golang.org/x/sys ) ;
81
78
disables locking _ and_ shared memory on all platforms.
82
79
- ` sqlite3_noshm ` disables shared memory on all platforms.
83
80
84
- > [ !CAUTION]
85
- > If file locking is incompatible with POSIX advisory locks,
86
- > accessing databases concurrently with this package and other SQLite implementations
87
- > is unsafe, and will eventually corrupt data.
88
- > This will only be the case if you explicitly opt into BSD locks with ` sqlite3_flock ` .
89
- > The SQLite [ ` unix-flock ` ] ( https://sqlite.org/compile.html#enable_locking_style ) VFS
90
- > is always compatible with ` sqlite3_flock ` .
81
+ > [ !IMPORTANT]
82
+ > The default configuration of this package is compatible with
83
+ > the standard [ Unix and Windows SQLite VFSes] ( https://sqlite.org/vfs.html#multiple_vfses ) ;
84
+ > ` sqlite3_flock ` is compatible with the [ ` unix-flock ` VFS] ( https://sqlite.org/compile.html#enable_locking_style ) .
85
+ > If incompatible file locking is used, accessing databases concurrently with _ other_ SQLite libraries
86
+ > will eventually corrupt data.
0 commit comments