| 1 |
SQlite Module |
| 2 |
|
| 3 |
Timo Teräs |
| 4 |
|
| 5 |
Edited by |
| 6 |
|
| 7 |
Timo Teräs |
| 8 |
|
| 9 |
Edited by |
| 10 |
|
| 11 |
Julien Chavanton |
| 12 |
|
| 13 |
flowroute.com |
| 14 |
<[email protected]> |
| 15 |
|
| 16 |
Edited by |
| 17 |
|
| 18 |
Andreas Granig |
| 19 |
|
| 20 |
sipfront.com |
| 21 |
<[email protected]> |
| 22 |
|
| 23 |
Copyright © 2011 Timo Teräs |
| 24 |
|
| 25 |
Copyright © 2017 |
| 26 |
|
| 27 |
Copyright © 2024 |
| 28 |
__________________________________________________________________ |
| 29 |
|
| 30 |
Table of Contents |
| 31 |
|
| 32 |
1. Admin Guide |
| 33 |
|
| 34 |
1. Overview |
| 35 |
2. Dependencies |
| 36 |
|
| 37 |
2.1. Kamailio Modules |
| 38 |
2.2. External Libraries or Applications |
| 39 |
|
| 40 |
3. Parameters |
| 41 |
|
| 42 |
3.1. db_set_readonly (string) |
| 43 |
3.2. db_set_journal_mode (string) |
| 44 |
3.3. db_set_busy_timeout (int) |
| 45 |
|
| 46 |
4. Functions |
| 47 |
5. Usage |
| 48 |
|
| 49 |
List of Examples |
| 50 |
|
| 51 |
1.1. Set db_set_readonly parameter |
| 52 |
1.2. Set db_set_journal_mode parameter |
| 53 |
1.3. Set db_set_busy_timeout parameter |
| 54 |
1.4. loading the module usage |
| 55 |
1.5. db_url module parameter usage |
| 56 |
1.6. DBURL define usage |
| 57 |
|
| 58 |
Chapter 1. Admin Guide |
| 59 |
|
| 60 |
Table of Contents |
| 61 |
|
| 62 |
1. Overview |
| 63 |
2. Dependencies |
| 64 |
|
| 65 |
2.1. Kamailio Modules |
| 66 |
2.2. External Libraries or Applications |
| 67 |
|
| 68 |
3. Parameters |
| 69 |
|
| 70 |
3.1. db_set_readonly (string) |
| 71 |
3.2. db_set_journal_mode (string) |
| 72 |
3.3. db_set_busy_timeout (int) |
| 73 |
|
| 74 |
4. Functions |
| 75 |
5. Usage |
| 76 |
|
| 77 |
1. Overview |
| 78 |
|
| 79 |
The module is an implementation of the internal DB API v1 connector for |
| 80 |
SQlite 3 file. |
| 81 |
|
| 82 |
2. Dependencies |
| 83 |
|
| 84 |
2.1. Kamailio Modules |
| 85 |
2.2. External Libraries or Applications |
| 86 |
|
| 87 |
2.1. Kamailio Modules |
| 88 |
|
| 89 |
The following modules must be loaded before this module: |
| 90 |
* No dependencies on other Kamailio modules. |
| 91 |
|
| 92 |
2.2. External Libraries or Applications |
| 93 |
|
| 94 |
The following libraries or applications must be installed before |
| 95 |
running Kamailio with this module loaded: |
| 96 |
* SQlite 3 library - e.g., libsqlite3-0 |
| 97 |
* SQlite 3 devel library - to compile the module e.g. libsqlite3-dev |
| 98 |
* SQlite 3 utilities - for kamdbctl e.g. sqlite3 |
| 99 |
|
| 100 |
3. Parameters |
| 101 |
|
| 102 |
3.1. db_set_readonly (string) |
| 103 |
3.2. db_set_journal_mode (string) |
| 104 |
3.3. db_set_busy_timeout (int) |
| 105 |
|
| 106 |
3.1. db_set_readonly (string) |
| 107 |
|
| 108 |
This will set the db connection to "SQLITE_OPEN_READONLY", useful if |
| 109 |
another program is writing to the DB. The value is the full path to the |
| 110 |
sqlite file used for example in any db_url or sqlops/sqlcon This |
| 111 |
parameter may be set multiple times to set many DB connections to |
| 112 |
readonly in the same configuration file. |
| 113 |
|
| 114 |
By default all the db connections are using "SQLITE_OPEN_READWRITE | |
| 115 |
SQLITE_OPEN_CREATE" |
| 116 |
|
| 117 |
Example 1.1. Set db_set_readonly parameter |
| 118 |
... |
| 119 |
# Don't use trailing slashes for db_sqlite params |
| 120 |
modparam("db_sqlite","db_set_readonly","var/mydb.sqlite") |
| 121 |
modparam("sqlops","sqlcon","lrn=>sqlite:///var/mydb.sqlite") # Example if using |
| 122 |
the sqlops module |
| 123 |
... |
| 124 |
|
| 125 |
3.2. db_set_journal_mode (string) |
| 126 |
|
| 127 |
This will set the db connection journal mode, for the given connection. |
| 128 |
The value is the full path to the sqlite file used for example in any |
| 129 |
db_url or sqlops/sqlcon Other journal mode are : DELETE | TRUNCATE | |
| 130 |
PERSIST | MEMORY | WAL | OFF When setting this option, you must also |
| 131 |
set db_set_busy_timeout, because all kamailio sub-processes will set |
| 132 |
this option individually and simultaneously, causing "database locked" |
| 133 |
errors on startup if no busy timeout is set. This parameter may be set |
| 134 |
multiple times to set many DB connections to readonly in the same |
| 135 |
configuration file. |
| 136 |
|
| 137 |
By default all the db connections are using sqlite default journaling |
| 138 |
mode. |
| 139 |
|
| 140 |
Example 1.2. Set db_set_journal_mode parameter |
| 141 |
... |
| 142 |
# In this example we are using Write-Ahead Logging in order to update the databa |
| 143 |
se |
| 144 |
# from another process(external to Kamailio) without facing any locking. |
| 145 |
|
| 146 |
# Don't use trailing slashes for db_sqlite params |
| 147 |
#!subst "!DB_FILE!var/mydb.sqlite!" |
| 148 |
modparam("db_sqlite","db_set_readonly","DB_FILE") # We are also opening the da |
| 149 |
tabase in readonly |
| 150 |
modparam("db_sqlite","db_set_journal_mode","DB_FILE=WAL;") |
| 151 |
modparam("db_sqlite","db_set_busy_timeout","DB_FILE=300;") # wait 300ms max for |
| 152 |
locks to release |
| 153 |
modparam("sqlops","sqlcon","lrn=>sqlite:///DB_FILE") |
| 154 |
... |
| 155 |
|
| 156 |
3.3. db_set_busy_timeout (int) |
| 157 |
|
| 158 |
This will set the db connection busy timeout to let it wait for the |
| 159 |
given milliseconds for database locks to be released by other processes |
| 160 |
before giving up. Use this with the WAL journaling mode if you run into |
| 161 |
"database locked" errors. The value is the full path to the sqlite file |
| 162 |
used for example in any db_url or sqlops/sqlcon This parameter may be |
| 163 |
set multiple times to set the busy-timeout for different DB connections |
| 164 |
in the same configuration file. |
| 165 |
|
| 166 |
By default all the db connections are NOT using any busy timeout, |
| 167 |
causing them to immediately give up and return a "databased locked" |
| 168 |
error if another process is locking it at the same time. |
| 169 |
|
| 170 |
Example 1.3. Set db_set_busy_timeout parameter |
| 171 |
... |
| 172 |
# In this example we are using Write-Ahead Logging in combination with a busy-ti |
| 173 |
meout to prevent |
| 174 |
"database locked" errors. Note that you have to leave out the leading slash in t |
| 175 |
he DB file! |
| 176 |
|
| 177 |
#!subst "!DB_FILE!var/mydb.sqlite!" |
| 178 |
modparam("db_sqlite","db_set_journal_mode","DB_FILE=WAL;") |
| 179 |
modparam("db_sqlite","db_set_busy_timeout","DB_FILE=300;") # wait 300ms max for |
| 180 |
locks to release |
| 181 |
modparam("sqlops","sqlcon","lrn=>sqlite:///DB_FILE") |
| 182 |
... |
| 183 |
|
| 184 |
4. Functions |
| 185 |
|
| 186 |
NONE |
| 187 |
|
| 188 |
5. Usage |
| 189 |
|
| 190 |
To use the module, first you have to load it in the Kamailio |
| 191 |
configuration file. |
| 192 |
|
| 193 |
Example 1.4. loading the module usage |
| 194 |
... |
| 195 |
loadmodule "db_sqlite.so" |
| 196 |
... |
| 197 |
|
| 198 |
Then set the db_url (or similar) parameter of modules that have to use |
| 199 |
the SQLite database to driver part 'sqlite://', followed by the path to |
| 200 |
database file. For example: |
| 201 |
|
| 202 |
Example 1.5. db_url module parameter usage |
| 203 |
... |
| 204 |
modparam("auth_db", "db_url", "sqlite:///etc/kamailio/kamailio.db") |
| 205 |
... |
| 206 |
|
| 207 |
In the default config file, defined token DBURL can be updated like: |
| 208 |
|
| 209 |
Example 1.6. DBURL define usage |
| 210 |
... |
| 211 |
#!define DBURL "sqlite:///etc/kamailio/kamailio.db" |
| 212 |
... |